dbus.c 68.8 KB
Newer Older
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
1
/*
2
 *  Copyright (C) 2004-2013 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
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty f
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
14 15
 *  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
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
19
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 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
#ifdef HAVE_CONFIG_H
33
#include "config.h"
34
#endif
Alexandre Savard's avatar
Alexandre Savard committed
35

36
#include <glib/gi18n.h>
37
#include "str_utils.h"
38 39 40
#include "calltab.h"
#include "callmanager-glue.h"
#include "configurationmanager-glue.h"
41
#ifdef SFL_VIDEO
42
#include "videomanager-glue.h"
43
#endif
44 45 46 47 48 49 50
#include "instance-glue.h"
#include "preferencesdialog.h"
#include "mainwindow.h"
#include "marshaller.h"
#include "sliders.h"
#include "statusicon.h"
#include "assistant.h"
51
#include "accountlist.h"
52
#include "accountlistconfigdialog.h"
53
#include "accountconfigdialog.h"
Emmanuel Lepage's avatar
Emmanuel Lepage committed
54
#include "messaging/message_tab.h"
55
#include "ring_client.h"
56 57
#include "dbus.h"
#include "actions.h"
58

59
#include "presence.h"
60 61
#include "presencemanager-glue.h"
#include "presencewindow.h"
Alexandre Savard's avatar
Alexandre Savard committed
62

63
#ifdef SFL_VIDEO
Rafaël Carré's avatar
Rafaël Carré committed
64
#include "config/videoconf.h"
65
#include "video/video_callbacks.h"
66
#endif
67
#include "account_schema.h"
68
#include "mainwindow.h"
69

70
#ifdef SFL_VIDEO
Tristan Matthews's avatar
Tristan Matthews committed
71
static DBusGProxy *video_proxy;
72
#endif
Tristan Matthews's avatar
Tristan Matthews committed
73 74 75
static DBusGProxy *call_proxy;
static DBusGProxy *config_proxy;
static DBusGProxy *instance_proxy;
76
static DBusGProxy *presence_proxy;
77
static GDBusProxy *session_manager_proxy;
78 79

/* Returns TRUE if there was an error, FALSE otherwise */
80
static gboolean check_error(GError *error)
81 82
{
    if (error) {
83
        g_warning("%s", error->message);
84 85
        if (g_error_matches(error, DBUS_GERROR, DBUS_GERROR_SERVICE_UNKNOWN)) {
            g_error_free(error);
86
            g_warning("daemon crashed, quitting rudely...");
87 88
            exit(EXIT_FAILURE);
        }
89 90 91 92 93
        g_error_free(error);
        return TRUE;
    }
    return FALSE;
}
94

95
static void
96
new_call_created_cb(G_GNUC_UNUSED DBusGProxy *proxy, const gchar *accountID,
97
                    const gchar *callID, const gchar *to, SFLPhoneClient *client)
98
{
Tristan Matthews's avatar
Tristan Matthews committed
99 100
    callable_obj_t *c = create_new_call(CALL, CALL_STATE_RINGING, callID,
                                        accountID, to, to);
101

Tristan Matthews's avatar
Tristan Matthews committed
102 103
    calllist_add_call(current_calls_tab, c);
    calltree_add_call(current_calls_tab, c, NULL);
104

105 106
    update_actions(client);
    calltree_display(current_calls_tab, client);
107 108
}

109
static void
110
incoming_call_cb(G_GNUC_UNUSED DBusGProxy *proxy, const gchar *accountID,
111
                 const gchar *callID, const gchar *from, SFLPhoneClient *client)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
112
{
113
    // We receive the from field under a formatted way. We want to extract the number and the name of the caller
114
    gchar *display_name = call_get_display_name(from);
115
    gchar *peer_number = call_get_peer_number(from);
116

Tristan Matthews's avatar
Tristan Matthews committed
117 118
    callable_obj_t *c = create_new_call(CALL, CALL_STATE_INCOMING, callID,
                                        accountID, display_name, peer_number);
119

120
    g_free(peer_number);
121
    g_free(display_name);
122

123
    /* Legacy system tray option, requires TopIcons GNOME extension */
124
    status_tray_icon_blink(TRUE);
125 126
    if (g_settings_get_boolean(client->settings, "popup-main-window"))
        popup_main_window(client);
127

128 129 130
    if (g_settings_get_boolean(client->settings, "bring-window-to-front"))
        main_window_bring_to_front(client, c->_time_start);

131 132
    notify_incoming_call(c, client);
    sflphone_incoming_call(c, client);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
133 134
}

