diff --git a/src/core.cpp b/src/core.cpp index 58937a51f..4c54494d1 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -482,7 +482,6 @@ void Core::onGroupInvite(Tox*, int friendnumber, uint8_t type, const uint8_t *da void Core::onGroupMessage(Tox*, int groupnumber, int peernumber, const uint8_t * message, uint16_t length, void *_core) { Core* core = static_cast(_core); - emit core->groupMessageReceived(groupnumber, peernumber, CString::toString(message, length), false); } @@ -1239,7 +1238,9 @@ bool Core::loadConfiguration(QString path) if (salt.size() == 0) { // maybe we should handle this better - qWarning() << "Core: history db isn't encrypted, but encryption is set!! No history loaded..."; + Widget::getInstance()->showWarningMsgBox(tr("Encrypted History"), tr("No encrypted history file found.\nHistory will be disabled!")); + Settings::getInstance().setEncryptLogs(false); + Settings::getInstance().setEnableLogging(false); } else { diff --git a/src/historykeeper.cpp b/src/historykeeper.cpp index 5a83d6dbe..c846ff9d2 100644 --- a/src/historykeeper.cpp +++ b/src/historykeeper.cpp @@ -132,9 +132,10 @@ HistoryKeeper::HistoryKeeper(GenericDdInterface *db_) : setSyncType(Settings::getInstance().getDbSyncType()); + messageID = 0; QSqlQuery sqlAnswer = db->exec("select seq from sqlite_sequence where name=\"history\";"); - sqlAnswer.first(); - messageID = sqlAnswer.value(0).toInt(); + if (sqlAnswer.first()) + messageID = sqlAnswer.value(0).toInt(); } HistoryKeeper::~HistoryKeeper() @@ -148,7 +149,7 @@ int HistoryKeeper::addChatEntry(const QString& chat, const QString& message, con int sender_id = getAliasID(sender); db->exec("BEGIN TRANSACTION;"); - db->exec(QString("INSERT INTO history (timestamp, chat_id, sender, message) ") + + db->exec(QString("INSERT INTO history (timestamp, chat_id, sender, message)") + QString("VALUES (%1, %2, %3, '%4');") .arg(dt.toMSecsSinceEpoch()).arg(chat_id).arg(sender_id).arg(wrapMessage(message))); db->exec(QString("INSERT INTO sent_status (status) VALUES (%1);").arg(isSent)); diff --git a/src/misc/db/encrypteddb.cpp b/src/misc/db/encrypteddb.cpp index 8ae7ea123..b2e5e0328 100644 --- a/src/misc/db/encrypteddb.cpp +++ b/src/misc/db/encrypteddb.cpp @@ -24,8 +24,8 @@ #include #include -qint64 EncryptedDb::plainChunkSize = 4096; -qint64 EncryptedDb::encryptedChunkSize = EncryptedDb::plainChunkSize + tox_pass_encryption_extra_length(); +qint64 EncryptedDb::encryptedChunkSize = 4096; +qint64 EncryptedDb::plainChunkSize = EncryptedDb::encryptedChunkSize - tox_pass_encryption_extra_length(); EncryptedDb::EncryptedDb(const QString &fname, QList initList) : PlainDb(":memory:", initList), fileName(fname) @@ -65,7 +65,7 @@ EncryptedDb::~EncryptedDb() QSqlQuery EncryptedDb::exec(const QString &query) { QSqlQuery retQSqlQuery = PlainDb::exec(query); - if (query.startsWith("INSERT", Qt::CaseInsensitive)) + if (checkCmd(query)) appendToEncrypted(query); return retQSqlQuery; @@ -100,31 +100,15 @@ bool EncryptedDb::pullFileContent(const QString &fname, QByteArray &buf) for (auto ba_line : splittedBA) { QString line = QByteArray::fromBase64(ba_line); - if (line.size() == 0) - continue; - - bool isGoodLine = false; - if (line.startsWith("CREATE", Qt::CaseInsensitive) || line.startsWith("INSERT", Qt::CaseInsensitive)) - { - if (line.endsWith(");")) - { - sqlCmds.append(line); - isGoodLine = true; - } - } - - if (!isGoodLine) - { - qWarning() << "Encrypted history log is corrupted: errors in content"; - buf = QByteArray(); - return false; - } + sqlCmds.append(line); } + PlainDb::exec("BEGIN TRANSACTION;"); for (auto line : sqlCmds) { QSqlQuery r = PlainDb::exec(line); } + PlainDb::exec("COMMIT TRANSACTION;"); dbFile.close(); @@ -184,3 +168,14 @@ bool EncryptedDb::check(const QString &fname) file.close(); return state; } + +bool EncryptedDb::checkCmd(const QString &cmd) +{ + if (cmd.startsWith("INSERT", Qt::CaseInsensitive) || cmd.startsWith("UPDATE", Qt::CaseInsensitive) + || cmd.startsWith("DELETE", Qt::CaseInsensitive)) + { + return true; + } + + return false; +} diff --git a/src/misc/db/encrypteddb.h b/src/misc/db/encrypteddb.h index bbac817c4..c27fb5c8c 100644 --- a/src/misc/db/encrypteddb.h +++ b/src/misc/db/encrypteddb.h @@ -34,6 +34,7 @@ public: private: bool pullFileContent(const QString& fname, QByteArray &buf); void appendToEncrypted(const QString &sql); + bool checkCmd(const QString &cmd); QFile encrFile; QString fileName;