dbus.c 58.7 KB
Newer Older
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
1
/*
2
 *  Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 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
 *  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.
20 21 22 23 24 25 26 27 28 29 30
 *
 *  Additional permission under GNU GPL version 3 section 7:
 *
 *  If you modify this program, or any covered work, by linking or
 *  combining it with the OpenSSL project's OpenSSL library (or a
 *  modified version of that library), containing parts covered by the
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 *  grants you additional permission to convey the resulting work.
 *  Corresponding Source for a non-source form of such a combination
 *  shall include the source code for the parts of OpenSSL used as well
 *  as that of the covered work.
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
31
 */
32
#include <config.h>
Julien Bonjean's avatar
Julien Bonjean committed
33

areversat's avatar
areversat committed
34
#include <calltab.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
35 36
#include <callmanager-glue.h>
#include <configurationmanager-glue.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
37
#include <instance-glue.h>
38 39
#include <preferencesdialog.h>
#include <accountlistconfigdialog.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
40
#include <mainwindow.h>
41
#include <marshaller.h>
42
#include <sliders.h>
43
#include <statusicon.h>
44
#include <assistant.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
45

46 47 48
#include <dbus.h>
#include <actions.h>
#include <string.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
49

50 51
#define DEFAULT_DBUS_TIMEOUT 30000

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
52 53 54
DBusGConnection * connection;
DBusGProxy * callManagerProxy;
DBusGProxy * configurationManagerProxy;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
55
DBusGProxy * instanceProxy;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
56

57 58 59
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
60
{
61
  DEBUG("Incoming call (%s) from %s", callID, from);
62

63 64 65 66 67
  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);
68

69 70
  DEBUG("    peer name: %s", peer_name);
  DEBUG("    peer number: %s", peer_number);
71

72 73
  create_new_call(CALL, CALL_STATE_INCOMING, g_strdup(callID), g_strdup(
      accountID), peer_name, peer_number, &c);
74
#if GTK_CHECK_VERSION(2,10,0)
75 76
  status_tray_icon_blink(TRUE);
  popup_main_window();
77
#endif
78

79 80 81
  set_timestamp(&c->_time_start);
  notify_incoming_call(c);
  sflphone_incoming_call(c);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
82 83
}

84 85 86
static void
zrtp_negotiation_failed_cb(DBusGProxy *proxy UNUSED, const gchar* callID,
    const gchar* reason, const gchar* severity, void * foo  UNUSED )
87
{
88 89 90 91 92 93 94
  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);
95
    }
96 97
}

98 99 100
static void
curent_selected_codec(DBusGProxy *proxy UNUSED, const gchar* callID,
    const gchar* codecName, void * foo  UNUSED )
Alexandre Savard's avatar
Alexandre Savard committed
101
{
102 103
  // DEBUG ("%s codec decided for call %s",codecName,callID);
  // sflphone_display_selected_codec (codecName);
Alexandre Savard's avatar
Alexandre Savard committed
104
}
105

106 107 108
static void
volume_changed_cb(DBusGProxy *proxy UNUSED, const gchar* device, const gdouble value,
    void * foo  UNUSED )
109
{
110 111
  DEBUG ("Volume of %s changed to %f.",device, value);
  set_slider(device, value);
112 113
}

114 115 116
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
117
{
118 119
  DEBUG ("%d Voice mail waiting!",nb);
  sflphone_notify_voice_mail(accountID, nb);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
120 121
}

122 123 124
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
125
{
126
  DEBUG ("Message %s!",msg);
Julien Bonjean's avatar
Julien Bonjean committed
127

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
128 129
}

130 131 132
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
133
{
134 135 136
  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
137
    {
138
      if (strcmp(state, "HUNGUP") == 0)
139
        {
140
          if (c->_state == CALL_STATE_CURRENT)
141
            {
142 143 144 145
              // 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);
146
            }
147
          stop_notification();
148
          calltree_update_call(history, c, NULL);
149
          status_bar_display_account();
150
	  sflphone_hung_up(c);
151
        }
152
      else if (strcmp(state, "UNHOLD_CURRENT") == 0)
153
        {
154
          sflphone_current(c);
155
        }
156
      else if (strcmp(state, "UNHOLD_RECORD") == 0)
157
        {
158
          sflphone_record(c);
159
        }
160
      else if (strcmp(state, "HOLD") == 0)
161
        {
162
          sflphone_hold(c);
163
        }
164
      else if (strcmp(state, "RINGING") == 0)
165
        {
166
          sflphone_ringing(c);
167
        }
168
      else if (strcmp(state, "CURRENT") == 0)
169
        {
170
          sflphone_current(c);
171
        }
172
      else if (strcmp(state, "FAILURE") == 0)
173
        {
174
          sflphone_fail(c);
175
        }
176
      else if (strcmp(state, "BUSY") == 0)
177
        {
178
          sflphone_busy(c);
179
        }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
180
    }
181
  else
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
182
    {
183 184 185 186
      // 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)
187
        {
188 189 190
          callable_obj_t *new_call;
          GHashTable *call_details;
          gchar *type;
191

192
          DEBUG ("New ringing call! accountID: %s", callID);
193

194 195 196
          // 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);
197

198 199 200
          // Restore the callID to be synchronous with the daemon
          new_call->_callID = g_strdup(callID);
          type = g_hash_table_lookup(call_details, "CALL_TYPE");
201

202
          if (g_strcasecmp(type, "0") == 0)
Emmanuel Milou's avatar
Emmanuel Milou committed
203
            {
204 205
              // DEBUG("incoming\n");
              new_call->_history_state = INCOMING;
Emmanuel Milou's avatar
Emmanuel Milou committed
206
            }
207
          else
Emmanuel Milou's avatar
Emmanuel Milou committed
208
            {
209 210
              // DEBUG("outgoing\n");
              new_call->_history_state = OUTGOING;
Emmanuel Milou's avatar
Emmanuel Milou committed
211 212
            }

213 214 215 216 217
          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
218

219
          //sflphone_incoming_call (new_call);
220
        }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
221
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
222 223
}

224
static void
225 226
conference_changed_cb(DBusGProxy *proxy UNUSED, const gchar* confID,
    const gchar* state, void * foo  UNUSED )
227
{
228

229 230 231 232 233 234
  // 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);
235

236
  if (changed_conf)
237
    {
238 239
      // remove old conference from calltree
      calltree_remove_conference(current_calls, changed_conf, NULL);
240

241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
      // 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");
        }
258

259
      participants = (gchar**) dbus_get_participant_list(changed_conf->_confID);
260

261 262 263 264 265
      // update conferece participants
      conference_participant_list_update(participants, changed_conf);

      // add new conference to calltree
      calltree_add_conference(current_calls, changed_conf);
266
    }
267 268 269
}

static void
270
conference_created_cb(DBusGProxy *proxy UNUSED, const gchar* confID, void * foo  UNUSED )
271
{
Alexandre Savard's avatar
Alexandre Savard committed
272
  DEBUG ("DBUS: Conference %s added", confID);
273

274 275 276 277 278
  conference_obj_t* new_conf;
  callable_obj_t* call;
  gchar* call_id;
  gchar** participants;
  gchar** part;
279

280
  create_new_conference(CONFERENCE_STATE_ACTIVE_ATACHED, confID, &new_conf);
281

282
  participants = (gchar**) dbus_get_participant_list(new_conf->_confID);
283

Alexandre Savard's avatar
Alexandre Savard committed
284
  // Update conference list
285
  conference_participant_list_update(participants, new_conf);
286

Alexandre Savard's avatar
Alexandre Savard committed
287 288
  // Add conference ID in in each calls
  for (part = participants; *part; part++) {
289 290 291
      call_id = (gchar*) (*part);
      call = calllist_get(current_calls, call_id);
      call->_confID = g_strdup(confID);
Alexandre Savard's avatar
Alexandre Savard committed
292
  }
293

294 295
  conferencelist_add(new_conf);
  calltree_add_conference(current_calls, new_conf);
296 297 298
}

