mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Fixes
This commit is contained in:
parent
a432a16e01
commit
eb0b33be32
@ -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*>(_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
|
||||
{
|
||||
|
@ -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));
|
||||
|
@ -24,8 +24,8 @@
|
||||
#include <QDebug>
|
||||
#include <QSqlError>
|
||||
|
||||
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<QString> 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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user