managerimpl.cpp 81.7 KB
Newer Older
jpbl's avatar
jpbl committed
1
/*
2
 *  Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
3
 *  Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com>
jpbl's avatar
jpbl committed
4
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
5
 *  Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com>
6
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
7
 *  Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
8
 *  Author: Guillaume Carmel-Archambault <guillaume.carmel-archambault@savoirfairelinux.com>
jpbl's avatar
jpbl committed
9
10
 *  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
11
 *  the Free Software Foundation; either version 3 of the License, or
jpbl's avatar
jpbl committed
12
 *  (at your option) any later version.
13
 *
jpbl's avatar
jpbl committed
14
15
16
17
 *  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.
18
 *
jpbl's avatar
jpbl committed
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
21
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
22
23
24
25
26
27
28
29
30
31
32
 *
 *  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.
jpbl's avatar
jpbl committed
33
34
 */

35
#ifdef HAVE_CONFIG_H
36
#include "config.h"
37
#endif
38

39
#include "logger.h"
40
#include "managerimpl.h"
41
#include "account_schema.h"
42
43

#include "dbus/callmanager.h"
44
#include "global.h"
45
#include "fileutils.h"
46
#include "map_utils.h"
47
#include "sip/sipvoiplink.h"
48
#include "sip/sipaccount.h"
49
#include "sip/sipcall.h"
50
#include "im/instant_messaging.h"
51
52

#if HAVE_IAX
53
#include "iax/iaxaccount.h"
54
#include "iax/iaxcall.h"
55
56
57
#include "iax/iaxvoiplink.h"
#endif

58
#include "numbercleaner.h"
59
60
#include "config/yamlparser.h"
#include "config/yamlemitter.h"
61
62
#include "audio/alsa/alsalayer.h"
#include "audio/sound/tonelist.h"
63
64
#include "audio/sound/audiofile.h"
#include "audio/sound/dtmf.h"
65
#include "history/historynamecache.h"
66
#include "manager.h"
67

68
#include "dbus/configurationmanager.h"
69
70
71
#ifdef SFL_VIDEO
#include "dbus/video_controls.h"
#endif
72

73
#include "conference.h"
74
#include "scoped_lock.h"
75

76
#include <cerrno>
77
#include <algorithm>
78
#include <ctime>
jpbl's avatar
jpbl committed
79
80
#include <cstdlib>
#include <iostream>
81
#include <tr1/functional>
Tristan Matthews's avatar
cleanup    
Tristan Matthews committed
82
#include <iterator>
jpbl's avatar
jpbl committed
83
#include <fstream>
84
#include <sstream>
jpbl's avatar
jpbl committed
85
#include <sys/types.h> // mkdir(2)
86
#include <sys/stat.h>  // mkdir(2)
87

88
ManagerImpl::ManagerImpl() :
89
    preferences(), voipPreferences(),
90
    hookPreference(),  audioPreference(), shortcutPreferences(),
91
    hasTriedToRegister_(false), audioCodecFactory(), dbus_(), config_(),
92
93
    currentCallId_(), currentCallMutex_(), audiodriver_(0), dtmfKey_(),
    toneMutex_(), telephoneTone_(), audiofile_(), audioLayerMutex_(),
94
    waitingCalls_(), waitingCallsMutex_(), path_(),
95
    IPToIPMap_(), mainBuffer_(), conferenceMap_(), history_(), finished_(false)
