From e976366ce8c75d2119d16032e21fbcc8689585c8 Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tristan.matthews@savoirfairelinux.com> Date: Tue, 15 Nov 2011 19:46:36 -0500 Subject: [PATCH] * #7842: fixed Weffc++ warnings/uninitialized variables --- daemon/configure.ac | 2 +- daemon/src/account.cpp | 6 +- daemon/src/audio/audiolayer.cpp | 1 + daemon/src/audio/audiolayer.h | 3 - daemon/src/audio/audiorecord.cpp | 2 + daemon/src/audio/audiorecord.h | 5 +- daemon/src/audio/audiorecorder.cpp | 3 +- .../src/audio/audiortp/audio_rtp_factory.cpp | 5 +- daemon/src/audio/audiortp/audio_rtp_factory.h | 2 + .../audiortp/audio_rtp_record_handler.cpp | 2 + .../audio/audiortp/audio_rtp_record_handler.h | 4 - .../src/audio/audiortp/audio_rtp_session.cpp | 2 + daemon/src/audio/audiortp/audio_rtp_session.h | 2 + .../src/audio/audiortp/audio_srtp_session.h | 2 + .../audiortp/audio_symmetric_rtp_session.cpp | 1 + .../audiortp/audio_symmetric_rtp_session.h | 2 + .../audio/audiortp/zrtp_session_callback.cpp | 1 - .../audio/audiortp/zrtp_session_callback.h | 2 + daemon/src/audio/codecs/audiocodec.h | 2 +- daemon/src/audio/codecs/audiocodecfactory.cpp | 3 +- daemon/src/audio/codecs/celtcodec.cpp | 6 +- daemon/src/audio/codecs/g722.cpp | 35 +- daemon/src/audio/codecs/speexcodec.h | 45 +- daemon/src/audio/delaydetection.cpp | 12 +- daemon/src/audio/delaydetection.h | 7 - daemon/src/audio/echosuppress.cpp | 10 +- daemon/src/audio/echosuppress.h | 4 +- daemon/src/audio/mainbuffer.cpp | 2 +- daemon/src/audio/pulseaudio/audiostream.cpp | 2 +- daemon/src/audio/pulseaudio/pulselayer.cpp | 3 + daemon/src/audio/recordable.cpp | 2 +- daemon/src/audio/recordable.h | 2 - daemon/src/audio/ringbuffer.cpp | 3 + daemon/src/audio/samplerateconverter.cpp | 3 +- daemon/src/audio/sound/audiofile.h | 1 + daemon/src/audio/speexechocancel.cpp | 37 +- daemon/src/audio/speexechocancel.h | 9 +- daemon/src/call.cpp | 10 +- daemon/src/conference.cpp | 1 + daemon/src/conference.h | 2 - daemon/src/config/config.h | 2 +- daemon/src/config/yamlemitter.cpp | 281 +++++------- daemon/src/config/yamlemitter.h | 44 +- daemon/src/config/yamlnode.h | 8 +- daemon/src/config/yamlparser.cpp | 410 ++++++++---------- daemon/src/config/yamlparser.h | 53 +-- daemon/src/dbus/configurationmanager.cpp | 8 +- daemon/src/dbus/configurationmanager.h | 12 +- daemon/src/dbus/dbus_cpp.h | 2 + daemon/src/dbus/dbusmanager.cpp | 8 +- daemon/src/dbus/instance.cpp | 13 +- daemon/src/history/historyitem.cpp | 4 +- daemon/src/history/historymanager.cpp | 3 +- daemon/src/iax/iaxaccount.cpp | 2 +- daemon/src/iax/iaxcall.cpp | 3 +- daemon/src/iax/iaxcall.h | 3 + daemon/src/iax/iaxvoiplink.cpp | 1 + daemon/src/iax/iaxvoiplink.h | 2 + daemon/src/managerimpl.cpp | 12 +- daemon/src/managerimpl.h | 2 - daemon/src/preferences.cpp | 3 + daemon/src/preferences.h | 3 +- daemon/src/sip/pattern.cpp | 7 +- daemon/src/sip/pattern.h | 2 + daemon/src/sip/sdes_negotiator.cpp | 9 +- daemon/src/sip/sdp.cpp | 11 +- daemon/src/sip/sdp.h | 4 +- daemon/src/sip/sipaccount.cpp | 22 +- daemon/src/sip/sipvoiplink.cpp | 2 +- daemon/src/voiplink.cpp | 2 + daemon/src/voiplink.h | 5 +- daemon/test/Makefile.am | 3 - daemon/test/audiolayertest.cpp | 3 + daemon/test/audiolayertest.h | 8 +- daemon/test/echocanceltest.cpp | 10 +- daemon/test/echocanceltest.h | 11 +- daemon/test/historytest.h | 6 +- daemon/test/instantmessagingtest.h | 6 +- daemon/test/sdesnegotiatortest.cpp | 4 +- daemon/test/sdesnegotiatortest.h | 7 +- daemon/test/sdptest.h | 8 +- 81 files changed, 578 insertions(+), 679 deletions(-) diff --git a/daemon/configure.ac b/daemon/configure.ac index aa26c38b55..4d7225140a 100644 --- a/daemon/configure.ac +++ b/daemon/configure.ac @@ -178,7 +178,7 @@ DBUS_CPP_REQUIRED_VERSION=0.6.0-pre1 PKG_CHECK_MODULES(DBUSCPP, dbus-c++-1,, AC_MSG_ERROR([You need the DBus-c++ libraries (version $DBUS_CPP_REQUIRED_VERSION or better)])) -CXXFLAGS="${CXXFLAGS} -g -Wno-return-type -Wall -Wextra -Wnon-virtual-dtor -Wfatal-errors" +CXXFLAGS="${CXXFLAGS} -g -Wno-return-type -Wall -Wextra -Wnon-virtual-dtor -Weffc++ -Wfatal-errors" AC_CHECK_LIB([expat], XML_ParserCreate_MM, [AC_CHECK_HEADERS(expat.h, have_expat=true, have_expat=false)], diff --git a/daemon/src/account.cpp b/daemon/src/account.cpp index 8053e1d430..5501e3aa94 100644 --- a/daemon/src/account.cpp +++ b/daemon/src/account.cpp @@ -35,16 +35,20 @@ Account::Account(const std::string& accountID, const std::string &type) : accountID_(accountID) + , username_() + , hostname_() + , alias_() , link_(NULL) , enabled_(true) , type_(type) , registrationState_(Unregistered) , codecOrder_() - , codecStr_("") + , codecStr_() , ringtonePath_("/usr/share/sflphone/ringtones/konga.ul") , ringtoneEnabled_(true) , displayName_("") , userAgent_("SFLphone") + , mailBox_() { // Initialize the codec order, used when creating a new account loadDefaultCodecs(); diff --git a/daemon/src/audio/audiolayer.cpp b/daemon/src/audio/audiolayer.cpp index a094b006a3..285f31978b 100644 --- a/daemon/src/audio/audiolayer.cpp +++ b/daemon/src/audio/audiolayer.cpp @@ -39,6 +39,7 @@ AudioLayer::AudioLayer() , urgentRingBuffer_(SIZEBUF, Call::DEFAULT_ID) , audioSampleRate_(Manager::instance().getMainBuffer()->getInternalSamplingRate()) , mutex_() + , dcblocker_() , audioPref(Manager::instance().audioPreference) , converter_(new SamplerateConverter(audioSampleRate_)) , lastNotificationTime_(0) diff --git a/daemon/src/audio/audiolayer.h b/daemon/src/audio/audiolayer.h index 0601ddf388..cc36e45374 100644 --- a/daemon/src/audio/audiolayer.h +++ b/daemon/src/audio/audiolayer.h @@ -133,11 +133,8 @@ class AudioLayer { * Lock for the entire audio layer */ ost::Mutex mutex_; - DcBlocker dcblocker_; - AudioPreference &audioPref; - SamplerateConverter *converter_; private: diff --git a/daemon/src/audio/audiorecord.cpp b/daemon/src/audio/audiorecord.cpp index 0df3f91014..dcfe03fdde 100644 --- a/daemon/src/audio/audiorecord.cpp +++ b/daemon/src/audio/audiorecord.cpp @@ -52,6 +52,7 @@ struct wavhdr { AudioRecord::AudioRecord() : fileHandle_(NULL) + , fileType_(FILE_INVALID) , channels_(1) , byteCounter_(0) , sndSmplRate_(8000) @@ -62,6 +63,7 @@ AudioRecord::AudioRecord() : fileHandle_(NULL) , mixBuffer_(new SFLDataFormat[nbSamplesMax_]) , micBuffer_(new SFLDataFormat[nbSamplesMax_]) , spkBuffer_(new SFLDataFormat[nbSamplesMax_]) + , savePath_() { createFilename(); } diff --git a/daemon/src/audio/audiorecord.h b/daemon/src/audio/audiorecord.h index 256d013011..d865a5509e 100644 --- a/daemon/src/audio/audiorecord.h +++ b/daemon/src/audio/audiorecord.h @@ -35,11 +35,12 @@ #include <cstdlib> #include "global.h" +#include "noncopyable.h" class AudioRecord { public: - enum FILE_TYPE { FILE_RAW, FILE_WAV }; + enum FILE_TYPE { FILE_RAW, FILE_WAV, FILE_INVALID }; AudioRecord(); @@ -237,6 +238,8 @@ class AudioRecord { */ std::string savePath_; + private: + NON_COPYABLE(AudioRecord); }; #endif // _AUDIO_RECORD_H diff --git a/daemon/src/audio/audiorecorder.cpp b/daemon/src/audio/audiorecorder.cpp index 8c7a6acd2f..462c32165b 100644 --- a/daemon/src/audio/audiorecorder.cpp +++ b/daemon/src/audio/audiorecorder.cpp @@ -34,7 +34,8 @@ int AudioRecorder::count_ = 0; -AudioRecorder::AudioRecorder(AudioRecord *arec, MainBuffer *mb) : Thread(), mbuffer_(mb), arecord_(arec) +AudioRecorder::AudioRecorder(AudioRecord *arec, MainBuffer *mb) : Thread(), + recorderId_(), mbuffer_(mb), arecord_(arec) { assert(mb); setCancel(cancelDeferred); diff --git a/daemon/src/audio/audiortp/audio_rtp_factory.cpp b/daemon/src/audio/audiortp/audio_rtp_factory.cpp index ee57e4ec08..5ce37ce1f5 100644 --- a/daemon/src/audio/audiortp/audio_rtp_factory.cpp +++ b/daemon/src/audio/audiortp/audio_rtp_factory.cpp @@ -42,7 +42,10 @@ namespace sfl { -AudioRtpFactory::AudioRtpFactory(SIPCall *ca) : rtpSession_(NULL), remoteContext_(NULL), localContext_(NULL), ca_(ca) +AudioRtpFactory::AudioRtpFactory(SIPCall *ca) : rtpSession_(NULL), + audioRtpThreadMutex_(), srtpEnabled_(false), + keyExchangeProtocol_(Symmetric), helloHashEnabled_(false), + remoteContext_(NULL), localContext_(NULL), ca_(ca) {} AudioRtpFactory::~AudioRtpFactory() diff --git a/daemon/src/audio/audiortp/audio_rtp_factory.h b/daemon/src/audio/audiortp/audio_rtp_factory.h index 0e33ae57c7..9e8ca514ce 100644 --- a/daemon/src/audio/audiortp/audio_rtp_factory.h +++ b/daemon/src/audio/audiortp/audio_rtp_factory.h @@ -35,6 +35,7 @@ #include <cc++/thread.h> #include <ccrtp/CryptoContext.h> #include "audio_rtp_session.h" +#include "noncopyable.h" #include "sip/sdes_negotiator.h" @@ -138,6 +139,7 @@ class AudioRtpFactory { void sendDtmfDigit(int digit); private: + NON_COPYABLE(AudioRtpFactory); AudioRtpSession *rtpSession_; ost::Mutex audioRtpThreadMutex_; diff --git a/daemon/src/audio/audiortp/audio_rtp_record_handler.cpp b/daemon/src/audio/audiortp/audio_rtp_record_handler.cpp index cb523a21b7..8ce03be489 100644 --- a/daemon/src/audio/audiortp/audio_rtp_record_handler.cpp +++ b/daemon/src/audio/audiortp/audio_rtp_record_handler.cpp @@ -47,8 +47,10 @@ AudioRtpRecord::AudioRtpRecord() : , codecSampleRate_(0) , codecFrameSize_(0) , converterSamplingRate_(0) + , dtmfQueue_() , micAmplFactor_(initFadeinFactor) , noiseSuppress_(0) + , audioProcessMutex_() , callId_("") , dtmfPayloadType_(101) // same as Asterisk { diff --git a/daemon/src/audio/audiortp/audio_rtp_record_handler.h b/daemon/src/audio/audiortp/audio_rtp_record_handler.h index cf8c20e9f4..9012049a13 100644 --- a/daemon/src/audio/audiortp/audio_rtp_record_handler.h +++ b/daemon/src/audio/audiortp/audio_rtp_record_handler.h @@ -169,18 +169,14 @@ class AudioRtpRecordHandler { void putDtmfEvent(int digit); protected: - AudioRtpRecord audioRtpRecord_; private: const std::string id_; - EchoSuppress echoCanceller; - GainControl gainController; }; - } #endif // AUDIO_RTP_RECORD_HANDLER_H__ diff --git a/daemon/src/audio/audiortp/audio_rtp_session.cpp b/daemon/src/audio/audiortp/audio_rtp_session.cpp index 2420657163..5c89844177 100644 --- a/daemon/src/audio/audiortp/audio_rtp_session.cpp +++ b/daemon/src/audio/audiortp/audio_rtp_session.cpp @@ -47,6 +47,8 @@ AudioRtpSession::AudioRtpSession(SIPCall * sipcall, RtpMethod type, ost::RTPData AudioRtpRecordHandler(sipcall) , ca_(sipcall) , type_(type) + , remote_ip_() + , remote_port_(0) , timestamp_(0) , timestampIncrement_(0) , timestampCount_(0) diff --git a/daemon/src/audio/audiortp/audio_rtp_session.h b/daemon/src/audio/audiortp/audio_rtp_session.h index 35733fa491..58031f9aba 100644 --- a/daemon/src/audio/audiortp/audio_rtp_session.h +++ b/daemon/src/audio/audiortp/audio_rtp_session.h @@ -38,6 +38,7 @@ #include <audio/codecs/audiocodec.h> #include <ccrtp/rtp.h> #include <ccrtp/formats.h> +#include "noncopyable.h" class SIPCall; @@ -96,6 +97,7 @@ class AudioRtpSession : public AudioRtpRecordHandler { RtpMethod type_; private: + NON_COPYABLE(AudioRtpSession); /** * Set the audio codec for this RTP session diff --git a/daemon/src/audio/audiortp/audio_srtp_session.h b/daemon/src/audio/audiortp/audio_srtp_session.h index 28d822caa4..f641e8eaa5 100644 --- a/daemon/src/audio/audiortp/audio_srtp_session.h +++ b/daemon/src/audio/audiortp/audio_srtp_session.h @@ -33,6 +33,7 @@ #include "audio_rtp_session.h" #include "audio_symmetric_rtp_session.h" #include "sip/sdes_negotiator.h" +#include "noncopyable.h" #include <ccrtp/CryptoContext.h> #include <vector> @@ -109,6 +110,7 @@ class AudioSrtpSession : public AudioSymmetricRtpSession { ost::CryptoContext* localCryptoCtx_; private: + NON_COPYABLE(AudioSrtpSession); /** * Init local master key according to current crypto context diff --git a/daemon/src/audio/audiortp/audio_symmetric_rtp_session.cpp b/daemon/src/audio/audiortp/audio_symmetric_rtp_session.cpp index 9fbd639f38..37f8f7deae 100644 --- a/daemon/src/audio/audiortp/audio_symmetric_rtp_session.cpp +++ b/daemon/src/audio/audiortp/audio_symmetric_rtp_session.cpp @@ -44,6 +44,7 @@ namespace sfl { AudioSymmetricRtpSession::AudioSymmetricRtpSession(SIPCall * sipcall) : ost::SymmetricRTPSession(ost::InetHostAddress(sipcall->getLocalIp().c_str()), sipcall->getLocalAudioPort()) , AudioRtpSession(sipcall, Symmetric, this, this) + , echoCanceller() , rtpThread_(new AudioRtpThread(this)) { INFO("AudioSymmetricRtpSession: Setting new RTP session with destination %s:%d", ca_->getLocalIp().c_str(), ca_->getLocalAudioPort()); diff --git a/daemon/src/audio/audiortp/audio_symmetric_rtp_session.h b/daemon/src/audio/audiortp/audio_symmetric_rtp_session.h index 22d3a8a56f..162bcadbed 100644 --- a/daemon/src/audio/audiortp/audio_symmetric_rtp_session.h +++ b/daemon/src/audio/audiortp/audio_symmetric_rtp_session.h @@ -42,6 +42,7 @@ #include "noncopyable.h" using std::ptrdiff_t; + #include <ccrtp/rtp.h> #include <ccrtp/iqueue.h> #include <cc++/numbers.h> // ost::Time @@ -70,6 +71,7 @@ class AudioSymmetricRtpSession : public ost::TimerPort, public ost::SymmetricRTP } private: + NON_COPYABLE(AudioSymmetricRtpSession); class AudioRtpThread : public ost::Thread, public ost::TimerPort { public: diff --git a/daemon/src/audio/audiortp/zrtp_session_callback.cpp b/daemon/src/audio/audiortp/zrtp_session_callback.cpp index 7afde913b0..24e6a9bbf8 100644 --- a/daemon/src/audio/audiortp/zrtp_session_callback.cpp +++ b/daemon/src/audio/audiortp/zrtp_session_callback.cpp @@ -28,7 +28,6 @@ * as that of the covered work. */ #include "zrtp_session_callback.h" - #include "global.h" #include "sip/sipcall.h" #include "dbus/dbusmanager.h" diff --git a/daemon/src/audio/audiortp/zrtp_session_callback.h b/daemon/src/audio/audiortp/zrtp_session_callback.h index fb03b71e0b..08bb9cf4fb 100644 --- a/daemon/src/audio/audiortp/zrtp_session_callback.h +++ b/daemon/src/audio/audiortp/zrtp_session_callback.h @@ -39,6 +39,7 @@ using std::ptrdiff_t; #include <libzrtpcpp/ZrtpUserCallback.h> #include <exception> #include <map> +#include "noncopyable.h" class SIPCall; @@ -57,6 +58,7 @@ class ZrtpSessionCallback: public ZrtpUserCallback { void confirmGoClear(); private: + NON_COPYABLE(ZrtpSessionCallback); SIPCall* sipcall_; static std::map<int32, std::string> infoMap_; static std::map<int32, std::string> warningMap_; diff --git a/daemon/src/audio/codecs/audiocodec.h b/daemon/src/audio/codecs/audiocodec.h index 0846c4e347..f1b42ffe86 100644 --- a/daemon/src/audio/codecs/audiocodec.h +++ b/daemon/src/audio/codecs/audiocodec.h @@ -33,7 +33,6 @@ #define __AUDIO_CODEC_H__ #include <string> -#include <iostream> #include <dlfcn.h> #include "codec.h" @@ -161,6 +160,7 @@ class AudioCodec : public Codec { bool hasDynamicPayload_; private: + AudioCodec& operator=(const AudioCodec&); uint8 payload_; ost::DynamicPayloadFormat* payloadFormat_; diff --git a/daemon/src/audio/codecs/audiocodecfactory.cpp b/daemon/src/audio/codecs/audiocodecfactory.cpp index 0574123e8d..0dc73e5832 100644 --- a/daemon/src/audio/codecs/audiocodecfactory.cpp +++ b/daemon/src/audio/codecs/audiocodecfactory.cpp @@ -37,7 +37,8 @@ #include <algorithm> // for std::find #include "fileutils.h" -AudioCodecFactory::AudioCodecFactory() : codecsMap_() +AudioCodecFactory::AudioCodecFactory() : + codecsMap_(), defaultCodecOrder_(), libCache_(), codecInMemory_() { typedef std::vector<sfl::Codec*> CodecVector; CodecVector codecDynamicList(scanCodecDirectory()); diff --git a/daemon/src/audio/codecs/celtcodec.cpp b/daemon/src/audio/codecs/celtcodec.cpp index f992d2bed9..ccc59910e1 100644 --- a/daemon/src/audio/codecs/celtcodec.cpp +++ b/daemon/src/audio/codecs/celtcodec.cpp @@ -37,7 +37,7 @@ class Celt : public sfl::AudioCodec { public: - Celt(int payload = 115) : sfl::AudioCodec(payload, "celt") { + Celt(int payload = 115) : sfl::AudioCodec(payload, "celt"), mode_(0), enc_(0), dec_(0) { clockRate_ = 32000; frameSize_ = 320; // fixed frameSize, TODO: support variable size from 64 to 512 channel_ = 1; @@ -119,14 +119,10 @@ class Celt : public sfl::AudioCodec { } private: - CELTMode *mode_; CELTEncoder *enc_; CELTDecoder *dec_; - - celt_int32 celt_frame_size_; - celt_int32 skip_; }; // the class factories diff --git a/daemon/src/audio/codecs/g722.cpp b/daemon/src/audio/codecs/g722.cpp index 1df5b0f86b..7a7931ce7a 100644 --- a/daemon/src/audio/codecs/g722.cpp +++ b/daemon/src/audio/codecs/g722.cpp @@ -36,34 +36,26 @@ #include "../common.h" #include "audiocodec.h" #include "g722.h" +#include "noncopyable.h" #include <stdlib.h> #include <string.h> #include <cassert> -#define TRUE 1 -#define FALSE 0 - - class G722 : public sfl::AudioCodec { public: - - G722(int payload=9) - : sfl::AudioCodec(payload, "G722") { + G722(int payload=9) : sfl::AudioCodec(payload, "G722"), + decode_s(new g722_decode_state_t), + encode_s(new g722_encode_state_t) { clockRate_ = 16000; frameSize_ = 320; // samples, 20 ms at 16kHz channel_ = 1; bitrate_ = 64; hasDynamicPayload_ = false; - - decode_s = new g722_decode_state_t; - encode_s = new g722_encode_state_t; - g722_decode_init(); g722_encode_init(); - } ~G722() { @@ -84,17 +76,16 @@ class G722 : public sfl::AudioCodec { void g722_encode_init() { - encode_s->itu_test_mode = FALSE; + encode_s->itu_test_mode = false; // 8 => 64 kbps; 7 => 56 kbps; 6 => 48 kbps encode_s->bits_per_sample = 8; // Enable 8khz mode, encode using lower subband only - encode_s->eight_k = FALSE; + encode_s->eight_k = false; - - // Never set packed TRUE when using 64 kbps - encode_s->packed = FALSE; + // Never set packed true when using 64 kbps + encode_s->packed = false; memset(encode_s->band, 0, sizeof(decode_s->band)); encode_s->band[0].det = 32; @@ -110,16 +101,16 @@ class G722 : public sfl::AudioCodec { void g722_decode_init() { - decode_s->itu_test_mode = FALSE; + decode_s->itu_test_mode = false; // 8 => 64 kbps; 7 => 56 kbps; 6 => 48 kbps decode_s->bits_per_sample = 8; // Enable 8khz mode, encode using lower subband only - decode_s->eight_k = FALSE; + decode_s->eight_k = false; - // Never set packed TRUE when using 64 kbps - decode_s->packed = FALSE; + // Never set packed true when using 64 kbps + decode_s->packed = false; memset(decode_s->band, 0, sizeof(decode_s->band)); decode_s->band[0].det = 32; @@ -811,6 +802,7 @@ class G722 : public sfl::AudioCodec { } private: + NON_COPYABLE(G722); g722_decode_state_t *decode_s; g722_encode_state_t *encode_s; @@ -828,4 +820,3 @@ extern "C" void destroy(sfl::Codec* a) delete a; } - diff --git a/daemon/src/audio/codecs/speexcodec.h b/daemon/src/audio/codecs/speexcodec.h index 64e2966b23..7b53fcdce2 100644 --- a/daemon/src/audio/codecs/speexcodec.h +++ b/daemon/src/audio/codecs/speexcodec.h @@ -65,29 +65,32 @@ const SpeexMode* speexMode[3] = { class Speex : public sfl::AudioCodec { public: - Speex(int payload) : sfl::AudioCodec(payload, "speex") { - assert(payload >= 110 && payload <= 112); - assert(110 == PAYLOAD_CODEC_SPEEX_8000 && - 111 == PAYLOAD_CODEC_SPEEX_16000 && - 112 == PAYLOAD_CODEC_SPEEX_32000); - int type = payload - 110; + Speex(int payload) : + sfl::AudioCodec(payload, "speex"), speex_dec_bits_(), + speex_enc_bits_(), speex_dec_state_(0), speex_enc_state_(0), + speex_frame_size_(0) { + assert(payload >= 110 && payload <= 112); + assert(110 == PAYLOAD_CODEC_SPEEX_8000 && + 111 == PAYLOAD_CODEC_SPEEX_16000 && + 112 == PAYLOAD_CODEC_SPEEX_32000); + int type = payload - 110; - clockRate_ = clockRate[type]; - frameSize_ = frameSize[type]; - channel_ = 1; - bitrate_ = bitRate[type]; - hasDynamicPayload_ = dynamicPayload[type]; + clockRate_ = clockRate[type]; + frameSize_ = frameSize[type]; + channel_ = 1; + bitrate_ = bitRate[type]; + hasDynamicPayload_ = dynamicPayload[type]; - // Init the decoder struct - speex_bits_init(&speex_dec_bits_); - speex_dec_state_ = speex_decoder_init(speexMode[type]); + // Init the decoder struct + speex_bits_init(&speex_dec_bits_); + speex_dec_state_ = speex_decoder_init(speexMode[type]); - // Init the encoder struct - speex_bits_init(&speex_enc_bits_); - speex_enc_state_ = speex_encoder_init(speexMode[type]); + // Init the encoder struct + speex_bits_init(&speex_enc_bits_); + speex_enc_state_ = speex_encoder_init(speexMode[type]); - speex_encoder_ctl(speex_enc_state_, SPEEX_SET_SAMPLING_RATE, &clockRate_); - speex_decoder_ctl(speex_dec_state_, SPEEX_GET_FRAME_SIZE, &speex_frame_size_); + speex_encoder_ctl(speex_enc_state_, SPEEX_SET_SAMPLING_RATE, &clockRate_); + speex_decoder_ctl(speex_dec_state_, SPEEX_GET_FRAME_SIZE, &speex_frame_size_); } NON_COPYABLE(Speex); @@ -117,8 +120,8 @@ class Speex : public sfl::AudioCodec { } private: - SpeexBits speex_dec_bits_; - SpeexBits speex_enc_bits_; + SpeexBits speex_dec_bits_; + SpeexBits speex_enc_bits_; void *speex_dec_state_; void *speex_enc_state_; int speex_frame_size_; diff --git a/daemon/src/audio/delaydetection.cpp b/daemon/src/audio/delaydetection.cpp index 34d2a2d33d..3f56f0c782 100644 --- a/daemon/src/audio/delaydetection.cpp +++ b/daemon/src/audio/delaydetection.cpp @@ -97,11 +97,15 @@ void FirFilter::reset() } -DelayDetection::DelayDetection() : internalState_(WaitForSpeaker), decimationFilter_(ird), bandpassFilter_(irb), segmentSize_(DELAY_BUFF_SIZE), downsamplingFactor_(8) +DelayDetection::DelayDetection() : + internalState_(WaitForSpeaker), decimationFilter_(ird), + bandpassFilter_(irb), segmentSize_(DELAY_BUFF_SIZE), + downsamplingFactor_(8), + spkrDownSize_(DELAY_BUFF_SIZE / downsamplingFactor_), + micDownSize_(WINDOW_SIZE / downsamplingFactor_), + nbMicSampleStored_(0), + nbSpkrSampleStored_(0) { - micDownSize_ = WINDOW_SIZE / downsamplingFactor_; - spkrDownSize_ = DELAY_BUFF_SIZE / downsamplingFactor_; - memset(spkrReference_, 0, sizeof(float) *WINDOW_SIZE*2); memset(capturedData_, 0, sizeof(float) *DELAY_BUFF_SIZE*2); memset(spkrReferenceDown_, 0, sizeof(float) *WINDOW_SIZE*2); diff --git a/daemon/src/audio/delaydetection.h b/daemon/src/audio/delaydetection.h index 003c9a53b9..286baab13c 100644 --- a/daemon/src/audio/delaydetection.h +++ b/daemon/src/audio/delaydetection.h @@ -128,11 +128,6 @@ class DelayDetection { int downsamplingFactor_; - /** - * Resulting correlation size (s + w -1) - */ - short correlationSize_; - float spkrReference_[WINDOW_SIZE*2]; float capturedData_[DELAY_BUFF_SIZE*2]; @@ -147,8 +142,6 @@ class DelayDetection { float correlationResult_[DELAY_BUFF_SIZE*2]; - int remainingIndex_; - int spkrDownSize_; int micDownSize_; diff --git a/daemon/src/audio/echosuppress.cpp b/daemon/src/audio/echosuppress.cpp index e5bb739971..4f384c0bf8 100644 --- a/daemon/src/audio/echosuppress.cpp +++ b/daemon/src/audio/echosuppress.cpp @@ -14,15 +14,15 @@ #define SAMPLES_PER_FRAME 160 -EchoSuppress::EchoSuppress(pj_pool_t *pool) +EchoSuppress::EchoSuppress(pj_pool_t *pool) : echoState_(0) { - if (pjmedia_echo_create(pool, 8000, SAMPLES_PER_FRAME, 250, 0, PJMEDIA_ECHO_SIMPLE | PJMEDIA_ECHO_NO_LOCK, &echoState) != PJ_SUCCESS) + if (pjmedia_echo_create(pool, 8000, SAMPLES_PER_FRAME, 250, 0, PJMEDIA_ECHO_SIMPLE | PJMEDIA_ECHO_NO_LOCK, &echoState_) != PJ_SUCCESS) throw std::runtime_error("EchoCancel: Could not create echo canceller"); } EchoSuppress::~EchoSuppress() { - pjmedia_echo_destroy(echoState); + pjmedia_echo_destroy(echoState_); } void EchoSuppress::putData(SFLDataFormat *inputData, int samples) @@ -30,7 +30,7 @@ void EchoSuppress::putData(SFLDataFormat *inputData, int samples) assert(samples == SAMPLES_PER_FRAME); assert(sizeof(SFLDataFormat) == sizeof(pj_int16_t)); - if (pjmedia_echo_playback(echoState, reinterpret_cast<pj_int16_t *>(inputData)) != PJ_SUCCESS) + if (pjmedia_echo_playback(echoState_, reinterpret_cast<pj_int16_t *>(inputData)) != PJ_SUCCESS) WARN("EchoCancel: Problem while putting input data"); } @@ -38,6 +38,6 @@ void EchoSuppress::getData(SFLDataFormat *outputData) { assert(sizeof(SFLDataFormat) == sizeof(pj_int16_t)); - if (pjmedia_echo_capture(echoState, reinterpret_cast<pj_int16_t *>(outputData), 0) != PJ_SUCCESS) + if (pjmedia_echo_capture(echoState_, reinterpret_cast<pj_int16_t *>(outputData), 0) != PJ_SUCCESS) WARN("EchoCancel: Problem while getting output data"); } diff --git a/daemon/src/audio/echosuppress.h b/daemon/src/audio/echosuppress.h index 1bdf67c0fc..15b7eed932 100644 --- a/daemon/src/audio/echosuppress.h +++ b/daemon/src/audio/echosuppress.h @@ -10,6 +10,7 @@ #include "pjmedia/echo.h" #include "global.h" +#include "noncopyable.h" class EchoSuppress { public: @@ -26,11 +27,12 @@ class EchoSuppress { void getData(SFLDataFormat *); private: + NON_COPYABLE(EchoSuppress); /** * The internal state of the echo canceller */ - pjmedia_echo_state *echoState; + pjmedia_echo_state *echoState_; }; #endif /* ECHOSUPPRESS_H_ */ diff --git a/daemon/src/audio/mainbuffer.cpp b/daemon/src/audio/mainbuffer.cpp index 74cd86e355..997db98202 100644 --- a/daemon/src/audio/mainbuffer.cpp +++ b/daemon/src/audio/mainbuffer.cpp @@ -33,7 +33,7 @@ #include <utility> // for std::pair #include "manager.h" -MainBuffer::MainBuffer() : internalSamplingRate_(8000) +MainBuffer::MainBuffer() : ringBufferMap_(), callIDMap_(), mutex_(), internalSamplingRate_(8000) {} MainBuffer::~MainBuffer() diff --git a/daemon/src/audio/pulseaudio/audiostream.cpp b/daemon/src/audio/pulseaudio/audiostream.cpp index 07cd9c325d..c0ffe920db 100644 --- a/daemon/src/audio/pulseaudio/audiostream.cpp +++ b/daemon/src/audio/pulseaudio/audiostream.cpp @@ -32,7 +32,7 @@ #include "pulselayer.h" AudioStream::AudioStream(pa_context *c, pa_threaded_mainloop *m, const char *desc, int type, int smplrate, std::string *deviceName) - : mainloop_(m) + : audiostream_(0), mainloop_(m) { static const pa_channel_map channel_map = { 1, diff --git a/daemon/src/audio/pulseaudio/pulselayer.cpp b/daemon/src/audio/pulseaudio/pulselayer.cpp index e4be1aab8c..2568b3a08d 100644 --- a/daemon/src/audio/pulseaudio/pulselayer.cpp +++ b/daemon/src/audio/pulseaudio/pulselayer.cpp @@ -70,8 +70,11 @@ PulseLayer::PulseLayer() : playback_(0) , record_(0) , ringtone_(0) + , sinkList_() + , sourceList_() , mic_buffer_(0) , mic_buf_size_(0) + , context_(0) , mainloop_(pa_threaded_mainloop_new()) { setenv("PULSE_PROP_media.role", "phone", 1); diff --git a/daemon/src/audio/recordable.cpp b/daemon/src/audio/recordable.cpp index 4b9ea8f41b..b55b4ed7cb 100644 --- a/daemon/src/audio/recordable.cpp +++ b/daemon/src/audio/recordable.cpp @@ -30,7 +30,7 @@ #include "recordable.h" #include "manager.h" -Recordable::Recordable() : recorder(&recAudio, Manager::instance().getMainBuffer()) +Recordable::Recordable() : recAudio(), recorder(&recAudio, Manager::instance().getMainBuffer()) { recAudio.setRecordingOption(AudioRecord::FILE_WAV, 8000, Manager::instance().audioPreference.getRecordpath()); } diff --git a/daemon/src/audio/recordable.h b/daemon/src/audio/recordable.h index 3e900a2f47..13effb2ef5 100644 --- a/daemon/src/audio/recordable.h +++ b/daemon/src/audio/recordable.h @@ -38,7 +38,6 @@ class Recordable { public: Recordable(); - virtual ~Recordable(); /** @@ -93,7 +92,6 @@ class Recordable { AudioRecord recAudio; AudioRecorder recorder; - }; #endif diff --git a/daemon/src/audio/ringbuffer.cpp b/daemon/src/audio/ringbuffer.cpp index 6cc11987ec..9119838ffe 100644 --- a/daemon/src/audio/ringbuffer.cpp +++ b/daemon/src/audio/ringbuffer.cpp @@ -48,7 +48,10 @@ int RingBuffer::count_rb = 0; RingBuffer::RingBuffer(int size, const std::string &call_id) : endPos_(0) , bufferSize_(size > MIN_BUFFER_SIZE ? size : MIN_BUFFER_SIZE) , buffer_(NULL) + , readpointer_() , buffer_id_(call_id) + , buffer_input_rec(0) + , buffer_output_rec(0) { buffer_ = new unsigned char[bufferSize_]; count_rb++; diff --git a/daemon/src/audio/samplerateconverter.cpp b/daemon/src/audio/samplerateconverter.cpp index 6fbc9abde3..3337639d50 100644 --- a/daemon/src/audio/samplerateconverter.cpp +++ b/daemon/src/audio/samplerateconverter.cpp @@ -32,7 +32,8 @@ #include "manager.h" #include <cassert> -SamplerateConverter::SamplerateConverter(int freq) : maxFreq_(freq) +SamplerateConverter::SamplerateConverter(int freq) : floatBufferIn_(0), + floatBufferOut_(0), samples_(0), maxFreq_(freq), src_state_(0) { int err; src_state_ = src_new(SRC_LINEAR, 1, &err); diff --git a/daemon/src/audio/sound/audiofile.h b/daemon/src/audio/sound/audiofile.h index 1ebf376be7..5c00aea689 100644 --- a/daemon/src/audio/sound/audiofile.h +++ b/daemon/src/audio/sound/audiofile.h @@ -52,6 +52,7 @@ class AudioFileException : public std::runtime_error { */ class AudioFile : public AudioLoop { public: + AudioFile() : filepath_() {} std::string getFilePath() const { return filepath_; } diff --git a/daemon/src/audio/speexechocancel.cpp b/daemon/src/audio/speexechocancel.cpp index fbff291816..c5daacddaf 100644 --- a/daemon/src/audio/speexechocancel.cpp +++ b/daemon/src/audio/speexechocancel.cpp @@ -30,42 +30,37 @@ // number of sample to process, (800 à 4000 samples, 100 to 500 ms) #define EC_FILTER_LENGTH 800 +namespace { +const int SPEEX_SAMPLE_RATE = 8000; +const int RINGBUFFER_SIZE = 100000; +} -SpeexEchoCancel::SpeexEchoCancel() +SpeexEchoCancel::SpeexEchoCancel() : + echoDelay_(Manager::instance().getEchoCancelDelay() * SPEEX_SAMPLE_RATE / 1000), + echoTailLength_(Manager::instance().getEchoCancelTailLength() * SPEEX_SAMPLE_RATE / 1000), + echoState_(speex_echo_state_init(EC_FRAME_SIZE, echoTailLength_)), + preState_(speex_preprocess_state_init(EC_FRAME_SIZE, SPEEX_SAMPLE_RATE)), + micData_(new RingBuffer(RINGBUFFER_SIZE)), + spkrData_(new RingBuffer(RINGBUFFER_SIZE)), + spkrStopped_(true) { - int samplingRate = 8000; - - int echoDelayMs = Manager::instance().getEchoCancelDelay(); - int echoTailLengthMs = Manager::instance().getEchoCancelTailLength(); - - echoDelay_ = echoDelayMs * samplingRate / 1000; - echoTailLength_ = echoTailLengthMs * samplingRate / 1000; - - // echoState_ = speex_echo_state_init (EC_FRAME_SIZE, EC_FILTER_LENGTH); - echoState_ = speex_echo_state_init(EC_FRAME_SIZE, echoTailLength_); - preState_ = speex_preprocess_state_init(EC_FRAME_SIZE, samplingRate); - DEBUG("EchoCancel: Initializing echo canceller with delay: %d, filter length: %d, frame size: %d and samplerate %d", - echoDelay_, echoTailLength_, EC_FRAME_SIZE, samplingRate); + echoDelay_, echoTailLength_, EC_FRAME_SIZE, SPEEX_SAMPLE_RATE); - speex_echo_ctl(echoState_, SPEEX_ECHO_SET_SAMPLING_RATE, &samplingRate); + int rate = SPEEX_SAMPLE_RATE; + speex_echo_ctl(echoState_, SPEEX_ECHO_SET_SAMPLING_RATE, &rate); speex_preprocess_ctl(preState_, SPEEX_PREPROCESS_SET_ECHO_STATE, echoState_); - micData_ = new RingBuffer(100000); - spkrData_ = new RingBuffer(100000); - micData_->createReadPointer(); spkrData_->createReadPointer(); - - spkrStopped_ = true; } SpeexEchoCancel::~SpeexEchoCancel() { speex_echo_state_destroy(echoState_); speex_preprocess_state_destroy(preState_); - delete micData_; delete spkrData_; + delete micData_; } void SpeexEchoCancel::putData(SFLDataFormat *inputData, int samples) diff --git a/daemon/src/audio/speexechocancel.h b/daemon/src/audio/speexechocancel.h index f5d6217624..48d945384f 100644 --- a/daemon/src/audio/speexechocancel.h +++ b/daemon/src/audio/speexechocancel.h @@ -21,6 +21,7 @@ #define SPEEXECHOCANCEL_H #include "global.h" +#include "noncopyable.h" class RingBuffer; class SpeexEchoState_; @@ -48,17 +49,17 @@ class SpeexEchoCancel { int process(SFLDataFormat *, SFLDataFormat *, int samples); private: + NON_COPYABLE(SpeexEchoCancel); - SpeexEchoState *echoState_; + int echoDelay_; + int echoTailLength_; + SpeexEchoState *echoState_; SpeexPreprocessState *preState_; RingBuffer *micData_; RingBuffer *spkrData_; - int echoDelay_; - int echoTailLength_; - bool spkrStopped_; SFLDataFormat tmpSpkr_[5000]; diff --git a/daemon/src/call.cpp b/daemon/src/call.cpp index 839f70b94c..258d2ca22e 100644 --- a/daemon/src/call.cpp +++ b/daemon/src/call.cpp @@ -39,20 +39,18 @@ Call::Call(const std::string& id, Call::CallType type) , localIPAddress_("") , localAudioPort_(0) , id_(id) - , confID_("") + , confID_() , type_(type) , connectionState_(Call::Disconnected) , callState_(Call::Inactive) , callConfig_(Call::Classic) , peerName_() , peerNumber_() -{ -} - + , displayName_() +{} Call::~Call() -{ -} +{} void Call::setConnectionState(ConnectionState state) diff --git a/daemon/src/conference.cpp b/daemon/src/conference.cpp index ec39cf0101..fc37157b58 100644 --- a/daemon/src/conference.cpp +++ b/daemon/src/conference.cpp @@ -39,6 +39,7 @@ Conference::Conference() : id_(Manager::instance().getNewCallID()) , confState_(ACTIVE_ATTACHED) + , participants_() { Recordable::initRecFileName(id_); } diff --git a/daemon/src/conference.h b/daemon/src/conference.h index f4f1993095..4ce74de722 100644 --- a/daemon/src/conference.h +++ b/daemon/src/conference.h @@ -97,9 +97,7 @@ class Conference : public Recordable { virtual bool setRecording(); private: std::string id_; - ConferenceState confState_; - ParticipantSet participants_; }; diff --git a/daemon/src/config/config.h b/daemon/src/config/config.h index d046f894d7..b91dd819c1 100644 --- a/daemon/src/config/config.h +++ b/daemon/src/config/config.h @@ -92,7 +92,7 @@ class ConfigTreeIterator { class ConfigTree { public: - ConfigTree() {} + ConfigTree() : sections_(), defaultValueMap_() {} ~ConfigTree(); /** * Add a default value for a given key. diff --git a/daemon/src/config/yamlemitter.cpp b/daemon/src/config/yamlemitter.cpp index 4c21298fed..cc6a93b1c8 100644 --- a/daemon/src/config/yamlemitter.cpp +++ b/daemon/src/config/yamlemitter.cpp @@ -34,7 +34,9 @@ namespace Conf { -YamlEmitter::YamlEmitter(const char *file) : filename(file), isFirstAccount(true) +YamlEmitter::YamlEmitter(const char *file) : filename_(file), fd_(0), + emitter_(), document_(), topLevelMapping_(0), isFirstAccount_(true), + accountSequence_(0) { open(); } @@ -44,350 +46,279 @@ YamlEmitter::~YamlEmitter() close(); } -void YamlEmitter::open() throw(YamlEmitterException) +void YamlEmitter::open() { - fd = fopen(filename.c_str(), "w"); + fd_ = fopen(filename_.c_str(), "w"); - if (!fd) + if (!fd_) throw YamlEmitterException("Could not open file descriptor"); - if (!yaml_emitter_initialize(&emitter)) + if (!yaml_emitter_initialize(&emitter_)) throw YamlEmitterException("Could not initialize emitter"); // Allows unescaped unicode characters - yaml_emitter_set_unicode(&emitter, 1); + yaml_emitter_set_unicode(&emitter_, 1); - yaml_emitter_set_output_file(&emitter, fd); + yaml_emitter_set_output_file(&emitter_, fd_); - if (yaml_document_initialize(&document, NULL, NULL, NULL, 0, 0) == 0) { + if (yaml_document_initialize(&document_, NULL, NULL, NULL, 0, 0) == 0) throw YamlEmitterException("Could not initialize yaml document while saving configuration"); - } // Init the main configuration mapping - if ((topLevelMapping = yaml_document_add_mapping(&document, NULL, YAML_BLOCK_MAPPING_STYLE)) == 0) { + if ((topLevelMapping_ = yaml_document_add_mapping(&document_, NULL, YAML_BLOCK_MAPPING_STYLE)) == 0) throw YamlEmitterException("Could not create top level mapping"); - } } -void YamlEmitter::close() throw(YamlEmitterException) +void YamlEmitter::close() { - yaml_emitter_delete(&emitter); + yaml_emitter_delete(&emitter_); - if (!fd) + if (!fd_) throw YamlEmitterException("File descriptor not valid"); - - if (fclose(fd)) + if (fclose(fd_)) throw YamlEmitterException("Error closing file descriptor"); } -void YamlEmitter::serializeData() throw(YamlEmitterException) +void YamlEmitter::serializeData() { // Document object is destroyed once its content is emitted - if (yaml_emitter_dump(&emitter, &document) == 0) { + if (yaml_emitter_dump(&emitter_, &document_) == 0) throw YamlEmitterException("Error while emitting configuration yaml document"); - } } -void YamlEmitter::serializeAccount(MappingNode *map) throw(YamlEmitterException) +void YamlEmitter::serializeAccount(MappingNode *map) { int accountmapping; - if (map->getType() != MAPPING) { + if (map->getType() != MAPPING) throw YamlEmitterException("Node type is not a mapping while writing account"); - } - if (isFirstAccount) { + if (isFirstAccount_) { int accountid; DEBUG("YamlEmitter: Create account sequence"); - // 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 *) "accounts", -1, YAML_PLAIN_SCALAR_STYLE)) == 0) { + // 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 *) "accounts", -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) { + 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) == 0) { + if (yaml_document_append_mapping_pair(&document_, topLevelMapping_, accountid, accountSequence_) == 0) throw YamlEmitterException("Could not add mapping pair to top level mapping"); - } - isFirstAccount = false; + isFirstAccount_ = false; } - if ((accountmapping = yaml_document_add_mapping(&document, NULL, YAML_BLOCK_MAPPING_STYLE)) == 0) { + 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) == 0) { + if (yaml_document_append_sequence_item(&document_, accountSequence_, accountmapping) == 0) throw YamlEmitterException("Could not append account mapping to sequence"); - } - - try { - Mapping *internalmap = map->getMapping(); - Mapping::iterator iter; - for (iter = internalmap->begin(); iter != internalmap->end(); ++iter) - addMappingItem(accountmapping, iter->first, iter->second); - } catch (YamlEmitterException &e) { - throw; - } + Mapping *internalmap = map->getMapping(); + for (Mapping::iterator iter = internalmap->begin(); iter != internalmap->end(); ++iter) + addMappingItem(accountmapping, iter->first, iter->second); } -void YamlEmitter::serializePreference(MappingNode *map) throw(YamlEmitterException) +void YamlEmitter::serializePreference(MappingNode *map) { - std::string preferencestr("preferences"); - - int preferenceid, preferencemapping; - 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) + static const char * const PREFERENCE_STR = "preferences"; + int preferenceid; + + if ((preferenceid = yaml_document_add_scalar(&document_, NULL, (yaml_char_t *) PREFERENCE_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) + int preferencemapping; + 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) == 0) + if (yaml_document_append_mapping_pair(&document_, topLevelMapping_, preferenceid, preferencemapping) == 0) throw YamlEmitterException("Could not add mapping pair to top leve mapping"); Mapping *internalmap = map->getMapping(); - Mapping::iterator iter = internalmap->begin(); - - try { - while (iter != internalmap->end()) { - addMappingItem(preferencemapping, iter->first, iter->second); - iter++; - } - } catch (YamlEmitterException &e) { - throw; - } - + for (Mapping::iterator iter = internalmap->begin(); iter != internalmap->end(); ++iter) + addMappingItem(preferencemapping, iter->first, iter->second); } -void YamlEmitter::serializeVoipPreference(MappingNode *map) throw(YamlEmitterException) +void YamlEmitter::serializeVoipPreference(MappingNode *map) { - std::string preferencestr("voipPreferences"); - - int preferenceid, preferencemapping; - 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) + + static const char *const PREFERENCE_STR = "voipPreferences"; + int preferenceid; + if ((preferenceid = yaml_document_add_scalar(&document_, NULL, (yaml_char_t *) PREFERENCE_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) + int preferencemapping; + 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) == 0) + if (yaml_document_append_mapping_pair(&document_, topLevelMapping_, preferenceid, preferencemapping) == 0) throw YamlEmitterException("Could not add mapping pair to top leve mapping"); Mapping *internalmap = map->getMapping(); Mapping::iterator iter = internalmap->begin(); - try { - while (iter != internalmap->end()) { - addMappingItem(preferencemapping, iter->first, iter->second); - iter++; - } - } catch (YamlEmitterException &e) { - throw; + while (iter != internalmap->end()) { + addMappingItem(preferencemapping, iter->first, iter->second); + iter++; } - } -void YamlEmitter::serializeAddressbookPreference(MappingNode *map) throw(YamlEmitterException) +void YamlEmitter::serializeAddressbookPreference(MappingNode *map) { - std::string preferencestr("addressbook"); - - int preferenceid, preferencemapping; - 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) + static const char * const PREFERENCE_STR = "addressbook"; + int preferenceid; + if ((preferenceid = yaml_document_add_scalar(&document_, NULL, (yaml_char_t *) PREFERENCE_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) + int preferencemapping; + 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) == 0) + if (yaml_document_append_mapping_pair(&document_, topLevelMapping_, preferenceid, preferencemapping) == 0) throw YamlEmitterException("Could not add mapping pair to top leve mapping"); Mapping *internalmap = map->getMapping(); - Mapping::iterator iter = internalmap->begin(); - - try { - while (iter != internalmap->end()) { - addMappingItem(preferencemapping, iter->first, iter->second); - iter++; - } - } catch (YamlEmitterException &e) { - throw; - } + for (Mapping::iterator iter = internalmap->begin(); iter != internalmap->end(); ++iter) + addMappingItem(preferencemapping, iter->first, iter->second); } -void YamlEmitter::serializeHooksPreference(MappingNode *map) throw(YamlEmitterException) +void YamlEmitter::serializeHooksPreference(MappingNode *map) { - std::string preferencestr("hooks"); - - int preferenceid, preferencemapping; - 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) + static const char * const PREFERENCE_STR = "hooks"; + int preferenceid; + if ((preferenceid = yaml_document_add_scalar(&document_, NULL, (yaml_char_t *) PREFERENCE_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) + int preferencemapping; + 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) == 0) + if (yaml_document_append_mapping_pair(&document_, topLevelMapping_, preferenceid, preferencemapping) == 0) throw YamlEmitterException("Could not add mapping pair to top leve mapping"); Mapping *internalmap = map->getMapping(); - Mapping::iterator iter = internalmap->begin(); - - try { - while (iter != internalmap->end()) { - addMappingItem(preferencemapping, iter->first, iter->second); - iter++; - } - } catch (YamlEmitterException &e) { - throw; - } + for (Mapping::iterator iter = internalmap->begin(); iter != internalmap->end(); ++iter) + addMappingItem(preferencemapping, iter->first, iter->second); } -void YamlEmitter::serializeAudioPreference(MappingNode *map) throw(YamlEmitterException) +void YamlEmitter::serializeAudioPreference(MappingNode *map) { - std::string preferencestr("audio"); + static const char *const PREFERENCE_STR = "audio"; int preferenceid, preferencemapping; 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) + if ((preferenceid = yaml_document_add_scalar(&document_, NULL, (yaml_char_t *) PREFERENCE_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) + 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) == 0) + if (yaml_document_append_mapping_pair(&document_, topLevelMapping_, preferenceid, preferencemapping) == 0) throw YamlEmitterException("Could not add mapping pair to top leve mapping"); Mapping *internalmap = map->getMapping(); - Mapping::iterator iter = internalmap->begin(); - - try { - while (iter != internalmap->end()) { - addMappingItem(preferencemapping, iter->first, iter->second); - iter++; - } - } catch (YamlEmitterException &e) { - throw; - } - + for (Mapping::iterator iter = internalmap->begin(); iter != internalmap->end(); ++iter) + addMappingItem(preferencemapping, iter->first, iter->second); } -void YamlEmitter::serializeShortcutPreference(MappingNode *map) throw(YamlEmitterException) +void YamlEmitter::serializeShortcutPreference(MappingNode *map) { - std::string preferencestr("shortcuts"); - - int preferenceid, preferencemapping; - 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) + static const char *const PREFERENCE_STR = "shortcuts"; + int preferenceid; + if ((preferenceid = yaml_document_add_scalar(&document_, NULL, (yaml_char_t *) PREFERENCE_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) + int preferencemapping; + 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) == 0) + if (yaml_document_append_mapping_pair(&document_, topLevelMapping_, preferenceid, preferencemapping) == 0) throw YamlEmitterException("Could not add mapping pair to top leve mapping"); Mapping *internalmap = map->getMapping(); - Mapping::iterator iter = internalmap->begin(); - - try { - while (iter != internalmap->end()) { - addMappingItem(preferencemapping, iter->first, iter->second); - iter++; - } - } catch (YamlEmitterException &e) { - throw; - } + for (Mapping::iterator iter = internalmap->begin(); iter != internalmap->end(); ++iter) + addMappingItem(preferencemapping, iter->first, iter->second); } void YamlEmitter::addMappingItem(int mappingid, std::string key, YamlNode *node) { - int temp1, temp2; - if (node->getType() == SCALAR) { ScalarNode *sclr = (ScalarNode *) node; - if ((temp1 = yaml_document_add_scalar(&document, NULL, (yaml_char_t *) key.c_str(), -1, YAML_PLAIN_SCALAR_STYLE)) == 0) + int temp1; + 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) + int temp2; + 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) == 0) + if (yaml_document_append_mapping_pair(&document_, mappingid, temp1, temp2) == 0) throw YamlEmitterException("Could not append mapping pair to mapping"); } else if (node->getType() == MAPPING) { MappingNode *map = (MappingNode *) node; - if ((temp1 = yaml_document_add_scalar(&document, NULL, (yaml_char_t *) key.c_str(), -1, YAML_PLAIN_SCALAR_STYLE)) == 0) + int temp1; + 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) + int temp2; + 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) == 0) + if (yaml_document_append_mapping_pair(&document_, mappingid, temp1, temp2) == 0) throw YamlEmitterException("Could not add mapping pair to mapping"); - try { - Mapping *internalmap = map->getMapping(); - Mapping::iterator iter; + Mapping *internalmap = map->getMapping(); + for (Mapping::iterator iter = internalmap->begin(); iter != internalmap->end(); ++iter) + addMappingItem(temp2, iter->first, iter->second); - for (iter = internalmap->begin(); iter != internalmap->end(); ++iter) - addMappingItem(temp2, iter->first, iter->second); - } catch (YamlEmitterException) { - throw; - } } else if (node->getType() == SEQUENCE) { SequenceNode *seqnode = static_cast<SequenceNode *>(node); - if ((temp1 = yaml_document_add_scalar(&document, NULL, (yaml_char_t *) key.c_str(), -1, YAML_PLAIN_SCALAR_STYLE)) == 0) + int temp1; + 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_sequence(&document, NULL, YAML_BLOCK_SEQUENCE_STYLE)) == 0) + int temp2; + if ((temp2 = yaml_document_add_sequence(&document_, NULL, YAML_BLOCK_SEQUENCE_STYLE)) == 0) throw YamlEmitterException("Could not add scalar to document"); - if (yaml_document_append_mapping_pair(&document, mappingid, temp1, temp2) == 0) + if (yaml_document_append_mapping_pair(&document_, mappingid, temp1, temp2) == 0) throw YamlEmitterException("Could not append mapping pair to mapping"); Sequence *seq = seqnode->getSequence(); - Sequence::const_iterator it; - - for (it = seq->begin(); it != seq->end(); ++it) { + for (Sequence::const_iterator it = seq->begin(); it != seq->end(); ++it) { YamlNode *yamlNode = *it; int id; - - if ((id = yaml_document_add_mapping(&document, NULL, YAML_BLOCK_MAPPING_STYLE)) == 0) + if ((id = 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, temp2, id) == 0) + if (yaml_document_append_sequence_item(&document_, temp2, id) == 0) throw YamlEmitterException("Could not append account mapping to sequence"); MappingNode *mapnode = static_cast<MappingNode*>(yamlNode); diff --git a/daemon/src/config/yamlemitter.h b/daemon/src/config/yamlemitter.h index 638ee5a745..7cbd4f7ec5 100644 --- a/daemon/src/config/yamlemitter.h +++ b/daemon/src/config/yamlemitter.h @@ -53,26 +53,25 @@ class YamlEmitter { public: YamlEmitter(const char *file); - ~YamlEmitter(); - void open() throw(YamlEmitterException); + void open(); - void close() throw(YamlEmitterException); + void close(); - void serializeAccount(MappingNode *map) throw(YamlEmitterException); + void serializeAccount(MappingNode *map); - void serializePreference(MappingNode *map) throw(YamlEmitterException); + void serializePreference(MappingNode *map); - void serializeVoipPreference(MappingNode *map) throw(YamlEmitterException); + void serializeVoipPreference(MappingNode *map); - void serializeAddressbookPreference(MappingNode *map) throw(YamlEmitterException); + void serializeAddressbookPreference(MappingNode *map); - void serializeHooksPreference(MappingNode *map) throw(YamlEmitterException); + void serializeHooksPreference(MappingNode *map); - void serializeAudioPreference(MappingNode *map) throw(YamlEmitterException); + void serializeAudioPreference(MappingNode *map); - void serializeShortcutPreference(MappingNode *map) throw(YamlEmitterException); + void serializeShortcutPreference(MappingNode *map); void writeAudio(); @@ -80,55 +79,50 @@ class YamlEmitter { void writeVoiplink(); - void serializeData() throw(YamlEmitterException); + void serializeData(); private: NON_COPYABLE(YamlEmitter); void addMappingItem(int mappingid, std::string key, YamlNode *node); - std::string filename; + std::string filename_; - FILE *fd; + FILE *fd_; /** * The parser structure. */ - yaml_emitter_t emitter; + yaml_emitter_t emitter_; /** * The event structure array. */ - yaml_event_t events[EMITTER_MAXEVENT]; - - /** - * - */ - unsigned char buffer[EMITTER_BUFFERSIZE]; + yaml_event_t events_[EMITTER_MAXEVENT]; + unsigned char buffer_[EMITTER_BUFFERSIZE]; /** * Main document for this serialization */ - yaml_document_t document; + yaml_document_t document_; /** * Reference id to the top levell mapping when creating */ - int topLevelMapping; + int topLevelMapping_; /** * We need to add the account sequence if this is the first account to be */ - bool isFirstAccount; + bool isFirstAccount_; /** * Reference to the account sequence */ - int accountSequence; + int accountSequence_; friend class ConfigurationTest; - }; } diff --git a/daemon/src/config/yamlnode.h b/daemon/src/config/yamlnode.h index a183ebe04d..1a7850d066 100644 --- a/daemon/src/config/yamlnode.h +++ b/daemon/src/config/yamlnode.h @@ -35,6 +35,7 @@ #include <list> #include <map> #include <stdexcept> +#include "noncopyable.h" namespace Conf { @@ -63,6 +64,7 @@ class YamlNode { virtual void deleteChildNodes() = 0; private: + NON_COPYABLE(YamlNode); NodeType type; YamlNode *topNode; }; @@ -70,7 +72,7 @@ class YamlNode { class YamlDocument : YamlNode { public: - YamlDocument(YamlNode* top=NULL) : YamlNode(DOCUMENT, top) {} + YamlDocument(YamlNode* top=NULL) : YamlNode(DOCUMENT, top), doc() {} void addNode(YamlNode *node); @@ -88,7 +90,7 @@ class YamlDocument : YamlNode { class SequenceNode : public YamlNode { public: - SequenceNode(YamlNode *top) : YamlNode(SEQUENCE, top) {} + SequenceNode(YamlNode *top) : YamlNode(SEQUENCE, top), seq() {} Sequence *getSequence() { return &seq; @@ -105,7 +107,7 @@ class SequenceNode : public YamlNode { class MappingNode : public YamlNode { public: - MappingNode(YamlNode *top) : YamlNode(MAPPING, top) {} + MappingNode(YamlNode *top) : YamlNode(MAPPING, top), map(), tmpKey() {} Mapping *getMapping() { return ↦ diff --git a/daemon/src/config/yamlparser.cpp b/daemon/src/config/yamlparser.cpp index dabc229330..44ba3e29bb 100644 --- a/daemon/src/config/yamlparser.cpp +++ b/daemon/src/config/yamlparser.cpp @@ -33,47 +33,47 @@ #include "../global.h" #include "config.h" #include "yamlnode.h" -#include <stdio.h> +#include <cstdio> namespace Conf { -YamlParser::YamlParser(const char *file) : filename(file) - , events() - , eventNumber(0) - , doc(NULL) - , eventIndex(0) - , accountSequence(NULL) - , preferenceNode(NULL) - , addressbookNode(NULL) - , audioNode(NULL) - , hooksNode(NULL) - , voiplinkNode(NULL) - , shortcutNode(NULL) +YamlParser::YamlParser(const char *file) : filename_(file) + , fd_(fopen(filename_.c_str(), "rb")) + , parser_() + , events_() + , eventNumber_(0) + , doc_(NULL) + , eventIndex_(0) + , accountSequence_(NULL) + , preferenceNode_(NULL) + , addressbookNode_(NULL) + , audioNode_(NULL) + , hooksNode_(NULL) + , voiplinkNode_(NULL) + , shortcutNode_(NULL) { - fd = fopen(filename.c_str(), "rb"); - - if (!fd) + if (!fd_) throw YamlParserException("Could not open file descriptor"); - if (!yaml_parser_initialize(&parser)) + if (!yaml_parser_initialize(&parser_)) throw YamlParserException("Could not initialize"); - yaml_parser_set_input_file(&parser, fd); + yaml_parser_set_input_file(&parser_, fd_); } YamlParser::~YamlParser() { - if (fd) { - fclose(fd); - yaml_parser_delete(&parser); + if (fd_) { + fclose(fd_); + yaml_parser_delete(&parser_); } - for (int i = 0; i < eventNumber; i++) - yaml_event_delete(&events[i]); + for (int i = 0; i < eventNumber_; ++i) + yaml_event_delete(&events_[i]); - if (doc) { - doc->deleteChildNodes(); - delete doc; + if (doc_) { + doc_->deleteChildNodes(); + delete doc_; } } @@ -82,26 +82,20 @@ void YamlParser::serializeEvents() bool done = false; yaml_event_t event, copiedEvent; - try { - while (not done) { - - if (!yaml_parser_parse(&parser, &event)) - throw YamlParserException("Error while parsing"); + while (not done) { + if (!yaml_parser_parse(&parser_, &event)) + throw YamlParserException("Error while parsing"); - done = (event.type == YAML_STREAM_END_EVENT); + done = (event.type == YAML_STREAM_END_EVENT); - copyEvent(&copiedEvent, &event); + copyEvent(&copiedEvent, &event); - events.push_back(copiedEvent); + events_.push_back(copiedEvent); - eventNumber++; + ++eventNumber_; - yaml_event_delete(&event); - } - } catch (const YamlParserException &e) { - throw; + yaml_event_delete(&event); } - } @@ -200,267 +194,211 @@ void YamlParser::copyEvent(yaml_event_t *event_to, yaml_event_t *event_from) YamlDocument *YamlParser::composeEvents() { - try { - 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"); + if (eventNumber_ == 0) + throw YamlParserException("No event available"); - eventIndex = 0; + if (events_[0].type != YAML_STREAM_START_EVENT) + throw YamlParserException("Parsing does not start with stream start"); - processStream(); - } catch (const YamlParserException &e) { - throw; - } + eventIndex_ = 0; + processStream(); - return doc; + return doc_; } void YamlParser::processStream() { - try { - while ((eventIndex < eventNumber) && (events[eventIndex].type != YAML_STREAM_END_EVENT)) { + for (; (eventIndex_ < eventNumber_) and (events_[eventIndex_].type != YAML_STREAM_END_EVENT); ++eventIndex_) + if (events_[eventIndex_].type == YAML_DOCUMENT_START_EVENT) + processDocument(); - 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"); - } catch (const YamlParserException &e) { - throw; - } + if (events_[eventIndex_].type != YAML_STREAM_END_EVENT) + throw YamlParserException("Did not found end of stream"); } void YamlParser::processDocument() { - try { - - 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; - } + doc_ = new YamlDocument(); - eventIndex++; - } - - if (events[eventIndex].type != YAML_DOCUMENT_END_EVENT) - throw YamlParserException("Did not found end of document"); + if (!doc_) + throw YamlParserException("Not able to create new document"); - } catch (const YamlParserException &e) { - throw; + for (; (eventIndex_ < eventNumber_) and (events_[eventIndex_].type != YAML_DOCUMENT_END_EVENT); ++eventIndex_) { + 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; + } } + + if (events_[eventIndex_].type != YAML_DOCUMENT_END_EVENT) + throw YamlParserException("Did not found end of document"); } void YamlParser::processScalar(YamlNode *topNode) { - try { - - if (!topNode) - throw YamlParserException("No container for scalar"); + if (!topNode) + throw YamlParserException("No container for scalar"); - ScalarNode *sclr = new ScalarNode(std::string((const char*)events[eventIndex].data.scalar.value), topNode); + ScalarNode *sclr = new ScalarNode(std::string((const char*)events_[eventIndex_].data.scalar.value), 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; - } - } catch (const YamlParserException &e) { - throw; + 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) { - try { - if (!topNode) - throw YamlParserException("No container for sequence"); + if (!topNode) + throw YamlParserException("No container for sequence"); - SequenceNode *seq = new SequenceNode(topNode); + SequenceNode *seq = new SequenceNode(topNode); - switch (topNode->getType()) { - case DOCUMENT: - ((YamlDocument *)(topNode))->addNode(seq); + 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_; + + for (; (eventIndex_ < eventNumber_) and (events_[eventIndex_].type != YAML_SEQUENCE_END_EVENT); ++eventIndex_) { + switch (events_[eventIndex_].type) { + case YAML_SCALAR_EVENT: + processScalar(seq); break; - case SEQUENCE: - ((SequenceNode *)(topNode))->addNode(seq); + case YAML_SEQUENCE_START_EVENT: + processSequence(seq); + break; + case YAML_MAPPING_START_EVENT: + processMapping(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; - } + if (events_[eventIndex_].type != YAML_SEQUENCE_END_EVENT) + throw YamlParserException("Did not found end of sequence"); - eventIndex++; - } +} - if (events[eventIndex].type != YAML_SEQUENCE_END_EVENT) - throw YamlParserException("Did not found end of sequence"); +void YamlParser::processMapping(YamlNode *topNode) +{ + if (!topNode) + throw YamlParserException("No container for mapping"); - } catch (const YamlParserException &e) { - throw; + 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_; -void YamlParser::processMapping(YamlNode *topNode) -{ - try { + while ((eventIndex_ < eventNumber_) && (events_[eventIndex_].type != YAML_MAPPING_END_EVENT)) { - if (!topNode) - throw YamlParserException("No container for mapping"); + if (events_[eventIndex_].type != YAML_SCALAR_EVENT) + throw YamlParserException("Mapping not followed by a key"); - MappingNode *map = new MappingNode(topNode); + map->setTmpKey(std::string((const char *)events_[eventIndex_].data.scalar.value)); + ++eventIndex_; - switch (topNode->getType()) { - case DOCUMENT: - ((YamlDocument *)(topNode))->addNode(map); + switch (events_[eventIndex_].type) { + case YAML_SCALAR_EVENT: + processScalar(map); break; - case SEQUENCE: - ((SequenceNode *)(topNode))->addNode(map); + case YAML_SEQUENCE_START_EVENT: + processSequence(map); + break; + case YAML_MAPPING_START_EVENT: + processMapping(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"); - - map->setTmpKey(std::string((const char *)events[eventIndex].data.scalar.value)); - - 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"); - - } catch (const YamlParserException &e) { - throw; + ++eventIndex_; } + + if (events_[eventIndex_].type != YAML_MAPPING_END_EVENT) + throw YamlParserException("Did not found end of mapping"); } void YamlParser::constructNativeData() { - try { - Sequence *seq; - - seq = doc->getSequence(); - - Sequence::iterator iter = seq->begin(); - - while (iter != seq->end()) { - - switch ((*iter)->getType()) { - case SCALAR: - throw YamlParserException("No scalar allowed at document level, expect a mapping"); - break; - case SEQUENCE: - throw YamlParserException("No sequence allowed at document level, expect a mapping"); - break; - case MAPPING: { - MappingNode *map = (MappingNode *)(*iter); - mainNativeDataMapping(map); - break; - } - default: - throw YamlParserException("Unknown type in configuration file, expect a mapping"); - break; - } - - iter++; + Sequence *seq = doc_->getSequence(); + for (Sequence::iterator iter = seq->begin(); iter != seq->end(); ++iter) { + switch ((*iter)->getType()) { + case SCALAR: + throw YamlParserException("No scalar allowed at document level, expect a mapping"); + break; + case SEQUENCE: + throw YamlParserException("No sequence allowed at document level, expect a mapping"); + break; + case MAPPING: { + MappingNode *map = (MappingNode *)(*iter); + mainNativeDataMapping(map); + break; + } + default: + throw YamlParserException("Unknown type in configuration file, expect a mapping"); + break; } - } catch (const YamlParserException &e) { - throw; } - } - void YamlParser::mainNativeDataMapping(MappingNode *map) { Mapping *mapping = map->getMapping(); - accountSequence = (SequenceNode*)(*mapping)["accounts"]; - addressbookNode = (MappingNode*)(*mapping)["addressbook"]; - audioNode = (MappingNode*)(*mapping)["audio"]; - hooksNode = (MappingNode*)(*mapping)["hooks"]; - preferenceNode = (MappingNode*)(*mapping)["preferences"]; - voiplinkNode = (MappingNode*)(*mapping)["voipPreferences"]; - shortcutNode = (MappingNode*)(*mapping)["shortcuts"]; + accountSequence_ = (SequenceNode*)(*mapping)["accounts"]; + addressbookNode_ = (MappingNode*)(*mapping)["addressbook"]; + audioNode_ = (MappingNode*)(*mapping)["audio"]; + hooksNode_ = (MappingNode*)(*mapping)["hooks"]; + preferenceNode_ = (MappingNode*)(*mapping)["preferences"]; + voiplinkNode_ = (MappingNode*)(*mapping)["voipPreferences"]; + shortcutNode_ = (MappingNode*)(*mapping)["shortcuts"]; } - } + diff --git a/daemon/src/config/yamlparser.h b/daemon/src/config/yamlparser.h index 43b54f466b..1c6ec4fb99 100644 --- a/daemon/src/config/yamlparser.h +++ b/daemon/src/config/yamlparser.h @@ -33,10 +33,11 @@ #include "yamlnode.h" #include <yaml.h> -#include <stdio.h> +#include <cstdio> #include <stdexcept> #include <string> #include <vector> +#include "noncopyable.h" namespace Conf { @@ -66,34 +67,35 @@ class YamlParser { void constructNativeData(); SequenceNode *getAccountSequence() { - return accountSequence; + return accountSequence_; }; MappingNode *getPreferenceNode() { - return preferenceNode; + return preferenceNode_; } MappingNode *getAddressbookNode() { - return addressbookNode; + return addressbookNode_; } MappingNode *getAudioNode() { - return audioNode; + return audioNode_; } MappingNode *getHookNode() { - return hooksNode; + return hooksNode_; } MappingNode *getVoipPreferenceNode() { - return voiplinkNode; + return voiplinkNode_; } MappingNode *getShortcutNode() { - return shortcutNode; + return shortcutNode_; } private: + NON_COPYABLE(YamlParser); /** * Copy yaml parser event in event_to according to their type. @@ -115,47 +117,40 @@ class YamlParser { /** * Configuration file name */ - std::string filename; + std::string filename_; /** * Configuration file descriptor */ - FILE *fd; + FILE *fd_; /** * The parser structure. */ - yaml_parser_t parser; + yaml_parser_t parser_; /** * The event structure array. */ - YamlEventVector events; + YamlEventVector events_; /** * Number of event actually parsed */ - int eventNumber; + int eventNumber_; - YamlDocument *doc; + YamlDocument *doc_; - int eventIndex; + int eventIndex_; - SequenceNode *accountSequence; - - MappingNode *preferenceNode; - - MappingNode *addressbookNode; - - MappingNode *audioNode; - - MappingNode *hooksNode; - - MappingNode *voiplinkNode; - - MappingNode *shortcutNode; + SequenceNode *accountSequence_; + MappingNode *preferenceNode_; + MappingNode *addressbookNode_; + MappingNode *audioNode_; + MappingNode *hooksNode_; + MappingNode *voiplinkNode_; + MappingNode *shortcutNode_; }; - } #endif diff --git a/daemon/src/dbus/configurationmanager.cpp b/daemon/src/dbus/configurationmanager.cpp index c9e7356846..056b819de1 100644 --- a/daemon/src/dbus/configurationmanager.cpp +++ b/daemon/src/dbus/configurationmanager.cpp @@ -45,13 +45,7 @@ const char* ConfigurationManager::SERVER_PATH = ConfigurationManager::ConfigurationManager(DBus::Connection& connection) : DBus::ObjectAdaptor(connection, SERVER_PATH) -{ - shortcutsKeys.push_back("pick_up"); - shortcutsKeys.push_back("hang_up"); - shortcutsKeys.push_back("popup_window"); - shortcutsKeys.push_back("toggle_pick_up_hang_up"); - shortcutsKeys.push_back("toggle_hold"); -} +{} std::map<std::string, std::string> ConfigurationManager::getIp2IpDetails() { diff --git a/daemon/src/dbus/configurationmanager.h b/daemon/src/dbus/configurationmanager.h index f1516b0ad1..f3e0367017 100644 --- a/daemon/src/dbus/configurationmanager.h +++ b/daemon/src/dbus/configurationmanager.h @@ -40,9 +40,11 @@ #pragma GCC diagnostic ignored "-Wignored-qualifiers" #pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Weffc++" #include "configurationmanager-glue.h" #pragma GCC diagnostic warning "-Wignored-qualifiers" #pragma GCC diagnostic warning "-Wunused-parameter" +#pragma GCC diagnostic warning "-Weffc++" #if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6 #pragma GCC diagnostic warning "-Wunused-but-set-variable" @@ -50,12 +52,10 @@ #include "dbus_cpp.h" -class ConfigurationManager - : public org::sflphone::SFLphone::ConfigurationManager_adaptor, - public DBus::IntrospectableAdaptor, - public DBus::ObjectAdaptor { - private: - std::vector<std::string> shortcutsKeys; +class ConfigurationManager : + public org::sflphone::SFLphone::ConfigurationManager_adaptor, + public DBus::IntrospectableAdaptor, + public DBus::ObjectAdaptor { public: diff --git a/daemon/src/dbus/dbus_cpp.h b/daemon/src/dbus/dbus_cpp.h index 8991c6fb41..f1c9031043 100644 --- a/daemon/src/dbus/dbus_cpp.h +++ b/daemon/src/dbus/dbus_cpp.h @@ -33,9 +33,11 @@ #pragma GCC diagnostic ignored "-Wshadow" #pragma GCC diagnostic ignored "-Wignored-qualifiers" #pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Weffc++" #include <dbus-c++/dbus.h> #pragma GCC diagnostic warning "-Wignored-qualifiers" #pragma GCC diagnostic warning "-Wshadow" #pragma GCC diagnostic warning "-Wunused-parameter" +#pragma GCC diagnostic warning "-Weffc++" #endif // DBUS_CPP_WRAPPER_H_ diff --git a/daemon/src/dbus/dbusmanager.cpp b/daemon/src/dbus/dbusmanager.cpp index 9c2a1a1eba..5d273fab90 100644 --- a/daemon/src/dbus/dbusmanager.cpp +++ b/daemon/src/dbus/dbusmanager.cpp @@ -38,7 +38,13 @@ #include "configurationmanager.h" #include "networkmanager.h" -DBusManager::DBusManager() +DBusManager::DBusManager() : callManager_(0) + , configurationManager_(0) + , instanceManager_(0) + , dispatcher_() +#if USE_NETWORKMANAGER + , networkManager_(0) +#endif { try { DBus::_init_threading(); diff --git a/daemon/src/dbus/instance.cpp b/daemon/src/dbus/instance.cpp index 6da75c8505..09185ad926 100644 --- a/daemon/src/dbus/instance.cpp +++ b/daemon/src/dbus/instance.cpp @@ -31,24 +31,23 @@ #include "instance.h" #include "../manager.h" -Instance::Instance(DBus::Connection& connection) - : DBus::ObjectAdaptor(connection, "/org/sflphone/SFLphone/Instance") -{ - count = 0; -} +Instance::Instance(DBus::Connection& connection) : + DBus::ObjectAdaptor(connection, "/org/sflphone/SFLphone/Instance"), + count(0) +{} void Instance::Register(const int32_t& pid UNUSED, const std::string& name UNUSED) { - count++; + ++count; } void Instance::Unregister(const int32_t& pid UNUSED) { - count --; + --count; if (count <= 0) { Manager::instance().terminate(); diff --git a/daemon/src/history/historyitem.cpp b/daemon/src/history/historyitem.cpp index aca76630be..738c7cf4a4 100644 --- a/daemon/src/history/historyitem.cpp +++ b/daemon/src/history/historyitem.cpp @@ -57,7 +57,9 @@ HistoryItem::HistoryItem(const std::string ×tamp_start, {} -HistoryItem::HistoryItem(std::string serialized_form) +HistoryItem::HistoryItem(std::string serialized_form) : + timestamp_start_(), timestamp_stop_(), call_type_(CALL_MISSED), name_(), + number_(), id_(), account_id_(), recording_file_(), confID_(), timeAdded_() { for (int index = 0; serialized_form.find(ITEM_SEPARATOR, 0) != std::string::npos; ++index) { size_t pos = serialized_form.find(ITEM_SEPARATOR, 0); diff --git a/daemon/src/history/historymanager.cpp b/daemon/src/history/historymanager.cpp index 8b68632232..28970000fc 100644 --- a/daemon/src/history/historymanager.cpp +++ b/daemon/src/history/historymanager.cpp @@ -35,7 +35,8 @@ #include <cc++/file.h> #include <time.h> -HistoryManager::HistoryManager() : history_loaded_(false), history_path_("") +HistoryManager::HistoryManager() : + history_items_(), history_loaded_(false), history_path_("") {} int HistoryManager::load_history(int limit, const std::string &path) diff --git a/daemon/src/iax/iaxaccount.cpp b/daemon/src/iax/iaxaccount.cpp index 53b8705d6d..eda848c4a8 100644 --- a/daemon/src/iax/iaxaccount.cpp +++ b/daemon/src/iax/iaxaccount.cpp @@ -38,7 +38,7 @@ #include "manager.h" IAXAccount::IAXAccount(const std::string& accountID) - : Account(accountID, "iax2") + : Account(accountID, "iax2"), password_() { link_ = new IAXVoIPLink(accountID); } diff --git a/daemon/src/iax/iaxcall.cpp b/daemon/src/iax/iaxcall.cpp index 4302102a2f..a1eb21ec93 100644 --- a/daemon/src/iax/iaxcall.cpp +++ b/daemon/src/iax/iaxcall.cpp @@ -56,7 +56,8 @@ int codecToASTFormat(int c) } } -IAXCall::IAXCall(const std::string& id, Call::CallType type) : Call(id, type), session(NULL) +IAXCall::IAXCall(const std::string& id, Call::CallType type) : Call(id, type), + format(0), session(NULL) {} int IAXCall::getSupportedFormat(const std::string &accountID) const diff --git a/daemon/src/iax/iaxcall.h b/daemon/src/iax/iaxcall.h index e81c3bb70e..b282252039 100644 --- a/daemon/src/iax/iaxcall.h +++ b/daemon/src/iax/iaxcall.h @@ -32,6 +32,7 @@ #define IAXCALL_H #include "call.h" +#include "noncopyable.h" /** * @file: iaxcall.h @@ -72,6 +73,8 @@ class IAXCall : public Call { int format; iax_session* session; + private: + NON_COPYABLE(IAXCall); }; #endif diff --git a/daemon/src/iax/iaxvoiplink.cpp b/daemon/src/iax/iaxvoiplink.cpp index 4aed158f7c..f8e10cb1e1 100644 --- a/daemon/src/iax/iaxvoiplink.cpp +++ b/daemon/src/iax/iaxvoiplink.cpp @@ -45,6 +45,7 @@ IAXVoIPLink::IAXVoIPLink(const std::string& accountID) : evThread_(new EventThread(this)) , regSession_(NULL) , nextRefreshStamp_(0) + , mutexIAX_() , converter_(44100) , initDone_(false) , accountID_(accountID) diff --git a/daemon/src/iax/iaxvoiplink.h b/daemon/src/iax/iaxvoiplink.h index 1b29e2199e..b8da8b9032 100644 --- a/daemon/src/iax/iaxvoiplink.h +++ b/daemon/src/iax/iaxvoiplink.h @@ -36,6 +36,7 @@ #include <iax-client.h> #include "audio/codecs/audiocodec.h" // for DEC_BUFFER_SIZE #include "global.h" +#include "noncopyable.h" #include "audio/samplerateconverter.h" namespace sfl { @@ -175,6 +176,7 @@ class IAXVoIPLink : public VoIPLink { virtual std::string getCurrentCodecName(Call *c) const; private: + NON_COPYABLE(IAXVoIPLink); /* * Decode the message count IAX send. * Returns only the new messages number diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index 14e8e391a9..5625855a3c 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -68,12 +68,16 @@ #include <sys/stat.h> // mkdir(2) ManagerImpl::ManagerImpl() : - hasTriedToRegister_(false), config_(), currentCallId_(), + preferences(), voipPreferences(), addressbookPreference(), + hookPreference(), audioPreference(), shortcutPreferences(), + hasTriedToRegister_(false), audioCodecFactory(), dbus_(), config_(), currentCallId_(), currentCallMutex_(), audiodriver_(0), dtmfKey_(0), toneMutex_(), telephoneTone_(0), audiofile_(0), speakerVolume_(0), micVolume_(0), - waitingCall_(), waitingCallMutex_(), nbIncomingWaitingCall_(0), path_(""), - callAccountMap_(), callAccountMapMutex_(), callConfigMap_(), accountMap_(), - history_(new HistoryManager), imModule_(new sfl::InstantMessaging) + audiolayerMutex_(), waitingCall_(), waitingCallMutex_(), + nbIncomingWaitingCall_(0), path_(), callAccountMap_(), + callAccountMapMutex_(), callConfigMap_(), accountMap_(), + mainBuffer_(), conferenceMap_(), history_(new HistoryManager), + imModule_(new sfl::InstantMessaging) { // initialize random generator for call id srand(time(NULL)); diff --git a/daemon/src/managerimpl.h b/daemon/src/managerimpl.h index a12b3f00a4..fff615a48d 100644 --- a/daemon/src/managerimpl.h +++ b/daemon/src/managerimpl.h @@ -1208,8 +1208,6 @@ class ManagerImpl { * send, and receive instant messages. */ sfl::InstantMessaging *imModule_; - - Conf::YamlEmitter *emitter_; }; #endif // __MANAGER_H__ diff --git a/daemon/src/preferences.cpp b/daemon/src/preferences.cpp index a690ae47e9..8844bf3256 100644 --- a/daemon/src/preferences.cpp +++ b/daemon/src/preferences.cpp @@ -408,6 +408,9 @@ void AudioPreference::unserialize(Conf::MappingNode *map) } } +ShortcutPreferences::ShortcutPreferences() : hangup_(), pickup_(), popup_(), + toggleHold_(), togglePickupHangup_() {} + std::map<std::string, std::string> ShortcutPreferences::getShortcuts() const { std::map<std::string, std::string> shortcutsMap; diff --git a/daemon/src/preferences.h b/daemon/src/preferences.h index 58892b0dd0..b056527825 100644 --- a/daemon/src/preferences.h +++ b/daemon/src/preferences.h @@ -566,6 +566,7 @@ class AudioPreference : public Serializable { class ShortcutPreferences : public Serializable { public: + ShortcutPreferences(); virtual void serialize(Conf::YamlEmitter *emitter); virtual void unserialize(Conf::MappingNode *map); @@ -600,7 +601,7 @@ class ShortcutPreferences : public Serializable { return toggleHold_; } - void setToggleHold(std::string hold) { + void setToggleHold(const std::string &hold) { toggleHold_ = hold; } diff --git a/daemon/src/sip/pattern.cpp b/daemon/src/sip/pattern.cpp index a4aab2c2c5..d1b139cc26 100644 --- a/daemon/src/sip/pattern.cpp +++ b/daemon/src/sip/pattern.cpp @@ -35,18 +35,17 @@ namespace sfl { Pattern::Pattern(const std::string& pattern, const std::string& options) : pattern_(pattern), + subject_(), re_(NULL), ovector_(NULL), ovectorSize_(0), count_(0), - options_(0) + options_(0), + optionsDescription_(options) { // Set offsets offset_[0] = offset_[1] = 0; - // Set options. - optionsDescription_ = options; - for (unsigned int i = 0; i < options.length(); i++) { switch (options.at(i)) { case 'i': diff --git a/daemon/src/sip/pattern.h b/daemon/src/sip/pattern.h index 1883a23388..a33ad4eaa9 100644 --- a/daemon/src/sip/pattern.h +++ b/daemon/src/sip/pattern.h @@ -33,6 +33,7 @@ #include <string> #include <vector> #include <pcre.h> +#include "noncopyable.h" namespace sfl { @@ -295,6 +296,7 @@ class Pattern { std::vector<std::string> split(); private: + NON_COPYABLE(Pattern); // The regular expression that represents that pattern. std::string pattern_; diff --git a/daemon/src/sip/sdes_negotiator.cpp b/daemon/src/sip/sdes_negotiator.cpp index e32a3548bb..1d0d808e13 100644 --- a/daemon/src/sip/sdes_negotiator.cpp +++ b/daemon/src/sip/sdes_negotiator.cpp @@ -42,7 +42,14 @@ using namespace sfl; SdesNegotiator::SdesNegotiator(const std::vector<CryptoSuiteDefinition>& localCapabilites, const std::vector<std::string>& remoteAttribute) : remoteAttribute_(remoteAttribute), - localCapabilities_(localCapabilites) + localCapabilities_(localCapabilites), + cryptoSuite_(), + srtpKeyMethod_(), + srtpKeyInfo_(), + lifetime_(), + mkiValue_(), + mkiLength_(), + authTagLength_() {} std::vector<CryptoAttribute *> SdesNegotiator::parse() diff --git a/daemon/src/sip/sdp.cpp b/daemon/src/sip/sdp.cpp index 136515bb1c..2034f39c71 100644 --- a/daemon/src/sip/sdp.cpp +++ b/daemon/src/sip/sdp.cpp @@ -42,15 +42,16 @@ Sdp::Sdp(pj_pool_t *pool) , remoteSession_(NULL) , activeLocalSession_(NULL) , activeRemoteSession_(NULL) - , localIpAddr_("") - , remoteIpAddr_("") + , codec_list_() + , sessionAudioMedia_() + , localIpAddr_() + , remoteIpAddr_() , localAudioPort_(0) , remoteAudioPort_(0) - , zrtpHelloHash_("") + , zrtpHelloHash_() , srtpCrypto_() , telephoneEventPayload_(101) // same as asterisk -{ -} +{} void Sdp::setActiveLocalSdpSession(const pjmedia_sdp_session *sdp) { diff --git a/daemon/src/sip/sdp.h b/daemon/src/sip/sdp.h index 86ae72be98..7c467fc5fa 100644 --- a/daemon/src/sip/sdp.h +++ b/daemon/src/sip/sdp.h @@ -277,6 +277,8 @@ class Sdp { void receivingAnswerAfterInitialOffer(const pjmedia_sdp_session* remote); private: + NON_COPYABLE(Sdp); + /** * The pool to allocate memory, ownership to SipCall * SDP should not release the pool itself @@ -355,8 +357,6 @@ class Sdp { */ unsigned int telephoneEventPayload_; - NON_COPYABLE(Sdp); - /* * Build the sdp media section * Add rtpmap field if necessary diff --git a/daemon/src/sip/sipaccount.cpp b/daemon/src/sip/sipaccount.cpp index f679d8d0ae..fdd463449f 100644 --- a/daemon/src/sip/sipaccount.cpp +++ b/daemon/src/sip/sipaccount.cpp @@ -41,29 +41,32 @@ SIPAccount::SIPAccount(const std::string& accountID) : Account(accountID, "SIP") , transport_(NULL) + , credentials_() , regc_(NULL) , bRegister_(false) , registrationExpire_(600) , interface_("default") , publishedSameasLocal_(true) - , publishedIpAddress_("") + , publishedIpAddress_() , localPort_(DEFAULT_SIP_PORT) , publishedPort_(DEFAULT_SIP_PORT) - , serviceRoute_("") + , serviceRoute_() , tlsListenerPort_(DEFAULT_SIP_TLS_PORT) , transportType_(PJSIP_TRANSPORT_UNSPECIFIED) , cred_(NULL) + , tlsSetting_() + , stunServerName_() , stunPort_(0) , dtmfType_(OVERRTP) , tlsEnable_("false") , tlsPort_(DEFAULT_SIP_TLS_PORT) - , tlsCaListFile_("") - , tlsCertificateFile_("") - , tlsPrivateKeyFile_("") - , tlsPassword_("") + , tlsCaListFile_() + , tlsCertificateFile_() + , tlsPrivateKeyFile_() + , tlsPassword_() , tlsMethod_("TLSv1") - , tlsCiphers_("") - , tlsServerName_("") + , tlsCiphers_() + , tlsServerName_(0, 0) , tlsVerifyServer_(true) , tlsVerifyClient_(true) , tlsRequireClientCertificate_(true) @@ -78,9 +81,8 @@ SIPAccount::SIPAccount(const std::string& accountID) , zrtpDisplaySasOnce_(false) , zrtpHelloHash_(true) , zrtpNotSuppWarning_(true) + , registrationStateDetailed_() { - stunServerName_.ptr = NULL; - stunServerName_.slen = 0; link_ = SIPVoIPLink::instance(); } diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index 48a5a577b8..45ba05ec46 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -167,7 +167,7 @@ pjsip_route_hdr *createRouteSet(const std::string &route, pj_pool_t *hdr_pool) /*************************************************************************************************/ -SIPVoIPLink::SIPVoIPLink() : evThread_(new EventThread(this)) +SIPVoIPLink::SIPVoIPLink() : transportMap_(), evThread_(new EventThread(this)) { #define TRY(ret) do { \ if (ret != PJ_SUCCESS) \ diff --git a/daemon/src/voiplink.cpp b/daemon/src/voiplink.cpp index 335d5871d5..6a34ea5f4c 100644 --- a/daemon/src/voiplink.cpp +++ b/daemon/src/voiplink.cpp @@ -34,6 +34,8 @@ #include "call.h" #include "voiplink.h" +VoIPLink::VoIPLink() : callMap_(), callMapMutex_() {} + VoIPLink::~VoIPLink() { ost::MutexLock m(callMapMutex_); diff --git a/daemon/src/voiplink.h b/daemon/src/voiplink.h index 5095d2a1d3..52257afd75 100644 --- a/daemon/src/voiplink.h +++ b/daemon/src/voiplink.h @@ -60,12 +60,9 @@ class VoipLinkException : public std::runtime_error { */ class VoIPLink { public: - /** - * Virtual destructor - */ + VoIPLink(); virtual ~VoIPLink(); - /** * Virtual method * Event listener. Each event send by the call manager is received and handled from here diff --git a/daemon/test/Makefile.am b/daemon/test/Makefile.am index 5a23e32309..28c269d257 100644 --- a/daemon/test/Makefile.am +++ b/daemon/test/Makefile.am @@ -24,8 +24,6 @@ test_SOURCES = \ historytest.cpp \ numbercleanertest.h \ numbercleanertest.cpp \ - rtptest.h \ - rtptest.cpp \ sdesnegotiatortest.h \ sdesnegotiatortest.cpp \ instantmessagingtest.h \ @@ -50,7 +48,6 @@ test_SOURCES = \ mainbuffertest.h \ numbercleanertest.h \ ringtonetest.h \ - rtptest.h \ sdesnegotiatortest.h \ sdptest.h \ siptest.h \ diff --git a/daemon/test/audiolayertest.cpp b/daemon/test/audiolayertest.cpp index d9581653bf..589271f04b 100644 --- a/daemon/test/audiolayertest.cpp +++ b/daemon/test/audiolayertest.cpp @@ -39,6 +39,9 @@ using std::cout; using std::endl; +AudioLayerTest::AudioLayerTest() : manager_(0), pulselayer_(0), layer_(0) +{} + void AudioLayerTest::testAudioLayerConfig() { DEBUG("-------------------- AudioLayerTest::testAudioLayerConfig --------------------\n"); diff --git a/daemon/test/audiolayertest.h b/daemon/test/audiolayertest.h index 6515933b7c..994cbaa62f 100644 --- a/daemon/test/audiolayertest.h +++ b/daemon/test/audiolayertest.h @@ -42,7 +42,7 @@ #include <cppunit/TestCase.h> #include <cppunit/TestSuite.h> -#include <assert.h> +#include <cassert> // Application import #include "manager.h" @@ -52,6 +52,7 @@ #include "audio/audiolayer.h" #include "audio/alsa/alsalayer.h" #include "audio/pulseaudio/pulselayer.h" +#include "noncopyable.h" class AudioLayerTest: public CppUnit::TestFixture { @@ -63,17 +64,16 @@ class AudioLayerTest: public CppUnit::TestFixture { CPPUNIT_TEST_SUITE_END(); public: - + AudioLayerTest(); void testAudioLayerConfig(); void testPulseConnect(); void testAudioLayerSwitch(); private: + NON_COPYABLE(AudioLayerTest); ManagerImpl* manager_; - PulseLayer* pulselayer_; - int layer_; }; CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AudioLayerTest, "AudioLayerTest"); diff --git a/daemon/test/echocanceltest.cpp b/daemon/test/echocanceltest.cpp index 6102b9591d..53b03faed8 100644 --- a/daemon/test/echocanceltest.cpp +++ b/daemon/test/echocanceltest.cpp @@ -35,6 +35,8 @@ using namespace std; +EchoCancelTest::EchoCancelTest() : echoCanceller_() {} + void EchoCancelTest::testEchoCancelProcessing() { const int nbSamples = 160; @@ -45,7 +47,6 @@ void EchoCancelTest::testEchoCancelProcessing() SFLDataFormat spkrData[1000]; SFLDataFormat echoCancelData[1000]; - // near end input with echo ifstream micFile("sample_no_echo_8kHz_16bit.raw", ifstream::in); // far end input to train filter @@ -53,7 +54,6 @@ void EchoCancelTest::testEchoCancelProcessing() // echo cancelled output ofstream echoCancelFile("sample_echocancel_500ms_8kHz_16bit.raw", ofstream::out); - micFile.seekg(0, ios::end); inputFileLength = micFile.tellg() / sizeof(SFLDataFormat); micFile.seekg(0, ios::beg); @@ -64,16 +64,14 @@ void EchoCancelTest::testEchoCancelProcessing() micFile.read(reinterpret_cast<char *>(micData), nbSamples * sizeof(SFLDataFormat)); spkrFile.read(reinterpret_cast<char *>(spkrData), nbSamples * sizeof(SFLDataFormat)); - echoCanceller.putData(spkrData, nbSamples); - echoCanceller.process(micData, echoCancelData, nbSamples); + echoCanceller_.putData(spkrData, nbSamples); + echoCanceller_.process(micData, echoCancelData, nbSamples); echoCancelFile.write(reinterpret_cast<char *>(echoCancelData), nbSamples * sizeof(SFLDataFormat)); remainingLength -= nbSamples; } - - CPPUNIT_ASSERT(true); } diff --git a/daemon/test/echocanceltest.h b/daemon/test/echocanceltest.h index 381fcad34f..6bd8f3a4c8 100644 --- a/daemon/test/echocanceltest.h +++ b/daemon/test/echocanceltest.h @@ -42,12 +42,10 @@ #include <cppunit/TestCase.h> #include <cppunit/TestSuite.h> -#include <assert.h> +#include <cassert> #include "audio/speexechocancel.h" - - class EchoCancelTest: public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(EchoCancelTest); @@ -55,14 +53,13 @@ class EchoCancelTest: public CppUnit::TestFixture { CPPUNIT_TEST_SUITE_END(); public: - + EchoCancelTest(); void testEchoCancelProcessing(); private: - - SpeexEchoCancel echoCanceller; - + SpeexEchoCancel echoCanceller_; }; + CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(EchoCancelTest, "EchoCancelTest"); CPPUNIT_TEST_SUITE_REGISTRATION(EchoCancelTest); diff --git a/daemon/test/historytest.h b/daemon/test/historytest.h index 0a187e1734..9fb3b97d0f 100644 --- a/daemon/test/historytest.h +++ b/daemon/test/historytest.h @@ -34,9 +34,10 @@ #include <cppunit/TestCase.h> #include <cppunit/TestSuite.h> -#include <assert.h> +#include <cassert> // Application import +#include "noncopyable.h" #include "history/historymanager.h" /* @@ -64,7 +65,7 @@ class HistoryTest : public CppUnit::TestCase { CPPUNIT_TEST_SUITE_END(); public: - HistoryTest() : CppUnit::TestCase("History Tests") {} + HistoryTest() : CppUnit::TestCase("History Tests"), history(0) {} /* * Code factoring - Common resources can be initialized here. @@ -95,6 +96,7 @@ class HistoryTest : public CppUnit::TestCase { void tearDown(); private: + NON_COPYABLE(HistoryTest); HistoryManager *history; }; diff --git a/daemon/test/instantmessagingtest.h b/daemon/test/instantmessagingtest.h index f653fc39ca..867e19eedf 100644 --- a/daemon/test/instantmessagingtest.h +++ b/daemon/test/instantmessagingtest.h @@ -34,10 +34,11 @@ #include <cppunit/TestCase.h> #include <cppunit/TestSuite.h> -#include <assert.h> +#include <cassert> // Application import #include "im/instant_messaging.h" +#include "noncopyable.h" /* * @file instantmessagingtest.h @@ -63,7 +64,7 @@ class InstantMessagingTest : public CppUnit::TestCase { CPPUNIT_TEST_SUITE_END(); public: - InstantMessagingTest() : CppUnit::TestCase("Instant messaging module Tests") {} + InstantMessagingTest() : CppUnit::TestCase("Instant messaging module Tests"), im_(0) {} /* * Code factoring - Common resources can be initialized here. @@ -92,6 +93,7 @@ class InstantMessagingTest : public CppUnit::TestCase { void testIllFormatedMessage(); private: + NON_COPYABLE(InstantMessagingTest); sfl::InstantMessaging *im_; }; diff --git a/daemon/test/sdesnegotiatortest.cpp b/daemon/test/sdesnegotiatortest.cpp index da2325f6b9..2330412ff1 100644 --- a/daemon/test/sdesnegotiatortest.cpp +++ b/daemon/test/sdesnegotiatortest.cpp @@ -47,10 +47,12 @@ #include <unistd.h> #include "global.h" - using std::cout; using std::endl; +SdesNegotiatorTest::SdesNegotiatorTest() : pattern(0), sdesnego(0), + remoteOffer(0), localCapabilities(0) +{} void SdesNegotiatorTest::testTagPattern() { diff --git a/daemon/test/sdesnegotiatortest.h b/daemon/test/sdesnegotiatortest.h index dbb46c966d..eb9bb74cde 100644 --- a/daemon/test/sdesnegotiatortest.h +++ b/daemon/test/sdesnegotiatortest.h @@ -48,6 +48,8 @@ #include <pjlib-util.h> #include <pjnath/stun_config.h> +#include "noncopyable.h" + /* * @file sdesnegotiationTest.cpp * @brief Regroups unitary tests related to the plugin manager. @@ -79,6 +81,7 @@ class SdesNegotiatorTest : public CppUnit::TestCase { public: + SdesNegotiatorTest(); /* * Code factoring - Common resources can be released here. * This method is called by unitcpp after each test @@ -102,13 +105,11 @@ class SdesNegotiatorTest : public CppUnit::TestCase { void test32ByteKeyLength(); private: + NON_COPYABLE(SdesNegotiatorTest); sfl::Pattern *pattern; - sfl::SdesNegotiator *sdesnego; - std::vector<std::string> *remoteOffer; - std::vector<sfl::CryptoSuiteDefinition> *localCapabilities; }; diff --git a/daemon/test/sdptest.h b/daemon/test/sdptest.h index 574158c12c..e149f9b03a 100644 --- a/daemon/test/sdptest.h +++ b/daemon/test/sdptest.h @@ -59,6 +59,7 @@ #include "global.h" #include "sip/sdp.h" +#include "noncopyable.h" class SdpSessionException : public std::exception { public: @@ -90,7 +91,8 @@ class SDPTest : public CppUnit::TestCase { CPPUNIT_TEST_SUITE_END(); public: - SDPTest() : CppUnit::TestCase("SDP module Tests") {} + SDPTest() : CppUnit::TestCase("SDP module Tests"), session_(0), + testPool_(0), poolCache_() {} /** * Code factoring - Common resources can be initialized here. @@ -115,13 +117,11 @@ class SDPTest : public CppUnit::TestCase { void testReinvite(); private: + NON_COPYABLE(SDPTest); Sdp *session_; - pj_pool_t *testPool_; - pj_caching_pool poolCache_; - }; /* Register our test module */ -- GitLab