Skip to content
Snippets Groups Projects
Commit bed13016 authored by Emmanuel Lepage Vallée's avatar Emmanuel Lepage Vallée Committed by Stepan Salenikovich
Browse files

history: Fix regression + integer overflow

While not documented, "0" was used as "unlimited hsitory", but
with the recent change, it became "no history". It may make sense
to use -1 as unlimited, but that would break compatibility for
those who imported sflphone configs into Ring.

Also use "long long" as holder for the seconds count. LLVM
UBSAN asserted on an interget overflow on (32bit) ARMv7.

Change-Id: I7137d7f015fd3b42bd46624fa342a39246f05a59
Tuleap: #103
parent d8d144b4
Branches
Tags
No related merge requests found
...@@ -281,6 +281,13 @@ void CategorizedHistoryModel::setHistoryLimited(bool isLimited) ...@@ -281,6 +281,13 @@ void CategorizedHistoryModel::setHistoryLimited(bool isLimited)
ConfigurationManager::instance().setHistoryLimit(0); ConfigurationManager::instance().setHistoryLimit(0);
} }
///Set if the history is enabled
void CategorizedHistoryModel::setHistoryEnabled(bool isEnabled)
{
if (!isEnabled)
ConfigurationManager::instance().setHistoryLimit(-1);
}
///Set the number of days before history items are discarded ///Set the number of days before history items are discarded
void CategorizedHistoryModel::setHistoryLimit(int numberOfDays) void CategorizedHistoryModel::setHistoryLimit(int numberOfDays)
{ {
...@@ -290,7 +297,7 @@ void CategorizedHistoryModel::setHistoryLimit(int numberOfDays) ...@@ -290,7 +297,7 @@ void CategorizedHistoryModel::setHistoryLimit(int numberOfDays)
///Is history items are being deleted after "historyLimit()" days ///Is history items are being deleted after "historyLimit()" days
bool CategorizedHistoryModel::isHistoryLimited() const bool CategorizedHistoryModel::isHistoryLimited() const
{ {
return ConfigurationManager::instance().getHistoryLimit() != 0; return ConfigurationManager::instance().getHistoryLimit() > 0;
} }
///Number of days before items are discarded (0 = never) ///Number of days before items are discarded (0 = never)
...@@ -299,6 +306,12 @@ int CategorizedHistoryModel::historyLimit() const ...@@ -299,6 +306,12 @@ int CategorizedHistoryModel::historyLimit() const
return ConfigurationManager::instance().getHistoryLimit(); return ConfigurationManager::instance().getHistoryLimit();
} }
///Get if the history is enabled
bool CategorizedHistoryModel::isHistoryEnabled() const
{
return ConfigurationManager::instance().getHistoryLimit() >= 0;
}
/***************************************************************************** /*****************************************************************************
* * * *
......
...@@ -53,6 +53,8 @@ public: ...@@ -53,6 +53,8 @@ public:
//Properties //Properties
Q_PROPERTY(bool hasCollections READ hasCollections ) Q_PROPERTY(bool hasCollections READ hasCollections )
Q_PROPERTY(bool historyEnabled READ isHistoryEnabled WRITE setHistoryEnabled)
Q_PROPERTY(bool historyLimited READ isHistoryLimited WRITE setHistoryLimited)
//Singleton //Singleton
static CategorizedHistoryModel& instance(); static CategorizedHistoryModel& instance();
...@@ -60,6 +62,7 @@ public: ...@@ -60,6 +62,7 @@ public:
//Getters //Getters
int acceptedPayloadTypes () const; int acceptedPayloadTypes () const;
bool isHistoryLimited () const; bool isHistoryLimited () const;
bool isHistoryEnabled () const;
int historyLimit () const; int historyLimit () const;
const CallMap getHistoryCalls () const; const CallMap getHistoryCalls () const;
...@@ -70,6 +73,7 @@ public: ...@@ -70,6 +73,7 @@ public:
void setCategoryRole(int role); void setCategoryRole(int role);
void setHistoryLimited(bool isLimited); void setHistoryLimited(bool isLimited);
void setHistoryLimit(int numberOfDays); void setHistoryLimit(int numberOfDays);
void setHistoryEnabled(bool isEnabled);
//Model implementation //Model implementation
virtual bool setData ( const QModelIndex& index, const QVariant &value, int role ) override; virtual bool setData ( const QModelIndex& index, const QVariant &value, int role ) override;
...@@ -120,4 +124,3 @@ Q_SIGNALS: ...@@ -120,4 +124,3 @@ Q_SIGNALS:
///Emitted when a new item is added to prevent full reload ///Emitted when a new item is added to prevent full reload
void newHistoryCall ( Call* call ); void newHistoryCall ( Call* call );
}; };
...@@ -80,6 +80,9 @@ LocalHistoryCollection::~LocalHistoryCollection() ...@@ -80,6 +80,9 @@ LocalHistoryCollection::~LocalHistoryCollection()
void LocalHistoryEditor::saveCall(QTextStream& stream, const Call* call) void LocalHistoryEditor::saveCall(QTextStream& stream, const Call* call)
{ {
if (!CategorizedHistoryModel::instance().isHistoryEnabled())
return;
stream.setCodec("UTF-8"); stream.setCodec("UTF-8");
const QString direction = (call->direction()==Call::Direction::INCOMING)? const QString direction = (call->direction()==Call::Direction::INCOMING)?
Call::HistoryStateName::INCOMING : Call::HistoryStateName::OUTGOING; Call::HistoryStateName::INCOMING : Call::HistoryStateName::OUTGOING;
...@@ -209,6 +212,9 @@ bool LocalHistoryCollection::isEnabled() const ...@@ -209,6 +212,9 @@ bool LocalHistoryCollection::isEnabled() const
bool LocalHistoryCollection::load() bool LocalHistoryCollection::load()
{ {
if (!CategorizedHistoryModel::instance().isHistoryEnabled())
return false;
QFile file(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1Char('/') +"history.ini"); QFile file(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1Char('/') +"history.ini");
if ( file.open(QIODevice::ReadOnly | QIODevice::Text) ) { if ( file.open(QIODevice::ReadOnly | QIODevice::Text) ) {
QMap<QString,QString> hc; QMap<QString,QString> hc;
...@@ -218,7 +224,9 @@ bool LocalHistoryCollection::load() ...@@ -218,7 +224,9 @@ bool LocalHistoryCollection::load()
lines << file.readLine().trimmed(); lines << file.readLine().trimmed();
file.close(); file.close();
int dayLimit = CategorizedHistoryModel::instance().historyLimit() * 24 * 3600; const bool isLimited = CategorizedHistoryModel::instance().isHistoryLimited();
const long long dayLimit = CategorizedHistoryModel::instance().historyLimit() * 24 * 3600;
time_t now = time(0); // get time now time_t now = time(0); // get time now
for (const QString& line : lines) { for (const QString& line : lines) {
...@@ -226,7 +234,7 @@ bool LocalHistoryCollection::load() ...@@ -226,7 +234,7 @@ bool LocalHistoryCollection::load()
if ((line.isEmpty() || !line.size()) && hc.size()) { if ((line.isEmpty() || !line.size()) && hc.size()) {
Call* pastCall = Call::buildHistoryCall(hc); Call* pastCall = Call::buildHistoryCall(hc);
if ((now - pastCall->startTimeStamp()) < dayLimit) { if (!isLimited || ( (now - pastCall->startTimeStamp()) < dayLimit) ) {
pastCall->setCollection(this); pastCall->setCollection(this);
editor<Call>()->addExisting(pastCall); editor<Call>()->addExisting(pastCall);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment