Commit 9e7a3d7d authored by Karel Slaný's avatar Karel Slaný

Pulled shared code modifications from desktop application repository.

parent 1e11bd7a
......@@ -93,7 +93,9 @@ SOURCES += \
src/datovka_shared/io/sqlite/db.cpp \
src/datovka_shared/io/sqlite/db_single.cpp \
src/datovka_shared/io/sqlite/table.cpp \
src/datovka_shared/isds/account_interface.cpp \
src/datovka_shared/isds/box_interface.cpp \
src/datovka_shared/isds/error.cpp \
src/datovka_shared/isds/internal_conversion.cpp \
src/datovka_shared/isds/message_interface.cpp \
src/datovka_shared/isds/type_conversion.cpp \
......@@ -192,7 +194,9 @@ HEADERS += \
src/datovka_shared/io/sqlite/db.h \
src/datovka_shared/io/sqlite/db_single.h \
src/datovka_shared/io/sqlite/table.h \
src/datovka_shared/isds/account_interface.h \
src/datovka_shared/isds/box_interface.h \
src/datovka_shared/isds/error.h \
src/datovka_shared/isds/internal_conversion.h \
src/datovka_shared/isds/message_interface.h \
src/datovka_shared/isds/type_conversion.h \
......
/*
* Copyright (C) 2014-2018 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#include "src/datovka_shared/isds/account_interface.h"
/* Null objects - for convenience. */
static const QString nullString;
/*!
* @brief PIMPL Otp class.
*/
class Isds::OtpPrivate {
//Q_DISABLE_COPY(OtpPrivate)
public:
OtpPrivate(void)
: m_method(Type::OM_UNKNOWN), m_otpCode(),
m_resolution(Type::OR_UNKNOWN)
{ }
OtpPrivate &operator=(const OtpPrivate &other) Q_DECL_NOTHROW
{
m_method = other.m_method;
m_otpCode = other.m_otpCode;
m_resolution = other.m_resolution;
return *this;
}
bool operator==(const OtpPrivate &other) const
{
return (m_method == other.m_method) &&
(m_otpCode == other.m_otpCode) &&
(m_resolution == other.m_resolution);
}
/* Input members. */
enum Type::OtpMethod m_method; /*!< OTP authentication method to be used. */
QString m_otpCode; /*!<
* One-time password to use. Pass null value, if you
* don't know it yet (e.g. in case of first phase
* of the time-based OTP to request new code from
* ISDS.)
*/
/* Output members. */
enum Type::OtpResolution m_resolution; /*!<
* Fine-grade resolution of OTP
* authentication state description.
*/
};
Isds::Otp::Otp(void)
: d_ptr(Q_NULLPTR)
{
}
Isds::Otp::Otp(const Otp &other)
: d_ptr((other.d_func() != Q_NULLPTR) ? (new (std::nothrow) OtpPrivate) : Q_NULLPTR)
{
Q_D(Otp);
if (d == Q_NULLPTR) {
return;
}
*d = *other.d_func();
}
#ifdef Q_COMPILER_RVALUE_REFS
Isds::Otp::Otp(Otp &&other) Q_DECL_NOEXCEPT
: d_ptr(other.d_ptr.take()) //d_ptr(std::move(other.d_ptr))
{
}
#endif /* Q_COMPILER_RVALUE_REFS */
Isds::Otp::~Otp(void)
{
}
/*!
* @brief Ensures private OTP presence.
*
* @note Returns if private OTP could not be allocated.
*/
#define ensureOtpPrivate(_x_) \
do { \
if (Q_UNLIKELY(d_ptr == Q_NULLPTR)) { \
OtpPrivate *p = new (std::nothrow) OtpPrivate; \
if (Q_UNLIKELY(p == Q_NULLPTR)) { \
Q_ASSERT(0); \
return _x_; \
} \
d_ptr.reset(p); \
} \
} while (0)
Isds::Otp &Isds::Otp::operator=(const Otp &other) Q_DECL_NOTHROW
{
if (other.d_func() == Q_NULLPTR) {
d_ptr.reset(Q_NULLPTR);
return *this;
}
ensureOtpPrivate(*this);
Q_D(Otp);
*d = *other.d_func();
return *this;
}
#ifdef Q_COMPILER_RVALUE_REFS
Isds::Otp &Isds::Otp::operator=(Otp &&other) Q_DECL_NOTHROW
{
swap(*this, other);
return *this;
}
#endif /* Q_COMPILER_RVALUE_REFS */
bool Isds::Otp::operator==(const Otp &other) const
{
Q_D(const Otp);
if ((d == Q_NULLPTR) && ((other.d_func() == Q_NULLPTR))) {
return true;
} else if ((d == Q_NULLPTR) || ((other.d_func() == Q_NULLPTR))) {
return false;
}
return *d == *other.d_func();
}
bool Isds::Otp::operator!=(const Otp &other) const
{
return !operator==(other);
}
bool Isds::Otp::isNull(void) const
{
Q_D(const Otp);
return d == Q_NULLPTR;
}
enum Isds::Type::OtpMethod Isds::Otp::method(void) const
{
Q_D(const Otp);
if (Q_UNLIKELY(d == Q_NULLPTR)) {
return Type::OM_UNKNOWN;
}
return d->m_method;
}
void Isds::Otp::setMethod(enum Type::OtpMethod m)
{
ensureOtpPrivate();
Q_D(Otp);
d->m_method = m;
}
const QString &Isds::Otp::otpCode(void) const
{
Q_D(const Otp);
if (Q_UNLIKELY(d == Q_NULLPTR)) {
return nullString;
}
return d->m_otpCode;
}
void Isds::Otp::setOtpCode(const QString &oc)
{
ensureOtpPrivate();
Q_D(Otp);
d->m_otpCode = oc;
}
#ifdef Q_COMPILER_RVALUE_REFS
void Isds::Otp::setOtpCode(QString &&oc)
{
ensureOtpPrivate();
Q_D(Otp);
d->m_otpCode = oc;
}
#endif /* Q_COMPILER_RVALUE_REFS */
enum Isds::Type::OtpResolution Isds::Otp::resolution(void) const
{
Q_D(const Otp);
if (Q_UNLIKELY(d == Q_NULLPTR)) {
return Type::OR_UNKNOWN;
}
return d->m_resolution;
}
void Isds::Otp::setResolution(enum Type::OtpResolution r)
{
ensureOtpPrivate();
Q_D(Otp);
d->m_resolution = r;
}
void Isds::swap(Otp &first, Otp &second) Q_DECL_NOTHROW
{
using std::swap;
swap(first.d_ptr, second.d_ptr);
}
/*
* Copyright (C) 2014-2018 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#pragma once
#include <QScopedPointer>
#include <QString>
#include "src/datovka_shared/isds/types.h"
/*
* Structures based on from pril_2/ISDS_OTP_autentizace.pdf.
*/
namespace Isds {
class OtpPrivate;
/*!
* @brief One-time password authentication data.
*/
class Otp {
Q_DECLARE_PRIVATE(Otp)
public:
Otp(void);
Otp(const Otp &other);
#ifdef Q_COMPILER_RVALUE_REFS
Otp(Otp &&other) Q_DECL_NOEXCEPT;
#endif /* Q_COMPILER_RVALUE_REFS */
~Otp(void);
Otp &operator=(const Otp &other) Q_DECL_NOTHROW;
#ifdef Q_COMPILER_RVALUE_REFS
Otp &operator=(Otp &&other) Q_DECL_NOTHROW;
#endif /* Q_COMPILER_RVALUE_REFS */
bool operator==(const Otp &other) const;
bool operator!=(const Otp &other) const;
friend void swap(Otp &first, Otp &second) Q_DECL_NOTHROW;
bool isNull(void) const;
/* Authentication method. */
enum Type::OtpMethod method(void) const;
void setMethod(enum Type::OtpMethod m);
/* One-time password. */
const QString &otpCode(void) const;
void setOtpCode(const QString &oc);
#ifdef Q_COMPILER_RVALUE_REFS
void setOtpCode(QString &&oc);
#endif /* Q_COMPILER_RVALUE_REFS */
/* Resolution state. */
enum Type::OtpResolution resolution(void) const;
void setResolution(enum Type::OtpResolution r);
private:
QScopedPointer<OtpPrivate> d_ptr; // std::unique_ptr ?
};
void swap(Otp &first, Otp &second) Q_DECL_NOTHROW;
}
This diff is collapsed.
This diff is collapsed.
/*
* Copyright (C) 2014-2018 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#include "src/datovka_shared/isds/error.h"
static const QString nullString;
/*!
* @brief PIMPL Error class.
*/
class Isds::ErrorPrivate {
//Q_DISABLE_COPY(ErrorPrivate)
public:
ErrorPrivate(void)
: m_code(Type::ERR_SUCCESS), m_longDescr()
{ }
ErrorPrivate &operator=(const ErrorPrivate &other) Q_DECL_NOTHROW
{
m_code = other.m_code;
m_longDescr = other.m_longDescr;
return *this;
}
bool operator==(const ErrorPrivate &other) const
{
return (m_code == other.m_code) &&
(m_longDescr == other.m_longDescr);
}
enum Type::Error m_code;
QString m_longDescr;
};
Isds::Error::Error(void)
: d_ptr(Q_NULLPTR)
{
}
Isds::Error::Error(const Error &other)
: d_ptr((other.d_func() != Q_NULLPTR) ? (new (std::nothrow) ErrorPrivate) : Q_NULLPTR)
{
Q_D(Error);
if (d == Q_NULLPTR) {
return;
}
*d = *other.d_func();
}
#ifdef Q_COMPILER_RVALUE_REFS
Isds::Error::Error(Error &&other) Q_DECL_NOEXCEPT
: d_ptr(other.d_ptr.take()) //d_ptr(std::move(other.d_ptr))
{
}
#endif /* Q_COMPILER_RVALUE_REFS */
Isds::Error::~Error(void)
{
}
/*!
* @brief Ensures private error presence.
*
* @note Returns if private error could not be allocated.
*/
#define ensureErrorPrivate(_x_) \
do { \
if (Q_UNLIKELY(d_ptr == Q_NULLPTR)) { \
ErrorPrivate *p = new (std::nothrow) ErrorPrivate; \
if (Q_UNLIKELY(p == Q_NULLPTR)) { \
Q_ASSERT(0); \
return _x_; \
} \
d_ptr.reset(p); \
} \
} while (0)
Isds::Error &Isds::Error::operator=(const Error &other) Q_DECL_NOTHROW
{
if (other.d_func() == Q_NULLPTR) {
d_ptr.reset(Q_NULLPTR);
return *this;
}
ensureErrorPrivate(*this);
Q_D(Error);
*d = *other.d_func();
return *this;
}
#ifdef Q_COMPILER_RVALUE_REFS
Isds::Error &Isds::Error::operator=(Error &&other) Q_DECL_NOTHROW
{
swap(*this, other);
return *this;
}
#endif /* Q_COMPILER_RVALUE_REFS */
bool Isds::Error::operator==(const Error &other) const
{
Q_D(const Error);
if ((d == Q_NULLPTR) && ((other.d_func() == Q_NULLPTR))) {
return true;
} else if ((d == Q_NULLPTR) || ((other.d_func() == Q_NULLPTR))) {
return false;
}
return *d == *other.d_func();
}
bool Isds::Error::operator!=(const Error &other) const
{
return !operator==(other);
}
bool Isds::Error::isNull(void) const
{
Q_D(const Error);
return d == Q_NULLPTR;
}
enum Isds::Type::Error Isds::Error::code(void) const
{
Q_D(const Error);
if (Q_UNLIKELY(d == Q_NULLPTR)) {
return Type::ERR_SUCCESS;
}
return d->m_code;
}
void Isds::Error::setCode(enum Type::Error c)
{
ensureErrorPrivate();
Q_D(Error);
d->m_code = c;
}
const QString &Isds::Error::longDescr(void) const
{
Q_D(const Error);
if (Q_UNLIKELY(d == Q_NULLPTR)) {
return nullString;
}
return d->m_longDescr;
}
void Isds::Error::setLongDescr(const QString &ld)
{
ensureErrorPrivate();
Q_D(Error);
d->m_longDescr = ld;
}
#ifdef Q_COMPILER_RVALUE_REFS
void Isds::Error::setLongDescr(QString &&ld)
{
ensureErrorPrivate();
Q_D(Error);
d->m_longDescr = ld;
}
#endif /* Q_COMPILER_RVALUE_REFS */
void Isds::swap(Error &first, Error &second) Q_DECL_NOTHROW
{
using std::swap;
swap(first.d_ptr, second.d_ptr);
}
/*
* Copyright (C) 2014-2018 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#pragma once
#include <QScopedPointer>
#include <QString>
#include "src/datovka_shared/isds/types.h"
/*
* Encapsulates error structure as it is more or less used by libisds.
*/
namespace Isds {
class ErrorPrivate;
/*!
* @brief Describes an error situation as it may occur while
* communicating with ISDS.
*/
class Error {
Q_DECLARE_PRIVATE(Error)
public:
Error(void);
Error(const Error &other);
#ifdef Q_COMPILER_RVALUE_REFS
Error(Error &&other) Q_DECL_NOEXCEPT;
#endif /* Q_COMPILER_RVALUE_REFS */
~Error(void);
Error &operator=(const Error &other) Q_DECL_NOTHROW;
#ifdef Q_COMPILER_RVALUE_REFS
Error &operator=(Error &&other) Q_DECL_NOTHROW;
#endif /* Q_COMPILER_RVALUE_REFS */
bool operator==(const Error &other) const;
bool operator!=(const Error &other) const;
friend void swap(Error &first, Error &second) Q_DECL_NOTHROW;
bool isNull(void) const;
/* error code */
enum Type::Error code(void) const;
void setCode(enum Type::Error c);
/* long error description - detail */
const QString &longDescr(void) const;
void setLongDescr(const QString &ld);
#ifdef Q_COMPILER_RVALUE_REFS
void setLongDescr(QString &&ld);
#endif /* Q_COMPILER_RVALUE_REFS */
private:
QScopedPointer<ErrorPrivate> d_ptr; // std::unique_ptr ?
};
void swap(Error &first, Error &second) Q_DECL_NOTHROW;
}
......@@ -225,7 +225,7 @@ bool Isds::toLongInt(long int **cLongPtr, qint64 i)
return true;
}
enum Isds::Type::NilBool Isds::fromBool(const _Bool *cBoolPtr)
enum Isds::Type::NilBool Isds::fromBoolPtr(const _Bool *cBoolPtr)
{
if (cBoolPtr == NULL) {
return Type::BOOL_NULL;
......@@ -236,7 +236,7 @@ enum Isds::Type::NilBool Isds::fromBool(const _Bool *cBoolPtr)
}
}
bool Isds::toBool(_Bool **cBoolPtr, enum Type::NilBool nilBool)
bool Isds::toBoolPtr(_Bool **cBoolPtr, enum Type::NilBool nilBool)
{
if (Q_UNLIKELY(cBoolPtr == NULL)) {
Q_ASSERT(0);
......
......@@ -143,7 +143,7 @@ namespace Isds {
* @param[in] cBoolPtr Pointer to bool.
* @return Nullable bool enumeration type.
*/
enum Type::NilBool fromBool(const _Bool *cBoolPtr);
enum Type::NilBool fromBoolPtr(const _Bool *cBoolPtr);
/*!
* @brief Sets bool pointer according to supplied value.
......@@ -152,7 +152,7 @@ namespace Isds {
* @param[in] nilBool Nullable bool value.
* @return True on success, false in failure.
*/
bool toBool(_Bool **cBoolPtr, enum Type::NilBool nilBool);
bool toBoolPtr(_Bool **cBoolPtr, enum Type::NilBool nilBool);
/*!
* @brief Converts string to non-negative integer.
......
......@@ -87,8 +87,6 @@ namespace Isds {
void setValue(QByteArray &&v);
#endif /* Q_COMPILER_RVALUE_REFS */
friend Hash libisds2hash(const struct isds_hash *ih, bool *ok);
private:
QScopedPointer<HashPrivate> d_ptr; // std::unique_ptr ?
};
......@@ -144,9 +142,6 @@ namespace Isds {
static
const QString &type2string(enum Type::Event type);
friend Event libisds2event(const struct isds_event *ie,
bool *ok);
private:
QScopedPointer<EventPrivate> d_ptr; // std::unique_ptr ?
};
......@@ -396,9 +391,6 @@ namespace Isds {
static
QChar dmType2Char(enum Type::DmType t);
friend Envelope libisds2envelope(const struct isds_envelope *ie,
bool *ok);
private:
QScopedPointer<EnvelopePrivate> d_ptr; // std::unique_ptr ?
};
......@@ -482,9 +474,6 @@ namespace Isds {
void setFormat(QString &&f);
#endif /* Q_COMPILER_RVALUE_REFS */
friend Document libisds2document(const struct isds_document *id,
bool *ok);
private:
QScopedPointer<DocumentPrivate> d_ptr; // std::unique_ptr ?
};
......@@ -542,9 +531,6 @@ namespace Isds {
void setDocuments(QList<Document> &&dl);
#endif /* Q_COMPILER_RVALUE_REFS */
friend Message libisds2message(const struct isds_message *im,
bool *ok);
private:
QScopedPointer<MessagePrivate> d_ptr; // std::unique_ptr ?
};
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment