dbus.c 63.7 KB
Newer Older
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
1
2
/*
 *  Copyright (C) 2007 Savoir-Faire Linux inc.
3
 *  Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
4
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
5
 *  Author: Guillaume Carmel-Archambault <guillaume.carmel-archambault@savoirfairelinux.com>
Julien Bonjean's avatar
Julien Bonjean committed
6
 *
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
7
8
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 3 of the License, or
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
10
 *  (at your option) any later version.
Julien Bonjean's avatar
Julien Bonjean committed
11
 *
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
12
13
14
15
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
Julien Bonjean's avatar
Julien Bonjean committed
16
 *
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
17
18
19
20
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
21
#include <config.h>
Julien Bonjean's avatar
Julien Bonjean committed
22

areversat's avatar
areversat committed
23
#include <calltab.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
24
25
#include <callmanager-glue.h>
#include <configurationmanager-glue.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
26
#include <instance-glue.h>
27
28
#include <preferencesdialog.h>
#include <accountlistconfigdialog.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
29
#include <mainwindow.h>
30
#include <marshaller.h>
31
#include <sliders.h>
32
#include <statusicon.h>
33
#include <assistant.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
34

35
36
37
#include <dbus.h>
#include <actions.h>
#include <string.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
38

39
40
#define DEFAULT_DBUS_TIMEOUT 30000

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
41
42
43
DBusGConnection * connection;
DBusGProxy * callManagerProxy;
DBusGProxy * configurationManagerProxy;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
44
DBusGProxy * instanceProxy;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
45

46
47
48
static void
incoming_call_cb(DBusGProxy *proxy UNUSED, const gchar* accountID,
    const gchar* callID, const gchar* from, void * foo  UNUSED )
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
49
{
50
  DEBUG("Incoming call (%s) from %s", callID, from);
51

52
53
54
55
56
  callable_obj_t * c;
  gchar *peer_name, *peer_number;
  // We receive the from field under a formatted way. We want to extract the number and the name of the caller
  peer_name = call_get_peer_name(from);
  peer_number = call_get_peer_number(from);
57

58
59
  DEBUG("    peer name: %s", peer_name);
  DEBUG("    peer number: %s", peer_number);
60

61
62
  create_new_call(CALL, CALL_STATE_INCOMING, g_strdup(callID), g_strdup(
      accountID), peer_name, peer_number, &c);
63
#if GTK_CHECK_VERSION(2,10,0)
64
65
  status_tray_icon_blink(TRUE);
  popup_main_window();
66
#endif
67

68
69
70
  set_timestamp(&c->_time_start);
  notify_incoming_call(c);
  sflphone_incoming_call(c);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
71
72
}

73
74
75
static void
zrtp_negotiation_failed_cb(DBusGProxy *proxy UNUSED, const gchar* callID,
    const gchar* reason, const gchar* severity, void * foo  UNUSED )
76
{
77
78
79
80
81
82
83
  DEBUG ("Zrtp negotiation failed.");
  main_window_zrtp_negotiation_failed(callID, reason, severity);
  callable_obj_t * c = NULL;
  c = calllist_get(current_calls, callID);
  if (c)
    {
      notify_zrtp_negotiation_failed(c);
84
    }
85
86
}

87
88
89
static void
curent_selected_codec(DBusGProxy *proxy UNUSED, const gchar* callID,
    const gchar* codecName, void * foo  UNUSED )
Alexandre Savard's avatar
Alexandre Savard committed
90
{
91
92
  // DEBUG ("%s codec decided for call %s",codecName,callID);
  // sflphone_display_selected_codec (codecName);
Alexandre Savard's avatar
Alexandre Savard committed
93
}
94

95
96
97
static void
volume_changed_cb(DBusGProxy *proxy UNUSED, const gchar* device, const gdouble value,
    void * foo  UNUSED )
98
{
99
100
  DEBUG ("Volume of %s changed to %f.",device, value);
  set_slider(device, value);
101
102
}

103
104
105
static void
voice_mail_cb(DBusGProxy *proxy UNUSED, const gchar* accountID, const guint nb,
    void * foo  UNUSED )
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
106
{
107
108
  DEBUG ("%d Voice mail waiting!",nb);
  sflphone_notify_voice_mail(accountID, nb);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
109
110
}

111
112
113
static void
incoming_message_cb(DBusGProxy *proxy UNUSED, const gchar* accountID UNUSED,
    const gchar* msg, void * foo  UNUSED )
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
114
{
115
  DEBUG ("Message %s!",msg);
Julien Bonjean's avatar
Julien Bonjean committed
116

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
117
118
}

119
120
121
static void
call_state_cb(DBusGProxy *proxy UNUSED, const gchar* callID, const gchar* state,
    void * foo  UNUSED )
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
122
{
123
124
125
  DEBUG ("Call %s state %s",callID, state);
  callable_obj_t * c = calllist_get(current_calls, callID);
  if (c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
126
    {
127
      if (strcmp(state, "HUNGUP") == 0)
128
        {
129
          if (c->_state == CALL_STATE_CURRENT)
130
            {
131
132
133
134
              // peer hung up, the conversation was established, so _stop has been initialized with the current time value
              DEBUG("call state current");
              set_timestamp(&c->_time_stop);
              calltree_update_call(history, c, NULL);
135
            }
136
137
138
139
          stop_notification();
          sflphone_hung_up(c);
          calltree_update_call(history, c, NULL );
          status_bar_display_account();
140
        }
141
      else if (strcmp(state, "UNHOLD_CURRENT") == 0)
142
        {
143
          sflphone_current(c);
144
        }
145
      else if (strcmp(state, "UNHOLD_RECORD") == 0)
146
        {
147
          sflphone_record(c);
148
        }
149
      else if (strcmp(state, "HOLD") == 0)
150
        {
151
          sflphone_hold(c);
152
        }
153
      else if (strcmp(state, "RINGING") == 0)
154
        {
155
          sflphone_ringing(c);
156
        }
157
      else if (strcmp(state, "CURRENT") == 0)
158
        {
159
          sflphone_current(c);
160
        }
161
      else if (strcmp(state, "FAILURE") == 0)
162
        {
163
          sflphone_fail(c);
164
        }
165
      else if (strcmp(state, "BUSY") == 0)
166
        {
167
          sflphone_busy(c);
168
        }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
169
    }
170
  else
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
171
    {
172
173
174
175
      // The callID is unknow, threat it like a new call
      // If it were an incoming call, we won't be here
      // It means that a new call has been initiated with an other client (cli for instance)
      if (strcmp(state, "RINGING") == 0 || strcmp(state, "CURRENT") == 0)
176
        {
177
178
179
          callable_obj_t *new_call;
          GHashTable *call_details;
          gchar *type;
180

181
          DEBUG ("New ringing call! accountID: %s", callID);
182

183
184
185
          // We fetch the details associated to the specified call
          call_details = dbus_get_call_details(callID);
          create_new_call_from_details(callID, call_details, &new_call);
186

187
188
189
          // Restore the callID to be synchronous with the daemon
          new_call->_callID = g_strdup(callID);
          type = g_hash_table_lookup(call_details, "CALL_TYPE");
190

191
          if (g_strcasecmp(type, "0") == 0)
Emmanuel Milou's avatar
Emmanuel Milou committed
192
            {
193
194
              // DEBUG("incoming\n");
              new_call->_history_state = INCOMING;
Emmanuel Milou's avatar
Emmanuel Milou committed
195
            }
196
          else
Emmanuel Milou's avatar
Emmanuel Milou committed
197
            {
198
199
              // DEBUG("outgoing\n");
              new_call->_history_state = OUTGOING;
Emmanuel Milou's avatar
Emmanuel Milou committed
200
201
            }

202
203
204
205
206
          calllist_add(current_calls, new_call);
          calllist_add(history, new_call);
          calltree_add_call(current_calls, new_call, NULL);
          update_actions();
          calltree_display(current_calls);
Emmanuel Milou's avatar
Emmanuel Milou committed
207

208
          //sflphone_incoming_call (new_call);
209
        }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
210
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
211
212
}

213
static void
214
215
conference_changed_cb(DBusGProxy *proxy UNUSED, const gchar* confID,
    const gchar* state, void * foo  UNUSED )
216
{
217

218
219
220
221
222
223
  // sflphone_display_transfer_status("Transfer successfull");
  conference_obj_t* changed_conf = conferencelist_get(confID);
  gchar** participants;
  gchar** part;

  DEBUG("conference new state %s\n", state);
224

225
  if (changed_conf)
226
    {
227
228
      // remove old conference from calltree
      calltree_remove_conference(current_calls, changed_conf, NULL);
229

230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
      // update conference state
      if (strcmp(state, "ACTIVE_ATACHED") == 0)
        {
          changed_conf->_state = CONFERENCE_STATE_ACTIVE_ATACHED;
        }
      else if (strcmp(state, "ACTIVE_DETACHED") == 0)
        {
          changed_conf->_state = CONFERENCE_STATE_ACTIVE_DETACHED;
        }
      else if (strcmp(state, "HOLD") == 0)
        {
          changed_conf->_state = CONFERENCE_STATE_HOLD;
        }
      else
        {
          DEBUG("Error: conference state not recognized");
        }
247

248
      participants = (gchar**) dbus_get_participant_list(changed_conf->_confID);
249

250
251
252
253
254
      // update conferece participants
      conference_participant_list_update(participants, changed_conf);

      // add new conference to calltree
      calltree_add_conference(current_calls, changed_conf);
255
    }
256
257
258
}

static void
259
conference_created_cb(DBusGProxy *proxy UNUSED, const gchar* confID, void * foo  UNUSED )
260
{
261
  DEBUG ("Conference added %s\n", confID);
262

263
264
265
266
267
  conference_obj_t* new_conf;
  callable_obj_t* call;
  gchar* call_id;
  gchar** participants;
  gchar** part;
268

269
270
  create_new_conference(CONFERENCE_STATE_ACTIVE_ATACHED, confID, &new_conf);
  // new_conf->_confID = g_strdup(confID);
271

272
  participants = (gchar**) dbus_get_participant_list(new_conf->_confID);
273

274
  conference_participant_list_update(participants, new_conf);
275

276
277
278
279
280
281
  // participant = new_conf->participant;
  for (part = participants; *part; part++)
    {
      call_id = (gchar*) (*part);
      call = calllist_get(current_calls, call_id);
      call->_confID = g_strdup(confID);
282
283
    }

284
285
  conferencelist_add(new_conf);
  calltree_add_conference(current_calls, new_conf);
286
287
288
}

static void
289
conference_removed_cb(DBusGProxy *proxy UNUSED, const gchar* confID, void * foo  UNUSED )
290
{
291
  DEBUG ("Conference removed %s\n", confID);
292

293
294
295
  conference_obj_t * c = conferencelist_get(confID);
  calltree_remove_conference(current_calls, c, NULL);
  conferencelist_remove(c->_confID);
296
297
}

298
299
static void
accounts_changed_cb(DBusGProxy *proxy UNUSED, void * foo  UNUSED )
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
300
{
301
302
303
304
  DEBUG ("Accounts changed");
  sflphone_fill_account_list();
  sflphone_fill_ip2ip_profile();
  account_list_config_dialog_fill();
305

306
307
308
  // Update the status bar in case something happened
  // Should fix ticket #1215
  status_bar_display_account();
309

310
311
  // Update the tooltip on the status icon
  statusicon_set_tooltip ();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
312
313
}

314
315
static void
transfer_succeded_cb(DBusGProxy *proxy UNUSED, void * foo  UNUSED )
316
{
317
318
  DEBUG ("Transfer succeded\n");
  sflphone_display_transfer_status("Transfer successfull");
319
320
}

321
322
static void
transfer_failed_cb(DBusGProxy *proxy UNUSED, void * foo  UNUSED )
323
{
324
325
  DEBUG ("Transfer failed\n");
  sflphone_display_transfer_status("Transfer failed");
326
327
}

328
329
static void
secure_sdes_on_cb(DBusGProxy *proxy UNUSED, const gchar *callID, void *foo UNUSED)
330
{
331
332
333
334
335
336
  DEBUG("SRTP using SDES is on");
  callable_obj_t *c = calllist_get(current_calls, callID);
  if (c)
    {
      sflphone_srtp_sdes_on(c);
      notify_secure_on(c);
337
338
339
340
341
    }

}

static void
342
secure_sdes_off_cb(DBusGProxy *proxy UNUSED, const gchar *callID, void *foo UNUSED)
343
{
344
345
346
347
348
349
  DEBUG("SRTP using SDES is off");
  callable_obj_t *c = calllist_get(current_calls, callID);
  if (c)
    {
      sflphone_srtp_sdes_off(c);
      notify_secure_off(c);
350
351
352
    }
}

353
354
355
static void
secure_zrtp_on_cb(DBusGProxy *proxy UNUSED, const gchar* callID, const gchar* cipher,
    void * foo  UNUSED )
356
{
357
358
359
360
361
362
363
364
  DEBUG ("SRTP using ZRTP is ON secure_on_cb");
  callable_obj_t * c = calllist_get(current_calls, callID);
  if (c)
    {
      c->_srtp_cipher = g_strdup(cipher);

      sflphone_srtp_zrtp_on(c);
      notify_secure_on(c);
365
366
367
    }
}

368
369
static void
secure_zrtp_off_cb(DBusGProxy *proxy UNUSED, const gchar* callID, void * foo  UNUSED )
370
{
371
372
373
374
375
376
  DEBUG ("SRTP using ZRTP is OFF");
  callable_obj_t * c = calllist_get(current_calls, callID);
  if (c)
    {
      sflphone_srtp_zrtp_off(c);
      notify_secure_off(c);
377
378
379
    }
}

380
381
382
static void
show_zrtp_sas_cb(DBusGProxy *proxy UNUSED, const gchar* callID, const gchar* sas,
    const gboolean verified, void * foo  UNUSED )
383
{
384
385
386
387
388
  DEBUG ("Showing SAS");
  callable_obj_t * c = calllist_get(current_calls, callID);
  if (c)
    {
      sflphone_srtp_zrtp_show_sas(c, sas, verified);
389
390
391
    }
}

392
393
static void
confirm_go_clear_cb(DBusGProxy *proxy UNUSED, const gchar* callID, void * foo  UNUSED )
394
{
395
396
397
398
399
  DEBUG ("Confirm Go Clear request");
  callable_obj_t * c = calllist_get(current_calls, callID);
  if (c)
    {
      sflphone_confirm_go_clear(c);
400
401
402
    }
}

403
404
static void
zrtp_not_supported_cb(DBusGProxy *proxy UNUSED, const gchar* callID, void * foo  UNUSED )
405
{
406
407
408
409
410
411
  DEBUG ("ZRTP not supported on the other end");
  callable_obj_t * c = calllist_get(current_calls, callID);
  if (c)
    {
      sflphone_srtp_zrtp_not_supported(c);
      notify_zrtp_not_supported(c);
412
413
414
    }
}

415
416
417
static void
sip_call_state_cb(DBusGProxy *proxy UNUSED, const gchar* callID,
    const gchar* description, const guint code, void * foo  UNUSED )
418
{
419
420
  callable_obj_t * c = NULL;
  c = calllist_get(current_calls, callID);
421

422
423
424
425
  if (c != NULL)
    {
      DEBUG("sip_call_state_cb received code %d", code);
      sflphone_call_state_changed(c, description, code);
426
427
    }
}
428

429
430
static void
error_alert(DBusGProxy *proxy UNUSED, int errCode, void * foo  UNUSED )
431
{
432
433
  ERROR ("Error notifying : (%i)", errCode);
  sflphone_throw_exception(errCode);
434
435
}

436
437
438
gboolean
dbus_connect()
{
Julien Bonjean's avatar
Julien Bonjean committed
439

440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
  GError *error = NULL;
  connection = NULL;
  instanceProxy = NULL;

  g_type_init();

  connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);

  if (error)
    {
      ERROR ("Failed to open connection to bus: %s",
          error->message);
      g_error_free(error);
      return FALSE;
    }

  /* Create a proxy object for the "bus driver" (name "org.freedesktop.DBus") */

  instanceProxy = dbus_g_proxy_new_for_name(connection,
      "org.sflphone.SFLphone", "/org/sflphone/SFLphone/Instance",
      "org.sflphone.SFLphone.Instance");
  /*
   instanceProxy = dbus_g_proxy_new_for_name_owner (connection,
   "org.sflphone.SFLphone",
   "/org/sflphone/SFLphone/Instance",
   "org.sflphone.SFLphone.Instance",
   &error);
   */

  if (instanceProxy == NULL)
    {
      ERROR ("Failed to get proxy to Instance");
      return FALSE;
    }

  DEBUG ("DBus connected to Instance");

  callManagerProxy = dbus_g_proxy_new_for_name(connection,
      "org.sflphone.SFLphone", "/org/sflphone/SFLphone/CallManager",
      "org.sflphone.SFLphone.CallManager");

  /*
   callManagerProxy = dbus_g_proxy_new_for_name_owner (connection,
   "org.sflphone.SFLphone",
   "/org/sflphone/SFLphone/CallManager",
   "org.sflphone.SFLphone.CallManager",
   &error);
   */
  if (callManagerProxy == NULL)
    {
      ERROR ("Failed to get proxy to CallManagers");
      return FALSE;
    }

  DEBUG ("DBus connected to CallManager");
  /* STRING STRING STRING Marshaller */
  /* Incoming call */
  dbus_g_object_register_marshaller(
      g_cclosure_user_marshal_VOID__STRING_STRING_STRING, G_TYPE_NONE,
      G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
  dbus_g_proxy_add_signal(callManagerProxy, "incomingCall", G_TYPE_STRING,
      G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
  dbus_g_proxy_connect_signal(callManagerProxy, "incomingCall",
      G_CALLBACK(incoming_call_cb), NULL, NULL);

  dbus_g_proxy_add_signal(callManagerProxy, "zrtpNegotiationFailed",
      G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
  dbus_g_proxy_connect_signal(callManagerProxy, "zrtpNegotiationFailed",
      G_CALLBACK(zrtp_negotiation_failed_cb), NULL, NULL);

  /* Current codec */
  dbus_g_object_register_marshaller(
      g_cclosure_user_marshal_VOID__STRING_STRING_STRING, G_TYPE_NONE,
      G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
  dbus_g_proxy_add_signal(callManagerProxy, "currentSelectedCodec",
      G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
  dbus_g_proxy_connect_signal(callManagerProxy, "currentSelectedCodec",
      G_CALLBACK(curent_selected_codec), NULL, NULL);

  /* Register a marshaller for STRING,STRING */
  dbus_g_object_register_marshaller(
      g_cclosure_user_marshal_VOID__STRING_STRING, G_TYPE_NONE, G_TYPE_STRING,
      G_TYPE_STRING, G_TYPE_INVALID);
  dbus_g_proxy_add_signal(callManagerProxy, "callStateChanged", G_TYPE_STRING,
      G_TYPE_STRING, G_TYPE_INVALID);
  dbus_g_proxy_connect_signal(callManagerProxy, "callStateChanged",
      G_CALLBACK(call_state_cb), NULL, NULL);

  dbus_g_object_register_marshaller(g_cclosure_user_marshal_VOID__STRING_INT,
      G_TYPE_NONE, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INVALID);
  dbus_g_proxy_add_signal(callManagerProxy, "voiceMailNotify", G_TYPE_STRING,
      G_TYPE_INT, G_TYPE_INVALID);
  dbus_g_proxy_connect_signal(callManagerProxy, "voiceMailNotify",
      G_CALLBACK(voice_mail_cb), NULL, NULL);

  dbus_g_proxy_add_signal(callManagerProxy, "incomingMessage", G_TYPE_STRING,
      G_TYPE_STRING, G_TYPE_INVALID);
  dbus_g_proxy_connect_signal(callManagerProxy, "incomingMessage",
      G_CALLBACK(incoming_message_cb), NULL, NULL);

  dbus_g_object_register_marshaller(
      g_cclosure_user_marshal_VOID__STRING_DOUBLE, G_TYPE_NONE, G_TYPE_STRING,
      G_TYPE_DOUBLE, G_TYPE_INVALID);
  dbus_g_proxy_add_signal(callManagerProxy, "volumeChanged", G_TYPE_STRING,
      G_TYPE_DOUBLE, G_TYPE_INVALID);
  dbus_g_proxy_connect_signal(callManagerProxy, "volumeChanged",
      G_CALLBACK(volume_changed_cb), NULL, NULL);

  dbus_g_proxy_add_signal(callManagerProxy, "transferSucceded", G_TYPE_INVALID);
  dbus_g_proxy_connect_signal(callManagerProxy, "transferSucceded",
      G_CALLBACK(transfer_succeded_cb), NULL, NULL);

  dbus_g_proxy_add_signal(callManagerProxy, "transferFailed", G_TYPE_INVALID);
  dbus_g_proxy_connect_signal(callManagerProxy, "transferFailed",
      G_CALLBACK(transfer_failed_cb), NULL, NULL);

  /* Conference related callback */

  dbus_g_object_register_marshaller(g_cclosure_user_marshal_VOID__STRING,
      G_TYPE_NONE, G_TYPE_STRING, G_TYPE_INVALID);
  dbus_g_proxy_add_signal(callManagerProxy, "conferenceChanged", G_TYPE_STRING,
      G_TYPE_STRING, G_TYPE_INVALID);
  dbus_g_proxy_connect_signal(callManagerProxy, "conferenceChanged",
      G_CALLBACK(conference_changed_cb), NULL, NULL);

  dbus_g_proxy_add_signal(callManagerProxy, "conferenceCreated", G_TYPE_STRING,
      G_TYPE_INVALID);
  dbus_g_proxy_connect_signal(callManagerProxy, "conferenceCreated",
      G_CALLBACK(conference_created_cb), NULL, NULL);

  dbus_g_proxy_add_signal(callManagerProxy, "conferenceRemoved", G_TYPE_STRING,
      G_TYPE_INVALID);
  dbus_g_proxy_connect_signal(callManagerProxy, "conferenceRemoved",
      G_CALLBACK(conference_removed_cb), NULL, NULL);

  /* Security related callbacks */

  dbus_g_proxy_add_signal(callManagerProxy, "secureSdesOn", G_TYPE_STRING,
      G_TYPE_INVALID);
  dbus_g_proxy_connect_signal(callManagerProxy, "secureSdesOn",
      G_CALLBACK(secure_sdes_on_cb), NULL, NULL);

  dbus_g_proxy_add_signal(callManagerProxy, "secureSdesOff", G_TYPE_STRING,
      G_TYPE_INVALID);
  dbus_g_proxy_connect_signal(callManagerProxy, "secureSdesOff",
      G_CALLBACK(secure_sdes_off_cb), NULL, NULL);

  /* Register a marshaller for STRING,STRING,BOOL */
  dbus_g_object_register_marshaller(
      g_cclosure_user_marshal_VOID__STRING_STRING_BOOL, G_TYPE_NONE,
      G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_INVALID);
  dbus_g_proxy_add_signal(callManagerProxy, "showSAS", G_TYPE_STRING,
      G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_INVALID);
  dbus_g_proxy_connect_signal(callManagerProxy, "showSAS",
      G_CALLBACK(show_zrtp_sas_cb), NULL, NULL);

  dbus_g_proxy_add_signal(callManagerProxy, "secureZrtpOn", G_TYPE_STRING,
      G_TYPE_STRING, G_TYPE_INVALID);
  dbus_g_proxy_connect_signal(callManagerProxy, "secureZrtpOn",
      G_CALLBACK(secure_zrtp_on_cb), NULL, NULL);

  /* Register a marshaller for STRING*/
  dbus_g_object_register_marshaller(g_cclosure_user_marshal_VOID__STRING,
      G_TYPE_NONE, G_TYPE_STRING, G_TYPE_INVALID);
  dbus_g_proxy_add_signal(callManagerProxy, "secureZrtpOff", G_TYPE_STRING,
      G_TYPE_INVALID);
  dbus_g_proxy_connect_signal(callManagerProxy, "secureZrtpOff",
      G_CALLBACK(secure_zrtp_off_cb), NULL, NULL);
  dbus_g_proxy_add_signal(callManagerProxy, "zrtpNotSuppOther", G_TYPE_STRING,
      G_TYPE_INVALID);
  dbus_g_proxy_connect_signal(callManagerProxy, "zrtpNotSuppOther",
      G_CALLBACK(zrtp_not_supported_cb), NULL, NULL);
  dbus_g_proxy_add_signal(callManagerProxy, "confirmGoClear", G_TYPE_STRING,
      G_TYPE_INVALID);
  dbus_g_proxy_connect_signal(callManagerProxy, "confirmGoClear",
      G_CALLBACK(confirm_go_clear_cb), NULL, NULL);

  /* VOID STRING STRING INT */
  dbus_g_object_register_marshaller(
      g_cclosure_user_marshal_VOID__STRING_STRING_INT, G_TYPE_NONE,
      G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INVALID);

  dbus_g_proxy_add_signal(callManagerProxy, "sipCallStateChanged",
      G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INVALID);
  dbus_g_proxy_connect_signal(callManagerProxy, "sipCallStateChanged",
      G_CALLBACK(sip_call_state_cb), NULL, NULL);

  configurationManagerProxy = dbus_g_proxy_new_for_name(connection,
      "org.sflphone.SFLphone", "/org/sflphone/SFLphone/ConfigurationManager",
      "org.sflphone.SFLphone.ConfigurationManager");

  /*
   configurationManagerProxy = dbus_g_proxy_new_for_name_owner (connection,
   "org.sflphone.SFLphone",
   "/org/sflphone/SFLphone/ConfigurationManager",
   "org.sflphone.SFLphone.ConfigurationManager",
   &error);
   */
  if (!configurationManagerProxy)
    {
      ERROR ("Failed to get proxy to ConfigurationManager");
      return FALSE;
    }
  DEBUG ("DBus connected to ConfigurationManager");
  dbus_g_proxy_add_signal(configurationManagerProxy, "accountsChanged",
      G_TYPE_INVALID);
  dbus_g_proxy_connect_signal(configurationManagerProxy, "accountsChanged",
      G_CALLBACK(accounts_changed_cb), NULL, NULL);

  dbus_g_object_register_marshaller(g_cclosure_user_marshal_VOID__INT,
      G_TYPE_NONE, G_TYPE_INT, G_TYPE_INVALID);
  dbus_g_proxy_add_signal(configurationManagerProxy, "errorAlert", G_TYPE_INT,
      G_TYPE_INVALID);
  dbus_g_proxy_connect_signal(configurationManagerProxy, "errorAlert",
      G_CALLBACK(error_alert), NULL, NULL);

  /* Defines a default timeout for the proxies */
657
#if HAVE_DBUS_G_PROXY_SET_DEFAULT_TIMEOUT
658
659
660
  dbus_g_proxy_set_default_timeout(callManagerProxy, DEFAULT_DBUS_TIMEOUT);
  dbus_g_proxy_set_default_timeout(instanceProxy, DEFAULT_DBUS_TIMEOUT);
  dbus_g_proxy_set_default_timeout(configurationManagerProxy, DEFAULT_DBUS_TIMEOUT);
661
#endif
662
663

  return TRUE;
664
665
}

666
667
void
dbus_clean()
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
668
{
669
670
671
  g_object_unref(callManagerProxy);
  g_object_unref(configurationManagerProxy);
  g_object_unref(instanceProxy);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
672
673
}

674
675
void
dbus_hold(const callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
676
{
677
  DEBUG("dbus_hold %s\n", c->_callID);
678

679
680
681
  GError *error = NULL;
  org_sflphone_SFLphone_CallManager_hold(callManagerProxy, c->_callID, &error);
  if (error)
682
    {
683
684
685
      ERROR ("Failed to call hold() on CallManager: %s",
          error->message);
      g_error_free(error);
686
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
687
688
}

689
690
void
dbus_unhold(const callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
691
{
692
  DEBUG("dbus_unhold %s\n", c->_callID);
693

694
695
696
  GError *error = NULL;
  org_sflphone_SFLphone_CallManager_unhold(callManagerProxy, c->_callID, &error);
  if (error)
697
    {
698
699
700
      ERROR ("Failed to call unhold() on CallManager: %s",
          error->message);
      g_error_free(error);
701
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
702
703
}

704
705
void
dbus_hold_conference(const conference_obj_t * c)
Alexandre Savard's avatar
Alexandre Savard committed
706
{
707
  DEBUG("dbus_hold_conference %s\n", c->_confID);
Alexandre Savard's avatar
Alexandre Savard committed
708

709
710
711
712
  GError *error = NULL;
  org_sflphone_SFLphone_CallManager_hold_conference(callManagerProxy,
      c->_confID, &error);
  if (error)
Alexandre Savard's avatar
Alexandre Savard committed
713
    {
714
715
716
      ERROR ("Failed to call hold() on CallManager: %s",
          error->message);
      g_error_free(error);
Alexandre Savard's avatar
Alexandre Savard committed
717
718
719
    }
}

720
721
void
dbus_unhold_conference(const conference_obj_t * c)
Alexandre Savard's avatar
Alexandre Savard committed
722
{
723
  DEBUG("dbus_unhold_conference %s\n", c->_confID);
Alexandre Savard's avatar
Alexandre Savard committed
724

725
726
727
728
  GError *error = NULL;
  org_sflphone_SFLphone_CallManager_unhold_conference(callManagerProxy,
      c->_confID, &error);
  if (error)
Alexandre Savard's avatar
Alexandre Savard committed
729
    {
730
731
732
      ERROR ("Failed to call unhold() on CallManager: %s",
          error->message);
      g_error_free(error);
Alexandre Savard's avatar
Alexandre Savard committed
733
734
735
    }
}

736
737
void
dbus_hang_up(const callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
738
{
739
740
741
742
743
744
  DEBUG("dbus_hang_up %s\n", c->_callID);

  GError *error = NULL;
  org_sflphone_SFLphone_CallManager_hang_up(callManagerProxy, c->_callID,
      &error);
  if (error)
745
    {
746
747
748
      ERROR ("Failed to call hang_up() on CallManager: %s",
          error->message);
      g_error_free(error);
749
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
750
751
}

752
753
void
dbus_hang_up_conference(const conference_obj_t * c)
Alexandre Savard's avatar
Alexandre Savard committed
754
{
755
756
757
758
759
760
  DEBUG("dbus_hang_up_conference %s\n", c->_confID);

  GError *error = NULL;
  org_sflphone_SFLphone_CallManager_hang_up_conference(callManagerProxy,
      c->_confID, &error);
  if (error)
Alexandre Savard's avatar
Alexandre Savard committed
761
    {
762
763
764
      ERROR ("Failed to call hang_up() on CallManager: %s",
          error->message);
      g_error_free(error);
Alexandre Savard's avatar
Alexandre Savard committed
765
766
767
    }
}

768
769
void
dbus_transfert(const callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
770
{
771
772
773
774
  GError *error = NULL;
  org_sflphone_SFLphone_CallManager_transfert(callManagerProxy, c->_callID,
      c->_trsft_to, &error);
  if (error)
775
    {
776
777
778
      ERROR ("Failed to call transfert() on CallManager: %s",
          error->message);
      g_error_free(error);
779
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
780
781
}

782
783
void
dbus_accept(const callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
784
{
785
#if GTK_CHECK_VERSION(2,10,0)
786
  status_tray_icon_blink(FALSE);
787
#endif
788

789
  DEBUG("dbus_accept %s\n", c->_callID);
790

791
792
793
  GError *error = NULL;
  org_sflphone_SFLphone_CallManager_accept(callManagerProxy, c->_callID, &error);
  if (error)
794
    {
795
796
797
      ERROR ("Failed to call accept(%s) on CallManager: %s", c->_callID,
          (error->message == NULL ? g_quark_to_string(error->domain): error->message));
      g_error_free(error);
798
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
799
800
}

801
802
void
dbus_refuse(const callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
803
{
804
#if GTK_CHECK_VERSION(2,10,0)
805
  status_tray_icon_blink(FALSE);
806
#endif
807

808
  DEBUG("dbus_refuse %s\n", c->_callID);
809

810
811
812
  GError *error = NULL;
  org_sflphone_SFLphone_CallManager_refuse(callManagerProxy, c->_callID, &error);
  if (error)
813
    {
814
815
816
      ERROR ("Failed to call refuse() on CallManager: %s",
          error->message);
      g_error_free(error);
817
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
818
819
}

820
821
void
dbus_place_call(const callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
822
{
823
  DEBUG("dbus_place_call %s\n", c->_callID);
824

825
826
827
828
  GError *error = NULL;
  org_sflphone_SFLphone_CallManager_place_call(callManagerProxy, c->_accountID,
      c->_callID, c->_peer_number, &error);
  if (error)
829
    {
830
831
832
      ERROR ("Failed to call placeCall() on CallManager: %s",
          error->message);
      g_error_free(error);
833
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
834
835
}

836
837
838
839
840
gchar**
dbus_account_list()
{
  GError *error = NULL;
  char ** array;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
841

842
843
  if (!org_sflphone_SFLphone_ConfigurationManager_get_account_list(
      configurationManagerProxy, &array, &error))
844
    {
845
846
      if (error->domain == DBUS_GERROR && error->code
          == DBUS_GERROR_REMOTE_EXCEPTION)
847
        {
848
          ERROR ("Caught remote method (get_account_list) exception  %s: %s", dbus_g_error_get_name(error), error->message);
849
        }
850
      else
851
        {
852
          ERROR("Error while calling get_account_list: %s", error->message);
853
        }
854
855
      g_error_free(error);
      return NULL;
856
    }
857
858
859
860
  else
    {
      DEBUG ("DBus called get_account_list() on ConfigurationManager");
      return array;
861
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
862
863
}

864
865
GHashTable*
dbus_account_details(gchar * accountID)
866
{
867
868
  GError *error = NULL;
  GHashTable * details;
Julien Bonjean's avatar
Julien Bonjean committed
869

870
871
  if (!org_sflphone_SFLphone_ConfigurationManager_get_account_details(
      configurationManagerProxy, accountID, &details, &error))
872
    {
873
874
      if (error->domain == DBUS_GERROR && error->code
          == DBUS_GERROR_REMOTE_EXCEPTION)
875
        {
876
          ERROR ("Caught remote method (get_account_details) exception  %s: %s", dbus_g_error_get_name(error), error->message);
877
        }
878
      else
879
        {
880
          ERROR("Error while calling get_account_details: %s", error->message);
881
        }
882
883
      g_error_free(error);
      return NULL;
884
    }
885
886
887
  else
    {
      return details;
888
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
889
890
}

891
void
892
893
dbus_set_credential(account_t *a, int index)
{
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
  DEBUG("Sending credential %d to server", index);
  GError *error = NULL;
  GHashTable * credential = g_ptr_array_index(a->credential_information, index);

  if (credential == NULL)
    {
      DEBUG("Credential %d was deleted", index);
    }
  else
    {
      org_sflphone_SFLphone_ConfigurationManager_set_credential(
          configurationManagerProxy, a->accountID, index, credential, &error);
    }

  if (error)
    {
      ERROR ("Failed to call set_credential() on ConfigurationManager: %s",
          error->message);
      g_error_free(error);
    }
}
void
dbus_set_number_of_credential(account_t *a, int number)
{
  DEBUG("Sending number of credential %d to server", number);
  GError *error = NULL;

  org_sflphone_SFLphone_ConfigurationManager_set_number_of_credential(
      configurationManagerProxy, a->accountID, number, &error);

  if (error)
    {
      ERROR ("Failed to call set_number_of_credential() on ConfigurationManager: %s",
          error->message);
      g_error_free(error);
    }
}
void
932
933
dbus_delete_all_credential(account_t *a)
{
934
935
936
937
938
939
940
941
942
943
944
945
  DEBUG("Deleting all credentials\n");
  GError *error = NULL;

  org_sflphone_SFLphone_ConfigurationManager_delete_all_credential(
      configurationManagerProxy, a->accountID, &error);

  if (error)
    {
      ERROR ("Failed to call deleteAllCredential on ConfigurationManager: %s",
          error->message);
      g_error_free(error);
    }
946
}
947

948
int
949
dbus_get_number_of_credential(gchar * accountID)
950
{
951
952
953
954
  GError *error = NULL;
  int number = 0;

  DEBUG("Getting number of credential for account %s", accountID);
955

956
957
958
959
960
961
962
  if (!org_sflphone_SFLphone_ConfigurationManager_get_number_of_credential(
      configurationManagerProxy, accountID, &number, &error))
    {
      if (error->domain == DBUS_GERROR && error->code
          == DBUS_GERROR_REMOTE_EXCEPTION)
        {
          ERROR ("Caught remote method (get_account_details) exception  %s: %s", dbus_g_error_get_name(error), error->message);
963
        }
964
965
966
      else
        {
          ERROR("Error while calling get_account_details: %s", error->message);
967
        }
968
969
970
971
972
973
974
      g_error_free(error);
      return 0;
    }
  else
    {
      DEBUG("%d credential(s) found for account %s", number, accountID);
      return number;
975
976
977
    }
}

978
979
GHashTable*
dbus_get_credential(gchar * accountID, int index)
980
{
981
982
  GError *error = NULL;
  GHashTable * details;
983

984
985
986
987
988
989
990
991
992
993
994
  if (!org_sflphone_SFLphone_ConfigurationManager_get_credential(
      configurationManagerProxy, accountID, index, &details, &error))
    {
      if (error->domain == DBUS_GERROR && error->code
          == DBUS_GERROR_REMOTE_EXCEPTION)
        {
          ERROR ("Caught remote method (get_account_details) exception  %s: %s", dbus_g_error_get_name(error), error->message);
        }
      else
        {
          ERROR("Error while calling get_account_details: %s", error->message);
995
        }
996
997
998
999
1000
      g_error_free(error);
      return NULL;
    }
  else
    {
For faster browsing, not all history is shown. View entire blame