static void
299
conference_removed_cb(DBusGProxy *proxy UNUSED, const gchar* confID, void * foo  UNUSED )
300
{
301
  DEBUG ("DBUS: Conference removed %s", confID);
302

303 304
  conference_obj_t * c = conferencelist_get(confID);
  calltree_remove_conference(current_calls, c, NULL);
305 306 307 308 309 310

  GSList *participant = c->participant_list;
  callable_obj_t *call;
  while(participant) {

      call = calllist_get(current_calls, (const gchar *)(participant->data));
311 312 313 314 315 316
      if(call) {
	DEBUG("DBUS: Remove participant %s", call->_callID);
	if(call->_confID){
	  g_free(call->_confID);
	  call->_confID = NULL;
	}
317 318 319 320
      }
      participant = conference_next_participant(participant);
  }
  
321
  conferencelist_remove(c->_confID);
322 323
}

324 325
static void
accounts_changed_cb(DBusGProxy *proxy UNUSED, void * foo  UNUSED )
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
326
{
327 328 329 330
  DEBUG ("Accounts changed");
  sflphone_fill_account_list();
  sflphone_fill_ip2ip_profile();
  account_list_config_dialog_fill();
331

332 333 334
  // Update the status bar in case something happened
  // Should fix ticket #1215
  status_bar_display_account();
335

336 337
  // Update the tooltip on the status icon
  statusicon_set_tooltip ();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
338 339
}

340 341
static void
transfer_succeded_cb(DBusGProxy *proxy UNUSED, void * foo  UNUSED )
342
{
343 344
  DEBUG ("Transfer succeded\n");
  sflphone_display_transfer_status("Transfer successfull");
345 346
}

347 348
static void
transfer_failed_cb(DBusGProxy *proxy UNUSED, void * foo  UNUSED )
349
{
350 351
  DEBUG ("Transfer failed\n");
  sflphone_display_transfer_status("Transfer failed");
352 353
}

354 355
static void
secure_sdes_on_cb(DBusGProxy *proxy UNUSED, const gchar *callID, void *foo UNUSED)
356
{
357 358 359 360 361 362
  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);
363 364 365 366 367
    }

}

static void
368
secure_sdes_off_cb(DBusGProxy *proxy UNUSED, const gchar *callID, void *foo UNUSED)
369
{
370 371 372 373 374 375
  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);
376 377 378
    }
}

379 380 381
static void
secure_zrtp_on_cb(DBusGProxy *proxy UNUSED, const gchar* callID, const gchar* cipher,
    void * foo  UNUSED )
382
{
383 384 385 386 387 388 389 390
  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);
391 392 393
    }
}

394 395
static void
secure_zrtp_off_cb(DBusGProxy *proxy UNUSED, const gchar* callID, void * foo  UNUSED )
396
{
397 398 399 400 401 402
  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);
403 404 405
    }
}

406 407 408
static void
show_zrtp_sas_cb(DBusGProxy *proxy UNUSED, const gchar* callID, const gchar* sas,
    const gboolean verified, void * foo  UNUSED )
409
{
410 411 412 413 414
  DEBUG ("Showing SAS");
  callable_obj_t * c = calllist_get(current_calls, callID);
  if (c)
    {
      sflphone_srtp_zrtp_show_sas(c, sas, verified);
415 416 417
    }
}

418 419
static void
confirm_go_clear_cb(DBusGProxy *proxy UNUSED, const gchar* callID, void * foo  UNUSED )
420
{
421 422 423 424 425
  DEBUG ("Confirm Go Clear request");
  callable_obj_t * c = calllist_get(current_calls, callID);
  if (c)
    {
      sflphone_confirm_go_clear(c);
426 427 428
    }
}

429 430
static void
zrtp_not_supported_cb(DBusGProxy *proxy UNUSED, const gchar* callID, void * foo  UNUSED )
431
{
432 433 434 435 436 437
  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);
438 439 440
    }
}

