qTox
Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
|
Implements a low level RAII interface to a SQLCipher (SQlite3) database. More...
#include <rawdatabase.h>
Classes | |
class | Query |
struct | Transaction |
Public Types | |
enum | SqlCipherParams { SqlCipherParams::p3_0, SqlCipherParams::halfUpgradedTo4, SqlCipherParams::p4_0 } |
Public Slots | |
bool | setPassword (const QString &password) |
Changes the database password, encrypting or decrypting if necessary. More... | |
bool | rename (const QString &newPath) |
Moves the database file on disk to match the new path. More... | |
bool | remove () |
Deletes the on disk database file after closing it. More... | |
Public Member Functions | |
RawDatabase (const QString &path, const QString &password, const QByteArray &salt) | |
Tries to open a database. More... | |
~RawDatabase () | |
bool | isOpen () |
Checks, that the database is open. More... | |
bool | execNow (const QString &statement) |
Executes a SQL transaction synchronously. More... | |
bool | execNow (const Query &statement) |
Executes a SQL transaction synchronously. More... | |
bool | execNow (const QVector< Query > &statements) |
void | execLater (const QString &statement) |
Executes a SQL transaction asynchronously. More... | |
void | execLater (const Query &statement) |
void | execLater (const QVector< Query > &statements) |
void | sync () |
Waits until all the pending transactions are executed. More... | |
Static Public Member Functions | |
static QString | toString (SqlCipherParams params) |
Protected Slots | |
bool | open (const QString &path, const QString &hexKey={}) |
Tries to open the database with the given (possibly empty) key. More... | |
void | close () |
Close the database and free its associated resources. More... | |
void | process () |
Implements the actual processing of pending transactions. Unqueues, compiles, binds and executes queries, then notifies of results. More... | |
Static Protected Member Functions | |
static QString | deriveKey (const QString &password, const QByteArray &salt) |
Derives a 256bit key from the password and returns it hex-encoded. More... | |
static QString | deriveKey (const QString &password) |
Derives a 256bit key from the password and returns it hex-encoded. More... | |
static QVariant | extractData (sqlite3_stmt *stmt, int col) |
Extracts a variant from one column of a result row depending on the column type. More... | |
static void | regexpInsensitive (sqlite3_context *ctx, int argc, sqlite3_value **argv) |
Use for create function in db for search data use regular experessions without case sensitive. More... | |
static void | regexpSensitive (sqlite3_context *ctx, int argc, sqlite3_value **argv) |
Use for create function in db for search data use regular experessions without case sensitive. More... | |
Private Member Functions | |
QString | anonymizeQuery (const QByteArray &query) |
Hides public keys and timestamps in query. More... | |
bool | openEncryptedDatabaseAtLatestSupportedVersion (const QString &hexKey) |
bool | updateSavedCipherParameters (const QString &hexKey, SqlCipherParams newParams) |
Changes stored db encryption from SQLCipher 3.x defaults to 4.x defaults. More... | |
bool | setCipherParameters (SqlCipherParams params, const QString &database={}) |
SqlCipherParams | highestSupportedParams () |
SqlCipherParams | readSavedCipherParams (const QString &hexKey, SqlCipherParams newParams) |
bool | setKey (const QString &hexKey) |
int | getUserVersion () |
bool | encryptDatabase (const QString &newHexKey) |
bool | decryptDatabase () |
bool | commitDbSwap (const QString &hexKey) |
bool | testUsable () |
Static Private Member Functions | |
static void | regexp (sqlite3_context *ctx, int argc, sqlite3_value **argv, const QRegularExpression::PatternOptions cs) |
Private Attributes | |
sqlite3 * | sqlite |
std::unique_ptr< QThread > | workerThread |
QQueue< Transaction > | pendingTransactions |
QMutex | transactionsMutex |
Protects pendingTransactions. More... | |
QString | path |
QByteArray | currentSalt |
QString | currentHexKey |
Implements a low level RAII interface to a SQLCipher (SQlite3) database.
Thread-safe, does all database operations on a worker thread. The queries must not contain transaction commands (BEGIN/COMMIT/...) or the behavior is undefined.
Definition at line 52 of file rawdatabase.h.
|
strong |
Enumerator | |
---|---|
p3_0 | |
halfUpgradedTo4 | |
p4_0 |
Definition at line 90 of file rawdatabase.h.
RawDatabase::RawDatabase | ( | const QString & | path, |
const QString & | password, | ||
const QByteArray & | salt | ||
) |
Tries to open a database.
path | Path to database. |
password | If empty, the database will be opened unencrypted. Otherwise we will use toxencryptsave to derive a key and encrypt the database. |
Definition at line 87 of file rawdatabase.cpp.
RawDatabase::~RawDatabase | ( | ) |
|
private |
Hides public keys and timestamps in query.
query | Source query, which should be anonymized. |
Definition at line 877 of file rawdatabase.cpp.
|
protectedslot |
Close the database and free its associated resources.
Definition at line 371 of file rawdatabase.cpp.
|
private |
Definition at line 589 of file rawdatabase.cpp.
|
private |
Definition at line 569 of file rawdatabase.cpp.
|
staticprotected |
Derives a 256bit key from the password and returns it hex-encoded.
password | Password to decrypt database |
Definition at line 685 of file rawdatabase.cpp.
|
staticprotected |
Derives a 256bit key from the password and returns it hex-encoded.
password | Password to decrypt database |
salt | Salt to improve password strength, must be TOX_PASS_SALT_LENGTH bytes |
Definition at line 708 of file rawdatabase.cpp.
|
private |
Definition at line 543 of file rawdatabase.cpp.
void RawDatabase::execLater | ( | const QString & | statement | ) |
Executes a SQL transaction asynchronously.
statement | Statement to execute. |
Definition at line 452 of file rawdatabase.cpp.
void RawDatabase::execLater | ( | const Query & | statement | ) |
void RawDatabase::execLater | ( | const QVector< Query > & | statements | ) |
bool RawDatabase::execNow | ( | const QString & | statement | ) |
Executes a SQL transaction synchronously.
statement | Statement to execute. |
Definition at line 400 of file rawdatabase.cpp.
bool RawDatabase::execNow | ( | const Query & | statement | ) |
Executes a SQL transaction synchronously.
statement | Statement to execute. |
Definition at line 410 of file rawdatabase.cpp.
bool RawDatabase::execNow | ( | const QVector< Query > & | statements | ) |
|
staticprotected |
Extracts a variant from one column of a result row depending on the column type.
stmt | Statement to execute. |
col | Number of column to extract. |
Definition at line 894 of file rawdatabase.cpp.
|
private |
Definition at line 356 of file rawdatabase.cpp.
|
private |
Definition at line 297 of file rawdatabase.cpp.
bool RawDatabase::isOpen | ( | ) |
Checks, that the database is open.
Definition at line 389 of file rawdatabase.cpp.
|
protectedslot |
Tries to open the database with the given (possibly empty) key.
path | Path to database. |
hexKey | Hex representation of the key in string. |
Definition at line 143 of file rawdatabase.cpp.
|
private |
Definition at line 186 of file rawdatabase.cpp.
|
protectedslot |
Implements the actual processing of pending transactions. Unqueues, compiles, binds and executes queries, then notifies of results.
Definition at line 736 of file rawdatabase.cpp.
|
private |
Definition at line 326 of file rawdatabase.cpp.
|
staticprivate |
|
staticprotected |
Use for create function in db for search data use regular experessions without case sensitive.
ctx | ctx the context in which an SQL function executes |
argc | number of arguments |
argv | arguments |
Definition at line 918 of file rawdatabase.cpp.
|
staticprotected |
Use for create function in db for search data use regular experessions without case sensitive.
ctx | the context in which an SQL function executes |
argc | number of arguments |
argv | arguments |
Definition at line 929 of file rawdatabase.cpp.
|
slot |
Deletes the on disk database file after closing it.
Definition at line 646 of file rawdatabase.cpp.
|
slot |
Moves the database file on disk to match the new path.
newPath | Path to move database file. |
Definition at line 612 of file rawdatabase.cpp.
|
private |
Definition at line 254 of file rawdatabase.cpp.
|
private |
Definition at line 346 of file rawdatabase.cpp.
|
slot |
Changes the database password, encrypting or decrypting if necessary.
password | If password is empty, the database will be decrypted. |
Definition at line 493 of file rawdatabase.cpp.
void RawDatabase::sync | ( | ) |
Waits until all the pending transactions are executed.
Definition at line 482 of file rawdatabase.cpp.
|
private |
Definition at line 210 of file rawdatabase.cpp.
|
inlinestatic |
|
private |
Changes stored db encryption from SQLCipher 3.x defaults to 4.x defaults.
Definition at line 219 of file rawdatabase.cpp.
|
private |
Definition at line 177 of file rawdatabase.h.
|
private |
Definition at line 176 of file rawdatabase.h.
|
private |
Definition at line 175 of file rawdatabase.h.
|
private |
Definition at line 173 of file rawdatabase.h.
|
private |
Definition at line 171 of file rawdatabase.h.
|
private |
Protects pendingTransactions.
Definition at line 174 of file rawdatabase.h.
|
private |
Definition at line 172 of file rawdatabase.h.