diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index b36e8f23c043ea51a48add98615fdb64af3b84ef..5094ff92c2292bcb64c34e8287dd00b615968a87 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -41,6 +41,7 @@ #include "global.h" #include "sip/sipaccount.h" #include "iax/iaxaccount.h" +#include "numbercleaner.h" #include "audio/alsa/alsalayer.h" #include "audio/pulseaudio/pulselayer.h" @@ -71,7 +72,6 @@ ManagerImpl::ManagerImpl (void) : _waitingCallMutex(), _nbIncomingWaitingCall (0), _path (""), _callAccountMap(), _callAccountMapMutex(), _callConfigMap(), _accountMap(), - _cleaner (new NumberCleaner), _history (new HistoryManager), _imModule(new sfl::InstantMessaging) { // initialize random generator for call id @@ -83,7 +83,6 @@ ManagerImpl::~ManagerImpl (void) { delete _imModule; delete _history; - delete _cleaner; delete _audiofile; } @@ -204,11 +203,6 @@ void ManagerImpl::switchCall (const std::string& id) bool ManagerImpl::outgoingCall (const std::string& account_id, const std::string& call_id, const std::string& to, const std::string& conf_id) { - - std::string pattern, to_cleaned; - Call::CallConfiguration callConfig; - SIPVoIPLink *siplink; - if (call_id.empty()) { _debug ("Manager: New outgoing call abbort, missing callid"); return false; @@ -226,13 +220,13 @@ bool ManagerImpl::outgoingCall (const std::string& account_id, std::string current_call_id(getCurrentCallId()); + std::string prefix; if (hookPreference.getNumberEnabled()) - _cleaner->set_phone_number_prefix (hookPreference.getNumberAddPrefix()); - else - _cleaner->set_phone_number_prefix (""); + prefix = hookPreference.getNumberAddPrefix(); - to_cleaned = _cleaner->clean (to); + std::string to_cleaned(NumberCleaner::clean(to, prefix)); + Call::CallConfiguration callConfig; /* Check what kind of call we are dealing with */ checkCallConfiguration (call_id, to_cleaned, &callConfig); @@ -250,9 +244,7 @@ bool ManagerImpl::outgoingCall (const std::string& account_id, if (callConfig == Call::IPtoIP) { _debug ("Manager: Start IP2IP call"); /* We need to retrieve the sip voiplink instance */ - siplink = SIPVoIPLink::instance (); - - if (siplink->SIPNewIpToIpCall(call_id, to_cleaned)) { + if (SIPVoIPLink::instance()->SIPNewIpToIpCall(call_id, to_cleaned)) { switchCall (call_id); return true; } else @@ -269,16 +261,13 @@ bool ManagerImpl::outgoingCall (const std::string& account_id, return false; } - if(!associateCallToAccount (call_id, account_id)) { + if(!associateCallToAccount (call_id, account_id)) _warn("Manager: Warning: Could not associate call id %s to account id %s", call_id.c_str(), account_id.c_str()); - } - Call *call = NULL; try { - call = getAccountLink(account_id)->newOutgoingCall (call_id, to_cleaned); + Call *call = getAccountLink(account_id)->newOutgoingCall (call_id, to_cleaned); switchCall (call_id); - call->setConfId(conf_id); } catch (const VoipLinkException &e) { callFailure (call_id); diff --git a/daemon/src/managerimpl.h b/daemon/src/managerimpl.h index 3dabaf6e1f698c99b40a957c5974fd82386cf3d3..97439234f06adf862c44882c0c8ab53a81ac2b7f 100644 --- a/daemon/src/managerimpl.h +++ b/daemon/src/managerimpl.h @@ -46,7 +46,6 @@ #include "call.h" #include "conference.h" -#include "numbercleaner.h" #include "audio/sound/tonelist.h" // for Tone::TONEID declaration #include "audio/sound/audiofile.h" @@ -1245,8 +1244,6 @@ class ManagerImpl // Assignment Operator ManagerImpl& operator= (const ManagerImpl& rh); - NumberCleaner *_cleaner; - /** * To handle the persistent history */ diff --git a/daemon/src/numbercleaner.cpp b/daemon/src/numbercleaner.cpp index 55a4601468f89865d63ec9737a1b0fa1e20da1d5..2e83b6299256117edd46d386f22d8382b9424f6c 100644 --- a/daemon/src/numbercleaner.cpp +++ b/daemon/src/numbercleaner.cpp @@ -30,36 +30,19 @@ */ #include "numbercleaner.h" - -#include <iostream> - -NumberCleaner::NumberCleaner (void) : _prefix ("") -{ -} - -NumberCleaner::~NumberCleaner (void) -{ -} - -std::string NumberCleaner::clean (std::string to_clean) -{ - - strip_char (" ", &to_clean); - // TODO Check for IP to IP call - // strip_char (".", &to_clean); - strip_char ("-", &to_clean); - strip_char ("(", &to_clean); - strip_char (")", &to_clean); - - return to_clean.insert (0, this->get_phone_number_prefix ()); +#include <algorithm> + +namespace { + void strip_chars(const std::string &to_strip, std::string &num) + { + for (std::string::const_iterator iter = to_strip.begin(); + iter != to_strip.end(); ++iter) + num.erase(std::remove(num.begin(), num.end(), *iter), num.end()); + } } -void NumberCleaner::strip_char (std::string to_strip, std::string *num) +std::string NumberCleaner::clean(std::string to_clean, const std::string &prefix) { - - std::size_t pos; - - while ( (pos= (*num).find (to_strip)) != std::string::npos) { - *num = (*num).erase (pos, 1); - } + strip_chars(" -()", to_clean); + return to_clean.insert(0, prefix); } diff --git a/daemon/src/numbercleaner.h b/daemon/src/numbercleaner.h index bf53e3cfa7c6cb7c422c596a641fdfd2128b2d78..9af37c17e8ddfed9e0fc1afeffbd403cf50ebc14 100644 --- a/daemon/src/numbercleaner.h +++ b/daemon/src/numbercleaner.h @@ -29,36 +29,14 @@ * as that of the covered work. */ -#ifndef _NUMBER_CLEANER_H -#define _NUMBER_CLEANER_H +#ifndef _NUMBER_CLEANER_H_ +#define _NUMBER_CLEANER_H_ -#include "logger.h" #include <string> -class NumberCleaner +namespace NumberCleaner { - - public: - NumberCleaner (void); - ~NumberCleaner (void); - - std::string clean (std::string to_clean); - - void set_phone_number_prefix (std::string prefix) { - _debug ("Number: Set phone number prefix %s", _prefix.c_str()); - _prefix = prefix; - } - - std::string get_phone_number_prefix (void) const { - return _prefix; - } - - private: - - std::string _prefix; - - void strip_char (std::string to_strip, std::string *num); - -}; + std::string clean(std::string to_clean, const std::string &prefix = ""); +} #endif diff --git a/daemon/src/preferences.cpp b/daemon/src/preferences.cpp index 7f63de7b416b25ef49055e8204bc069651ac7ddb..b629f832314f52eaf02ccd655f30427676d572c3 100644 --- a/daemon/src/preferences.cpp +++ b/daemon/src/preferences.cpp @@ -241,8 +241,6 @@ HookPreference::HookPreference() : _iax2Enabled (false) } -HookPreference::~HookPreference() {} - void HookPreference::serialize (Conf::YamlEmitter *emitter) { Conf::MappingNode preferencemap (NULL); diff --git a/daemon/src/preferences.h b/daemon/src/preferences.h index 8cf75b79c197e74321e59d401b4d064f8f1ea8ee..e875a31a695750f6261e80a658e8b51e49ce6401 100644 --- a/daemon/src/preferences.h +++ b/daemon/src/preferences.h @@ -351,8 +351,6 @@ class HookPreference : public Serializable HookPreference(); - ~HookPreference(); - virtual void serialize (Conf::YamlEmitter *emitter); virtual void unserialize (Conf::MappingNode *map); diff --git a/daemon/test/numbercleanertest.cpp b/daemon/test/numbercleanertest.cpp index 18b8a3d0131d2d00fe2dd6b3176dd7bc8d58370d..172e28ef14ea95a5ab87f4694e1e8bef2972e319 100644 --- a/daemon/test/numbercleanertest.cpp +++ b/daemon/test/numbercleanertest.cpp @@ -51,100 +51,78 @@ #define VALID_PREPENDED_NUMBER "95143334444" #define VALID_EXTENSION "136" -using std::cout; -using std::endl; - - -void NumberCleanerTest::setUp() -{ - // Instanciate the cleaner singleton - cleaner = new NumberCleaner (); -} - void NumberCleanerTest::test_format_1 (void) { _debug ("-------------------- NumberCleanerTest::test_format_1 --------------------\n"); - - CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_1) == VALID_NUMBER); + CPPUNIT_ASSERT (NumberCleaner::clean (NUMBER_TEST_1) == VALID_NUMBER); } void NumberCleanerTest::test_format_2 (void) { _debug ("-------------------- NumberCleanerTest::test_format_2 --------------------\n"); - CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_2) == VALID_NUMBER); + CPPUNIT_ASSERT (NumberCleaner::clean (NUMBER_TEST_2) == VALID_NUMBER); } void NumberCleanerTest::test_format_3 (void) { _debug ("-------------------- NumberCleanerTest::test_format_3 --------------------\n"); - CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_3) == VALID_NUMBER); + CPPUNIT_ASSERT (NumberCleaner::clean (NUMBER_TEST_3) == VALID_NUMBER); } void NumberCleanerTest::test_format_4 (void) { _debug ("-------------------- NumberCleanerTest::test_format_4 --------------------\n"); - CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_4) == VALID_NUMBER); + CPPUNIT_ASSERT (NumberCleaner::clean (NUMBER_TEST_4) == VALID_NUMBER); } void NumberCleanerTest::test_format_5 (void) { _debug ("-------------------- NumberCleanerTest::test_format_5 --------------------\n"); - CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_5) == VALID_NUMBER); + CPPUNIT_ASSERT (NumberCleaner::clean (NUMBER_TEST_5) == VALID_NUMBER); } void NumberCleanerTest::test_format_6 (void) { _debug ("-------------------- NumberCleanerTest::test_format_6 --------------------\n"); - CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_6) == VALID_NUMBER); + CPPUNIT_ASSERT (NumberCleaner::clean (NUMBER_TEST_6) == VALID_NUMBER); } void NumberCleanerTest::test_format_7 (void) { _debug ("-------------------- NumberCleanerTest::test_format_7 --------------------\n"); - CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_7) == VALID_EXTENSION); + CPPUNIT_ASSERT (NumberCleaner::clean (NUMBER_TEST_7) == VALID_EXTENSION); } void NumberCleanerTest::test_format_8 (void) { _debug ("-------------------- NumberCleanerTest::test_format_8 --------------------\n"); - CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_8) == VALID_NUMBER); + CPPUNIT_ASSERT (NumberCleaner::clean (NUMBER_TEST_8) == VALID_NUMBER); } void NumberCleanerTest::test_format_9 (void) { _debug ("-------------------- NumberCleanerTest::test_format_9 --------------------\n"); - CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_9) == VALID_NUMBER); + CPPUNIT_ASSERT (NumberCleaner::clean (NUMBER_TEST_9) == VALID_NUMBER); } void NumberCleanerTest::test_format_10 (void) { _debug ("-------------------- NumberCleanerTest::test_format_10 --------------------\n"); - cleaner->set_phone_number_prefix ("9"); - CPPUNIT_ASSERT (cleaner->get_phone_number_prefix () == "9"); - CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_1) == VALID_PREPENDED_NUMBER); + CPPUNIT_ASSERT (NumberCleaner::clean (NUMBER_TEST_1, "9") == VALID_PREPENDED_NUMBER); } void NumberCleanerTest::test_format_11 (void) { _debug ("-------------------- NumberCleanerTest::test_format_11 --------------------\n"); - cleaner->set_phone_number_prefix ("9"); - CPPUNIT_ASSERT (cleaner->get_phone_number_prefix () == "9"); - CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_10) == VALID_EXTENSION); -} - -void NumberCleanerTest::tearDown() -{ - // Delete the cleaner object - delete cleaner; - cleaner=0; + CPPUNIT_ASSERT (NumberCleaner::clean (NUMBER_TEST_10, "9") == VALID_EXTENSION); } diff --git a/daemon/test/numbercleanertest.h b/daemon/test/numbercleanertest.h index c02bfdb131eea0356fe75ec0d3238f217ebe5b14..71f22c61bf979d80552fa17cee18933109b8d726 100644 --- a/daemon/test/numbercleanertest.h +++ b/daemon/test/numbercleanertest.h @@ -59,48 +59,26 @@ class NumberCleanerTest : public CppUnit::TestCase { CPPUNIT_TEST (test_format_4); CPPUNIT_TEST (test_format_5); CPPUNIT_TEST (test_format_6); + /*CPPUNIT_TEST (test_format_7); + CPPUNIT_TEST (test_format_8); + CPPUNIT_TEST (test_format_9);*/ CPPUNIT_TEST (test_format_10); CPPUNIT_TEST_SUITE_END (); public: NumberCleanerTest() : CppUnit::TestCase("Hook Manager Tests") {} - /* - * Code factoring - Common resources can be initialized here. - * This method is called by unitcpp before each test - */ - void setUp(); - void test_format_1 (); - void test_format_2 (); - void test_format_3 (); - void test_format_4 (); - void test_format_5 (); - void test_format_6 (); - void test_format_7 (); - void test_format_8 (); - void test_format_9 (); - void test_format_10 (); - void test_format_11 (); - - /* - * Code factoring - Common resources can be released here. - * This method is called by unitcpp after each test - */ - void tearDown (); - - private: - NumberCleaner *cleaner; }; /* Register our test module */