441 442 443
static void
sip_call_state_cb(DBusGProxy *proxy UNUSED, const gchar* callID,
    const gchar* description, const guint code, void * foo  UNUSED )
444
{
445 446
  callable_obj_t * c = NULL;
  c = calllist_get(current_calls, callID);
447

448 449 450 451
  if (c != NULL)
    {
      DEBUG("sip_call_state_cb received code %d", code);
      sflphone_call_state_changed(c, description, code);
452 453
    }
}
454

455 456
static void
error_alert(DBusGProxy *proxy UNUSED, int errCode, void * foo  UNUSED )
457
{
458 459
  ERROR ("Error notifying : (%i)", errCode);
  sflphone_throw_exception(errCode);
460 461
}

462 463 464
gboolean
dbus_connect()
{
Julien Bonjean's avatar
Julien Bonjean committed
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 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
  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 */
683
#if HAVE_DBUS_G_PROXY_SET_DEFAULT_TIMEOUT
684 685 686
  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);
687
#endif
688 689

  return TRUE;
690 691
}

692 693
void
dbus_clean()
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
694
{
695 696 697
  g_object_unref(callManagerProxy);
  g_object_unref(configurationManagerProxy);
  g_object_unref(instanceProxy);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
698 699
}

700 701
void
dbus_hold(const callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
702
{
703
  DEBUG("dbus_hold %s\n", c->_callID);
704

705 706 707
  GError *error = NULL;
  org_sflphone_SFLphone_CallManager_hold(callManagerProxy, c->_callID, &error);
  if (error)
708
    {
709 710 711
      ERROR ("Failed to call hold() on CallManager: %s",
          error->message);
      g_error_free(error);
712
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
713 714
}

715 716
void
dbus_unhold(const callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
717
{
718
  DEBUG("dbus_unhold %s\n", c->_callID);
719

720 721 722
  GError *error = NULL;
  org_sflphone_SFLphone_CallManager_unhold(callManagerProxy, c->_callID, &error);
  if (error)
723
    {
724 725 726
      ERROR ("Failed to call unhold() on CallManager: %s",
          error->message);
      g_error_free(error);
727
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
728 729
}

730 731
void
dbus_hold_conference(const conference_obj_t * c)
Alexandre Savard's avatar
Alexandre Savard committed
732
{
733
  DEBUG("dbus_hold_conference %s\n", c->_confID);
Alexandre Savard's avatar
Alexandre Savard committed
734

735 736 737 738
  GError *error = NULL;
  org_sflphone_SFLphone_CallManager_hold_conference(callManagerProxy,
      c->_confID, &error);
  if (error)
Alexandre Savard's avatar
Alexandre Savard committed
739
    {
740 741 742
      ERROR ("Failed to call hold() on CallManager: %s",
          error->message);
      g_error_free(error);
Alexandre Savard's avatar
Alexandre Savard committed
743 744 745
    }
}

746 747
void
dbus_unhold_conference(const conference_obj_t * c)
Alexandre Savard's avatar
Alexandre Savard committed
748
{
749
  DEBUG("dbus_unhold_conference %s\n", c->_confID);
Alexandre Savard's avatar
Alexandre Savard committed
750

751 752 753 754
  GError *error = NULL;
  org_sflphone_SFLphone_CallManager_unhold_conference(callManagerProxy,
      c->_confID, &error);
  if (error)
Alexandre Savard's avatar
Alexandre Savard committed
755
    {
756 757 758
      ERROR ("Failed to call unhold() on CallManager: %s",
          error->message);
      g_error_free(error);
Alexandre Savard's avatar
Alexandre Savard committed
759 760 761
    }
}

762 763
void
dbus_hang_up(const callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
764
{
765 766 767 768 769 770
  DEBUG("dbus_hang_up %s\n", c->_callID);

  GError *error = NULL;
  org_sflphone_SFLphone_CallManager_hang_up(callManagerProxy, c->_callID,
      &error);
  if (error)
771
    {
772 773 774
      ERROR ("Failed to call hang_up() on CallManager: %s",
          error->message);
      g_error_free(error);
775
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
776 777
}

778 779
void
dbus_hang_up_conference(const conference_obj_t * c)
Alexandre Savard's avatar
Alexandre Savard committed
780
{
781 782 783 784 785 786
  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
787
    {
788 789 790
      ERROR ("Failed to call hang_up() on CallManager: %s",
          error->message);
      g_error_free(error);
Alexandre Savard's avatar
Alexandre Savard committed
791 792 793
    }
}

794 795
void
dbus_transfert(const callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
796
{
797 798 799 800
  GError *error = NULL;
  org_sflphone_SFLphone_CallManager_transfert(callManagerProxy, c->_callID,
      c->_trsft_to, &error);
  if (error)
801
    {
802 803 804
      ERROR ("Failed to call transfert() on CallManager: %s",
          error->message);
      g_error_free(error);
805
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
806 807
}

808 809
void
dbus_accept(const callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
810
{
811
#if GTK_CHECK_VERSION(2,10,0)
812
  status_tray_icon_blink(FALSE);
813
#endif
814

815
  DEBUG("dbus_accept %s\n", c->_callID);
816

817 818 819
  GError *error = NULL;
  org_sflphone_SFLphone_CallManager_accept(callManagerProxy, c->_callID, &error);
  if (error)
820
    {
821 822 823
      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);
824
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
825 826
}

827 828
void
dbus_refuse(const callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
829
{
830
#if GTK_CHECK_VERSION(2,10,0)
831
  status_tray_icon_blink(FALSE);
832
#endif
833

834
  DEBUG("dbus_refuse %s\n", c->_callID);
835

836 837 838
  GError *error = NULL;
  org_sflphone_SFLphone_CallManager_refuse(callManagerProxy, c->_callID, &error);
  if (error)
839
    {
840 841 842
      ERROR ("Failed to call refuse() on CallManager: %s",
          error->message);
      g_error_free(error);
843
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
844 845
}

846 847
void
dbus_place_call(const callable_obj_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
848
{
849
  DEBUG("dbus_place_call %s\n", c->_callID);
850

851 852 853 854
  GError *error = NULL;
  org_sflphone_SFLphone_CallManager_place_call(callManagerProxy, c->_accountID,
      c->_callID, c->_peer_number, &error);
  if (error)
855
    {
856 857 858
      ERROR ("Failed to call placeCall() on CallManager: %s",
          error->message);
      g_error_free(error);
859
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
860 861
}

862 863 864 865 866
gchar**
dbus_account_list()
{
  GError *error = NULL;
  char ** array;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
867

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

890 891
GHashTable*
dbus_account_details(gchar * accountID)
892
{
893 894
  GError *error = NULL;
  GHashTable * details;
Julien Bonjean's avatar
Julien Bonjean committed
895

896 897
  DEBUG("Dbus: Get account detail accountid %s", accountID);

898 899
  if (!org_sflphone_SFLphone_ConfigurationManager_get_account_details(
      configurationManagerProxy, accountID, &details, &error))
900
    {
901 902
      if (error->domain == DBUS_GERROR && error->code
          == DBUS_GERROR_REMOTE_EXCEPTION)
903
        {
904
          ERROR ("Caught remote method (get_account_details) exception  %s: %s", dbus_g_error_get_name(error), error->message);
905
        }
906
      else
907
        {
908
          ERROR("Error while calling get_account_details: %s", error->message);
909
        }
910 911
      g_error_free(error);
      return NULL;
912
    }
913 914 915
  else
    {
      return details;
916
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
917 918
}

919
void
920 921
dbus_set_credential(account_t *a, int index)
{
922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959
  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
960 961
dbus_delete_all_credential(account_t *a)
{
962 963 964 965 966 967 968 969 970 971 972 973
  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);
    }
974
}
975

976
int
977
dbus_get_number_of_credential(gchar * accountID)
978
{
979 980 981 982
  GError *error = NULL;
  int number = 0;

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

984 985 986 987 988 989 990
  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);
991
        }
992