configurationmanager.cpp 13 KB
Newer Older
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
1
/*
2
 *  Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 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>
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.
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.
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

33
#ifdef HAVE_CONFIG_H
Rafaël Carré's avatar
Rafaël Carré committed
34
#include "config.h"
35
#endif
Rafaël Carré's avatar
Rafaël Carré committed
36

37
#include "configurationmanager.h"
38
#include <sstream>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
39
#include "../manager.h"
40
#include "sip/sipvoiplink.h"
41
#include "sip/siptransport.h"
42
#include "account.h"
43
#include "logger.h"
44
#include "sip/sipaccount.h"
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
45

46
const char* ConfigurationManager::SERVER_PATH =
Julien Bonjean's avatar
Julien Bonjean committed
47
48
    "/org/sflphone/SFLphone/ConfigurationManager";

49
50
ConfigurationManager::ConfigurationManager(DBus::Connection& connection) :
    DBus::ObjectAdaptor(connection, SERVER_PATH)
51
{}
52

53
std::map<std::string, std::string> ConfigurationManager::getIp2IpDetails()
Julien Bonjean's avatar
Julien Bonjean committed
54
55
{
    std::map<std::string, std::string> ip2ipAccountDetails;
56
    SIPAccount *sipaccount = Manager::instance().getIP2IPAccount();
57

Julien Bonjean's avatar
Julien Bonjean committed
58
    if (!sipaccount) {
59
        ERROR("ConfigurationManager: could not find IP2IP account");
Julien Bonjean's avatar
Julien Bonjean committed
60
        return ip2ipAccountDetails;
61
    } else
62
        return sipaccount->getIp2IpDetails();
63

64
    std::map<std::string, std::string> tlsSettings(getTlsSettings());
65
66
    std::copy(tlsSettings.begin(), tlsSettings.end(),
              std::inserter(ip2ipAccountDetails, ip2ipAccountDetails.end()));
67

Julien Bonjean's avatar
Julien Bonjean committed
68
    return ip2ipAccountDetails;
69
70
}

Julien Bonjean's avatar
Julien Bonjean committed
71

72
std::map<std::string, std::string> ConfigurationManager::getAccountDetails(
73
74
    const std::string& accountID)
{
75
    return Manager::instance().getAccountDetails(accountID);
76
}
Julien Bonjean's avatar
Julien Bonjean committed
77

78
std::map<std::string, std::string>
79
ConfigurationManager::getTlsSettingsDefault()
80
81
82
{
    std::stringstream portstr;
    portstr << DEFAULT_SIP_TLS_PORT;
Julien Bonjean's avatar
Julien Bonjean committed
83

84
    std::map<std::string, std::string> tlsSettingsDefault;
85
86
87
88
89
90
91
92
93
94
95
96
97
    tlsSettingsDefault[CONFIG_TLS_LISTENER_PORT] = portstr.str();
    tlsSettingsDefault[CONFIG_TLS_CA_LIST_FILE] = "";
    tlsSettingsDefault[CONFIG_TLS_CERTIFICATE_FILE] = "";
    tlsSettingsDefault[CONFIG_TLS_PRIVATE_KEY_FILE] = "";
    tlsSettingsDefault[CONFIG_TLS_PASSWORD] = "";
    tlsSettingsDefault[CONFIG_TLS_METHOD] = "TLSv1";
    tlsSettingsDefault[CONFIG_TLS_CIPHERS] = "";
    tlsSettingsDefault[CONFIG_TLS_SERVER_NAME] = "";
    tlsSettingsDefault[CONFIG_TLS_VERIFY_SERVER] = "true";
    tlsSettingsDefault[CONFIG_TLS_VERIFY_CLIENT] = "true";
    tlsSettingsDefault[CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE] = "true";
    tlsSettingsDefault[CONFIG_TLS_NEGOTIATION_TIMEOUT_SEC] = "2";
    tlsSettingsDefault[CONFIG_TLS_NEGOTIATION_TIMEOUT_MSEC] = "0";
98

99
    return tlsSettingsDefault;
100
101
}

Julien Bonjean's avatar
Julien Bonjean committed
102
103
104
std::map<std::string, std::string> ConfigurationManager::getTlsSettings()
{
    std::map<std::string, std::string> tlsSettings;
105

106
    SIPAccount *sipaccount = Manager::instance().getIP2IPAccount();
107

Julien Bonjean's avatar
Julien Bonjean committed
108
109
    if (!sipaccount)
        return tlsSettings;
110

111
    return sipaccount->getTlsSettings();
112
113
}

114
void ConfigurationManager::setTlsSettings(const std::map<std::string, std::string>& details)
Julien Bonjean's avatar
Julien Bonjean committed
115
{
116
    SIPAccount * sipaccount = Manager::instance().getIP2IPAccount();
117

Julien Bonjean's avatar
Julien Bonjean committed
118
    if (!sipaccount) {
119
        DEBUG("ConfigurationManager: Error: No valid account in set TLS settings");
Julien Bonjean's avatar
Julien Bonjean committed
120
121
122
        return;
    }

123
    sipaccount->setTlsSettings(details);
Julien Bonjean's avatar
Julien Bonjean committed
124
125
126
127
128

    Manager::instance().saveConfig();

    // Update account details to the client side
    accountsChanged();
129
130
}

131

132
void ConfigurationManager::setAccountDetails(const std::string& accountID, const std::map<std::string, std::string>& details)
Julien Bonjean's avatar
Julien Bonjean committed
133
{
134
    Manager::instance().setAccountDetails(accountID, details);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
135
136
}

137
void ConfigurationManager::sendRegister(const std::string& accountID, const bool& enable)
Julien Bonjean's avatar
Julien Bonjean committed
138
{
139
    Manager::instance().sendRegister(accountID, enable);
140
141
}

142
std::string ConfigurationManager::addAccount(const std::map<std::string, std::string>& details)
Julien Bonjean's avatar
Julien Bonjean committed
143
{
144
    return Manager::instance().addAccount(details);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
145
146
}

147
void ConfigurationManager::removeAccount(const std::string& accoundID)
Julien Bonjean's avatar
Julien Bonjean committed
148
{
149
    return Manager::instance().removeAccount(accoundID);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
150
151
}

Julien Bonjean's avatar
Julien Bonjean committed
152
153
154
std::vector<std::string> ConfigurationManager::getAccountList()
{
    return Manager::instance().getAccountList();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
155
156
}

Emmanuel Milou's avatar
Emmanuel Milou committed
157
158
/**
 * Send the list of all codecs loaded to the client through DBus.
159
 * Can stay global, as only the active codecs will be set per accounts
Emmanuel Milou's avatar
Emmanuel Milou committed
160
 */