Emmanuel Milou's avatar
[#2402]    
Emmanuel Milou committed
96
{
97
98
99
    pthread_mutex_init(&currentCallMutex_, NULL);
    pthread_mutex_init(&toneMutex_, NULL);
    pthread_mutex_init(&audioLayerMutex_, NULL);
100
    pthread_mutex_init(&waitingCallsMutex_, NULL);
101
    // initialize random generator for call id
102
    srand(time(NULL));
jpbl's avatar
jpbl committed
103
104
}

105
106
107
ManagerImpl::~ManagerImpl()
{
    // destroy in reverse order of initialization
108
    pthread_mutex_destroy(&waitingCallsMutex_);
109
110
111
112
113
    pthread_mutex_destroy(&audioLayerMutex_);
    pthread_mutex_destroy(&toneMutex_);
    pthread_mutex_destroy(&currentCallMutex_);
}

114
115
116
117
118
119
120
121
122
123
124
125
126
127
namespace {
    // Creates a backup of the file at "path" with a .bak suffix appended
    void make_backup(const std::string &path)
    {
        const std::string backup_path(path + ".bak");
        std::ifstream src(path.c_str());
        std::ofstream dest(backup_path.c_str());
        dest << src.rdbuf();
        src.close();
        dest.close();
    }
}


128
void ManagerImpl::init(const std::string &config_file)
Emmanuel Milou's avatar
[#2402]    
Emmanuel Milou committed
129
{
130
    path_ = config_file.empty() ? createConfigFile() : config_file;
131
    DEBUG("Configuration file path: %s", path_.c_str());
132

133
134
    bool no_errors = true;

135
    try {
136
        FILE *file = fopen(path_.c_str(), "rb");
137

138
139
        if (file) {
            Conf::YamlParser parser(file);
140
141
142
            parser.serializeEvents();
            parser.composeEvents();
            parser.constructNativeData();
143
            const int error_count = loadAccountMap(parser);
144
            fclose(file);
145
            if (error_count > 0) {
146
147
                WARN("Errors while parsing %s", path_.c_str());
                no_errors = false;
148
            }
149
        } else {
150
151
152
            WARN("Config file not found: creating default account map");
            loadDefaultAccountMap();
        }
153
    } catch (const Conf::YamlParserException &e) {
154
        ERROR("%s", e.what());
155
        no_errors = false;
156
157
    }

158
159
160
161
    // always back up last error-free configuration
    if (no_errors)
        make_backup(path_);

162
    initAudioDriver();
163

Tristan Matthews's avatar
Tristan Matthews committed
164
    {
165
        sfl::ScopedLock lock(audioLayerMutex_);
Tristan Matthews's avatar
Tristan Matthews committed
166
        if (audiodriver_) {
167
            {
168
                sfl::ScopedLock toneLock(toneMutex_);
169
170
                telephoneTone_.reset(new TelephoneTone(preferences.getZoneToneChoice(), audiodriver_->getSampleRate()));
            }
171
            dtmfKey_.reset(new DTMF(getMainBuffer().getInternalSamplingRate()));
Tristan Matthews's avatar
Tristan Matthews committed
172
        }
173
    }
174

175
    history_.load(preferences.getHistoryLimit());
176
    registerAccounts();
jpbl's avatar
jpbl committed
177
178
}

179
180
181
182
183
184
185
186
void ManagerImpl::run()
{
    DEBUG("Starting DBus event loop");
    dbus_.exec();
}

void ManagerImpl::finish()
{
187
188
189
190
191
192
193
194
    if (finished_)
        return;

    finished_ = true;
    // Unset signal handlers
    signal(SIGHUP, SIG_DFL);
    signal(SIGINT, SIG_DFL);
    signal(SIGTERM, SIG_DFL);
195

196
    std::vector<std::string> callList(getCallList());
197
    DEBUG("Hangup %zu remaining call(s)", callList.size());
198

199
    for (std::vector<std::string>::iterator iter = callList.begin();
200
            iter != callList.end(); ++iter)
201
        hangupCall(*iter);
202

203
204
    saveConfig();

205
    unregisterAllAccounts();
206

207
    SIPVoIPLink::destroy();
208
209
210
#if HAVE_IAX
    IAXVoIPLink::unloadAccountMap();
#endif
211

212
    {
213
        sfl::ScopedLock lock(audioLayerMutex_);
214
215
216
217

        delete audiodriver_;
        audiodriver_ = NULL;
    }
218

219
    dbus_.exit();
jpbl's avatar
jpbl committed
220
221
}

222
bool ManagerImpl::isCurrentCall(const std::string& callId) const
Emmanuel Milou's avatar
[#2402]    
Emmanuel Milou committed
223
{
224
    return currentCallId_ == callId;
jpbl's avatar
jpbl committed
225
226
}

227
bool ManagerImpl::hasCurrentCall() const
Emmanuel Milou's avatar
[#2402]    
Emmanuel Milou committed
228
{
229
    return not currentCallId_.empty();
jpbl's avatar
jpbl committed
230
231
}

232
std::string
233
ManagerImpl::getCurrentCallId() const
Emmanuel Milou's avatar
[#2402]    
Emmanuel Milou committed
234
{
235
    return currentCallId_;
jpbl's avatar
jpbl committed
236
237
}

238
239
240
241
242
void ManagerImpl::unsetCurrentCall()
{
    switchCall("");
}

243
void ManagerImpl::switchCall(const std::string& id)
Emmanuel Milou's avatar
[#2402]    
Emmanuel Milou committed
244
{
245
    sfl::ScopedLock m(currentCallMutex_);
246
    DEBUG("----- Switch current call id to %s -----", id.c_str());
247
    currentCallId_ = id;
jpbl's avatar
jpbl committed
248
249
250
251
252
}

///////////////////////////////////////////////////////////////////////////////
// Management of events' IP-phone user
///////////////////////////////////////////////////////////////////////////////
253
/* Main Thread */
Emmanuel Milou's avatar
Emmanuel Milou committed
254

255
bool ManagerImpl::outgoingCall(const std::string& account_id,
256
257
258
                               const std::string& call_id,
                               const std::string& to,
                               const std::string& conf_id)
Emmanuel Milou's avatar
[#2402]    
Emmanuel Milou committed
259
{
260
    if (call_id.empty()) {
261
        DEBUG("New outgoing call abort, missing callid");
Emmanuel Lepage's avatar
Emmanuel Lepage committed
262
263
        return false;
    }
264

265
    // Call ID must be unique
266
    if (isValidCall(call_id)) {
267
        ERROR("Call id already exists in outgoing call");
268
269
270
        return false;
    }

271
    DEBUG("New outgoing call %s to %s", call_id.c_str(), to.c_str());
272

273
274
    stopTone();

275
    std::string current_call_id(getCurrentCallId());
276

277
    std::string prefix(hookPreference.getNumberAddPrefix());
278

279
    std::string to_cleaned(NumberCleaner::clean(to, prefix));
Emmanuel Milou's avatar
Emmanuel Milou committed
280

281
282
    // in any cases we have to detach from current communication
    if (hasCurrentCall()) {
283
        DEBUG("Has current call (%s) put it onhold", current_call_id.c_str());
284

285
        // if this is not a conference and this and is not a conference participant
286
        if (not isConference(current_call_id) and not isConferenceParticipant(current_call_id))
287
            onHoldCall(current_call_id);
288
        else if (isConference(current_call_id) and not isConferenceParticipant(call_id))
289
            detachParticipant(MainBuffer::DEFAULT_ID);
290
    }
291

292
    DEBUG("Selecting account %s", account_id.c_str());
293

294
    // fallback using the default sip account if the specied doesn't exist
Tristan Matthews's avatar
Tristan Matthews committed
295
    std::string use_account_id;
296
    if (!accountExists(account_id)) {
297
        WARN("Account does not exist, trying with default SIP account");
298
299
300
301
        use_account_id = SIPAccount::IP2IP_PROFILE;
    }
    else {
        use_account_id = account_id;
302
    }
303

304
    try {
305
        Call *call = getAccountLink(account_id)->newOutgoingCall(call_id, to_cleaned, use_account_id);
306
307

        // try to reverse match the peer name using the cache
Tristan Matthews's avatar
Tristan Matthews committed
308
        if (call->getDisplayName().empty()) {
309
            const std::string pseudo_contact_name(HistoryNameCache::getInstance().getNameFromHistory(call->getPeerNumber(), call->getAccountId()));
Tristan Matthews's avatar
Tristan Matthews committed
310
            if (not pseudo_contact_name.empty())
311
312
                call->setDisplayName(pseudo_contact_name);
        }
313
        switchCall(call_id);
314
        call->setConfId(conf_id);
315
    } catch (const VoipLinkException &e) {
316
        callFailure(call_id);
317
        ERROR("%s", e.what());
318
        return false;
319
320
321
322
    } catch (ost::Socket *) {
        callFailure(call_id);
        ERROR("Could not bind socket");
        return false;
323
324
    }

325
    getMainBuffer().dumpInfo();
Alexandre Savard's avatar
Alexandre Savard committed
326

327
    return true;
jpbl's avatar
jpbl committed
328
329
}

yanmorin's avatar
   
yanmorin committed
330
//THREAD=Main : for outgoing Call
331
bool ManagerImpl::answerCall(const std::string& call_id)
Emmanuel Milou's avatar
[#2402]    
Emmanuel Milou committed
332
{
333
    bool result = true;
334
335
336
337
338
339
    Call *call = getCallFromCallID(call_id);

    if (call == NULL) {
        ERROR("Call %s is NULL", call_id.c_str());
        return false;
    }
340

341
    // If sflphone is ringing
342
    stopTone();
343

344
    // set playback mode to VOICE
345
    AudioLayer *al = getAudioDriver();
346
347
    if(al) al->setPlaybackMode(AudioLayer::VOICE);

348
    // store the current call id
349
    std::string current_call_id(getCurrentCallId());
350

351
352
    // in any cases we have to detach from current communication
    if (hasCurrentCall()) {
353

354
        DEBUG("Currently conversing with %s", current_call_id.c_str());
355

356
        if (not isConference(current_call_id) and not isConferenceParticipant(current_call_id)) {
357
            DEBUG("Answer call: Put the current call (%s) on hold", current_call_id.c_str());
358
            onHoldCall(current_call_id);
359
        } else if (isConference(current_call_id) and not isConferenceParticipant(call_id)) {
360
            // if we are talking to a conference and we are answering an incoming call
361
            DEBUG("Detach main participant from conference");
362
            detachParticipant(MainBuffer::DEFAULT_ID);
363
364
        }
    }
365

366
    try {
367
        VoIPLink *link = getAccountLink(call->getAccountId());
368
369
        if (link)
            link->answer(call);
370
    } catch (const std::runtime_error &e) {
371
        ERROR("%s", e.what());
372
        result = false;
373
    }
Alexandre Savard's avatar
Alexandre Savard committed
374

375
    // if it was waiting, it's waiting no more
376
    removeWaitingCall(call_id);
377

378
    // if we dragged this call into a conference already
379
    if (isConferenceParticipant(call_id))
380
        switchCall(call->getConfId());
381
    else
382
        switchCall(call_id);
383

384
    // Connect streams
385
    addStream(call_id);
386

387
    getMainBuffer().dumpInfo();
Alexandre Savard's avatar
Alexandre Savard committed
388

389
    // Start recording if set in preference
390
    if (audioPreference.getIsAlwaysRecording())
391
        toggleRecordingCall(call_id);
392
393

    // update call state on client side
394
    dbus_.getCallManager()->callStateChanged(call_id, "CURRENT");
395
    return result;
jpbl's avatar
jpbl committed
396
397
}

398
399
400
401
402
403
404
405
406
void ManagerImpl::checkAudio()
{
    if (getCallList().empty()) {
        sfl::ScopedLock lock(audioLayerMutex_);
        if (audiodriver_)
            audiodriver_->stopStream();
    }
}

yanmorin's avatar
   
yanmorin committed
407
//THREAD=Main
408
bool ManagerImpl::hangupCall(const std::string& callId)
Emmanuel Milou's avatar
[#2402]    
Emmanuel Milou committed
409
{
410
    // store the current call id
411
    std::string currentCallId(getCurrentCallId());
yanmorin's avatar
   
yanmorin committed
412

413
    stopTone();
414

415
    // set playback mode to NONE
416
    AudioLayer *al = getAudioDriver();
417
418
    if(al) al->setPlaybackMode(AudioLayer::NONE);

419
    /* Broadcast a signal over DBus */
420
    DEBUG("Send DBUS call state change (HUNGUP) for id %s", callId.c_str());
421
    dbus_.getCallManager()->callStateChanged(callId, "HUNGUP");
422

423
    /* We often get here when the call was hungup before being created */
424
    if (not isValidCall(callId) and not isIPToIP(callId)) {
425
        DEBUG("Could not hang up call %s, call not valid", callId.c_str());
426
        checkAudio();
427
        return false;
428
429
    }

430
431
432
    // Disconnect streams
    removeStream(callId);

433
    if (isConferenceParticipant(callId)) {
434
        removeParticipant(callId);
435
    } else {
436
437
        // we are not participating in a conference, current call switched to ""
        if (not isConference(currentCallId))
438
            unsetCurrentCall();
439
    }
440

441
    if (isIPToIP(callId)) {
442
        /* Direct IP to IP call */
443
        try {
444
            Call * call = SIPVoIPLink::instance()->getSipCall(callId);
445
446
            if (call) {
                history_.addCall(call, preferences.getHistoryLimit());
447
                SIPVoIPLink::instance()->hangup(callId, 0);
448
                checkAudio();
449
450
                saveHistory();
            }
451
        } catch (const VoipLinkException &e) {
452
            ERROR("%s", e.what());
453
            return false;
454
        }
455
    } else {
456
        Call * call = getCallFromCallID(callId);
457
458
        if (call) {
            history_.addCall(call, preferences.getHistoryLimit());
459
            VoIPLink *link = getAccountLink(call->getAccountId());
460
            link->hangup(callId, 0);
461
            checkAudio();
462
463
            saveHistory();
        }
464
    }
465

466
    getMainBuffer().dumpInfo();
467
    return true;
jpbl's avatar
jpbl committed
468
469
}

470
bool ManagerImpl::hangupConference(const std::string& id)
Emmanuel Milou's avatar
[#2402]    
Emmanuel Milou committed
471
{
472
    DEBUG("Hangup conference %s", id.c_str());
Alexandre Savard's avatar
Alexandre Savard committed
473

474
    ConferenceMap::iterator iter_conf = conferenceMap_.find(id);
Alexandre Savard's avatar
Alexandre Savard committed
475

476
    if (iter_conf != conferenceMap_.end()) {
477
        Conference *conf = iter_conf->second;
Alexandre Savard's avatar
Alexandre Savard committed
478

479
480
        if (conf) {
            ParticipantSet participants(conf->getParticipantList());
481

482
483
484
            for (ParticipantSet::const_iterator iter = participants.begin();
                    iter != participants.end(); ++iter)
                hangupCall(*iter);
485
        } else {
486
            ERROR("No such conference %s", id.c_str());
487
488
            return false;
        }
489
    }
Alexandre Savard's avatar
Alexandre Savard committed
490

491
    unsetCurrentCall();
492

493
    getMainBuffer().dumpInfo();
494

495
    return true;
Alexandre Savard's avatar
Alexandre Savard committed
496
497
}

jpbl's avatar
jpbl committed
498

yanmorin's avatar
   
yanmorin committed
499
//THREAD=Main
500
bool ManagerImpl::onHoldCall(const std::string& callId)
Emmanuel Milou's avatar
[#2402]    
Emmanuel Milou committed
501
{
502
    bool result = true;
503

504
    stopTone();
505

506
    std::string current_call_id(getCurrentCallId());
507

508
    try {
509
        if (isIPToIP(callId)) {
510
            SIPVoIPLink::instance()->onhold(callId);
511
512
513
        } else {
            /* Classic call, attached to an account */
            std::string account_id(getAccountFromCall(callId));
514

515
            if (account_id.empty()) {
516
                DEBUG("Account ID %s or callid %s doesn't exist in call onHold", account_id.c_str(), callId.c_str());
517
                return false;
518
            }
519
520
521
522

            getAccountLink(account_id)->onhold(callId);
        }
    } catch (const VoipLinkException &e) {
523
        ERROR("%s", e.what());
524
        result = false;
525
    }
526

527
    // Unbind calls in main buffer
528
    removeStream(callId);
529

530
    // Remove call from teh queue if it was still there
531
    removeWaitingCall(callId);
532

533
    // keeps current call id if the action is not holding this call or a new outgoing call
534
    // this could happen in case of a conference
535
    if (current_call_id == callId)
536
        unsetCurrentCall();
537

538
    dbus_.getCallManager()->callStateChanged(callId, "HOLD");
539

540
    getMainBuffer().dumpInfo();
541
    return result;
yanmorin's avatar
   
yanmorin committed
542
543
544
}

//THREAD=Main
545
bool ManagerImpl::offHoldCall(const std::string& callId)
Emmanuel Milou's avatar
[#2402]    
Emmanuel Milou committed
546
{
547
    bool result = true;
548

549
    stopTone();
550

Tristan Matthews's avatar
Tristan Matthews committed
551
    const std::string currentCallId(getCurrentCallId());
552

Tristan Matthews's avatar
Tristan Matthews committed
553
    // Place current call on hold if it isn't
554
    if (hasCurrentCall()) {
Tristan Matthews's avatar
Tristan Matthews committed
555
        if (not isConference(currentCallId) and not isConferenceParticipant(currentCallId)) {
556
            DEBUG("Has current call (%s), put on hold", currentCallId.c_str());
557
            onHoldCall(currentCallId);
558
559
        } else if (isConference(currentCallId) && callId != currentCallId) {
            holdConference(currentCallId);
560
        } else if (isConference(currentCallId) and not isConferenceParticipant(callId))
561
            detachParticipant(MainBuffer::DEFAULT_ID);
562
    }
alexandresavard's avatar
alexandresavard committed
563

564
    if (isIPToIP(callId))
Tristan Matthews's avatar
Tristan Matthews committed
565
        SIPVoIPLink::instance()->offhold(callId);
566
    else {
567
        /* Classic call, attached to an account */
568
        Call * call = getCallFromCallID(callId);
569

570
        if (call)
571
            getAccountLink(call->getAccountId())->offhold(callId);
572
573
        else
            result = false;
574
    }
575

576
    dbus_.getCallManager()->callStateChanged(callId, "UNHOLD");
577

578
    if (isConferenceParticipant(callId)) {
579
        Call *call = getCallFromCallID(callId);
580
        if (call)
581
            switchCall(call->getConfId());
582
583
        else
            result = false;
584
    } else
585
        switchCall(callId);
586

587
588
    addStream(callId);

589
    getMainBuffer().dumpInfo();
590
    return result;
jpbl's avatar
jpbl committed
591
592
}

yanmorin's avatar
   
yanmorin committed
593
//THREAD=Main
594
bool ManagerImpl::transferCall(const std::string& callId, const std::string& to)
Emmanuel Milou's avatar
[#2402]    
Emmanuel Milou committed
595
{
596
    if (isConferenceParticipant(callId)) {
597
        removeParticipant(callId);
Tristan Matthews's avatar
cleanup    
Tristan Matthews committed
598
    } else if (not isConference(getCurrentCallId()))
599
        unsetCurrentCall();
600

601
    // Direct IP to IP call
602
    if (isIPToIP(callId)) {
603
        SIPVoIPLink::instance()->transfer(callId, to);
604
605
    } else {
        std::string accountID(getAccountFromCall(callId));
606

607
        if (accountID.empty())
608
            return false;
609

610
611
        VoIPLink *link = getAccountLink(accountID);
        link->transfer(callId, to);
612
    }
613

614
    // remove waiting call in case we make transfer without even answer
615
    removeWaitingCall(callId);
616

617
    getMainBuffer().dumpInfo();
Alexandre Savard's avatar
Alexandre Savard committed
618

619
    return true;
jpbl's avatar
jpbl committed
620
621
}

622
void ManagerImpl::transferFailed()
Emmanuel Milou's avatar
[#2402]    
Emmanuel Milou committed
623
{
624
    dbus_.getCallManager()->transferFailed();
625
626
}

627
void ManagerImpl::transferSucceeded()
Emmanuel Milou's avatar
[#2402]    
Emmanuel Milou committed
628
{
629
    dbus_.getCallManager()->transferSucceeded();
630
631
}

632
bool ManagerImpl::attendedTransfer(const std::string& transferID, const std::string& targetID)
633
{
634
    if (isIPToIP(transferID))
Rafaël Carré's avatar
Rafaël Carré committed
635
        return SIPVoIPLink::instance()->attendedTransfer(transferID, targetID);
636

Rafaël Carré's avatar
Rafaël Carré committed
637
    // Classic call, attached to an account
638
    std::string accountid(getAccountFromCall(transferID));
639

640
641
642
643
    if (accountid.empty())
        return false;

    return getAccountLink(accountid)->attendedTransfer(transferID, targetID);
644
645
}

yanmorin's avatar
   
yanmorin committed
646
//THREAD=Main : Call:Incoming
647
bool ManagerImpl::refuseCall(const std::string& id)
Emmanuel Milou's avatar
[#2402]    
Emmanuel Milou committed
648
{
649
650
651
    if (!isValidCall(id))
        return false;

652
    stopTone();
653

Rafaël Carré's avatar
Rafaël Carré committed
654
    if (getCallList().size() <= 1) {
655
        sfl::ScopedLock lock(audioLayerMutex_);
656
        audiodriver_->stopStream();
657
    }
Emmanuel Milou's avatar
Emmanuel Milou committed
658

659
    /* Direct IP to IP call */
660

661
    if (isIPToIP(id))