~noskcaj/ubuntu/saucy/sflphone/merge-1.2.3-2

« back to all changes in this revision

Viewing changes to daemon/src/history/historyitem.cpp

  • Committer: Package Import Robot
  • Author(s): Francois Marier
  • Date: 2012-02-18 21:47:09 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120218214709-6362d71gqdsdkrj5
Tags: 1.0.2-1
* New upstream release
  - remove logging patch (applied upstream)
  - update s390 patch since it was partially applied upstream
* Include the Evolution plugin as a separate binary package

* Fix compilation issues on SH4 (closes: #658987)
* Merge Ubuntu's binutils-gold linking fix

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 */
32
32
 
33
33
#include "historyitem.h"
34
 
#include <sstream>
35
34
#include <cstdlib>
36
 
#include "manager.h"
37
 
 
38
 
static const char * const ITEM_SEPARATOR = "|";
39
 
 
40
 
HistoryItem::HistoryItem(const std::string &timestamp_start,
41
 
                         CallType call_type, const std::string &timestamp_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),
50
 
        name_(name),
51
 
        number_(number),
52
 
        id_(id),
53
 
        account_id_(account_id),
54
 
        recording_file_(recording),
55
 
        confID_(confID),
56
 
        timeAdded_(timeAdded)
 
35
#include <istream>
 
36
 
 
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";
 
46
 
 
47
const char * const HistoryItem::MISSED_STRING =         "missed";
 
48
const char * const HistoryItem::INCOMING_STRING =       "incoming";
 
49
const char * const HistoryItem::OUTGOING_STRING =       "outgoing";
 
50
 
 
51
using std::map;
 
52
using std::string;
 
53
 
 
54
HistoryItem::HistoryItem(const map<string, string> &args) : entryMap_(args),
 
55
    timestampStart_(std::atol(entryMap_[TIMESTAMP_START_KEY].c_str()))
57
56
{}
58
57
 
59
 
 
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)
63
59
{
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);
68
 
 
69
 
        switch (index) {
70
 
            case 0: // The call type
71
 
                call_type_ = (CallType) atoi(tmp.c_str());
72
 
                break;
73
 
            case 1: // The number field
74
 
                number_ = tmp;
75
 
                break;
76
 
            case 2: // The name field
77
 
                name_ = tmp;
78
 
 
79
 
                if (name_ == "empty")
80
 
                    name_ = "";
81
 
                break;
82
 
            case 3: // The start timestamp
83
 
                timestamp_start_ = tmp;
84
 
                break;
85
 
            case 4: // The end timestamp
86
 
                timestamp_stop_ = tmp;
87
 
                break;
88
 
            case 5: // The ID
89
 
                id_ = tmp;
90
 
                break;
91
 
            case 6: // The account ID
92
 
                account_id_ = tmp;
93
 
                break;
94
 
            case 7: // The recorded file name
95
 
                recording_file_ = tmp;
96
 
                break;
97
 
            case 8: // The conference ID
98
 
                confID_ = tmp;
99
 
                break;
100
 
            case 9: // the time
101
 
                timeAdded_ = tmp;
102
 
                break;
103
 
            default: // error
104
 
                ERROR("Unserialized form %d not recognized\n", index);
105
 
                break;
 
60
    string tmp;
 
61
    while (std::getline(entry, tmp, '\n')) {
 
62
        size_t pos = tmp.find('=');
 
63
        if (pos == string::npos)
 
64
            break;
 
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));
 
68
            entryMap_[key] = val;
106
69
        }
107
70
    }
108
 
}
109
 
 
110
 
bool HistoryItem::save(Conf::ConfigTree **history)
111
 
{
112
 
    std::stringstream section;
113
 
    std::stringstream call_type;
114
 
 
115
 
    // The section is : "[" + timestamp = "]"
116
 
    section << rand();
117
 
    std::string sectionstr = section.str();
118
 
    call_type << call_type_;
119
 
 
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_);
130
 
}
131
 
 
132
 
std::string HistoryItem::serialize() const
133
 
{
134
 
    // Replace empty string with a valid standard string value
135
 
    std::string name(name_);
136
 
 
137
 
    if (name.empty())
138
 
        name = "empty";
139
 
 
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_);
143
 
 
144
 
    if (account_id_.empty() or not valid_account(account_id_))
145
 
        accountID = "empty";
146
 
 
147
 
    std::stringstream res;
148
 
    // Serialize it
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_;
151
 
 
152
 
    return res.str();
153
 
}
154
 
 
155
 
 
156
 
bool HistoryItem::valid_account(const std::string &id) const
157
 
{
158
 
    return Manager::instance().accountExists(id);
 
71
    timestampStart_ = std::atol(entryMap_[TIMESTAMP_START_KEY].c_str());
 
72
}
 
73
 
 
74
map<string, string> HistoryItem::toMap() const
 
75
{
 
76
    return entryMap_;
 
77
}
 
78
 
 
79
bool HistoryItem::youngerThan(unsigned long otherTime) const
 
80
{
 
81
    return timestampStart_ > otherTime;
 
82
}
 
83
 
 
84
bool HistoryItem::hasPeerNumber() const
 
85
{
 
86
    return entryMap_.find(PEER_NUMBER_KEY) != entryMap_.end();
 
87
}
 
88
 
 
89
void HistoryItem::print(std::ostream &o) const
 
90
{
 
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;
 
95
}
 
96
 
 
97
std::ostream& operator << (std::ostream& o, const HistoryItem& item)
 
98
{
 
99
    item.print(o);
 
100
    return o;
159
101
}