diff --git a/daemon/configure.ac b/daemon/configure.ac index aa26c38b556c7dbab47eb50811692cc69dba58ea..4d7225140a6067f7d716f8bc0c2118e1bde84c57 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 8053e1d430587135c0c870b6c8b7d8e4796adc87..5501e3aa9423fb796202ab8670c909abefef8eb7 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 a094b006a3b544f89edd331df84dd50f8e9c7e37..285f31978bc3864374dca74f8a7940b8b462d717 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 0601ddf3881e4dc23a39002b17937bdc0cbd7575..cc36e453745a342178cee867df424bfcca88dabb 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 0df3f9101498bb9e2e9836a0b5ace02a4386b4d4..dcfe03fdde815d10fbcf4c94c39ca249cf6460ab 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 256d013011d66a39acf464f30388c48c3e37ba3a..d865a5509e44a40190b832a58ef980886e85918d 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 8c7a6acd2f1e66ba13891fcd75a2abc60f56a323..462c32165b74342434d0ebff8e44d25e469476c7 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 ee57e4ec085b6a0c15149358ac4a66a248245638..5ce37ce1f53c08fc342d4b60daff3beefc3173dd 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 0e33ae57c7d4f063122a23b60b260ad10a9a1b6a..9e8ca514ceb67216b48bb6408de2f1eb88d0f89d 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 cb523a21b7c91230a7bb8b8fa459b7bddeeac9f3..8ce03be48914e6902196162e5b23d51cba85c0d1 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 cf8c20e9f48eee754ad30c26241730be265e2e05..9012049a133d1b279448835ba31e3c5d7bcb4a75 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 24206571631eef9e804c7ea3a62e5e62695ed682..5c898441773cb0dff2e2a65434ad742c7f43b7d1 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 35733fa49141217f89e5e208d9f49b217ae7504f..58031f9aba6f1a2b8e715c904594ed66ccf30d99 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 28d822caa4c226e5d464fb0bbe5842675bff425c..f641e8eaa55b21065e7efcee35eb87f3543f93eb 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 9fbd639f38be6c51c684801175df24c58f920425..37f8f7deae6d2be05c2a833032cd1568c7f58409 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 22d3a8a56f16f1b2071502252701320bb07e55ea..162bcadbed5f43d1a611a829b44a72e2e8aa5258 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 7afde913b0307b3d5862259db1955ce957b1bc8a..24e6a9bbf8e6953a98d55be2edeaa9950ebbc3f1 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 fb03b71e0b99984c6c6256a82e7777c5ec72d9ec..08bb9cf4fb4c9bffd2f9fbc49d50520dda88a6c3 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 0846c4e3471052851d766ce286ca96d53582d61e..f1b42ffe86d7f4c1afef1927947f9de13ffb14e9 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 0574123e8daebf75f2dc8bf7354fb96ef000d6fd..0dc73e5832f3a36ee0b45f5b75d2471e10c84bb0 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 f992d2bed91f034bb041c03fb4f1c76e2580da2e..ccc59910e16944ee6782903a18bb8e22e6597ede 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 1df5b0f86bcad47f498f32399459a807468c4513..7a7931ce7a5e3df6b21bef52201e28d74061c07a 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 64e2966b23a49ecf06319ac4c30ba3682ea0b148..7b53fcdce261ed1b24bb644341080f3faee599b9 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 34d2a2d33d624cf458b0d087639f30477a7560da..3f56f0c7823c947c92e01d08c1db1a2615ccc268 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 003c9a53b9b817430d6aca7eb41586ff45eaed3b..286baab13c628402b9ebfb615b5bd2fbb80ff99c 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 e5bb739971e510e0dc2de74488d5726ade26a89e..4f384c0bf8a747ab752d52cf6ee6ccff86f17be8 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 1bdf67c0fcabb8564a4bedc835189d85974c6065..15b7eed93231622d00ed5d6c56ebcc014fd61e68 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 74cd86e3553fa140ae91be8c0609b69ed15e2fc4..997db982023a46f5386d097fc95a4675e2c42618 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 07cd9c325db51d6a80d69b8fd5ec6038195c2a66..c0ffe920db965b05725231dd6689e8a256767e50 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 e4be1aab8cee196efd7cefad981dfbbb755afa00..2568b3a08d9a62186291637ae719a7642a54b90e 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 4b9ea8f41bdeeb2ad900ad5e1a5d291813faccd6..b55b4ed7cbece13b86170dab909459d3c14bdb50 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 3e900a2f479dbc0dfb868b62befa7c656b720c2e..13effb2ef53da4eee22c724a3ddbc3dbc08dc6c2 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 6cc11987ec1de479510e39e72ea4d96e3e35f2f6..9119838ffea0acfdebc05288b9204bfb8963c269 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 6fbc9abde3a79c995d63382f0f1d8a621dcbec81..3337639d50f592a3088f454ec0550c3f685bfc17 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 1ebf376be7672a0e8c1315e4891158940c926110..5c00aea6896cecebc2fdb554d8d552f3eb396b58 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 fbff2918160ae63f29d23a7736e60915979e917e..c5daacddafa48bead5b0b74c6b9af7e380eef5f3 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 f5d62176241afcbbac0b2716cde44b6e93d4bb1e..48d945384f90322897968ee7e89f166f4a09da15 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 839f70b94cba72afe437082134421518b3e81c8d..258d2ca22e8d95e4eb0bb9a72208fd1e5f055dba 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 ec39cf01015c7d33aaf968526ba457ac6717f779..fc37157b582898a800a3fff06fccaa70689b1f5d 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 f4f1993095ec2ab64d878a26355e31c0b59b0032..4ce74de722d1363ceae5e4d3ae1a9935d57788ba 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 d046f894d701b30822c66322f4dbbfd030c722c5..b91dd819c154dbce27251e7c5a10fc7a895d3be1 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 4c21298fedf1dd53f0c3eaf060b6e429f45b74d1..cc6a93b1c874c7b1c283fe592fce8228f661e15f 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 638ee5a74562756e71fabec5bc2b1fb7afa918cb..7cbd4f7ec516333aeebf7cd1a17545eb966e20ad 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 a183ebe04dbb9863b882e3fa2234fcb1101a38c0..1a7850d0669f34e408e25bc450524614fd9d80ea 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 dabc22933084b4d8ea57db7a9d16c3c57934af1c..44ba3e29bb10f7753ca515109a726982e3911293 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 43b54f466b0647c8166afc05b893c4522d59d431..1c6ec4fb99932db639c57080f068cbc6e7ce07cb 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 c9e73568467d81e7645cdfb92ebe7b7db5af5d20..056b819de1217eb56fa71529a33e9046bfc8b8fd 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 f1516b0ad1f828bf0eec760ee2d2c41f5db5625b..f3e03670176e22a0a86fdda460b9f2c3aa562512 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 8991c6fb41349e92555f8924ad622b83b9741d86..f1c9031043fda3d0683a3d84aa1593255b1708c3 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 9c2a1a1eba42ac838d7afed4c6b066b817083ab0..5d273fab9064575af63c625cedee100725088c09 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 6da75c8505dbbf24f9357a2aac78f5527dba7364..09185ad926865dcea0ec1a8471ed533782a73764 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 aca76630bec0fe7e67d5220e5ffa310db9e7991f..738c7cf4a441b9d64e175c79d24b9b82c659a3d6 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 8b6863223213bc9b8a1840f5eab6f9135d0d4267..28970000fcef1d53a847c4d01fa35a94cb8a2bd1 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 53b8705d6d4111a0e598265e52d575a20bd14831..eda848c4a84fc6d5b72f6eb6cb8926f7786f69b7 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 4302102a2f6db683f171ec771b27f8021ae4205c..a1eb21ec93ac7f467f43094922af9eb1d4301402 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 e81c3bb70ebe0a98167ee35c8211388b8eec93c5..b2822520398726543001c18ad02f581f2462f43e 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 4aed158f7c62c0c62ba3b922bae82bf1e3d7c7d5..f8e10cb1e15f1d942e9ed41b3a925c56529cf3ae 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 1b29e2199e0bd486c7dfb8064aafda7f1590f92a..b8da8b90326376891537a65a6c6f8bf3ad38d00c 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 14e8e391a9406dc837a2dab8dcf17b8c7f185477..5625855a3c5c9a59f18041190373bad5cabe7729 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 a12b3f00a4bf310fc5ae3090c6e857c328554031..fff615a48d8072889eab549693efdb7d3b49712a 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 a690ae47e98e93d70ff0c297ef7ae8cd79a9c7fd..8844bf3256cc86fad25ddd0f7fec5db73125338a 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 58892b0dd08956c6c540e1346d68157bbf034128..b056527825de51bd6728ec758bfc04173cdfe4c1 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 a4aab2c2c570ffd127fdc06d61ec944d95dc20e3..d1b139cc269f204ba49b9f7c005159030eb19985 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 1883a23388c0c8c2f2d0236f21d89f55e74c1691..a33ad4eaa90c81d4c5f4a4a898847fda79034243 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 e32a3548bbb55ec539b28bd0f6a12becd48a91ac..1d0d808e13dda73498234d8de8e3ae975ac543af 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 136515bb1cb4f8147e560083ddc17da7f62a0878..2034f39c71f43d8e527d620fe98d13246531fe04 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 86ae72be9819ca2fc80dd8ea219cc280e514259c..7c467fc5faf588e9d551052529226f4a8dcd09f7 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 f679d8d0aed39b9a8a501791352e35e28e521c79..fdd463449f0e624cae0ad0f99c1eca0473013fa3 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 48a5a577b8d1c008d841afa2f846a73dc14f0a2f..45ba05ec467259ac26c21ec10c9af368db60756e 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 335d5871d5e273dbdb504fbfc28a0da2bb12342c..6a34ea5f4cf704ba933bfbd3f17ce70d6ca49cf2 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 5095d2a1d3d30627b7c619b86e1cadecb59ceb8d..52257afd75300cd18bb07194652ce79382c77922 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 5a23e32309ebf043588c37a442e92332f9a9d93b..28c269d257e34af7e9c53d885d1deba3c7911399 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 d9581653bf525f66b99ae2c99bbc6599092d4e01..589271f04b33ef3d5d47ad93762c031b7719b174 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 6515933b7c9b27221f815c79d88be022afdaeace..994cbaa62f96f567d60f8b97bf7232f9ec0c1895 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 6102b9591d0ab4b4606a346315e33b432e055c96..53b03faed8b26b8237e923cb2d6452079c095d83 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 381fcad34f6d0bbf9e67fbc8565f6cb93624c331..6bd8f3a4c8358e2a8e82ddd11ea3e1d16e7cc370 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 0a187e1734246c4e9c5692394060bfaac4890dab..9fb3b97d0f35a222626d4bab3603a58e0795d638 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 f653fc39ca1c1ec53469e825868cf17bf443e919..867e19eedfdcfa91424c5870b5d203e9ad04113e 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 da2325f6b93ee0aa02ccf103ddbd5fcefd304b10..2330412ff1a28b8d928b4bc26582acee8e3a56a6 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 dbb46c966d97b6645f159e931cde652581e49152..eb9bb74cde8fc360dcc456e8d70eaf0114e252c0 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 574158c12c1e9cd7254e14d3ebe03249d703cbd7..e149f9b03aa25e434f406607b362df640a7e97b3 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 */