~ubuntu-branches/ubuntu/saucy/sflphone/saucy

« back to all changes in this revision

Viewing changes to sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2010-12-24 16:33:55 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20101224163355-tkvvikqxbrbav6up
Tags: 0.9.11-1
* New upstream release
* Add new build dependencies on libwebkit-dev and libyaml-dev

* Bump Standards-Version up to 3.9.1
* Bump debhelper compatibility to 8
* Patch another typo in the upstream code (lintian notice)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *  Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc.
3
3
 *  Author: Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com>
 
4
 *  Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
4
5
 *
5
6
 *  This program is free software; you can redistribute it and/or modify
6
7
 *  it under the terms of the GNU General Public License as published by
35
36
#include "AudioSymmetricRtpSession.h"
36
37
#include "manager.h"
37
38
#include "account.h"
 
39
#include "sip/sdp.h"
38
40
#include "sip/sipcall.h"
 
41
#include "sip/sipaccount.h"
39
42
#include "sip/SdesNegotiator.h"
40
43
 
41
44
#include <assert.h>
64
67
    stop();
65
68
}
66
69
 
67
 
void AudioRtpFactory::initAudioRtpConfig(SIPCall *ca)
 
70
void AudioRtpFactory::initAudioRtpConfig (SIPCall *ca)
68
71
{
69
72
    assert (ca);
70
73
 
76
79
 
77
80
    AccountID accountId = Manager::instance().getAccountFromCall (ca->getCallId());
78
81
 
79
 
    // Check if it is an IP-to-IP call
80
 
    if (accountId == AccountNULL) {
81
 
        _srtpEnabled = Manager::instance().getConfigBool (IP2IP_PROFILE, SRTP_ENABLE);
82
 
        _keyExchangeProtocol = Manager::instance().getConfigInt (IP2IP_PROFILE, SRTP_KEY_EXCHANGE);
83
 
        _debug ("Ip-to-ip profile selected with key exchange protocol number %d", _keyExchangeProtocol);
84
 
        _helloHashEnabled = Manager::instance().getConfigBool (IP2IP_PROFILE, ZRTP_HELLO_HASH);
85
 
    } else {
86
 
        _srtpEnabled = Manager::instance().getConfigBool (accountId, SRTP_ENABLE);
87
 
        _keyExchangeProtocol = Manager::instance().getConfigInt (accountId, SRTP_KEY_EXCHANGE);
 
82
    _debug ("AudioRtpFactory: Init rtp session for account %s", accountId.c_str());
 
83
 
 
84
    // Manager::instance().getAccountLink (accountId);
 
85
    Account *account = Manager::instance().getAccount (accountId);
 
86
 
 
87
    if (!account)
 
88
        _error ("AudioRtpFactory: Error no account found");
 
89
 
 
90
    if (account->getType() == "SIP") {
 
91
        SIPAccount *sipaccount = static_cast<SIPAccount *> (account);
 
92
        _srtpEnabled = sipaccount->getSrtpEnable();
 
93
        std::string tempkey = sipaccount->getSrtpKeyExchange();
 
94
 
 
95
        if (tempkey == "sdes")
 
96
            _keyExchangeProtocol = Sdes;
 
97
        else if (tempkey == "zrtp")
 
98
            _keyExchangeProtocol = Zrtp;
 
99
        else
 
100
            _keyExchangeProtocol = Symmetric;
 
101
 
88
102
        _debug ("Registered account %s profile selected with key exchange protocol number %d", accountId.c_str(), _keyExchangeProtocol);
89
 
        _helloHashEnabled = Manager::instance().getConfigBool (accountId, ZRTP_HELLO_HASH);
 
103
        _helloHashEnabled = sipaccount->getZrtpHelloHash();
 
104
    } else {
 
105
        _srtpEnabled = false;
 
106
        _keyExchangeProtocol = Symmetric;
 
107
        _helloHashEnabled = false;
90
108
    }
 
109
 
91
110
}
92
111
 
93
112
void AudioRtpFactory::initAudioRtpSession (SIPCall * ca)
94
113
{
95
114
    ost::MutexLock m (_audioRtpThreadMutex);
96
115
 
97
 
    _debug ("Srtp enable: %d ", _srtpEnabled);
 
116
    _debug ("AudioRtpFactory: Srtp enable: %d ", _srtpEnabled);
 
117
 
98
118
    if (_srtpEnabled) {
99
 
        std::string zidFilename (Manager::instance().getConfigString (SIGNALISATION, ZRTP_ZIDFILE));
 
119
        std::string zidFilename (Manager::instance().voipPreferences.getZidFile());
100
120
 
101
121
        switch (_keyExchangeProtocol) {
102
122
 
115
135
 
116
136
            case Sdes:
117
137
 
118
 
                _rtpSession = new AudioSrtpSession (&Manager::instance(), ca);
 
138
                _rtpSession = new AudioSrtpSession (&Manager::instance(), ca);
119
139
                _rtpSessionType = Sdes;
120
 
 
121
 
                ca->getLocalSDP()->set_srtp_crypto(static_cast<AudioSrtpSession *> (_rtpSession)->getLocalCryptoInfo());
122
 
                break;
 
140
                break;
123
141
 
124
142
            default:
125
 
                _debug("Unsupported Rtp Session Exception Type!");
 
143
                _debug ("Unsupported Rtp Session Exception Type!");
126
144
                throw UnsupportedRtpSessionType();
127
145
        }
128
146
    } else {
141
159
    switch (_rtpSessionType) {
142
160
 
143
161
        case Sdes:
144
 
            if (static_cast<AudioSrtpSession *> (_rtpSession)->startRtpThread(audiocodec) != 0) {
 
162
 
 
163
            if (static_cast<AudioSrtpSession *> (_rtpSession)->startRtpThread (audiocodec) != 0) {
145
164
                throw AudioRtpFactoryException ("RTP: Error: Failed to start AudioSRtpSession thread");
146
165
            }
147
 
            break;
 
166
 
 
167
            break;
148
168
 
149
169
        case Symmetric:
150
170
            _debug ("Starting symmetric rtp thread");
151
171
 
152
 
            if (static_cast<AudioSymmetricRtpSession *> (_rtpSession)->startRtpThread(audiocodec) != 0) {
 
172
            if (static_cast<AudioSymmetricRtpSession *> (_rtpSession)->startRtpThread (audiocodec) != 0) {
153
173
                throw AudioRtpFactoryException ("RTP: Error: Failed to start AudioSymmetricRtpSession thread");
154
174
            }
155
175
 
157
177
 
158
178
        case Zrtp:
159
179
 
160
 
            if (static_cast<AudioZrtpSession *> (_rtpSession)->startRtpThread(audiocodec) != 0) {
 
180
            if (static_cast<AudioZrtpSession *> (_rtpSession)->startRtpThread (audiocodec) != 0) {
161
181
                throw AudioRtpFactoryException ("RTP: Error: Failed to start AudioZrtpSession thread");
162
182
            }
 
183
 
163
184
            break;
164
185
    }
165
186
}
167
188
void AudioRtpFactory::stop (void)
168
189
{
169
190
    ost::MutexLock mutex (_audioRtpThreadMutex);
170
 
    _info("RTP: Stopping audio rtp session");
 
191
    _info ("RTP: Stopping audio rtp session");
171
192
 
172
193
    if (_rtpSession == NULL) {
173
194
        _debugException ("RTP: Error: _rtpSession is null when trying to stop. Returning.");
178
199
        switch (_rtpSessionType) {
179
200
 
180
201
            case Sdes:
181
 
                delete static_cast<AudioSrtpSession *> (_rtpSession);
182
 
                break;
 
202
                delete static_cast<AudioSrtpSession *> (_rtpSession);
 
203
                break;
183
204
 
184
205
            case Symmetric:
185
206
                delete static_cast<AudioSymmetricRtpSession *> (_rtpSession);
193
214
        _rtpSession = NULL;
194
215
    } catch (...) {
195
216
        _debugException ("RTP: Error: Exception caught when stopping the audio rtp session");
196
 
        throw AudioRtpFactoryException("RTP: Error: caught exception in AudioRtpFactory::stop");
 
217
        throw AudioRtpFactoryException ("RTP: Error: caught exception in AudioRtpFactory::stop");
197
218
    }
198
219
}
199
220
 
200
221
void AudioRtpFactory::updateDestinationIpAddress (void)
201
222
{
202
223
    _info ("RTP: Updating IP address");
 
224
 
203
225
    if (_rtpSession == NULL) {
204
226
        throw AudioRtpFactoryException ("RTP: Error: _rtpSession was null when trying to update IP address");
205
227
    }
207
229
    switch (_rtpSessionType) {
208
230
 
209
231
        case Sdes:
210
 
            static_cast<AudioSrtpSession *> (_rtpSession)->updateDestinationIpAddress();
211
 
            break;
 
232
            static_cast<AudioSrtpSession *> (_rtpSession)->updateDestinationIpAddress();
 
233
            break;
212
234
 
213
235
        case Symmetric:
214
236
            static_cast<AudioSymmetricRtpSession *> (_rtpSession)->updateDestinationIpAddress();
215
237
            break;
216
238
 
217
239
        case Zrtp:
218
 
            static_cast<AudioZrtpSession *> (_rtpSession)->updateDestinationIpAddress();
 
240
            static_cast<AudioZrtpSession *> (_rtpSession)->updateDestinationIpAddress();
219
241
            break;
220
242
    }
221
243
}
222
244
 
223
245
sfl::AudioSymmetricRtpSession * AudioRtpFactory::getAudioSymetricRtpSession()
224
246
{
225
 
        if ( (_rtpSessionType == Symmetric) && (_rtpSessionType != NULL)) {
226
 
                return static_cast<AudioSymmetricRtpSession *> (_rtpSession);
227
 
            } else {
228
 
                throw AudioRtpFactoryException("RTP: Error: _rtpSession is NULL in getAudioSymetricRtpSession");
229
 
            }
 
247
    if ( (_rtpSessionType == Symmetric) && (_rtpSessionType != NULL)) {
 
248
        return static_cast<AudioSymmetricRtpSession *> (_rtpSession);
 
249
    } else {
 
250
        throw AudioRtpFactoryException ("RTP: Error: _rtpSession is NULL in getAudioSymetricRtpSession");
 
251
    }
230
252
}
231
253
 
232
254
sfl::AudioZrtpSession * AudioRtpFactory::getAudioZrtpSession()
234
256
    if ( (_rtpSessionType == Zrtp) && (_rtpSessionType != NULL)) {
235
257
        return static_cast<AudioZrtpSession *> (_rtpSession);
236
258
    } else {
237
 
        throw AudioRtpFactoryException("RTP: Error: _rtpSession is NULL in getAudioZrtpSession");
238
 
    }
239
 
}
240
 
 
241
 
void AudioRtpFactory::setRemoteCryptoInfo(sfl::SdesNegotiator& nego)
242
 
{
243
 
    if ( _rtpSession && _rtpSessionType && (_rtpSessionType == Sdes)) {
244
 
        static_cast<AudioSrtpSession *> (_rtpSession)->setRemoteCryptoInfo(nego);
245
 
    }
246
 
    else {
247
 
        throw AudioRtpFactoryException("RTP: Error: _rtpSession is NULL in setRemoteCryptoInfo");
248
 
    }
249
 
}
250
 
 
251
 
void AudioRtpFactory::sendDtmfDigit(int digit) {
252
 
        switch(_rtpSessionType) {
253
 
 
254
 
        case Sdes:
255
 
                static_cast<AudioSrtpSession *> (_rtpSession)->putDtmfEvent(digit);
256
 
                break;
257
 
 
258
 
        case Symmetric:
259
 
                static_cast<AudioSymmetricRtpSession *> (_rtpSession)->putDtmfEvent(digit);
260
 
                break;
261
 
 
262
 
        case Zrtp:
263
 
                static_cast<AudioZrtpSession *> (_rtpSession)->putDtmfEvent(digit);
264
 
                break;
265
 
        }
 
259
        throw AudioRtpFactoryException ("RTP: Error: _rtpSession is NULL in getAudioZrtpSession");
 
260
    }
 
261
}
 
262
 
 
263
void sfl::AudioRtpFactory::initLocalCryptoInfo (SIPCall * ca)
 
264
{
 
265
    if (_rtpSession && _rtpSessionType && (_rtpSessionType == Sdes)) {
 
266
        static_cast<AudioSrtpSession *> (_rtpSession)->initLocalCryptoInfo ();
 
267
 
 
268
        ca->getLocalSDP()->set_srtp_crypto (static_cast<AudioSrtpSession *> (_rtpSession)->getLocalCryptoInfo());
 
269
    }
 
270
}
 
271
 
 
272
void AudioRtpFactory::setRemoteCryptoInfo (sfl::SdesNegotiator& nego)
 
273
{
 
274
    if (_rtpSession && _rtpSessionType && (_rtpSessionType == Sdes)) {
 
275
        static_cast<AudioSrtpSession *> (_rtpSession)->setRemoteCryptoInfo (nego);
 
276
    } else {
 
277
        throw AudioRtpFactoryException ("RTP: Error: _rtpSession is NULL in setRemoteCryptoInfo");
 
278
    }
 
279
}
 
280
 
 
281
void AudioRtpFactory::sendDtmfDigit (int digit)
 
282
{
 
283
 
 
284
    switch (_rtpSessionType) {
 
285
 
 
286
        case Sdes:
 
287
            static_cast<AudioSrtpSession *> (_rtpSession)->putDtmfEvent (digit);
 
288
            break;
 
289
 
 
290
        case Symmetric:
 
291
            static_cast<AudioSymmetricRtpSession *> (_rtpSession)->putDtmfEvent (digit);
 
292
            break;
 
293
 
 
294
        case Zrtp:
 
295
            static_cast<AudioZrtpSession *> (_rtpSession)->putDtmfEvent (digit);
 
296
            break;
 
297
    }
 
298
 
266
299
}
267
300
}
268
301