161
std::vector<int32_t> ConfigurationManager::getAudioCodecList()
Julien Bonjean's avatar
Julien Bonjean committed
162
{
163
    std::vector<int32_t> list(Manager::instance().audioCodecFactory.getAudioCodecList());
Emmanuel Milou's avatar
Emmanuel Milou committed
164

165
166
167
    if (list.empty())
        errorAlert(CODECS_NOT_LOADED);

Julien Bonjean's avatar
Julien Bonjean committed
168
    return list;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
169
170
}

171
std::vector<std::string> ConfigurationManager::getSupportedTlsMethod()
Julien Bonjean's avatar
Julien Bonjean committed
172
173
{
    std::vector<std::string> method;
174
175
176
177
    method.push_back("Default");
    method.push_back("TLSv1");
    method.push_back("SSLv3");
    method.push_back("SSLv23");
Julien Bonjean's avatar
Julien Bonjean committed
178
    return method;
179
180
}

181
std::vector<std::string> ConfigurationManager::getAudioCodecDetails(const int32_t& payload)
Julien Bonjean's avatar
Julien Bonjean committed
182
{
183
    std::vector<std::string> result(Manager::instance().audioCodecFactory.getCodecSpecifications(payload));
184

185
186
    if (result.empty())
        errorAlert(CODECS_NOT_LOADED);
187

188
    return result;
189
190
}

