Commit 2270988d authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #6744: simplified numbercleaner

parent 154ceab2
......@@ -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);
......
......@@ -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
*/
......
......@@ -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);
}
......@@ -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
......@@ -241,8 +241,6 @@ HookPreference::HookPreference() : _iax2Enabled (false)
}
HookPreference::~HookPreference() {}
void HookPreference::serialize (Conf::YamlEmitter *emitter)
{
Conf::MappingNode preferencemap (NULL);
......
......@@ -351,8 +351,6 @@ class HookPreference : public Serializable
HookPreference();
~HookPreference();
virtual void serialize (Conf::YamlEmitter *emitter);
virtual void unserialize (Conf::MappingNode *map);
......
......@@ -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);
}
......@@ -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 */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment