diff --git a/sflphone-client-gnome/src/actions.c b/sflphone-client-gnome/src/actions.c index 44c4a783e90c8f628870b707c7c00843b7005e44..846eaf0c62d1a333199f48c9fc03b6f4b0123f9b 100644 --- a/sflphone-client-gnome/src/actions.c +++ b/sflphone-client-gnome/src/actions.c @@ -203,22 +203,28 @@ void sflphone_fill_account_list (void) { gchar** array; gchar** accountID; unsigned int i; - int count; - GQueue *codeclist; - - DEBUG("SFLphone: Fill account list"); + int count; + GQueue *codeclist; - count = current_account_get_message_number (); + DEBUG("SFLphone: Fill account list"); + + count = current_account_get_message_number (); account_list_clear (); array = (gchar **)dbus_account_list(); if(array) { + /* + if(!(*accountID)) + DEBUG("hhhhhhhhhmmmmmmmmmmmm"); + */ + for (accountID = array; *accountID; accountID++) { account_t * a = g_new0(account_t,1); a->accountID = g_strdup(*accountID); + DEBUG("------------------- Account ID %s", a->accountID); a->credential_information = NULL; // TODO Clean codec list QUEUE account_list_add(a); diff --git a/sflphone-client-gnome/src/dbus/dbus.c b/sflphone-client-gnome/src/dbus/dbus.c index 9265e1f53db302a6ac4ef971d70be4eeee5f0f13..b3d4dc16f1fdc13eb78c645018bd154f39223673 100644 --- a/sflphone-client-gnome/src/dbus/dbus.c +++ b/sflphone-client-gnome/src/dbus/dbus.c @@ -893,6 +893,8 @@ dbus_account_details(gchar * accountID) GError *error = NULL; GHashTable * details; + DEBUG("Dbus: Get account detail accountid %s", accountID); + if (!org_sflphone_SFLphone_ConfigurationManager_get_account_details( configurationManagerProxy, accountID, &details, &error)) { diff --git a/sflphone-common/configure.ac b/sflphone-common/configure.ac index 0cf89b3821fa0b9276e98b3003d8d6bb00f16080..01576155701cb5969c42f8b0170f339c6fdd2ef8 100644 --- a/sflphone-common/configure.ac +++ b/sflphone-common/configure.ac @@ -265,9 +265,24 @@ fi xml_CFLAGS= xml_LIBS=-lexpat - AC_SUBST(xml_CFLAGS) +AC_SUBST(xml_CFLAGS) AC_SUBST(xml_LIBS) +AC_CHECK_LIB([yaml], yaml_parser_initialize, + [AC_CHECK_HEADERS(expat.h, have_expat=true, have_expat=false)], + have_yaml = false) + +if ! $have_yaml; then +AC_MSG_ERROR([You need the eXpat xml parser] + [http://expat.sourceforge.net/]) +fi + +yaml_CFLAGS= +yaml_LIBS=-lyaml + +AC_SUBST(yaml_CFLAGS) +AC_SUBST(yaml_LIBS) + AC_CHECK_LIB([pthread], pthread_create, [AC_CHECK_HEADERS(pthread.h, have_pthread=true, have_pthread=false)], have_pthread=false) @@ -292,6 +307,7 @@ AC_SUBST(PCRE_CFLAGS) + # For the tools/, we need libdbus-c++ for the "build" architecture as well AM_CONDITIONAL(CROSS_COMPILING, test "$cross_compiling" = "yes") diff --git a/sflphone-common/sequenceParser.yml b/sflphone-common/sequenceParser.yml new file mode 100755 index 0000000000000000000000000000000000000000..48d5b8d777cbac3ffbb2660ef8e0ebd56d87ee8e --- /dev/null +++ b/sflphone-common/sequenceParser.yml @@ -0,0 +1,202 @@ +--- +accounts: + - id: IP2IP + alias: + username: + password: + hostname: + enable: true + type: SIP + expire: 3600 + interface: default + port: 5060 + mailbox: + publishAddr: 0.0.0.0 + publishPort: 5060 + sameasLocal: true + resolveOnce: false + codecs: 0/9/110/111/112/ + stunServer: stun.sflphone.org + stunEnabled: false + displayName: Alexandre Savard + credential: + count: 0 + srtp: + enable: false + keyExchange: sdes + rtpFallback: false + zrtp: + displaySas: false + displaySasOnce: false + helloHashEnabled: false + notSuppWarning: false + tls: + tlsPort: 5061 + certificate: + calist: + ciphers: + enable: false + method: TLSv1 + timeout: 0 + password: + privateKey: + requireCertif: false + server: + verifyClient: false + verifyServer: false + + - id: Account:1278432417 + alias: sfl-181 + username: 181 + password: sfl-181pw + hostname: 192.168.50.3 + enable: true + type: SIP + expire: 3600 + interface: default + port: 5060 + mailbox: 97 + publishAddr: 192.168.50.182 + publishPort: 5060 + sameasLocal: true + resolveOnce: false + codecs: 0/9/110/111/112/ + stunServer: stun.sflphone.org + stunEnabled: false + displayName: Alexandre Savard + credential: + count: 0 + srtp: + enable: false + keyExchange: sdes + rtpFallback: false + zrtp: + displaySas: false + displaySasOnce: false + helloHashEnabled: false + notSuppWarning: false + tls: + tlsPort: 5061 + certificate: /home/msavard/Development/sflphone/sflphone-client-gnome/config.guess + calist: /home/msavard/Development/sflphone/sflphone-client-gnome/aclocal.m4 + ciphers: + enable: false + method: TLSv1 + timeout: 0 + password: + privateKey: /home/msavard/Development/sflphone/sflphone-client-gnome/config.log + requireCertif: true + server: + verifyClient: true + verifyServer: true + + - id: Account:1278432440 + alias: sfl-431 + username: 431 + password: alexandre + hostname: mtl.savoirfairelinux.net + enable: false + type: SIP + expire: 3600 + interface: default + port: 5060 + mailbox: 97 + publishAddr: 0.0.0.0 + publishPort: 5060 + sameasLocal: true + resolveOnce: false + codecs: 0/9/110/111/112/ + stunServer: stun.sflphone.org + stunEnabled: false + displayName: Alexandre Savard + credential: + count: 0 + srtp: + enable: false + keyExchange: sdes + rtpFallback: false + zrtp: + displaySas: false + displaySasOnce: false + helloHashEnabled: false + notSuppWarning: false + tls: + tlsPort: 5061 + certificate: /home/msavard/Development/sflphone/sflphone-client-gnome/config.guess + calist: /home/msavard/Development/sflphone/sflphone-client-gnome/aclocal.m4 + ciphers: + enable: false + method: TLSv1 + timeout: 0 + password: + privateKey: /home/msavard/Development/sflphone/sflphone-client-gnome/config.log + requireCertif: true + server: + verifyClient: false + verifyServer: false + +addressbook: + photo: true + enabled: true + list: 1243608768.30329.0@emilou-desktop/1243456917.15690.23@emilou-desktop/ + maxResults: 25 + business: true + home: false + mobile: false + +audio: + alsa: + cardin: 0 + cardout: 0 + cardout: 0 + framesize: 20 + plugin: default + smplrate: 44100 + pulse: + devicePlayback: + deviceRecord: + deviceRingtone: + recordpath: /home/msavard/Bureau + ringchoice: /usr/share/sflphone/ringtones/konga.ul + volumemic: 100 + volumespkr: 100 + +hooks: + iax2Enabled: false + numberAddPrefix: false + numberEnabled: false + sipEnabled: false + urlCommand: x-www-browser + urlSipField: X-sflphone-url + +preferences: + order: Account:1278432440/Account:1278432417/ + audioApi: 0 + dialpadDisplay: 0 + historyEnabled: 1 + historyLimit: 30 + historyMaxCalls: 20 + notifyAll: true + notifyMails: false + zoneToneChoice: North America + registrationExpire: 180 + ringtoneEnabled: true + portNum: 5060 + searchBarDisplay: true + startHidden: 0 + volumeDisplay: 0 + windowHeight: 332 + windowPopup: 0 + windowPosition: 0 + windowWidth: 240 + zeroConfenable: false + md5Hash: false + +voipPreferences: + playDtmf: true + playTones: true + pulseLength: 250 + sendDtmfAs: 0 + symmetric: true + zidFile: sfl.zid +... \ No newline at end of file diff --git a/sflphone-common/src/Makefile.am b/sflphone-common/src/Makefile.am index 10950a290304ca4bfb9a69a28ae31562e9b453eb..d97477c85f4debd7a397253f4053b4ebeb966c89 100644 --- a/sflphone-common/src/Makefile.am +++ b/sflphone-common/src/Makefile.am @@ -10,6 +10,7 @@ sflphoned_SOURCES = \ conference.cpp \ voiplink.cpp \ main.cpp \ + preferences.cpp \ managerimpl.cpp \ managerimpl_registration.cpp \ observer.cpp \ @@ -47,6 +48,7 @@ noinst_LTLIBRARIES = libsflphone.la noinst_HEADERS = \ conference.h \ voiplink.h \ + preferences.h \ managerimpl.h \ manager.h \ global.h \ @@ -82,7 +84,8 @@ libsflphone_la_LDFLAGS = \ @PULSEAUDIO_LIBS@ \ @SAMPLERATE_LIBS@ \ @libssl_LIBS@ \ - @UUID_LIBS@ + @UUID_LIBS@ \ + @yaml_LIBS@ libsflphone_la_CFLAGS = \ @CCGNU2_CFLAGS@ \ @@ -94,7 +97,8 @@ libsflphone_la_CFLAGS = \ @PULSEAUDIO_CFLAGS@ \ @SAMPLERATE_CFLAGS@ \ @libssl_CFLAGS@ \ - @UUID_CFLAGS@ + @UUID_CFLAGS@ \ + @yaml_CFLAGS@ libsflphone_la_SOURCES = diff --git a/sflphone-common/src/account.cpp b/sflphone-common/src/account.cpp index 40da977a2050c990bd347218a8820daf6bdc36ad..329166a30dc21539def1d66ed28b8fe393e0a969 100644 --- a/sflphone-common/src/account.cpp +++ b/sflphone-common/src/account.cpp @@ -39,6 +39,7 @@ Account::Account (const AccountID& accountID, std::string type) : , _enabled (false) , _type (type) , _codecOrder () + , _startupCodecStr("") { setRegistrationState (Unregistered); } @@ -49,21 +50,13 @@ Account::~Account() void Account::loadConfig() { - std::string p; - - p = Manager::instance().getConfigString (_accountID , CONFIG_ACCOUNT_TYPE); -#ifdef USE_IAX - _enabled = (Manager::instance().getConfigString (_accountID, CONFIG_ACCOUNT_ENABLE) == "true") ? true : false; -#else - - if (p == "IAX") - _enabled = false; - else - _enabled = (Manager::instance().getConfigString (_accountID, CONFIG_ACCOUNT_ENABLE) == "true") ? true : false; - + // If IAX is not supported, do not register this account +#ifndef USE_IAX + if (_type == "IAX") + _enabled = false; #endif - loadAudioCodecs (); + loadAudioCodecs (); } void Account::setRegistrationState (RegistrationState state) { @@ -80,17 +73,16 @@ void Account::setRegistrationState (RegistrationState state) { void Account::loadAudioCodecs (void) { // if the user never set the codec list, use the default configuration for this account - if (Manager::instance ().getConfigString (_accountID, "ActiveCodecs") == "") { + if(_startupCodecStr == "") { _info ("Account: use the default order"); Manager::instance ().getCodecDescriptorMap ().setDefaultOrder(); } - // else retrieve the one set in the user config file else { std::vector<std::string> active_list = Manager::instance ().retrieveActiveCodecs(); // This property is now set per account basis - std::string s = Manager::instance ().getConfigString (_accountID, "ActiveCodecs"); - setActiveCodecs (Manager::instance ().unserialize (s)); + // std::string s = Manager::instance ().getConfigString (_accountID, "ActiveCodecs"); + setActiveCodecs (Manager::instance ().unserialize (_startupCodecStr)); } } diff --git a/sflphone-common/src/account.h b/sflphone-common/src/account.h index 80bfbd36ba1838b9e0c2d6dc482b3185f3e44219..5120bfd8297988b5294319dd0a9472cc8be35a09 100644 --- a/sflphone-common/src/account.h +++ b/sflphone-common/src/account.h @@ -37,6 +37,7 @@ #include "config/config.h" #include "voiplink.h" +#include "config/serializable.h" class VoIPLink; @@ -131,7 +132,21 @@ typedef enum RegistrationState { #define REGISTRATION_STATE_DESCRIPTION "Registration.description" -class Account{ +// General configuration keys for accounts +const Conf::Key aliasKey("alias"); +const Conf::Key typeKey("type"); +const Conf::Key idKey("id"); +const Conf::Key usernameKey("username"); +const Conf::Key passwordKey("password"); +const Conf::Key hostnameKey("hostname"); +const Conf::Key accountEnableKey("enable"); +const Conf::Key mailboxKey("mailbox"); + +const Conf::Key codecsKey("codecs"); // 0/9/110/111/112/ + +#define find_in_map(X, Y) if((iter = map_cpy.find(X)) != map_cpy.end()) { Y = iter->second; } + +class Account : public Serializable{ public: @@ -142,6 +157,15 @@ class Account{ */ virtual ~Account(); + virtual void serialize(Conf::YamlEmitter *emitter) = 0; + + virtual void unserialize(Conf::MappingNode *map) = 0; + + virtual void setAccountDetails(const std::map<std::string, std::string>& details) = 0; + + virtual std::map<std::string, std::string> getAccountDetails() = 0; + + /** * Load the settings for this account. */ @@ -180,6 +204,8 @@ class Account{ */ bool isEnabled() { return _enabled; } + void setEnabled(bool enabl) { _enabled = enabl; } + /** * Get the registration state of the specified link * @return RegistrationState The registration state of underlying VoIPLink @@ -228,13 +254,13 @@ class Account{ inline std::string getType( void ) { return _type; } inline void setType( std::string type ) { _type = type; } - /** - * Accessor to data structures - * @return CodecOrder& The list that reflects the user's choice - */ - inline CodecOrder& getActiveCodecs() { return _codecOrder; } - - void setActiveCodecs (const std::vector <std::string>& list); + /** + * Accessor to data structures + * @return CodecOrder& The list that reflects the user's choice + */ + inline CodecOrder& getActiveCodecs() { return _codecOrder; } + + void setActiveCodecs (const std::vector <std::string>& list); private: // copy constructor @@ -243,7 +269,7 @@ class Account{ // assignment operator Account& operator=(const Account& rh); - void loadAudioCodecs (void); + void loadAudioCodecs (void); protected: /** @@ -301,10 +327,16 @@ class Account{ */ std::pair<int, std::string> _registrationStateDetailed; - /** - * Vector containing the order of the codecs - */ - CodecOrder _codecOrder; + /** + * Vector containing the order of the codecs + */ + CodecOrder _codecOrder; + + /** + * List of codec obtained when parsing configuration and used + * to generate codec order list, should not be used elsewhere. + */ + std::string _startupCodecStr; }; diff --git a/sflphone-common/src/accountcreator.cpp b/sflphone-common/src/accountcreator.cpp index c0b2abc383a972223cff6d44928d7c916f00b1be..91adfdb3901562f20537e132fba3cdb4141ef665 100644 --- a/sflphone-common/src/accountcreator.cpp +++ b/sflphone-common/src/accountcreator.cpp @@ -50,13 +50,17 @@ AccountCreator::createAccount (AccountType type, AccountID accountID) { switch (type) { - case SIP_ACCOUNT: - return new SIPAccount (accountID); - break; + case SIP_ACCOUNT: { + _debug("createaccount accountID %s", accountID.c_str()); + return new SIPAccount (accountID); + } + break; - case SIP_DIRECT_IP_ACCOUNT: - return new SIPAccount (IP2IP_PROFILE); - break; + case SIP_DIRECT_IP_ACCOUNT: { + _debug("createaccount accountID IP2IP_PROFILE"); + return new SIPAccount (IP2IP_PROFILE); + break; + } #ifdef USE_IAX case IAX_ACCOUNT: diff --git a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp old mode 100644 new mode 100755 index e8294513e28dbe42875a979c3a672956b7717e5e..403ec11ad0f1ac9f68fd676c4553fc28754e57a5 --- a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp +++ b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp @@ -521,9 +521,9 @@ bool PulseLayer::createStreams (pa_context* c) // _debug("Device list size %d", getDevicelist()->size()); - std::string playbackDevice = _manager->getConfigString(AUDIO, PULSE_DEVICE_PLAYBACK); - std::string recordDevice = _manager->getConfigString(AUDIO, PULSE_DEVICE_PLAYBACK); - std::string ringtoneDevice = _manager->getConfigString(AUDIO, PULSE_DEVICE_PLAYBACK); + std::string playbackDevice = _manager->audioPreference.getDevicePlayback(); + std::string recordDevice = _manager->audioPreference.getDeviceRecord(); + std::string ringtoneDevice = _manager->audioPreference.getDeviceRingtone(); _debug("Audio: Device stored in config for playback: %s", playbackDevice.c_str()); _debug("Audio: Device stored in config for ringtone: %s", recordDevice.c_str()); @@ -617,8 +617,8 @@ void PulseLayer::closeCaptureStream (void) if (record) { std::string deviceName(pa_stream_get_device_name(record->pulseStream())); - _debug("record device to be stored in config: %s", deviceName.c_str()); - _manager->setConfig(AUDIO, PULSE_DEVICE_RECORD, deviceName); + _debug("Audio: record device to be stored in config: %s", deviceName.c_str()); + _manager->audioPreference.setDeviceRecord(deviceName); delete record; record=NULL; } @@ -629,16 +629,16 @@ void PulseLayer::closePlaybackStream (void) { if (playback) { std::string deviceName(pa_stream_get_device_name(playback->pulseStream())); - _debug("playback device to be stored in config: %s", deviceName.c_str()); - _manager->setConfig(AUDIO, PULSE_DEVICE_PLAYBACK, deviceName); + _debug("Audio: playback device to be stored in config: %s", deviceName.c_str()); + _manager->audioPreference.setDevicePlayback(deviceName); delete playback; playback=NULL; } if(ringtone) { std::string deviceName(pa_stream_get_device_name(ringtone->pulseStream())); - _debug("ringtone device to be stored in config: %s", deviceName.c_str()); - _manager->setConfig(AUDIO, PULSE_DEVICE_RINGTONE, deviceName); + _debug("Audio: ringtone device to be stored in config: %s", deviceName.c_str()); + _manager->audioPreference.setDeviceRingtone(deviceName); delete ringtone; ringtone = NULL; } diff --git a/sflphone-common/src/config/Makefile.am b/sflphone-common/src/config/Makefile.am old mode 100644 new mode 100755 index d72225850fc3415ab1c5818cace8bc740401fe29..4d84e41e5949827722e41beb10127edf8d1bd7d8 --- a/sflphone-common/src/config/Makefile.am +++ b/sflphone-common/src/config/Makefile.am @@ -3,4 +3,21 @@ SUBDIRS = noinst_LTLIBRARIES = libconfig.la libconfig_la_SOURCES = \ - config.cpp config.h + config.cpp \ + yamlengine.cpp \ + yamlemitter.cpp \ + yamlparser.cpp \ + yamlnode.cpp + +noinst_HEADERS = \ + config.h \ + engine.h \ + serializable.h \ + yamlengine.h \ + yamlemitter.h \ + yamlparser.h \ + yamlnode.h + +libconfig_la_LDFLAGS = @yaml_LIBS@ + +libconfig_la_CFLAGS = @yaml_CFLAGS@ \ No newline at end of file diff --git a/sflphone-common/src/config/config.cpp b/sflphone-common/src/config/config.cpp old mode 100644 new mode 100755 index 83bba767b1e7ff66891c2836485f68ddc7f8f966..9f735964de9e45de8aa005817d8b7b714f6d13ac --- a/sflphone-common/src/config/config.cpp +++ b/sflphone-common/src/config/config.cpp @@ -38,6 +38,7 @@ #include <errno.h> #include <iostream> #include <string.h> +#include "yamlparser.h" namespace Conf { @@ -50,6 +51,7 @@ ConfigTree::ConfigTree() :_sections() // dtor ConfigTree::~ConfigTree() { + // erase every new ItemMap (by CreateSection) SectionMap::iterator iter = _sections.begin(); diff --git a/sflphone-common/src/config/config.h b/sflphone-common/src/config/config.h old mode 100644 new mode 100755 diff --git a/sflphone-common/src/config/engine.h b/sflphone-common/src/config/engine.h new file mode 100755 index 0000000000000000000000000000000000000000..c2345b656e73cca9c4af7258fbd6779d2a185dce --- /dev/null +++ b/sflphone-common/src/config/engine.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc. + * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * 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. + * + * 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. + * + * 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. + */ + +#ifndef __ENGINE_H__ +#define __ENGINE_H__ + +#include <yaml.h> + +class Engine { + + public: + + virtual void open() = 0; + + virtual void close() = 0; + + virtual void write() = 0; + + virtual void read() = 0; + +}; + +#endif diff --git a/sflphone-common/src/config/serializable.h b/sflphone-common/src/config/serializable.h new file mode 100755 index 0000000000000000000000000000000000000000..e9b88cc84c1059c1a917b0f86b971a6bcc401ab9 --- /dev/null +++ b/sflphone-common/src/config/serializable.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc. + * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * 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. + * + * 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. + * + * 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. + */ + +#ifndef __SERIALIZABLE_H__ +#define __SERIALIZABLE_H__ + + +#include "yamlparser.h" +#include "yamlemitter.h" +#include "yamlnode.h" + +class Engine; +// class MappingNode; + +class Serializable { + + public: + + virtual void serialize(Conf::YamlEmitter *emitter) = 0; + + virtual void unserialize(Conf::MappingNode *map) = 0; + + private: + +}; + +#endif diff --git a/sflphone-common/src/config/yamlemitter.cpp b/sflphone-common/src/config/yamlemitter.cpp new file mode 100755 index 0000000000000000000000000000000000000000..507fd35ffbf530e2465f3cdc11f38500841f6a98 --- /dev/null +++ b/sflphone-common/src/config/yamlemitter.cpp @@ -0,0 +1,338 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc. + * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * 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. + * + * 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. + * + * 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. + */ + +#include "yamlemitter.h" +#include <stdio.h> +#include "../global.h" + +namespace Conf { + +YamlEmitter::YamlEmitter(const char *file) : filename(file), isFirstAccount(true) +{ + open(); +} + +YamlEmitter::~YamlEmitter() +{ + close(); +} + +void YamlEmitter::open() +{ + fd = fopen(filename.c_str(), "wb"); + + if(!fd) + throw YamlEmitterException("Could not open file descriptor"); + + if(!yaml_emitter_initialize(&emitter)) + throw YamlEmitterException("Could not initialize emitter"); + + // Use unicode format + yaml_emitter_set_unicode(&emitter, 1); + + yaml_emitter_set_output_file(&emitter, fd); + + yaml_document_initialize(&document, NULL, NULL, NULL, 0, 0); + + // Init the main configuration mapping + if((topLevelMapping = yaml_document_add_mapping (&document, NULL, YAML_BLOCK_MAPPING_STYLE)) == 0) + throw YamlEmitterException("Could not create top level mapping"); +} + +void YamlEmitter::close() +{ + // yaml_emitter_delete(&emitter); + + if(!fd) + throw YamlEmitterException("File descriptor not valid"); + + fclose(fd); + /* + if(!fclose(fd)) + throw YamlEmitterException("Error closing file descriptor"); + */ + + yaml_document_delete(&document); +} + +void YamlEmitter::read() {} + +void YamlEmitter::write() +{ + +} + +void YamlEmitter::serializeData() +{ + yaml_emitter_dump(&emitter, &document); +} + + +void YamlEmitter::serializeAccount(MappingNode *map) +{ + + std::string accountstr("accounts"); + + int accountid, accountmapping; + + _debug("YamlEmitter: Serialize account"); + + if(map->getType() != MAPPING) + throw YamlEmitterException("Node type is not a mapping while writing account"); + + if(isFirstAccount) { + // accountSequence need to be static outside this scope since reused each time an account is written + if((accountid = yaml_document_add_scalar(&document, NULL, (yaml_char_t *)accountstr.c_str(), -1, YAML_PLAIN_SCALAR_STYLE)) == 0) + throw YamlEmitterException("Could not add preference scalar to document"); + + if((accountSequence = yaml_document_add_sequence (&document, NULL, YAML_BLOCK_SEQUENCE_STYLE)) == 0) + throw YamlEmitterException("Could not add sequence to document"); + + if(!yaml_document_append_mapping_pair (&document, topLevelMapping, accountid, accountSequence)) + throw YamlEmitterException("Could not add mapping pair to top level mapping"); + + isFirstAccount = false; + } + + if((accountmapping = yaml_document_add_mapping (&document, NULL, YAML_BLOCK_MAPPING_STYLE)) == 0) + throw YamlEmitterException("Could not add account mapping to document"); + + if(!yaml_document_append_sequence_item (&document, accountSequence, accountmapping)) + throw YamlEmitterException("Could not append account mapping to sequence"); + + Mapping *internalmap = map->getMapping(); + Mapping::iterator iter = internalmap->begin(); + + while(iter != internalmap->end()) { + addMappingItem(accountmapping, iter->first, iter->second); + iter++; + } + +} + +void YamlEmitter::serializePreference(MappingNode *map) +{ + std::string preferencestr("preferences"); + + int preferenceid, preferencemapping; + + _debug("YamlEmitter: Serialize preference"); + + if(map->getType() != MAPPING) + throw YamlEmitterException("Node type is not a mapping while writing preferences"); + + if((preferenceid = yaml_document_add_scalar(&document, NULL, (yaml_char_t *)preferencestr.c_str(), -1, YAML_PLAIN_SCALAR_STYLE)) == 0) + throw YamlEmitterException("Could not add scalar to document"); + + if((preferencemapping = yaml_document_add_mapping (&document, NULL, YAML_BLOCK_MAPPING_STYLE)) == 0) + throw YamlEmitterException("Could not add mapping to document"); + + if(!yaml_document_append_mapping_pair (&document, topLevelMapping, preferenceid, preferencemapping)) + throw YamlEmitterException("Could not add mapping pair to top leve mapping"); + + Mapping *internalmap = map->getMapping(); + Mapping::iterator iter = internalmap->begin(); + + while(iter != internalmap->end()) { + addMappingItem(preferencemapping, iter->first, iter->second); + iter++; + } + +} + +void YamlEmitter::serializeVoipPreference(MappingNode *map) +{ + std::string preferencestr("voipPreferences"); + + int preferenceid, preferencemapping; + + _debug("YamlEmitter: Serialize voip preference"); + + if(map->getType() != MAPPING) + throw YamlEmitterException("Node type is not a mapping while writing preferences"); + + if((preferenceid = yaml_document_add_scalar(&document, NULL, (yaml_char_t *)preferencestr.c_str(), -1, YAML_PLAIN_SCALAR_STYLE)) == 0) + throw YamlEmitterException("Could not add scalar to document"); + + if((preferencemapping = yaml_document_add_mapping (&document, NULL, YAML_BLOCK_MAPPING_STYLE)) == 0) + throw YamlEmitterException("Could not add mapping to document"); + + if(!yaml_document_append_mapping_pair (&document, topLevelMapping, preferenceid, preferencemapping)) + throw YamlEmitterException("Could not add mapping pair to top leve mapping"); + + Mapping *internalmap = map->getMapping(); + Mapping::iterator iter = internalmap->begin(); + + while(iter != internalmap->end()) { + addMappingItem(preferencemapping, iter->first, iter->second); + iter++; + } + +} + +void YamlEmitter::serializeAddressbookPreference(MappingNode *map) +{ + std::string preferencestr("addressbook"); + + int preferenceid, preferencemapping; + + _debug("YamlEmitter: Serialize addressbook preferences"); + + if(map->getType() != MAPPING) + throw YamlEmitterException("Node type is not a mapping while writing preferences"); + + if((preferenceid = yaml_document_add_scalar(&document, NULL, (yaml_char_t *)preferencestr.c_str(), -1, YAML_PLAIN_SCALAR_STYLE)) == 0) + throw YamlEmitterException("Could not add scalar to document"); + + if((preferencemapping = yaml_document_add_mapping (&document, NULL, YAML_BLOCK_MAPPING_STYLE)) == 0) + throw YamlEmitterException("Could not add mapping to document"); + + if(!yaml_document_append_mapping_pair (&document, topLevelMapping, preferenceid, preferencemapping)) + throw YamlEmitterException("Could not add mapping pair to top leve mapping"); + + Mapping *internalmap = map->getMapping(); + Mapping::iterator iter = internalmap->begin(); + + while(iter != internalmap->end()) { + addMappingItem(preferencemapping, iter->first, iter->second); + iter++; + } + +} + +void YamlEmitter::serializeHooksPreference(MappingNode *map) +{ + std::string preferencestr("hooks"); + + int preferenceid, preferencemapping; + + _debug("YamlEmitter: Serialize hooks preferences"); + + if(map->getType() != MAPPING) + throw YamlEmitterException("Node type is not a mapping while writing preferences"); + + if((preferenceid = yaml_document_add_scalar(&document, NULL, (yaml_char_t *)preferencestr.c_str(), -1, YAML_PLAIN_SCALAR_STYLE)) == 0) + throw YamlEmitterException("Could not add scalar to document"); + + if((preferencemapping = yaml_document_add_mapping (&document, NULL, YAML_BLOCK_MAPPING_STYLE)) == 0) + throw YamlEmitterException("Could not add mapping to document"); + + if(!yaml_document_append_mapping_pair (&document, topLevelMapping, preferenceid, preferencemapping)) + throw YamlEmitterException("Could not add mapping pair to top leve mapping"); + + Mapping *internalmap = map->getMapping(); + Mapping::iterator iter = internalmap->begin(); + + while(iter != internalmap->end()) { + addMappingItem(preferencemapping, iter->first, iter->second); + iter++; + } + +} + + +void YamlEmitter::serializeAudioPreference(MappingNode *map) +{ + std::string preferencestr("audio"); + + int preferenceid, preferencemapping; + + _debug("YamlEmitter: Serialize hooks preferences"); + + if(map->getType() != MAPPING) + throw YamlEmitterException("Node type is not a mapping while writing preferences"); + + if((preferenceid = yaml_document_add_scalar(&document, NULL, (yaml_char_t *)preferencestr.c_str(), -1, YAML_PLAIN_SCALAR_STYLE)) == 0) + throw YamlEmitterException("Could not add scalar to document"); + + if((preferencemapping = yaml_document_add_mapping (&document, NULL, YAML_BLOCK_MAPPING_STYLE)) == 0) + throw YamlEmitterException("Could not add mapping to document"); + + if(!yaml_document_append_mapping_pair (&document, topLevelMapping, preferenceid, preferencemapping)) + throw YamlEmitterException("Could not add mapping pair to top leve mapping"); + + Mapping *internalmap = map->getMapping(); + Mapping::iterator iter = internalmap->begin(); + + while(iter != internalmap->end()) { + addMappingItem(preferencemapping, iter->first, iter->second); + iter++; + } + +} + + +void YamlEmitter::addMappingItem(int mappingid, Key key, YamlNode *node) +{ + + if(node->getType() == SCALAR) { + + int temp1, temp2; + + ScalarNode *sclr = (ScalarNode *)node; + + if((temp1 = yaml_document_add_scalar(&document, NULL, (yaml_char_t *)key.c_str(), -1, YAML_PLAIN_SCALAR_STYLE)) == 0) + throw YamlEmitterException("Could not add scalar to document"); + + if((temp2 = yaml_document_add_scalar(&document, NULL, (yaml_char_t *)sclr->getValue().c_str(), -1, YAML_PLAIN_SCALAR_STYLE)) == 0) + throw YamlEmitterException("Could not add scalar to document"); + + if(!yaml_document_append_mapping_pair (&document, mappingid, temp1, temp2)) + throw YamlEmitterException("Could not append mapping pair to mapping"); + + } + else if(node->getType() == MAPPING){ + + int temp1, temp2; + + if((temp1 = yaml_document_add_scalar(&document, NULL, (yaml_char_t *)key.c_str(), -1, YAML_PLAIN_SCALAR_STYLE)) == 0) + throw YamlEmitterException("Could not add scalar to document"); + + if((temp2 = yaml_document_add_mapping (&document, NULL, YAML_BLOCK_MAPPING_STYLE)) == 0) + throw YamlEmitterException("Could not add scalar to document"); + + if(!yaml_document_append_mapping_pair (&document, mappingid, temp1, temp2)) + throw YamlEmitterException("Could not add mapping pair to mapping"); + + MappingNode *map = (MappingNode *)node; + Mapping *internalmap = map->getMapping(); + Mapping::iterator iter = internalmap->begin(); + + while(iter != internalmap->end()) { + addMappingItem(temp2, iter->first, iter->second); + iter++; + } + } + else + throw YamlEmitterException("Unknown node type while adding mapping node"); +} + + +} diff --git a/sflphone-common/src/config/yamlemitter.h b/sflphone-common/src/config/yamlemitter.h new file mode 100755 index 0000000000000000000000000000000000000000..ddf098fdc9f43c45d08d24a2281108b628c66451 --- /dev/null +++ b/sflphone-common/src/config/yamlemitter.h @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc. + * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * 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. + * + * 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. + * + * 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. + */ + +#ifndef __YAMLEMITTER_H__ +#define __YAMLEMITTER_H__ + +#include <yaml.h> +#include <exception> +#include <string> +#include "yamlnode.h" + +namespace Conf { + +#define EMITTER_BUFFERSIZE 65536 +#define EMITTER_MAXEVENT 1024 + +class YamlEmitterException : public std::exception +{ + public: + YamlEmitterException(const std::string& str="") throw() : errstr(str) {} + + virtual ~YamlEmitterException() throw() {} + + virtual const char *what() const throw() { + std::string expt("YamlParserException occured: "); + expt.append(errstr); + + return expt.c_str(); + } + private: + std::string errstr; + +}; + +class YamlEmitter { + + public: + + YamlEmitter(const char *file); + + ~YamlEmitter(); + + void open(); + + void close(); + + void read(); + + void write(); + + void serializeAccount(MappingNode *map); + + void serializePreference(MappingNode *map); + + void serializeVoipPreference(MappingNode *map); + + void serializeAddressbookPreference(MappingNode *map); + + void serializeHooksPreference(MappingNode *map); + + void serializeAudioPreference(MappingNode *map); + + void writeAudio(); + + void writeHooks(); + + void writeVoiplink(); + + void serializeData(); + + private: + + void addMappingItem(int mappingid, Key key, YamlNode *node); + + std::string filename; + + FILE *fd; + + /** + * The parser structure. + */ + yaml_emitter_t emitter; + + /** + * The event structure array. + */ + yaml_event_t events[EMITTER_MAXEVENT]; + + /** + * + */ + unsigned char buffer[EMITTER_BUFFERSIZE]; + + + /** + * Main document for this serialization + */ + yaml_document_t document; + + /** + * Reference id to the top levell mapping when creating + */ + int topLevelMapping; + + /** + * We need to add the account sequence if this is the first account to be + */ + bool isFirstAccount; + + /** + * Reference to the account sequence + */ + int accountSequence; + + friend class ConfigurationTest; + +}; + +} + +#endif diff --git a/sflphone-common/src/config/yamlengine.cpp b/sflphone-common/src/config/yamlengine.cpp new file mode 100755 index 0000000000000000000000000000000000000000..30a2545bfdea02643916d02cbbef5565196335fa --- /dev/null +++ b/sflphone-common/src/config/yamlengine.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc. + * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * 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. + * + * 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. + * + * 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. + */ + +#include "yamlengine.h" +#include "../global.h" + + +namespace Conf { + +YamlEngine::YamlEngine() {} + +YamlEngine::~YamlEngine() {} + +void YamlEngine::openConfigFile() +{ + + Conf::YamlParser *parser; + + try { + parser = new Conf::YamlParser("sequence.yml"); + } + catch (Conf::YamlParserException &e) { + _error("ConfigTree: %s", e.what()); + } + + try { + parser->serializeEvents(); + } + catch(Conf::YamlParserException &e) { + _error("ConfigTree: %s", e.what()); + } + + try { + document = parser->composeEvents(); + } + catch(Conf::YamlParserException &e) { + _error("ConfigTree: %s", e.what()); + } + + try { + delete parser; + parser = NULL; + } + catch (Conf::YamlParserException &e) { + _error("ConfigTree: %s", e.what()); + } +} + +void YamlEngine::closeConfigFile() +{ + +} + +void YamlEngine::read() {} + +void YamlEngine::write() {} + +} diff --git a/sflphone-common/src/config/yamlengine.h b/sflphone-common/src/config/yamlengine.h new file mode 100755 index 0000000000000000000000000000000000000000..2997760bc2d96da4066c71e491e05f15ea083751 --- /dev/null +++ b/sflphone-common/src/config/yamlengine.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc. + * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * 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. + * + * 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. + * + * 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. + */ + +#ifndef __YAMLENGINE_H__ +#define __YAMLENGINE_H__ + +#include "engine.h" +#include "yamlnode.h" +#include "yamlparser.h" +#include "yamlemitter.h" +#include <exception> + +namespace Conf { + +class YamlEngineException : public std::exception { + + virtual const char *what() const throw() { + return "YamlEngineException occured"; + } +}; + +class YamlEngine : public Engine { + + public: + + YamlEngine(); + + ~YamlEngine(); + + virtual void openConfigFile(); + + virtual void closeConfigFile(); + + virtual void write(); + + virtual void read(); + + private: + + YamlParser *parser; + + YamlEmitter *emitter; + + YamlDocument *document; + +}; + +} + +#endif diff --git a/sflphone-common/src/config/yamlnode.cpp b/sflphone-common/src/config/yamlnode.cpp new file mode 100755 index 0000000000000000000000000000000000000000..c494ea04434b88c61608df1693d5d09a58ee8fae --- /dev/null +++ b/sflphone-common/src/config/yamlnode.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc. + * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * 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. + * + * 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. + * + * 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. + */ + +#include "yamlnode.h" +#include "src/global.h" + +namespace Conf { + + +void YamlDocument::addNode(YamlNode *node) +{ + Sequence::iterator it = doc.end(); + doc.insert(it, node); +} + +YamlNode *YamlDocument::popNode() +{ + Sequence::iterator it = doc.begin(); + YamlNode *node = doc.front(); + + //removed element's destructor is called + doc.pop_front(); + + return node; +} + +void MappingNode::addNode(YamlNode *node) +{ + Mapping::iterator it = map.end(); + map.insert(it, std::pair<Key, YamlNode *>(tmpKey, node)); +} + +void MappingNode::setKeyValue(Key key, YamlNode *value) +{ + Mapping::iterator it = map.end(); + map.insert(it, std::pair<Key, YamlNode *>(key, value)); +} + +void MappingNode::removeKeyValue(Key key) +{ + +Mapping::iterator it = map.find(key); + map.erase(it); +} + + +YamlNode *MappingNode::getValue(Key key) +{ + Mapping::iterator it = map.find(key); + + if(it != map.end()) { + return it->second; + } + else { + _debug("Could not fine %s", key.c_str()); + return NULL; + } +} + + +void SequenceNode::addNode(YamlNode *node) +{ + Sequence::iterator it = seq.end(); + seq.insert(it, node); +} + +} + diff --git a/sflphone-common/src/config/yamlnode.h b/sflphone-common/src/config/yamlnode.h new file mode 100755 index 0000000000000000000000000000000000000000..e341b355038910426e5a47d1c9569582178d3563 --- /dev/null +++ b/sflphone-common/src/config/yamlnode.h @@ -0,0 +1,182 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc. + * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * 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. + * + * 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. + * + * 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. + */ + +#ifndef __YAMLNODE_H__ +#define __YAMLNODE_H__ + +#include <string> +#include <list> +#include <map> +#include <exception> + +namespace Conf { + + +class YamlNode; + +typedef std::string Key; +typedef std::string Value; +typedef std::list<YamlNode *> Sequence; +typedef std::map<Key, YamlNode *> Mapping; + +class YamlNodeException : public std::exception +{ + + public: + YamlNodeException(const std::string& str="") throw() : errstr(str) {} + + virtual ~YamlNodeException() throw() {} + + virtual const char *what() const throw() { + std::string expt("YamlNodeException occured: "); + expt.append(errstr); + + return expt.c_str(); + } + private: + std::string errstr; + +}; + +enum NodeType { DOCUMENT, SCALAR, MAPPING, SEQUENCE }; + +class YamlNode { + + public: + + YamlNode(NodeType t, YamlNode *top=NULL) : type(t), topNode(top) {} + + ~YamlNode() {} + + NodeType getType() { return type; } + + YamlNode *getTopNode() { return topNode; } + + private: + + NodeType type; + + YamlNode *topNode; + +}; + + +class YamlDocument : YamlNode { + + public: + + YamlDocument(YamlNode* top=NULL) : YamlNode(DOCUMENT, top) {} + + ~YamlDocument() {} + + void addNode(YamlNode *node); + + YamlNode *popNode(void); + + Sequence *getSequence(void) { return &doc; } + + private: + + Sequence doc; + + }; + +class SequenceNode : public YamlNode { + + public: + + SequenceNode(YamlNode *top) : YamlNode(SEQUENCE, top) {} + + ~SequenceNode() {} + + Sequence *getSequence() { return &seq; } + + void addNode(YamlNode *node); + + private: + + Sequence seq; + +}; + + +class MappingNode : public YamlNode { + + public: + + MappingNode(YamlNode *top) : YamlNode(MAPPING, top) {} + + ~MappingNode() {} + + Mapping *getMapping() { return ↦ } + + void addNode(YamlNode *node); + + void setTmpKey(Key key) { tmpKey = key; } + + void setKeyValue(Key key, YamlNode *value); + + void removeKeyValue(Key key); + + YamlNode *getValue(Key key); + + private: + + Mapping map; + + Key tmpKey; + +}; + + +class ScalarNode : public YamlNode { + + public: + + ScalarNode(Value v="", YamlNode *top=NULL) : YamlNode(SCALAR, top), val(v) {} + + ~ScalarNode() {} + + Value getValue() { return val; } + + void setValue(Value v) { val = v; } + + private: + + Value val; + +}; + + +} + + + +#endif diff --git a/sflphone-common/src/config/yamlparser.cpp b/sflphone-common/src/config/yamlparser.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a132d08f7c8e0ac41b9e802e330ec3ebfef9caf2 --- /dev/null +++ b/sflphone-common/src/config/yamlparser.cpp @@ -0,0 +1,528 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc. + * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * 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. + * + * 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. + * + * 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. + */ + +#include "yamlparser.h" + +#include "../global.h" +#include "config.h" +#include "yamlnode.h" +#include <stdio.h> + +namespace Conf { + +YamlParser::YamlParser(const char *file) : filename(file) +{ + memset(buffer, 0, PARSER_BUFFERSIZE); + + open(); +} + +YamlParser::~YamlParser() +{ + close(); +} + +void YamlParser::open() +{ + + fd = fopen(filename.c_str(), "rb"); + + if(!fd) + throw YamlParserException("Could not open file descriptor"); + + if(!yaml_parser_initialize(&parser)) + throw YamlParserException("Could not open file descriptor"); + + yaml_parser_set_input_file(&parser, fd); +} + +void YamlParser::close() +{ + + yaml_parser_delete(&parser); + + if(!fd) + throw YamlParserException("File descriptor not valid"); + + fclose(fd); + // if(!fclose(fd)) + // throw YamlParserException("Error closing file descriptor"); + + +} + +void YamlParser::serializeEvents() +{ + bool done = false; + yaml_event_t event; + + while(!done) { + + if(!yaml_parser_parse(&parser, &event)) + throw YamlParserException("Error while parsing"); + + done = (event.type == YAML_STREAM_END_EVENT); + + if(eventNumber > PARSER_MAXEVENT) + throw YamlParserException("Reached maximum of event"); + + if(!copyEvent(&(events[eventNumber++]), &event)) + throw YamlParserException("Error copying event"); + + } +} + + +int YamlParser::copyEvent(yaml_event_t *event_to, yaml_event_t *event_from) +{ + + switch (event_from->type) { + case YAML_STREAM_START_EVENT: { + // _debug("YAML_STREAM_START_EVENT"); + return yaml_stream_start_event_initialize(event_to, + event_from->data.stream_start.encoding); + } + + case YAML_STREAM_END_EVENT: { + //_debug("YAML_STREAM_END_EVENT"); + return yaml_stream_end_event_initialize(event_to); + } + + case YAML_DOCUMENT_START_EVENT: { + // _debug("YAML_DOCUMENT_START_EVENT"); + return yaml_document_start_event_initialize(event_to, + event_from->data.document_start.version_directive, + event_from->data.document_start.tag_directives.start, + event_from->data.document_start.tag_directives.end, + event_from->data.document_start.implicit); + } + + case YAML_DOCUMENT_END_EVENT: { + // _debug("YAML_DOCUMENT_END_EVENT"); + return yaml_document_end_event_initialize(event_to, + event_from->data.document_end.implicit); + } + case YAML_ALIAS_EVENT:{ + // _debug("YAML_ALIAS_EVENT"); + return yaml_alias_event_initialize(event_to, + event_from->data.alias.anchor); + } + case YAML_SCALAR_EVENT: { + // _debug("YAML_SCALAR_EVENT"); + return yaml_scalar_event_initialize(event_to, + event_from->data.scalar.anchor, + event_from->data.scalar.tag, + event_from->data.scalar.value, + event_from->data.scalar.length, + event_from->data.scalar.plain_implicit, + event_from->data.scalar.quoted_implicit, + event_from->data.scalar.style); + } + case YAML_SEQUENCE_START_EVENT: { + // _debug("YAML_SEQUENCE_START_EVENT"); + return yaml_sequence_start_event_initialize(event_to, + event_from->data.sequence_start.anchor, + event_from->data.sequence_start.tag, + event_from->data.sequence_start.implicit, + event_from->data.sequence_start.style); + } + case YAML_SEQUENCE_END_EVENT: { + // _debug("YAML_SEQUENCE_END_EVENT"); + return yaml_sequence_end_event_initialize(event_to); + } + case YAML_MAPPING_START_EVENT: { + // _debug("YAML_MAPPING_START_EVENT"); + return yaml_mapping_start_event_initialize(event_to, + event_from->data.mapping_start.anchor, + event_from->data.mapping_start.tag, + event_from->data.mapping_start.implicit, + event_from->data.mapping_start.style); + } + case YAML_MAPPING_END_EVENT: { + // _debug("YAML_MAPPING_END_EVENT"); + return yaml_mapping_end_event_initialize(event_to); + + } + default: + assert(1); + + } + + return 0; +} + + +YamlDocument *YamlParser::composeEvents() { + + // _debug("YamlParser: Compose Events"); + + if(eventNumber == 0) + throw YamlParserException("No event available"); + + if(events[0].type != YAML_STREAM_START_EVENT) + throw YamlParserException("Parsing does not start with stream start"); + + eventIndex = 0; + + processStream(); + + return doc; +} + +void YamlParser::processStream () { + + // _debug("YamlParser: process stream"); + + while((eventIndex < eventNumber) && (events[eventIndex].type != YAML_STREAM_END_EVENT)) { + + if(events[eventIndex].type == YAML_DOCUMENT_START_EVENT) + processDocument(); + + eventIndex++; + } + + if(events[eventIndex].type != YAML_STREAM_END_EVENT) + throw YamlParserException("Did not found end of stream"); +} + + +void YamlParser::processDocument() +{ + // _debug("YamlParser: process document"); + + doc = new YamlDocument(); + + if(!doc) + throw YamlParserException("Not able to create new document"); + + while((eventIndex < eventNumber) && (events[eventIndex].type != YAML_DOCUMENT_END_EVENT)) { + + switch(events[eventIndex].type){ + case YAML_SCALAR_EVENT: + processScalar((YamlNode *)doc); + break; + case YAML_SEQUENCE_START_EVENT: + processSequence((YamlNode *)doc); + break; + case YAML_MAPPING_START_EVENT: + processMapping((YamlNode *)doc); + break; + default: + break; + } + + eventIndex++; + } + + if(events[eventIndex].type != YAML_DOCUMENT_END_EVENT) + throw YamlParserException("Did not found end of document"); + +} + + +void YamlParser::processScalar(YamlNode *topNode) +{ + + _debug("YamlParser: process scalar"); + + if(!topNode) + throw YamlParserException("No container for scalar"); + + char buffer[1000]; + snprintf(buffer, 1000, "%s", events[eventIndex].data.scalar.value); + _debug("and the scalar is: %s", buffer); + + ScalarNode *sclr = new ScalarNode(buffer, topNode); + + switch(topNode->getType()) { + case DOCUMENT: + ((YamlDocument *)(topNode))->addNode(sclr); + break; + case SEQUENCE: + ((SequenceNode *)(topNode))->addNode(sclr); + break; + case MAPPING: + ((MappingNode *)(topNode))->addNode(sclr); + case SCALAR: + default: + break; + } +} + + +void YamlParser::processSequence(YamlNode *topNode) +{ + _debug("YamlParser: process sequence"); + + if(!topNode) + throw YamlParserException("No container for sequence"); + + SequenceNode *seq = new SequenceNode(topNode); + + switch(topNode->getType()) { + case DOCUMENT: + ((YamlDocument *)(topNode))->addNode(seq); + break; + case SEQUENCE: + ((SequenceNode *)(topNode))->addNode(seq); + break; + case MAPPING: + ((MappingNode *)(topNode))->addNode(seq); + case SCALAR: + default: + break; + } + + eventIndex++; + + while((eventIndex < eventNumber) && (events[eventIndex].type != YAML_SEQUENCE_END_EVENT)) { + + switch(events[eventIndex].type){ + case YAML_SCALAR_EVENT: + processScalar(seq); + break; + case YAML_SEQUENCE_START_EVENT: + processSequence(seq); + break; + case YAML_MAPPING_START_EVENT: + processMapping(seq); + break; + default: + break; + } + + eventIndex++; + } + + if(events[eventIndex].type != YAML_SEQUENCE_END_EVENT) + throw YamlParserException("Did not found end of sequence"); +} + + +void YamlParser::processMapping(YamlNode *topNode) +{ + _debug("YamlParser: process mapping -----------------------------------------"); + + if(!topNode) + throw YamlParserException("No container for mapping"); + + MappingNode *map = new MappingNode(topNode); + + switch(topNode->getType()) { + case DOCUMENT: + ((YamlDocument *)(topNode))->addNode(map); + break; + case SEQUENCE: + ((SequenceNode *)(topNode))->addNode(map); + break; + case MAPPING: + ((MappingNode *)(topNode))->addNode(map); + case SCALAR: + default: + break; + } + + eventIndex++; + + while((eventIndex < eventNumber) && (events[eventIndex].type != YAML_MAPPING_END_EVENT)) { + + if(events[eventIndex].type != YAML_SCALAR_EVENT) + throw YamlParserException("Mapping not followed by a key"); + + char buffer[1000]; + snprintf(buffer, 1000, "%s", events[eventIndex].data.scalar.value); + map->setTmpKey(Key(buffer)); + _debug("KEY %s", buffer); + + eventIndex++; + + switch(events[eventIndex].type){ + case YAML_SCALAR_EVENT: + processScalar(map); + break; + case YAML_SEQUENCE_START_EVENT: + processSequence(map); + break; + case YAML_MAPPING_START_EVENT: + processMapping(map); + break; + default: + break; + } + + eventIndex++; + } + + if(events[eventIndex].type != YAML_MAPPING_END_EVENT) + throw YamlParserException("Did not found end of mapping"); +} + +void YamlParser::constructNativeData() { + + Sequence *seq; + + seq = doc->getSequence(); + + Sequence::iterator iter = seq->begin(); + + while(iter != seq->end()) { + + switch((*iter)->getType()){ + case SCALAR: + _debug("construct scalar"); + throw YamlParserException("No scalar allowed at document level, expect a mapping"); + break; + case SEQUENCE: + _debug("construct sequence"); + throw YamlParserException("No sequence allowed at document level, expect a mapping"); + break; + case MAPPING: { + _debug("construct mapping"); + MappingNode *map = (MappingNode *)(*iter); + mainNativeDataMapping(map); + break; + } + default: + throw YamlParserException("Unknown type in configuration file, expect a mapping"); + break; + } + iter++; + + } + +} + + +void YamlParser::mainNativeDataMapping(MappingNode *map) { + + + Mapping::iterator iter = map->getMapping()->begin(); + + Key accounts("accounts"); + Key addressbook("addressbook"); + Key audio("audio"); + Key hooks("hooks"); + Key preferences("preferences"); + Key voiplink("voipPreferences"); + + while(iter != map->getMapping()->end()) { + + _debug("Iterating: %s", iter->first.c_str()); + if(accounts.compare(iter->first) == 0) { + _debug("Adding voip account sequence"); + accountSequence = (SequenceNode *)(iter->second); + } + else if(addressbook.compare(iter->first) == 0) { + _debug("Adding voip addressbook sequence"); + addressbookSequence = (SequenceNode *)(iter->second); + } + else if(audio.compare(iter->first) == 0) { + _debug("Adding voip audio sequence"); + audioSequence = (SequenceNode *)(iter->second); + } + else if(hooks.compare(iter->first) == 0) { + _debug("Adding voip hooks sequence"); + hooksSequence = (SequenceNode *)(iter->second); + } + else if(preferences.compare(iter->first) == 0) { + _debug("Adding voip preference sequence"); + preferenceSequence = (SequenceNode *)(iter->second); + } + else if(voiplink.compare(iter->first) == 0) { + _debug("Adding voip voip sequence"); + voiplinkSequence = (SequenceNode *)(iter->second); + } + else + throw YamlParserException("Unknow map key in configuration"); + + iter++; + } + _debug("Done"); +} + + /* +void YamlParser::buildAccounts(SequenceNode *seq) { + + // Each element in sequence is a new account to create + Sequence::iterator iterSeq = seq->getSequence()->begin(); + + MappingNode *map; + + Key accTypeKey("type"); + while(iterSeq != seq->getSequence()->end()) { + + map = (MappingNode *)(*iterSeq); + + ScalarNode * val = (ScalarNode *)(map->getValue(accTypeKey)); + Value accountType = val->getValue(); + + iterSeq++; + + if (accountType == "sip") { + // tmpAccount = AccountCreator::createAccount(AccountCreator::SIP_ACCOUNT, *iter); + _debug("Account is SIP!!!"); + } + else if (accountType == "iax") { + // tmpAccount = AccountCreator::createAccount(AccountCreator::IAX_ACCOUNT, *iter); + } + + + std::string accountType; + + accountType = getConfigString(*iter, CONFIG_ACCOUNT_TYPE); + + if (accountType == "SIP") { + tmpAccount = AccountCreator::createAccount( + AccountCreator::SIP_ACCOUNT, *iter); + } + + else if (accountType == "IAX") { + tmpAccount = AccountCreator::createAccount( + AccountCreator::IAX_ACCOUNT, *iter); + } + + else { + _error ("Unknown %s param in config file (%s)", CONFIG_ACCOUNT_TYPE, accountType.c_str()); + } + + if (tmpAccount != NULL) { + _debug ("Loading account %s ", iter->c_str()); + _accountMap[iter->c_str()] = tmpAccount; + // tmpAccount->setVoIPLink(SIPVoIPLink::instance ("")); + tmpAccount->setVoIPLink(); + nbAccount++; + } + + iter++; + */ +// } + +//} +} diff --git a/sflphone-common/src/config/yamlparser.h b/sflphone-common/src/config/yamlparser.h new file mode 100644 index 0000000000000000000000000000000000000000..5a3de72479f98e501e8acc84c1ef5407b9e9ccc6 --- /dev/null +++ b/sflphone-common/src/config/yamlparser.h @@ -0,0 +1,158 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc. + * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * 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. + * + * 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. + * + * 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. + */ + +#ifndef __YAMLPARSER_H__ +#define __YAMLPARSER_H__ + +#include "yamlnode.h" +#include <yaml.h> +#include <stdio.h> +#include <exception> +#include <string> + +namespace Conf { + +#define PARSER_BUFFERSIZE 65536 +#define PARSER_MAXEVENT 1024 + +class YamlParserException : public std::exception +{ + public: + YamlParserException(const std::string& str="") throw() : errstr(str) {} + + virtual ~YamlParserException() throw() {} + + virtual const char *what() const throw() { + std::string expt("YamlParserException occured: "); + expt.append(errstr); + + return expt.c_str(); + } + private: + std::string errstr; +}; + + +class YamlParser { + + public: + + YamlParser(const char *file); + + ~YamlParser(); + + void open(); + + void close(); + + void serializeEvents(); + + YamlDocument *composeEvents(); + + void constructNativeData(); + + SequenceNode *getAccountSequence(void) { return accountSequence; }; + + SequenceNode *getPreferenceSequence(void) { return preferenceSequence; } + + SequenceNode *getAddressbookSequence(void) { return addressbookSequence; } + + SequenceNode *getAudioSequence(void) { return audioSequence; } + + SequenceNode *getHookSequence(void) { return hooksSequence; } + + SequenceNode *getVoipPreferenceSequence(void) { return voiplinkSequence; } + + private: + + /** + * Copy yaml parser event in event_to according to their type. + */ + int copyEvent(yaml_event_t *event_to, yaml_event_t *event_from); + + void processStream(void); + + void processDocument(void); + + void processScalar(YamlNode *topNode); + + void processSequence(YamlNode *topNode); + + void processMapping(YamlNode *topNode); + + void mainNativeDataMapping(MappingNode *map); + + // void buildAccounts(SequenceNode *map); + + std::string filename; + + FILE *fd; + + /** + * The parser structure. + */ + yaml_parser_t parser; + + /** + * The event structure array. + */ + yaml_event_t events[PARSER_MAXEVENT]; + + /** + * + */ + unsigned char buffer[PARSER_BUFFERSIZE]; + + /** + * Number of event actually parsed + */ + int eventNumber; + + YamlDocument *doc; + + int eventIndex; + + SequenceNode *accountSequence; + + SequenceNode *preferenceSequence; + + SequenceNode *addressbookSequence; + + SequenceNode *audioSequence; + + SequenceNode *hooksSequence; + + SequenceNode *voiplinkSequence; + +}; + +} + +#endif diff --git a/sflphone-common/src/dbus/configurationmanager-introspec.xml b/sflphone-common/src/dbus/configurationmanager-introspec.xml old mode 100644 new mode 100755 index f75d22c662e8b34451ef22540ec124e3c7f25b08..75b3413d66e869bdd0ca9113de853aa8727414e2 --- a/sflphone-common/src/dbus/configurationmanager-introspec.xml +++ b/sflphone-common/src/dbus/configurationmanager-introspec.xml @@ -633,20 +633,6 @@ </arg> </method> - <method name="setNotify" tp:name-for-bindings="setNotify"> - <tp:docstring> - </tp:docstring> - </method> - - <method name="getNotify" tp:name-for-bindings="getNotify"> - <tp:docstring> - </tp:docstring> - <arg type="i" name="level" direction="out"> - <tp:docstring> - </tp:docstring> - </arg> - </method> - <method name="setMailNotify" tp:name-for-bindings="setMailNotify"> <tp:docstring> </tp:docstring> @@ -661,69 +647,6 @@ </arg> </method> - <method name="getDialpad" tp:name-for-bindings="getDialpad"> - <tp:docstring> - </tp:docstring> - <arg type="i" name="state" direction="out"> - <tp:docstring> - </tp:docstring> - </arg> - </method> - - <method name="setDialpad" tp:name-for-bindings="setDialpad"> - <tp:docstring> - </tp:docstring> - <arg type="b" name="display" direction="in"> - <tp:docstring> - </tp:docstring> - </arg> - </method> - - <method name="getSearchbar" tp:name-for-bindings="getSearchbar"> - <tp:docstring> - </tp:docstring> - <arg type="i" name="state" direction="out"> - <tp:docstring> - </tp:docstring> - </arg> - </method> - - <method name="setSearchbar" tp:name-for-bindings="setSearchbar"> - <tp:docstring> - </tp:docstring> - </method> - - <method name="setHistoryEnabled" tp:name-for-bindings="setHistoryEnabled"> - <tp:docstring> - </tp:docstring> - </method> - - <method name="getHistoryEnabled" tp:name-for-bindings="getHistoryEnabled"> - <tp:docstring> - </tp:docstring> - <arg type="s" name="state" direction="out"> - <tp:docstring> - </tp:docstring> - </arg> - </method> - - <method name="getVolumeControls" tp:name-for-bindings="getVolumeControls"> - <tp:docstring> - </tp:docstring> - <arg type="i" name="state" direction="out"> - <tp:docstring> - </tp:docstring> - </arg> - </method> - - <method name="setVolumeControls" tp:name-for-bindings="setVolumeControls"> - <tp:docstring> - </tp:docstring> - <arg type="b" name="display" direction="in"> - <tp:docstring> - </tp:docstring> - </arg> - </method> <method name="getHistoryLimit" tp:name-for-bindings="getHistoryLimit"> <tp:docstring> @@ -743,136 +666,6 @@ </arg> </method> - <method name="startHidden" tp:name-for-bindings="startHidden"> - <tp:docstring> - </tp:docstring> - </method> - - <method name="isStartHidden" tp:name-for-bindings="isStartHidden"> - <tp:docstring> - </tp:docstring> - <arg type="i" name="state" direction="out"> - <tp:docstring> - </tp:docstring> - </arg> - </method> - - <method name="popupMode" tp:name-for-bindings="popupMode"> - <tp:docstring> - </tp:docstring> - <arg type="i" name="state" direction="out"> - <tp:docstring> - </tp:docstring> - </arg> - </method> - - <method name="switchPopupMode" tp:name-for-bindings="switchPopupMode"> - <tp:docstring> - </tp:docstring> - </method> - - <method name="getWindowWidth" tp:name-for-bindings="getWindowWidth"> - <tp:docstring> - Unused - </tp:docstring> - <arg type="i" name="width" direction="out"> - <tp:docstring> - </tp:docstring> - </arg> - </method> - - <method name="getWindowHeight" tp:name-for-bindings="getWindowHeight"> - <tp:docstring> - Unused - </tp:docstring> - <arg type="i" name="height" direction="out"> - <tp:docstring> - </tp:docstring> - </arg> - </method> - - <method name="setWindowWidth" tp:name-for-bindings="setWindowWidth"> - <tp:docstring> - Unused - </tp:docstring> - <arg type="i" name="width" direction="in"> - <tp:docstring> - </tp:docstring> - </arg> - </method> - - <method name="setWindowHeight" tp:name-for-bindings="setWindowHeight"> - <tp:docstring> - Unused - </tp:docstring> - <arg type="i" name="height" direction="in"> - <tp:docstring> - </tp:docstring> - </arg> - </method> - - <method name="getWindowPositionX" tp:name-for-bindings="getWindowPositionX"> - <tp:docstring> - Unused - </tp:docstring> - <arg type="i" name="posX" direction="out"> - <tp:docstring> - </tp:docstring> - </arg> - </method> - - <method name="setWindowPositionX" tp:name-for-bindings="setWindowPositionX"> - <tp:docstring> - Unused - </tp:docstring> - <arg type="i" name="posX" direction="in"> - <tp:docstring> - </tp:docstring> - </arg> - </method> - - <method name="getWindowPositionY" tp:name-for-bindings="getWindowPositionY"> - <tp:docstring> - Unused - </tp:docstring> - <arg type="i" name="posY" direction="out"> - <tp:docstring> - </tp:docstring> - </arg> - </method> - - <method name="setWindowPositionY" tp:name-for-bindings="setWindowPositionY"> - <tp:docstring> - Unused - </tp:docstring> - <arg type="i" name="posY" direction="in"> - <tp:docstring> - </tp:docstring> - </arg> - </method> - - <method name="enableStatusIcon" tp:name-for-bindings="enableStatusIcon"> - <tp:docstring> - Allow SFLphone icon to be displayed in system tray - </tp:docstring> - <arg type="s" name="value" direction="in"> - <tp:docstring> - true/false - </tp:docstring> - </arg> - </method> - - <method name="isStatusIconEnabled" tp:name-for-bindings="isStatusIconEnabled"> - <tp:docstring> - Test if SFLphone icon is displayed in system tray. - </tp:docstring> - <arg type="s" name="value" direction="out"> - <tp:docstring> - true/false - </tp:docstring> - </arg> - </method> - <!-- Addressbook configuration --> <method name="getAddressbookSettings" tp:name-for-bindings="getAddressbookSettings"> diff --git a/sflphone-common/src/dbus/configurationmanager.cpp b/sflphone-common/src/dbus/configurationmanager.cpp old mode 100644 new mode 100755 index b6b08c5617fea26ef987254f3b5594bb4fcb865b..f09c743fbdbd5d854b88b46370b153b40e74a4d5 --- a/sflphone-common/src/dbus/configurationmanager.cpp +++ b/sflphone-common/src/dbus/configurationmanager.cpp @@ -35,6 +35,7 @@ #include <sstream> #include "../manager.h" #include "sip/sipvoiplink.h" +#include "sip/sipaccount.h" const char* ConfigurationManager::SERVER_PATH = "/org/sflphone/SFLphone/ConfigurationManager"; @@ -50,15 +51,18 @@ ConfigurationManager::ConfigurationManager(DBus::Connection& connection) : std::map<std::string, std::string> ConfigurationManager::getAccountDetails( const std::string& accountID) { - return Manager::instance().getAccountDetails(accountID); + + _debug("ConfigurationManager: get account details %s", accountID.c_str()); + return Manager::instance().getAccountDetails(accountID); } std::map<std::string, std::string> ConfigurationManager::getTlsSettingsDefault( void) { std::map<std::string, std::string> tlsSettingsDefault; + tlsSettingsDefault.insert(std::pair<std::string, std::string>( - TLS_LISTENER_PORT, DEFAULT_SIP_TLS_PORT)); + TLS_LISTENER_PORT, DEFAULT_SIP_TLS_PORT)); tlsSettingsDefault.insert(std::pair<std::string, std::string>( TLS_CA_LIST_FILE, "")); tlsSettingsDefault.insert(std::pair<std::string, std::string>( @@ -91,34 +95,24 @@ std::map<std::string, std::string> ConfigurationManager::getIp2IpDetails(void) { std::map<std::string, std::string> ip2ipAccountDetails; - ip2ipAccountDetails.insert(std::pair<std::string, std::string>(ACCOUNT_ID, - IP2IP_PROFILE)); - ip2ipAccountDetails.insert(std::pair<std::string, std::string>( - SRTP_KEY_EXCHANGE, Manager::instance().getConfigString( - IP2IP_PROFILE, SRTP_KEY_EXCHANGE))); - ip2ipAccountDetails.insert(std::pair<std::string, std::string>(SRTP_ENABLE, - Manager::instance().getConfigString(IP2IP_PROFILE, SRTP_ENABLE))); - ip2ipAccountDetails.insert(std::pair<std::string, std::string>( - SRTP_RTP_FALLBACK, Manager::instance().getConfigString( - IP2IP_PROFILE, SRTP_RTP_FALLBACK))); - ip2ipAccountDetails.insert(std::pair<std::string, std::string>( - ZRTP_DISPLAY_SAS, Manager::instance().getConfigString( - IP2IP_PROFILE, ZRTP_DISPLAY_SAS))); - ip2ipAccountDetails.insert(std::pair<std::string, std::string>( - ZRTP_HELLO_HASH, Manager::instance().getConfigString(IP2IP_PROFILE, - ZRTP_HELLO_HASH))); - ip2ipAccountDetails.insert(std::pair<std::string, std::string>( - ZRTP_NOT_SUPP_WARNING, Manager::instance().getConfigString( - IP2IP_PROFILE, ZRTP_NOT_SUPP_WARNING))); - ip2ipAccountDetails.insert(std::pair<std::string, std::string>( - ZRTP_DISPLAY_SAS_ONCE, Manager::instance().getConfigString( - IP2IP_PROFILE, ZRTP_DISPLAY_SAS_ONCE))); - - ip2ipAccountDetails.insert(std::pair<std::string, std::string>( - LOCAL_INTERFACE, Manager::instance().getConfigString(IP2IP_PROFILE, - LOCAL_INTERFACE))); - ip2ipAccountDetails.insert(std::pair<std::string, std::string>(LOCAL_PORT, - Manager::instance().getConfigString(IP2IP_PROFILE, LOCAL_PORT))); + SIPAccount *sipaccount = (SIPAccount *)Manager::instance().getAccount(IP2IP_PROFILE); + + if(!sipaccount) { + _error("ConfigurationManager: could not find account"); + return ip2ipAccountDetails; + } + + ip2ipAccountDetails.insert(std::pair<std::string, std::string>(ACCOUNT_ID, IP2IP_PROFILE)); + ip2ipAccountDetails.insert(std::pair<std::string, std::string>(SRTP_KEY_EXCHANGE, sipaccount->getSrtpKeyExchange())); + ip2ipAccountDetails.insert(std::pair<std::string, std::string>(SRTP_ENABLE, sipaccount->getSrtpEnable() ? "true" : "false")); + ip2ipAccountDetails.insert(std::pair<std::string, std::string>(SRTP_RTP_FALLBACK, sipaccount->getSrtpFallback() ? "true" : "false")); + ip2ipAccountDetails.insert(std::pair<std::string, std::string>(ZRTP_DISPLAY_SAS, sipaccount->getZrtpDisplaySas() ? "true" : "false")); + ip2ipAccountDetails.insert(std::pair<std::string, std::string>(ZRTP_HELLO_HASH, sipaccount->getZrtpHelloHash() ? "true" : "false")); + ip2ipAccountDetails.insert(std::pair<std::string, std::string>(ZRTP_NOT_SUPP_WARNING, sipaccount->getZrtpNotSuppWarning() ? "true" : "false")); + ip2ipAccountDetails.insert(std::pair<std::string, std::string>(ZRTP_DISPLAY_SAS_ONCE, sipaccount->getZrtpDiaplaySasOnce() ? "true" : "false")); + ip2ipAccountDetails.insert(std::pair<std::string, std::string>(LOCAL_INTERFACE, sipaccount->getLocalInterface())); + std::stringstream portstr; portstr << sipaccount->getLocalPort(); + ip2ipAccountDetails.insert(std::pair<std::string, std::string>(LOCAL_PORT, portstr.str())); std::map<std::string, std::string> tlsSettings; tlsSettings = getTlsSettings(IP2IP_PROFILE); @@ -134,66 +128,39 @@ void ConfigurationManager::setIp2IpDetails(const std::map<std::string, std::map<std::string, std::string> map_cpy = details; std::map<std::string, std::string>::iterator it; - it = map_cpy.find(LOCAL_INTERFACE); + SIPAccount *sipaccount = (SIPAccount *)Manager::instance().getAccount(IP2IP_PROFILE); - if (it != details.end()) { - Manager::instance().setConfig(IP2IP_PROFILE, LOCAL_INTERFACE, - it->second); + if(!sipaccount) { + _error("ConfigurationManager: could not find account"); } + - it = map_cpy.find(LOCAL_PORT); + it = map_cpy.find(LOCAL_INTERFACE); + if (it != details.end()) sipaccount->setLocalInterface(it->second); - if (it != details.end()) { - Manager::instance().setConfig(IP2IP_PROFILE, LOCAL_PORT, it->second); - } + it = map_cpy.find(LOCAL_PORT); + if (it != details.end()) sipaccount->setLocalPort(atoi(it->second.data())); it = map_cpy.find(SRTP_ENABLE); - - if (it != details.end()) { - Manager::instance().setConfig(IP2IP_PROFILE, SRTP_ENABLE, it->second); - } + if (it != details.end()) sipaccount->setSrtpEnable((it->second == "true")); it = map_cpy.find(SRTP_RTP_FALLBACK); - - if (it != details.end()) { - Manager::instance().setConfig(IP2IP_PROFILE, SRTP_RTP_FALLBACK, - it->second); - } + if (it != details.end()) sipaccount->setSrtpFallback((it->second == "true")); it = map_cpy.find(SRTP_KEY_EXCHANGE); - - if (it != details.end()) { - Manager::instance().setConfig(IP2IP_PROFILE, SRTP_KEY_EXCHANGE, - it->second); - } + if (it != details.end()) sipaccount->setSrtpKeyExchange(it->second); it = map_cpy.find(ZRTP_DISPLAY_SAS); - - if (it != details.end()) { - Manager::instance().setConfig(IP2IP_PROFILE, ZRTP_DISPLAY_SAS, - it->second); - } + if (it != details.end()) sipaccount->setZrtpDisplaySas((it->second == "true")); it = map_cpy.find(ZRTP_NOT_SUPP_WARNING); - - if (it != details.end()) { - Manager::instance().setConfig(IP2IP_PROFILE, ZRTP_NOT_SUPP_WARNING, - it->second); - } + if (it != details.end()) sipaccount->setZrtpNotSuppWarning((it->second == "true")); it = map_cpy.find(ZRTP_HELLO_HASH); - - if (it != details.end()) { - Manager::instance().setConfig(IP2IP_PROFILE, ZRTP_HELLO_HASH, - it->second); - } + if (it != details.end()) sipaccount->setZrtpHelloHash((it->second == "true")); it = map_cpy.find(ZRTP_DISPLAY_SAS_ONCE); - - if (it != details.end()) { - Manager::instance().setConfig(IP2IP_PROFILE, ZRTP_DISPLAY_SAS_ONCE, - it->second); - } + if (it != details.end()) sipaccount->setZrtpDiaplaySasOnce((it->second == "true")); setTlsSettings(IP2IP_PROFILE, details); @@ -209,129 +176,84 @@ void ConfigurationManager::setIp2IpDetails(const std::map<std::string, std::map<std::string, std::string> ConfigurationManager::getTlsSettings( const std::string& section) { + std::map<std::string, std::string> tlsSettings; - tlsSettings.insert(std::pair<std::string, std::string>(TLS_LISTENER_PORT, - Manager::instance().getConfigString(section, TLS_LISTENER_PORT))); - tlsSettings.insert(std::pair<std::string, std::string>(TLS_ENABLE, - Manager::instance().getConfigString(section, TLS_ENABLE))); - tlsSettings.insert(std::pair<std::string, std::string>(TLS_CA_LIST_FILE, - Manager::instance().getConfigString(section, TLS_CA_LIST_FILE))); - tlsSettings.insert(std::pair<std::string, std::string>( - TLS_CERTIFICATE_FILE, Manager::instance().getConfigString(section, - TLS_CERTIFICATE_FILE))); - tlsSettings.insert(std::pair<std::string, std::string>( - TLS_PRIVATE_KEY_FILE, Manager::instance().getConfigString(section, - TLS_PRIVATE_KEY_FILE))); - tlsSettings.insert(std::pair<std::string, std::string>(TLS_PASSWORD, - Manager::instance().getConfigString(section, TLS_PASSWORD))); - tlsSettings.insert(std::pair<std::string, std::string>(TLS_METHOD, - Manager::instance().getConfigString(section, TLS_METHOD))); - tlsSettings.insert(std::pair<std::string, std::string>(TLS_CIPHERS, - Manager::instance().getConfigString(section, TLS_CIPHERS))); - tlsSettings.insert(std::pair<std::string, std::string>(TLS_SERVER_NAME, - Manager::instance().getConfigString(section, TLS_SERVER_NAME))); - tlsSettings.insert(std::pair<std::string, std::string>(TLS_VERIFY_SERVER, - Manager::instance().getConfigString(section, TLS_VERIFY_SERVER))); - tlsSettings.insert(std::pair<std::string, std::string>(TLS_VERIFY_CLIENT, - Manager::instance().getConfigString(section, TLS_VERIFY_CLIENT))); - tlsSettings.insert(std::pair<std::string, std::string>( - TLS_REQUIRE_CLIENT_CERTIFICATE, - Manager::instance().getConfigString(section, - TLS_REQUIRE_CLIENT_CERTIFICATE))); - tlsSettings.insert(std::pair<std::string, std::string>( - TLS_NEGOTIATION_TIMEOUT_SEC, Manager::instance().getConfigString( - section, TLS_NEGOTIATION_TIMEOUT_SEC))); - tlsSettings.insert(std::pair<std::string, std::string>( - TLS_NEGOTIATION_TIMEOUT_MSEC, Manager::instance().getConfigString( - section, TLS_NEGOTIATION_TIMEOUT_MSEC))); + SIPAccount *sipaccount = (SIPAccount *)Manager::instance().getAccount(IP2IP_PROFILE); + + if(!sipaccount) + return tlsSettings; + + std::stringstream portstr; portstr << sipaccount->getTlsListenerPort(); + tlsSettings.insert(std::pair<std::string, std::string>(TLS_LISTENER_PORT, portstr.str())); + tlsSettings.insert(std::pair<std::string, std::string>(TLS_ENABLE, sipaccount->getTlsEnable())); + tlsSettings.insert(std::pair<std::string, std::string>(TLS_CA_LIST_FILE, sipaccount->getTlsCaListFile())); + tlsSettings.insert(std::pair<std::string, std::string>(TLS_CERTIFICATE_FILE, sipaccount->getTlsCertificateFile())); + tlsSettings.insert(std::pair<std::string, std::string>(TLS_PRIVATE_KEY_FILE, sipaccount->getTlsPrivateKeyFile())); + tlsSettings.insert(std::pair<std::string, std::string>(TLS_PASSWORD, sipaccount->getTlsPassword())); + tlsSettings.insert(std::pair<std::string, std::string>(TLS_METHOD, sipaccount->getTlsMethod())); + tlsSettings.insert(std::pair<std::string, std::string>(TLS_CIPHERS, sipaccount->getTlsCiphers())); + tlsSettings.insert(std::pair<std::string, std::string>(TLS_SERVER_NAME, sipaccount->getTlsServerName())); + tlsSettings.insert(std::pair<std::string, std::string>(TLS_VERIFY_SERVER, sipaccount->getTlsVerifyServer() ? "true" : "false")); + tlsSettings.insert(std::pair<std::string, std::string>(TLS_VERIFY_CLIENT, sipaccount->getTlsVerifyClient() ? "true" : "false")); + tlsSettings.insert(std::pair<std::string, std::string>(TLS_REQUIRE_CLIENT_CERTIFICATE, sipaccount->getTlsRequireClientCertificate() ? "true" : "false")); + tlsSettings.insert(std::pair<std::string, std::string>(TLS_NEGOTIATION_TIMEOUT_SEC, sipaccount->getTlsNegotiationTimeoutSec())); + tlsSettings.insert(std::pair<std::string, std::string>(TLS_NEGOTIATION_TIMEOUT_MSEC, sipaccount->getTlsNegotiationTimeoutMsec())); + return tlsSettings; } void ConfigurationManager::setTlsSettings(const std::string& section, const std::map<std::string, std::string>& details) { + std::map<std::string, std::string> map_cpy = details; std::map<std::string, std::string>::iterator it; - it = map_cpy.find(TLS_LISTENER_PORT); - if (it != details.end()) { - Manager::instance().setConfig(section, TLS_LISTENER_PORT, it->second); + SIPAccount * sipaccount = (SIPAccount *)Manager::instance().getAccount(IP2IP_PROFILE); + + if(!sipaccount) { + _debug("ConfigurationManager: Error: No valid account in set TLS settings"); + return; } - it = map_cpy.find(TLS_ENABLE); + it = map_cpy.find(TLS_LISTENER_PORT); + if (it != details.end()) sipaccount->setTlsListenerPort(atoi(it->second.data())); - if (it != details.end()) { - Manager::instance().setConfig(section, TLS_ENABLE, it->second); - } + it = map_cpy.find(TLS_ENABLE); + if (it != details.end()) sipaccount->setTlsEnable(it->second); it = map_cpy.find(TLS_CA_LIST_FILE); - - if (it != map_cpy.end()) { - Manager::instance().setConfig(section, TLS_CA_LIST_FILE, it->second); - } + if (it != map_cpy.end()) sipaccount->setTlsCaListFile(it->second); it = map_cpy.find(TLS_CERTIFICATE_FILE); - - if (it != map_cpy.end()) { - Manager::instance().setConfig(section, TLS_CERTIFICATE_FILE, it->second); - } + if (it != map_cpy.end()) sipaccount->setTlsCertificateFile(it->second); it = map_cpy.find(TLS_PRIVATE_KEY_FILE); - - if (it != map_cpy.end()) { - Manager::instance().setConfig(section, TLS_PRIVATE_KEY_FILE, it->second); - } + if (it != map_cpy.end()) sipaccount->setTlsPrivateKeyFile(it->second); it = map_cpy.find(TLS_PASSWORD); - - if (it != map_cpy.end()) { - Manager::instance().setConfig(section, TLS_PASSWORD, it->second); - } + if (it != map_cpy.end()) sipaccount->setTlsPassword(it->second); it = map_cpy.find(TLS_METHOD); - - if (it != map_cpy.end()) { - Manager::instance().setConfig(section, TLS_METHOD, it->second); - } + if (it != map_cpy.end()) sipaccount->setTlsMethod(it->second); it = map_cpy.find(TLS_CIPHERS); - - if (it != map_cpy.end()) { - Manager::instance().setConfig(section, TLS_CIPHERS, it->second); - } + if (it != map_cpy.end()) sipaccount->setTlsCiphers(it->second); it = map_cpy.find(TLS_SERVER_NAME); - - if (it != map_cpy.end()) { - Manager::instance().setConfig(section, TLS_SERVER_NAME, it->second); - } + if (it != map_cpy.end()) sipaccount->setTlsServerName(it->second); it = map_cpy.find(TLS_VERIFY_CLIENT); - - if (it != map_cpy.end()) { - Manager::instance().setConfig(section, TLS_VERIFY_CLIENT, it->second); - } + if (it != map_cpy.end()) sipaccount->setTlsVerifyClient((it->second == "true") ? true : false); it = map_cpy.find(TLS_REQUIRE_CLIENT_CERTIFICATE); - - if (it != map_cpy.end()) { - Manager::instance().setConfig(section, TLS_REQUIRE_CLIENT_CERTIFICATE, - it->second); - } + if (it != map_cpy.end()) sipaccount->setTlsRequireClientCertificate((it->second == "true") ? true : false); it = map_cpy.find(TLS_NEGOTIATION_TIMEOUT_SEC); - - if (it != map_cpy.end()) { - Manager::instance().setConfig(section, TLS_NEGOTIATION_TIMEOUT_SEC, - it->second); - } + if (it != map_cpy.end()) sipaccount->setTlsNegotiationTimeoutSec(it->second); it = map_cpy.find(TLS_NEGOTIATION_TIMEOUT_MSEC); - - if (it != map_cpy.end()) { - Manager::instance().setConfig(section, TLS_NEGOTIATION_TIMEOUT_MSEC, - it->second); - } + if (it != map_cpy.end()) sipaccount->setTlsNegotiationTimeoutMsec(it->second); Manager::instance().saveConfig(); @@ -348,37 +270,37 @@ std::map<std::string, std::string> ConfigurationManager::getCredential( streamOut << index; credentialIndex = streamOut.str(); + SIPAccount *sipaccount = (SIPAccount *)Manager::instance().getAccount(accountID); + + std::string section = std::string("Credential") + std::string(":") + accountID + std::string(":") + credentialIndex; std::map<std::string, std::string> credentialInformation; - std::string username = Manager::instance().getConfigString(section, - USERNAME); - std::string password = Manager::instance().getConfigString(section, - PASSWORD); - std::string realm = Manager::instance().getConfigString(section, REALM); - - credentialInformation.insert(std::pair<std::string, std::string>(USERNAME, - username)); - credentialInformation.insert(std::pair<std::string, std::string>(PASSWORD, - password)); - credentialInformation.insert(std::pair<std::string, std::string>(REALM, - realm)); + std::string username = sipaccount->getUsername(); + std::string password = sipaccount->getPassword(); + std::string realm = sipaccount->getRealm(); + + credentialInformation.insert(std::pair<std::string, std::string>(USERNAME, username)); + credentialInformation.insert(std::pair<std::string, std::string>(PASSWORD, password)); + credentialInformation.insert(std::pair<std::string, std::string>(REALM, realm)); return credentialInformation; } int32_t ConfigurationManager::getNumberOfCredential( const std::string& accountID) { - return Manager::instance().getConfigInt(accountID, CONFIG_CREDENTIAL_NUMBER); + + SIPAccount *sipaccount = (SIPAccount *)Manager::instance().getAccount(accountID); + return sipaccount->getCredentialCount(); } void ConfigurationManager::setNumberOfCredential(const std::string& accountID, const int32_t& number) { - if (accountID != AccountNULL || !accountID.empty()) { - Manager::instance().setConfig(accountID, CONFIG_CREDENTIAL_NUMBER, - number); - } + if (accountID != AccountNULL || !accountID.empty()) { + SIPAccount *sipaccount = (SIPAccount *)Manager::instance().getAccount(accountID); + sipaccount->setCredentialCount(number); + } } void ConfigurationManager::setCredential(const std::string& accountID, @@ -596,17 +518,11 @@ std::vector<std::string> ConfigurationManager::getRecordDeviceList() { } bool ConfigurationManager::isMd5CredentialHashing(void) { - bool isEnabled = Manager::instance().getConfigBool(PREFERENCES, - CONFIG_MD5HASH); - return isEnabled; + return Manager::instance().preferences.getMd5Hash(); } void ConfigurationManager::setMd5CredentialHashing(const bool& enabled) { - if (enabled) { - Manager::instance().setConfig(PREFERENCES, CONFIG_MD5HASH, TRUE_STR); - } else { - Manager::instance().setConfig(PREFERENCES, CONFIG_MD5HASH, FALSE_STR); - } + Manager::instance().preferences.setMd5Hash(enabled); } int32_t ConfigurationManager::isIax2Enabled(void) { @@ -637,6 +553,7 @@ void ConfigurationManager::setRecordPath(const std::string& recPath) { Manager::instance().setRecordPath(recPath); } +/* int32_t ConfigurationManager::getDialpad(void) { return Manager::instance().getDialpad(); } @@ -660,6 +577,7 @@ int32_t ConfigurationManager::getVolumeControls(void) { void ConfigurationManager::setVolumeControls(const bool& display) { Manager::instance().setVolumeControls(display); } +*/ int32_t ConfigurationManager::getHistoryLimit(void) { return Manager::instance().getHistoryLimit(); @@ -669,6 +587,7 @@ void ConfigurationManager::setHistoryLimit(const int32_t& days) { Manager::instance().setHistoryLimit(days); } +/* void ConfigurationManager::setHistoryEnabled(void) { Manager::instance().setHistoryEnabled(); } @@ -700,6 +619,7 @@ void ConfigurationManager::setNotify(void) { int32_t ConfigurationManager::getNotify(void) { return Manager::instance().getNotify(); } +*/ void ConfigurationManager::setAudioManager(const int32_t& api) { Manager::instance().setAudioManager(api); @@ -792,45 +712,6 @@ std::vector<std::string> ConfigurationManager::getAllIpInterfaceByName(void) { return vector; } -int32_t ConfigurationManager::getWindowWidth(void) { - - return Manager::instance().getConfigInt(PREFERENCES, WINDOW_WIDTH); -} - -int32_t ConfigurationManager::getWindowHeight(void) { - - return Manager::instance().getConfigInt(PREFERENCES, WINDOW_HEIGHT); -} - -void ConfigurationManager::setWindowWidth(const int32_t& width) { - - Manager::instance().setConfig(PREFERENCES, WINDOW_WIDTH, width); -} - -void ConfigurationManager::setWindowHeight(const int32_t& height) { - - Manager::instance().setConfig(PREFERENCES, WINDOW_HEIGHT, height); -} - -int32_t ConfigurationManager::getWindowPositionX(void) { - - return Manager::instance().getConfigInt(PREFERENCES, WINDOW_POSITION_X); -} - -int32_t ConfigurationManager::getWindowPositionY(void) { - - return Manager::instance().getConfigInt(PREFERENCES, WINDOW_POSITION_Y); -} - -void ConfigurationManager::setWindowPositionX(const int32_t& posX) { - - Manager::instance().setConfig(PREFERENCES, WINDOW_POSITION_X, posX); -} - -void ConfigurationManager::setWindowPositionY(const int32_t& posY) { - - Manager::instance().setConfig(PREFERENCES, WINDOW_POSITION_Y, posY); -} std::map<std::string, int32_t> ConfigurationManager::getShortcuts() { @@ -863,12 +744,3 @@ void ConfigurationManager::setShortcuts( Manager::instance().saveConfig(); } -void ConfigurationManager::enableStatusIcon (const std::string& value) { - - Manager::instance ().setConfig (PREFERENCES, SHOW_STATUSICON, value); -} - -std::string ConfigurationManager::isStatusIconEnabled (void) { - - return Manager::instance ().getConfigString (PREFERENCES, SHOW_STATUSICON); -} diff --git a/sflphone-common/src/dbus/configurationmanager.h b/sflphone-common/src/dbus/configurationmanager.h old mode 100644 new mode 100755 index 7c351af08efb36b95ca6334f7fc6475a00d33805..9dc33d059163e2ed7df2aec79a7a7a221db27249 --- a/sflphone-common/src/dbus/configurationmanager.h +++ b/sflphone-common/src/dbus/configurationmanager.h @@ -109,40 +109,14 @@ public: void setRingtoneChoice( const std::string& tone ); std::string getRecordPath( void ); void setRecordPath(const std::string& recPath ); - int32_t getDialpad( void ); - void setDialpad (const bool& display); - int32_t getSearchbar( void ); - - void setSearchbar( void ); + void setHistoryLimit( const int32_t& days); int32_t getHistoryLimit (void); - void setHistoryEnabled (void); - std::string getHistoryEnabled (void); - - int32_t getVolumeControls( void ); - void setVolumeControls (const bool& display); - int32_t isStartHidden( void ); - void startHidden( void ); - int32_t popupMode( void ); - void switchPopupMode( void ); - int32_t getNotify( void ); - void setNotify( void ); int32_t getMailNotify( void ); void setMailNotify( void ); - int32_t getWindowWidth (void); - int32_t getWindowHeight (void); - void setWindowWidth (const int32_t& width); - void setWindowHeight (const int32_t& height); - int32_t getWindowPositionX (void); - int32_t getWindowPositionY (void); - void setWindowPositionX (const int32_t& posX); - void setWindowPositionY (const int32_t& posY); - - void enableStatusIcon (const std::string&); - std::string isStatusIconEnabled (void); std::map<std::string, int32_t> getAddressbookSettings (void); void setAddressbookSettings (const std::map<std::string, int32_t>& settings); diff --git a/sflphone-common/src/iax/iaxaccount.cpp b/sflphone-common/src/iax/iaxaccount.cpp index 2c277cb0827ee138efb7e835d4362a188ba7d032..42ca92abb162a6e1cde5e902998c4bd0c27c5e2d 100644 --- a/sflphone-common/src/iax/iaxaccount.cpp +++ b/sflphone-common/src/iax/iaxaccount.cpp @@ -47,6 +47,29 @@ IAXAccount::~IAXAccount() _link = NULL; } +void IAXAccount::serialize(Conf::YamlEmitter *emitter) +{ + +} + +void IAXAccount::unserialize(Conf::MappingNode *map) +{ + +} + +void IAXAccount::setAccountDetails(const std::map<std::string, std::string>& details) +{ + +} + +std::map<std::string, std::string> IAXAccount::getAccountDetails() +{ + std::map<std::string, std::string> a; + + return a; +} + + void IAXAccount::setVoIPLink() { diff --git a/sflphone-common/src/iax/iaxaccount.h b/sflphone-common/src/iax/iaxaccount.h index 929f7af38a8fa391bc154c88fa05f72ce138cbec..1075dd70aba2b2eebfbc7a0ed453d17cd98875a7 100644 --- a/sflphone-common/src/iax/iaxaccount.h +++ b/sflphone-common/src/iax/iaxaccount.h @@ -44,6 +44,14 @@ class IAXAccount : public Account ~IAXAccount(); + virtual void serialize(Conf::YamlEmitter *emitter); + + virtual void unserialize(Conf::MappingNode *map); + + void setAccountDetails(const std::map<std::string, std::string>& details); + + std::map<std::string, std::string> getAccountDetails(); + void setVoIPLink (); /** diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp old mode 100644 new mode 100755 index d4000073edc94d44cffa51398cd46efb31487849..a84cf491343945f2ae4d779cfd347a6eb388d41c --- a/sflphone-common/src/managerimpl.cpp +++ b/sflphone-common/src/managerimpl.cpp @@ -72,8 +72,6 @@ #define MD5_APPEND(pms,buf,len) pj_md5_update(pms, (const pj_uint8_t*)buf, len) -#define find_in_map(X, Y) if((iter = map_cpy.find(X)) != map_cpy.end()) { Y = iter->second; } - ManagerImpl::ManagerImpl (void) : _hasTriedToRegister(false), _config(), _currentCallId2(), _currentCallMutex(), _codecBuilder(NULL), _audiodriver(NULL), @@ -113,9 +111,13 @@ ManagerImpl::~ManagerImpl (void) { void ManagerImpl::init () { + _debug("Manager: Init"); + // Load accounts, init map loadAccountMap(); + _debug("Manager: account map loaded"); + initVolume(); if (_exist == 0) { @@ -135,7 +137,7 @@ void ManagerImpl::init () { unsigned int sampleRate = audiolayer->getSampleRate(); _debugInit ("Manager: Load telephone tone"); - std::string country = getConfigString(PREFERENCES, ZONE_TONE); + std::string country = preferences.getZoneToneChoice(); _telephoneTone = new TelephoneTone(country, sampleRate); _debugInit ("Manager: Loading DTMF key"); @@ -143,7 +145,7 @@ void ManagerImpl::init () { } // Load the history - _history->load_history(getConfigInt(PREFERENCES, CONFIG_HISTORY_LIMIT)); + _history->load_history(preferences.getHistoryLimit()); } void ManagerImpl::terminate () { @@ -211,11 +213,10 @@ bool ManagerImpl::outgoingCall (const std::string& account_id, CallID current_call_id = getCurrentCallId(); - if (getConfigString(HOOKS, PHONE_NUMBER_HOOK_ENABLED) == "1") - _cleaner->set_phone_number_prefix(getConfigString(HOOKS, - PHONE_NUMBER_HOOK_ADD_PREFIX)); + if(hookPreference.getNumberEnabled()) + _cleaner->set_phone_number_prefix(hookPreference.getNumberAddPrefix()); else - _cleaner->set_phone_number_prefix(""); + _cleaner->set_phone_number_prefix(""); to_cleaned = _cleaner->clean(to); @@ -1406,8 +1407,32 @@ void ManagerImpl::removeStream (const CallID& call_id) { //THREAD=Main bool ManagerImpl::saveConfig (void) { _debug ("Saving Configuration to XDG directory %s ... ", _path.c_str()); - setConfig(AUDIO, VOLUME_SPKR, getSpkrVolume()); - setConfig(AUDIO, VOLUME_MICRO, getMicVolume()); + audioPreference.setVolumemic(getMicVolume()); + audioPreference.setVolumespkr(getSpkrVolume()); + + AccountMap::iterator iter = _accountMap.begin(); + + try{ + emitter = new Conf::YamlEmitter("sequenceEmitter.yml"); + + while(iter != _accountMap.end()) { + iter->second->serialize(emitter); + iter++; + } + + preferences.serialize(emitter); + voipPreferences.serialize(emitter); + addressbookPreference.serialize(emitter); + hookPreference.serialize(emitter); + audioPreference.serialize(emitter); + + emitter->serializeData(); + + delete emitter; + } + catch (Conf::YamlEmitterException &e) { + _error("ConfigTree: %s", e.what()); + } _setupLoaded = _config.saveConfigTree(_path.data()); return _setupLoaded; @@ -1440,7 +1465,7 @@ bool ManagerImpl::playDtmf (char code) { stopTone(); - bool hasToPlayTone = getConfigBool(SIGNALISATION, PLAY_DTMF); + bool hasToPlayTone = voipPreferences.getPlayDtmf(); if (!hasToPlayTone) { _debug ("Manager: playDtmf: Do not have to play a tone..."); @@ -1448,7 +1473,7 @@ bool ManagerImpl::playDtmf (char code) { } // length in milliseconds - pulselen = getConfigInt(SIGNALISATION, PULSE_LENGTH); + pulselen = voipPreferences.getPulseLength(); if (!pulselen) { _debug ("Manager: playDtmf: Pulse length is not set..."); @@ -1773,6 +1798,9 @@ void ManagerImpl::startVoiceMessageNotification (const AccountID& accountId, } void ManagerImpl::connectionStatusNotification () { + + _debug("Manager: connectionStatusNotification"); + if (_dbus != NULL) { _dbus->getConfigurationManager()->accountsChanged(); } @@ -1788,7 +1816,7 @@ bool ManagerImpl::playATone (Tone::TONEID toneId) { // _debug ("Manager: Play tone %d", toneId); - hasToPlayTone = getConfigBool(SIGNALISATION, PLAY_TONES); + hasToPlayTone = voipPreferences.getPlayTones(); if (!hasToPlayTone) return false; @@ -1816,7 +1844,7 @@ bool ManagerImpl::playATone (Tone::TONEID toneId) { void ManagerImpl::stopTone () { bool hasToPlayTone; - hasToPlayTone = getConfigBool(SIGNALISATION, PLAY_TONES); + hasToPlayTone = voipPreferences.getPlayTones(); if (!hasToPlayTone) return; @@ -1879,7 +1907,7 @@ void ManagerImpl::ringtone () { //TODO Comment this because it makes the daemon crashes since the main thread //synchronizes the ringtone thread. - ringchoice = getConfigString(AUDIO, RING_CHOICE); + ringchoice = audioPreference.getRingchoice(); //if there is no / inside the path if (ringchoice.find(DIR_SEPARATOR_CH) == std::string::npos) { @@ -2356,7 +2384,8 @@ void ManagerImpl::setOutputAudioPlugin (const std::string& audioPlugin) { // set config if (res) - setConfig(AUDIO, ALSA_PLUGIN, audioPlugin); + audioPreference.setPlugin(audioPlugin); + //setConig(AUDIO, ALSA_PLUGIN, audioPlugin); } /** @@ -2402,21 +2431,21 @@ void ManagerImpl::setAudioDevice (const int index, int streamType) { _audiodriver->openDevice(_audiodriver->getIndexIn(), index, _audiodriver->getIndexRing(), _audiodriver->getSampleRate(), _audiodriver->getFrameSize(), SFL_PCM_PLAYBACK, alsaplugin); - setConfig(AUDIO, ALSA_CARD_ID_OUT, index); + audioPreference.setCardout(index); break; case SFL_PCM_CAPTURE: _debug("Manager: Set input device"); _audiodriver->openDevice(index, _audiodriver->getIndexOut(), _audiodriver->getIndexRing(), _audiodriver->getSampleRate(), _audiodriver->getFrameSize(), SFL_PCM_CAPTURE, alsaplugin); - setConfig(AUDIO, ALSA_CARD_ID_IN, index); + audioPreference.setCardin(index); break; case SFL_PCM_RINGTONE: _debug("Manager: Set ringtone device"); _audiodriver->openDevice(_audiodriver->getIndexOut(), _audiodriver->getIndexOut(), index, _audiodriver->getSampleRate(), _audiodriver->getFrameSize(), SFL_PCM_RINGTONE, alsaplugin); - setConfig(AUDIO, ALSA_CARD_ID_RING, index); + audioPreference.setCardring(index); break; default: _warn("Unknown stream type"); @@ -2467,18 +2496,18 @@ int ManagerImpl::isIax2Enabled (void) { } int ManagerImpl::isRingtoneEnabled (void) { - return (getConfigString(PREFERENCES, CONFIG_RINGTONE) == "true") ? 1 : 0; + return preferences.getRingtoneEnabled() ? 1 : 0; } void ManagerImpl::ringtoneEnabled (void) { - (getConfigString(PREFERENCES, CONFIG_RINGTONE) == RINGTONE_ENABLED) ? setConfig( - PREFERENCES, CONFIG_RINGTONE, FALSE_STR) - : setConfig(PREFERENCES, CONFIG_RINGTONE, TRUE_STR); + + preferences.getRingtoneEnabled() ? preferences.setRingtoneEnabled(false) : preferences.setRingtoneEnabled(true); + } std::string ManagerImpl::getRingtoneChoice (void) { // we need the absolute path - std::string tone_name = getConfigString(AUDIO, RING_CHOICE); + std::string tone_name = audioPreference.getRingchoice(); std::string tone_path; if (tone_name.find(DIR_SEPARATOR_CH) == std::string::npos) { @@ -2497,63 +2526,23 @@ std::string ManagerImpl::getRingtoneChoice (void) { void ManagerImpl::setRingtoneChoice (const std::string& tone) { // we save the absolute path - setConfig(AUDIO, RING_CHOICE, tone); + audioPreference.setRingchoice(tone); } std::string ManagerImpl::getRecordPath (void) { - return getConfigString(AUDIO, RECORD_PATH); + return audioPreference.getRecordpath(); } void ManagerImpl::setRecordPath (const std::string& recPath) { _debug ("ManagerImpl::setRecordPath(%s)! ", recPath.c_str()); - setConfig(AUDIO, RECORD_PATH, recPath); + audioPreference.setRecordpath(recPath); } bool ManagerImpl::getMd5CredentialHashing (void) { - return getConfigBool(PREFERENCES, CONFIG_MD5HASH); -} - -int ManagerImpl::getDialpad (void) { - if (getConfigString(PREFERENCES, CONFIG_DIALPAD) == TRUE_STR) { - return 1; - } else { - return 0; - } -} - -void ManagerImpl::setDialpad (bool display) { - std::string set; - - display ? set = TRUE_STR : set = FALSE_STR; - // If the value we received is different from the one saved in the config file, save the new value - // Else do nothing - - if ((display && (getConfigString(PREFERENCES, CONFIG_DIALPAD) != TRUE_STR)) - || (!display && (getConfigString(PREFERENCES, CONFIG_DIALPAD) - != FALSE_STR))) - setConfig(PREFERENCES, CONFIG_DIALPAD, set); -} - -int ManagerImpl::getVolumeControls (void) { - if (getConfigString(PREFERENCES, CONFIG_VOLUME) == TRUE_STR) { - return 1; - } else { - return 0; - } + return preferences.getMd5Hash(); } -void ManagerImpl::setVolumeControls (bool display) { - std::string set; - display ? set = TRUE_STR : set = FALSE_STR; - // If the value we received is different from the one saved in the config file, save the new value - // Else do nothing - - if ((display && (getConfigString(PREFERENCES, CONFIG_VOLUME) != TRUE_STR)) - || (!display && (getConfigString(PREFERENCES, CONFIG_VOLUME) - != FALSE_STR))) - setConfig(PREFERENCES, CONFIG_VOLUME, set); -} void ManagerImpl::setRecordingCall (const CallID& id) { @@ -2579,66 +2568,21 @@ bool ManagerImpl::isRecording (const CallID& id) { return rec->isRecording(); } -void ManagerImpl::startHidden (void) { - (getConfigString(PREFERENCES, CONFIG_START) == START_HIDDEN) ? setConfig( - PREFERENCES, CONFIG_START, FALSE_STR) : setConfig(PREFERENCES, - CONFIG_START, TRUE_STR); -} - -int ManagerImpl::isStartHidden (void) { - return (getConfigBool(PREFERENCES, CONFIG_START) == true) ? 1 : 0; -} - -void ManagerImpl::switchPopupMode (void) { - (getConfigString(PREFERENCES, CONFIG_POPUP) == WINDOW_POPUP) ? setConfig( - PREFERENCES, CONFIG_POPUP, FALSE_STR) : setConfig(PREFERENCES, - CONFIG_POPUP, TRUE_STR); -} void ManagerImpl::setHistoryLimit (const int& days) { - setConfig(PREFERENCES, CONFIG_HISTORY_LIMIT, days); + preferences.setHistoryLimit(days); } int ManagerImpl::getHistoryLimit (void) { - return getConfigInt(PREFERENCES, CONFIG_HISTORY_LIMIT); + return preferences.getHistoryLimit(); } -std::string ManagerImpl::getHistoryEnabled (void) { - return getConfigString(PREFERENCES, CONFIG_HISTORY_ENABLED); -} - -void ManagerImpl::setHistoryEnabled (void) { - (getConfigString(PREFERENCES, CONFIG_HISTORY_ENABLED) == TRUE_STR) ? setConfig( - PREFERENCES, CONFIG_HISTORY_ENABLED, FALSE_STR) - : setConfig(PREFERENCES, CONFIG_HISTORY_ENABLED, TRUE_STR); -} - -int ManagerImpl::getSearchbar (void) { - return getConfigInt(PREFERENCES, CONFIG_SEARCHBAR); -} - -void ManagerImpl::setSearchbar (void) { - (getConfigInt(PREFERENCES, CONFIG_SEARCHBAR) == 1) ? setConfig(PREFERENCES, - CONFIG_SEARCHBAR, FALSE_STR) : setConfig(PREFERENCES, - CONFIG_SEARCHBAR, TRUE_STR); -} - -int ManagerImpl::popupMode (void) { - return (getConfigBool(PREFERENCES, CONFIG_POPUP) == true) ? 1 : 0; -} - -int32_t ManagerImpl::getNotify (void) { - return (getConfigBool(PREFERENCES, CONFIG_NOTIFY) == true) ? 1 : 0; -} - -void ManagerImpl::setNotify (void) { - (getConfigString(PREFERENCES, CONFIG_NOTIFY) == NOTIFY_ALL) ? setConfig( - PREFERENCES, CONFIG_NOTIFY, FALSE_STR) : setConfig(PREFERENCES, - CONFIG_NOTIFY, TRUE_STR); +int32_t ManagerImpl::getMailNotify (void) { + return preferences.getNotifyMails(); } -int32_t ManagerImpl::getMailNotify (void) { - return getConfigInt(PREFERENCES, CONFIG_MAIL_NOTIFY); +void ManagerImpl::setMailNotify (void) { + preferences.getNotifyMails() ? preferences.setNotifyMails(true) : preferences.setNotifyMails(false); } void ManagerImpl::setAudioManager (const int32_t& api) { @@ -2658,7 +2602,7 @@ void ManagerImpl::setAudioManager (const int32_t& api) { return; } - setConfig(PREFERENCES, CONFIG_AUDIO, api); + preferences.setAudioApi(api); switchAudioManager(); return; @@ -2666,14 +2610,9 @@ void ManagerImpl::setAudioManager (const int32_t& api) { } int32_t ManagerImpl::getAudioManager (void) { - return getConfigInt(PREFERENCES, CONFIG_AUDIO); + return preferences.getAudioApi(); } -void ManagerImpl::setMailNotify (void) { - (getConfigString(PREFERENCES, CONFIG_MAIL_NOTIFY) == NOTIFY_ALL) ? setConfig( - PREFERENCES, CONFIG_MAIL_NOTIFY, FALSE_STR) - : setConfig(PREFERENCES, CONFIG_MAIL_NOTIFY, TRUE_STR); -} void ManagerImpl::notifyErrClient (const int32_t& errCode) { if (_dbus) { @@ -2705,7 +2644,7 @@ std::string ManagerImpl::getCurrentAudioOutputPlugin (void) { if (alsalayer) return alsalayer -> getAudioPlugin(); else - return getConfigString(AUDIO, ALSA_PLUGIN); + return audioPreference.getPlugin(); } @@ -2792,16 +2731,17 @@ bool ManagerImpl::initAudioDriver (void) { _debugInit ("AudioLayer Creation"); - if (getConfigInt(PREFERENCES, CONFIG_AUDIO) == ALSA) { + if (preferences.getAudioApi() == ALSA) { _audiodriver = new AlsaLayer(this); _audiodriver->setMainBuffer(&_mainBuffer); - } else if (getConfigInt(PREFERENCES, CONFIG_AUDIO) == PULSEAUDIO) { + } + else if(preferences.getAudioApi() == PULSEAUDIO) { if (app_is_running("pulseaudio") == 0) { _audiodriver = new PulseLayer(this); _audiodriver->setMainBuffer(&_mainBuffer); } else { _audiodriver = new AlsaLayer(this); - setConfig(PREFERENCES, CONFIG_AUDIO, ALSA); + preferences.setAudioApi(ALSA); _audiodriver->setMainBuffer(&_mainBuffer); } } else @@ -2835,13 +2775,13 @@ void ManagerImpl::selectAudioDriver (void) { _debug ("Audio layer type: %i" , layer); /* Retrieve the global devices info from the user config */ - alsaPlugin = getConfigString(AUDIO, ALSA_PLUGIN); - numCardIn = getConfigInt(AUDIO, ALSA_CARD_ID_IN); - numCardOut = getConfigInt(AUDIO, ALSA_CARD_ID_OUT); - numCardRing = getConfigInt(AUDIO, ALSA_CARD_ID_RING); - // sampleRate = getConfigInt(AUDIO, AUDIO_SAMPLE_RATE); + alsaPlugin = audioPreference.getPlugin(); + numCardIn = audioPreference.getCardin(); + numCardOut = audioPreference.getCardout(); + numCardRing = audioPreference.getCardring(); + sampleRate = _mainBuffer.getInternalSamplingRate(); - frameSize = getConfigInt(AUDIO, ALSA_FRAME_SIZE); + frameSize = audioPreference.getFramesize(); /* Only for the ALSA layer, we check the sound card information */ @@ -2851,19 +2791,19 @@ void ManagerImpl::selectAudioDriver (void) { if (!alsalayer -> soundCardIndexExist(numCardIn, SFL_PCM_CAPTURE)) { _debug (" Card with index %i doesn't exist or cannot capture. Switch to 0.", numCardIn); numCardIn = ALSA_DFT_CARD_ID; - setConfig(AUDIO, ALSA_CARD_ID_IN, ALSA_DFT_CARD_ID); + audioPreference.setCardin(ALSA_DFT_CARD_ID); } if (!alsalayer -> soundCardIndexExist(numCardOut, SFL_PCM_PLAYBACK)) { _debug (" Card with index %i doesn't exist or cannot playback. Switch to 0.", numCardOut); numCardOut = ALSA_DFT_CARD_ID; - setConfig(AUDIO, ALSA_CARD_ID_OUT, ALSA_DFT_CARD_ID); + audioPreference.setCardout(ALSA_DFT_CARD_ID); } if (!alsalayer->soundCardIndexExist(numCardRing, SFL_PCM_RINGTONE)) { _debug(" Card with index %i doesn't exist or cannot ringtone. Switch to 0.", numCardRing); numCardRing = ALSA_DFT_CARD_ID; - setConfig(AUDIO, ALSA_CARD_ID_RING, ALSA_DFT_CARD_ID); + audioPreference.setCardring(ALSA_DFT_CARD_ID); } } @@ -2891,17 +2831,16 @@ void ManagerImpl::switchAudioManager (void) { type = _audiodriver->getLayerType(); - // samplerate = getConfigInt(AUDIO, AUDIO_SAMPLE_RATE); samplerate = _mainBuffer.getInternalSamplingRate(); - framesize = getConfigInt(AUDIO, ALSA_FRAME_SIZE); + framesize = audioPreference.getFramesize(); _debug ("Mnager: samplerate: %i, framesize %i\n", samplerate, framesize); - alsaPlugin = getConfigString(AUDIO, ALSA_PLUGIN); + alsaPlugin = audioPreference.getPlugin(); - numCardIn = getConfigInt(AUDIO, ALSA_CARD_ID_IN); - numCardOut = getConfigInt(AUDIO, ALSA_CARD_ID_OUT); - numCardRing = getConfigInt(AUDIO, ALSA_CARD_ID_RING); + numCardIn = audioPreference.getCardin(); + numCardOut = audioPreference.getCardout(); + numCardRing = audioPreference.getCardring(); _debug ("Manager: Deleting current layer... "); @@ -2970,15 +2909,15 @@ void ManagerImpl::audioSamplingRateChanged (void) { type = _audiodriver->getLayerType(); samplerate = _mainBuffer.getInternalSamplingRate(); - framesize = getConfigInt(AUDIO, ALSA_FRAME_SIZE); + framesize = audioPreference.getFramesize(); _debug ("Mnager: samplerate: %i, framesize %i\n", samplerate, framesize); - alsaPlugin = getConfigString(AUDIO, ALSA_PLUGIN); + alsaPlugin = audioPreference.getPlugin(); - numCardIn = getConfigInt(AUDIO, ALSA_CARD_ID_IN); - numCardOut = getConfigInt(AUDIO, ALSA_CARD_ID_OUT); - numCardRing = getConfigInt(AUDIO, ALSA_CARD_ID_RING); + numCardIn = audioPreference.getCardin(); + numCardOut = audioPreference.getCardout(); + numCardRing = audioPreference.getCardring(); _debug ("Manager: Deleting current layer... "); @@ -3026,7 +2965,7 @@ void ManagerImpl::audioSamplingRateChanged (void) { delete _telephoneTone; _debugInit ("Manager: Load telephone tone"); - std::string country = getConfigString(PREFERENCES, ZONE_TONE); + std::string country = preferences.getZoneToneChoice(); _telephoneTone = new TelephoneTone(country, sampleRate); @@ -3056,8 +2995,8 @@ void ManagerImpl::audioSamplingRateChanged (void) { */ void ManagerImpl::initVolume () { _debugInit ("Initiate Volume"); - setSpkrVolume(getConfigInt(AUDIO, VOLUME_SPKR)); - setMicVolume(getConfigInt(AUDIO, VOLUME_MICRO)); + setSpkrVolume(audioPreference.getVolumespkr()); + setMicVolume(audioPreference.getVolumemic()); } void ManagerImpl::setSpkrVolume (unsigned short spkr_vol) { @@ -3083,7 +3022,7 @@ void ManagerImpl::setMicVolume (unsigned short mic_vol) { int ManagerImpl::getLocalIp2IpPort (void) { // The SIP port used for default account (IP to IP) calls= - return getConfigInt(IP2IP_PROFILE, LOCAL_PORT); + return preferences.getPortNum(); } @@ -3244,7 +3183,7 @@ std::string ManagerImpl::getConfigString (const std::string& section, //THREAD=Main bool ManagerImpl::setConfig (const std::string& section, const std::string& name, const std::string& value) { - // _debug ("ManagerImpl::setConfig %s %s %s", section.c_str(), name.c_str(), value.c_str()); + return _config.setConfigTreeItem(section, name, value); } @@ -3259,7 +3198,8 @@ bool ManagerImpl::setConfig (const std::string& section, void ManagerImpl::setAccountsOrder (const std::string& order) { _debug ("Setcreate accounts order : %s", order.c_str()); // Set the new config - setConfig(PREFERENCES, CONFIG_ACCOUNTS_ORDER, order); + + preferences.setAccountOrder(order); } std::vector<std::string> ManagerImpl::getAccountList () { @@ -3268,25 +3208,35 @@ std::vector<std::string> ManagerImpl::getAccountList () { std::vector<std::string> account_order; unsigned int i; + _debug("Manager: Get account list"); + account_order = loadAccountOrder(); AccountMap::iterator iter; // The IP2IP profile is always available, and first in the list iter = _accountMap.find(IP2IP_PROFILE); - if (iter->second != NULL) - v.push_back(iter->first.data()); + if (iter->second != NULL) { + _debug("PUSHING BACK %s", iter->first.c_str()); + // v.push_back(iter->first.data()); + v.push_back(iter->second->getAccountID()); + } + else { + _error("Manager: could not find IP2IP profile in getAccount list"); + } // If no order has been set, load the default one // ie according to the creation date. if (account_order.size() == 0) { + _debug("Manager: account order is empty"); iter = _accountMap.begin(); while (iter != _accountMap.end()) { if (iter->second != NULL && iter->first != IP2IP_PROFILE) { - //_debug("PUSHING BACK %s\n", iter->first.c_str()); - v.push_back(iter->first.data()); + _debug("PUSHING BACK %s", iter->first.c_str()); + // v.push_back(iter->first.data()); + v.push_back(iter->second->getAccountID()); } iter++; @@ -3296,14 +3246,16 @@ std::vector<std::string> ManagerImpl::getAccountList () { // Otherelse, load the custom one // ie according to the saved order else { - + _debug("Manager: Load account list according to preferences"); for (i = 0; i < account_order.size(); i++) { // This account has not been loaded, so we ignore it if ((iter = _accountMap.find(account_order[i])) != _accountMap.end()) { // If the account is valid if (iter->second != NULL && iter->first != IP2IP_PROFILE) { - v.push_back(iter->first.data()); + _debug("PUSHING BACK %s\n", iter->first.c_str()); + // v.push_back(iter->first.data()); + v.push_back(iter->second->getAccountID()); } } } @@ -3313,151 +3265,20 @@ std::vector<std::string> ManagerImpl::getAccountList () { } std::map<std::string, std::string> ManagerImpl::getAccountDetails ( - const AccountID& accountID) { - std::map<std::string, std::string> a; - - Account * account = _accountMap[accountID]; - - if (account == NULL) { - _debug ("Cannot getAccountDetails on a non-existing accountID %s. Defaults will be used.", accountID.c_str()); - } - - a.insert(std::pair<std::string, std::string>(ACCOUNT_ID, accountID)); - - // The IP profile does not allow to set an alias - (accountID == IP2IP_PROFILE) ? a.insert( - std::pair<std::string, std::string>(CONFIG_ACCOUNT_ALIAS, - DIRECT_IP_CALL)) : a.insert(std::pair<std::string, - std::string>(CONFIG_ACCOUNT_ALIAS, getConfigString(accountID, - CONFIG_ACCOUNT_ALIAS))); - - a.insert(std::pair<std::string, std::string>(CONFIG_ACCOUNT_ENABLE, - getConfigString(accountID, CONFIG_ACCOUNT_ENABLE))); - a.insert(std::pair<std::string, std::string>(CONFIG_ACCOUNT_RESOLVE_ONCE, - getConfigString(accountID, CONFIG_ACCOUNT_RESOLVE_ONCE))); - a.insert(std::pair<std::string, std::string>(CONFIG_ACCOUNT_TYPE, - getConfigString(accountID, CONFIG_ACCOUNT_TYPE))); - a.insert(std::pair<std::string, std::string>(HOSTNAME, getConfigString( - accountID, HOSTNAME))); - a.insert(std::pair<std::string, std::string>(USERNAME, getConfigString( - accountID, USERNAME))); - a.insert(std::pair<std::string, std::string>(ROUTESET, getConfigString( - accountID, ROUTESET))); - a.insert(std::pair<std::string, std::string>(PASSWORD, getConfigString( - accountID, PASSWORD))); - a.insert(std::pair<std::string, std::string>(REALM, getConfigString( - accountID, REALM))); - a.insert(std::pair<std::string, std::string>(USERAGENT, getConfigString( - accountID, USERAGENT))); - a.insert(std::pair<std::string, std::string>(AUTHENTICATION_USERNAME, - getConfigString(accountID, AUTHENTICATION_USERNAME))); - a.insert(std::pair<std::string, std::string>(CONFIG_ACCOUNT_MAILBOX, - getConfigString(accountID, CONFIG_ACCOUNT_MAILBOX))); - a.insert(std::pair<std::string, std::string>( - CONFIG_ACCOUNT_REGISTRATION_EXPIRE, getConfigString(accountID, - CONFIG_ACCOUNT_REGISTRATION_EXPIRE))); - a.insert(std::pair<std::string, std::string>(LOCAL_INTERFACE, - getConfigString(accountID, LOCAL_INTERFACE))); - a.insert(std::pair<std::string, std::string>(PUBLISHED_SAMEAS_LOCAL, - getConfigString(accountID, PUBLISHED_SAMEAS_LOCAL))); - a.insert(std::pair<std::string, std::string>(PUBLISHED_ADDRESS, - getConfigString(accountID, PUBLISHED_ADDRESS))); - a.insert(std::pair<std::string, std::string>(LOCAL_PORT, getConfigString( - accountID, LOCAL_PORT))); - a.insert(std::pair<std::string, std::string>(PUBLISHED_PORT, - getConfigString(accountID, PUBLISHED_PORT))); - a.insert(std::pair<std::string, std::string>(DISPLAY_NAME, getConfigString( - accountID, DISPLAY_NAME))); - a.insert(std::pair<std::string, std::string>(STUN_ENABLE, getConfigString( - accountID, STUN_ENABLE))); - a.insert(std::pair<std::string, std::string>(STUN_SERVER, getConfigString( - accountID, STUN_SERVER))); - a.insert(std::pair<std::string, std::string>(ACCOUNT_DTMF_TYPE, getConfigString( - accountID, ACCOUNT_DTMF_TYPE))); - - RegistrationState state = Unregistered; - std::string registrationStateCode; - std::string registrationStateDescription; - - if (account != NULL) { - if (accountID == IP2IP_PROFILE) { - registrationStateCode = EMPTY_FIELD; - registrationStateDescription = "Direct IP call"; - } else { - state = account->getRegistrationState(); - int code = account->getRegistrationStateDetailed().first; - std::stringstream out; - out << code; - registrationStateCode = out.str(); - registrationStateDescription - = account->getRegistrationStateDetailed().second; - } - } - - (accountID == IP2IP_PROFILE) ? a.insert( - std::pair<std::string, std::string>(REGISTRATION_STATUS, "READY")) - : a.insert(std::pair<std::string, std::string>(REGISTRATION_STATUS, - mapStateNumberToString(state))); - - a.insert(std::pair<std::string, std::string>(REGISTRATION_STATE_CODE, - registrationStateCode)); - a.insert(std::pair<std::string, std::string>( - REGISTRATION_STATE_DESCRIPTION, registrationStateDescription)); - a.insert(std::pair<std::string, std::string>(SRTP_KEY_EXCHANGE, - getConfigString(accountID, SRTP_KEY_EXCHANGE))); - a.insert(std::pair<std::string, std::string>(SRTP_ENABLE, getConfigString( - accountID, SRTP_ENABLE))); - a.insert(std::pair<std::string, std::string>(SRTP_RTP_FALLBACK, - getConfigString(accountID, SRTP_RTP_FALLBACK))); - a.insert(std::pair<std::string, std::string>(ZRTP_DISPLAY_SAS, - getConfigString(accountID, ZRTP_DISPLAY_SAS))); - a.insert(std::pair<std::string, std::string>(ZRTP_DISPLAY_SAS_ONCE, - getConfigString(accountID, ZRTP_DISPLAY_SAS_ONCE))); - a.insert(std::pair<std::string, std::string>(ZRTP_HELLO_HASH, - getConfigString(accountID, ZRTP_HELLO_HASH))); - a.insert(std::pair<std::string, std::string>(ZRTP_NOT_SUPP_WARNING, - getConfigString(accountID, ZRTP_NOT_SUPP_WARNING))); - - // TLS listener is unique and parameters are modified through IP2IP_PROFILE - a.insert(std::pair<std::string, std::string>(TLS_LISTENER_PORT, - Manager::instance().getConfigString(IP2IP_PROFILE, - TLS_LISTENER_PORT))); - a.insert(std::pair<std::string, std::string>(TLS_ENABLE, - Manager::instance().getConfigString(accountID, TLS_ENABLE))); - a.insert(std::pair<std::string, std::string>(TLS_CA_LIST_FILE, - Manager::instance().getConfigString(accountID, TLS_CA_LIST_FILE))); - a.insert( - std::pair<std::string, std::string>(TLS_CERTIFICATE_FILE, - Manager::instance().getConfigString(accountID, - TLS_CERTIFICATE_FILE))); - a.insert( - std::pair<std::string, std::string>(TLS_PRIVATE_KEY_FILE, - Manager::instance().getConfigString(accountID, - TLS_PRIVATE_KEY_FILE))); - a.insert(std::pair<std::string, std::string>(TLS_PASSWORD, - Manager::instance().getConfigString(accountID, TLS_PASSWORD))); - a.insert(std::pair<std::string, std::string>(TLS_METHOD, - Manager::instance().getConfigString(accountID, TLS_METHOD))); - a.insert(std::pair<std::string, std::string>(TLS_CIPHERS, - Manager::instance().getConfigString(accountID, TLS_CIPHERS))); - a.insert(std::pair<std::string, std::string>(TLS_SERVER_NAME, - Manager::instance().getConfigString(accountID, TLS_SERVER_NAME))); - a.insert(std::pair<std::string, std::string>(TLS_VERIFY_SERVER, - Manager::instance().getConfigString(accountID, TLS_VERIFY_SERVER))); - a.insert(std::pair<std::string, std::string>(TLS_VERIFY_CLIENT, - Manager::instance().getConfigString(accountID, TLS_VERIFY_CLIENT))); - a.insert(std::pair<std::string, std::string>( - TLS_REQUIRE_CLIENT_CERTIFICATE, - Manager::instance().getConfigString(accountID, - TLS_REQUIRE_CLIENT_CERTIFICATE))); - a.insert(std::pair<std::string, std::string>(TLS_NEGOTIATION_TIMEOUT_SEC, - Manager::instance().getConfigString(accountID, - TLS_NEGOTIATION_TIMEOUT_SEC))); - a.insert(std::pair<std::string, std::string>(TLS_NEGOTIATION_TIMEOUT_MSEC, - Manager::instance().getConfigString(accountID, - TLS_NEGOTIATION_TIMEOUT_MSEC))); - - return a; + const AccountID& accountID) { + + _debug("------------------------ Manager: get account details %s", accountID.c_str()); + + Account * account; + if(!(account = _accountMap[accountID])) { + _warn("Manager: Cannot getAccountDetails on a non-existing accountID %s.", accountID.c_str()); + // return an empty map + std::map<std::string, std::string> a; + return a; + } + else + return account->getAccountDetails(); + } /* Transform digest to string. @@ -3571,227 +3392,32 @@ void ManagerImpl::setCredential (const std::string& accountID, Manager::instance().setConfig(section, PASSWORD, password); } -//TODO: tidy this up. Make a macro or inline // method to reduce the if/else mess. // Even better, switch to XML ! void ManagerImpl::setAccountDetails (const std::string& accountID, const std::map<std::string, std::string>& details) { - std::map<std::string, std::string> map_cpy; - std::map<std::string, std::string>::iterator iter; + _debug("----------------------- Manager: Set account details %s", accountID.c_str()); + + Account* account; + if(!(account = getAccount(accountID))) { + _warn("Manager: Cannot setAccountDetails on a non-existing accountID %s.", accountID.c_str()); + return; + } - // Work on a copy - map_cpy = details; + account->setAccountDetails(details); - // Get the account type - std::string accountType; - find_in_map(CONFIG_ACCOUNT_TYPE, accountType) - - std::string alias; - std::string type; - std::string hostname; - std::string username; - std::string password; - std::string mailbox; - std::string accountEnable; - - - // Account setting common to SIP and IAX - find_in_map(CONFIG_ACCOUNT_ALIAS, alias) - find_in_map(CONFIG_ACCOUNT_TYPE, type) - find_in_map(HOSTNAME, hostname) - find_in_map(USERNAME, username) - find_in_map(PASSWORD, password) - find_in_map(CONFIG_ACCOUNT_MAILBOX, mailbox); - find_in_map(CONFIG_ACCOUNT_ENABLE, accountEnable); - - setConfig(accountID, CONFIG_ACCOUNT_ALIAS, alias); - setConfig(accountID, CONFIG_ACCOUNT_TYPE, type); - setConfig(accountID, HOSTNAME, hostname); - setConfig(accountID, USERNAME, username); - setConfig(accountID, PASSWORD, password); - setConfig(accountID, CONFIG_ACCOUNT_MAILBOX, mailbox); - setConfig(accountID, CONFIG_ACCOUNT_ENABLE, accountEnable); - - // SIP specific account settings - if(accountType == "SIP") { - - std::string ua_name; - std::string realm; - std::string routeset; - std::string authenticationName; - - std::string resolveOnce; - std::string registrationExpire; - - std::string displayName; - std::string localInterface; - std::string publishedSameasLocal; - std::string localAddress; - std::string publishedAddress; - std::string localPort; - std::string publishedPort; - std::string stunEnable; - std::string stunServer; - std::string dtmfType; - std::string srtpEnable; - std::string srtpRtpFallback; - std::string zrtpDisplaySas; - std::string zrtpDisplaySasOnce; - std::string zrtpNotSuppWarning; - std::string zrtpHelloHash; - std::string srtpKeyExchange; - - std::string tlsListenerPort; - std::string tlsEnable; - std::string tlsCaListFile; - std::string tlsCertificateFile; - std::string tlsPrivateKeyFile; - std::string tlsPassword; - std::string tlsMethod; - std::string tlsCiphers; - std::string tlsServerName; - std::string tlsVerifyServer; - std::string tlsVerifyClient; - std::string tlsRequireClientCertificate; - std::string tlsNegotiationTimeoutSec; - std::string tlsNegotiationTimeoutMsec; - - // general sip settings - find_in_map(DISPLAY_NAME, displayName) - find_in_map(ROUTESET, routeset) - find_in_map(LOCAL_INTERFACE, localInterface) - find_in_map(PUBLISHED_SAMEAS_LOCAL, publishedSameasLocal) - find_in_map(PUBLISHED_ADDRESS, publishedAddress) - find_in_map(LOCAL_PORT, localPort) - find_in_map(PUBLISHED_PORT, publishedPort) - find_in_map(STUN_ENABLE, stunEnable) - find_in_map(STUN_SERVER, stunServer) - find_in_map(ACCOUNT_DTMF_TYPE, dtmfType) - find_in_map(CONFIG_ACCOUNT_RESOLVE_ONCE, resolveOnce) - find_in_map(CONFIG_ACCOUNT_REGISTRATION_EXPIRE, registrationExpire) - - setConfig(accountID, DISPLAY_NAME, displayName); - setConfig(accountID, ROUTESET, routeset); - setConfig(accountID, LOCAL_INTERFACE, localInterface); - setConfig(accountID, PUBLISHED_SAMEAS_LOCAL, publishedSameasLocal); - setConfig(accountID, PUBLISHED_ADDRESS, publishedAddress); - setConfig(accountID, LOCAL_PORT, localPort); - setConfig(accountID, PUBLISHED_PORT, publishedPort); - setConfig(accountID, STUN_ENABLE, stunEnable); - setConfig(accountID, STUN_SERVER, stunServer); - setConfig(accountID, ACCOUNT_DTMF_TYPE, dtmfType); - setConfig(accountID, CONFIG_ACCOUNT_RESOLVE_ONCE, resolveOnce); - setConfig(accountID, CONFIG_ACCOUNT_REGISTRATION_EXPIRE, registrationExpire); - - // sip credential - find_in_map(REALM, realm) - find_in_map(AUTHENTICATION_USERNAME, authenticationName) - find_in_map(USERAGENT, ua_name) - - setConfig(accountID, REALM, realm); - setConfig(accountID, USERAGENT, ua_name); - setConfig(accountID, AUTHENTICATION_USERNAME, authenticationName); - - // srtp settings - find_in_map(SRTP_ENABLE, srtpEnable) - find_in_map(SRTP_RTP_FALLBACK, srtpRtpFallback) - find_in_map(ZRTP_DISPLAY_SAS, zrtpDisplaySas) - find_in_map(ZRTP_DISPLAY_SAS_ONCE, zrtpDisplaySasOnce) - find_in_map(ZRTP_NOT_SUPP_WARNING, zrtpNotSuppWarning) - find_in_map(ZRTP_HELLO_HASH, zrtpHelloHash) - find_in_map(SRTP_KEY_EXCHANGE, srtpKeyExchange) - - setConfig(accountID, SRTP_ENABLE, srtpEnable); - setConfig(accountID, SRTP_RTP_FALLBACK, srtpRtpFallback); - setConfig(accountID, ZRTP_DISPLAY_SAS, zrtpDisplaySas); - setConfig(accountID, ZRTP_DISPLAY_SAS_ONCE, zrtpDisplaySasOnce); - setConfig(accountID, ZRTP_NOT_SUPP_WARNING, zrtpNotSuppWarning); - setConfig(accountID, ZRTP_HELLO_HASH, zrtpHelloHash); - setConfig(accountID, SRTP_KEY_EXCHANGE, srtpKeyExchange); - - // TLS settings - // The TLS listener is unique and globally defined through IP2IP_PROFILE - if(accountID == IP2IP_PROFILE) { - find_in_map(TLS_LISTENER_PORT, tlsListenerPort) - } - find_in_map(TLS_ENABLE, tlsEnable) - find_in_map(TLS_CA_LIST_FILE, tlsCaListFile) - find_in_map(TLS_CERTIFICATE_FILE, tlsCertificateFile) - find_in_map(TLS_PRIVATE_KEY_FILE, tlsPrivateKeyFile) - find_in_map(TLS_PASSWORD, tlsPassword) - find_in_map(TLS_METHOD, tlsMethod) - find_in_map(TLS_CIPHERS, tlsCiphers) - find_in_map(TLS_SERVER_NAME, tlsServerName) - find_in_map(TLS_VERIFY_SERVER, tlsVerifyServer) - find_in_map(TLS_VERIFY_CLIENT, tlsVerifyClient) - find_in_map(TLS_REQUIRE_CLIENT_CERTIFICATE, tlsRequireClientCertificate) - find_in_map(TLS_NEGOTIATION_TIMEOUT_SEC, tlsNegotiationTimeoutSec) - find_in_map(TLS_NEGOTIATION_TIMEOUT_MSEC, tlsNegotiationTimeoutMsec) - - - // The TLS listener is unique and globally defined through IP2IP_PROFILE - if (accountID == IP2IP_PROFILE){ - setConfig(accountID, TLS_LISTENER_PORT, tlsListenerPort); - } - setConfig(accountID, TLS_ENABLE, tlsEnable); - setConfig(accountID, TLS_CA_LIST_FILE, tlsCaListFile); - setConfig(accountID, TLS_CERTIFICATE_FILE, tlsCertificateFile); - setConfig(accountID, TLS_PRIVATE_KEY_FILE, tlsPrivateKeyFile); - setConfig(accountID, TLS_PASSWORD, tlsPassword); - setConfig(accountID, TLS_METHOD, tlsMethod); - setConfig(accountID, TLS_CIPHERS, tlsCiphers); - setConfig(accountID, TLS_SERVER_NAME, tlsServerName); - setConfig(accountID, TLS_VERIFY_SERVER, tlsVerifyServer); - setConfig(accountID, TLS_VERIFY_CLIENT, tlsVerifyClient); - setConfig(accountID, TLS_REQUIRE_CLIENT_CERTIFICATE, tlsRequireClientCertificate); - setConfig(accountID, TLS_NEGOTIATION_TIMEOUT_SEC, tlsNegotiationTimeoutSec); - setConfig(accountID, TLS_NEGOTIATION_TIMEOUT_MSEC,tlsNegotiationTimeoutMsec); - - if (!getMd5CredentialHashing()) { - setConfig(accountID, PASSWORD, password); - } else { - // Make sure not to re-hash the password field if - // it is already saved as a MD5 Hash. - // TODO: This test is weak. Fix this. - if ((password.compare(getConfigString(accountID, PASSWORD)) != 0)) { - _debug ("Password sent and password from config are different. Re-hashing"); - std::string hash; - - if (authenticationName.empty()) { - hash = computeMd5HashFromCredential(username, password, realm); - } else { - hash = computeMd5HashFromCredential(authenticationName, - password, realm); - } - - setConfig(accountID, PASSWORD, hash); - } - } + saveConfig(); - } - - saveConfig(); - - Account * acc = NULL; - acc = getAccount(accountID); - - if (acc != NULL) { - acc->loadConfig(); - - if (acc->isEnabled()) { - acc->registerVoIPLink(); - } else { - acc->unregisterVoIPLink(); - } - } else { - _debug ("ManagerImpl::setAccountDetails: account is NULL"); - } + if (account->isEnabled()) + account->registerVoIPLink(); + else + account->unregisterVoIPLink(); - // Update account details to the client side - if (_dbus) - _dbus->getConfigurationManager()->accountsChanged(); + // Update account details to the client side + if (_dbus) + _dbus->getConfigurationManager()->accountsChanged(); } @@ -3831,13 +3457,14 @@ std::string ManagerImpl::addAccount ( setAccountDetails(accountID.str(), details); // Add the newly created account in the account order list - account_list = getConfigString(PREFERENCES, CONFIG_ACCOUNTS_ORDER); + account_list = preferences.getAccountOrder(); if (account_list != "") { newAccountID += "/"; // Prepend the new account account_list.insert(0, newAccountID); - setConfig(PREFERENCES, CONFIG_ACCOUNTS_ORDER, account_list); + + preferences.setAccountOrder(account_list); } saveConfig(); @@ -3849,11 +3476,17 @@ std::string ManagerImpl::addAccount ( } void ManagerImpl::deleteAllCredential (const AccountID& accountID) { - int numberOfCredential = getConfigInt(accountID, CONFIG_CREDENTIAL_NUMBER); + + Account *account = getAccount(accountID); + + if(account->getType() != "SIP") + return; - int i; + SIPAccount *sipaccount = (SIPAccount *)account; - for (i = 0; i < numberOfCredential; i++) { + int numberOfCredential = sipaccount->getCredentialCount(); + + for (int i = 0; i < numberOfCredential; i++) { std::string credentialIndex; std::stringstream streamOut; streamOut << i; @@ -3865,7 +3498,7 @@ void ManagerImpl::deleteAllCredential (const AccountID& accountID) { } if (accountID.empty() == false) { - setConfig(accountID, CONFIG_CREDENTIAL_NUMBER, 0); + sipaccount->setCredentialCount(0); } } @@ -3950,14 +3583,20 @@ std::vector<std::string> ManagerImpl::loadAccountOrder (void) { std::string account_list; std::vector<std::string> account_vect; - account_list = getConfigString(PREFERENCES, CONFIG_ACCOUNTS_ORDER); + Conf::Key accountOrder("order"); + + account_list = preferences.getAccountOrder(); + return unserialize(account_list); } short ManagerImpl::loadAccountMap () { - _debug ("Loading account map"); + _debug ("Manager: Loading account map"); + + int nbAccount = buildConfiguration(); + /* short nbAccount = 0; TokenList sections = _config.getSections(); std::string accountType; @@ -4033,10 +3672,143 @@ short ManagerImpl::loadAccountMap () { } _debug ("nb account loaded %i \n", nbAccount); - + */ return nbAccount; } +short ManagerImpl::buildConfiguration() { + + _debug("Manager: Build Accounts"); + + // Conf::YamlParser *parser; + Account *tmpAccount = NULL; + int nbAccount = 0; + + try { + + parser = new Conf::YamlParser("sequenceParser.yml"); + + parser->serializeEvents(); + + parser->composeEvents(); + + parser->constructNativeData(); + + } + catch (Conf::YamlParserException &e) { + _error("Manager: %s", e.what()); + } + + // build preferences + preferences.unserialize((Conf::MappingNode *)(parser->getPreferenceSequence())); + voipPreferences.unserialize((Conf::MappingNode *)(parser->getVoipPreferenceSequence())); + addressbookPreference.unserialize((Conf::MappingNode *)(parser->getAddressbookSequence())); + hookPreference.unserialize((Conf::MappingNode *)(parser->getHookSequence())); + audioPreference.unserialize((Conf::MappingNode *)(parser->getAudioSequence())); + + Conf::SequenceNode *seq = parser->getAccountSequence(); + + // Each element in sequence is a new account to create + Conf::Sequence::iterator iterSeq = seq->getSequence()->begin(); + Conf::Sequence::iterator iterIP2IP = seq->getSequence()->begin(); + + Conf::MappingNode *map; + + Conf::Key accTypeKey("type"); + Conf::Key accID("id"); + + // Build IP2IP first + Conf::Key iptoipID("IP2IP"); + + while(iterIP2IP != seq->getSequence()->end()) { + + map = (Conf::MappingNode *)(*iterSeq); + + Conf::ScalarNode * val = (Conf::ScalarNode *)(map->getValue(accID)); + Conf::Value accountid = val->getValue(); + + if(accountid == "IP2IP") { + + _directIpAccount = AccountCreator::createAccount(AccountCreator::SIP_DIRECT_IP_ACCOUNT, ""); + + _debug ("Manager: Create default \"account\" (used as default UDP transport)"); + if (_directIpAccount == NULL) { + _debug ("Manager: Failed to create default \"account\""); + } else { + + _accountMap[IP2IP_PROFILE] = _directIpAccount; + + // Force IP2IP settings to be loaded to be loaded + // No registration in the sense of the REGISTER method is performed. + _directIpAccount->registerVoIPLink(); + + // SIPVoIPlink is used as a singleton, it is the first call to instance here + // The SIP library initialization is done in the SIPVoIPLink constructor + // We need the IP2IP settings to be loaded at this time as they are used + // for default sip transport + + // _directIpAccount->setVoIPLink(SIPVoIPLink::instance ("")); + _directIpAccount->setVoIPLink(); + + break; + } + } + + iterIP2IP++; + } + while(iterSeq != seq->getSequence()->end()) { + + map = (Conf::MappingNode *)(*iterSeq); + + Conf::ScalarNode * val = (Conf::ScalarNode *)(map->getValue(accTypeKey)); + Conf::Value accountType = val->getValue(); + + val = (Conf::ScalarNode *)(map->getValue(accID)); + Conf::Value accountid = val->getValue(); + + _debug("accountid: %s", accountid.c_str()); + if (accountType == "SIP" && accountid != "IP2IP") { + _debug("Account is SIP!!!"); + tmpAccount = AccountCreator::createAccount(AccountCreator::SIP_ACCOUNT, accountid); + } + else if (accountType == "IAX" && accountid != "IP2IP") { + tmpAccount = AccountCreator::createAccount(AccountCreator::IAX_ACCOUNT, accountid); + } + + _debug("ok"); + + if (tmpAccount != NULL) { + + try { + tmpAccount->unserialize(map); + } + catch(SipAccountException &e) { + _error("Manager: %s", e.what()); + } + + _debug ("Manager: Loading account %s ", accountid.c_str()); + _accountMap[accountid] = tmpAccount; + // tmpAccount->setVoIPLink(SIPVoIPLink::instance ("")); + tmpAccount->setVoIPLink(); + nbAccount++; + } + + iterSeq++; + } + + try { + delete parser; + } + catch (Conf::YamlParserException &e) { + _error("AccountCreator: %s", e.what()); + } + + parser = NULL; + + return nbAccount; + +} + void ManagerImpl::unloadAccountMap () { AccountMap::iterator iter = _accountMap.begin(); @@ -4140,22 +3912,12 @@ std::map<std::string, int32_t> ManagerImpl::getAddressbookSettings () { std::map<std::string, int32_t> settings; - settings.insert(std::pair<std::string, int32_t>("ADDRESSBOOK_ENABLE", - getConfigInt(ADDRESSBOOK, ADDRESSBOOK_ENABLE))); - settings.insert(std::pair<std::string, int32_t>("ADDRESSBOOK_MAX_RESULTS", - getConfigInt(ADDRESSBOOK, ADDRESSBOOK_MAX_RESULTS))); - settings.insert(std::pair<std::string, int32_t>( - "ADDRESSBOOK_DISPLAY_CONTACT_PHOTO", getConfigInt(ADDRESSBOOK, - ADDRESSBOOK_DISPLAY_CONTACT_PHOTO))); - settings.insert(std::pair<std::string, int32_t>( - "ADDRESSBOOK_DISPLAY_PHONE_BUSINESS", getConfigInt(ADDRESSBOOK, - ADDRESSBOOK_DISPLAY_PHONE_BUSINESS))); - settings.insert(std::pair<std::string, int32_t>( - "ADDRESSBOOK_DISPLAY_PHONE_HOME", getConfigInt(ADDRESSBOOK, - ADDRESSBOOK_DISPLAY_PHONE_HOME))); - settings.insert(std::pair<std::string, int32_t>( - "ADDRESSBOOK_DISPLAY_PHONE_MOBILE", getConfigInt(ADDRESSBOOK, - ADDRESSBOOK_DISPLAY_PHONE_MOBILE))); + settings.insert(std::pair<std::string, int32_t>("ADDRESSBOOK_ENABLE", addressbookPreference.getEnabled() ? 1 : 0)); + settings.insert(std::pair<std::string, int32_t>("ADDRESSBOOK_MAX_RESULTS", addressbookPreference.getMaxResults())); + settings.insert(std::pair<std::string, int32_t>("ADDRESSBOOK_DISPLAY_CONTACT_PHOTO", addressbookPreference.getPhoto() ? 1 : 0)); + settings.insert(std::pair<std::string, int32_t>("ADDRESSBOOK_DISPLAY_PHONE_BUSINESS", addressbookPreference.getBusiness() ? 1 : 0)); + settings.insert(std::pair<std::string, int32_t>("ADDRESSBOOK_DISPLAY_PHONE_HOME", addressbookPreference.getHome() ? 1 : 0)); + settings.insert(std::pair<std::string, int32_t>("ADDRESSBOOK_DISPLAY_PHONE_MOBILE", addressbookPreference.getMobile() ? 1 : 0)); return settings; } @@ -4163,18 +3925,13 @@ std::map<std::string, int32_t> ManagerImpl::getAddressbookSettings () { void ManagerImpl::setAddressbookSettings ( const std::map<std::string, int32_t>& settings) { - setConfig(ADDRESSBOOK, ADDRESSBOOK_ENABLE, (*settings.find( - "ADDRESSBOOK_ENABLE")).second); - setConfig(ADDRESSBOOK, ADDRESSBOOK_MAX_RESULTS, (*settings.find( - "ADDRESSBOOK_MAX_RESULTS")).second); - setConfig(ADDRESSBOOK, ADDRESSBOOK_DISPLAY_CONTACT_PHOTO, (*settings.find( - "ADDRESSBOOK_DISPLAY_CONTACT_PHOTO")).second); - setConfig(ADDRESSBOOK, ADDRESSBOOK_DISPLAY_PHONE_BUSINESS, (*settings.find( - "ADDRESSBOOK_DISPLAY_PHONE_BUSINESS")).second); - setConfig(ADDRESSBOOK, ADDRESSBOOK_DISPLAY_PHONE_HOME, (*settings.find( - "ADDRESSBOOK_DISPLAY_PHONE_HOME")).second); - setConfig(ADDRESSBOOK, ADDRESSBOOK_DISPLAY_PHONE_MOBILE, (*settings.find( - "ADDRESSBOOK_DISPLAY_PHONE_MOBILE")).second); + + addressbookPreference.setEnabled((settings.find("ADDRESSBOOK_ENABLE")->second == 1) ? true : false); + addressbookPreference.setMaxResults(settings.find("ADDRESSBOOK_MAX_RESULTS")->second); + addressbookPreference.setPhoto((settings.find("ADDRESSBOOK_DISPLAY_CONTACT_PHOTO")->second == 1) ? true : false); + addressbookPreference.setBusiness((settings.find("ADDRESSBOOK_DISPLAY_PHONE_BUSINESS")->second == 1) ? true : false); + addressbookPreference.setHone((settings.find("ADDRESSBOOK_DISPLAY_PHONE_HOME")->second == 1) ? true : false); + addressbookPreference.setMobile((settings.find("ADDRESSBOOK_DISPLAY_PHONE_MOBILE")->second == 1) ? true : false); // Write it to the configuration file saveConfig(); @@ -4183,12 +3940,13 @@ void ManagerImpl::setAddressbookSettings ( void ManagerImpl::setAddressbookList (const std::vector<std::string>& list) { std::string s = serialize(list); - setConfig(ADDRESSBOOK, ADDRESSBOOK_LIST, s); + addressbookPreference.setList(s); + } std::vector<std::string> ManagerImpl::getAddressbookList (void) { - std::string s = getConfigString(ADDRESSBOOK, ADDRESSBOOK_LIST); + std::string s = addressbookPreference.getList(); return unserialize(s); } @@ -4196,39 +3954,25 @@ std::map<std::string, std::string> ManagerImpl::getHookSettings () { std::map<std::string, std::string> settings; - settings.insert(std::pair<std::string, std::string>("URLHOOK_SIP_FIELD", - getConfigString(HOOKS, URLHOOK_SIP_FIELD))); - settings.insert(std::pair<std::string, std::string>("URLHOOK_COMMAND", - getConfigString(HOOKS, URLHOOK_COMMAND))); - settings.insert(std::pair<std::string, std::string>("URLHOOK_SIP_ENABLED", - getConfigString(HOOKS, URLHOOK_SIP_ENABLED))); - settings.insert(std::pair<std::string, std::string>("URLHOOK_IAX2_ENABLED", - getConfigString(HOOKS, URLHOOK_IAX2_ENABLED))); - settings.insert(std::pair<std::string, std::string>( - "PHONE_NUMBER_HOOK_ENABLED", getConfigString(HOOKS, - PHONE_NUMBER_HOOK_ENABLED))); - settings.insert(std::pair<std::string, std::string>( - "PHONE_NUMBER_HOOK_ADD_PREFIX", getConfigString(HOOKS, - PHONE_NUMBER_HOOK_ADD_PREFIX))); + + settings.insert(std::pair<std::string, std::string>("URLHOOK_IAX2_ENABLED", hookPreference.getIax2Enabled() ? "true" : "false")); + settings.insert(std::pair<std::string, std::string>("PHONE_NUMBER_HOOK_ADD_PREFIX", hookPreference.getNumberAddPrefix())); + settings.insert(std::pair<std::string, std::string>("PHONE_NUMBER_HOOK_ENABLED", hookPreference.getNumberEnabled() ? "true" : "false")); + settings.insert(std::pair<std::string, std::string>("URLHOOK_SIP_ENABLED", hookPreference.getSipEnabled() ? "true" : "false")); + settings.insert(std::pair<std::string, std::string>("URLHOOK_COMMAND", hookPreference.getUrlCommand())); + settings.insert(std::pair<std::string, std::string>("URLHOOK_SIP_FIELD", hookPreference.getUrlSipField())); return settings; } -void ManagerImpl::setHookSettings ( - const std::map<std::string, std::string>& settings) { +void ManagerImpl::setHookSettings (const std::map<std::string, std::string>& settings) { - setConfig(HOOKS, URLHOOK_SIP_FIELD, - (*settings.find("URLHOOK_SIP_FIELD")).second); - setConfig(HOOKS, URLHOOK_COMMAND, - (*settings.find("URLHOOK_COMMAND")).second); - setConfig(HOOKS, URLHOOK_SIP_ENABLED, - (*settings.find("URLHOOK_SIP_ENABLED")).second); - setConfig(HOOKS, URLHOOK_IAX2_ENABLED, (*settings.find( - "URLHOOK_IAX2_ENABLED")).second); - setConfig(HOOKS, PHONE_NUMBER_HOOK_ENABLED, (*settings.find( - "PHONE_NUMBER_HOOK_ENABLED")).second); - setConfig(HOOKS, PHONE_NUMBER_HOOK_ADD_PREFIX, (*settings.find( - "PHONE_NUMBER_HOOK_ADD_PREFIX")).second); + hookPreference.setIax2Enabled((settings.find("URLHOOK_IAX2_ENABLED")->second == "true") ? true : false); + hookPreference.setNumberAddPrefix(settings.find("PHONE_NUMBER_HOOK_ADD_PREFIX")->second); + hookPreference.setNumberEnabled((settings.find("PHONE_NUMBER_HOOK_ENABLED")->second == "true") ? true : false); + hookPreference.setSipEnabled((settings.find("URLHOOK_SIP_ENABLED")->second == "true") ? true : false); + hookPreference.setUrlCommand(settings.find("URLHOOK_COMMAND")->second); + hookPreference.setUrlSipField(settings.find("URLHOOK_SIP_FIELD")->second); // Write it to the configuration file saveConfig(); @@ -4333,9 +4077,9 @@ std::map<std::string, std::string> ManagerImpl::send_history_to_client (void) { void ManagerImpl::receive_history_from_client (std::map<std::string, std::string> history) { - _history->set_serialized_history(history, Manager::instance().getConfigInt( - PREFERENCES, CONFIG_HISTORY_LIMIT)); - _history->save_history(); + + _history->set_serialized_history(history, preferences.getHistoryLimit());; + _history->save_history(); } std::vector<std::string> ManagerImpl::getCallList (void) { diff --git a/sflphone-common/src/managerimpl.h b/sflphone-common/src/managerimpl.h old mode 100644 new mode 100755 index fc457c767d62130242f5665b3b4e573ddd3c8ebe..68bf3b84a7e50d5b4e44e41c79ca3c74c14921d8 --- a/sflphone-common/src/managerimpl.h +++ b/sflphone-common/src/managerimpl.h @@ -55,6 +55,9 @@ #include "audio/codecs/codecDescriptor.h" // CodecDescriptor class contained by value here #include "audio/mainbuffer.h" +#include "yamlemitter.h" +#include "yamlparser.h" +#include "preferences.h" class AudioLayer; class GuiFramework; @@ -111,6 +114,18 @@ class ManagerImpl { ManagerImpl (void); ~ManagerImpl (void); + Preferences preferences; + + VoipPreference voipPreferences; + + AddressbookPreference addressbookPreference; + + HookPreference hookPreference; + + AudioPreference audioPreference; + + short buildConfiguration(); + /** * Initialisation of thread (sound) and map. * Init a new VoIPLink, audio codec and audio driver @@ -647,24 +662,24 @@ class ManagerImpl { * @return int 1 if dialpad has to be displayed * 0 otherwise */ - int getDialpad( void ); + // int getDialpad( void ); /** * Set the dialpad visible or not */ - void setDialpad (bool display); + // void setDialpad (bool display); /** * Tells if the user wants to display the volume controls or not * @return int 1 if the controls have to be displayed * 0 otherwise */ - int getVolumeControls( void ); + // int getVolumeControls( void ); /** * Set the volume controls ( mic and speaker ) visible or not */ - void setVolumeControls (bool display); + // void setVolumeControls (bool display); /** * Set recording on / off @@ -690,9 +705,9 @@ class ManagerImpl { */ int getHistoryLimit (void); - void setHistoryEnabled (void); + // void setHistoryEnabled (void); - std::string getHistoryEnabled (void); + // std::string getHistoryEnabled (void); /** @@ -713,35 +728,35 @@ class ManagerImpl { * @return int 1 if it should popup on incoming calls * 0 if it should never popups */ - int popupMode( void ); + // int popupMode( void ); /** * Configure the popup behaviour * When SFLphone is in the system tray, you can configure when it popups * Never or only on incoming calls */ - void switchPopupMode( void ); + // void switchPopupMode( void ); /** * Determine whether or not the search bar (history) should be displayed */ - int getSearchbar( void ); + // int getSearchbar( void ); /** * Configure the search bar behaviour */ - void setSearchbar( void ); + // void setSearchbar( void ); /** * Set the desktop notification level */ - void setNotify( void ); + // void setNotify( void ); /** * Get the desktop notification level * @return int The notification level */ - int32_t getNotify( void ); + // int32_t getNotify( void ); /** * Set the desktop mail notification level @@ -1042,6 +1057,14 @@ class ManagerImpl { ost::Mutex* getAudioLayerMutex() { return &_audiolayer_mutex; } + /** + * Helper function that creates an MD5 Hash from the credential + * information provided as parameters. The hash is computed as + * MD5(username ":" realm ":" password). + * + */ + std::string computeMd5HashFromCredential(const std::string& username, const std::string& password, const std::string& realm); + private: /* Transform digest to string. * output must be at least PJSIP_MD5STRLEN+1 bytes. @@ -1052,14 +1075,6 @@ class ManagerImpl { */ void digest2str(const unsigned char digest[], char *output); - /** - * Helper function that creates an MD5 Hash from the credential - * information provided as parameters. The hash is computed as - * MD5(username ":" realm ":" password). - * - */ - std::string computeMd5HashFromCredential(const std::string& username, const std::string& password, const std::string& realm); - /** * Check if a process is running with the system command * @@ -1340,6 +1355,9 @@ private: */ void check_call_configuration (const CallID& id, const std::string& to, Call::CallConfiguration *callConfig); + Conf::YamlParser *parser; + Conf::YamlEmitter *emitter; + #ifdef TEST bool testCallAccountMap(); bool testAccountMap(); diff --git a/sflphone-common/src/managerimpl_registration.cpp b/sflphone-common/src/managerimpl_registration.cpp old mode 100644 new mode 100755 index 552b2eb4568b25771a766a8c9950b38a4e03b3e8..1329aaa68bce3104d60de4bdacf9b26655739c7b --- a/sflphone-common/src/managerimpl_registration.cpp +++ b/sflphone-common/src/managerimpl_registration.cpp @@ -58,7 +58,7 @@ ManagerImpl::registerAccounts() bool flag = true; AccountMap::iterator iter; - _debugInit ("Initiate VoIP Links Registration"); + _debugInit ("Manager: Initiate VoIP Links Registration"); iter = _accountMap.begin(); /* Loop on the account map previously loaded */ @@ -98,7 +98,7 @@ ManagerImpl::initRegisterAccounts() bool flag = true; AccountMap::iterator iter; - _debugInit ("Initiate VoIP Links Registration"); + _debugInit ("Manager: Initiate VoIP Links Registration"); iter = _accountMap.begin(); /* Loop on the account map previously loaded */ @@ -248,13 +248,16 @@ ManagerImpl::sendRegister (const std::string& accountID , const int32_t& enable) { // Update the active field - setConfig (accountID, CONFIG_ACCOUNT_ENABLE, (enable == 1) ? TRUE_STR:FALSE_STR); - Account* acc = getAccount (accountID); + + if(enable == 1) + acc->setEnabled(true); + else + acc->setEnabled(false); + acc->loadConfig(); // Test on the freshly updated value - if (acc->isEnabled()) { // Verify we aren't already registered, then register _debug ("Send register for account %s\n" , accountID.c_str()); diff --git a/sflphone-common/src/preferences.cpp b/sflphone-common/src/preferences.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2c08c9cd12c8a01de5a7f1dac591b08fd03715d5 --- /dev/null +++ b/sflphone-common/src/preferences.cpp @@ -0,0 +1,419 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc. + * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * 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. + * + * 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. + * + * 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. + */ + +#include "preferences.h" +#include <sstream> +#include "global.h" + +Preferences::Preferences() : _accountOrder("") + , _audioApi(0) + , _historyLimit(30) + , _historyMaxCalls(20) + , _notifyMails(false) + , _zoneToneChoice("North America") + , _registrationExpire(180) + , _ringtoneEnabled(true) + , _portNum(5060) + , _searchBarDisplay(true) + , _zeroConfenable(false) + , _md5Hash(false) +{ + +} + +Preferences::~Preferences() {} + + +void Preferences::serialize(Conf::YamlEmitter *emiter) +{ + + _debug("Preference: Serialize configuration"); + + Conf::MappingNode preferencemap(NULL); + + Conf::ScalarNode order(_accountOrder); + std::stringstream audiostr; audiostr << _audioApi; + Conf::ScalarNode audioapi(audiostr.str()); + std::stringstream histlimitstr; histlimitstr << _historyLimit; + Conf::ScalarNode historyLimit(histlimitstr.str()); + std::stringstream histmaxstr; histmaxstr << _historyMaxCalls; + Conf::ScalarNode historyMaxCalls(histmaxstr.str()); + Conf::ScalarNode notifyMails(_notifyMails ? "true" : "false"); + Conf::ScalarNode zoneToneChoice(_zoneToneChoice); + std::stringstream expirestr; expirestr << _registrationExpire; + Conf::ScalarNode registrationExpire(expirestr.str()); + Conf::ScalarNode ringtoneEnabled(_ringtoneEnabled ? "true" : "false"); + std::stringstream portstr; portstr << _portNum; + Conf::ScalarNode portNum(portstr.str()); + Conf::ScalarNode searchBarDisplay(_searchBarDisplay ? "true" : "false"); + Conf::ScalarNode zeroConfenable(_zeroConfenable ? "true" : "false"); + Conf::ScalarNode md5Hash(_md5Hash ? "true" : "false"); + + preferencemap.setKeyValue(orderKey, &order); + preferencemap.setKeyValue(audioApiKey, &audioapi); + preferencemap.setKeyValue(historyLimitKey, &historyLimit); + preferencemap.setKeyValue(historyMaxCallsKey, &historyMaxCalls); + preferencemap.setKeyValue(notifyMailsKey, ¬ifyMails); + preferencemap.setKeyValue(zoneToneChoiceKey, &zoneToneChoice); + preferencemap.setKeyValue(registrationExpireKey, ®istrationExpire); + preferencemap.setKeyValue(ringtoneEnabledKey, &ringtoneEnabled); + preferencemap.setKeyValue(portNumKey, &portNum); + preferencemap.setKeyValue(searchBarDisplayKey, &searchBarDisplay); + preferencemap.setKeyValue(zeroConfenableKey, &zeroConfenable); + preferencemap.setKeyValue(md5HashKey, &md5Hash); + + emiter->serializePreference(&preferencemap); +} + +void Preferences::unserialize(Conf::MappingNode *map) +{ + + _debug("Preference: Unserialize configuration"); + + Conf::ScalarNode *val; + + val = (Conf::ScalarNode *)(map->getValue(orderKey)); + if(val) { _accountOrder = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(audioApiKey)); + if(val) { _audioApi = atoi(val->getValue().data()); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(historyLimitKey)); + if(val) { _historyLimit = atoi(val->getValue().data()); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(historyMaxCallsKey)); + if(val) { _historyMaxCalls = atoi(val->getValue().data()); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(notifyMailsKey)); + if(val) { _notifyMails = atoi(val->getValue().data()); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(zoneToneChoiceKey)); + if(val) { _zoneToneChoice = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(registrationExpireKey)); + if(val) { _registrationExpire = atoi(val->getValue().data()); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(ringtoneEnabledKey)); + if(val) { _registrationExpire = atoi(val->getValue().data()); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(portNumKey)); + if(val) { _portNum = atoi(val->getValue().data()); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(searchBarDisplayKey)); + if(val && !val->getValue().empty()) { _searchBarDisplay = (val->getValue().compare("true") == 0) ? true : false; val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(zeroConfenableKey)); + if(val && !val->getValue().empty()) { _zeroConfenable = (val->getValue().compare("true") == 0) ? true : false; val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(md5HashKey)); + if(val && !val->getValue().empty()) { _md5Hash = (val->getValue().compare("true") == 0) ? true : false; val = NULL; } + + + +} + + +VoipPreference::VoipPreference() : _playDtmf(true) + , _playTones(true) + , _pulseLength(250) + , _sendDtmfAs(0) + , _symmetricRtp(true) + , _zidFile("zidFile") +{ + +} + +VoipPreference::~VoipPreference() {} + + +void VoipPreference::serialize(Conf::YamlEmitter *emitter) +{ + Conf::MappingNode preferencemap(NULL); + + Conf::ScalarNode playDtmf(_playDtmf ? "true" : "false"); + Conf::ScalarNode playTones(_playTones ? "true" : "false"); + std::stringstream pulselengthstr; pulselengthstr << _pulseLength; + Conf::ScalarNode pulseLength(pulselengthstr.str()); + std::stringstream senddtmfstr; senddtmfstr << _sendDtmfAs; + Conf::ScalarNode sendDtmfAs(senddtmfstr.str()); + Conf::ScalarNode symmetricRtp(_symmetricRtp ? "true" : "false"); + Conf::ScalarNode zidFile(_zidFile.c_str()); + + preferencemap.setKeyValue(playDtmfKey, &playDtmf); + preferencemap.setKeyValue(playTonesKey, &playTones); + preferencemap.setKeyValue(pulseLengthKey, &pulseLength); + preferencemap.setKeyValue(sendDtmfAsKey, &sendDtmfAs); + preferencemap.setKeyValue(symmetricRtpKey, &symmetricRtp); + preferencemap.setKeyValue(zidFileKey, &zidFile); + + emitter->serializeVoipPreference(&preferencemap); +} + +void VoipPreference::unserialize(Conf::MappingNode *map) +{ + + _debug("VoipPreference: Unserialize configuration"); + + Conf::ScalarNode *val = NULL; + + val = (Conf::ScalarNode *)(map->getValue(playDtmfKey)); + if(val && !val->getValue().empty()) { _playDtmf = (val->getValue().compare("true") == 0) ? true : false; val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(playTonesKey)); + if(val && !val->getValue().empty()) { _playTones = (val->getValue().compare("true") == 0) ? true : false; val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(pulseLengthKey)); + if(val) { _pulseLength = atoi(val->getValue().data()); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(sendDtmfAsKey)); + if(val) { _sendDtmfAs = atoi(val->getValue().data()); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(symmetricRtpKey)); + if(val && !val->getValue().empty()) { _symmetricRtp = (val->getValue().compare("true") == 0) ? true : false; val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(zidFileKey)); + if(val) { _zidFile = val->getValue().c_str(); val = NULL; } + +} + + + +AddressbookPreference::AddressbookPreference() : _photo(true) + , _enabled(true) + , _list("") + , _maxResults(25) + , _business(true) + , _home(true) + , _mobile(true) +{ + +} + +AddressbookPreference::~AddressbookPreference() {} + +void AddressbookPreference::serialize(Conf::YamlEmitter *emitter) +{ + _debug("Addressbook: Serialize configuration"); + + Conf::MappingNode preferencemap(NULL); + + Conf::ScalarNode photo(_photo ? "true" : "false"); + Conf::ScalarNode enabled(_enabled ? "true" : "false"); + Conf::ScalarNode list(_list); + std::stringstream maxresultstr; maxresultstr << _maxResults; + Conf::ScalarNode maxResults(maxresultstr.str()); + Conf::ScalarNode business(_business ? "true" : "false"); + Conf::ScalarNode home(_home ? "true" : "false"); + Conf::ScalarNode mobile(_mobile ? "true" : "false"); + + preferencemap.setKeyValue(photoKey, &photo); + preferencemap.setKeyValue(enabledKey, &enabled); + preferencemap.setKeyValue(listKey, &list); + preferencemap.setKeyValue(maxResultsKey, &maxResults); + preferencemap.setKeyValue(businessKey, &business); + preferencemap.setKeyValue(homeKey, &home); + preferencemap.setKeyValue(mobileKey, &mobile); + + emitter->serializeAddressbookPreference(&preferencemap); + +} + +void AddressbookPreference::unserialize(Conf::MappingNode *map) +{ + _debug("Addressbook: Unserialize configuration"); + + Conf::ScalarNode *val = NULL; + + val = (Conf::ScalarNode *)(map->getValue(photoKey)); + if(val && !(val->getValue().empty())) { _photo = (val->getValue() == "true") ? true : false; val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(enabledKey)); + if(val && !val->getValue().empty()) { _enabled = (val->getValue() == "true") ? true : false; val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(listKey)); + if(val) { _list = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(maxResultsKey)); + if(val) { _maxResults = atoi(val->getValue().data()); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(businessKey)); + if(val && !val->getValue().empty()) { _business = (val->getValue() == "true") ? true : false; val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(homeKey)); + if(val && !val->getValue().empty()) { _home = (val->getValue() == "true") ? true : false; val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(mobileKey)); + if(val && !val->getValue().empty()) { _mobile = (val->getValue() == "true") ? true : false; val = NULL; } + +} + + +HookPreference::HookPreference() : _iax2Enabled(false) + , _numberAddPrefix("") + , _numberEnabled(false) + , _sipEnabled(false) + , _urlCommand("x-www-browser") + , _urlSipField("X-sflphone-url") +{ + +} + +HookPreference::~HookPreference() {} + +void HookPreference::serialize(Conf::YamlEmitter *emitter) +{ + _debug("Hook: Serialize configuration"); + + Conf::MappingNode preferencemap(NULL); + + Conf::ScalarNode iax2Enabled(_iax2Enabled ? "true" : "false"); + Conf::ScalarNode numberAddPrefix(_numberAddPrefix); + Conf::ScalarNode numberEnabled(_numberEnabled ? "true" : "false"); + Conf::ScalarNode sipEnabled(_sipEnabled ? "true" : "false"); + Conf::ScalarNode urlCommand(_urlCommand); + Conf::ScalarNode urlSipField(_urlSipField); + + preferencemap.setKeyValue(iax2EnabledKey, &iax2Enabled); + preferencemap.setKeyValue(numberAddPrefixKey, &numberAddPrefix); + preferencemap.setKeyValue(numberEnabledKey, &numberEnabled); + preferencemap.setKeyValue(sipEnabledKey, &sipEnabled); + preferencemap.setKeyValue(urlCommandKey, &urlCommand); + preferencemap.setKeyValue(urlSipFieldKey, &urlSipField); + + emitter->serializeHooksPreference(&preferencemap); +} + +void HookPreference::unserialize(Conf::MappingNode *map) +{ + Conf::ScalarNode *val = NULL; + + _debug("Hook: Unserialize preference"); + + val = (Conf::ScalarNode *)(map->getValue(iax2EnabledKey)); + if(val) { _iax2Enabled = (val->getValue() == "true") ? true : false; val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(numberAddPrefixKey)); + if(val) { _numberAddPrefix = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(numberEnabledKey)); + if(val) { _numberEnabled = (val->getValue() == "true") ? true : false; val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(sipEnabledKey)); + if(val) { _sipEnabled = (val->getValue() == "true") ? true : false; val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(urlCommandKey)); + if(val) { _urlCommand = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(urlSipFieldKey)); + if(val) { _urlSipField = val->getValue(); val = NULL; } + + +} + + + +AudioPreference::AudioPreference() : _cardin(0) + , _cardout(0) + , _cardring(0) + , _framesize(20) + , _plugin("default") + , _smplrate(44100) + , _devicePlayback("") + , _deviceRecord("") + , _deviceRingtone("") + , _recordpath("") + , _ringchoice("/usr/share/sflphone/ringtones/konga.ul") + , _volumemic(100) + , _volumespkr(100) +{ + +} + +AudioPreference::~AudioPreference() {} + +void AudioPreference::serialize(Conf::YamlEmitter *emitter) +{ + Conf::MappingNode preferencemap(NULL); + Conf::MappingNode alsapreferencemap(NULL); + Conf::MappingNode pulsepreferencemap(NULL); + + // alsa preference + std::stringstream instr; instr << _cardin; + Conf::ScalarNode cardin(instr.str()); // 0 + std::stringstream outstr; outstr << _cardout; + Conf::ScalarNode cardout(outstr.str()); // 0 + std::stringstream ringstr; ringstr << _cardring; + Conf::ScalarNode cardring(ringstr.str());// 0 + std::stringstream framestr; framestr << _framesize; + Conf::ScalarNode framesize(framestr.str()); // 20 + Conf::ScalarNode plugin(_plugin); // default + std::stringstream ratestr; ratestr << _smplrate; + Conf::ScalarNode smplrate(ratestr.str());// 44100 + + //pulseaudio preference + Conf::ScalarNode devicePlayback(_devicePlayback);//: + Conf::ScalarNode deviceRecord(_deviceRecord); //: + Conf::ScalarNode deviceRingtone(_deviceRingtone); //: + + // general preference + Conf::ScalarNode recordpath(_recordpath); //: /home/msavard/Bureau + Conf::ScalarNode ringchoice(_ringchoice); // : /usr/share/sflphone/ringtones/konga.ul + std::stringstream micstr; micstr << _volumemic; + Conf::ScalarNode volumemic(micstr.str()); //: 100 + std::stringstream spkrstr; spkrstr << _volumespkr; + Conf::ScalarNode volumespkr(spkrstr.str()); //: 100 + + preferencemap.setKeyValue(recordpathKey, &recordpath); + preferencemap.setKeyValue(ringchoiceKey, &ringchoice); + preferencemap.setKeyValue(volumemicKey, &volumemic); + preferencemap.setKeyValue(volumespkrKey, &volumespkr); + + preferencemap.setKeyValue(alsamapKey, &alsapreferencemap); + alsapreferencemap.setKeyValue(cardinKey, &cardin); + alsapreferencemap.setKeyValue(cardoutKey, &cardout); + alsapreferencemap.setKeyValue(cardringKey, &cardring); + alsapreferencemap.setKeyValue(framesizeKey, &framesize); + alsapreferencemap.setKeyValue(pluginKey, &plugin); + alsapreferencemap.setKeyValue(smplrateKey, &smplrate); + + preferencemap.setKeyValue(pulsemapKey, &pulsepreferencemap); + pulsepreferencemap.setKeyValue(devicePlaybackKey, &devicePlayback); + pulsepreferencemap.setKeyValue(deviceRecordKey, &deviceRecord); + pulsepreferencemap.setKeyValue(deviceRingtoneKey, &deviceRingtone); + + emitter->serializeAudioPreference(&preferencemap); + +} + +void AudioPreference::unserialize(Conf::MappingNode *map) +{ + Conf::ScalarNode *val = NULL; + + val = (Conf::ScalarNode *)(map->getValue(cardinKey)); + if(val) { _cardin = atoi(val->getValue().data()); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(cardoutKey)); + if(val) { _cardout = atoi(val->getValue().data()); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(cardringKey)); + if(val) { _cardring = atoi(val->getValue().data()); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(framesizeKey)); + if(val) { _framesize = atoi(val->getValue().data()); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(smplrateKey)); + if(val) { _smplrate = atoi(val->getValue().data()); val = NULL; } + + val = (Conf::ScalarNode *)(map->getValue(devicePlaybackKey)); + if(val) { _devicePlayback = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(deviceRecordKey)); + if(val) { _deviceRecord = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(deviceRingtoneKey)); + if(val) { _deviceRingtone = val->getValue(); val = NULL; } + + val = (Conf::ScalarNode *)(map->getValue(recordpathKey)); + if(val) { _recordpath = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(ringchoiceKey)); + if(val) { _ringchoice = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(volumemicKey)); + if(val) { _volumemic = atoi(val->getValue().data()); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(volumespkrKey)); + if(val) { _volumespkr = atoi(val->getValue().data()); val = NULL; } + +} diff --git a/sflphone-common/src/preferences.h b/sflphone-common/src/preferences.h new file mode 100755 index 0000000000000000000000000000000000000000..c9fda934795a10b7c444758630a3ab88975e6153 --- /dev/null +++ b/sflphone-common/src/preferences.h @@ -0,0 +1,368 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc. + * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * 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. + * + * 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. + * + * 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. + */ + +#ifndef __PREFERENCE_H__ +#define __PREFERENCE_H__ + +#include "config/serializable.h" + +// general preferences +const Conf::Key orderKey("order"); // : 1234/2345/ +const Conf::Key audioApiKey("audioApi"); // : 0 +const Conf::Key historyLimitKey("historyLimit"); // : 30 +const Conf::Key historyMaxCallsKey("historyMaxCalls"); // : 20 +const Conf::Key notifyMailsKey("notifyMails"); // : false +const Conf::Key zoneToneChoiceKey("zoneToneChoice"); // : North America +const Conf::Key registrationExpireKey("registrationExpire");// : 180 +const Conf::Key ringtoneEnabledKey("ringtoneEnabled"); // : true +const Conf::Key portNumKey("portNum"); // : 5060 +const Conf::Key searchBarDisplayKey("searchBarDisplay"); // : true +const Conf::Key zeroConfenableKey("zeroConfenable"); // : false +const Conf::Key md5HashKey("md5Hash"); // : false + +// voip preferences +const Conf::Key playDtmfKey("playDtmf"); // true true +const Conf::Key playTonesKey("playTones"); // true +const Conf::Key pulseLengthKey("pulseLength"); //=250 +const Conf::Key sendDtmfAsKey("sendDtmfAs");// =0 +const Conf::Key symmetricRtpKey("symmetric");// =true +const Conf::Key zidFileKey("zidFile");// =sfl.zid + +// addressbook preferences +const Conf::Key photoKey("photo");// false +const Conf::Key enabledKey("enabled");// true +const Conf::Key listKey("list");// 1243608768.30329.0@emilou-desktop/1243456917.15690.23@emilou-desktop/ +const Conf::Key maxResultsKey("maxResults");// 25 +const Conf::Key businessKey("business");// true +const Conf::Key homeKey("home");// false +const Conf::Key mobileKey("mobile");// false + +// hooks preferences +const Conf::Key iax2EnabledKey("iax2Enabled");// : false +const Conf::Key numberAddPrefixKey("numberAddPrefix");//: false +const Conf::Key numberEnabledKey("numberEnabled"); //: false +const Conf::Key sipEnabledKey("sipEnabled"); //: false +const Conf::Key urlCommandKey("urlCommand"); //: x-www-browser +const Conf::Key urlSipFieldKey("urlSipField"); //: X-sflphone-url + + +const Conf::Key alsamapKey("alsa"); +const Conf::Key pulsemapKey("pulse"); +const Conf::Key cardinKey("cardin");// : 0 +const Conf::Key cardoutKey("cardout");// 0 +const Conf::Key cardringKey("cardring");// : 0 +const Conf::Key framesizeKey("framesize");// : 20 +const Conf::Key pluginKey("plugin"); //: default +const Conf::Key smplrateKey("smplrate");//: 44100 +const Conf::Key devicePlaybackKey("devicePlayback");//: +const Conf::Key deviceRecordKey("deviceRecord");// : +const Conf::Key deviceRingtoneKey("deviceRecord");// : +const Conf::Key recordpathKey("recordpath");//: /home/msavard/Bureau +const Conf::Key ringchoiceKey("ringchoice");//: /usr/share/sflphone/ringtones/konga.ul +const Conf::Key volumemicKey("volumemic");//: 100 +const Conf::Key volumespkrKey("volumespkr");//: 100 + + +class Preferences : public Serializable { + + public: + + Preferences(); + + ~Preferences(); + + virtual void serialize(Conf::YamlEmitter *emitter); + + virtual void unserialize(Conf::MappingNode *map); + + + std::string getAccountOrder(void) { return _accountOrder; } + void setAccountOrder(std::string ord) { _accountOrder = ord; } + + int getAudioApi(void) { return _audioApi; } + void setAudioApi(int api) { _audioApi = api; } + + int getHistoryLimit(void) { return _historyLimit; } + void setHistoryLimit(int lim) { _historyLimit = lim; } + + int getHistoryMaxCalls(void) { return _historyMaxCalls; } + void setHistoryMaxCalls(int max) { _historyMaxCalls = max; } + + bool getNotifyMails(void) { return _notifyMails; } + void setNotifyMails(bool mails) { _notifyMails = mails; } + + std::string getZoneToneChoice(void) { return _zoneToneChoice; } + void setZoneToneChoice(std::string str) { _zoneToneChoice = str; } + + int getRegistrationExpire(void) { return _registrationExpire; } + void setRegistrationExpire(int exp) { _registrationExpire = exp; } + + bool getRingtoneEnabled(void) { return _ringtoneEnabled; } + void setRingtoneEnabled(bool ring) { _ringtoneEnabled = ring; } + + int getPortNum(void) { return _portNum; } + void setPortNum(int port) { _portNum = port; } + + bool getSearchBarDisplay(void) { return _searchBarDisplay; } + void setSearchBarDisplay(bool search) { _searchBarDisplay = search; } + + bool getZeroConfenable(void) { return _zeroConfenable; } + void setZeroConfenable(bool enable) { _zeroConfenable = enable; } + + bool getMd5Hash(void) { return _md5Hash; } + void setMd5Hash(bool md5) { _md5Hash = md5; } + + private: + + // account order + std::string _accountOrder; + + int _audioApi; + int _historyLimit; + int _historyMaxCalls; + bool _notifyMails; + std::string _zoneToneChoice; + int _registrationExpire; + bool _ringtoneEnabled; + int _portNum; + bool _searchBarDisplay; + bool _zeroConfenable; + bool _md5Hash; + +}; + + +class VoipPreference : public Serializable { + + public: + + VoipPreference(); + + ~VoipPreference(); + + virtual void serialize(Conf::YamlEmitter *emitter); + + virtual void unserialize(Conf::MappingNode *map); + + bool getPlayDtmf(void) { return _playDtmf; } + void setPlayDtmf(bool dtmf) { _playDtmf = dtmf; } + + bool getPlayTones(void) { return _playTones; } + void setPlayTones(bool tone) { _playTones = tone; } + + int getPulseLength(void) { return _pulseLength; } + void setPulseLength(int length) { _pulseLength = length; } + + int getSendDtmfAs(void) { return _sendDtmfAs; } + void setSendDtmfAs(int dtmf) { _sendDtmfAs = dtmf; } + + bool getSymmetricRtp(void) { return _symmetricRtp; } + void setSymmetricRtp(bool sym) { _symmetricRtp = sym; } + + std::string getZidFile(void) { return _zidFile; } + void setZidFile(std::string file) { _zidFile = file; } + + private: + + bool _playDtmf; + bool _playTones; + int _pulseLength; + int _sendDtmfAs; + bool _symmetricRtp; + std::string _zidFile; + +}; + +class AddressbookPreference : public Serializable { + + public: + + AddressbookPreference(); + + ~AddressbookPreference(); + + virtual void serialize(Conf::YamlEmitter *emitter); + + virtual void unserialize(Conf::MappingNode *map); + + bool getPhoto(void) { return _photo;} + void setPhoto(bool p) { _photo = p; } + + bool getEnabled(void) { return _enabled; } + void setEnabled(bool e) { _enabled = e; } + + std::string getList(void) { return _list; } + void setList(std::string l) { _list = l; } + + int getMaxResults(void) { return _maxResults; } + void setMaxResults(int r) { _maxResults = r; } + + bool getBusiness(void) { return _business; } + void setBusiness(bool b) { _business = b; } + + bool getHome(void) { return _home; } + void setHone(bool h) { _home = h; } + + bool getMobile(void) { return _mobile; } + void setMobile(bool m) { _mobile = m; } + + private: + + bool _photo; + bool _enabled; + std::string _list; + int _maxResults; + bool _business; + bool _home; + bool _mobile; + +}; + + +class HookPreference : public Serializable { + + public: + + HookPreference(); + + ~HookPreference(); + + virtual void serialize(Conf::YamlEmitter *emitter); + + virtual void unserialize(Conf::MappingNode *map); + + bool getIax2Enabled(void) { return _iax2Enabled; } + void setIax2Enabled( bool i) { _iax2Enabled = i; } + + std::string getNumberAddPrefix(void) { return _numberAddPrefix; } + void setNumberAddPrefix(std::string n) { _numberAddPrefix = n; } + + bool getNumberEnabled(void) { return _numberEnabled; } + void setNumberEnabled(bool n) { _numberEnabled = n; } + + bool getSipEnabled(void) { return _sipEnabled; } + void setSipEnabled(bool s) { _sipEnabled = s; } + + std::string getUrlCommand(void) { return _urlCommand; } + void setUrlCommand(std::string u) { _urlCommand = u; } + + std::string getUrlSipField(void) { return _urlSipField; } + void setUrlSipField(std::string u) { _urlSipField = u; } + + private: + + bool _iax2Enabled;// : false + std::string _numberAddPrefix;//: false + bool _numberEnabled; //: false + bool _sipEnabled; //: false + std::string _urlCommand; //: x-www-browser + std::string _urlSipField; //: X-sflphone-url + +}; + + +class AudioPreference : public Serializable { + + public: + + AudioPreference(); + + ~AudioPreference(); + + virtual void serialize(Conf::YamlEmitter *emitter); + + virtual void unserialize(Conf::MappingNode *map); + + // alsa preference + int getCardin(void) { return _cardin; } + void setCardin(int c) { _cardin = c; } + + int getCardout(void) { return _cardout; } + void setCardout(int c) { _cardout = c; } + + int getCardring(void) { return _cardring; } + void setCardring(int c) { _cardring = c; } + + int getFramesize(void) { return _framesize; } + void setFramesize(int f) { _framesize = f; } + + std::string getPlugin(void) { return _plugin; } + void setPlugin(std::string p) { _plugin = p; } + + int getSmplrate(void) { return _smplrate; } + void setSmplrate(int r) { _smplrate = r; } + + //pulseaudio preference + std::string getDevicePlayback(void) { return _devicePlayback; } + void setDevicePlayback(std::string p) { _devicePlayback = p; } + + std::string getDeviceRecord(void) { return _deviceRecord; } + void setDeviceRecord(std::string r) { _deviceRecord = r; } + + std::string getDeviceRingtone(void) { return _deviceRingtone; } + void setDeviceRingtone(std::string r) { _deviceRingtone = r; } + + // general preference + std::string getRecordpath(void) { return _recordpath; } + void setRecordpath(std::string r) { _recordpath = r; } + + std::string getRingchoice(void) { return _ringchoice; } + void setRingchoice(std::string r) { _ringchoice = r; } + + int getVolumemic(void) { return _volumemic; } + void setVolumemic(int m) { _volumemic = m; } + + int getVolumespkr(void) { return _volumespkr; } + void setVolumespkr(int s) { _volumespkr = s; } + + private: + + // alsa preference + int _cardin; // 0 + int _cardout; // 0 + int _cardring;// 0 + int _framesize; // 20 + std::string _plugin; // default + int _smplrate;// 44100 + + //pulseaudio preference + std::string _devicePlayback;//: + std::string _deviceRecord; //: + std::string _deviceRingtone; //: + + // general preference + std::string _recordpath; //: /home/msavard/Bureau + std::string _ringchoice; // : /usr/share/sflphone/ringtones/konga.ul + int _volumemic; //: 100 + int _volumespkr; //: 100 + +}; + +#endif diff --git a/sflphone-common/src/sip/sipaccount.cpp b/sflphone-common/src/sip/sipaccount.cpp old mode 100644 new mode 100755 index 97318b47928130283ed86f44dcd0dd056f1edbc8..d9ee027aa9aa149ac738dc6e0b5eb961f797db45 --- a/sflphone-common/src/sip/sipaccount.cpp +++ b/sflphone-common/src/sip/sipaccount.cpp @@ -34,6 +34,41 @@ #include "manager.h" #include "user_cfg.h" #include <pwd.h> +#include <sstream> + +// CredentialItem::CredentialItem() {} + +// CredentialItem::~CredentialItem() {} + +Credentials::Credentials() : credentialCount(0) {} + +Credentials::~Credentials() {} + +CredentialItem *Credentials::getCredential(int index) +{ + if((index >= 0) && (index < credentialCount)) + return &(credentialArray[index]); + else + return NULL; +} + +void Credentials::serialize(Conf::YamlEmitter *emitter) +{ + +} + +void Credentials::unserialize(Conf::MappingNode *map) +{ + + Conf::ScalarNode *val = NULL; + + _debug("SipAccount: Unserialize"); + + val = (Conf::ScalarNode *)(map->getValue(credentialCountKey)); + if(val) { credentialCount = atoi(val->getValue().data()); val = NULL; } +} + + SIPAccount::SIPAccount (const AccountID& accountID) : Account (accountID, "sip") @@ -56,8 +91,38 @@ SIPAccount::SIPAccount (const AccountID& accountID) , _tlsSetting (NULL) , _dtmfType(OVERRTP) , _displayName ("") + , _tlsEnable("") + , _tlsPortStr("") + , _tlsCaListFile("") + , _tlsCertificateFile("") + , _tlsPrivateKeyFile("") + , _tlsPassword("") + , _tlsMethod("") + , _tlsCiphers("") + , _tlsServerName("") + , _tlsVerifyServer(false) + , _tlsVerifyClient(false) + , _tlsRequireClientCertificate(false) + , _tlsNegotiationTimeoutSec("") + , _tlsNegotiationTimeoutMsec("") + , _stunServer("") + , _tlsEnabled(false) + , _stunEnabled(false) + // , _routeSet("") + , _authenticationUsename("") + // , _tlsListenerPort("5061") + , _srtpEnabled(false) + , _srtpKeyExchange("") + , _srtpFallback(false) + , _zrtpDisplaySas(false) + , _zrtpDisplaySasOnce(false) + , _zrtpHelloHash(false) + , _zrtpNotSuppWarning(false) + , _useragent("SFLphone") { + _debug("Sip account constructor called"); + // IP2IP settings must be loaded before singleton instanciation, cannot call it here... // _link = SIPVoIPLink::instance (""); @@ -78,6 +143,533 @@ SIPAccount::~SIPAccount() free (_tlsSetting); } +void SIPAccount::serialize(Conf::YamlEmitter *emitter) { + + _debug("SipAccount: serialize %s", _accountID.c_str()); + + + Conf::MappingNode accountmap(NULL); + Conf::MappingNode credentialmap(NULL); + Conf::MappingNode srtpmap(NULL); + Conf::MappingNode zrtpmap(NULL); + Conf::MappingNode tlsmap(NULL); + + Conf::ScalarNode id(Account::_accountID); + Conf::ScalarNode username(Account::_username); + Conf::ScalarNode password(Account::_password); + Conf::ScalarNode alias(Account::_alias); + Conf::ScalarNode hostname(Account::_hostname); + Conf::ScalarNode enable(_enabled ? "true" : "false"); + Conf::ScalarNode type(Account::_type); + Conf::ScalarNode expire(_registrationExpire); + Conf::ScalarNode interface(_interface); + std::stringstream portstr; portstr << _localPort; + Conf::ScalarNode port(portstr.str()); + + Conf::ScalarNode mailbox("97"); + Conf::ScalarNode publishAddr(_publishedIpAddress); + std::stringstream publicportstr; publicportstr << _publishedPort; + Conf::ScalarNode publishPort(publicportstr.str()); + Conf::ScalarNode sameasLocal(_publishedSameasLocal ? "true" : "false"); + Conf::ScalarNode resolveOnce(_resolveOnce ? "true" : "false"); + Conf::ScalarNode codecs(_startupCodecStr); + Conf::ScalarNode stunServer(std::string(_stunServerName.ptr, _stunServerName.slen)); + Conf::ScalarNode stunEnabled(_stunEnabled ? "true" : "false"); + Conf::ScalarNode displayName(_displayName); + Conf::ScalarNode dtmfType(_dtmfType==0 ? "overrtp" : "sipinfo"); + + std::stringstream countstr; countstr << _credentialCount; + Conf::ScalarNode count(countstr.str()); + + Conf::ScalarNode srtpenabled(_srtpEnabled ? "true" : "false"); + Conf::ScalarNode keyExchange(_srtpKeyExchange); + Conf::ScalarNode rtpFallback(_srtpFallback ? "true" : "false"); + + Conf::ScalarNode displaySas(_zrtpDisplaySas ? "true" : "false"); + Conf::ScalarNode displaySasOnce(_zrtpDisplaySasOnce ? "true" : "false"); + Conf::ScalarNode helloHashEnabled(_zrtpHelloHash ? "true" : "false"); + Conf::ScalarNode notSuppWarning(_zrtpNotSuppWarning ? "true" : "false"); + + Conf::ScalarNode tlsport(_tlsPortStr); + Conf::ScalarNode certificate(_tlsCertificateFile); + Conf::ScalarNode calist(_tlsCaListFile); + Conf::ScalarNode ciphers(_tlsCiphers); + Conf::ScalarNode tlsenabled(_tlsEnable); + Conf::ScalarNode tlsmethod(_tlsMethod); + Conf::ScalarNode timeout(_tlsNegotiationTimeoutSec); + Conf::ScalarNode tlspassword(_tlsPassword); + Conf::ScalarNode privatekey(_tlsPrivateKeyFile); + Conf::ScalarNode requirecertif(_tlsRequireClientCertificate ? "true" : "false"); + Conf::ScalarNode server(_tlsServerName); + Conf::ScalarNode verifyclient(_tlsVerifyServer ? "true" : "false"); + Conf::ScalarNode verifyserver(_tlsVerifyClient ? "true" : "false"); + + accountmap.setKeyValue(aliasKey, &alias); + accountmap.setKeyValue(typeKey, &type); + accountmap.setKeyValue(idKey, &id); + accountmap.setKeyValue(usernameKey, &username); + accountmap.setKeyValue(passwordKey, &password); + accountmap.setKeyValue(hostnameKey, &hostname); + accountmap.setKeyValue(accountEnableKey, &enable); + accountmap.setKeyValue(mailboxKey, &mailbox); + accountmap.setKeyValue(expireKey, &expire); + accountmap.setKeyValue(interfaceKey, &interface); + accountmap.setKeyValue(portKey, &port); + accountmap.setKeyValue(publishAddrKey, &publishAddr); + accountmap.setKeyValue(publishPortKey, &publishPort); + accountmap.setKeyValue(sameasLocalKey, &sameasLocal); + accountmap.setKeyValue(resolveOnceKey, &resolveOnce); + accountmap.setKeyValue(dtmfTypeKey, &dtmfType); + accountmap.setKeyValue(displayNameKey, &displayName); + accountmap.setKeyValue(codecsKey, &codecs); + + accountmap.setKeyValue(srtpKey, &srtpmap); + srtpmap.setKeyValue(srtpEnableKey, &srtpenabled); + srtpmap.setKeyValue(keyExchangeKey, &keyExchange); + srtpmap.setKeyValue(rtpFallbackKey, &rtpFallback); + + accountmap.setKeyValue(zrtpKey, &zrtpmap); + zrtpmap.setKeyValue(displaySasKey, &displaySas); + zrtpmap.setKeyValue(displaySasOnceKey, &displaySasOnce); + zrtpmap.setKeyValue(helloHashEnabledKey, &helloHashEnabled); + zrtpmap.setKeyValue(notSuppWarningKey, ¬SuppWarning); + + accountmap.setKeyValue(credKey, &credentialmap); + credentialmap.setKeyValue(credentialCountKey, &count); + + accountmap.setKeyValue(tlsKey, &tlsmap); + tlsmap.setKeyValue(tlsPortKey, &tlsport); + tlsmap.setKeyValue(certificateKey, &certificate); + tlsmap.setKeyValue(calistKey, &calist); + tlsmap.setKeyValue(ciphersKey, &ciphers); + tlsmap.setKeyValue(tlsEnableKey, &tlsenabled); + tlsmap.setKeyValue(methodKey, &tlsmethod); + tlsmap.setKeyValue(timeoutKey, &timeout); + tlsmap.setKeyValue(tlsPasswordKey, &tlspassword); + tlsmap.setKeyValue(privateKeyKey, &privatekey); + tlsmap.setKeyValue(requireCertifKey, &requirecertif); + tlsmap.setKeyValue(serverKey, &server); + tlsmap.setKeyValue(verifyClientKey, &verifyclient); + tlsmap.setKeyValue(verifyServerKey, &verifyserver); + + try{ + emitter->serializeAccount(&accountmap); + } + catch (Conf::YamlEmitterException &e) { + _error("ConfigTree: %s", e.what()); + } +} + + +void SIPAccount::unserialize(Conf::MappingNode *map) +{ + Conf::ScalarNode *val; + Conf::MappingNode *srtpMap; + Conf::MappingNode *tlsMap; + Conf::MappingNode *zrtpMap; + Conf::MappingNode *credMap; + + _debug("SipAccount: Unserialize"); + + val = (Conf::ScalarNode *)(map->getValue(aliasKey)); + if(val) { _alias = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(typeKey)); + if(val) { _type = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(idKey)); + if(val) { _accountID = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(usernameKey)); + if(val) { _username = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(passwordKey)); + if(val) { _password = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(hostnameKey)); + if(val) { _hostname = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(accountEnableKey)); + if(val) { _enabled = (val->getValue().compare("true") == 0) ? true : false; val = NULL; } + // val = (Conf::ScalarNode *)(map->getValue(mailboxKey)); + + val = (Conf::ScalarNode *)(map->getValue(codecsKey)); + if(val) { _startupCodecStr = val->getValue(); val = NULL; } + + val = (Conf::ScalarNode *)(map->getValue(expireKey)); + if(val) { _registrationExpire = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(interfaceKey)); + if(val) { _interface = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(portKey)); + if(val) { _localPort = atoi(val->getValue().data()); val = NULL; } + // val = (Conf::ScalarNode *)(map->getValue(mailboxKey)); + val = (Conf::ScalarNode *)(map->getValue(publishAddrKey)); + if(val) { _publishedIpAddress = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(publishPortKey)); + if(val) { _publishedPort = atoi(val->getValue().data()); val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(sameasLocalKey)); + if(val) { _publishedSameasLocal = (val->getValue().compare("true") == 0) ? true : false; val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(resolveOnceKey)); + if(val) { _resolveOnce = (val->getValue().compare("true") == 0) ? true : false; val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(dtmfTypeKey)); + if(val) { val = NULL; } + // _dtmfType = atoi(val->getValue(); + + // stun enabled + val = (Conf::ScalarNode *)(map->getValue(stunEnabledKey)); + if(val) { _stunEnabled = (val->getValue().compare("true") == 0) ? true : false; val = NULL; } + val = (Conf::ScalarNode *)(map->getValue(stunServerKey)); + if(val) { _stunServer = val->getValue(); val = NULL; } + _stunServerName = pj_str ( (char*) _stunServer.data()); + + credMap = (Conf::MappingNode *)(map->getValue(credKey)); + credentials.unserialize(credMap); + + _credentialCount = credentials.getCredentialCount(); + + val = (Conf::ScalarNode *)(map->getValue(displayNameKey)); + if(val) { _displayName = val->getValue(); val = NULL; } + + // get srtp submap + srtpMap = (Conf::MappingNode *)(map->getValue(srtpKey)); + if(!srtpMap) + throw SipAccountException(" did not found srtp map"); + + val = (Conf::ScalarNode *)(srtpMap->getValue(srtpEnableKey)); + if(val) { _srtpEnabled = (val->getValue().compare("true") == 0) ? true : false; val = NULL; } + val = (Conf::ScalarNode *)(srtpMap->getValue(keyExchangeKey)); + if(val) { _srtpKeyExchange = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(srtpMap->getValue(rtpFallbackKey)); + if(val) { _srtpFallback = (val->getValue().compare("true") == 0) ? true : false; val = NULL; } + + // get zrtp submap + zrtpMap = (Conf::MappingNode *)(map->getValue(zrtpKey)); + if(!zrtpMap) + throw SipAccountException(" did not found zrtp map"); + + val = (Conf::ScalarNode *)(zrtpMap->getValue(displaySasKey)); + if(val) { _zrtpDisplaySas = (val->getValue().compare("true") == 0) ? true : false; val = NULL; } + val = (Conf::ScalarNode *)(zrtpMap->getValue(displaySasOnceKey)); + if(val) { _zrtpDisplaySasOnce = (val->getValue().compare("true") == 0) ? true : false; val = NULL; } + val = (Conf::ScalarNode *)(zrtpMap->getValue(helloHashEnabledKey)); + if(val) { _zrtpHelloHash = (val->getValue().compare("true") == 0) ? true : false; val = NULL; } + val = (Conf::ScalarNode *)(zrtpMap->getValue(notSuppWarningKey)); + if(val) { _zrtpNotSuppWarning = (val->getValue().compare("true") == 0) ? true : false; val = NULL; } + + // get tls submap + tlsMap = (Conf::MappingNode *)(map->getValue(tlsKey)); + if(!tlsMap) + throw SipAccountException(" did not found tls map"); + + val = (Conf::ScalarNode *)(tlsMap->getValue(tlsEnableKey)); + if(val) { _tlsEnable = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(tlsMap->getValue(tlsPortKey)); + if(val) { _tlsPortStr = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(tlsMap->getValue(certificateKey)); + if(val) { _tlsCertificateFile = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(tlsMap->getValue(calistKey)); + if(val) { _tlsCaListFile = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(tlsMap->getValue(ciphersKey)); + if(val) { _tlsCiphers = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(tlsMap->getValue(methodKey)); + if(val) { _tlsMethod = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(tlsMap->getValue(timeoutKey)); + if(val) _tlsNegotiationTimeoutSec = val->getValue(); + if(val) { _tlsNegotiationTimeoutMsec = val->getValue(); val=NULL; } + val = (Conf::ScalarNode *)(tlsMap->getValue(tlsPasswordKey)); + if(val) { _tlsPassword = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(tlsMap->getValue(privateKeyKey)); + if(val) { _tlsPrivateKeyFile = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(tlsMap->getValue(requireCertifKey)); + if(val) { _tlsRequireClientCertificate = (val->getValue().compare("true") == 0) ? true : false; val = NULL; } + val = (Conf::ScalarNode *)(tlsMap->getValue(serverKey)); + if(val) { _tlsServerName = val->getValue(); val = NULL; } + val = (Conf::ScalarNode *)(tlsMap->getValue(verifyClientKey)); + if(val) { _tlsVerifyServer = (val->getValue().compare("true") == 0) ? true : false; val = NULL; } + val = (Conf::ScalarNode *)(tlsMap->getValue(verifyServerKey)); + if(val) { _tlsVerifyClient = (val->getValue().compare("true") == 0) ? true : false; val = NULL; } + +} + + +void SIPAccount::setAccountDetails(const std::map<std::string, std::string>& details) +{ + + std::map<std::string, std::string> map_cpy; + std::map<std::string, std::string>::iterator iter; + + // Work on a copy + map_cpy = details; + + std::string alias; + std::string type; + std::string hostname; + std::string username; + std::string password; + std::string mailbox; + std::string accountEnable; + + // Account setting common to SIP and IAX + find_in_map(CONFIG_ACCOUNT_ALIAS, alias) + find_in_map(CONFIG_ACCOUNT_TYPE, type) + find_in_map(HOSTNAME, hostname) + find_in_map(USERNAME, username) + find_in_map(PASSWORD, password) + find_in_map(CONFIG_ACCOUNT_MAILBOX, mailbox); + find_in_map(CONFIG_ACCOUNT_ENABLE, accountEnable); + + setAlias(alias); + setType(type); + setUsername(username); + setHostname(hostname); + setPassword(password); + setEnabled((accountEnable.compare("true") == 0) ? true : false); + + // SIP specific account settings + if(getType() == "SIP") { + + std::string ua_name; + std::string realm; + std::string routeset; + std::string authenticationName; + + std::string resolveOnce; + std::string registrationExpire; + + std::string displayName; + std::string localInterface; + std::string publishedSameasLocal; + std::string localAddress; + std::string publishedAddress; + std::string localPort; + std::string publishedPort; + std::string stunEnable; + std::string stunServer; + std::string dtmfType; + std::string srtpEnable; + std::string srtpRtpFallback; + std::string zrtpDisplaySas; + std::string zrtpDisplaySasOnce; + std::string zrtpNotSuppWarning; + std::string zrtpHelloHash; + std::string srtpKeyExchange; + + std::string tlsListenerPort; + std::string tlsEnable; + std::string tlsCaListFile; + std::string tlsCertificateFile; + std::string tlsPrivateKeyFile; + std::string tlsPassword; + std::string tlsMethod; + std::string tlsCiphers; + std::string tlsServerName; + std::string tlsVerifyServer; + std::string tlsVerifyClient; + std::string tlsRequireClientCertificate; + std::string tlsNegotiationTimeoutSec; + std::string tlsNegotiationTimeoutMsec; + + // general sip settings + find_in_map(DISPLAY_NAME, displayName) + find_in_map(ROUTESET, routeset) + find_in_map(LOCAL_INTERFACE, localInterface) + find_in_map(PUBLISHED_SAMEAS_LOCAL, publishedSameasLocal) + find_in_map(PUBLISHED_ADDRESS, publishedAddress) + find_in_map(LOCAL_PORT, localPort) + find_in_map(PUBLISHED_PORT, publishedPort) + find_in_map(STUN_ENABLE, stunEnable) + find_in_map(STUN_SERVER, stunServer) + find_in_map(ACCOUNT_DTMF_TYPE, dtmfType) + find_in_map(CONFIG_ACCOUNT_RESOLVE_ONCE, resolveOnce) + find_in_map(CONFIG_ACCOUNT_REGISTRATION_EXPIRE, registrationExpire) + + setDisplayName(displayName); + setRouteSet(routeset); + setLocalInterface(localInterface); + setPublishedSameasLocal((publishedSameasLocal.compare("true") == 0) ? true : false); + setPublishedAddress(publishedAddress); + setLocalPort(atoi(localPort.data())); + setPublishedPort(atoi(publishedPort.data())); + // sipaccount->setStunServerName + // sipaccount->setStunServer(); + // sipaccount->setStunEnable(); + setResolveOnce((resolveOnce.compare("true")==0) ? true : false); + setRegistrationExpire(registrationExpire); + + // sip credential + find_in_map(REALM, realm) + find_in_map(AUTHENTICATION_USERNAME, authenticationName) + find_in_map(USERAGENT, ua_name) + + setUseragent(ua_name); + + // srtp settings + find_in_map(SRTP_ENABLE, srtpEnable) + find_in_map(SRTP_RTP_FALLBACK, srtpRtpFallback) + find_in_map(ZRTP_DISPLAY_SAS, zrtpDisplaySas) + find_in_map(ZRTP_DISPLAY_SAS_ONCE, zrtpDisplaySasOnce) + find_in_map(ZRTP_NOT_SUPP_WARNING, zrtpNotSuppWarning) + find_in_map(ZRTP_HELLO_HASH, zrtpHelloHash) + find_in_map(SRTP_KEY_EXCHANGE, srtpKeyExchange) + + setSrtpEnable((srtpEnable.compare("true") == 0) ? true : false); + setSrtpFallback((srtpRtpFallback.compare("true") == 0) ? true : false); + setZrtpDisplaySas((zrtpDisplaySas.compare("true") == 0) ? true : false); + setZrtpDiaplaySasOnce((zrtpDisplaySasOnce.compare("true") == 0) ? true : false); + setZrtpNotSuppWarning((zrtpNotSuppWarning.compare("true") == 0) ? true : false); + setZrtpHelloHash((zrtpHelloHash.compare("true") == 0) ? true : false); + // sipaccount->setSrtpKeyExchange((srtpKeyExchange.compare("true") == 0) ? true : false); + setSrtpKeyExchange(srtpKeyExchange); + + // TLS settings + // The TLS listener is unique and globally defined through IP2IP_PROFILE + if(_accountID == IP2IP_PROFILE) { + find_in_map(TLS_LISTENER_PORT, tlsListenerPort) + } + find_in_map(TLS_ENABLE, tlsEnable) + find_in_map(TLS_CA_LIST_FILE, tlsCaListFile) + find_in_map(TLS_CERTIFICATE_FILE, tlsCertificateFile) + find_in_map(TLS_PRIVATE_KEY_FILE, tlsPrivateKeyFile) + find_in_map(TLS_PASSWORD, tlsPassword) + find_in_map(TLS_METHOD, tlsMethod) + find_in_map(TLS_CIPHERS, tlsCiphers) + find_in_map(TLS_SERVER_NAME, tlsServerName) + find_in_map(TLS_VERIFY_SERVER, tlsVerifyServer) + find_in_map(TLS_VERIFY_CLIENT, tlsVerifyClient) + find_in_map(TLS_REQUIRE_CLIENT_CERTIFICATE, tlsRequireClientCertificate) + find_in_map(TLS_NEGOTIATION_TIMEOUT_SEC, tlsNegotiationTimeoutSec) + find_in_map(TLS_NEGOTIATION_TIMEOUT_MSEC, tlsNegotiationTimeoutMsec) + + if (_accountID == IP2IP_PROFILE){ + setTlsListenerPort(atoi(tlsListenerPort.data())); + } + setTlsEnable(tlsEnable); + setTlsCaListFile(tlsCaListFile); + setTlsCertificateFile(tlsCertificateFile); + setTlsPrivateKeyFile(tlsPrivateKeyFile); + setTlsPassword(tlsPassword); + setTlsMethod(tlsMethod); + setTlsCiphers(tlsCiphers); + setTlsServerName(tlsServerName); + setTlsVerifyServer(tlsVerifyServer.compare("true") ? true : false); + setTlsVerifyClient(tlsVerifyServer.compare("true") ? true : false); + setTlsRequireClientCertificate(tlsRequireClientCertificate.compare("true") ? true : false); + setTlsNegotiationTimeoutSec(tlsNegotiationTimeoutSec); + setTlsNegotiationTimeoutMsec(tlsNegotiationTimeoutMsec); + + if (!Manager::instance().preferences.getMd5Hash()) { + setPassword(password); + } else { + // Make sure not to re-hash the password field if + // it is already saved as a MD5 Hash. + // TODO: This test is weak. Fix this. + if ((password.compare(getPassword()) != 0)) { + _debug ("SipAccount: Password sent and password from config are different. Re-hashing"); + std::string hash; + + if (authenticationName.empty()) { + hash = Manager::instance().computeMd5HashFromCredential(username, password, realm); + } else { + hash = Manager::instance().computeMd5HashFromCredential(authenticationName, password, realm); + } + + setPassword(hash); + } + } + } +} + +std::map<std::string, std::string> SIPAccount::getAccountDetails() +{ + _debug("--------------------------- SipAccount: get account details %s", _accountID.c_str()); + + std::map<std::string, std::string> a; + + a.insert(std::pair<std::string, std::string>(ACCOUNT_ID, _accountID)); + + // The IP profile does not allow to set an alias + (_accountID == IP2IP_PROFILE) ? + a.insert(std::pair<std::string, std::string>(CONFIG_ACCOUNT_ALIAS, IP2IP_PROFILE)) : + a.insert(std::pair<std::string, std::string>(CONFIG_ACCOUNT_ALIAS, getAlias())); + + a.insert(std::pair<std::string, std::string>(CONFIG_ACCOUNT_ENABLE, isEnabled() ? "true" : "false")); + a.insert(std::pair<std::string, std::string>(CONFIG_ACCOUNT_TYPE, getType())); + a.insert(std::pair<std::string, std::string>(HOSTNAME, getHostname())); + a.insert(std::pair<std::string, std::string>(USERNAME, getUsername())); + a.insert(std::pair<std::string, std::string>(PASSWORD, getPassword())); + + RegistrationState state = Unregistered; + std::string registrationStateCode; + std::string registrationStateDescription; + + + if (_accountID == IP2IP_PROFILE) { + registrationStateCode = EMPTY_FIELD; + registrationStateDescription = "Direct IP call"; + } else { + state = getRegistrationState(); + int code = getRegistrationStateDetailed().first; + std::stringstream out; out << code; + registrationStateCode = out.str(); + registrationStateDescription = getRegistrationStateDetailed().second; + } + + + (_accountID == IP2IP_PROFILE) ? + a.insert(std::pair<std::string, std::string>(REGISTRATION_STATUS, "READY")) : + a.insert(std::pair<std::string, std::string>(REGISTRATION_STATUS, Manager::instance().mapStateNumberToString(state))); + + a.insert(std::pair<std::string, std::string>(REGISTRATION_STATE_CODE, registrationStateCode)); + a.insert(std::pair<std::string, std::string>(REGISTRATION_STATE_DESCRIPTION, registrationStateDescription)); + + // Add sip specific details + if(getType() == "SIP") { + + a.insert(std::pair<std::string, std::string>(ROUTESET, getRouteSet())); + a.insert(std::pair<std::string, std::string>(CONFIG_ACCOUNT_RESOLVE_ONCE, isResolveOnce() ? "true" : "false")); + a.insert(std::pair<std::string, std::string>(REALM, _realm)); + a.insert(std::pair<std::string, std::string>(USERAGENT, getUseragent())); + + a.insert(std::pair<std::string, std::string>(CONFIG_ACCOUNT_REGISTRATION_EXPIRE, getRegistrationExpire())); + a.insert(std::pair<std::string, std::string>(LOCAL_INTERFACE, getLocalInterface())); + a.insert(std::pair<std::string, std::string>(PUBLISHED_SAMEAS_LOCAL, getPublishedSameasLocal() ? "true" : "false")); + a.insert(std::pair<std::string, std::string>(PUBLISHED_ADDRESS, getPublishedAddress())); + + std::stringstream localport; localport << getLocalPort(); + a.insert(std::pair<std::string, std::string>(LOCAL_PORT, localport.str())); + std::stringstream publishedport; publishedport << getPublishedPort(); + a.insert(std::pair<std::string, std::string>(PUBLISHED_PORT, publishedport.str())); + a.insert(std::pair<std::string, std::string>(STUN_ENABLE, isStunEnabled() ? "true" : "false")); + a.insert(std::pair<std::string, std::string>(STUN_SERVER, std::string(getStunServerName().ptr, getStunServerName().slen))); + a.insert(std::pair<std::string, std::string>(ACCOUNT_DTMF_TYPE, (getDtmfType() == 0) ? "0" : "1")); + + a.insert(std::pair<std::string, std::string>(SRTP_KEY_EXCHANGE, getSrtpKeyExchange())); + a.insert(std::pair<std::string, std::string>(SRTP_ENABLE, getSrtpEnable() ? "true" : "false")); + a.insert(std::pair<std::string, std::string>(SRTP_RTP_FALLBACK, getSrtpFallback() ? "true" : "false")); + + a.insert(std::pair<std::string, std::string>(ZRTP_DISPLAY_SAS, getZrtpDisplaySas() ? "true" : "false")); + a.insert(std::pair<std::string, std::string>(ZRTP_DISPLAY_SAS_ONCE, getZrtpDiaplaySasOnce() ? "true" : "false")); + a.insert(std::pair<std::string, std::string>(ZRTP_HELLO_HASH, getZrtpHelloHash() ? "true" : "false")); + a.insert(std::pair<std::string, std::string>(ZRTP_NOT_SUPP_WARNING, getZrtpNotSuppWarning() ? "true" : "false")); + + // TLS listener is unique and parameters are modified through IP2IP_PROFILE + std::stringstream tlslistenerport; + tlslistenerport << getTlsListenerPort(); + a.insert(std::pair<std::string, std::string>(TLS_LISTENER_PORT, tlslistenerport.str())); + a.insert(std::pair<std::string, std::string>(TLS_ENABLE, getTlsEnable())); + a.insert(std::pair<std::string, std::string>(TLS_CA_LIST_FILE, getTlsCaListFile())); + a.insert(std::pair<std::string, std::string>(TLS_CERTIFICATE_FILE, getTlsCertificateFile())); + a.insert(std::pair<std::string, std::string>(TLS_PRIVATE_KEY_FILE, getTlsPrivateKeyFile())); + a.insert(std::pair<std::string, std::string>(TLS_PASSWORD, getTlsPassword())); + a.insert(std::pair<std::string, std::string>(TLS_METHOD, getTlsMethod())); + a.insert(std::pair<std::string, std::string>(TLS_CIPHERS, getTlsCiphers())); + a.insert(std::pair<std::string, std::string>(TLS_SERVER_NAME, getTlsServerName())); + a.insert(std::pair<std::string, std::string>(TLS_VERIFY_SERVER, getTlsVerifyServer() ? "true" : "false")); + a.insert(std::pair<std::string, std::string>(TLS_VERIFY_CLIENT, getTlsVerifyClient() ? "true" : "false")); + a.insert(std::pair<std::string, std::string>(TLS_REQUIRE_CLIENT_CERTIFICATE, getTlsRequireClientCertificate() ? "true" : "false")); + a.insert(std::pair<std::string, std::string>(TLS_NEGOTIATION_TIMEOUT_SEC, getTlsNegotiationTimeoutSec())); + a.insert(std::pair<std::string, std::string>(TLS_NEGOTIATION_TIMEOUT_MSEC, getTlsNegotiationTimeoutMsec())); + + } + + return a; + +} + // void SIPAccount::setVoIPLink(VoIPLink *link) { void SIPAccount::setVoIPLink() { @@ -90,13 +682,15 @@ void SIPAccount::setVoIPLink() { int SIPAccount::initCredential (void) { + _debug("SipAccount: Init credential"); + int credentialCount = 0; - credentialCount = Manager::instance().getConfigInt (_accountID, CONFIG_CREDENTIAL_NUMBER); + credentialCount = credentials.getCredentialCount(); credentialCount += 1; bool md5HashingEnabled = false; int dataType = 0; - md5HashingEnabled = Manager::instance().getConfigBool (PREFERENCES, CONFIG_MD5HASH); + md5HashingEnabled = Manager::instance().preferences.getMd5Hash(); std::string digest; // Create the credential array @@ -111,8 +705,10 @@ int SIPAccount::initCredential (void) // Use authentication username if provided if (!_authenticationUsername.empty()) { + _debug("Use credential authentication name -------------------------------------"); cred_info[0].username = pj_str (strdup (_authenticationUsername.c_str())); } else { + _debug("Use credential uername name -------------------------------------"); cred_info[0].username = pj_str (strdup (_username.c_str())); } @@ -141,6 +737,7 @@ int SIPAccount::initCredential (void) int i; for (i = 1; i < credentialCount; i++) { + _debug("--------------------------------------- Not supposed to have any credential"); std::string credentialIndex; std::stringstream streamOut; streamOut << i - 1; @@ -174,7 +771,7 @@ int SIPAccount::initCredential (void) _debug ("Setting credential %d realm = %s passwd = %s username = %s data_type = %d", i, realm.c_str(), password.c_str(), username.c_str(), cred_info[i].data_type); } - _credentialCount = credentialCount; + credentials.setCredentialCount(credentialCount); _cred = cred_info; @@ -184,10 +781,10 @@ int SIPAccount::initCredential (void) int SIPAccount::registerVoIPLink() { - _debug ("Register account %s", getAccountID().c_str()); + _debug ("Account: Register account %s", getAccountID().c_str()); // Init general settings - loadConfig(); + // loadConfig(); if (_hostname.length() >= PJ_MAX_HOSTNAME) { return !SUCCESS; @@ -197,7 +794,7 @@ int SIPAccount::registerVoIPLink() initCredential(); // Init TLS settings if the user wants to use TLS - bool tlsEnabled = Manager::instance().getConfigBool (_accountID, TLS_ENABLE); + bool tlsEnabled = false; if (tlsEnabled) { _transportType = PJSIP_TRANSPORT_TLS; @@ -205,12 +802,15 @@ int SIPAccount::registerVoIPLink() } // Init STUN settings for this account if the user selected it - bool stunEnabled = Manager::instance().getConfigBool (_accountID, STUN_ENABLE); + bool stunEnabled = _stunEnabled; if (stunEnabled) { _transportType = PJSIP_TRANSPORT_START_OTHER; initStunConfiguration (); } + else { + _stunServerName = pj_str ((char*) _stunServer.data()); + } // In our definition of the // ip2ip profile (aka Direct IP Calls), @@ -275,8 +875,9 @@ void SIPAccount::initTlsConfiguration (void) } // TLS listener is unique and should be only modified through IP2IP_PROFILE - std::string tlsPortStr = Manager::instance().getConfigString(_accountID, TLS_LISTENER_PORT); - setTlsListenerPort(atoi(tlsPortStr.c_str())); + + // setTlsListenerPort(atoi(tlsPortStr.c_str())); + setTlsListenerPort(atoi(_tlsPortStr.c_str())); _tlsSetting = (pjsip_tls_setting *) malloc (sizeof (pjsip_tls_setting)); @@ -284,33 +885,20 @@ void SIPAccount::initTlsConfiguration (void) pjsip_tls_setting_default (_tlsSetting); - std::string tlsCaListFile = Manager::instance().getConfigString (_accountID, TLS_CA_LIST_FILE); - std::string tlsCertificateFile = Manager::instance().getConfigString (_accountID, TLS_CERTIFICATE_FILE); - std::string tlsPrivateKeyFile = Manager::instance().getConfigString (_accountID, TLS_PRIVATE_KEY_FILE); - std::string tlsPassword = Manager::instance().getConfigString (_accountID, TLS_PASSWORD); - std::string tlsMethod = Manager::instance().getConfigString (_accountID, TLS_METHOD); - std::string tlsCiphers = Manager::instance().getConfigString (_accountID, TLS_CIPHERS); - std::string tlsServerName = Manager::instance().getConfigString (_accountID, TLS_SERVER_NAME); - bool tlsVerifyServer = Manager::instance().getConfigBool (_accountID, TLS_VERIFY_SERVER); - bool tlsVerifyClient = Manager::instance().getConfigBool (_accountID, TLS_VERIFY_CLIENT); - bool tlsRequireClientCertificate = Manager::instance().getConfigBool (_accountID, TLS_REQUIRE_CLIENT_CERTIFICATE); - std::string tlsNegotiationTimeoutSec = Manager::instance().getConfigString (_accountID, TLS_NEGOTIATION_TIMEOUT_SEC); - std::string tlsNegotiationTimeoutMsec = Manager::instance().getConfigString (_accountID, TLS_NEGOTIATION_TIMEOUT_MSEC); - - pj_cstr (&_tlsSetting->ca_list_file, tlsCaListFile.c_str()); - pj_cstr (&_tlsSetting->cert_file, tlsCertificateFile.c_str()); - pj_cstr (&_tlsSetting->privkey_file, tlsPrivateKeyFile.c_str()); - pj_cstr (&_tlsSetting->password, tlsPassword.c_str()); - _tlsSetting->method = sslMethodStringToPjEnum (tlsMethod); - pj_cstr (&_tlsSetting->ciphers, tlsCiphers.c_str()); - pj_cstr (&_tlsSetting->server_name, tlsServerName.c_str()); - - _tlsSetting->verify_server = (tlsVerifyServer == true) ? PJ_TRUE: PJ_FALSE; - _tlsSetting->verify_client = (tlsVerifyClient == true) ? PJ_TRUE: PJ_FALSE; - _tlsSetting->require_client_cert = (tlsRequireClientCertificate == true) ? PJ_TRUE: PJ_FALSE; - - _tlsSetting->timeout.sec = atol (tlsNegotiationTimeoutSec.c_str()); - _tlsSetting->timeout.msec = atol (tlsNegotiationTimeoutMsec.c_str()); + pj_cstr (&_tlsSetting->ca_list_file, _tlsCaListFile.c_str()); + pj_cstr (&_tlsSetting->cert_file, _tlsCertificateFile.c_str()); + pj_cstr (&_tlsSetting->privkey_file, _tlsPrivateKeyFile.c_str()); + pj_cstr (&_tlsSetting->password, _tlsPassword.c_str()); + _tlsSetting->method = sslMethodStringToPjEnum (_tlsMethod); + pj_cstr (&_tlsSetting->ciphers, _tlsCiphers.c_str()); + pj_cstr (&_tlsSetting->server_name, _tlsServerName.c_str()); + + _tlsSetting->verify_server = (_tlsVerifyServer == true) ? PJ_TRUE: PJ_FALSE; + _tlsSetting->verify_client = (_tlsVerifyClient == true) ? PJ_TRUE: PJ_FALSE; + _tlsSetting->require_client_cert = (_tlsRequireClientCertificate == true) ? PJ_TRUE: PJ_FALSE; + + _tlsSetting->timeout.sec = atol (_tlsNegotiationTimeoutSec.c_str()); + _tlsSetting->timeout.msec = atol (_tlsNegotiationTimeoutMsec.c_str()); } @@ -319,8 +907,7 @@ void SIPAccount::initStunConfiguration (void) size_t pos; std::string stunServer, serverName, serverPort; - stunServer = Manager::instance().getConfigString (_accountID, STUN_SERVER); - + stunServer = _stunServer; // Init STUN socket pos = stunServer.find (':'); @@ -339,51 +926,10 @@ void SIPAccount::initStunConfiguration (void) void SIPAccount::loadConfig() { - // Load primary credential - setUsername (Manager::instance().getConfigString (_accountID, USERNAME)); - setRouteSet(Manager::instance().getConfigString(_accountID, ROUTESET)); - setPassword (Manager::instance().getConfigString (_accountID, PASSWORD)); - _authenticationUsername = Manager::instance().getConfigString (_accountID, AUTHENTICATION_USERNAME); - _realm = Manager::instance().getConfigString (_accountID, REALM); - _resolveOnce = Manager::instance().getConfigString (_accountID, CONFIG_ACCOUNT_RESOLVE_ONCE) == "1" ? true : false; - - // Load general account settings - setHostname (Manager::instance().getConfigString (_accountID, HOSTNAME)); - - if (Manager::instance().getConfigString (_accountID, CONFIG_ACCOUNT_REGISTRATION_EXPIRE).empty()) { + if (_registrationExpire.empty()) _registrationExpire = DFT_EXPIRE_VALUE; - } else { - _registrationExpire = Manager::instance().getConfigString (_accountID, CONFIG_ACCOUNT_REGISTRATION_EXPIRE); - } - - // Load network settings - // Local parameters - - // Load local interface - setLocalInterface(Manager::instance().getConfigString (_accountID, LOCAL_INTERFACE)); - - std::string localPort = Manager::instance().getConfigString (_accountID, LOCAL_PORT); - setLocalPort (atoi (localPort.c_str())); - - - // Published parameters - setPublishedSameasLocal (Manager::instance().getConfigString (_accountID, PUBLISHED_SAMEAS_LOCAL) == TRUE_STR ? true : false); - - std::string publishedPort = Manager::instance().getConfigString (_accountID, PUBLISHED_PORT); - - setPublishedPort (atoi (publishedPort.c_str())); - setPublishedAddress (Manager::instance().getConfigString (_accountID, PUBLISHED_ADDRESS)); - - if(Manager::instance().getConfigString (_accountID, ACCOUNT_DTMF_TYPE) == OVERRTPSTR) - _dtmfType = OVERRTP; - else - _dtmfType = SIPINFO; - - // Init TLS settings if the user wants to use TLS - bool tlsEnabled = Manager::instance().getConfigBool (_accountID, TLS_ENABLE); - - if (tlsEnabled) { + if (_tlsEnabled) { initTlsConfiguration(); _transportType = PJSIP_TRANSPORT_TLS; } else { @@ -540,6 +1086,8 @@ std::string SIPAccount::getServerUri (void) // UDP does not require the transport specification + _debug("---------------------------- _hostname %s", _hostname.c_str()); + if (_transportType == PJSIP_TRANSPORT_TLS) { scheme = "sips:"; transport = ";transport=" + std::string (pjsip_transport_get_type_name (_transportType)); @@ -578,8 +1126,6 @@ std::string SIPAccount::getContactHeader (const std::string& address, const std: transport = ""; } - _displayName = Manager::instance().getConfigString (_accountID, DISPLAY_NAME); - _debug ("Display Name: %s", _displayName.c_str()); int len = pj_ansi_snprintf (contact, PJSIP_MAX_URL_SIZE, diff --git a/sflphone-common/src/sip/sipaccount.h b/sflphone-common/src/sip/sipaccount.h old mode 100644 new mode 100755 index 51fb6de0c451eaffd5642f2b4824f15384ab14e0..70cad3af7883c65b211c6ea8528b8180395ea480 --- a/sflphone-common/src/sip/sipaccount.h +++ b/sflphone-common/src/sip/sipaccount.h @@ -41,12 +41,63 @@ #include "sipvoiplink.h" #include "pjsip/sip_transport_tls.h" #include "pjsip/sip_types.h" +#include "config/serializable.h" +#include <exception> +#include <map> enum DtmfType { OVERRTP, SIPINFO}; #define OVERRTPSTR "overrtp" #define SIPINFOSTR "sipinfo" + +// SIP specific configuration keys +const Conf::Key expireKey("expire"); +const Conf::Key interfaceKey("interface"); +const Conf::Key portKey("port"); +const Conf::Key publishAddrKey("publishAddr"); +const Conf::Key publishPortKey("publishPort"); +const Conf::Key sameasLocalKey("sameasLocal"); +const Conf::Key resolveOnceKey("resolveOnce"); +const Conf::Key dtmfTypeKey("dtmfType"); + +// TODO: write an object to store credential which implement serializable +const Conf::Key srtpKey("srtp"); +const Conf::Key srtpEnableKey("enable"); +const Conf::Key keyExchangeKey("keyExchange"); +const Conf::Key rtpFallbackKey("rtpFallback"); + +// TODO: wirte an object to store zrtp params wich implement serializable +const Conf::Key zrtpKey("zrtp"); +const Conf::Key displaySasKey("displaySas"); +const Conf::Key displaySasOnceKey("displaySasOnce"); +const Conf::Key helloHashEnabledKey("helloHashEnabled"); +const Conf::Key notSuppWarningKey("notSuppWarning"); + +// TODO: write an object to store tls params which implement serializable +const Conf::Key tlsKey("tls"); +const Conf::Key tlsPortKey("tlsPort"); +const Conf::Key certificateKey("certificate"); +const Conf::Key calistKey("calist"); +const Conf::Key ciphersKey("ciphers"); +const Conf::Key tlsEnableKey("enable"); +const Conf::Key methodKey("method"); +const Conf::Key timeoutKey("timeout"); +const Conf::Key tlsPasswordKey("password"); +const Conf::Key privateKeyKey("privateKey"); +const Conf::Key requireCertifKey("requireCertif"); +const Conf::Key serverKey("server"); +const Conf::Key verifyClientKey("verifyClient"); +const Conf::Key verifyServerKey("verifyServer"); + +const Conf::Key stunEnabledKey("stunEnabled"); +const Conf::Key stunServerKey("stunServer"); + +const Conf::Key credKey("credential"); +const Conf::Key credentialCountKey("count"); + +const Conf::Key displayNameKey("displayName"); + class SIPVoIPLink; /** @@ -54,6 +105,61 @@ class SIPVoIPLink; * @brief A SIP Account specify SIP specific functions and object (SIPCall/SIPVoIPLink) */ +class SipAccountException : public std::exception +{ + public: + SipAccountException(const std::string& str="") throw() : errstr(str) {} + + virtual ~SipAccountException() throw() {} + + virtual const char *what() const throw() { + std::string expt("SipAccountException occured: "); + expt.append(errstr); + + return expt.c_str(); + } + private: + std::string errstr; + +}; + +class CredentialItem +{ + public: + + std::string username; + std::string password; + std::string realm; +}; + + +class Credentials : public Serializable +{ + public: + + Credentials(); + + ~Credentials(); + + virtual void serialize(Conf::YamlEmitter *emitter); + + virtual void unserialize(Conf::MappingNode *map); + + int getCredentialCount(void) { return credentialCount; } + void setCredentialCount(int count) { credentialCount = count; } + + void setNewCredential(std::string username, std::string password, std::string realm); + CredentialItem *getCredential(int index); + + private: + + int credentialCount; + + CredentialItem credentialArray[10]; + +}; + + class SIPAccount : public Account { public: @@ -74,6 +180,14 @@ class SIPAccount : public Account */ virtual ~SIPAccount(); + virtual void serialize(Conf::YamlEmitter *emitter); + + virtual void unserialize(Conf::MappingNode *map); + + virtual void setAccountDetails(const std::map<std::string, std::string>& details); + + virtual std::map<std::string, std::string> getAccountDetails(); + /** * Set route header to appears in sip messages for this account */ @@ -112,6 +226,7 @@ class SIPAccount : public Account inline void setAuthenticationUsername(const std::string& username) { _authenticationUsername = username; } inline bool isResolveOnce(void) { return _resolveOnce; } + void setResolveOnce(bool reslv) { _resolveOnce = reslv; } /** @@ -161,7 +276,8 @@ class SIPAccount : public Account * @param none * @return int The number of credentials set for this account. */ - inline int getCredentialCount(void) { return _credentialCount; } + inline int getCredentialCount(void) { return credentials.getCredentialCount(); } + inline void setCredentialCount(int count) { return credentials.setCredentialCount(count); } /** * @return pjsip_tls_setting structure, filled from the configuration @@ -197,7 +313,7 @@ class SIPAccount : public Account * account is set to OTHER. */ inline bool isStunEnabled(void) { return (_transportType == PJSIP_TRANSPORT_START_OTHER) ? true: false; } - + inline void setStunEnabled(bool enabl) { _stunEnabled = enabl; } /* * @return pj_str_t "From" uri based on account information. @@ -330,9 +446,78 @@ class SIPAccount : public Account std::string getTransportMapKey(void); DtmfType getDtmfType(void) { return _dtmfType; } - void setDtmfType(DtmfType type) { _dtmfType = type; } + std::string getDisplayName(void) { return _displayName; } + void setDisplayName(std::string name) { _displayName = name ;} + + bool getSrtpEnable(void) { return _srtpEnabled; } + void setSrtpEnable(bool enabl) { _srtpEnabled = enabl; } + + std::string getSrtpKeyExchange(void) { return _srtpKeyExchange; } + void setSrtpKeyExchange(std::string key) { _srtpKeyExchange = key; } + + bool getSrtpFallback(void) { return _srtpFallback; } + void setSrtpFallback(bool fallback) { _srtpFallback = fallback; } + + bool getZrtpDisplaySas(void) { return _zrtpDisplaySas; } + void setZrtpDisplaySas(bool sas) { _zrtpDisplaySas = sas; } + + bool getZrtpDiaplaySasOnce(void) { return _zrtpDisplaySasOnce; } + void setZrtpDiaplaySasOnce(bool sasonce) { _zrtpDisplaySasOnce = sasonce; } + + bool getZrtpNotSuppWarning(void) { return _zrtpNotSuppWarning; } + void setZrtpNotSuppWarning(bool warning) { _zrtpNotSuppWarning = warning; } + + bool getZrtpHelloHash(void) { return _zrtpHelloHash; } + void setZrtpHelloHash(bool hellohash) { _zrtpHelloHash = hellohash; } + // void setSrtpKeyExchange + + std::string getRealm(void) { return _realm; } + void setRealm(std::string r) { _realm = r; } + + std::string getTlsEnable(void) {return _tlsEnable; } + void setTlsEnable(std::string enabl) { _tlsEnable = enabl; } + + std::string getTlsCaListFile(void) { return _tlsCaListFile; } + void setTlsCaListFile(std::string calist) { _tlsCaListFile = calist; } + + std::string getTlsCertificateFile(void) { return _tlsCertificateFile; } + void setTlsCertificateFile(std::string cert) { _tlsCertificateFile = cert; } + + std::string getTlsPrivateKeyFile(void) { return _tlsPrivateKeyFile; } + void setTlsPrivateKeyFile(std::string priv) { _tlsPrivateKeyFile = priv; } + + std::string getTlsPassword(void) { return _tlsPassword; } + void setTlsPassword(std::string pass) { _tlsPassword = pass; } + + std::string getTlsMethod(void) { return _tlsMethod; } + void setTlsMethod(std::string meth) { _tlsMethod = meth; } + + std::string getTlsCiphers(void) { return _tlsCiphers; } + void setTlsCiphers(std::string cipher) { _tlsCiphers = cipher; } + + std::string getTlsServerName(void) { return _tlsServerName; } + void setTlsServerName(std::string name) { _tlsServerName = name; } + + bool getTlsVerifyServer(void) { return _tlsVerifyServer; } + void setTlsVerifyServer(bool verif) { _tlsVerifyServer = verif; } + + bool getTlsVerifyClient(void) { return _tlsVerifyClient; } + void setTlsVerifyClient(bool verif) { _tlsVerifyClient = verif; } + + bool getTlsRequireClientCertificate(void) { return _tlsRequireClientCertificate; } + void setTlsRequireClientCertificate(bool require) { _tlsRequireClientCertificate = require; } + + std::string getTlsNegotiationTimeoutSec(void) { return _tlsNegotiationTimeoutSec; } + void setTlsNegotiationTimeoutSec(std::string timeout) { _tlsNegotiationTimeoutSec = timeout; } + + std::string getTlsNegotiationTimeoutMsec(void) { return _tlsNegotiationTimeoutMsec; } + void setTlsNegotiationTimeoutMsec(std::string timeout) { _tlsNegotiationTimeoutMsec = timeout; } + + std::string getUseragent(void) { return _useragent; } + void setUseragent(std::string ua) { _useragent = ua; } + private: /* Maps a string description of the SSL method @@ -415,6 +600,7 @@ class SIPAccount : public Account pjsip_cred_info *_cred; std::string _realm; std::string _authenticationUsername; + Credentials credentials; // The TLS settings, if tls is chosen as // a sip transport. @@ -429,7 +615,50 @@ class SIPAccount : public Account DtmfType _dtmfType; // Display Name that can be used in SIP URI. - std::string _displayName; + std::string _displayName; + + std::string _tlsEnable; + std::string _tlsPortStr; + std::string _tlsCaListFile; + std::string _tlsCertificateFile; + std::string _tlsPrivateKeyFile; + std::string _tlsPassword; + std::string _tlsMethod; + std::string _tlsCiphers; + std::string _tlsServerName; + bool _tlsVerifyServer; + bool _tlsVerifyClient; + bool _tlsRequireClientCertificate; + std::string _tlsNegotiationTimeoutSec; + std::string _tlsNegotiationTimeoutMsec; + + std::string _stunServer; + + bool _tlsEnabled; + bool _stunEnabled; + + // std::string _routeset; + + // std::string _realm; + std::string _authenticationUsename; + + // std::string _tlsListenerPort; + // std::string _routeSet; + // std::string _dtmfType; + + + bool _srtpEnabled; + std::string _srtpKeyExchange; + bool _srtpFallback; + + bool _zrtpDisplaySas; + bool _zrtpDisplaySasOnce; + bool _zrtpHelloHash; + bool _zrtpNotSuppWarning; + + std::string _useragent; + + }; #endif diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp old mode 100644 new mode 100755 index a005ab44408ff388ebe41076eb77fd0ee2de9444..5a92fcb49d13d0f8f72a1cb66bdc2275127f26fb --- a/sflphone-common/src/sip/sipvoiplink.cpp +++ b/sflphone-common/src/sip/sipvoiplink.cpp @@ -266,6 +266,8 @@ SIPVoIPLink::SIPVoIPLink (const AccountID& accountID) , _regPort (atoi (DEFAULT_SIP_PORT)) , _clients (0) { + + _debug("SIPVOIPLINK"); // to get random number for RANDOM_PORT srand (time (NULL)); @@ -444,13 +446,16 @@ std::string SIPVoIPLink::get_useragent_name (const AccountID& id) useragent << PROGNAME << "/" << SFLPHONED_VERSION; return useragent.str(); */ + + SIPAccount *account = (SIPAccount *)Manager::instance().getAccount(id); + std::ostringstream useragent; - - useragent << Manager::instance ().getConfigString (id, USERAGENT); - if (useragent.str() == "sflphone" || useragent.str() == "") - useragent << "/" << SFLPHONED_VERSION; - return useragent.str (); + useragent << account->getUseragent(); + if (useragent.str() == "sflphone" || useragent.str() == "") + useragent << "/" << SFLPHONED_VERSION; + + return useragent.str (); } void @@ -575,6 +580,7 @@ int SIPVoIPLink::sendRegister (AccountID id) std::string fromUri = account->getFromUri(); std::string srvUri = account->getServerUri(); + _debug("----------------------------------------------- srvUri %s, %s", account->getAccountID().c_str(), srvUri.c_str()); std::string address = findLocalAddressFromUri (srvUri, account->getAccountTransport ()); int port = findLocalPortFromUri (srvUri, account->getAccountTransport ()); @@ -650,8 +656,11 @@ int SIPVoIPLink::sendRegister (AccountID id) pj_list_push_back (&hdr_list, (pjsip_hdr*) h); // pj_list_push_back (&hdr_list, (pjsip_hdr*) routing); + if (regc) + _debug("No regc ......"); + pjsip_regc_add_headers (regc, &hdr_list); - + status = pjsip_regc_register (regc, PJ_TRUE, &tdata); if (status != PJ_SUCCESS) { @@ -1335,7 +1344,7 @@ SIPVoIPLink::dtmfSipInfo(SIPCall *call, char code) pjsip_media_type ctype; - duration = Manager::instance().getConfigInt (SIGNALISATION, PULSE_LENGTH); + duration = Manager::instance().voipPreferences.getPulseLength(); dtmf_body = new char[body_len]; @@ -2558,10 +2567,14 @@ std::string SIPVoIPLink::findLocalAddressFromUri (const std::string& uri, pjsip_ return machineName; } - std::string localaddr(localAddress.ptr, localAddress.slen); - _debug ("SIP: Local address discovered from attached transport: %s", localaddr.c_str()); + std::string localaddr(localAddress.ptr, localAddress.slen); + + if(localaddr == "0.0.0.0") + loadSIPLocalIP (&localaddr); - return std::string (localAddress.ptr, localAddress.slen); + _debug ("SIP: Local address discovered from attached transport: %s", localaddr.c_str()); + + return localaddr; } @@ -3285,8 +3298,10 @@ void call_on_media_update (pjsip_inv_session *inv, pj_status_t status) // if RTPFALLBACK, change RTP session AccountID accountID = Manager::instance().getAccountFromCall (call->getCallId()); - if(Manager::instance().getConfigString (accountID, SRTP_RTP_FALLBACK) == "true") - call->getAudioRtp()->initAudioRtpSession(call); + SIPAccount *account = (SIPAccount *)Manager::instance().getAccount(accountID); + + if(account->getSrtpFallback()) + call->getAudioRtp()->initAudioRtpSession(call); } if(nego_success && call->getAudioRtp()->getAudioRtpType() != sfl::Sdes) { @@ -3427,7 +3442,7 @@ void regc_cb (struct pjsip_regc_cbparam *param) out << (expire_value * 2); std::string s = out.str(); - Manager::instance().setConfig(account->getAccountID(), CONFIG_ACCOUNT_REGISTRATION_EXPIRE, s); + account->setRegistrationExpire(s); account->registerVoIPLink(); } break; @@ -3635,18 +3650,19 @@ mod_on_rx_request (pjsip_rx_data *rdata) /******************************************* URL HOOK *********************************************/ - if (Manager::instance().getConfigString (HOOKS, URLHOOK_SIP_ENABLED) == "1") { + if (Manager::instance().hookPreference.getSipEnabled()) { _debug("UserAgent: Set sip url hooks"); std::string header_value; - header_value = fetch_header_value (rdata->msg_info.msg, Manager::instance().getConfigString (HOOKS, URLHOOK_SIP_FIELD)); + header_value = fetch_header_value (rdata->msg_info.msg, + Manager::instance().hookPreference.getUrlSipField()); if (header_value.size () < header_value.max_size()) { if (header_value!="") { urlhook->addAction (header_value, - Manager::instance().getConfigString (HOOKS, URLHOOK_COMMAND)); + Manager::instance().hookPreference.getUrlCommand()); } } else throw length_error ("UserAgent: Url exceeds std::string max_size"); diff --git a/sflphone-common/test/Makefile.am b/sflphone-common/test/Makefile.am index ed3baa511efa87f422b7e52bd0ec3681b7c9a287..9da8e2f60349f9304800235277ac1158142b6d92 100644 --- a/sflphone-common/test/Makefile.am +++ b/sflphone-common/test/Makefile.am @@ -40,5 +40,5 @@ LLIBS=$(CPPUNIT_LIBS) \ ../src/sflphoned-numbercleaner.o \ ../src/sflphoned-observer.o \ ../src/sflphoned-voiplink.o \ + ../src/sflphoned-preferences.o \ ../src/libsflphone.la - diff --git a/sflphone-common/test/configurationtest.cpp b/sflphone-common/test/configurationtest.cpp old mode 100644 new mode 100755 index 23294f67ccb7b2316212cf823f709768b5db0f8a..62fa5743d95b74c7d2367048420686acaacd2aaa --- a/sflphone-common/test/configurationtest.cpp +++ b/sflphone-common/test/configurationtest.cpp @@ -150,3 +150,147 @@ void ConfigurationTest::testInitAudioDriver() { else CPPUNIT_FAIL ("Wrong audio layer type"); } + + +void ConfigurationTest::testYamlParser() +{ + + Conf::YamlParser *parser; + try { + + parser = new Conf::YamlParser("sequence2.yml"); + + parser->serializeEvents(); + + parser->composeEvents(); + + parser->constructNativeData(); + + delete parser; + parser = NULL; + + } + catch (Conf::YamlParserException &e) { + _error("ConfigTree: %s", e.what()); + } + +} + +void ConfigurationTest::testYamlEmitter() +{ + Conf::YamlEmitter *emitter; + + Conf::MappingNode accountmap(NULL); + Conf::MappingNode credentialmap(NULL); + Conf::MappingNode srtpmap(NULL); + Conf::MappingNode zrtpmap(NULL); + Conf::MappingNode tlsmap(NULL); + + + Conf::ScalarNode id("Account:1278432417"); + Conf::ScalarNode username("181"); + Conf::ScalarNode password("pass181"); + Conf::ScalarNode alias("sfl-181"); + Conf::ScalarNode hostname("192.168.50.3"); + Conf::ScalarNode enable("true"); + Conf::ScalarNode type("SIP"); + Conf::ScalarNode expire("3600"); + Conf::ScalarNode interface("default"); + Conf::ScalarNode port("5060"); + Conf::ScalarNode mailbox("97"); + Conf::ScalarNode publishAddr("192.168.50.182"); + Conf::ScalarNode publishPort("5060"); + Conf::ScalarNode sameasLocal("true"); + Conf::ScalarNode resolveOnce("false"); + Conf::ScalarNode codecs("0/9/110/111/112/"); + Conf::ScalarNode stunServer("stun.sflphone.org"); + Conf::ScalarNode stunEnabled("false"); + Conf::ScalarNode displayName("Alexandre Savard"); + Conf::ScalarNode dtmfType("sipinfo"); + + Conf::ScalarNode count("0"); + + Conf::ScalarNode srtpenabled("false"); + Conf::ScalarNode keyExchange("sdes"); + Conf::ScalarNode rtpFallback("false"); + + Conf::ScalarNode displaySas("false"); + Conf::ScalarNode displaySasOnce("false"); + Conf::ScalarNode helloHashEnabled("false"); + Conf::ScalarNode notSuppWarning("false"); + + Conf::ScalarNode tlsport(""); + Conf::ScalarNode certificate(""); + Conf::ScalarNode calist(""); + Conf::ScalarNode ciphers(""); + Conf::ScalarNode tlsenabled("false"); + Conf::ScalarNode tlsmethod("TLSV1"); + Conf::ScalarNode timeout("0"); + Conf::ScalarNode tlspassword(""); + Conf::ScalarNode privatekey(""); + Conf::ScalarNode requirecertif("true"); + Conf::ScalarNode server(""); + Conf::ScalarNode verifyclient("true"); + Conf::ScalarNode verifyserver("true"); + + accountmap.setKeyValue(aliasKey, &alias); + accountmap.setKeyValue(typeKey, &type); + accountmap.setKeyValue(idKey, &id); + accountmap.setKeyValue(usernameKey, &username); + accountmap.setKeyValue(passwordKey, &password); + accountmap.setKeyValue(hostnameKey, &hostname); + accountmap.setKeyValue(accountEnableKey, &enable); + accountmap.setKeyValue(mailboxKey, &mailbox); + accountmap.setKeyValue(expireKey, &expire); + accountmap.setKeyValue(interfaceKey, &interface); + accountmap.setKeyValue(portKey, &port); + accountmap.setKeyValue(publishAddrKey, &publishAddr); + accountmap.setKeyValue(publishPortKey, &publishPort); + accountmap.setKeyValue(sameasLocalKey, &sameasLocal); + accountmap.setKeyValue(resolveOnceKey, &resolveOnce); + accountmap.setKeyValue(dtmfTypeKey, &dtmfType); + accountmap.setKeyValue(displayNameKey, &displayName); + + accountmap.setKeyValue(srtpKey, &srtpmap); + srtpmap.setKeyValue(srtpEnableKey, &srtpenabled); + srtpmap.setKeyValue(keyExchangeKey, &keyExchange); + srtpmap.setKeyValue(rtpFallbackKey, &rtpFallback); + + accountmap.setKeyValue(zrtpKey, &zrtpmap); + zrtpmap.setKeyValue(displaySasKey, &displaySas); + zrtpmap.setKeyValue(displaySasOnceKey, &displaySasOnce); + zrtpmap.setKeyValue(helloHashEnabledKey, &helloHashEnabled); + zrtpmap.setKeyValue(notSuppWarningKey, ¬SuppWarning); + + accountmap.setKeyValue(credKey, &credentialmap); + credentialmap.setKeyValue(credentialCountKey, &count); + + accountmap.setKeyValue(tlsKey, &tlsmap); + tlsmap.setKeyValue(tlsPortKey, &tlsport); + tlsmap.setKeyValue(certificateKey, &certificate); + tlsmap.setKeyValue(calistKey, &calist); + tlsmap.setKeyValue(ciphersKey, &ciphers); + tlsmap.setKeyValue(tlsEnableKey, &tlsenabled); + tlsmap.setKeyValue(methodKey, &tlsmethod); + tlsmap.setKeyValue(timeoutKey, &timeout); + tlsmap.setKeyValue(tlsPasswordKey, &tlspassword); + tlsmap.setKeyValue(privateKeyKey, &privatekey); + tlsmap.setKeyValue(requireCertifKey, &requirecertif); + tlsmap.setKeyValue(serverKey, &server); + tlsmap.setKeyValue(verifyClientKey, &verifyclient); + tlsmap.setKeyValue(verifyServerKey, &verifyserver); + + try{ + emitter = new Conf::YamlEmitter("/tmp/sequenceEmiter.txt"); + + emitter->writeAccount(&accountmap); + emitter->writeAccount(&accountmap); + emitter->serializeData(); + + delete emitter; + } + catch (Conf::YamlEmitterException &e) { + _error("ConfigTree: %s", e.what()); + } + +} diff --git a/sflphone-common/test/configurationtest.h b/sflphone-common/test/configurationtest.h old mode 100644 new mode 100755 index 1e2f572aa55ecd36324eb1672f0954a6f7badb94..84d840674fad87fcaf467925c05a9537a7983464 --- a/sflphone-common/test/configurationtest.h +++ b/sflphone-common/test/configurationtest.h @@ -50,6 +50,11 @@ #include "audio/audiolayer.h" #include "global.h" #include "user_cfg.h" +#include "config/yamlparser.h" +#include "config/yamlemitter.h" +#include "config/yamlnode.h" +#include "sip/sipaccount.h" +#include "account.h" class ConfigurationTest: public CppUnit::TestFixture { @@ -57,11 +62,13 @@ class ConfigurationTest: public CppUnit::TestFixture { * Use cppunit library macros to add unit test the factory */ CPPUNIT_TEST_SUITE( ConfigurationTest ); - CPPUNIT_TEST( testInitVolume ); - CPPUNIT_TEST( testDefaultValueAudio ); - CPPUNIT_TEST( testDefaultValuePreferences ); - CPPUNIT_TEST( testDefaultValueSignalisation ); - CPPUNIT_TEST( testInitAudioDriver ); +// CPPUNIT_TEST( testInitVolume ); +// CPPUNIT_TEST( testDefaultValueAudio ); +// CPPUNIT_TEST( testDefaultValuePreferences ); +// CPPUNIT_TEST( testDefaultValueSignalisation ); +// CPPUNIT_TEST( testInitAudioDriver ); +// CPPUNIT_TEST( testYamlParser ); + CPPUNIT_TEST( testYamlEmitter ); CPPUNIT_TEST_SUITE_END(); public: @@ -91,6 +98,10 @@ public: void testInitVolume(); void testInitAudioDriver(); + + void testYamlParser(); + + void testYamlEmitter(); }; /* Register our test module */ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ConfigurationTest, "ConfigurationTest"); diff --git a/sflphone-common/test/sequence.yml b/sflphone-common/test/sequence.yml new file mode 100755 index 0000000000000000000000000000000000000000..9cb54dd63661ab25b6255cb23ae414259c8bb91f --- /dev/null +++ b/sflphone-common/test/sequence.yml @@ -0,0 +1,22 @@ +accounts: + - id: 1234 + alias: sfl-181 + username: 181 + password: sfl-181pw + hostname: sflphone.org + enable: true + type: sip + + - id: 2345 + alias: sfl-431 + username: 431 + password: alexandre + hostname: 192.168.50.3 + enable: true + type: sip + + + + + + diff --git a/sflphone-common/test/sequence2.yml b/sflphone-common/test/sequence2.yml new file mode 100644 index 0000000000000000000000000000000000000000..c63756336f815a62a8745e960d6263be9c047807 --- /dev/null +++ b/sflphone-common/test/sequence2.yml @@ -0,0 +1,117 @@ +accounts: + - id: 1234 + alias: sfl-181 + username: 181 + password: sfl-181pw + hostname: sflphone.org + enable: true + type: sip + + - id: 2345 + alias: sfl-431 + username: 431 + password: alexandre + hostname: 192.168.50.3 + enable: true + type: sip + expire: 3600 + interface: lo + port: 5065 + mailbox: 97 + publishaddr: 127.0.0.1 + publishport: 5065 + sameaslocal: true + resolveonce: false + codecs: 0/9/110/111/112/ + credential: + count: 0 + srtp: + enable: true + keyexchange: sdes + rtpfallback: true + zrtp: + displaySas: true + displaySasOnce: false + helloHashEnabled: true + notSuppWarning: true + tls: + certificate: /home/msavard/Development/sflphone/sflphone-client-gnome/config.guess + calist: /home/msavard/Development/sflphone/sflphone-client-gnome/aclocal.m4 + ciphers: + enable: true + method: TLSv1 + timeout: 0 + password: + privatekey: /home/msavard/Development/sflphone/sflphone-client-gnome/config.log + requirecertif: true + server: + verifyclient: true + verifyserver: true + +addressbook: + photo: false + enabled: true + list: 1243608768.30329.0@emilou-desktop/1243456917.15690.23@emilou-desktop/ + max_results: 25 + business: true + home: false + mobile: false + +audio: + alsa: + cardin: 0 + cardout: 0 + cardout: 0 + framesize: 20 + plugin: default + smplrate: 44100 + pulse: + devicePlayback: + deviceRecord: + deviceRingtone: + recordpath: /home/msavard/Bureau + ringchoice: /usr/share/sflphone/ringtones/konga.ul + volumemic: 100 + volumespkr: 100 + +hooks: + iax2Enabled: false + numberAddPrefix: false + numberEnabled: false + sipEnabled: false + urlCommand: x-www-browser + urlSipField: X-sflphone-url + +preferences: + order: 1234/2345 + audioapi: 0 + dialpaddisplay: 0 + historyenabled: 1 + historylimit: 30 + historymaxCalls: 20 + notifyall: true + notifymails: false + zoneToneChoice: North America + registrationexpire: 180 + ringtonesenable: true + portnum: 5060 + searchbardisplay: true + starthidden: 0 + volumedisplay: 0 + windowheight: 332 + windowpopup: 0 + windowposition: 0 + windowposition: 24 + windowwidth: 240 + zeroconfenable: false + md5Hash: false + +voiplink: + playDtmf: true + playTones: true + pulseLength: 250 + sendDTMFas: 0 + stunenable: 0 + stunserver: stun.sflphone.org + symmetric: true + zidFile: sfl.zid \ No newline at end of file