Commit f31e87e8 authored by Karel Slaný's avatar Karel Slaný
Browse files

Pulled changes of shared code.

parent 56c7671f
......@@ -115,6 +115,7 @@ SOURCES += \
src/datovka_shared/isds/internal_conversion.cpp \
src/datovka_shared/isds/message_interface.cpp \
src/datovka_shared/isds/type_conversion.cpp \
src/datovka_shared/json/helper.cpp \
src/datovka_shared/localisation/localisation.cpp \
src/datovka_shared/log/global.cpp \
src/datovka_shared/log/log.cpp \
......@@ -124,7 +125,6 @@ SOURCES += \
src/datovka_shared/records_management/conversion.cpp \
src/datovka_shared/records_management/io/records_management_connection.cpp \
src/datovka_shared/records_management/json/entry_error.cpp \
src/datovka_shared/records_management/json/helper.cpp \
src/datovka_shared/records_management/json/service_info.cpp \
src/datovka_shared/records_management/json/stored_files.cpp \
src/datovka_shared/records_management/json/upload_file.cpp \
......@@ -238,6 +238,7 @@ HEADERS += \
src/datovka_shared/isds/message_interface.h \
src/datovka_shared/isds/type_conversion.h \
src/datovka_shared/isds/types.h \
src/datovka_shared/json/helper.h \
src/datovka_shared/localisation/localisation.h \
src/datovka_shared/log/global.h \
src/datovka_shared/log/log_c.h \
......@@ -248,7 +249,6 @@ HEADERS += \
src/datovka_shared/records_management/conversion.h \
src/datovka_shared/records_management/io/records_management_connection.h \
src/datovka_shared/records_management/json/entry_error.h \
src/datovka_shared/records_management/json/helper.h \
src/datovka_shared/records_management/json/service_info.h \
src/datovka_shared/records_management/json/stored_files.h \
src/datovka_shared/records_management/json/upload_file.h \
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2017 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2017 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2017 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -222,6 +222,46 @@ static const char postsignum_qca3_sub_pem[] =
"5KhDYA==""\n"
"-----END CERTIFICATE-----";
static const char postsignum_qca3_sub_tsa_file[] = "postsignum_qca3_sub-tsa.pem";
static const char postsignum_qca3_sub_tsa_name[] = "PostSignum Qualified CA 3-TSA";
static const char postsignum_qca3_sub_tsa_pem[] =
"-----BEGIN CERTIFICATE-----""\n"
"MIIGSDCCBTCgAwIBAgICANUwDQYJKoZIhvcNAQELBQAwWzELMAkGA1UEBhMCQ1ox""\n"
"LDAqBgNVBAoMI8SMZXNrw6EgcG/FoXRhLCBzLnAuIFtJxIwgNDcxMTQ5ODNdMR4w""\n"
"HAYDVQQDExVQb3N0U2lnbnVtIFJvb3QgUUNBIDIwHhcNMTgxMDI1MDcyOTE3WhcN""\n"
"MjUwMTE5MDgwNDMxWjBjMQswCQYDVQQGEwJDWjEsMCoGA1UECgwjxIxlc2vDoSBw""\n"
"b8WhdGEsIHMucC4gW0nEjCA0NzExNDk4M10xJjAkBgNVBAMTHVBvc3RTaWdudW0g""\n"
"UXVhbGlmaWVkIENBIDMtVFNBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC""\n"
"AQEAwc2QqDKrJgrtmoTt5FOx8YZjDA7cFzDPCpdbugwnenXg0ZZg96Emvmq/Y8X+""\n"
"oYumOkBwr6jDmwj5EajqYvm5Wi+SqROdDdaWBfTaWnklgypXrHLXVKn1znsAZBuK""\n"
"5MhOKy4CQOeg7Jgg7DvgvrEUCgbmLTEXigpsbBJx0An6QW9cHzSWGWG9CGlTdUUW""\n"
"BB6SFlBSXgv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pZ251bS5jei9jcmwvcHNyb290cWNhMi5j""\n"
"cmwwMqAwoC6GLGh0dHA6Ly93d3cyLnBvc3RzaWdudW0uY3ovY3JsL3Bzcm9vdHFj""\n"
"YTIuY3JsMDGgL6AthitodHRwOi8vcG9zdHNpZ251bS50dGMuY3ovY3JsL3Bzcm9v""\n"
"dHFjYTIuY3JsMB0GA1UdDgQWBBRsw+aHUj0hN36Xs2TOEa127kSy1jANBgkqhkiG""\n"
"9w0BAQsFAAOCAQEAU0UkMCe/3FpM0jW1akSEuZ1VSfqJtQ/k6GFXBPbUi3pmpHkc""\n"
"NJsE9PlNC/e819Gz0xCiCpfYMJFAuh+VoPVD0S1MpSpBw9iXbUKn/BQGRc9nNvRy""\n"
"aHSA90wwSyh5+/4Bm7/MySyiN7nk1dlWo8/Kn4lMF/wvh41+dPTrv4mgOgqJel04""\n"
"Dd31v990D+LvxwLB5hVK6YjkUXivBPjIx6CI9tcMcM/9mKEouc2HjlaMjSbWNMO7""\n"
"srRPPnYvvzcOKg75wPE0TWhhEK+JR4oTf0YHmTXPbG4z6X+lbmDZ49ikWuCKzP1l""\n"
"bA2jlU5wkBh6F0/Of8cFyxgOMWyfgCMzxiBWow==""\n"
"-----END CERTIFICATE-----";
#if 0
static const char equifax_ca_file[] = "equifax_ca.pem";
static const char equifax_ca_name[] = "Equifax Secure Certificate Authority";
......@@ -290,6 +330,7 @@ const char *pem_files[] = {
postsignum_qca2_root_file,
postsignum_qca2_sub_file,
postsignum_qca3_sub_file,
postsignum_qca3_sub_tsa_file,
// equifax_ca_file,
digicert_ca_root_file,
// NULL,
......@@ -306,6 +347,7 @@ const struct pem_str all_pem_strs[] = {
{postsignum_qca2_root_name, postsignum_qca2_root_pem},
{postsignum_qca2_sub_name, postsignum_qca2_sub_pem},
{postsignum_qca3_sub_name, postsignum_qca3_sub_pem},
{postsignum_qca3_sub_tsa_name, postsignum_qca3_sub_tsa_pem},
// {equifax_ca_name, equifax_ca_pem},
{digicert_ca_root_name, digicert_ca_root_pem},
{NULL, NULL}
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2017 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2017 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2018 CZ.NIC
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -22,6 +22,7 @@
*/
#include <QDir>
#include <QFileInfo>
#include <QSqlError>
#include <QSqlQuery>
#include <QVariant>
......@@ -33,55 +34,179 @@
const QString SQLiteDb::memoryLocation(":memory:");
const QString SQLiteDb::dbDriverType("QSQLITE");
SQLiteDb::SQLiteDb(const QString &connectionName)
/*!
* @brief Make an SQL operation which does not return any query result.
*
* @param[in] db SQLite database object.
* @param[in] queryStrig String with SQL query.
* @return True on success, false on failure.
*/
static
bool queryOperation(QSqlDatabase &db, const QString &queryStr)
{
m_db = QSqlDatabase::addDatabase(dbDriverType, connectionName);
}
QSqlQuery query(db);
SQLiteDb::~SQLiteDb(void)
{
m_db.close();
if (Q_UNLIKELY(queryStr.isEmpty())) {
Q_ASSERT(0);
return false;
}
if (!query.prepare(queryStr)) {
logErrorNL("Cannot prepare SQL query: %s.",
query.lastError().text().toUtf8().constData());
return false;
}
if (!query.exec()) {
logErrorNL("Cannot execute SQL query: %s.",
query.lastError().text().toUtf8().constData());
return false;
}
return true;
}
QString SQLiteDb::fileName(void) const
/*!
* @brief Make a query whose result is a single number.
*
* @param[in] db SQLite database object.
* @param[in] queryStrig String with SQL query.
* @param[out] ok Value is set to false on any error.
* @return Result number. Returns -1 on error.
*/
static
qint64 queryNumber(QSqlDatabase &db, const QString &queryStr,
bool *ok = Q_NULLPTR)
{
return m_db.databaseName();
QSqlQuery query(db);
qint64 num = -1;
if (Q_UNLIKELY(queryStr.isEmpty())) {
Q_ASSERT(0);
goto fail;
}
if (!query.prepare(queryStr)) {
logErrorNL("Cannot prepare SQL command: %s.",
query.lastError().text().toUtf8().constData());
goto fail;
}
if (query.exec() && query.isActive()) {
query.first();
if (query.isValid()) {
bool iOk = false;
num = query.value(0).toLongLong(&iOk);
if (Q_UNLIKELY(!iOk)) {
goto fail;
}
} else {
goto fail;
}
} else {
logErrorNL("Cannot execute SQL query: %s.",
query.lastError().text().toUtf8().constData());
goto fail;
}
if (ok != Q_NULLPTR) {
*ok = true;
}
return num;
fail:
if (ok != Q_NULLPTR) {
*ok = false;
}
return -1;
}
bool SQLiteDb::beginTransaction(void)
/*!
* @brief Attaches a database file to opened database.
*
* @param[in,out] query Query to work with.
* @param[in] fileName File containing database to be attached.
* @return False on error.
*/
static
bool queryAttach(QSqlQuery &query, const QString &fileName)
{
QSqlQuery query(m_db);
QString queryStr("BEGIN DEFERRED TRANSACTION");
QString queryStr("ATTACH DATABASE :fileName AS " DB2);
if (!query.prepare(queryStr)) {
logErrorNL("Cannot prepare SQL query: %s.",
query.lastError().text().toUtf8().constData());
return false;
goto fail;
}
query.bindValue(":fileName", fileName);
if (!query.exec()) {
logErrorNL("Cannot execute SQL query: %s.",
query.lastError().text().toUtf8().constData());
return false;
goto fail;
}
return true;
fail:
return false;
}
bool SQLiteDb::commitTransaction(void)
/*!
* @brief Detaches attached database file from opened database.
*
* @param[in,out] query Query to work with.
* @return False on error.
*/
static
bool queryDetach(QSqlQuery &query)
{
QSqlQuery query(m_db);
QString queryStr("COMMIT TRANSACTION");
QString queryStr("DETACH DATABASE " DB2);
if (!query.prepare(queryStr)) {
logErrorNL("Cannot prepare SQL query: %s.",
query.lastError().text().toUtf8().constData());
return false;
goto fail;
}
if (!query.exec()) {
logErrorNL("Cannot execute SQL query: %s.",
query.lastError().text().toUtf8().constData());
return false;
goto fail;
}
return true;
fail:
return false;
}
SQLiteDb::SQLiteDb(const QString &connectionName)
{
m_db = QSqlDatabase::addDatabase(dbDriverType, connectionName);
}
SQLiteDb::~SQLiteDb(void)
{
m_db.close();