33
33
#include "historyitem.h"
38
static const char * const ITEM_SEPARATOR = "|";
40
HistoryItem::HistoryItem(const std::string ×tamp_start,
41
CallType call_type, const std::string ×tamp_stop,
42
const std::string &name, const std::string &number,
43
const std::string &id, const std::string &account_id,
44
const std::string &recording,
45
const std::string &confID,
46
const std::string &timeAdded)
47
: timestamp_start_(timestamp_start),
48
timestamp_stop_(timestamp_stop),
49
call_type_(call_type),
53
account_id_(account_id),
54
recording_file_(recording),
37
const char * const HistoryItem::ACCOUNT_ID_KEY = "accountid";
38
const char * const HistoryItem::CALLID_KEY = "callid";
39
const char * const HistoryItem::CONFID_KEY = "confid";
40
const char * const HistoryItem::DISPLAY_NAME_KEY = "display_name";
41
const char * const HistoryItem::PEER_NUMBER_KEY = "peer_number";
42
const char * const HistoryItem::RECORDING_PATH_KEY = "recordfile";
43
const char * const HistoryItem::STATE_KEY = "state";
44
const char * const HistoryItem::TIMESTAMP_START_KEY = "timestamp_start";
45
const char * const HistoryItem::TIMESTAMP_STOP_KEY = "timestamp_stop";
47
const char * const HistoryItem::MISSED_STRING = "missed";
48
const char * const HistoryItem::INCOMING_STRING = "incoming";
49
const char * const HistoryItem::OUTGOING_STRING = "outgoing";
54
HistoryItem::HistoryItem(const map<string, string> &args) : entryMap_(args),
55
timestampStart_(std::atol(entryMap_[TIMESTAMP_START_KEY].c_str()))
60
HistoryItem::HistoryItem(std::string serialized_form) :
61
timestamp_start_(), timestamp_stop_(), call_type_(CALL_MISSED), name_(),
62
number_(), id_(), account_id_(), recording_file_(), confID_(), timeAdded_()
58
HistoryItem::HistoryItem(std::istream &entry) : entryMap_(), timestampStart_(0)
64
for (int index = 0; serialized_form.find(ITEM_SEPARATOR, 0) != std::string::npos; ++index) {
65
size_t pos = serialized_form.find(ITEM_SEPARATOR, 0);
66
std::string tmp(serialized_form.substr(0, pos));
67
serialized_form.erase(0, pos + 1);
70
case 0: // The call type
71
call_type_ = (CallType) atoi(tmp.c_str());
73
case 1: // The number field
76
case 2: // The name field
82
case 3: // The start timestamp
83
timestamp_start_ = tmp;
85
case 4: // The end timestamp
86
timestamp_stop_ = tmp;
91
case 6: // The account ID
94
case 7: // The recorded file name
95
recording_file_ = tmp;
97
case 8: // The conference ID
104
ERROR("Unserialized form %d not recognized\n", index);
61
while (std::getline(entry, tmp, '\n')) {
62
size_t pos = tmp.find('=');
63
if (pos == string::npos)
65
else if (pos < tmp.length() - 1) {
66
string key(tmp.substr(0, pos));
67
string val(tmp.substr(pos + 1, tmp.length() - pos - 1));
110
bool HistoryItem::save(Conf::ConfigTree **history)
112
std::stringstream section;
113
std::stringstream call_type;
115
// The section is : "[" + timestamp = "]"
117
std::string sectionstr = section.str();
118
call_type << call_type_;
120
return (*history)->setConfigTreeItem(sectionstr, "type", call_type.str())
121
&& (*history)->setConfigTreeItem(sectionstr, "timestamp_start", timestamp_start_)
122
&& (*history)->setConfigTreeItem(sectionstr, "timestamp_stop", timestamp_stop_)
123
&& (*history)->setConfigTreeItem(sectionstr, "number", number_)
124
&& (*history)->setConfigTreeItem(sectionstr, "id", id_)
125
&& (*history)->setConfigTreeItem(sectionstr, "accountid", account_id_)
126
&& (*history)->setConfigTreeItem(sectionstr, "name", name_)
127
&& (*history)->setConfigTreeItem(sectionstr, "recordfile", recording_file_)
128
&& (*history)->setConfigTreeItem(sectionstr, "confid", confID_)
129
&& (*history)->setConfigTreeItem(sectionstr, "timeadded", timeAdded_);
132
std::string HistoryItem::serialize() const
134
// Replace empty string with a valid standard string value
135
std::string name(name_);
140
// For the account ID, check also if the accountID corresponds to an existing account
141
// ie the account may have been removed
142
std::string accountID(account_id_);
144
if (account_id_.empty() or not valid_account(account_id_))
147
std::stringstream res;
149
res << call_type_ << ITEM_SEPARATOR << number_ << ITEM_SEPARATOR << name << ITEM_SEPARATOR << timestamp_start_ << ITEM_SEPARATOR << timestamp_stop_
150
<< ITEM_SEPARATOR << id_ << ITEM_SEPARATOR << accountID << ITEM_SEPARATOR << recording_file_ << ITEM_SEPARATOR << confID_ << ITEM_SEPARATOR << timeAdded_;
156
bool HistoryItem::valid_account(const std::string &id) const
158
return Manager::instance().accountExists(id);
71
timestampStart_ = std::atol(entryMap_[TIMESTAMP_START_KEY].c_str());
74
map<string, string> HistoryItem::toMap() const
79
bool HistoryItem::youngerThan(unsigned long otherTime) const
81
return timestampStart_ > otherTime;
84
bool HistoryItem::hasPeerNumber() const
86
return entryMap_.find(PEER_NUMBER_KEY) != entryMap_.end();
89
void HistoryItem::print(std::ostream &o) const
91
// every entry starts with "[" + random integer = "]"
92
for (map<string, string>::const_iterator iter = entryMap_.begin();
93
iter != entryMap_.end(); ++iter)
94
o << iter->first << "=" << iter->second << std::endl;
97
std::ostream& operator << (std::ostream& o, const HistoryItem& item)