135
static void
136
zrtp_negotiation_failed_cb(G_GNUC_UNUSED DBusGProxy *proxy, const gchar *callID,
137
                           const gchar *reason, const gchar *severity,
138
                           SFLPhoneClient *client)
139
{
140
    main_window_zrtp_negotiation_failed(callID, reason, severity, client);
Tristan Matthews's avatar
Tristan Matthews committed
141
    callable_obj_t *c = calllist_get_call(current_calls_tab, callID);
142

Rafaël Carré's avatar
Rafaël Carré committed
143
    if (c)
144
        notify_zrtp_negotiation_failed(c, client);
Alexandre Savard's avatar
Alexandre Savard committed
145
}
146

147
static void
148 149
volume_changed_cb(G_GNUC_UNUSED DBusGProxy *proxy, const gchar *device, gdouble value,
                  G_GNUC_UNUSED gpointer foo)
150
{
151
    set_slider_no_update(device, value);
152 153
}

154
static void
155
voice_mail_cb(G_GNUC_UNUSED DBusGProxy *proxy, const gchar *accountID, guint nb,
156
              SFLPhoneClient *client)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
157
{
158
    sflphone_notify_voice_mail(accountID, nb, client);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
159 160
}

161
static void
162 163
incoming_message_cb(G_GNUC_UNUSED DBusGProxy *proxy, const G_GNUC_UNUSED gchar *callID,
                    const G_GNUC_UNUSED gchar *from, const gchar *msg, SFLPhoneClient *client)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
164
{
165
    // do not display message if instant messaging is disabled
166
    if (!g_settings_get_boolean(client->settings, "instant-messaging-enabled"))
167 168
        return;

Tristan Matthews's avatar
Tristan Matthews committed
169
    callable_obj_t *call = calllist_get_call(current_calls_tab, callID);
170

171
    if (call) {
172
        new_text_message(call, msg, client);
173
    } else {
Tristan Matthews's avatar
Tristan Matthews committed
174
        conference_obj_t *conf = conferencelist_get(current_calls_tab, callID);
Rafaël Carré's avatar
Rafaël Carré committed
175
        if (!conf) {
176
            g_warning("Message received, but no recipient found");
Rafaël Carré's avatar
Rafaël Carré committed
177 178
            return;
        }
179

180
        new_text_message_conf(conf, msg, from, client);
181
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
182 183
}

184 185 186
/**
 * Perform the right sflphone action based on the requested state
 */
Tristan Matthews's avatar
Tristan Matthews committed
187
static void
188
process_existing_call_state_change(callable_obj_t *c, const gchar *state, SFLPhoneClient *client)
189
{
190
    if (c == NULL) {
191
        g_warning("Pointer to call is NULL in %s\n", __func__);
192
        return;
Tristan Matthews's avatar
Tristan Matthews committed
193
    } else if (state == NULL) {
194
        g_warning("Pointer to state is NULL in %s\n", __func__);
195 196
        return;
    }
197

198
    if (g_strcmp0(state, "HUNGUP") == 0) {
199
        if (c->_state == CALL_STATE_CURRENT)
200
            time(&c->_time_stop);
201

202
        calltree_update_call(history_tab, c, client);
203
        status_bar_display_account();
204
        sflphone_hung_up(c, client);
205
    } else if (g_strcmp0(state, "UNHOLD") == 0 || g_strcmp0(state, "CURRENT") == 0)
206
        sflphone_current(c, client);
207
    else if (g_strcmp0(state, "HOLD") == 0)
208
        sflphone_hold(c, client);
209
    else if (g_strcmp0(state, "RINGING") == 0)
210
        sflphone_ringing(c, client);
211
    else if (g_strcmp0(state, "FAILURE") == 0)
212
        sflphone_fail(c, client);
213
    else if (g_strcmp0(state, "BUSY") == 0)
214
        sflphone_busy(c, client);
215
}
216 217


218
/**
219
 * This function process call state changes in case the call have not been created yet.
220
 * This mainly occurs when another SFLphone client takes actions.
221
 */
222
static void
223
process_nonexisting_call_state_change(const gchar *callID, const gchar *state, SFLPhoneClient *client)
224
{
225
    if (callID == NULL) {
226
        g_warning("Pointer to call id is NULL in %s\n", __func__);
227
        return;
Tristan Matthews's avatar
Tristan Matthews committed
228
    } else if (state == NULL) {
229
        g_warning("Pointer to state is NULL in %s\n", __func__);
230
        return;
Tristan Matthews's avatar
Tristan Matthews committed
231 232
    } else if (g_strcmp0(state, "HUNGUP") == 0)
        return; // Could occur if a user picked up the phone and hung up without making a call
233

234
    // The callID is unknown, treat it like a new call
235 236
    // 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)
237
    if (g_strcmp0(state, "RINGING") == 0 || g_strcmp0(state, "CURRENT") == 0) {
Alexandre Savard's avatar
Alexandre Savard committed
238

239
        g_debug("New ringing call! accountID: %s", callID);
Alexandre Savard's avatar
Alexandre Savard committed
240

241 242 243 244
        restore_call(callID);
        callable_obj_t *new_call = calllist_get_call(current_calls_tab, callID);
        if (new_call)
            calltree_add_call(current_calls_tab, new_call, NULL);
245 246
        update_actions(client);
        calltree_display(current_calls_tab, client);
247 248 249 250
    }
}

static void
251
call_state_cb(G_GNUC_UNUSED DBusGProxy *proxy, const gchar *callID,
252
              const gchar *state, SFLPhoneClient *client)
253 254 255
{
    callable_obj_t *c = calllist_get_call(current_calls_tab, callID);

256
    if (c)
257
        process_existing_call_state_change(c, state, client);
258
    else {
259
        g_warning("Call does not exist");
260
        process_nonexisting_call_state_change(callID, state, client);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
261
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
262 263
}

Tristan Matthews's avatar
Tristan Matthews committed
264
static void
265
toggle_im(conference_obj_t *conf, G_GNUC_UNUSED gboolean activate)
Rafaël Carré's avatar
Rafaël Carré committed
266
{
267
    for (GSList *p = conf->participant_list; p; p = g_slist_next(p)) {
268
        //callable_obj_t *call = calllist_get_call(current_calls_tab, p->data);
269

270
        /*TODO elepage(2012) Implement IM messaging toggle here*/
Rafaël Carré's avatar
Rafaël Carré committed
271 272 273
    }
}

274
static void
275
conference_changed_cb(G_GNUC_UNUSED DBusGProxy *proxy, const gchar *confID,
276
                      const gchar *state, SFLPhoneClient *client)
277
{
278
    g_debug("Conference state changed: %s\n", state);
279 280

    conference_obj_t* changed_conf = conferencelist_get(current_calls_tab, confID);
281
    if (changed_conf == NULL) {
282
        g_warning("Conference is NULL in conference state changed");
283
        return;
284
    }
285

286
    // remove old conference from calltree
287
    calltree_remove_conference(current_calls_tab, changed_conf, client);
288 289

    // update conference state
290
    if (g_strcmp0(state, "ACTIVE_ATTACHED") == 0)
291
        changed_conf->_state = CONFERENCE_STATE_ACTIVE_ATTACHED;
292
    else if (g_strcmp0(state, "ACTIVE_DETACHED") == 0)
293
        changed_conf->_state = CONFERENCE_STATE_ACTIVE_DETACHED;
294
    else if (g_strcmp0(state, "ACTIVE_ATTACHED_REC") == 0)
295
        changed_conf->_state = CONFERENCE_STATE_ACTIVE_ATTACHED_RECORD;
296
    else if (g_strcmp0(state, "ACTIVE_DETACHED_REC") == 0)
297
        changed_conf->_state = CONFERENCE_STATE_ACTIVE_DETACHED_RECORD;
298
    else if (g_strcmp0(state, "HOLD") == 0)
299
        changed_conf->_state = CONFERENCE_STATE_HOLD;
300
    else if (g_strcmp0(state, "HOLD_REC") == 0)
301
        changed_conf->_state = CONFERENCE_STATE_HOLD_RECORD;
302
    else
303
        g_debug("Error: conference state not recognized");
304

305
    // reactivate instant messaging window for these calls
Rafaël Carré's avatar
Rafaël Carré committed
306
    toggle_im(changed_conf, TRUE);
307

Rafaël Carré's avatar
Rafaël Carré committed
308 309 310
    gchar **list = dbus_get_participant_list(changed_conf->_confID);
    conference_participant_list_update(list, changed_conf);
    g_strfreev(list);
311

312
    // deactivate instant messaging window for new participants
Rafaël Carré's avatar
Rafaël Carré committed
313
    toggle_im(changed_conf, FALSE);
314
    calltree_add_conference_to_current_calls(changed_conf, client);
315 316 317
}

static void
318
conference_created_cb(G_GNUC_UNUSED DBusGProxy *proxy, const gchar *confID, SFLPhoneClient *client)
319
{
320
    g_debug("Conference %s added", confID);
321

322
    conference_obj_t *new_conf = create_new_conference(CONFERENCE_STATE_ACTIVE_ATTACHED, confID);
323

324
    gchar **participants = dbus_get_participant_list(new_conf->_confID);
325

326
    // Update conference list
327
    conference_participant_list_update(participants, new_conf);
328

329
    // Add conference ID in in each calls
330 331 332
    for (gchar **part = participants; part && *part; ++part) {
        callable_obj_t *call = calllist_get_call(current_calls_tab, *part);

333
        /*TODO elepage (2012) implement merging IM conversation here*/
334

Tristan Matthews's avatar
Tristan Matthews committed
335
        // if one of these participants is currently recording, the whole conference will be recorded
336
        if (dbus_get_is_recording(call))
337
            new_conf->_state = CONFERENCE_STATE_ACTIVE_ATTACHED_RECORD;
338

339
        call->_historyConfID = g_strdup(confID);
340 341
    }

Rafaël Carré's avatar
Rafaël Carré committed
342 343
    g_strfreev(participants);

344
    time(&new_conf->_time_start);
345

Tristan Matthews's avatar
Tristan Matthews committed
346
    conferencelist_add(current_calls_tab, new_conf);
347
    calltree_add_conference_to_current_calls(new_conf, client);
348 349 350
}

static void
351
conference_removed_cb(G_GNUC_UNUSED DBusGProxy *proxy, const gchar *confID,
352
                      SFLPhoneClient *client)
353
{
354
    g_debug("Conference removed %s", confID);
Tristan Matthews's avatar
Tristan Matthews committed
355
    conference_obj_t *c = conferencelist_get(current_calls_tab, confID);
356
    if(c == NULL) {
357
        g_warning("Could not find conference %s from list", confID);
358 359 360
        return;
    }

361
    calltree_remove_conference(current_calls_tab, c, client);
362

363
    /*TODO elepage(2012) implement unmerging of IM here*/
364

365
    // remove all participants for this conference
366
    for (GSList *p = c->participant_list; p; p = g_slist_next(p)) {
367
        //callable_obj_t *call = calllist_get_call(current_calls_tab, p->data);
Emmanuel Lepage's avatar
Emmanuel Lepage committed
368
        /*TODO elepage(2012) implement unmerging of IM here*/
369
    }
370

Tristan Matthews's avatar
Tristan Matthews committed
371
    conferencelist_remove(current_calls_tab, c->_confID);
372 373
}

374
static void
375
record_playback_filepath_cb(G_GNUC_UNUSED DBusGProxy *proxy, const gchar *id,
Tristan Matthews's avatar
Tristan Matthews committed
376
                            const gchar *filepath)
377
{
378
    g_debug("Filepath for %s: %s", id, filepath);
Tristan Matthews's avatar
Tristan Matthews committed
379 380
    callable_obj_t *call = calllist_get_call(current_calls_tab, id);
    conference_obj_t *conf = conferencelist_get(current_calls_tab, id);
381

Tristan Matthews's avatar
Tristan Matthews committed
382
    if (call && conf) {
383
        g_warning("Two objects for this callid");
Tristan Matthews's avatar
Tristan Matthews committed
384
        return;
385 386
    }

Tristan Matthews's avatar
Tristan Matthews committed
387
    if (!call && !conf) {
388
        g_warning("Could not get object");
Tristan Matthews's avatar
Tristan Matthews committed
389
        return;
390
    }
Tristan Matthews's avatar
Tristan Matthews committed
391

392
    if (call && call->_recordfile == NULL)
Tristan Matthews's avatar
Tristan Matthews committed
393
        call->_recordfile = g_strdup(filepath);
394
    else if (conf && conf->_recordfile == NULL)
Tristan Matthews's avatar
Tristan Matthews committed
395
        conf->_recordfile = g_strdup(filepath);
396 397
}

398
static void
399
record_playback_stopped_cb(G_GNUC_UNUSED DBusGProxy *proxy, const gchar *filepath, SFLPhoneClient *client)
400
{
401
    g_debug("Playback stopped for %s", filepath);
Tristan Matthews's avatar
Tristan Matthews committed
402
    const gint calllist_size = calllist_get_size(history_tab);
403

404 405
    for (gint i = 0; i < calllist_size; i++) {
        callable_obj_t *call = calllist_get_nth(history_tab, i);
406

407
        if (call == NULL) {
408
            g_warning("Could not find %dth call", i);
409
            break;
410
        }
411 412
        if (g_strcmp0(call->_recordfile, filepath) == 0)
            call->_record_is_playing = FALSE;
413 414
    }

415
    update_actions(client);
416
}
417

418
static void
419 420
update_playback_scale_cb(G_GNUC_UNUSED DBusGProxy *proxy,
        const gchar *file_path, guint position, guint size)
421
{
422 423
    if (!main_window_update_playback_scale(file_path, position, size))
        update_ringtone_slider(position, size);
424 425
}

426
static void
427 428
registration_state_changed_cb(G_GNUC_UNUSED DBusGProxy *proxy, const gchar *accountID,
                              guint state, G_GNUC_UNUSED void *foo)
429
{
430
    g_debug("DBus: Registration state changed to %s for account %s",
431 432
          account_state_name(state), accountID);
    account_t *acc = account_list_get_by_id(accountID);
433
    if (acc) {
434
        acc->state = state;
435
        update_account_list_status_bar(acc);
436
        status_bar_display_account();
437
    }
438 439
}

440
static void
441
accounts_changed_cb(G_GNUC_UNUSED DBusGProxy *proxy, G_GNUC_UNUSED void *foo)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
442
{
443
    g_debug("Account details changed.");
444 445
    sflphone_fill_account_list();
    sflphone_fill_ip2ip_profile();
446 447

    // ui updates
448 449
    status_bar_display_account();
    statusicon_set_tooltip();
450
    update_presence_statusbar();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
451 452
}

453
static void
454
stun_status_failure_cb(G_GNUC_UNUSED DBusGProxy *proxy, const gchar *accountID, G_GNUC_UNUSED void *foo)
455
{
456
    g_warning("Error: Stun status failure: account %s failed to setup STUN",
457 458 459 460
          accountID);
    // Disable STUN for the account that tried to create the STUN transport
    account_t *account = account_list_get_by_id(accountID);
    if (account) {
461
        account_replace(account, CONFIG_STUN_ENABLE, "false");
462 463
        dbus_set_account_details(account);
    }
464 465 466
}

static void
467
stun_status_success_cb(G_GNUC_UNUSED DBusGProxy *proxy, G_GNUC_UNUSED const gchar *message, G_GNUC_UNUSED void *foo)
468
{
469
    g_debug("STUN setup successful");
470 471
}

472
static void
473
transfer_succeeded_cb(G_GNUC_UNUSED DBusGProxy *proxy, G_GNUC_UNUSED void *foo)
474
{
475
    sflphone_display_transfer_status("Transfer successful");
476 477
}

478
static void
479
transfer_failed_cb(G_GNUC_UNUSED DBusGProxy *proxy, G_GNUC_UNUSED void *foo)
480
{
481
    sflphone_display_transfer_status("Transfer failed");
482 483
}

484
static void
485
secure_sdes_on_cb(G_GNUC_UNUSED DBusGProxy *proxy, const gchar *callID, SFLPhoneClient *client)
486
{
487
    g_debug("SRTP using SDES is on");
Tristan Matthews's avatar
Tristan Matthews committed
488
    callable_obj_t *c = calllist_get_call(current_calls_tab, callID);
489

490
    if (c) {
491 492
        sflphone_srtp_sdes_on(c, client);
        notify_secure_on(c, client);
493 494 495 496
    }
}

static void
497
secure_sdes_off_cb(G_GNUC_UNUSED DBusGProxy *proxy, const gchar *callID, SFLPhoneClient *client)
498
{
499
    g_debug("SRTP using SDES is off");
Tristan Matthews's avatar
Tristan Matthews committed
500
    callable_obj_t *c = calllist_get_call(current_calls_tab, callID);
501

502
    if (c) {
503 504
        sflphone_srtp_sdes_off(c, client);
        notify_secure_off(c, client);
505 506 507
    }
}

508
static void
509
secure_zrtp_on_cb(G_GNUC_UNUSED DBusGProxy *proxy, const gchar *callID,
510
                  const gchar *cipher, SFLPhoneClient *client)
511
{
512
    g_debug("SRTP using ZRTP is ON with cipher %s", cipher);
Tristan Matthews's avatar
Tristan Matthews committed
513
    callable_obj_t *c = calllist_get_call(current_calls_tab, callID);
514

515
    if (c) {
516 517
        sflphone_srtp_zrtp_on(c, client);
        notify_secure_on(c, client);
518 519 520
    }
}

521
static void
522
secure_zrtp_off_cb(G_GNUC_UNUSED DBusGProxy *proxy, const gchar *callID, SFLPhoneClient *client)
523
{
524
    g_debug("SRTP using ZRTP is OFF");
Tristan Matthews's avatar
Tristan Matthews committed
525
    callable_obj_t *c = calllist_get_call(current_calls_tab, callID);
526

527
    if (c) {
528 529
        sflphone_srtp_zrtp_off(c, client);
        notify_secure_off(c, client);
530 531 532
    }
}

533
static void
534
show_zrtp_sas_cb(G_GNUC_UNUSED DBusGProxy *proxy, const gchar *callID, const gchar *sas,
535
                 gboolean verified, SFLPhoneClient *client)
536
{
537
    g_debug("Showing SAS");
538
    callable_obj_t *c = calllist_get_call(current_calls_tab, callID);
539

Tristan Matthews's avatar
Tristan Matthews committed
540
    if (c)
541
        sflphone_srtp_zrtp_show_sas(c, sas, verified, client);
542 543
}

544
static void
545
confirm_go_clear_cb(G_GNUC_UNUSED DBusGProxy *proxy, const gchar *callID, SFLPhoneClient *client)
546
{
547
    g_debug("Confirm Go Clear request");
548
    callable_obj_t *c = calllist_get_call(current_calls_tab, callID);
549

550
    if (c)
551
        main_window_confirm_go_clear(c, client);
552 553
}

554
static void
555
zrtp_not_supported_cb(G_GNUC_UNUSED DBusGProxy *proxy, const gchar *callID, SFLPhoneClient *client)
556
{
557
    g_debug("ZRTP not supported on the other end");
558
    callable_obj_t *c = calllist_get_call(current_calls_tab, callID);
559

560
    if (c) {
561 562
        main_window_zrtp_not_supported(c, client);
        notify_zrtp_not_supported(c, client);
563 564 565
    }
}

Tristan Matthews's avatar
Tristan Matthews committed
566 567 568 569 570 571 572 573 574

#ifdef RTCP_DEBUG
static void
print_rtcp_stats(const gchar *key, gint value, G_GNUC_UNUSED gpointer data)
{
    g_debug("%s: %d", key, value);
}
#endif

575
static void
576 577 578 579
on_rtcp_report_received_cb(G_GNUC_UNUSED DBusGProxy *proxy,
        const gchar *callID,
        G_GNUC_UNUSED const GHashTable *stats,
        G_GNUC_UNUSED SFLPhoneClient *client)
580 581
{
    g_debug("Daemon notification of new RTCP report for %s", callID);
Tristan Matthews's avatar
Tristan Matthews committed
582 583 584
#ifdef RTCP_DEBUG
    g_hash_table_foreach(stats, print_rtcp_stats, NULL);
#endif
585 586
}

587
static void
588
sip_call_state_cb(G_GNUC_UNUSED DBusGProxy *proxy, const gchar *callID,
589
                  const gchar *description, guint code, SFLPhoneClient *client)
590
{
591
    g_debug("Sip call state changed %s", callID);
Tristan Matthews's avatar
Tristan Matthews committed
592
    callable_obj_t *c = calllist_get_call(current_calls_tab, callID);
593

Rafaël Carré's avatar
Rafaël Carré committed
594
    if (c)
595
        sflphone_call_state_changed(c, description, code, client);
596
}
597

598
static void
599
error_alert(G_GNUC_UNUSED DBusGProxy *proxy, int err, G_GNUC_UNUSED void *foo)
600
{
601
    const gchar *msg;
602

Rafaël Carré's avatar
Rafaël Carré committed
603 604
    switch (err) {
        case ALSA_PLAYBACK_DEVICE:
605
            msg = _("ALSA notification: Error while opening playback device");
Rafaël Carré's avatar
Rafaël Carré committed
606 607
            break;
        case ALSA_CAPTURE_DEVICE:
Tristan Matthews's avatar