191
std::vector<int32_t> ConfigurationManager::getActiveAudioCodecList(const std::string& accountID)
Julien Bonjean's avatar
Julien Bonjean committed
192
{
Rafaël Carré's avatar
Cleanup    
Rafaël Carré committed
193
    std::vector<int32_t> v;
Emmanuel Milou's avatar
Emmanuel Milou committed
194

195
196
    Account *acc = Manager::instance().getAccount(accountID);

Rafaël Carré's avatar
Cleanup    
Rafaël Carré committed
197
198
    if (acc)
        return acc->getActiveCodecs();
Julien Bonjean's avatar
Julien Bonjean committed
199
200

    return v;
201
}
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
202

203
void ConfigurationManager::setActiveAudioCodecList(const std::vector<std::string>& list, const std::string& accountID)
Julien Bonjean's avatar
Julien Bonjean committed
204
{
205
206
    Account *acc = Manager::instance().getAccount(accountID);

Rafaël Carré's avatar
Rafaël Carré committed
207
    if (acc) {
208
        acc->setActiveCodecs(list);
Rafaël Carré's avatar
Rafaël Carré committed
209
210
        Manager::instance().saveConfig();
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
211
212
}

Alexandre Savard's avatar
Alexandre Savard committed
213

Julien Bonjean's avatar
Julien Bonjean committed
214
215
216
std::vector<std::string> ConfigurationManager::getAudioPluginList()
{
    std::vector<std::string> v;
217

218
219
    v.push_back(PCM_DEFAULT);
    v.push_back(PCM_DMIX_DSNOOP);
220

Julien Bonjean's avatar
Julien Bonjean committed
221
    return v;
222
}
223

Alexandre Savard's avatar
Alexandre Savard committed
224

225
void ConfigurationManager::setAudioPlugin(const std::string& audioPlugin)
Julien Bonjean's avatar
Julien Bonjean committed
226
{
227
    return Manager::instance().setAudioPlugin(audioPlugin);
228
229
}

Julien Bonjean's avatar
Julien Bonjean committed
230
231
232
std::vector<std::string> ConfigurationManager::getAudioOutputDeviceList()
{
    return Manager::instance().getAudioOutputDeviceList();
233
}
234

Julien Bonjean's avatar
Julien Bonjean committed
235
236
237
std::vector<std::string> ConfigurationManager::getAudioInputDeviceList()
{
    return Manager::instance().getAudioInputDeviceList();
238
}
239

240
void ConfigurationManager::setAudioOutputDevice(const int32_t& index)
Julien Bonjean's avatar
Julien Bonjean committed
241
{
242
    return Manager::instance().setAudioDevice(index, SFL_PCM_PLAYBACK);
243
244
}

245
void ConfigurationManager::setAudioInputDevice(const int32_t& index)
Julien Bonjean's avatar
Julien Bonjean committed
246
{
247
    return Manager::instance().setAudioDevice(index, SFL_PCM_CAPTURE);
248
249
}

250
void ConfigurationManager::setAudioRingtoneDevice(const int32_t& index)
Julien Bonjean's avatar
Julien Bonjean committed
251
{
252
    return Manager::instance().setAudioDevice(index, SFL_PCM_RINGTONE);
253
}
254

Julien Bonjean's avatar
Julien Bonjean committed
255
256
257
std::vector<std::string> ConfigurationManager::getCurrentAudioDevicesIndex()
{
    return Manager::instance().getCurrentAudioDevicesIndex();
258
}
259

260
int32_t ConfigurationManager::getAudioDeviceIndex(const std::string& name)
Julien Bonjean's avatar
Julien Bonjean committed
261
{
262
    return Manager::instance().getAudioDeviceIndex(name);
263
264
}

265
std::string ConfigurationManager::getCurrentAudioOutputPlugin()
Julien Bonjean's avatar
Julien Bonjean committed
266
{
267
    DEBUG("ConfigurationManager: Get audio plugin %s", Manager::instance().getCurrentAudioOutputPlugin().c_str());
268

Julien Bonjean's avatar
Julien Bonjean committed
269
    return Manager::instance().getCurrentAudioOutputPlugin();
270
271
}

272
std::string ConfigurationManager::getNoiseSuppressState()
Julien Bonjean's avatar
Julien Bonjean committed
273
274
{
    return Manager::instance().getNoiseSuppressState();
275
276
}

277
void ConfigurationManager::setNoiseSuppressState(const std::string& state)
Julien Bonjean's avatar
Julien Bonjean committed
278
{
279
    Manager::instance().setNoiseSuppressState(state);
280
281
}

282
std::string ConfigurationManager::getEchoCancelState()
283
{
284
    return Manager::instance().getEchoCancelState() ? "enabled" : "disabled";
285
286
287
288
}

void ConfigurationManager::setEchoCancelState(const std::string& state)
{
289
    Manager::instance().setEchoCancelState(state);
290
291
}

292
int ConfigurationManager::getEchoCancelTailLength()
293
{
294
    return Manager::instance().getEchoCancelTailLength();
295
296
297
298
}

void ConfigurationManager::setEchoCancelTailLength(const int32_t& length)
{
299
    Manager::instance().setEchoCancelTailLength(length);
300
301
}

302
int ConfigurationManager::getEchoCancelDelay()
303
{
304
    return Manager::instance().getEchoCancelDelay();
305
306
307
308
}

void ConfigurationManager::setEchoCancelDelay(const int32_t& delay)
{
309
    Manager::instance().setEchoCancelDelay(delay);
310
311
}

312
int32_t ConfigurationManager::isIax2Enabled()
Julien Bonjean's avatar
Julien Bonjean committed
313
{
314
    return HAVE_IAX;
Emmanuel Milou's avatar
Emmanuel Milou committed
315
}
316

317
std::string ConfigurationManager::getRecordPath()
Julien Bonjean's avatar
Julien Bonjean committed
318
319
{
    return Manager::instance().getRecordPath();
320
321
}

322
void ConfigurationManager::setRecordPath(const std::string& recPath)
Julien Bonjean's avatar
Julien Bonjean committed
323
{
324
    Manager::instance().setRecordPath(recPath);
325
326
}

327
bool ConfigurationManager::getIsAlwaysRecording()
328
{
329
    return Manager::instance().getIsAlwaysRecording();
330
331
332
333
}

void ConfigurationManager::setIsAlwaysRecording(const bool& rec)
{
334
    Manager::instance().setIsAlwaysRecording(rec);
335
}
336

337
int32_t ConfigurationManager::getHistoryLimit()
Julien Bonjean's avatar
Julien Bonjean committed
338
339
{
    return Manager::instance().getHistoryLimit();
340
341
}

342
343
344
345
346
void ConfigurationManager::clearHistory()
{
    return Manager::instance().clearHistory();
}

347
void ConfigurationManager::setHistoryLimit(const int32_t& days)
Julien Bonjean's avatar
Julien Bonjean committed
348
{
349
    Manager::instance().setHistoryLimit(days);
350
351
}

352
void ConfigurationManager::setAudioManager(const std::string& api)
Julien Bonjean's avatar
Julien Bonjean committed
353
{
354
    Manager::instance().setAudioManager(api);
355
356
}

357
std::string ConfigurationManager::getAudioManager()
Julien Bonjean's avatar
Julien Bonjean committed
358
359
{
    return Manager::instance().getAudioManager();
360
361
}

362
void ConfigurationManager::setMailNotify()
Julien Bonjean's avatar
Julien Bonjean committed
363
364
{
    Manager::instance().setMailNotify();
365
366
}

367
int32_t ConfigurationManager::getMailNotify()
Julien Bonjean's avatar
Julien Bonjean committed
368
369
{
    return Manager::instance().getMailNotify();
370
}
371

372
std::map<std::string, int32_t> ConfigurationManager::getAddressbookSettings()
Julien Bonjean's avatar
Julien Bonjean committed
373
374
{
    return Manager::instance().getAddressbookSettings();
Emmanuel Milou's avatar
Emmanuel Milou committed
375
376
}

377
void ConfigurationManager::setAddressbookSettings(const std::map<std::string, int32_t>& settings)
Julien Bonjean's avatar
Julien Bonjean committed
378
{
379
    Manager::instance().setAddressbookSettings(settings);
Emmanuel Milou's avatar
Emmanuel Milou committed
380
}
381

382
std::vector<std::string> ConfigurationManager::getAddressbookList()
Julien Bonjean's avatar
Julien Bonjean committed
383
384
{
    return Manager::instance().getAddressbookList();
385
386
}

387
void ConfigurationManager::setAddressbookList(
Julien Bonjean's avatar
Julien Bonjean committed
388
389
    const std::vector<std::string>& list)
{
390
    Manager::instance().setAddressbookList(list);
391
392
}

393
std::map<std::string, std::string> ConfigurationManager::getHookSettings()
Julien Bonjean's avatar
Julien Bonjean committed
394
{
395
    return Manager::instance().hookPreference.toMap();
396
397
}

398
void ConfigurationManager::setHookSettings(const std::map<std::string,
Julien Bonjean's avatar
Julien Bonjean committed
399
400
        std::string>& settings)
{
401
    Manager::instance().hookPreference = HookPreference(settings);
402
}
403

404
void ConfigurationManager::setAccountsOrder(const std::string& order)
Julien Bonjean's avatar
Julien Bonjean committed
405
{
406
    Manager::instance().setAccountsOrder(order);
407
408
}

409
std::vector<std::map<std::string, std::string> > ConfigurationManager::getHistory()
410
411
412
413
{
    return Manager::instance().getHistory();
}

414
415
std::string
ConfigurationManager::getAddrFromInterfaceName(const std::string& interface)
Julien Bonjean's avatar
Julien Bonjean committed
416
{
417
    return SipTransport::getInterfaceAddrFromName(interface);
418
419
}

420
std::vector<std::string> ConfigurationManager::getAllIpInterface()
Julien Bonjean's avatar
Julien Bonjean committed
421
{
422
    return SipTransport::getAllIpInterface();
423
}
424

425
std::vector<std::string> ConfigurationManager::getAllIpInterfaceByName()
Julien Bonjean's avatar
Julien Bonjean committed
426
{
427
    return SipTransport::getAllIpInterfaceByName();
428
}
429

Julien Bonjean's avatar
Julien Bonjean committed
430
431
432
std::map<std::string, std::string> ConfigurationManager::getShortcuts()
{
    return Manager::instance().shortcutPreferences.getShortcuts();
433
434
}

435
void ConfigurationManager::setShortcuts(
Julien Bonjean's avatar
Julien Bonjean committed
436
437
    const std::map<std::string, std::string>& shortcutsMap)
{
438
    Manager::instance().shortcutPreferences.setShortcuts(shortcutsMap);
Julien Bonjean's avatar
Julien Bonjean committed
439
    Manager::instance().saveConfig();
440
}
441

442
443
std::vector<std::map<std::string, std::string> > ConfigurationManager::getCredentials(
    const std::string& accountID)
444
{
445
    SIPAccount *account = dynamic_cast<SIPAccount*>(Manager::instance().getAccount(accountID));
446
    std::vector<std::map<std::string, std::string> > credentialInformation;
447

448
    if (!account)
449
        return credentialInformation;
450
451
    else
        return account->getCredentials();
452
453
}

454
void ConfigurationManager::setCredentials(const std::string& accountID,
455
456
        const std::vector<std::map<std::string, std::string> >& details)
{
457
458
459
    SIPAccount *account = dynamic_cast<SIPAccount*>(Manager::instance().getAccount(accountID));
    if (account)
        account->setCredentials(details);
460
}