[#1214] Associate an account to an history entry

This commit is contained in:
Emmanuel Milou
2009-06-08 23:01:45 -04:00
parent 918fbbaed4
commit bdb5f89857
9 changed files with 81 additions and 56 deletions

View File

@ -126,7 +126,7 @@ void create_new_call_from_details (const gchar *call_id, GHashTable *details, ca
void create_history_entry_from_serialized_form (gchar *timestamp, gchar *details, callable_obj_t **call)
{
gchar *peer_name="";
gchar *peer_number="", *accountID, *time_stop="";
gchar *peer_number="", *accountID="", *time_stop="";
callable_obj_t *new_call;
history_state_t history_state = MISSED;
char *ptr;
@ -151,6 +151,9 @@ void create_history_entry_from_serialized_form (gchar *timestamp, gchar *details
case 3:
time_stop = ptr;
break;
case 4:
accountID = ptr;
break;
default:
break;
}
@ -159,7 +162,7 @@ void create_history_entry_from_serialized_form (gchar *timestamp, gchar *details
}
create_new_call (HISTORY_ENTRY, CALL_STATE_DIALING, "", "", peer_name, peer_number, &new_call);
create_new_call (HISTORY_ENTRY, CALL_STATE_DIALING, "", accountID, peer_name, peer_number, &new_call);
new_call->_history_state = history_state;
new_call->_time_start = convert_gchar_to_timestamp (timestamp);
new_call->_time_stop = convert_gchar_to_timestamp (time_stop);
@ -262,8 +265,10 @@ gchar* serialize_history_entry (callable_obj_t *entry)
result = g_strconcat (history_state, separator,
entry->_peer_number, separator,
g_strcasecmp (entry->_peer_name,"") ==0 ? "empty": entry->_peer_name,
separator, timestamp, NULL);
g_strcasecmp (entry->_peer_name,"") ==0 ? "empty": entry->_peer_name, separator,
timestamp, separator,
g_strcasecmp (entry->_accountID,"") ==0 ? "empty": entry->_accountID,
NULL);
return result;
}

View File

@ -21,8 +21,10 @@
#include <historyitem.h>
#include <sstream>
#include "stdlib.h"
#include <manager.h>
#define ITEM_SEPARATOR "|"
#define EMPTY_STRING "empty"
HistoryItem::HistoryItem (std::string timestamp_start, CallType call_type, std::string timestamp_stop, std::string name, std::string number, std::string account_id)
: _timestamp_start (timestamp_start), _call_type (call_type), _timestamp_stop (timestamp_stop), _name (name), _number (number), _account_id (account_id)
@ -34,7 +36,7 @@ HistoryItem::HistoryItem (std::string timestamp, std::string serialized_form)
: _timestamp_start (timestamp)
{
size_t pos;
std::string tmp, id, name, number, stop;
std::string tmp, id, name, number, stop, account;
int indice=0;
while (serialized_form.find(ITEM_SEPARATOR, 0) != std::string::npos)
@ -56,6 +58,9 @@ HistoryItem::HistoryItem (std::string timestamp, std::string serialized_form)
case 3: // The end timestamp
stop = tmp;
break;
case 4: // The account ID
account = tmp;
break;
default: // error
std::cout <<"[ERROR] unserialized form not recognized."<<std::endl;
break;
@ -65,8 +70,9 @@ HistoryItem::HistoryItem (std::string timestamp, std::string serialized_form)
_call_type = (CallType)atoi (id.c_str());
_number = number;
_name = name;
_timestamp_stop = serialized_form;
(name == EMPTY_STRING) ? _name = "" : _name = name;
_timestamp_stop = stop;
(serialized_form == EMPTY_STRING) ? _account_id = "" : _account_id=serialized_form ;
}
HistoryItem::~HistoryItem ()
@ -87,6 +93,7 @@ bool HistoryItem::save (Conf::ConfigTree **history){
res = ( (*history)->setConfigTreeItem(section, "type", call_type.str())
&& (*history)->setConfigTreeItem(section, "timestamp_stop", _timestamp_stop)
&& (*history)->setConfigTreeItem(section, "number", _number)
&& (*history)->setConfigTreeItem(section, "accountid", _account_id)
&& (*history)->setConfigTreeItem(section, "name", _name) );
return res;
@ -96,28 +103,22 @@ std::string HistoryItem::serialize (void)
{
std::stringstream res;
std::string separator = ITEM_SEPARATOR;
std::string name, accountID;
// Replace empty string with a valid standard string value
(_name == "")? name = EMPTY_STRING : name = _name;
// For the account ID, check also if the accountID corresponds to an existing account
// ie the account may have been removed
(_account_id == "" || non_valid_account (_account_id))? accountID = "empty" : accountID = _account_id;
// Serialize it
res << _call_type << separator << _number << separator << name << separator << _timestamp_stop << separator << accountID;
res << _call_type << separator << _number << separator << _name << separator << _timestamp_stop ;
return res.str();
}
bool HistoryItem::non_valid_account (std::string id)
{
return !Manager::instance().accountExists (id);
}

View File

@ -60,6 +60,11 @@ class HistoryItem {
private:
/*
* @return true if the account ID corresponds to a loaded account
*/
bool non_valid_account (std::string);
/*
* Timestamp representing the date of the call
*/

View File

@ -78,9 +78,10 @@ int HistoryManager::load_history_items_map (Conf::ConfigTree *history_list)
timestamp_stop = getConfigString (*iter, "timestamp_stop", history_list);
name = getConfigString (*iter, "name", history_list);
number = getConfigString (*iter, "number", history_list);
accountID = getConfigString (*iter, "accountid", history_list);
timestamp_start = *iter;
item = new HistoryItem (timestamp_start, type, timestamp_stop, name, number);
item = new HistoryItem (timestamp_start, type, timestamp_stop, name, number, accountID);
add_new_history_entry (item);
nb_items ++;
@ -220,3 +221,4 @@ int HistoryManager::set_serialized_history (std::map <std::string, std::string>
return items_added;
}

View File

@ -1191,7 +1191,7 @@ ManagerImpl::createSettingsPath (void) {
* Initialization: Main Thread
*/
void
ManagerImpl::initConfigFile ( bool load_user_value )
ManagerImpl::initConfigFile (bool load_user_value, std::string alternate)
{
std::string mes = gettext("Init config file\n");
_debug("%s",mes.c_str());
@ -1199,7 +1199,7 @@ ManagerImpl::initConfigFile ( bool load_user_value )
std::string type_str("string");
std::string type_int("int");
std::string section;
std::string section, path;
// Default values, that will be overwritten by the call to
// 'populateFromFile' below.
@ -1257,9 +1257,14 @@ ManagerImpl::initConfigFile ( bool load_user_value )
fill_config_str (PHONE_NUMBER_HOOK_ENABLED, NO_STR);
fill_config_str (PHONE_NUMBER_HOOK_ADD_PREFIX, "");
// Loads config from ~/.sflphone/sflphonedrc or so..
if (createSettingsPath() == 1 && load_user_value) {
_exist = _config.populateFromFile(_path);
// Loads config from ~/.sflphone/sflphonedrc or so..
if (createSettingsPath() == 1 && load_user_value) {
(alternate == "")? path = _path : path = alternate;
std::cout << path << std::endl;
_exist = _config.populateFromFile(path);
}
_setupLoaded = (_exist == 2 ) ? false : true;

View File

@ -854,7 +854,7 @@ class ManagerImpl {
* Fills the local _config (Conf::ConfigTree) with the default contents.
* Called in main.cpp, just before Manager::init().
*/
void initConfigFile ( bool load_user_value = true );
void initConfigFile ( bool load_user_value=true, std::string alternate="");
/**
* Tell if the setup was already loaded
@ -1099,7 +1099,8 @@ class ManagerImpl {
*/
void unloadAccountMap();
/**
public:
/**
* Tell if an account exists
* @param accountID account ID check
* @return bool True if the account exists
@ -1107,9 +1108,6 @@ class ManagerImpl {
*/
bool accountExists(const AccountID& accountID);
public:
std::map<std::string, std::string> send_history_to_client (void);
void receive_history_from_client (std::map<std::string, std::string> history);
@ -1173,6 +1171,7 @@ private:
#endif
friend class ConfigurationTest;
friend class HistoryTest;
};
#endif // __MANAGER_H__

View File

@ -1,17 +1,20 @@
[144562436]
accountid=
name=Savoir-faire Linux
number=514-276-5468
timestamp_stop=144562458
type=0
[747638685]
accountid=Account:1239059899
name=Emmanuel Milou
number=136
timestamp_stop=747638765
type=2
[775354456]
name=Chez wam
accountid=Account:43789459478
name=
number=5143848557
timestamp_stop=775354987
type=1

View File

@ -3,21 +3,18 @@ number=514-276-5468
name=Savoir-faire Linux
type=0
timestamp_stop=144562458
accountid=
[747638685]
name=Emmanuel Milou
timestamp_stop=747638765
number=136
type=2
accountid=Account:1239059899
[775354456]
number=5143848557
name=Chez wam
name=
timestamp_stop=775354987
type=1
[534244222]
number=136
name=empty
timestamp_stop=5656534543
type=1
accountid=Account:43789459478

View File

@ -21,6 +21,7 @@
#include <sstream>
#include "historyTest.h"
#include "manager.h"
using std::cout;
using std::endl;
@ -28,6 +29,7 @@ using std::endl;
#define HOMEDIR (getenv ("HOME"))
#define HISTORY_SAMPLE "history-sample"
#define HISTORY_SAMPLE_SIZE 3
#define CONFIG_SAMPLE "sflphonedrc-sample"
void HistoryTest::setUp(){
// Instanciate the cleaner singleton
@ -105,6 +107,10 @@ void HistoryTest::test_get_history_serialized ()
std::map <std::string, std::string>::iterator iter;
std::string tmp;
// Load the sample user config
Manager::instance().initConfigFile(true, CONFIG_SAMPLE);
Manager::instance().loadAccountMap ();
CPPUNIT_ASSERT (history->load_history (HISTORY_SAMPLE) == HISTORY_SAMPLE_SIZE);
res = history->get_history_serialized ();
CPPUNIT_ASSERT (res.size()==HISTORY_SAMPLE_SIZE);
@ -114,13 +120,14 @@ void HistoryTest::test_get_history_serialized ()
// The serialized form is: calltype%to%from%callid
// Check the first
tmp = "0|514-276-5468|Savoir-faire Linux|144562458";
tmp = "0|514-276-5468|Savoir-faire Linux|144562458|empty";
CPPUNIT_ASSERT (tmp == res ["144562436"]);
tmp = "2|136|Emmanuel Milou|747638765";
tmp = "2|136|Emmanuel Milou|747638765|Account:1239059899";
CPPUNIT_ASSERT (tmp == res ["747638685"]);
tmp = "1|5143848557|Chez wam|775354987";
// the account ID does not correspond to a loaded account
tmp = "1|5143848557|empty|775354987|empty";
CPPUNIT_ASSERT (tmp == res ["775354456"]);
}
@ -131,9 +138,9 @@ void HistoryTest::test_set_serialized_history ()
std::string tmp;
Conf::ConfigTree history_list;
map_test["144562436"] = "0|514-276-5468|Savoir-faire Linux|144562458";
map_test["747638685"] = "2|136|Emmanuel Milou|747638765";
map_test["775354456"] = "1|5143848557|Chez wam|775354987";
map_test["144562436"] = "0|514-276-5468|Savoir-faire Linux|144562458|empty";
map_test["747638685"] = "2|136|Emmanuel Milou|747638765|Account:1239059899";
map_test["775354456"] = "1|5143848557|empty|775354987|Account:43789459478";
CPPUNIT_ASSERT (history->load_history (HISTORY_SAMPLE) == HISTORY_SAMPLE_SIZE);
CPPUNIT_ASSERT (history->set_serialized_history (map_test) == 3);
@ -141,16 +148,17 @@ void HistoryTest::test_set_serialized_history ()
map_test.clear ();
map_test = history->get_history_serialized ();
CPPUNIT_ASSERT (map_test.size()==HISTORY_SAMPLE_SIZE);
CPPUNIT_ASSERT (map_test.size()==3);
// Check the first
tmp = "0|514-276-5468|Savoir-faire Linux|144562458";
tmp = "0|514-276-5468|Savoir-faire Linux|144562458|empty";
CPPUNIT_ASSERT (tmp == map_test ["144562436"]);
tmp = "2|136|Emmanuel Milou|747638765";
tmp = "2|136|Emmanuel Milou|747638765|Account:1239059899";
CPPUNIT_ASSERT (tmp == map_test ["747638685"]);
tmp = "1|5143848557|Chez wam|775354987";
// the account ID does not correspond to a loaded account
tmp = "1|5143848557|empty|775354987|empty";
CPPUNIT_ASSERT (tmp == map_test ["775354456"]);
history->save_history_items_map (&history_list);