diff --git a/mobile-datovka.pro b/mobile-datovka.pro index eb2181a3abdd8a7ca3326ef04f1f373fb1fafc63..8f036bc2d248e1aa8a4d941a4f9baff2e79a4deb 100644 --- a/mobile-datovka.pro +++ b/mobile-datovka.pro @@ -93,6 +93,10 @@ 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/box_interface.cpp \ + src/datovka_shared/isds/internal_conversion.cpp \ + src/datovka_shared/isds/message_interface.cpp \ + src/datovka_shared/isds/type_conversion.cpp \ src/datovka_shared/localisation/localisation.cpp \ src/datovka_shared/records_management/conversion.cpp \ src/datovka_shared/records_management/io/records_management_connection.cpp \ @@ -117,6 +121,7 @@ SOURCES += \ src/global.cpp \ src/io/filesystem.cpp \ src/isds/isds_conversion.cpp \ + src/isds/isds_type_conversion.cpp \ src/locker.cpp \ src/log/log.cpp \ src/main.cpp \ @@ -131,7 +136,6 @@ SOURCES += \ src/net/isds_wrapper.cpp \ src/net/net_layer.cpp \ src/net/xml_layer.cpp \ - src/qml_interaction/attachment_data.cpp \ src/qml_interaction/image_provider.cpp \ src/qml_interaction/interaction_filesystem.cpp \ src/qml_interaction/interaction_zfo_file.cpp \ @@ -163,6 +167,15 @@ SOURCES += \ src/worker/task_records_management_stored_messages.cpp \ src/worker/task_send_message.cpp \ src/worker/task_send_sms.cpp \ + src/xml/xml_authenticate_message.cpp \ + src/xml/xml_base.cpp \ + src/xml/xml_download_delivery_info.cpp \ + src/xml/xml_download_message.cpp \ + src/xml/xml_download_message_author.cpp \ + src/xml/xml_download_message_list.cpp \ + src/xml/xml_mark_message_as_read.cpp \ + src/xml/xml_parse_zfo.cpp \ + src/xml/xml_send_message.cpp \ src/zfo.cpp HEADERS += \ @@ -175,6 +188,11 @@ 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/box_interface.h \ + src/datovka_shared/isds/internal_conversion.h \ + src/datovka_shared/isds/message_interface.h \ + src/datovka_shared/isds/type_conversion.h \ + src/datovka_shared/isds/types.h \ src/datovka_shared/localisation/localisation.h \ src/datovka_shared/records_management/conversion.h \ src/datovka_shared/records_management/io/records_management_connection.h \ @@ -198,8 +216,9 @@ HEADERS += \ src/files.h \ src/global.h \ src/io/db_tables.h \ - src/io/filesystem.h \ + src/io/filesystem.h \ src/isds/isds_conversion.h \ + src/isds/isds_type_conversion.h \ src/locker.h \ src/log/log.h \ src/messages.h \ @@ -214,7 +233,6 @@ HEADERS += \ src/net/isds_wrapper.h \ src/net/net_layer.h \ src/net/xml_layer.h \ - src/qml_interaction/attachment_data.h \ src/qml_interaction/image_provider.h \ src/qml_interaction/interaction_filesystem.h \ src/qml_interaction/interaction_zfo_file.h \ @@ -248,6 +266,15 @@ HEADERS += \ src/worker/task_records_management_stored_messages.h \ src/worker/task_send_message.h \ src/worker/task_send_sms.h \ + src/xml/xml_authenticate_message.h \ + src/xml/xml_base.h \ + src/xml/xml_download_delivery_info.h \ + src/xml/xml_download_message.h \ + src/xml/xml_download_message_author.h \ + src/xml/xml_download_message_list.h \ + src/xml/xml_mark_message_as_read.h \ + src/xml/xml_parse_zfo.h \ + src/xml/xml_send_message.h \ src/zfo.h android { diff --git a/src/auxiliaries/attachment_helper.cpp b/src/auxiliaries/attachment_helper.cpp index 9548af5ffc0c2c52aceb6fa6587b958c524b120f..97b509f35e8b56e3ed47805f2dd713618003d271 100644 --- a/src/auxiliaries/attachment_helper.cpp +++ b/src/auxiliaries/attachment_helper.cpp @@ -35,14 +35,13 @@ const QSet knowExp = QSet () << "odt" << "pdf" << "png" << "ppt" << "pptx" << "rtf" << "tiff" << "txt" << "wav" << "xls" << "xlsx" << "xml" << "zfo"; -QString getApproximatelyAttachmentFileSizeFromBase64(int base64Length) +QString approximateDataSize(int dataSize) { - QString str = ""; - base64Length = base64Length * 3 / 4; - if (base64Length >= 1000) { - str = "~" + QString::number(base64Length / 1000) + " kB" ; + QString str; + if (dataSize >= 1000) { + str = QLatin1String("~") + QString::number(dataSize / 1000) + QLatin1String(" kB"); } else { - str = "~" + QString::number(base64Length) + " B" ; + str = QLatin1String("~") + QString::number(dataSize) + QLatin1String(" B"); } return str; } diff --git a/src/auxiliaries/attachment_helper.h b/src/auxiliaries/attachment_helper.h index 0788364e8c1588d95e1866fab7b6f9d752c03c53..4fd0dd8f289de60e05512fd2b1573670593331a8 100644 --- a/src/auxiliaries/attachment_helper.h +++ b/src/auxiliaries/attachment_helper.h @@ -21,18 +21,17 @@ * the two. */ -#ifndef _ATTACHMENT_HELPER_H_ -#define _ATTACHMENT_HELPER_H_ +#pragma once #include /*! - * @brief Get aproximatle attachment file size from base64 length. + * @brief Get approximate data chunk size from supplied data size. * - * @param[in] base64Length Base64 content length. - * @return Aproximatle file size string. + * @param[in] dataSize Actual data size. + * @return Approximate data size including the unit. */ -QString getApproximatelyAttachmentFileSizeFromBase64(int base64Length); +QString approximateDataSize(int dataSize); /*! * @brief Get attachment icon from attachment file extension. @@ -41,5 +40,3 @@ QString getApproximatelyAttachmentFileSizeFromBase64(int base64Length); * @return Attachment icon filename string. */ QString getAttachmentFileIconFromFileExtension(const QString &fileName); - -#endif /* _ATTACHMENT_HELPER_H_ */ diff --git a/src/datovka_shared/isds/box_interface.cpp b/src/datovka_shared/isds/box_interface.cpp new file mode 100644 index 0000000000000000000000000000000000000000..337d5ab763e60e8cf2090ecfe33cfed5c2fa88aa --- /dev/null +++ b/src/datovka_shared/isds/box_interface.cpp @@ -0,0 +1,1776 @@ +/* + * 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 . + * + * 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 /* std::move */ + +#include "src/datovka_shared/isds/box_interface.h" + +/* Null objects - for convenience. */ +static const Isds::Address nullAddress; +static const Isds::BirthInfo nullBirthInfo; +static const Isds::PersonName nullPersonName; +static const QDate nullDate; +static const QString nullString; + +/*! + * @brief PIMPL Address class. + */ +class Isds::AddressPrivate { + //Q_DISABLE_COPY(AddressPrivate) +public: + AddressPrivate(void) + : m_adCity()/*, m_adDistrict() */, m_adStreet(), + m_adNumberInStreet(), m_adNumberInMunicipality(), + m_adZipCode(), m_adState()/*, m_adAMCode(-1) */ + { } + + AddressPrivate &operator=(const AddressPrivate &other) Q_DECL_NOTHROW + { + m_adCity = other.m_adCity; + //m_adDistrict = other.m_adDistrict; + m_adStreet = other.m_adStreet; + m_adNumberInStreet = other.m_adNumberInStreet; + m_adNumberInMunicipality = other.m_adNumberInMunicipality; + m_adZipCode = other.m_adZipCode; + m_adState = other.m_adState; + //m_adAMCode = other.m_adAMCode; + + return *this; + } + + bool operator==(const AddressPrivate &other) const + { + return (m_adCity == other.m_adCity) && + // (m_adDistrict == other.m_adDistrict) && + (m_adStreet == other.m_adStreet) && + (m_adNumberInStreet == other.m_adNumberInStreet) && + (m_adNumberInMunicipality == other.m_adNumberInMunicipality) && + (m_adZipCode == other.m_adZipCode) && + (m_adState == other.m_adState); + // (m_adAMCode == other.m_adAMCode); + } + + QString m_adCity; + //QString m_adDistrict; /* Not present in libisds-0.10.7. Optional, used in extended structure versions. */ + QString m_adStreet; + QString m_adNumberInStreet; + QString m_adNumberInMunicipality; + QString m_adZipCode; + QString m_adState; + //qint64 m_adAMCode; /* + // * Not present in libisds-0.10.7. + // * AM (adresni misto) code according to RUIAN (Registr uzemni identifikace, adres a nemovitosti) + // * It's a number code. + // * Optional, used in extended structure versions. + // */ +}; + +Isds::Address::Address(void) + : d_ptr(Q_NULLPTR) +{ +} + +Isds::Address::Address(const Address &other) + : d_ptr((other.d_func() != Q_NULLPTR) ? (new (std::nothrow) AddressPrivate) : Q_NULLPTR) +{ + Q_D(Address); + if (d == Q_NULLPTR) { + return; + } + + *d = *other.d_func(); +} + +#ifdef Q_COMPILER_RVALUE_REFS +Isds::Address::Address(Address &&other) Q_DECL_NOEXCEPT + : d_ptr(other.d_ptr.take()) //d_ptr(std::move(other.d_ptr)) +{ +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +Isds::Address::~Address(void) +{ +} + +/*! + * @brief Ensures private address presence. + * + * @note Returns if private address could not be allocated. + */ +#define ensureAddressPrivate(_x_) \ + do { \ + if (Q_UNLIKELY(d_ptr == Q_NULLPTR)) { \ + AddressPrivate *p = new (std::nothrow) AddressPrivate; \ + if (Q_UNLIKELY(p == Q_NULLPTR)) { \ + Q_ASSERT(0); \ + return _x_; \ + } \ + d_ptr.reset(p); \ + } \ + } while (0) + +Isds::Address &Isds::Address::operator=(const Address &other) Q_DECL_NOTHROW +{ + if (other.d_func() == Q_NULLPTR) { + d_ptr.reset(Q_NULLPTR); + return *this; + } + ensureAddressPrivate(*this); + Q_D(Address); + + *d = *other.d_func(); + + return *this; +} + +#ifdef Q_COMPILER_RVALUE_REFS +Isds::Address &Isds::Address::operator=(Address &&other) Q_DECL_NOTHROW +{ + swap(*this, other); + return *this; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +bool Isds::Address::operator==(const Address &other) const +{ + Q_D(const Address); + 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::Address::operator!=(const Address &other) const +{ + return !operator==(other); +} + +bool Isds::Address::isNull(void) const +{ + Q_D(const Address); + return d == Q_NULLPTR; +} + +const QString &Isds::Address::city(void) const +{ + Q_D(const Address); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_adCity; +} + +void Isds::Address::setCity(const QString &c) +{ + ensureAddressPrivate(); + Q_D(Address); + d->m_adCity = c; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Address::setCity(QString &&c) +{ + ensureAddressPrivate(); + Q_D(Address); + d->m_adCity = c; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::Address::street(void) const +{ + Q_D(const Address); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_adStreet; +} + +void Isds::Address::setStreet(const QString &s) +{ + ensureAddressPrivate(); + Q_D(Address); + d->m_adStreet = s; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Address::setStreet(QString &&s) +{ + ensureAddressPrivate(); + Q_D(Address); + d->m_adStreet = s; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::Address::numberInStreet(void) const +{ + Q_D(const Address); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_adNumberInStreet; +} + +void Isds::Address::setNumberInStreet(const QString &nis) +{ + ensureAddressPrivate(); + Q_D(Address); + d->m_adNumberInStreet = nis; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Address::setNumberInStreet(QString &&nis) +{ + ensureAddressPrivate(); + Q_D(Address); + d->m_adNumberInStreet = nis; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::Address::numberInMunicipality(void) const +{ + Q_D(const Address); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_adNumberInMunicipality; +} + +void Isds::Address::setNumberInMunicipality(const QString &nim) +{ + ensureAddressPrivate(); + Q_D(Address); + d->m_adNumberInMunicipality = nim; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Address::setNumberInMunicipality(QString &&nim) +{ + ensureAddressPrivate(); + Q_D(Address); + d->m_adNumberInMunicipality = nim; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::Address::zipCode(void) const +{ + Q_D(const Address); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_adZipCode; +} + +void Isds::Address::setZipCode(const QString &zc) +{ + ensureAddressPrivate(); + Q_D(Address); + d->m_adZipCode = zc; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Address::setZipCode(QString &&zc) +{ + ensureAddressPrivate(); + Q_D(Address); + d->m_adZipCode = zc; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::Address::state(void) const +{ + Q_D(const Address); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_adState; +} + +void Isds::Address::setState(const QString &s) +{ + ensureAddressPrivate(); + Q_D(Address); + d->m_adState = s; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Address::setState(QString &&s) +{ + ensureAddressPrivate(); + Q_D(Address); + d->m_adState = s; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +void Isds::swap(Address &first, Address &second) Q_DECL_NOTHROW +{ + using std::swap; + swap(first.d_ptr, second.d_ptr); +} + +/*! + * @brief PIMPL BirthInfo class. + */ +class Isds::BirthInfoPrivate { + //Q_DISABLE_COPY(BirthInfoPrivate) +public: + BirthInfoPrivate(void) + : m_biDate(), m_biCity(), m_biCounty(), m_biState() + { } + + BirthInfoPrivate &operator=(const BirthInfoPrivate &other) Q_DECL_NOTHROW + { + m_biDate = other.m_biDate; + m_biCity = other.m_biCity; + m_biCounty = other.m_biCounty; + m_biState = other.m_biState; + + return *this; + } + + bool operator==(const BirthInfoPrivate &other) const + { + return (m_biDate == other.m_biDate) && + (m_biCity == other.m_biCity) && + (m_biCounty == other.m_biCounty) && + (m_biState == other.m_biState); + } + + QDate m_biDate; + QString m_biCity; + QString m_biCounty; + QString m_biState; +}; + +Isds::BirthInfo::BirthInfo(void) + : d_ptr(Q_NULLPTR) +{ +} + +Isds::BirthInfo::BirthInfo(const BirthInfo &other) + : d_ptr((other.d_func() != Q_NULLPTR) ? (new (std::nothrow) BirthInfoPrivate) : Q_NULLPTR) +{ + Q_D(BirthInfo); + if (d == Q_NULLPTR) { + return; + } + + *d = *other.d_func(); +} + +#ifdef Q_COMPILER_RVALUE_REFS +Isds::BirthInfo::BirthInfo(BirthInfo &&other) Q_DECL_NOEXCEPT + : d_ptr(other.d_ptr.take()) //d_ptr(std::move(other.d_ptr)) +{ +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +Isds::BirthInfo::~BirthInfo(void) +{ +} + +/*! + * @brief Ensures private birth info presence. + * + * @note Returns if private birth info could not be allocated. + */ +#define ensureBirthInfoPrivate(_x_) \ + do { \ + if (Q_UNLIKELY(d_ptr == Q_NULLPTR)) { \ + BirthInfoPrivate *p = new (std::nothrow) BirthInfoPrivate; \ + if (Q_UNLIKELY(p == Q_NULLPTR)) { \ + Q_ASSERT(0); \ + return _x_; \ + } \ + d_ptr.reset(p); \ + } \ + } while (0) + +Isds::BirthInfo &Isds::BirthInfo::operator=(const BirthInfo &other) Q_DECL_NOTHROW +{ + if (other.d_func() == Q_NULLPTR) { + d_ptr.reset(Q_NULLPTR); + return *this; + } + ensureBirthInfoPrivate(*this); + Q_D(BirthInfo); + + *d = *other.d_func(); + + return *this; +} + +#ifdef Q_COMPILER_RVALUE_REFS +Isds::BirthInfo &Isds::BirthInfo::operator=(BirthInfo &&other) Q_DECL_NOTHROW +{ + swap(*this, other); + return *this; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +bool Isds::BirthInfo::operator==(const BirthInfo &other) const +{ + Q_D(const BirthInfo); + 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::BirthInfo::operator!=(const BirthInfo &other) const +{ + return !operator==(other); +} + +bool Isds::BirthInfo::isNull(void) const +{ + Q_D(const BirthInfo); + return d == Q_NULLPTR; +} + +const QDate &Isds::BirthInfo::date(void) const +{ + Q_D(const BirthInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullDate; + } + + return d->m_biDate; +} + +void Isds::BirthInfo::setDate(const QDate &bd) +{ + ensureBirthInfoPrivate(); + Q_D(BirthInfo); + d->m_biDate = bd; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::BirthInfo::setDate(QDate &&bd) +{ + ensureBirthInfoPrivate(); + Q_D(BirthInfo); + d->m_biDate = bd; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::BirthInfo::city(void) const +{ + Q_D(const BirthInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_biCity; +} + +void Isds::BirthInfo::setCity(const QString &c) +{ + ensureBirthInfoPrivate(); + Q_D(BirthInfo); + d->m_biCity = c; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::BirthInfo::setCity(QString &&c) +{ + ensureBirthInfoPrivate(); + Q_D(BirthInfo); + d->m_biCity = c; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::BirthInfo::county(void) const +{ + Q_D(const BirthInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_biCounty; +} + +void Isds::BirthInfo::setCounty(const QString &c) +{ + ensureBirthInfoPrivate(); + Q_D(BirthInfo); + d->m_biCounty = c; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::BirthInfo::setCounty(QString &&c) +{ + ensureBirthInfoPrivate(); + Q_D(BirthInfo); + d->m_biCounty = c; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::BirthInfo::state(void) const +{ + Q_D(const BirthInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_biState; +} + +void Isds::BirthInfo::setState(const QString &s) +{ + ensureBirthInfoPrivate(); + Q_D(BirthInfo); + d->m_biState = s; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::BirthInfo::setState(QString &&s) +{ + ensureBirthInfoPrivate(); + Q_D(BirthInfo); + d->m_biState = s; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +void Isds::swap(BirthInfo &first, BirthInfo &second) Q_DECL_NOTHROW +{ + using std::swap; + swap(first.d_ptr, second.d_ptr); +} + +/*! + * @brief PIMPL PersonName class. + */ +class Isds::PersonNamePrivate { + //Q_DISABLE_COPY(PersonNamePrivate) +public: + PersonNamePrivate(void) + : m_pnFirstName(), m_pnMiddleName(), m_pnLastName(), + m_pnLastNameAtBirth() + { } + + PersonNamePrivate &operator=(const PersonNamePrivate &other) Q_DECL_NOTHROW + { + m_pnFirstName = other.m_pnFirstName; + m_pnMiddleName = other.m_pnMiddleName; + m_pnLastName = other.m_pnLastName; + m_pnLastNameAtBirth = other.m_pnLastNameAtBirth; + + return *this; + } + + bool operator==(const PersonNamePrivate &other) const + { + return (m_pnFirstName == other.m_pnFirstName) && + (m_pnMiddleName == other.m_pnMiddleName) && + (m_pnLastName == other.m_pnLastName) && + (m_pnLastNameAtBirth == other.m_pnLastNameAtBirth); + } + + QString m_pnFirstName; + QString m_pnMiddleName; + QString m_pnLastName; + QString m_pnLastNameAtBirth; +}; + +Isds::PersonName::PersonName(void) + : d_ptr(Q_NULLPTR) +{ +} + +Isds::PersonName::PersonName(const PersonName &other) + : d_ptr((other.d_func() != Q_NULLPTR) ? (new (std::nothrow) PersonNamePrivate) : Q_NULLPTR) +{ + Q_D(PersonName); + if (d == Q_NULLPTR) { + return; + } + + *d = *other.d_func(); +} + +#ifdef Q_COMPILER_RVALUE_REFS +Isds::PersonName::PersonName(PersonName &&other) Q_DECL_NOEXCEPT + : d_ptr(other.d_ptr.take()) //d_ptr(std::move(other.d_ptr)) +{ +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +Isds::PersonName::~PersonName(void) +{ +} + +/*! + * @brief Ensures private person name presence. + * + * @note Returns if private person name could not be allocated. + */ +#define ensurePersonNamePrivate(_x_) \ + do { \ + if (Q_UNLIKELY(d_ptr == Q_NULLPTR)) { \ + PersonNamePrivate *p = new (std::nothrow) PersonNamePrivate; \ + if (Q_UNLIKELY(p == Q_NULLPTR)) { \ + Q_ASSERT(0); \ + return _x_; \ + } \ + d_ptr.reset(p); \ + } \ + } while (0) + +Isds::PersonName &Isds::PersonName::operator=(const PersonName &other) Q_DECL_NOTHROW +{ + if (other.d_func() == Q_NULLPTR) { + d_ptr.reset(Q_NULLPTR); + return *this; + } + ensurePersonNamePrivate(*this); + Q_D(PersonName); + + *d = *other.d_func(); + + return *this; +} + +#ifdef Q_COMPILER_RVALUE_REFS +Isds::PersonName &Isds::PersonName::operator=(PersonName &&other) Q_DECL_NOTHROW +{ + swap(*this, other); + return *this; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +bool Isds::PersonName::operator==(const PersonName &other) const +{ + Q_D(const PersonName); + 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::PersonName::operator!=(const PersonName &other) const +{ + return !operator==(other); +} + +bool Isds::PersonName::isNull(void) const +{ + Q_D(const PersonName); + return d == Q_NULLPTR; +} + +const QString &Isds::PersonName::firstName(void) const +{ + Q_D(const PersonName); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_pnFirstName; +} + +void Isds::PersonName::setFirstName(const QString &fn) +{ + ensurePersonNamePrivate(); + Q_D(PersonName); + d->m_pnFirstName = fn; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::PersonName::setFirstName(QString &&fn) +{ + ensurePersonNamePrivate(); + Q_D(PersonName); + d->m_pnFirstName = fn; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::PersonName::middleName(void) const +{ + Q_D(const PersonName); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_pnMiddleName; +} + +void Isds::PersonName::setMiddleName(const QString &mn) +{ + ensurePersonNamePrivate(); + Q_D(PersonName); + d->m_pnMiddleName = mn; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::PersonName::setMiddleName(QString &&mn) +{ + ensurePersonNamePrivate(); + Q_D(PersonName); + d->m_pnMiddleName = mn; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::PersonName::lastName(void) const +{ + Q_D(const PersonName); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_pnLastName; +} + +void Isds::PersonName::setLastName(const QString &ln) +{ + ensurePersonNamePrivate(); + Q_D(PersonName); + d->m_pnLastName = ln; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::PersonName::setLastName(QString &&ln) +{ + ensurePersonNamePrivate(); + Q_D(PersonName); + d->m_pnLastName = ln; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::PersonName::lastNameAtBirth(void) const +{ + Q_D(const PersonName); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_pnLastNameAtBirth; +} + +void Isds::PersonName::setLastNameAtBirth(const QString &lnab) +{ + ensurePersonNamePrivate(); + Q_D(PersonName); + d->m_pnLastNameAtBirth = lnab; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::PersonName::setLastNameAtBirth(QString &&lnab) +{ + ensurePersonNamePrivate(); + Q_D(PersonName); + d->m_pnLastNameAtBirth = lnab; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +void Isds::swap(PersonName &first, PersonName &second) Q_DECL_NOTHROW +{ + using std::swap; + swap(first.d_ptr, second.d_ptr); +} + +/*! + * @brief PIMPL DbOwnerInfo class. + */ +class Isds::DbOwnerInfoPrivate { + //Q_DISABLE_COPY(DbOwnerInfoPrivate) +public: + DbOwnerInfoPrivate(void) + : m_dbID(), m_dbType(Type::BT_NULL), m_ic(), m_personName(), + m_firmName(), m_birthInfo(), m_address(), m_nationality(), + m_email(), m_telNumber(), m_identifier(), m_registryCode(), + m_dbState(Type::BS_ERROR), + m_dbEffectiveOVM(Type::BOOL_NULL), + m_dbOpenAddressing(Type::BOOL_NULL) + { } + + DbOwnerInfoPrivate &operator=(const DbOwnerInfoPrivate &other) Q_DECL_NOTHROW + { + m_dbID = other.m_dbID; + m_dbType = other.m_dbType; + m_ic = other.m_ic; + m_personName = other.m_personName; + m_firmName = other.m_firmName; + m_birthInfo = other.m_birthInfo; + m_address = other.m_address; + m_nationality = other.m_nationality; + m_email = other.m_email; + m_telNumber = other.m_telNumber; + m_identifier = other.m_identifier; + m_registryCode = other.m_registryCode; + m_dbState = other.m_dbState; + m_dbEffectiveOVM = other.m_dbEffectiveOVM; + m_dbOpenAddressing = other.m_dbOpenAddressing; + + return *this; + } + + bool operator==(const DbOwnerInfoPrivate &other) const + { + return (m_dbID == other.m_dbID) && + (m_dbType == other.m_dbType) && + (m_ic == other.m_ic) && + (m_personName == other.m_personName) && + (m_firmName == other.m_firmName) && + (m_birthInfo == other.m_birthInfo) && + (m_address == other.m_address) && + (m_nationality == other.m_nationality) && + (m_email == other.m_email) && + (m_telNumber == other.m_telNumber) && + (m_identifier == other.m_identifier) && + (m_registryCode == other.m_registryCode) && + (m_dbState == other.m_dbState) && + (m_dbEffectiveOVM == other.m_dbEffectiveOVM) && + (m_dbOpenAddressing == other.m_dbOpenAddressing); + } + + QString m_dbID; + enum Type::DbType m_dbType; + QString m_ic; + PersonName m_personName; + QString m_firmName; + BirthInfo m_birthInfo; + Address m_address; + QString m_nationality; + QString m_email; + QString m_telNumber; + QString m_identifier; + QString m_registryCode; + enum Type::DbState m_dbState; + enum Type::NilBool m_dbEffectiveOVM; + enum Type::NilBool m_dbOpenAddressing; +}; + +Isds::DbOwnerInfo::DbOwnerInfo(void) + : d_ptr(Q_NULLPTR) +{ +} + +Isds::DbOwnerInfo::DbOwnerInfo(const DbOwnerInfo &other) + : d_ptr((other.d_func() != Q_NULLPTR) ? (new (std::nothrow) DbOwnerInfoPrivate) : Q_NULLPTR) +{ + Q_D(DbOwnerInfo); + if (d == Q_NULLPTR) { + return; + } + + *d = *other.d_func(); +} + +#ifdef Q_COMPILER_RVALUE_REFS +Isds::DbOwnerInfo::DbOwnerInfo(DbOwnerInfo &&other) Q_DECL_NOEXCEPT + : d_ptr(other.d_ptr.take()) //d_ptr(std::move(other.d_ptr)) +{ +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +Isds::DbOwnerInfo::~DbOwnerInfo(void) +{ +} + +/*! + * @brief Ensures private box owner info info presence. + * + * @note Returns if private box owner info could not be allocated. + */ +#define ensureDbOwnerInfoPrivate(_x_) \ + do { \ + if (Q_UNLIKELY(d_ptr == Q_NULLPTR)) { \ + DbOwnerInfoPrivate *p = new (std::nothrow) DbOwnerInfoPrivate; \ + if (Q_UNLIKELY(p == Q_NULLPTR)) { \ + Q_ASSERT(0); \ + return _x_; \ + } \ + d_ptr.reset(p); \ + } \ + } while (0) + +Isds::DbOwnerInfo &Isds::DbOwnerInfo::operator=(const DbOwnerInfo &other) Q_DECL_NOTHROW +{ + if (other.d_func() == Q_NULLPTR) { + d_ptr.reset(Q_NULLPTR); + return *this; + } + ensureDbOwnerInfoPrivate(*this); + Q_D(DbOwnerInfo); + + *d = *other.d_func(); + + return *this; +} + +#ifdef Q_COMPILER_RVALUE_REFS +Isds::DbOwnerInfo &Isds::DbOwnerInfo::operator=(DbOwnerInfo &&other) Q_DECL_NOTHROW +{ + swap(*this, other); + return *this; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +bool Isds::DbOwnerInfo::operator==(const DbOwnerInfo &other) const +{ + Q_D(const DbOwnerInfo); + 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::DbOwnerInfo::operator!=(const DbOwnerInfo &other) const +{ + return !operator==(other); +} + +bool Isds::DbOwnerInfo::isNull(void) const +{ + Q_D(const DbOwnerInfo); + return d == Q_NULLPTR; +} + +const QString &Isds::DbOwnerInfo::dbID(void) const +{ + Q_D(const DbOwnerInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_dbID; +} + +void Isds::DbOwnerInfo::setDbID(const QString &bi) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_dbID = bi; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::DbOwnerInfo::setDbID(QString &&bi) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_dbID = bi; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +enum Isds::Type::DbType Isds::DbOwnerInfo::dbType(void) const +{ + Q_D(const DbOwnerInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return Type::BT_NULL; + } + + return d->m_dbType; +} + +void Isds::DbOwnerInfo::setDbType(enum Type::DbType bt) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_dbType = bt; +} + +const QString &Isds::DbOwnerInfo::ic(void) const +{ + Q_D(const DbOwnerInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_ic; +} + +void Isds::DbOwnerInfo::setIc(const QString &ic) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_ic = ic; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::DbOwnerInfo::setIc(QString &&ic) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_ic = ic; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const Isds::PersonName &Isds::DbOwnerInfo::personName(void) const +{ + Q_D(const DbOwnerInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullPersonName; + } + + return d->m_personName; +} + +void Isds::DbOwnerInfo::setPersonName(const PersonName &pn) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_personName = pn; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::DbOwnerInfo::setPersonName(PersonName &&pn) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_personName = pn; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::DbOwnerInfo::firmName(void) const +{ + Q_D(const DbOwnerInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_firmName; +} + +void Isds::DbOwnerInfo::setFirmName(const QString &fn) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_firmName = fn; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::DbOwnerInfo::setFirmName(QString &&fn) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_firmName = fn; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const Isds::BirthInfo &Isds::DbOwnerInfo::birthInfo(void) const +{ + Q_D(const DbOwnerInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullBirthInfo; + } + + return d->m_birthInfo; +} + +void Isds::DbOwnerInfo::setBirthInfo(const BirthInfo &bi) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_birthInfo = bi; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::DbOwnerInfo::setBirthInfo(BirthInfo &&bi) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_birthInfo = bi; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const Isds::Address &Isds::DbOwnerInfo::address(void) const +{ + Q_D(const DbOwnerInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullAddress; + } + + return d->m_address; +} + +void Isds::DbOwnerInfo::setAddress(const Address &a) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_address = a; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::DbOwnerInfo::setAddress(Address &&a) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_address = a; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::DbOwnerInfo::nationality(void) const +{ + Q_D(const DbOwnerInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_nationality; +} + +void Isds::DbOwnerInfo::setNationality(const QString &n) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_nationality = n; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::DbOwnerInfo::setNationality(QString &&n) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_nationality = n; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::DbOwnerInfo::email(void) const +{ + Q_D(const DbOwnerInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_email; +} + +void Isds::DbOwnerInfo::setEmail(const QString &e) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_email = e; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::DbOwnerInfo::setEmail(QString &&e) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_email = e; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::DbOwnerInfo::telNumber(void) const +{ + Q_D(const DbOwnerInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_telNumber; +} + +void Isds::DbOwnerInfo::setTelNumber(const QString &tn) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_telNumber = tn; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::DbOwnerInfo::setTelNumber(QString &&tn) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_telNumber = tn; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::DbOwnerInfo::identifier(void) const +{ + Q_D(const DbOwnerInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_identifier; +} + +void Isds::DbOwnerInfo::setIdentifier(const QString &i) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_identifier = i; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::DbOwnerInfo::setIdentifier(QString &&i) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_identifier = i; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::DbOwnerInfo::registryCode(void) const +{ + Q_D(const DbOwnerInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_registryCode; +} + +void Isds::DbOwnerInfo::setRegistryCode(const QString &rc) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_registryCode = rc; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::DbOwnerInfo::setRegistryCode(QString &&rc) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_registryCode = rc; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +enum Isds::Type::DbState Isds::DbOwnerInfo::dbState(void) const +{ + Q_D(const DbOwnerInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return Type::BS_ERROR; + } + + return d->m_dbState; +} + +void Isds::DbOwnerInfo::setDbState(enum Type::DbState bs) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_dbState = bs; +} + +enum Isds::Type::NilBool Isds::DbOwnerInfo::dbEffectiveOVM(void) const +{ + Q_D(const DbOwnerInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return Type::BOOL_NULL; + } + + return d->m_dbEffectiveOVM; +} + +void Isds::DbOwnerInfo::setDbEffectiveOVM(enum Type::NilBool eo) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_dbEffectiveOVM = eo; +} + +enum Isds::Type::NilBool Isds::DbOwnerInfo::dbOpenAddressing(void) const +{ + Q_D(const DbOwnerInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return Type::BOOL_NULL; + } + + return d->m_dbOpenAddressing; +} + +void Isds::DbOwnerInfo::setDbOpenAddressing(enum Type::NilBool oa) +{ + ensureDbOwnerInfoPrivate(); + Q_D(DbOwnerInfo); + d->m_dbOpenAddressing = oa; +} + +void Isds::swap(DbOwnerInfo &first, DbOwnerInfo &second) Q_DECL_NOTHROW +{ + using std::swap; + swap(first.d_ptr, second.d_ptr); +} + +/*! + * @brief PIMPL DbUserInfo class. + */ +class Isds::DbUserInfoPrivate { + //Q_DISABLE_COPY(DbUserInfoPrivate) +public: + DbUserInfoPrivate(void) + : m_personName(), m_address(), m_biDate(), m_userID(), + m_userType(Type::UT_NULL), m_userPrivils(Type::PRIVIL_NONE), + m_ic(), m_firmName(), m_caStreet(), m_caCity(), m_caZipCode(), + m_caState() + { } + + DbUserInfoPrivate &operator=(const DbUserInfoPrivate &other) Q_DECL_NOTHROW + { + m_personName = other.m_personName; + m_address = other.m_address; + m_biDate = other.m_biDate; + m_userID = other.m_userID; + m_userType = other.m_userType; + m_userPrivils = other.m_userPrivils; + m_ic = other.m_ic; + m_firmName = other.m_firmName; + m_caStreet = other.m_caStreet; + m_caCity = other.m_caCity; + m_caZipCode = other.m_caZipCode; + m_caState = other.m_caState; + + return *this; + } + + bool operator==(const DbUserInfoPrivate &other) const + { + return (m_personName == other.m_personName) && + (m_address == other.m_address) && + (m_biDate == other.m_biDate) && + (m_userID == other.m_userID) && + (m_userType == other.m_userType) && + (m_userPrivils == other.m_userPrivils) && + (m_ic == other.m_ic) && + (m_firmName == other.m_firmName) && + (m_caStreet == other.m_caStreet) && + (m_caCity == other.m_caCity) && + (m_caZipCode == other.m_caZipCode) && + (m_caState == other.m_caState); + } + + PersonName m_personName; + Address m_address; + QDate m_biDate; + QString m_userID; + enum Type::UserType m_userType; + Type::Privileges m_userPrivils; + QString m_ic; + QString m_firmName; + QString m_caStreet; + QString m_caCity; + QString m_caZipCode; + QString m_caState; + //QString m_aifoTicket; /* Not present in libisds-0.10.7. */ +}; + +Isds::DbUserInfo::DbUserInfo(void) + : d_ptr(Q_NULLPTR) +{ +} + +Isds::DbUserInfo::DbUserInfo(const DbUserInfo &other) + : d_ptr((other.d_func() != Q_NULLPTR) ? (new (std::nothrow) DbUserInfoPrivate) : Q_NULLPTR) +{ + Q_D(DbUserInfo); + if (d == Q_NULLPTR) { + return; + } + + *d = *other.d_func(); +} + +#ifdef Q_COMPILER_RVALUE_REFS +Isds::DbUserInfo::DbUserInfo(DbUserInfo &&other) Q_DECL_NOEXCEPT + : d_ptr(other.d_ptr.take()) //d_ptr(std::move(other.d_ptr)) +{ +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +Isds::DbUserInfo::~DbUserInfo(void) +{ +} + +/*! + * @brief Ensures private box user info info presence. + * + * @note Returns if private box user info could not be allocated. + */ +#define ensureDbUserInfoPrivate(_x_) \ + do { \ + if (Q_UNLIKELY(d_ptr == Q_NULLPTR)) { \ + DbUserInfoPrivate *p = new (std::nothrow) DbUserInfoPrivate; \ + if (Q_UNLIKELY(p == Q_NULLPTR)) { \ + Q_ASSERT(0); \ + return _x_; \ + } \ + d_ptr.reset(p); \ + } \ + } while (0) + +Isds::DbUserInfo &Isds::DbUserInfo::operator=(const DbUserInfo &other) Q_DECL_NOTHROW +{ + if (other.d_func() == Q_NULLPTR) { + d_ptr.reset(Q_NULLPTR); + return *this; + } + ensureDbUserInfoPrivate(*this); + Q_D(DbUserInfo); + + *d = *other.d_func(); + + return *this; +} + +#ifdef Q_COMPILER_RVALUE_REFS +Isds::DbUserInfo &Isds::DbUserInfo::operator=(DbUserInfo &&other) Q_DECL_NOTHROW +{ + swap(*this, other); + return *this; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +bool Isds::DbUserInfo::operator==(const DbUserInfo &other) const +{ + Q_D(const DbUserInfo); + 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::DbUserInfo::operator!=(const DbUserInfo &other) const +{ + return !operator==(other); +} + +bool Isds::DbUserInfo::isNull(void) const +{ + Q_D(const DbUserInfo); + return d == Q_NULLPTR; +} + +const Isds::PersonName &Isds::DbUserInfo::personName(void) const +{ + Q_D(const DbUserInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullPersonName; + } + + return d->m_personName; +} + +void Isds::DbUserInfo::setPersonName(const PersonName &pn) +{ + ensureDbUserInfoPrivate(); + Q_D(DbUserInfo); + d->m_personName = pn; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::DbUserInfo::setPersonName(PersonName &&pn) +{ + ensureDbUserInfoPrivate(); + Q_D(DbUserInfo); + d->m_personName = pn; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const Isds::Address &Isds::DbUserInfo::address(void) const +{ + Q_D(const DbUserInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullAddress; + } + + return d->m_address; +} + +void Isds::DbUserInfo::setAddress(const Address &a) +{ + ensureDbUserInfoPrivate(); + Q_D(DbUserInfo); + d->m_address = a; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::DbUserInfo::setAddress(Address &&a) +{ + ensureDbUserInfoPrivate(); + Q_D(DbUserInfo); + d->m_address = a; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QDate &Isds::DbUserInfo::biDate(void) const +{ + Q_D(const DbUserInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullDate; + } + + return d->m_biDate; +} + +void Isds::DbUserInfo::setBiDate(const QDate &bd) +{ + ensureDbUserInfoPrivate(); + Q_D(DbUserInfo); + d->m_biDate = bd; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::DbUserInfo::setBiDate(QDate &&bd) +{ + ensureDbUserInfoPrivate(); + Q_D(DbUserInfo); + d->m_biDate = bd; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::DbUserInfo::userID(void) const +{ + Q_D(const DbUserInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_userID; +} + +void Isds::DbUserInfo::setUserId(const QString &uid) +{ + ensureDbUserInfoPrivate(); + Q_D(DbUserInfo); + d->m_userID = uid; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::DbUserInfo::setUserId(QString &&uid) +{ + ensureDbUserInfoPrivate(); + Q_D(DbUserInfo); + d->m_userID = uid; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +enum Isds::Type::UserType Isds::DbUserInfo::userType(void) const +{ + Q_D(const DbUserInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return Type::UT_NULL; + } + + return d->m_userType; +} + +void Isds::DbUserInfo::setUserType(enum Type::UserType ut) +{ + ensureDbUserInfoPrivate(); + Q_D(DbUserInfo); + d->m_userType = ut; +} + +Isds::Type::Privileges Isds::DbUserInfo::userPrivils(void) const +{ + Q_D(const DbUserInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return Type::PRIVIL_NONE; + } + + return d->m_userPrivils; +} + +void Isds::DbUserInfo::setUserPrivils(Type::Privileges p) +{ + ensureDbUserInfoPrivate(); + Q_D(DbUserInfo); + d->m_userPrivils = p; +} + +const QString &Isds::DbUserInfo::ic(void) const +{ + Q_D(const DbUserInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_ic; +} + +void Isds::DbUserInfo::setIc(const QString &ic) +{ + ensureDbUserInfoPrivate(); + Q_D(DbUserInfo); + d->m_ic = ic; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::DbUserInfo::setIc(QString &&ic) +{ + ensureDbUserInfoPrivate(); + Q_D(DbUserInfo); + d->m_ic = ic; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::DbUserInfo::firmName(void) const +{ + Q_D(const DbUserInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_firmName; +} + +void Isds::DbUserInfo::setFirmName(const QString &fn) +{ + ensureDbUserInfoPrivate(); + Q_D(DbUserInfo); + d->m_firmName = fn; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::DbUserInfo::setFirmName(QString &&fn) +{ + ensureDbUserInfoPrivate(); + Q_D(DbUserInfo); + d->m_firmName = fn; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::DbUserInfo::caStreet(void) const +{ + Q_D(const DbUserInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_caStreet; +} + +void Isds::DbUserInfo::setCaStreet(const QString &cs) +{ + ensureDbUserInfoPrivate(); + Q_D(DbUserInfo); + d->m_caStreet = cs; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::DbUserInfo::setCaStreet(QString &&cs) +{ + ensureDbUserInfoPrivate(); + Q_D(DbUserInfo); + d->m_caStreet = cs; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::DbUserInfo::caCity(void) const +{ + Q_D(const DbUserInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_caCity; +} + +void Isds::DbUserInfo::setCaCity(const QString &cc) +{ + ensureDbUserInfoPrivate(); + Q_D(DbUserInfo); + d->m_caCity = cc; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::DbUserInfo::setCaCity(QString &&cc) +{ + ensureDbUserInfoPrivate(); + Q_D(DbUserInfo); + d->m_caCity = cc; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::DbUserInfo::caZipCode(void) const +{ + Q_D(const DbUserInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_caZipCode; +} + +void Isds::DbUserInfo::setCaZipCode(const QString &cz) +{ + ensureDbUserInfoPrivate(); + Q_D(DbUserInfo); + d->m_caZipCode = cz; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::DbUserInfo::setCaZipCode(QString &&cz) +{ + ensureDbUserInfoPrivate(); + Q_D(DbUserInfo); + d->m_caZipCode = cz; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::DbUserInfo::caState(void) const +{ + Q_D(const DbUserInfo); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_caState; +} + +void Isds::DbUserInfo::setCaState(const QString &cs) +{ + ensureDbUserInfoPrivate(); + Q_D(DbUserInfo); + d->m_caState = cs; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::DbUserInfo::setCaState(QString &&cs) +{ + ensureDbUserInfoPrivate(); + Q_D(DbUserInfo); + d->m_caState = cs; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +void Isds::swap(DbUserInfo &first, DbUserInfo &second) Q_DECL_NOTHROW +{ + using std::swap; + swap(first.d_ptr, second.d_ptr); +} diff --git a/src/datovka_shared/isds/box_interface.h b/src/datovka_shared/isds/box_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..65848776d3281ea643534438e4af4ef9d2a7643f --- /dev/null +++ b/src/datovka_shared/isds/box_interface.h @@ -0,0 +1,462 @@ +/* + * 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 . + * + * 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 +#include +#include + +#include "src/datovka_shared/isds/types.h" + +/* + * Structures originating from pril_3/WS_ISDS_Sprava_datovych_schranek.pdf. + */ + +namespace Isds { + + class AddressPrivate; + /*! + * @brief Exists as address element group gAddress (dbTypes.xsd). + * // DbOwnerInfo, DbUserInfo, DbUserInfoExt + */ + class Address { + Q_DECLARE_PRIVATE(Address) + + public: + Address(void); + Address(const Address &other); +#ifdef Q_COMPILER_RVALUE_REFS + Address(Address &&other) Q_DECL_NOEXCEPT; +#endif /* Q_COMPILER_RVALUE_REFS */ + ~Address(void); + + Address &operator=(const Address &other) Q_DECL_NOTHROW; +#ifdef Q_COMPILER_RVALUE_REFS + Address &operator=(Address &&other) Q_DECL_NOTHROW; +#endif /* Q_COMPILER_RVALUE_REFS */ + + bool operator==(const Address &other) const; + bool operator!=(const Address &other) const; + + friend void swap(Address &first, Address &second) Q_DECL_NOTHROW; + + bool isNull(void) const; + + /* adCity */ + const QString &city(void) const; + void setCity(const QString &c); +#ifdef Q_COMPILER_RVALUE_REFS + void setCity(QString &&c); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* adDistrict - not present in libisds-0.10.7 */ + /* adStreet */ + const QString &street(void) const; + void setStreet(const QString &s); +#ifdef Q_COMPILER_RVALUE_REFS + void setStreet(QString &&s); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* adNumberInStreet */ + const QString &numberInStreet(void) const; + void setNumberInStreet(const QString &nis); +#ifdef Q_COMPILER_RVALUE_REFS + void setNumberInStreet(QString &&nis); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* adNumberInMunicipality */ + const QString &numberInMunicipality(void) const; + void setNumberInMunicipality(const QString &nim); +#ifdef Q_COMPILER_RVALUE_REFS + void setNumberInMunicipality(QString &&nim); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* adZipCode */ + const QString &zipCode(void) const; + void setZipCode(const QString &zc); +#ifdef Q_COMPILER_RVALUE_REFS + void setZipCode(QString &&zc); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* adState */ + const QString &state(void) const; + void setState(const QString &s); +#ifdef Q_COMPILER_RVALUE_REFS + void setState(QString &&s); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* adAMCode - not present in libisds-0.10.7 */ + + friend Address libisds2address(const struct isds_Address *ia, + bool *ok); + + private: + QScopedPointer d_ptr; // std::unique_ptr ? + }; + + void swap(Address &first, Address &second) Q_DECL_NOTHROW; + + class BirthInfoPrivate; + /*! + * @brief Exists as birth info element group gBirthInfo (dbTypes.xsd). + * // DbOwnerInfo + */ + class BirthInfo { + Q_DECLARE_PRIVATE(BirthInfo) + + public: + BirthInfo(void); + BirthInfo(const BirthInfo &other); +#ifdef Q_COMPILER_RVALUE_REFS + BirthInfo(BirthInfo &&other) Q_DECL_NOEXCEPT; +#endif /* Q_COMPILER_RVALUE_REFS */ + ~BirthInfo(void); + + BirthInfo &operator=(const BirthInfo &other) Q_DECL_NOTHROW; +#ifdef Q_COMPILER_RVALUE_REFS + BirthInfo &operator=(BirthInfo &&other) Q_DECL_NOTHROW; +#endif /* Q_COMPILER_RVALUE_REFS */ + + bool operator==(const BirthInfo &other) const; + bool operator!=(const BirthInfo &other) const; + + friend void swap(BirthInfo &first, BirthInfo &second) Q_DECL_NOTHROW; + + bool isNull(void) const; + + /* biDate */ + const QDate &date(void) const; + void setDate(const QDate &bd); +#ifdef Q_COMPILER_RVALUE_REFS + void setDate(QDate &&bd); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* biCity */ + const QString &city(void) const; + void setCity(const QString &c); +#ifdef Q_COMPILER_RVALUE_REFS + void setCity(QString &&c); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* biCounty */ /* cz: okres; de: Bezirk, Kreis; en: council area, county, district */ + const QString &county(void) const; + void setCounty(const QString &c); +#ifdef Q_COMPILER_RVALUE_REFS + void setCounty(QString &&c); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* biState */ /* cz: stat; de: Land, Staat; en: Country */ + const QString &state(void) const; + void setState(const QString &s); +#ifdef Q_COMPILER_RVALUE_REFS + void setState(QString &&s); +#endif /* Q_COMPILER_RVALUE_REFS */ + + friend BirthInfo libisds2birthInfo( + const struct isds_BirthInfo *ibi, bool *ok); + + private: + QScopedPointer d_ptr; // std::unique_ptr ? + }; + + void swap(BirthInfo &first, BirthInfo &second) Q_DECL_NOTHROW; + + class PersonNamePrivate; + /*! + * @brief Exists as name element group gPersonName (dbTypes.xsd). + * // DbOwnerInfo, DbUserInfo + * + * pril_3/WS_ISDS_Sprava_datovych_schranek.pdf (section 1.6) + */ + class PersonName { + Q_DECLARE_PRIVATE(PersonName) + + public: + PersonName(void); + PersonName(const PersonName &other); +#ifdef Q_COMPILER_RVALUE_REFS + PersonName(PersonName &&other) Q_DECL_NOEXCEPT; +#endif /* Q_COMPILER_RVALUE_REFS */ + ~PersonName(void); + + PersonName &operator=(const PersonName &other) Q_DECL_NOTHROW; +#ifdef Q_COMPILER_RVALUE_REFS + PersonName &operator=(PersonName &&other) Q_DECL_NOTHROW; +#endif /* Q_COMPILER_RVALUE_REFS */ + + bool operator==(const PersonName &other) const; + bool operator!=(const PersonName &other) const; + + friend void swap(PersonName &first, PersonName &second) Q_DECL_NOTHROW; + + bool isNull(void) const; + + /* pnFirstName */ + const QString &firstName(void) const; + void setFirstName(const QString &fn); +#ifdef Q_COMPILER_RVALUE_REFS + void setFirstName(QString &&fn); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* pnMiddleName */ + const QString &middleName(void) const; + void setMiddleName(const QString &mn); +#ifdef Q_COMPILER_RVALUE_REFS + void setMiddleName(QString &&mn); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* pnLastName */ + const QString &lastName(void) const; + void setLastName(const QString &ln); +#ifdef Q_COMPILER_RVALUE_REFS + void setLastName(QString &&ln); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* pnLastNameAtBirth */ + const QString &lastNameAtBirth(void) const; + void setLastNameAtBirth(const QString &lnab); +#ifdef Q_COMPILER_RVALUE_REFS + void setLastNameAtBirth(QString &&lnab); +#endif /* Q_COMPILER_RVALUE_REFS */ + + friend PersonName libisds2personName( + const struct isds_PersonName *ipn, bool *ok); + + private: + QScopedPointer d_ptr; // std::unique_ptr ? + }; + + void swap(PersonName &first, PersonName &second) Q_DECL_NOTHROW; + + class DbOwnerInfoPrivate; + /*! + * @brief Exists as type tDbOwnerInfo (dbTypes.xsd). + * + * pril_3/WS_ISDS_Sprava_datovych_schranek.pdf (section 1.6.1) + */ + class DbOwnerInfo { + Q_DECLARE_PRIVATE(DbOwnerInfo) + + public: + DbOwnerInfo(void); + DbOwnerInfo(const DbOwnerInfo &other); +#ifdef Q_COMPILER_RVALUE_REFS + DbOwnerInfo(DbOwnerInfo &&other) Q_DECL_NOEXCEPT; +#endif /* Q_COMPILER_RVALUE_REFS */ + ~DbOwnerInfo(void); + + DbOwnerInfo &operator=(const DbOwnerInfo &other) Q_DECL_NOTHROW; +#ifdef Q_COMPILER_RVALUE_REFS + DbOwnerInfo &operator=(DbOwnerInfo &&other) Q_DECL_NOTHROW; +#endif /* Q_COMPILER_RVALUE_REFS */ + + bool operator==(const DbOwnerInfo &other) const; + bool operator!=(const DbOwnerInfo &other) const; + + friend void swap(DbOwnerInfo &first, DbOwnerInfo &second) Q_DECL_NOTHROW; + + bool isNull(void) const; + + /* dbID */ + const QString &dbID(void) const; + void setDbID(const QString &bi); +#ifdef Q_COMPILER_RVALUE_REFS + void setDbID(QString &&bi); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dbType */ + enum Type::DbType dbType(void) const; + void setDbType(enum Type::DbType bt); + /* ic */ + const QString &ic(void) const; + void setIc(const QString &ic); +#ifdef Q_COMPILER_RVALUE_REFS + void setIc(QString &&ic); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* pnFirstName, pnMiddleName, pnLastName, pnLastNameAtBirth */ + const PersonName &personName(void) const; + void setPersonName(const PersonName &pn); +#ifdef Q_COMPILER_RVALUE_REFS + void setPersonName(PersonName &&pn); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* firmName */ + const QString &firmName(void) const; + void setFirmName(const QString &fn); +#ifdef Q_COMPILER_RVALUE_REFS + void setFirmName(QString &&fn); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* biDate, biCity, biCounty, biState */ + const BirthInfo &birthInfo(void) const; + void setBirthInfo(const BirthInfo &bi); +#ifdef Q_COMPILER_RVALUE_REFS + void setBirthInfo(BirthInfo &&bi); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* adCity, adStreet, adNumberInStreet, adNumberInMunicipality, adZipCode, adState */ + const Address &address(void) const; + void setAddress(const Address &a); +#ifdef Q_COMPILER_RVALUE_REFS + void setAddress(Address &&a); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* Nationality */ + const QString &nationality(void) const; + void setNationality(const QString &n); +#ifdef Q_COMPILER_RVALUE_REFS + void setNationality(QString &&n); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* email */ + const QString &email(void) const; + void setEmail(const QString &e); +#ifdef Q_COMPILER_RVALUE_REFS + void setEmail(QString &&e); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* telNumber */ + const QString &telNumber(void) const; + void setTelNumber(const QString &tn); +#ifdef Q_COMPILER_RVALUE_REFS + void setTelNumber(QString &&tn); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* identifier */ + const QString &identifier(void) const; + void setIdentifier(const QString &i); +#ifdef Q_COMPILER_RVALUE_REFS + void setIdentifier(QString &&i); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* registryCode */ + const QString ®istryCode(void) const; + void setRegistryCode(const QString &rc); +#ifdef Q_COMPILER_RVALUE_REFS + void setRegistryCode(QString &&rc); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dbState */ + enum Type::DbState dbState(void) const; + void setDbState(enum Type::DbState bs); + /* dbEffectiveOVM */ + enum Type::NilBool dbEffectiveOVM(void) const; + void setDbEffectiveOVM(enum Type::NilBool eo); + /* dbOpenAddressing */ + enum Type::NilBool dbOpenAddressing(void) const; + void setDbOpenAddressing(enum Type::NilBool oa); + + friend DbOwnerInfo libisds2dbOwnerInfo( + const struct isds_DbOwnerInfo *idoi, bool *ok); + + private: + QScopedPointer d_ptr; // std::unique_ptr ? + }; + + void swap(DbOwnerInfo &first, DbOwnerInfo &second) Q_DECL_NOTHROW; + + class DbUserInfoPrivate; + /*! + * @brief Exists as type tDbUserInfo, tDbUserInfoExt (dbTypes.xsd). + * + * pril_3/WS_ISDS_Sprava_datovych_schranek.pdf (section 1.6.2) + */ + class DbUserInfo { + Q_DECLARE_PRIVATE(DbUserInfo) + + public: + DbUserInfo(void); + DbUserInfo(const DbUserInfo &other); +#ifdef Q_COMPILER_RVALUE_REFS + DbUserInfo(DbUserInfo &&other) Q_DECL_NOEXCEPT; +#endif /* Q_COMPILER_RVALUE_REFS */ + ~DbUserInfo(void); + + DbUserInfo &operator=(const DbUserInfo &other) Q_DECL_NOTHROW; +#ifdef Q_COMPILER_RVALUE_REFS + DbUserInfo &operator=(DbUserInfo &&other) Q_DECL_NOTHROW; +#endif /* Q_COMPILER_RVALUE_REFS */ + + bool operator==(const DbUserInfo &other) const; + bool operator!=(const DbUserInfo &other) const; + + friend void swap(DbUserInfo &first, DbUserInfo &second) Q_DECL_NOTHROW; + + bool isNull(void) const; + + /* pnFirstName, pnMiddleName, pnLastName, pnLastNameAtBirth */ + const PersonName &personName(void) const; + void setPersonName(const PersonName &pn); +#ifdef Q_COMPILER_RVALUE_REFS + void setPersonName(PersonName &&pn); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* adCity, adStreet, adNumberInStreet, adNumberInMunicipality, adZipCode, adState */ + const Address &address(void) const; + void setAddress(const Address &a); +#ifdef Q_COMPILER_RVALUE_REFS + void setAddress(Address &&a); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* biDate */ + const QDate &biDate(void) const; + void setBiDate(const QDate &bd); +#ifdef Q_COMPILER_RVALUE_REFS + void setBiDate(QDate &&bd); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* userID */ + const QString &userID(void) const; + void setUserId(const QString &uid); +#ifdef Q_COMPILER_RVALUE_REFS + void setUserId(QString &&uid); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* userType */ + enum Type::UserType userType(void) const; + void setUserType(enum Type::UserType ut); + /* userPrivils */ + Type::Privileges userPrivils(void) const; + void setUserPrivils(Type::Privileges p); + /* ic */ + const QString &ic(void) const; + void setIc(const QString &ic); +#ifdef Q_COMPILER_RVALUE_REFS + void setIc(QString &&ic); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* firmName */ + const QString &firmName(void) const; + void setFirmName(const QString &fn); +#ifdef Q_COMPILER_RVALUE_REFS + void setFirmName(QString &&fn); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* caStreet */ + const QString &caStreet(void) const; + void setCaStreet(const QString &cs); +#ifdef Q_COMPILER_RVALUE_REFS + void setCaStreet(QString &&cs); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* caCity */ + const QString &caCity(void) const; + void setCaCity(const QString &cc); +#ifdef Q_COMPILER_RVALUE_REFS + void setCaCity(QString &&cc); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* caZipCode */ + const QString &caZipCode(void) const; + void setCaZipCode(const QString &cz); +#ifdef Q_COMPILER_RVALUE_REFS + void setCaZipCode(QString &&cz); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* caState */ + const QString &caState(void) const; + void setCaState(const QString &cs); +#ifdef Q_COMPILER_RVALUE_REFS + void setCaState(QString &&cs); +#endif /* Q_COMPILER_RVALUE_REFS */ + + friend DbUserInfo libisds2dbOwnerInfo( + const struct isds_DbUserInfo *idoi, bool *ok); + + private: + QScopedPointer d_ptr; // std::unique_ptr ? + }; + + void swap(DbUserInfo &first, DbUserInfo &second) Q_DECL_NOTHROW; + +} diff --git a/src/datovka_shared/isds/internal_conversion.cpp b/src/datovka_shared/isds/internal_conversion.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f66fd4e07285412e9e8324462c3db02003aae71c --- /dev/null +++ b/src/datovka_shared/isds/internal_conversion.cpp @@ -0,0 +1,291 @@ +/* + * 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 . + * + * 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 +#include +#include +#include /* struct timeval */ + +#include "src/datovka_shared/isds/internal_conversion.h" + +QByteArray Isds::fromCData(const void *cData, size_t cSize) +{ + if ((cData == NULL) || (cSize == 0)) { + return QByteArray(); + } + return QByteArray((const char *)cData, cSize); +} + +bool Isds::toCDataCopy(void **cDataPtr, size_t *cSize, const QByteArray &data) +{ + if (Q_UNLIKELY((cDataPtr == Q_NULLPTR) || (cSize == NULL))) { + Q_ASSERT(0); + return false; + } + if (*cDataPtr != NULL) { + /* Delete already created. */ + std::free(*cDataPtr); *cDataPtr = NULL; + *cSize = 0; + } + if (data.isNull() || (data.size() == 0)) { + return true; + } + /* Copy data content.*/ + *cSize = data.size(); + *cDataPtr = std::malloc(*cSize); + if (Q_UNLIKELY(*cDataPtr == NULL)) { + Q_ASSERT(0); + *cSize = 0; + return false; + } + std::memcpy(*cDataPtr, data.constData(), *cSize); + return true; +} + +QString Isds::fromCStr(const char *cStr) +{ + if (cStr == NULL) { + return QString(); + } + return QString(cStr); +} + +bool Isds::toCStrCopy(char **cStrPtr, const QString &str) +{ + if (Q_UNLIKELY(cStrPtr == Q_NULLPTR)) { + Q_ASSERT(0); + return false; + } + if (*cStrPtr != NULL) { + /* Delete already allocated. */ + std::free(*cStrPtr); *cStrPtr = NULL; + } + if (str.isNull()) { + return true; + } + /* Copy string content. */ + QByteArray strBytes(str.toUtf8()); /* Must not be deleted before memcpy. */ + const char *utfStr = strBytes.constData(); + if (utfStr == Q_NULLPTR) { + return true; + } + size_t utfStrLen = std::strlen(utfStr); + *cStrPtr = (char *)std::malloc(utfStrLen + 1); + if (Q_UNLIKELY(*cStrPtr == NULL)) { + Q_ASSERT(0); + return false; + } + if (utfStrLen > 0) { + std::memcpy(*cStrPtr, utfStr, utfStrLen); + } + (*cStrPtr)[utfStrLen] = '\0'; + return true; +} + +QDate Isds::dateFromStructTM(struct tm *cDate) +{ + if (cDate == NULL) { + return QDate(); + } + + int year = cDate->tm_year + 1900; + int month = cDate->tm_mon + 1; + int day = cDate->tm_mday; + return QDate(year, month, day); +} + +bool Isds::toCDateCopy(struct tm **cDatePtr, const QDate &date) +{ + if (Q_UNLIKELY(cDatePtr == Q_NULLPTR)) { + Q_ASSERT(0); + return false; + } + if (date.isNull()) { + if (*cDatePtr != NULL) { + /* Delete allocated. */ + std::free(*cDatePtr); *cDatePtr = NULL; + } + return true; + } + if (*cDatePtr == NULL) { + *cDatePtr = (struct tm *)std::malloc(sizeof(**cDatePtr)); + if (Q_UNLIKELY(*cDatePtr == NULL)) { + Q_ASSERT(0); + return false; + } + } + std::memset(*cDatePtr, 0, sizeof(**cDatePtr)); + + (*cDatePtr)->tm_year = date.year() - 1900; + (*cDatePtr)->tm_mon = date.month() - 1; + (*cDatePtr)->tm_mday = date.day(); + return true; +} + +QDateTime Isds::dateTimeFromStructTimeval(struct timeval *cDateTime) +{ + QDateTime timeStamp; + + if (cDateTime != NULL) { + /* TODO -- handle microseconds. */ +#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)) + timeStamp.setSecsSinceEpoch(cDateTime->tv_sec); +#else /* < Qt-5.8 */ + timeStamp.setTime_t(cDateTime->tv_sec); +#endif /* >= Qt-5.8 */ + timeStamp = timeStamp.addMSecs(cDateTime->tv_usec / 1000); + } + + return timeStamp; +} + +bool Isds::toCDateTimeCopy(struct timeval **cDateTimePtr, + const QDateTime &dateTime) +{ + if (Q_UNLIKELY(cDateTimePtr == Q_NULLPTR)) { + Q_ASSERT(0); + return false; + } + if (dateTime.isNull()) { + if (*cDateTimePtr != NULL) { + /* Delete allocated. */ + std::free(*cDateTimePtr); *cDateTimePtr = NULL; + } + return true; + } + if (*cDateTimePtr == NULL) { + *cDateTimePtr = + (struct timeval *)std::malloc(sizeof(**cDateTimePtr)); + if (Q_UNLIKELY(*cDateTimePtr == NULL)) { + Q_ASSERT(0); + return false; + } + } + std::memset(*cDateTimePtr, 0, sizeof(**cDateTimePtr)); + + /* TODO -- handle microseconds. */ +#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)) + (*cDateTimePtr)->tv_sec = dateTime.toSecsSinceEpoch(); +#else /* < Qt-5.8 */ + (*cDateTimePtr)->tv_sec = dateTime.toTime_t(); +#endif /* >= Qt-5.8 */ + (*cDateTimePtr)->tv_usec = dateTime.time().msec() * 1000; + return true; +} + +qint64 Isds::fromLongInt(const long int *cLongPtr) +{ + if (cLongPtr == NULL) { + return -1; + } + return *cLongPtr; +} + +bool Isds::toLongInt(long int **cLongPtr, qint64 i) +{ + if (Q_UNLIKELY(cLongPtr == Q_NULLPTR)) { + Q_ASSERT(0); + return false; + } + if (i < 0) { + if (*cLongPtr != NULL) { + std::free(*cLongPtr); *cLongPtr = NULL; + } + return true; + } + if (*cLongPtr == NULL) { + *cLongPtr = (long int*)std::malloc(sizeof(**cLongPtr)); + if (Q_UNLIKELY(*cLongPtr == NULL)) { + Q_ASSERT(0); + return false; + } + } + + **cLongPtr = i; + return true; +} + +enum Isds::Type::NilBool Isds::fromBool(const _Bool *cBoolPtr) +{ + if (cBoolPtr == NULL) { + return Type::BOOL_NULL; + } else if (*cBoolPtr == false) { + return Type::BOOL_FALSE; + } else { + return Type::BOOL_TRUE; + } +} + +bool Isds::toBool(_Bool **cBoolPtr, enum Type::NilBool nilBool) +{ + if (Q_UNLIKELY(cBoolPtr == NULL)) { + Q_ASSERT(0); + return false; + } + + if (nilBool == Type::BOOL_NULL) { + if (*cBoolPtr != NULL) { + std::free(*cBoolPtr); *cBoolPtr = NULL; + } + return true; + } + if (*cBoolPtr == NULL) { + *cBoolPtr = (_Bool *)std::malloc(sizeof(**cBoolPtr)); + if (Q_UNLIKELY(*cBoolPtr == NULL)) { + Q_ASSERT(0); + return false; + } + } + + **cBoolPtr = (nilBool == Type::BOOL_TRUE); + return true; +} + +qint64 Isds::string2NonNegativeLong(const QString &str, bool *ok) +{ + if (str.isEmpty()) { + if (ok != Q_NULLPTR) { + *ok = true; + } + return -1; + } + + bool iOk = false; + qint64 num = str.toLongLong(&iOk); + if ((!iOk) || (num < 0)) { + if (ok != Q_NULLPTR) { + *ok = false; + } + return -1; + } + + if (ok != Q_NULLPTR) { + *ok = true; + } + return num; +} + +QString Isds::nonNegativeLong2String(qint64 num) +{ + return (num >= 0) ? QString::number(num) : QString(); +} diff --git a/src/datovka_shared/isds/internal_conversion.h b/src/datovka_shared/isds/internal_conversion.h new file mode 100644 index 0000000000000000000000000000000000000000..9f90498a7df63d210bf0db93f4a4ea0efdd195bc --- /dev/null +++ b/src/datovka_shared/isds/internal_conversion.h @@ -0,0 +1,176 @@ +/* + * 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 . + * + * 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. + */ + +/* + * This header file must not be included in other header files. + * + * Functions in this compilation unit serve for converting types + * defined in libisds. + */ + +#pragma once + +#if defined(__APPLE__) || defined(__clang__) +# define __USE_C99_MATH +# define _Bool bool +#else /* !__APPLE__ */ +# include +#endif /* __APPLE__ */ + +#include +#include +#include +#include + +#include "src/datovka_shared/isds/types.h" + +namespace Isds { + + /*! + * @brief Converts C data into QByteArray. + * + * @param[in] cData C data pointer. + * @param[in] cSize Size of data. + * @return Byte array object, null byte array if NULL pointer or zero size was supplied. + */ + QByteArray fromCData(const void *cData, size_t cSize); + + /*! + * @brief Creates a C data copy from the supplied QBYteArray. + * + * @param[in,out] cDataPtr Pointer to C data. + * @param[in,out] cSize Size value to be set. + * @param[in] data Data object. + * @return True on success, false on failure. + */ + bool toCDataCopy(void **cDataPtr, size_t *cSize, + const QByteArray &data); + + /*! + * @brief Converts a C-string into QString. + * + * @param[in] cStr C string. + * @return String object, null string if NULL pointer was supplied. + */ + QString fromCStr(const char *cStr); + + /*! + * @brief Creates a C-string copy to the supplied QString. + * + * @param[in,out] cStrPtr Pointer to C string. + * @param[in] str String object. + * @return True on success, false in failure. + */ + bool toCStrCopy(char **cStrPtr, const QString &str); + + /*! + * @brief Converts date from struct tm. + * + * @param[in] cDate Struct tm containing date. + * @return Date object, null date if NULL pointer was supplied. + */ + QDate dateFromStructTM(struct tm *cDate); + + /*! + * @brief Creates a struct tm copy of the supplied QDate. + * + * @param[in,out] cDatePtr Address of pointer to struct tm. + * @param[in] date Date object. + * @return True on success, false in failure. + */ + bool toCDateCopy(struct tm **cDatePtr, const QDate &date); + + /*! + * @brief Converts date and time from struct timeval. + * + * @param[in] cDateTime Struct timeval containing date and time. + * @return Datetime object, null datetime if NULL pointer was supplied. + */ + QDateTime dateTimeFromStructTimeval(struct timeval *cDateTime); + + /*! + * @brief Creates a struct timeval copy of the supplied QDateTime. + * + * @param[in,out] cDateTimePtr Address of pointer to struct tm. + * @param[in] dateTime Date object. + * @return True on success, false in failure. + */ + bool toCDateTimeCopy(struct timeval **cDateTimePtr, + const QDateTime &dateTime); + + /*! + * @brief Convert from long int. + * + * @param[in] cLongPtr Pointer to long. + * @return -1 if NULL pointer supplied as parameter. + */ + qint64 fromLongInt(const long int *cLongPtr); + + /*! + * @brief Creates a long int from supplied number. + * + * @note Negative integers cause the pointer to be set to NULL. + * + * @param[in,out] cLongPtr Pointer to long int. + * @param[in] i Integerer. + * @return True on success, false in failure. + */ + bool toLongInt(long int **cLongPtr, qint64 i); + + /*! + * @brief Converts internal pointer to bool. + * + * @param[in] cBoolPtr Pointer to bool. + * @return Nullable bool enumeration type. + */ + enum Type::NilBool fromBool(const _Bool *cBoolPtr); + + /*! + * @brief Sets bool pointer according to supplied value. + * + * @param[in,out] cBoolPtr Bool pointer to be set. + * @param[in] nilBool Nullable bool value. + * @return True on success, false in failure. + */ + bool toBool(_Bool **cBoolPtr, enum Type::NilBool nilBool); + + /*! + * @brief Converts string to non-negative integer. + * + * @param[in] str String containing non-negative number. + * @param[out] ok Set to true if string contains non-negative number. + * @return Non-negative number if string contains a non-negative number. + * -1 if string is empty or on error. + */ + qint64 string2NonNegativeLong(const QString &str, bool *ok); + + /*! + * @brief Converts integer to string. Negative values result in null + * string. + * + * @param[in] num Number to be converted to string. + * @return String with decimal number representation. + * Null string if supplied value is negative. + */ + QString nonNegativeLong2String(qint64 num); +} diff --git a/src/datovka_shared/isds/message_interface.cpp b/src/datovka_shared/isds/message_interface.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2a2ed2b34003578456eef075fd35454ca7501734 --- /dev/null +++ b/src/datovka_shared/isds/message_interface.cpp @@ -0,0 +1,2220 @@ +/* + * 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 . + * + * 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 +#include /* std::move */ + +#include "src/datovka_shared/isds/internal_conversion.h" +#include "src/datovka_shared/isds/message_interface.h" + +/* Null objects - for convenience. */ +static const Isds::Envelope nullEnvelope; +static const Isds::Hash nullHash; +static const QByteArray nullByteArray; +static const QDateTime nullDateTime; +static const QList nullDocumentList; +static const QList nullEventList; +static const QString nullString; + +/*! + * @brief PIMPL Hash class. + */ +class Isds::HashPrivate { + //Q_DISABLE_COPY(HashPrivate) +public: + HashPrivate(void) + : m_alg(Type::HA_UNKNOWN), m_hash() + { } + + HashPrivate &operator=(const HashPrivate &other) Q_DECL_NOTHROW + { + m_alg = other.m_alg; + m_hash = other.m_hash; + + return *this; + } + + bool operator==(const HashPrivate &other) const + { + return (m_alg == other.m_alg) && + (m_hash == other.m_hash); + } + + enum Type::HashAlg m_alg; + QByteArray m_hash; +}; + +Isds::Hash::Hash(void) + : d_ptr(Q_NULLPTR) +{ +} + +Isds::Hash::Hash(const Hash &other) + : d_ptr((other.d_func() != Q_NULLPTR) ? (new (std::nothrow) HashPrivate) : Q_NULLPTR) +{ + Q_D(Hash); + if (d == Q_NULLPTR) { + return; + } + + *d = *other.d_func(); +} + +#ifdef Q_COMPILER_RVALUE_REFS +Isds::Hash::Hash(Hash &&other) Q_DECL_NOEXCEPT + : d_ptr(other.d_ptr.take()) //d_ptr(std::move(other.d_ptr)) +{ +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +Isds::Hash::~Hash(void) +{ +} + +/*! + * @brief Ensures private hash presence. + * + * @note Returns if private hash could not be allocated. + */ +#define ensureHashPrivate(_x_) \ + do { \ + if (Q_UNLIKELY(d_ptr == Q_NULLPTR)) { \ + HashPrivate *p = new (std::nothrow) HashPrivate; \ + if (Q_UNLIKELY(p == Q_NULLPTR)) { \ + Q_ASSERT(0); \ + return _x_; \ + } \ + d_ptr.reset(p); \ + } \ + } while (0) + +Isds::Hash &Isds::Hash::operator=(const Hash &other) Q_DECL_NOTHROW +{ + if (other.d_func() == Q_NULLPTR) { + d_ptr.reset(Q_NULLPTR); + return *this; + } + ensureHashPrivate(*this); + Q_D(Hash); + + *d = *other.d_func(); + + return *this; +} + +#ifdef Q_COMPILER_RVALUE_REFS +Isds::Hash &Isds::Hash::operator=(Hash &&other) Q_DECL_NOTHROW +{ + swap(*this, other); + return *this; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +bool Isds::Hash::operator==(const Hash &other) const +{ + Q_D(const Hash); + 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::Hash::operator!=(const Hash &other) const +{ + return !operator==(other); +} + +bool Isds::Hash::isNull(void) const +{ + Q_D(const Hash); + return d == Q_NULLPTR; +} + +QString Isds::Hash::base64Value(void) const +{ + const QByteArray &v(value()); + if (!v.isNull()) { + return QString::fromUtf8(v.toBase64()); + } else { + return QString(); + } +} + +void Isds::Hash::setBase64Value(const QString &ev) +{ + QByteArray v; + if (!ev.isNull()) { + v = QByteArray::fromBase64(ev.toUtf8()); + } + setValue(v); +} + +enum Isds::Type::HashAlg Isds::Hash::algorithm(void) const +{ + Q_D(const Hash); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return Type::HA_UNKNOWN; + } + + return d->m_alg; +} + +void Isds::Hash::setAlgorithm(enum Type::HashAlg a) +{ + ensureHashPrivate(); + Q_D(Hash); + d->m_alg = a; +} + +const QByteArray &Isds::Hash::value(void) const +{ + Q_D(const Hash); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullByteArray; + } + + return d->m_hash; +} + +void Isds::Hash::setValue(const QByteArray &v) +{ + ensureHashPrivate(); + Q_D(Hash); + d->m_hash = v; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Hash::setValue(QByteArray &&v) +{ + ensureHashPrivate(); + Q_D(Hash); + d->m_hash = v; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +void Isds::swap(Hash &first, Hash &second) Q_DECL_NOTHROW +{ + using std::swap; + swap(first.d_ptr, second.d_ptr); +} + +/*! + * @brief PIMPL Event class. + */ +class Isds::EventPrivate { + //Q_DISABLE_COPY(EventPrivate) +public: + EventPrivate(void) + : m_time(), m_type(Type::EV_UNKNOWN), m_descr() + { } + + EventPrivate &operator=(const EventPrivate &other) Q_DECL_NOTHROW + { + m_time = other.m_time; + m_type = other.m_type; + m_descr = other.m_descr; + + return *this; + } + + bool operator==(const EventPrivate &other) const + { + return (m_time == other.m_time) && + (m_type == other.m_type) && + (m_descr == other.m_descr); + } + + QDateTime m_time; /* dmEventTime */ + enum Type::Event m_type; /* Inspired by libisds. */ + QString m_descr; /* dmEventDescr */ +}; + +Isds::Event::Event(void) + : d_ptr(Q_NULLPTR) +{ +} + +Isds::Event::Event(const Event &other) + : d_ptr((other.d_func() != Q_NULLPTR) ? (new (std::nothrow) EventPrivate) : Q_NULLPTR) +{ + Q_D(Event); + if (d == Q_NULLPTR) { + return; + } + + *d = *other.d_func(); +} + +#ifdef Q_COMPILER_RVALUE_REFS +Isds::Event::Event(Event &&other) Q_DECL_NOEXCEPT + : d_ptr(other.d_ptr.take()) //d_ptr(std::move(other.d_ptr)) +{ +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +Isds::Event::~Event(void) +{ +} + +/*! + * @brief Ensures private event presence. + * + * @note Returns if private event could not be allocated. + */ +#define ensureEventPrivate(_x_) \ + do { \ + if (Q_UNLIKELY(d_ptr == Q_NULLPTR)) { \ + EventPrivate *p = new (std::nothrow) EventPrivate; \ + if (Q_UNLIKELY(p == Q_NULLPTR)) { \ + Q_ASSERT(0); \ + return _x_; \ + } \ + d_ptr.reset(p); \ + } \ + } while (0) + +Isds::Event &Isds::Event::operator=(const Event &other) Q_DECL_NOTHROW +{ + if (other.d_func() == Q_NULLPTR) { + d_ptr.reset(Q_NULLPTR); + return *this; + } + ensureEventPrivate(*this); + Q_D(Event); + + *d = *other.d_func(); + + return *this; +} + +#ifdef Q_COMPILER_RVALUE_REFS +Isds::Event &Isds::Event::operator=(Event &&other) Q_DECL_NOTHROW +{ + swap(*this, other); + return *this; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +bool Isds::Event::operator==(const Event &other) const +{ + Q_D(const Event); + 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::Event::operator!=(const Event &other) const +{ + return !operator==(other); +} + +bool Isds::Event::isNull(void) const +{ + Q_D(const Event); + return d == Q_NULLPTR; +} + +/*! + * @brief Converts description to event. + * + * @note Libisds does not know all events listed in the documentation. + */ +static +enum Isds::Type::Event descr2event(const QString &d) +{ + typedef QPair EventPair; + + static const QList pairs({ + {"EV0:", Isds::Type::EV_ENTERED}, + {"EV5:", Isds::Type::EV_DELIVERED}, + {"EV1:", Isds::Type::EV_ACCEPTED_LOGIN}, + {"EV11:", Isds::Type::EV_PRIMARY_LOGIN}, + {"EV12:", Isds::Type::EV_ENTRUSTED_LOGIN}, + {"EV13:", Isds::Type::EV_SYSCERT_LOGIN}, + {"EV2:", Isds::Type::EV_ACCEPTED_FICTION}, + {"EV3:", Isds::Type::EV_UNDELIVERABLE}, + {"EV4:", Isds::Type::EV_ACCEPTED_BY_RECIPIENT}, + {"EV8:", Isds::Type::EV_UNDELIVERED_AV_CHECK} + }); + + fprintf(stdout, "AAA '%s'\n", d.toUtf8().constData()); + + foreach (const EventPair &pair, pairs) { + if (d.startsWith(pair.first)) { + return pair.second; + } + } + + return Isds::Type::EV_UNKNOWN; +} + +void Isds::Event::setFromText(const QString &t) +{ + Q_UNUSED(t); /* TODO */ +} + +const QDateTime &Isds::Event::time(void) const +{ + Q_D(const Event); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullDateTime; + } + + return d->m_time; +} + +void Isds::Event::setTime(const QDateTime &t) +{ + ensureEventPrivate(); + Q_D(Event); + d->m_time = t; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Event::setTime(QDateTime &&t) +{ + ensureEventPrivate(); + Q_D(Event); + d->m_time = t; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +enum Isds::Type::Event Isds::Event::type(void) const +{ + Q_D(const Event); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return Type::EV_UNKNOWN; + } + + return d->m_type; +} + +void Isds::Event::setType(enum Type::Event et) +{ + ensureEventPrivate(); + Q_D(Event); + d->m_type = et; +} + +const QString &Isds::Event::descr(void) const +{ + Q_D(const Event); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + + return d->m_descr; +} + +void Isds::Event::setDescr(const QString &descr) +{ + ensureEventPrivate(); + Q_D(Event); + d->m_descr = descr; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Event::setDescr(QString &&descr) +{ + ensureEventPrivate(); + Q_D(Event); + d->m_descr = descr; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::Event::type2string(enum Type::Event type) +{ + static const QString ev0("EV0"), ev1("EV1"), ev2("EV2"), ev3("EV3"), + ev4("EV4"), ev5("EV5"), ev8("EV8"), ev11("EV11"), ev12("EV12"), + ev13("EV13"); + static const QString invalid; + + switch (type) { + case Type::EV_ENTERED: return ev0; break; + case Type::EV_DELIVERED: return ev5; break; + case Type::EV_ACCEPTED_LOGIN: return ev1; break; + case Type::EV_PRIMARY_LOGIN: return ev11; break; + case Type::EV_ENTRUSTED_LOGIN: return ev12; break; + case Type::EV_SYSCERT_LOGIN: return ev13; break; + case Type::EV_ACCEPTED_FICTION: return ev2; break; + case Type::EV_UNDELIVERABLE: return ev3; break; + case Type::EV_ACCEPTED_BY_RECIPIENT: return ev4; break; + case Type::EV_UNDELIVERED_AV_CHECK: return ev8; break; + case Type::EV_UNKNOWN: + default: + //logWarningNL("Unknown event type value '%d'.", type); + return invalid; + break; + } +} + +void Isds::swap(Event &first, Event &second) Q_DECL_NOTHROW +{ + using std::swap; + swap(first.d_ptr, second.d_ptr); +} + +class Isds::EnvelopePrivate { + //Q_DISABLE_COPY(EnvelopePrivate) +public: + EnvelopePrivate(void) + : m_dmID(), m_dbIDSender(), m_dmSender(), m_dmSenderAddress(), + m_dmSenderType(Type::BT_NULL), m_dmRecipient(), + m_dmRecipientAddress(), m_dmAmbiguousRecipient(Type::BOOL_NULL), + m_dmOrdinal(0), m_dmMessageStatus(Type::MS_NULL), + m_dmAttachmentSize(-1), m_dmDeliveryTime(), m_dmAcceptanceTime(), + m_dmHash(), m_dmQTimestamp(), m_dmEvents(), m_dmSenderOrgUnit(), + m_dmSenderOrgUnitNum(-1), m_dbIDRecipient(), m_dmRecipientOrgUnit(), + m_dmRecipientOrgUnitNum(-1), m_dmToHands(), m_dmAnnotation(), + m_dmRecipientRefNumber(), m_dmSenderRefNumber(), + m_dmRecipientIdent(), m_dmSenderIdent(), m_dmLegalTitleLaw(-1), + m_dmLegalTitleYear(-1), m_dmLegalTitleSect(), m_dmLegalTitlePar(), + m_dmLegalTitlePoint(), m_dmPersonalDelivery(Type::BOOL_NULL), + m_dmAllowSubstDelivery(Type::BOOL_NULL), m_dmType(), + m_dmOVM(Type::BOOL_NULL), m_dmPublishOwnID(Type::BOOL_NULL) + { } + + EnvelopePrivate &operator=(const EnvelopePrivate &other) Q_DECL_NOTHROW + { + m_dmID = other.m_dmID; + m_dbIDSender = other.m_dbIDSender; + m_dmSender = other.m_dmSender; + m_dmSenderAddress = other.m_dmSenderAddress; + m_dmSenderType = other.m_dmSenderType; + m_dmRecipient = other.m_dmRecipient; + m_dmRecipientAddress = other.m_dmRecipientAddress; + m_dmAmbiguousRecipient = other.m_dmAmbiguousRecipient; + + m_dmOrdinal = other.m_dmOrdinal; + m_dmMessageStatus = other.m_dmMessageStatus; + m_dmAttachmentSize = other.m_dmAttachmentSize; + m_dmDeliveryTime = other.m_dmDeliveryTime; + m_dmAcceptanceTime = other.m_dmAcceptanceTime; + m_dmHash = other.m_dmHash; + m_dmQTimestamp = other.m_dmQTimestamp; + m_dmEvents = other.m_dmEvents; + + m_dmSenderOrgUnit = other.m_dmSenderOrgUnit; + m_dmSenderOrgUnitNum = other.m_dmSenderOrgUnitNum; + m_dbIDRecipient = other.m_dbIDRecipient; + m_dmRecipientOrgUnit = other.m_dmRecipientOrgUnit; + m_dmRecipientOrgUnitNum = other.m_dmRecipientOrgUnitNum; + m_dmToHands = other.m_dmToHands; + m_dmAnnotation = other.m_dmAnnotation; + m_dmRecipientRefNumber = other.m_dmRecipientRefNumber; + m_dmSenderRefNumber = other.m_dmSenderRefNumber; + m_dmRecipientIdent = other.m_dmRecipientIdent; + m_dmSenderIdent = other.m_dmSenderIdent; + + /* Act addressing. */ + m_dmLegalTitleLaw = other.m_dmLegalTitleLaw; + m_dmLegalTitleYear = other.m_dmLegalTitleYear; + m_dmLegalTitleSect = other.m_dmLegalTitleSect; + m_dmLegalTitlePar = other.m_dmLegalTitlePar; + m_dmLegalTitlePoint = other.m_dmLegalTitlePoint; + m_dmPersonalDelivery = other.m_dmPersonalDelivery; + m_dmAllowSubstDelivery = other.m_dmAllowSubstDelivery; + m_dmType = other.m_dmType; + + /* Outgoing messages only. */ + m_dmOVM = other.m_dmOVM; + m_dmPublishOwnID = other.m_dmPublishOwnID; + + return *this; + } + + bool operator==(const EnvelopePrivate &other) const + { + return (m_dmID == other.m_dmID) && + (m_dbIDSender == other.m_dbIDSender) && + (m_dmSender == other.m_dmSender) && + (m_dmSenderAddress == other.m_dmSenderAddress) && + (m_dmSenderType == other.m_dmSenderType) && + (m_dmRecipient == other.m_dmRecipient) && + (m_dmRecipientAddress == other.m_dmRecipientAddress) && + (m_dmAmbiguousRecipient == other.m_dmAmbiguousRecipient) && + + (m_dmOrdinal == other.m_dmOrdinal) && + (m_dmMessageStatus == other.m_dmMessageStatus) && + (m_dmAttachmentSize == other.m_dmAttachmentSize) && + (m_dmDeliveryTime == other.m_dmDeliveryTime) && + (m_dmAcceptanceTime == other.m_dmAcceptanceTime) && + (m_dmHash == other.m_dmHash) && + (m_dmQTimestamp == other.m_dmQTimestamp) && + (m_dmEvents == other.m_dmEvents) && + + (m_dmSenderOrgUnit == other.m_dmSenderOrgUnit) && + (m_dmSenderOrgUnitNum == other.m_dmSenderOrgUnitNum) && + (m_dbIDRecipient == other.m_dbIDRecipient) && + (m_dmRecipientOrgUnit == other.m_dmRecipientOrgUnit) && + (m_dmRecipientOrgUnitNum == other.m_dmRecipientOrgUnitNum) && + (m_dmToHands == other.m_dmToHands) && + (m_dmAnnotation == other.m_dmAnnotation) && + (m_dmRecipientRefNumber == other.m_dmRecipientRefNumber) && + (m_dmSenderRefNumber == other.m_dmSenderRefNumber) && + (m_dmRecipientIdent == other.m_dmRecipientIdent) && + (m_dmSenderIdent == other.m_dmSenderIdent) && + + (m_dmLegalTitleLaw == other.m_dmLegalTitleLaw) && + (m_dmLegalTitleYear == other.m_dmLegalTitleYear) && + (m_dmLegalTitleSect == other.m_dmLegalTitleSect) && + (m_dmLegalTitlePar == other.m_dmLegalTitlePar) && + (m_dmLegalTitlePoint == other.m_dmLegalTitlePoint) && + (m_dmPersonalDelivery == other.m_dmPersonalDelivery) && + (m_dmAllowSubstDelivery == other.m_dmAllowSubstDelivery) && + (m_dmType == other.m_dmType) && + + (m_dmOVM == other.m_dmOVM) && + (m_dmPublishOwnID == other.m_dmPublishOwnID); + } + + QString m_dmID; + QString m_dbIDSender; + QString m_dmSender; + QString m_dmSenderAddress; + enum Type::DbType m_dmSenderType; + QString m_dmRecipient; + QString m_dmRecipientAddress; + enum Type::NilBool m_dmAmbiguousRecipient; + + quint64 m_dmOrdinal; /* Values start at 1. 0 is treated as NULL. */ + enum Type::DmState m_dmMessageStatus; + qint64 m_dmAttachmentSize; + QDateTime m_dmDeliveryTime; + QDateTime m_dmAcceptanceTime; + Hash m_dmHash; + QByteArray m_dmQTimestamp; + QList m_dmEvents; + + QString m_dmSenderOrgUnit; + qint64 m_dmSenderOrgUnitNum; + QString m_dbIDRecipient; + QString m_dmRecipientOrgUnit; + qint64 m_dmRecipientOrgUnitNum; + QString m_dmToHands; + QString m_dmAnnotation; + QString m_dmRecipientRefNumber; + QString m_dmSenderRefNumber; + QString m_dmRecipientIdent; + QString m_dmSenderIdent; + + /* Act addressing. */ + qint64 m_dmLegalTitleLaw; + qint64 m_dmLegalTitleYear; + QString m_dmLegalTitleSect; + QString m_dmLegalTitlePar; + QString m_dmLegalTitlePoint; + enum Type::NilBool m_dmPersonalDelivery; + enum Type::NilBool m_dmAllowSubstDelivery; + QChar m_dmType; + + /* Outgoing messages only. */ + enum Type::NilBool m_dmOVM; + enum Type::NilBool m_dmPublishOwnID; +}; + +Isds::Envelope::Envelope(void) + : d_ptr(Q_NULLPTR) +{ +} + +Isds::Envelope::Envelope(const Envelope &other) + : d_ptr((other.d_func() != Q_NULLPTR) ? (new (std::nothrow) EnvelopePrivate) : Q_NULLPTR) +{ + Q_D(Envelope); + if (d == Q_NULLPTR) { + return; + } + + *d = *other.d_func(); +} + +#ifdef Q_COMPILER_RVALUE_REFS +Isds::Envelope::Envelope(Envelope &&other) Q_DECL_NOEXCEPT + : d_ptr(other.d_ptr.take()) //d_ptr(std::move(other.d_ptr)) +{ +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +Isds::Envelope::~Envelope(void) +{ +} + +/*! + * @brief Ensures private envelope presence. + * + * @note Returns if private envelope could not be allocated. + */ +#define ensureEnvelopePrivate(_x_) \ + do { \ + if (Q_UNLIKELY(d_ptr == Q_NULLPTR)) { \ + EnvelopePrivate *p = new (std::nothrow) EnvelopePrivate; \ + if (Q_UNLIKELY(p == Q_NULLPTR)) { \ + Q_ASSERT(0); \ + return _x_; \ + } \ + d_ptr.reset(p); \ + } \ + } while (0) + +Isds::Envelope &Isds::Envelope::operator=(const Envelope &other) Q_DECL_NOTHROW +{ + if (other.d_func() == Q_NULLPTR) { + d_ptr.reset(Q_NULLPTR); + return *this; + } + ensureEnvelopePrivate(*this); + Q_D(Envelope); + + *d = *other.d_func(); + + return *this; +} + +#ifdef Q_COMPILER_RVALUE_REFS +Isds::Envelope &Isds::Envelope::operator=(Envelope &&other) Q_DECL_NOTHROW +{ + swap(*this, other); + return *this; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +bool Isds::Envelope::operator==(const Envelope &other) const +{ + Q_D(const Envelope); + 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::Envelope::operator!=(const Envelope &other) const +{ + return !operator==(other); +} + +bool Isds::Envelope::isNull(void) const +{ + Q_D(const Envelope); + return d == Q_NULLPTR; +} + +qint64 Isds::Envelope::dmId(void) const +{ + bool ok = false; + qint64 id = string2NonNegativeLong(dmID(), &ok); + return ok ? id : -1; +} + +void Isds::Envelope::setDmId(qint64 id) +{ + setDmID(nonNegativeLong2String(id)); +} + +QString Isds::Envelope::dmSenderOrgUnitNumStr(void) const +{ + return nonNegativeLong2String(dmSenderOrgUnitNum()); +} + +bool Isds::Envelope::setDmSenderOrgUnitNumStr(const QString &soun) +{ + bool ok = false; + qint64 num = string2NonNegativeLong(soun, &ok); + if (!ok) { + return false; + } + setDmSenderOrgUnitNum(num); + return true; +} + +QString Isds::Envelope::dmRecipientOrgUnitNumStr(void) const +{ + return nonNegativeLong2String(dmRecipientOrgUnitNum()); +} + +bool Isds::Envelope::setDmRecipientOrgUnitNumStr(const QString &roun) +{ + bool ok = false; + qint64 num = string2NonNegativeLong(roun, &ok); + if (!ok) { + return false; + } + setDmRecipientOrgUnitNum(num); + return true; +} + +QString Isds::Envelope::dmLegalTitleLawStr(void) const +{ + return nonNegativeLong2String(dmLegalTitleLaw()); +} + +bool Isds::Envelope::setDmLegalTitleLawStr(const QString &l) +{ + bool ok = false; + qint64 num = string2NonNegativeLong(l, &ok); + if (!ok) { + return false; + } + setDmLegalTitleLaw(num); + return true; +} + +QString Isds::Envelope::dmLegalTitleYearStr(void) const +{ + return nonNegativeLong2String(dmLegalTitleYear()); +} + +bool Isds::Envelope::setDmLegalTitleYearStr(const QString &y) +{ + bool ok = false; + qint64 num = string2NonNegativeLong(y, &ok); + if (!ok) { + return false; + } + setDmLegalTitleYear(num); + return true; +} + +const QString &Isds::Envelope::dmID(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + return d->m_dmID; +} + +void Isds::Envelope::setDmID(const QString &id) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmID = id; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Envelope::setDmID(QString &&id) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmID = id; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::Envelope::dbIDSender(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + return d->m_dbIDSender; +} + +void Isds::Envelope::setDbIDSender(const QString &sbi) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dbIDSender= sbi; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Envelope::setDbIDSender(QString &&sbi) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dbIDSender= sbi; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::Envelope::dmSender(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + return d->m_dmSender; +} + +void Isds::Envelope::setDmSender(const QString &sn) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmSender = sn; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Envelope::setDmSender(QString &&sn) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmSender = sn; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::Envelope::dmSenderAddress(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + return d->m_dmSenderAddress; +} + +void Isds::Envelope::setDmSenderAddress(const QString &sa) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmSenderAddress = sa; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Envelope::setDmSenderAddress(QString &&sa) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmSenderAddress = sa; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +enum Isds::Type::DbType Isds::Envelope::dmSenderType(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return Type::BT_NULL; + } + return d->m_dmSenderType; +} + +void Isds::Envelope::setDmSenderType(enum Type::DbType st) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmSenderType = st; +} + +const QString &Isds::Envelope::dmRecipient(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + return d->m_dmRecipient; +} + +void Isds::Envelope::setDmRecipient(const QString &rn) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmRecipient = rn; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Envelope::setDmRecipient(QString &&rn) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmRecipient = rn; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::Envelope::dmRecipientAddress(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + return d->m_dmRecipientAddress; +} + +void Isds::Envelope::setDmRecipientAddress(const QString &ra) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmRecipientAddress = ra; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Envelope::setDmRecipientAddress(QString &&ra) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmRecipientAddress = ra; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +enum Isds::Type::NilBool Isds::Envelope::dmAmbiguousRecipient(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return Type::BOOL_NULL; + } + return d->m_dmAmbiguousRecipient; +} + +void Isds::Envelope::setDmAmbiguousRecipient(enum Type::NilBool ar) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmAmbiguousRecipient = ar; +} + +quint64 Isds::Envelope::dmOrdinal(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return 0; + } + return d->m_dmOrdinal; +} + +void Isds::Envelope::setDmOrdinal(quint64 o) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmOrdinal = o; +} + +enum Isds::Type::DmState Isds::Envelope::dmMessageStatus(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return Type::MS_NULL; + } + return d->m_dmMessageStatus; +} + +void Isds::Envelope::setDmMessageStatus(enum Type::DmState s) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmMessageStatus = s; +} + +qint64 Isds::Envelope::dmAttachmentSize(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return -1; + } + return d->m_dmAttachmentSize; +} + +void Isds::Envelope::setDmAttachmentSize(qint64 as) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmAttachmentSize = as; +} + +const QDateTime &Isds::Envelope::dmDeliveryTime(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullDateTime; + } + return d->m_dmDeliveryTime; +} + +void Isds::Envelope::setDmDeliveryTime(const QDateTime &dt) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmDeliveryTime = dt; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Envelope::setDmDeliveryTime(QDateTime &&dt) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmDeliveryTime = dt; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QDateTime &Isds::Envelope::dmAcceptanceTime(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullDateTime; + } + return d->m_dmAcceptanceTime; +} + +void Isds::Envelope::setDmAcceptanceTime(const QDateTime &at) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmAcceptanceTime = at; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Envelope::setDmAcceptanceTime(QDateTime &&at) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmAcceptanceTime = at; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const Isds::Hash &Isds::Envelope::dmHash(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullHash; + } + return d->m_dmHash; +} + +void Isds::Envelope::setDmHash(const Hash &h) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmHash = h; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Envelope::setDmHash(Hash &&h) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmHash = h; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QByteArray &Isds::Envelope::dmQTimestamp(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullByteArray; + } + return d->m_dmQTimestamp; +} + +void Isds::Envelope::setDmQTimestamp(const QByteArray &ts) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmQTimestamp = ts; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Envelope::setDmQTimestamp(QByteArray &&ts) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmQTimestamp = ts; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QList &Isds::Envelope::dmEvents(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullEventList; + } + return d->m_dmEvents; +} + +void Isds::Envelope::setDmEvents(const QList &el) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmEvents = el; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Envelope::setDmEvents(QList &&el) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmEvents = el; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::Envelope::dmSenderOrgUnit(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + return d->m_dmSenderOrgUnit; +} + +void Isds::Envelope::setDmSenderOrgUnit(const QString &sou) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmSenderOrgUnit = sou; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Envelope::setDmSenderOrgUnit(QString &&sou) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmSenderOrgUnit = sou; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +qint64 Isds::Envelope::dmSenderOrgUnitNum(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return -1; + } + return d->m_dmSenderOrgUnitNum; +} + +void Isds::Envelope::setDmSenderOrgUnitNum(qint64 soun) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmSenderOrgUnitNum = (soun >= 0) ? soun : -1; +} + +const QString &Isds::Envelope::dbIDRecipient(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + return d->m_dbIDRecipient; +} + +void Isds::Envelope::setDbIDRecipient(const QString &rbi) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dbIDRecipient = rbi; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Envelope::setDbIDRecipient(QString &&rbi) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dbIDRecipient = rbi; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::Envelope::dmRecipientOrgUnit(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + return d->m_dmRecipientOrgUnit; +} + +void Isds::Envelope::setDmRecipientOrgUnit(const QString &rou) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmRecipientOrgUnit = rou; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Envelope::setDmRecipientOrgUnit(QString &&rou) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmRecipientOrgUnit = rou; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +qint64 Isds::Envelope::dmRecipientOrgUnitNum(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return -1; + } + return d->m_dmRecipientOrgUnitNum; +} + +void Isds::Envelope::setDmRecipientOrgUnitNum(qint64 roun) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmRecipientOrgUnitNum = (roun >= 0) ? roun : -1; +} + +const QString &Isds::Envelope::dmToHands(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + return d->m_dmToHands; +} + +void Isds::Envelope::setDmToHands(const QString &th) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmToHands = th; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Envelope::setDmToHands(QString &&th) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmToHands = th; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::Envelope::dmAnnotation(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + return d->m_dmAnnotation; +} + +void Isds::Envelope::setDmAnnotation(const QString &a) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmAnnotation = a; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Envelope::setDmAnnotation(QString &&a) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmAnnotation = a; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::Envelope::dmRecipientRefNumber(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + return d->m_dmRecipientRefNumber; +} + +void Isds::Envelope::setDmRecipientRefNumber(const QString &rrn) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmRecipientRefNumber = rrn; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Envelope::setDmRecipientRefNumber(QString &&rrn) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmRecipientRefNumber = rrn; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::Envelope::dmSenderRefNumber(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + return d->m_dmSenderRefNumber; +} + +void Isds::Envelope::setDmSenderRefNumber(const QString &srn) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmSenderRefNumber = srn; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Envelope::setDmSenderRefNumber(QString &&srn) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmSenderRefNumber = srn; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::Envelope::dmRecipientIdent(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + return d->m_dmRecipientIdent; +} + +void Isds::Envelope::setDmRecipientIdent(const QString &ri) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmRecipientIdent = ri; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Envelope::setDmRecipientIdent(QString &&ri) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmRecipientIdent = ri; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::Envelope::dmSenderIdent(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + return d->m_dmSenderIdent; +} + +void Isds::Envelope::setDmSenderIdent(const QString &si) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmSenderIdent = si; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Envelope::setDmSenderIdent(QString &&si) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmSenderIdent = si; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +qint64 Isds::Envelope::dmLegalTitleLaw(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return -1; + } + return d->m_dmLegalTitleLaw; +} + +void Isds::Envelope::setDmLegalTitleLaw(qint64 l) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmLegalTitleLaw = (l >= 0) ? l : -1; +} + +qint64 Isds::Envelope::dmLegalTitleYear(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return -1; + } + return d->m_dmLegalTitleYear; +} + +void Isds::Envelope::setDmLegalTitleYear(qint64 y) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmLegalTitleYear = (y >= 0) ? y : -1; +} + +const QString &Isds::Envelope::dmLegalTitleSect(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + return d->m_dmLegalTitleSect; +} + +void Isds::Envelope::setDmLegalTitleSect(const QString &s) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmLegalTitleSect = s; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Envelope::setDmLegalTitleSect(QString &&s) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmLegalTitleSect = s; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::Envelope::dmLegalTitlePar(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + return d->m_dmLegalTitlePar; +} + +void Isds::Envelope::setDmLegalTitlePar(const QString &p) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmLegalTitlePar = p; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Envelope::setDmLegalTitlePar(QString &&p) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmLegalTitlePar = p; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::Envelope::dmLegalTitlePoint(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + return d->m_dmLegalTitlePoint; +} + +void Isds::Envelope::setDmLegalTitlePoint(const QString &p) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmLegalTitlePoint = p; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Envelope::setDmLegalTitlePoint(QString &&p) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmLegalTitlePoint = p; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +enum Isds::Type::NilBool Isds::Envelope::dmPersonalDelivery(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return Type::BOOL_NULL; + } + return d->m_dmPersonalDelivery; +} + +void Isds::Envelope::setDmPersonalDelivery(enum Type::NilBool pd) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmPersonalDelivery = pd; +} + +enum Isds::Type::NilBool Isds::Envelope::dmAllowSubstDelivery(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return Type::BOOL_NULL; + } + return d->m_dmAllowSubstDelivery; +} + +void Isds::Envelope::setDmAllowSubstDelivery(enum Type::NilBool sd) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmAllowSubstDelivery = sd; +} + +QChar Isds::Envelope::dmType(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return QChar(); + } + return d->m_dmType; +} + +void Isds::Envelope::setDmType(QChar t) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmType = t; +} + +enum Isds::Type::NilBool Isds::Envelope::dmOVM(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return Type::BOOL_NULL; + } + return d->m_dmOVM; +} + +void Isds::Envelope::setDmOVM(enum Type::NilBool ovm) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmOVM = ovm; +} + +enum Isds::Type::NilBool Isds::Envelope::dmPublishOwnID(void) const +{ + Q_D(const Envelope); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return Type::BOOL_NULL; + } + return d->m_dmPublishOwnID; +} + +void Isds::Envelope::setDmPublishOwnID(enum Type::NilBool poi) +{ + ensureEnvelopePrivate(); + Q_D(Envelope); + d->m_dmPublishOwnID = poi; +} + +enum Isds::Type::DmType Isds::Envelope::char2DmType(QChar c) +{ + if (c.isNull()) { + return Type::MT_UNKNOWN; + } + + switch (c.unicode()) { + case Isds::Type::MT_I: + case Isds::Type::MT_K: + case Isds::Type::MT_O: + case Isds::Type::MT_V: + case Isds::Type::MT_A: + case Isds::Type::MT_B: + case Isds::Type::MT_C: + case Isds::Type::MT_D: + case Isds::Type::MT_E: + case Isds::Type::MT_G: + case Isds::Type::MT_X: + case Isds::Type::MT_Y: + case Isds::Type::MT_Z: + return (Isds::Type::DmType)c.unicode(); + break; + default: + return Type::MT_UNKNOWN; + break; + } +} + +QChar Isds::Envelope::dmType2Char(enum Type::DmType t) +{ + if (t != Type::MT_UNKNOWN) { + return t; + } else { + return QChar(); + } +} + +void Isds::swap(Envelope &first, Envelope &second) Q_DECL_NOTHROW +{ + using std::swap; + swap(first.d_ptr, second.d_ptr); +} + +/*! + * @brief PIMPL Document class. + */ +class Isds::DocumentPrivate { + //Q_DISABLE_COPY(DocumentPrivate) +public: + DocumentPrivate(void) + : m_xml(false), m_binaryContent(), m_mimeType(), + m_metaType(Type::FMT_UNKNOWN), m_fileGuid(), m_upFileGuid(), + m_fileDescr(), m_format() + { } + + DocumentPrivate &operator=(const DocumentPrivate &other) Q_DECL_NOTHROW + { + m_xml = other.m_xml; + m_binaryContent = other.m_binaryContent; + m_mimeType = other.m_mimeType; + m_metaType = other.m_metaType; + m_fileGuid = other.m_fileGuid; + m_upFileGuid = other.m_upFileGuid; + m_fileDescr = other.m_fileDescr; + m_format = other.m_format; + + return *this; + } + + bool operator==(const DocumentPrivate &other) const + { + return (m_binaryContent == other.m_binaryContent) && + // (m_xmlContent == other.m_xmlContent) && + (m_mimeType == other.m_mimeType) && + (m_metaType == other.m_metaType) && + (m_fileGuid == other.m_fileGuid) && + (m_upFileGuid == other.m_upFileGuid) && + (m_fileDescr == other.m_fileDescr) && + (m_format == other.m_format); + } + + bool m_xml; /*!< Inspired by libisds. Direct XML handling is not supported yet! */ + + QByteArray m_binaryContent; + // m_xmlContent; + + QString m_mimeType; /* See pril_2/WS_ISDS_Manipulace_s_datovymi_zpravami.pdf appendix 3. */ + enum Type::FileMetaType m_metaType; + QString m_fileGuid; /* Optional message-local document identifier. */ + QString m_upFileGuid; /* Optional reference to upper document. */ + QString m_fileDescr; /* Mandatory document name. */ + QString m_format; /* Optional. Can hold a form name for loading XML data from the dmXMLContent element. */ +}; + +Isds::Document::Document(void) + : d_ptr(Q_NULLPTR) +{ +} + +Isds::Document::Document(const Document &other) + : d_ptr((other.d_func() != Q_NULLPTR) ? (new (std::nothrow) DocumentPrivate) : Q_NULLPTR) +{ + Q_D(Document); + if (d == Q_NULLPTR) { + return; + } + + *d = *other.d_func(); +} + +#ifdef Q_COMPILER_RVALUE_REFS +Isds::Document::Document(Document &&other) Q_DECL_NOEXCEPT + : d_ptr(other.d_ptr.take()) //d_ptr(std::move(other.d_ptr)) +{ +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +Isds::Document::~Document(void) +{ +} + +/*! + * @brief Ensures private document presence. + * + * @note Returns if private document could not be allocated. + */ +#define ensureDocumentPrivate(_x_) \ + do { \ + if (Q_UNLIKELY(d_ptr == Q_NULLPTR)) { \ + DocumentPrivate *p = new (std::nothrow) DocumentPrivate; \ + if (Q_UNLIKELY(p == Q_NULLPTR)) { \ + Q_ASSERT(0); \ + return _x_; \ + } \ + d_ptr.reset(p); \ + } \ + } while (0) + +Isds::Document &Isds::Document::operator=(const Document &other) Q_DECL_NOTHROW +{ + if (other.d_func() == Q_NULLPTR) { + d_ptr.reset(Q_NULLPTR); + return *this; + } + ensureDocumentPrivate(*this); + Q_D(Document); + + *d = *other.d_func(); + + return *this; +} + +#ifdef Q_COMPILER_RVALUE_REFS +Isds::Document &Isds::Document::operator=(Document &&other) Q_DECL_NOTHROW +{ + swap(*this, other); + return *this; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +bool Isds::Document::operator==(const Document &other) const +{ + Q_D(const Document); + 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::Document::operator!=(const Document &other) const +{ + return !operator==(other); +} + +bool Isds::Document::isNull(void) const +{ + Q_D(const Document); + return d == Q_NULLPTR; +} + +bool Isds::Document::isXml(void) const +{ + Q_D(const Document); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return false; + } + return d->m_xml; +} + +QString Isds::Document::base64Content(void) const +{ + const QByteArray &content(binaryContent()); + if (!content.isNull()) { + return QString::fromUtf8(content.toBase64()); + } else { + return QString(); + } +} + +void Isds::Document::setBase64Content(const QString &ec) +{ + QByteArray content; + if (!ec.isNull()) { + content = QByteArray::fromBase64(ec.toUtf8()); + } + setBinaryContent(content); +} + +const QByteArray &Isds::Document::binaryContent(void) const +{ + Q_D(const Document); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullByteArray; + } + return d->m_binaryContent; +} + +void Isds::Document::setBinaryContent(const QByteArray &bc) +{ + ensureDocumentPrivate(); + Q_D(Document); + /* Should also delete XML content if it is present. */ + d->m_binaryContent = bc; + d->m_xml = false; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Document::setBinaryContent(QByteArray &&bc) +{ + ensureDocumentPrivate(); + Q_D(Document); + /* Should also delete XML content if it is present. */ + d->m_binaryContent = bc; + d->m_xml = false; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::Document::mimeType(void) const +{ + Q_D(const Document); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + return d->m_mimeType; +} + +void Isds::Document::setMimeType(const QString &mt) +{ + ensureDocumentPrivate(); + Q_D(Document); + d->m_mimeType = mt; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Document::setMimeType(QString &&mt) +{ + ensureDocumentPrivate(); + Q_D(Document); + d->m_mimeType = mt; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +enum Isds::Type::FileMetaType Isds::Document::fileMetaType(void) const +{ + Q_D(const Document); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return Isds::Type::FMT_UNKNOWN; + } + return d->m_metaType; +} + +void Isds::Document::setFileMetaType(enum Type::FileMetaType mt) +{ + ensureDocumentPrivate(); + Q_D(Document); + d->m_metaType = mt; +} + +const QString &Isds::Document::fileGuid(void) const +{ + Q_D(const Document); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + return d->m_fileGuid; +} + +void Isds::Document::setFileGuid(const QString &g) +{ + ensureDocumentPrivate(); + Q_D(Document); + d->m_fileGuid = g; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Document::setFileGuid(QString &&g) +{ + ensureDocumentPrivate(); + Q_D(Document); + d->m_fileGuid = g; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::Document::upFileGuid(void) const +{ + Q_D(const Document); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + return d->m_upFileGuid; +} + +void Isds::Document::setUpFileGuid(const QString &ug) +{ + ensureDocumentPrivate(); + Q_D(Document); + d->m_upFileGuid = ug; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Document::setUpFileGuid(QString &&ug) +{ + ensureDocumentPrivate(); + Q_D(Document); + d->m_upFileGuid = ug; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::Document::fileDescr(void) const +{ + Q_D(const Document); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + return d->m_fileDescr; +} + +void Isds::Document::setFileDescr(const QString &fd) +{ + ensureDocumentPrivate(); + Q_D(Document); + d->m_fileDescr = fd; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Document::setFileDescr(QString &&fd) +{ + ensureDocumentPrivate(); + Q_D(Document); + d->m_fileDescr = fd; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QString &Isds::Document::format(void) const +{ + Q_D(const Document); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullString; + } + return d->m_format; +} + +void Isds::Document::setFormat(const QString &f) +{ + ensureDocumentPrivate(); + Q_D(Document); + d->m_format = f; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Document::setFormat(QString &&f) +{ + ensureDocumentPrivate(); + Q_D(Document); + d->m_format = f; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +void Isds::swap(Document &first, Document &second) Q_DECL_NOTHROW +{ + using std::swap; + swap(first.d_ptr, second.d_ptr); +} + +/*! + * @brief PIMPL Message class. + */ +class Isds::MessagePrivate { + //Q_DISABLE_COPY(MessagePrivate) +public: + MessagePrivate(void) + : m_raw(), m_rawType(Type::RT_UNKNOWN), m_envelope(), m_documents() + { } + + MessagePrivate &operator=(const MessagePrivate &other) Q_DECL_NOTHROW + { + m_raw = other.m_raw; + m_rawType = other.m_rawType; + // m_xml + m_envelope = other.m_envelope; + m_documents = other.m_documents; + + return *this; + } + + bool operator==(const MessagePrivate &other) const + { + return (m_raw == other.m_raw) && + (m_rawType == other.m_rawType) && + // (m_xml == other.m_xml) && + (m_envelope == other.m_envelope) && + (m_documents == other.m_documents); + } + + QByteArray m_raw; + enum Type::RawType m_rawType; + // m_xml; /* Does not support direct XML access yet. */ + + Envelope m_envelope; + QList m_documents; +}; + +Isds::Message::Message(void) + : d_ptr(Q_NULLPTR) +{ +} + +Isds::Message::Message(const Message &other) + : d_ptr((other.d_func() != Q_NULLPTR) ? (new (std::nothrow) MessagePrivate) : Q_NULLPTR) +{ + Q_D(Message); + if (d == Q_NULLPTR) { + return; + } + + *d = *other.d_func(); +} + +#ifdef Q_COMPILER_RVALUE_REFS +Isds::Message::Message(Message &&other) Q_DECL_NOEXCEPT + : d_ptr(other.d_ptr.take()) //d_ptr(std::move(other.d_ptr)) +{ +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +Isds::Message::~Message(void) +{ +} + +/*! + * @brief Ensures private message presence. + * + * @note Returns if private message could not be allocated. + */ +#define ensureMessagePrivate(_x_) \ + do { \ + if (Q_UNLIKELY(d_ptr == Q_NULLPTR)) { \ + MessagePrivate *p = new (std::nothrow) MessagePrivate; \ + if (Q_UNLIKELY(p == Q_NULLPTR)) { \ + Q_ASSERT(0); \ + return _x_; \ + } \ + d_ptr.reset(p); \ + } \ + } while (0) + +Isds::Message &Isds::Message::operator=(const Message &other) Q_DECL_NOTHROW +{ + if (other.d_func() == Q_NULLPTR) { + d_ptr.reset(Q_NULLPTR); + return *this; + } + ensureMessagePrivate(*this); + Q_D(Message); + + *d = *other.d_func(); + + return *this; +} + +#ifdef Q_COMPILER_RVALUE_REFS +Isds::Message &Isds::Message::operator=(Message &&other) Q_DECL_NOTHROW +{ + swap(*this, other); + return *this; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +bool Isds::Message::operator==(const Message &other) const +{ + Q_D(const Message); + 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::Message::operator!=(const Message &other) const +{ + return !operator==(other); +} + +bool Isds::Message::isNull(void) const +{ + Q_D(const Message); + return d == Q_NULLPTR; +} + +const QByteArray &Isds::Message::raw(void) const +{ + Q_D(const Message); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullByteArray; + } + + return d->m_raw; +} + +void Isds::Message::setRaw(const QByteArray &r) +{ + ensureMessagePrivate(); + Q_D(Message); + d->m_raw = r; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Message::setRaw(QByteArray &&r) +{ + ensureMessagePrivate(); + Q_D(Message); + d->m_raw = r; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +enum Isds::Type::RawType Isds::Message::rawType(void) const +{ + Q_D(const Message); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return Isds::Type::RT_UNKNOWN; + } + + return d->m_rawType; +} + +void Isds::Message::setRawType(enum Type::RawType t) +{ + ensureMessagePrivate(); + Q_D(Message); + d->m_rawType = t; +} + +const Isds::Envelope &Isds::Message::envelope(void) const +{ + Q_D(const Message); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullEnvelope; + } + + return d->m_envelope; +} + +void Isds::Message::setEnvelope(const Envelope &e) +{ + ensureMessagePrivate(); + Q_D(Message); + d->m_envelope = e; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Message::setEnvelope(Envelope &&e) +{ + ensureMessagePrivate(); + Q_D(Message); + d->m_envelope = e; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +const QList &Isds::Message::documents(void) const +{ + Q_D(const Message); + if (Q_UNLIKELY(d == Q_NULLPTR)) { + return nullDocumentList; + } + + return d->m_documents; +} + +void Isds::Message::setDocuments(const QList &dl) +{ + ensureMessagePrivate(); + Q_D(Message); + d->m_documents = dl; +} + +#ifdef Q_COMPILER_RVALUE_REFS +void Isds::Message::setDocuments(QList &&dl) +{ + ensureMessagePrivate(); + Q_D(Message); + d->m_documents = dl; +} +#endif /* Q_COMPILER_RVALUE_REFS */ + +void Isds::swap(Message &first, Message &second) Q_DECL_NOTHROW +{ + using std::swap; + swap(first.d_ptr, second.d_ptr); +} diff --git a/src/datovka_shared/isds/message_interface.h b/src/datovka_shared/isds/message_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..ef21caa20c54f977fc05591fb31d3b445fd31d8a --- /dev/null +++ b/src/datovka_shared/isds/message_interface.h @@ -0,0 +1,554 @@ +/* + * 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 . + * + * 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 +#include +#include +#include +#include +#include + +#include "src/datovka_shared/isds/types.h" + +/* + * https://stackoverflow.com/questions/25250171/how-to-use-the-qts-pimpl-idiom + * + * QScopedPtr -> std::unique_ptr ? + */ + +/* + * Structures originating from pril_2/WS_ISDS_Manipulace_s_datovymi_zpravami.pdf. + */ + +namespace Isds { + + class HashPrivate; + /*! + * @brief Described in dmBaseTypes.xsd as type tHash + */ + class Hash { + Q_DECLARE_PRIVATE(Hash) + + public: + Hash(void); + Hash(const Hash &other); +#ifdef Q_COMPILER_RVALUE_REFS + Hash(Hash &&other) Q_DECL_NOEXCEPT; +#endif /* Q_COMPILER_RVALUE_REFS */ + ~Hash(void); + + Hash &operator=(const Hash &other) Q_DECL_NOTHROW; +#ifdef Q_COMPILER_RVALUE_REFS + Hash &operator=(Hash &&other) Q_DECL_NOTHROW; +#endif /* Q_COMPILER_RVALUE_REFS */ + + bool operator==(const Hash &other) const; + bool operator!=(const Hash &other) const; + + friend void swap(Hash &first, Hash &second) Q_DECL_NOTHROW; + + bool isNull(void) const; + + /* + * Convenience method. Access value as base64-encoded string. + */ + QString base64Value(void) const; + void setBase64Value(const QString &ev); + + /* algorithm */ + enum Type::HashAlg algorithm(void) const; + void setAlgorithm(enum Type::HashAlg a); + /* __item (binary representation) */ + const QByteArray &value(void) const; + void setValue(const QByteArray &v); +#ifdef Q_COMPILER_RVALUE_REFS + void setValue(QByteArray &&v); +#endif /* Q_COMPILER_RVALUE_REFS */ + + friend Hash libisds2hash(const struct isds_hash *ih, bool *ok); + + private: + QScopedPointer d_ptr; // std::unique_ptr ? + }; + + void swap(Hash &first, Hash &second) Q_DECL_NOTHROW; + + class EventPrivate; + /*! + * @brief Described in dmBaseTypes.xsd as type tEvent. + */ + class Event { + Q_DECLARE_PRIVATE(Event) + + public: + Event(void); + Event(const Event &other); +#ifdef Q_COMPILER_RVALUE_REFS + Event(Event &&other) Q_DECL_NOEXCEPT; +#endif /* Q_COMPILER_RVALUE_REFS */ + ~Event(void); + + Event &operator=(const Event &other) Q_DECL_NOTHROW; +#ifdef Q_COMPILER_RVALUE_REFS + Event &operator=(Event &&other) Q_DECL_NOTHROW; +#endif /* Q_COMPILER_RVALUE_REFS */ + + bool operator==(const Event &other) const; + bool operator!=(const Event &other) const; + + friend void swap(Event &first, Event &second) Q_DECL_NOTHROW; + + bool isNull(void) const; + + /* + * Convenience method. Sets type and descrpition from full text. + */ + void setFromText(const QString &t); + + const QDateTime &time(void) const; + void setTime(const QDateTime &t); +#ifdef Q_COMPILER_RVALUE_REFS + void setTime(QDateTime &&t); +#endif /* Q_COMPILER_RVALUE_REFS */ + enum Type::Event type(void) const; + void setType(enum Type::Event et); /* Type should be determined from description. */ + const QString &descr(void) const; + void setDescr(const QString &descr); +#ifdef Q_COMPILER_RVALUE_REFS + void setDescr(QString &&descr); +#endif /* Q_COMPILER_RVALUE_REFS */ + + /* Converts even type to string. */ + static + const QString &type2string(enum Type::Event type); + + friend Event libisds2event(const struct isds_event *ie, + bool *ok); + + private: + QScopedPointer d_ptr; // std::unique_ptr ? + }; + + void swap(Event &first, Event &second) Q_DECL_NOTHROW; + + class EnvelopePrivate; + /*! + * @brief Described in dmBaseTypes.xsd as group gMessageEnvelope + * pril_2/WS_ISDS_Manipulace_s_datovymi_zpravami.pdf + * section 2.1 (CreateMessage), section 2.4 (MessageDownload, SignedMessageDownload) + */ + class Envelope { + Q_DECLARE_PRIVATE(Envelope) + + public: + Envelope(void); + Envelope(const Envelope &other); +#ifdef Q_COMPILER_RVALUE_REFS + Envelope(Envelope &&other) Q_DECL_NOEXCEPT; +#endif /* Q_COMPILER_RVALUE_REFS */ + ~Envelope(void); + + Envelope &operator=(const Envelope &other) Q_DECL_NOTHROW; +#ifdef Q_COMPILER_RVALUE_REFS + Envelope &operator=(Envelope &&other) Q_DECL_NOTHROW; +#endif /* Q_COMPILER_RVALUE_REFS */ + + bool operator==(const Envelope &other) const; + bool operator!=(const Envelope &other) const; + + friend void swap(Envelope &first, Envelope &second) Q_DECL_NOTHROW; + + bool isNull(void) const; + + /* + * For convenience purposes. Message identifier consists only + * of digits, but documentation explicitly states that it is + * a max. 20 chars old string. + * + * Returns -1 if conversion to number fails. + */ + qint64 dmId(void) const; + void setDmId(qint64 id); + /* + * Convenience methods for number to string conversion. + */ + QString dmSenderOrgUnitNumStr(void) const; + bool setDmSenderOrgUnitNumStr(const QString &soun); + QString dmRecipientOrgUnitNumStr(void) const; + bool setDmRecipientOrgUnitNumStr(const QString &roun); + QString dmLegalTitleLawStr(void) const; + bool setDmLegalTitleLawStr(const QString &l); + QString dmLegalTitleYearStr(void) const; + bool setDmLegalTitleYearStr(const QString &y); + + /* dmID */ + const QString &dmID(void) const; + void setDmID(const QString &id); +#ifdef Q_COMPILER_RVALUE_REFS + void setDmID(QString &&id); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dbIDSender -- sender box identifier, max. 7 characters */ + const QString &dbIDSender(void) const; + void setDbIDSender(const QString &sbi); +#ifdef Q_COMPILER_RVALUE_REFS + void setDbIDSender(QString &&sbi); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmSender -- sender name, max. 100 characters */ + const QString &dmSender(void) const; + void setDmSender(const QString &sn); +#ifdef Q_COMPILER_RVALUE_REFS + void setDmSender(QString &&sn); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmSenderAddress -- sender address, max. 100 characters */ + const QString &dmSenderAddress(void) const; + void setDmSenderAddress(const QString &sa); +#ifdef Q_COMPILER_RVALUE_REFS + void setDmSenderAddress(QString &&sa); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmSenderType -- roughly specified sender box type */ + enum Type::DbType dmSenderType(void) const; + void setDmSenderType(enum Type::DbType st); + /* dmRecipient -- recipient name, max. 100 characters */ + const QString &dmRecipient(void) const; + void setDmRecipient(const QString &rn); +#ifdef Q_COMPILER_RVALUE_REFS + void setDmRecipient(QString &&rn); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmRecipientAddress -- recipient address, max. 100 characters */ + const QString &dmRecipientAddress(void) const; + void setDmRecipientAddress(const QString &ra); +#ifdef Q_COMPILER_RVALUE_REFS + void setDmRecipientAddress(QString &&ra); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmAmbiguousRecipient -- optional, recipient has elevated OVM role */ + enum Type::NilBool dmAmbiguousRecipient(void) const; + void setDmAmbiguousRecipient(enum Type::NilBool ar); + + /* dmOrdinal -- defined in ns1__tRecord (dmBaseTypes.xsd), ordinal number in list of messages */ + quint64 dmOrdinal(void) const; + void setDmOrdinal(quint64 o); + /* dmMessageStatus -- message state */ + enum Type::DmState dmMessageStatus(void) const; + void setDmMessageStatus(enum Type::DmState s); + /* dmAttachmentSize -- rounded size in kB */ + qint64 dmAttachmentSize(void) const; + void setDmAttachmentSize(qint64 as); + /* dmDeliveryTime */ + const QDateTime &dmDeliveryTime(void) const; + void setDmDeliveryTime(const QDateTime &dt); +#ifdef Q_COMPILER_RVALUE_REFS + void setDmDeliveryTime(QDateTime &&dt); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmAcceptanceTime */ + const QDateTime &dmAcceptanceTime(void) const; + void setDmAcceptanceTime(const QDateTime &at); +#ifdef Q_COMPILER_RVALUE_REFS + void setDmAcceptanceTime(QDateTime &&at); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmHash */ + const Hash &dmHash(void) const; + void setDmHash(const Hash &h); +#ifdef Q_COMPILER_RVALUE_REFS + void setDmHash(Hash &&h); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmQTimestamp -- qualified time stamp, optional */ + const QByteArray &dmQTimestamp(void) const; + void setDmQTimestamp(const QByteArray &ts); +#ifdef Q_COMPILER_RVALUE_REFS + void setDmQTimestamp(QByteArray &&ts); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmEvents -- list of events the message has passed through. */ + const QList &dmEvents(void) const; + void setDmEvents(const QList &el); +#ifdef Q_COMPILER_RVALUE_REFS + void setDmEvents(QList &&el); +#endif /* Q_COMPILER_RVALUE_REFS */ + + /* dmSenderOrgUnit -- sender organisation unit, optional */ + const QString &dmSenderOrgUnit(void) const; + void setDmSenderOrgUnit(const QString &sou); +#ifdef Q_COMPILER_RVALUE_REFS + void setDmSenderOrgUnit(QString &&sou); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmSenderOrgUnitNum */ + qint64 dmSenderOrgUnitNum(void) const; + void setDmSenderOrgUnitNum(qint64 soun); + /* dbIDRecipient -- recipient box identifier, max. 7 characters, mandatory */ + const QString &dbIDRecipient(void) const; + void setDbIDRecipient(const QString &rbi); +#ifdef Q_COMPILER_RVALUE_REFS + void setDbIDRecipient(QString &&rbi); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmRecipientOrgUnit -- recipient organisation unit, optional */ + const QString &dmRecipientOrgUnit(void) const; + void setDmRecipientOrgUnit(const QString &rou); +#ifdef Q_COMPILER_RVALUE_REFS + void setDmRecipientOrgUnit(QString &&rou); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmRecipientOrgUnitNum */ + qint64 dmRecipientOrgUnitNum(void) const; + void setDmRecipientOrgUnitNum(qint64 roun); + /* dmToHands -- optional */ + const QString &dmToHands(void) const; + void setDmToHands(const QString &th); +#ifdef Q_COMPILER_RVALUE_REFS + void setDmToHands(QString &&th); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmAnnotation -- subject/title, mac 255 characters */ + const QString &dmAnnotation(void) const; + void setDmAnnotation(const QString &a); +#ifdef Q_COMPILER_RVALUE_REFS + void setDmAnnotation(QString &&a); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmRecipientRefNumber -- recipient reference identifier, max. 50 characters, optional */ + const QString &dmRecipientRefNumber(void) const; + void setDmRecipientRefNumber(const QString &rrn); +#ifdef Q_COMPILER_RVALUE_REFS + void setDmRecipientRefNumber(QString &&rrn); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmSenderRefNumber -- sender reference identifier, max. 50 characters, optional */ + const QString &dmSenderRefNumber(void) const; + void setDmSenderRefNumber(const QString &srn); +#ifdef Q_COMPILER_RVALUE_REFS + void setDmSenderRefNumber(QString &&srn); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmRecipientIdent -- CZ: spisova znacka, DE: Aktenzeichen, max. 50 characters, optional */ + const QString &dmRecipientIdent(void) const; + void setDmRecipientIdent(const QString &ri); +#ifdef Q_COMPILER_RVALUE_REFS + void setDmRecipientIdent(QString &&ri); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmSenderIdent */ + const QString &dmSenderIdent(void) const; + void setDmSenderIdent(const QString &si); +#ifdef Q_COMPILER_RVALUE_REFS + void setDmSenderIdent(QString &&si); +#endif /* Q_COMPILER_RVALUE_REFS */ + + /* Act addressing. */ + /* dmLegalTitleLaw */ + qint64 dmLegalTitleLaw(void) const; + void setDmLegalTitleLaw(qint64 l); + /* dmLegalTitleYear */ + qint64 dmLegalTitleYear(void) const; + void setDmLegalTitleYear(qint64 y); + /* dmLegalTitleSect */ + const QString &dmLegalTitleSect(void) const; + void setDmLegalTitleSect(const QString &s); +#ifdef Q_COMPILER_RVALUE_REFS + void setDmLegalTitleSect(QString &&s); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmLegalTitlePar */ + const QString &dmLegalTitlePar(void) const; + void setDmLegalTitlePar(const QString &p); +#ifdef Q_COMPILER_RVALUE_REFS + void setDmLegalTitlePar(QString &&p); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmLegalTitlePoint -- CZ: pismeno, DE: Buchstabe */ + const QString &dmLegalTitlePoint(void) const; + void setDmLegalTitlePoint(const QString &p); +#ifdef Q_COMPILER_RVALUE_REFS + void setDmLegalTitlePoint(QString &&p); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmPersonalDelivery -- only for recipient or person with explicitly granted privileges */ + enum Type::NilBool dmPersonalDelivery(void) const; + void setDmPersonalDelivery(enum Type::NilBool pd); + /* dmAllowSubstDelivery -- substitutionary delivery, only for some recipients, e.g. courts */ + enum Type::NilBool dmAllowSubstDelivery(void) const; + void setDmAllowSubstDelivery(enum Type::NilBool sd); + /* dmType -- message type */ + QChar dmType(void) const; + void setDmType(QChar t); + + /* Outgoing messages only. */ + /* dmOVM */ + enum Type::NilBool dmOVM(void) const; + void setDmOVM(enum Type::NilBool ovm); + /* dmPublishOwnID */ + enum Type::NilBool dmPublishOwnID(void) const; + void setDmPublishOwnID(enum Type::NilBool poi); + + /* Convenience conversion functions. */ + static + enum Type::DmType char2DmType(QChar c); + static + QChar dmType2Char(enum Type::DmType t); + + friend Envelope libisds2envelope(const struct isds_envelope *ie, + bool *ok); + + private: + QScopedPointer d_ptr; // std::unique_ptr ? + }; + + void swap(Envelope &first, Envelope &second) Q_DECL_NOTHROW; + + class DocumentPrivate; + /*! + * @brief Described in dmBaseTypes.xsd as type tFilesArray_dmFile. + * pril_2/WS_ISDS_Manipulace_s_datovymi_zpravami.pdf + * section 2.1 (CreateMessage). + */ + class Document { + Q_DECLARE_PRIVATE(Document) + + public: + Document(void); + Document(const Document &other); +#ifdef Q_COMPILER_RVALUE_REFS + Document(Document &&other) Q_DECL_NOEXCEPT; +#endif /* Q_COMPILER_RVALUE_REFS */ + ~Document(void); + + Document &operator=(const Document &other) Q_DECL_NOTHROW; +#ifdef Q_COMPILER_RVALUE_REFS + Document &operator=(Document &&other) Q_DECL_NOTHROW; +#endif /* Q_COMPILER_RVALUE_REFS */ + + bool operator==(const Document &other) const; + bool operator!=(const Document &other) const; + + friend void swap(Document &first, Document &second) Q_DECL_NOTHROW; + + bool isNull(void) const; + + /* + * Convenience method. Access content as base64-encoded string. + */ + QString base64Content(void) const; + void setBase64Content(const QString &ec); + + bool isXml(void) const; /* Inspired by libisds. */ + + const QByteArray &binaryContent(void) const; + void setBinaryContent(const QByteArray &bc); +#ifdef Q_COMPILER_RVALUE_REFS + void setBinaryContent(QByteArray &&bc); +#endif /* Q_COMPILER_RVALUE_REFS */ + + /* dmMimeType */ + const QString &mimeType(void) const; + void setMimeType(const QString &mt); +#ifdef Q_COMPILER_RVALUE_REFS + void setMimeType(QString &&mt); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmFileMetaType */ + enum Type::FileMetaType fileMetaType(void) const; + void setFileMetaType(enum Type::FileMetaType mt); + /* dmFileGuid */ + const QString &fileGuid(void) const; + void setFileGuid(const QString &g); +#ifdef Q_COMPILER_RVALUE_REFS + void setFileGuid(QString &&g); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmUpFileGuid */ + const QString &upFileGuid(void) const; + void setUpFileGuid(const QString &ug); +#ifdef Q_COMPILER_RVALUE_REFS + void setUpFileGuid(QString &&ug); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmFileDescr */ + const QString &fileDescr(void) const; + void setFileDescr(const QString &fd); +#ifdef Q_COMPILER_RVALUE_REFS + void setFileDescr(QString &&fd); +#endif /* Q_COMPILER_RVALUE_REFS */ + /* dmFormat */ + const QString &format(void) const; + void setFormat(const QString &f); +#ifdef Q_COMPILER_RVALUE_REFS + void setFormat(QString &&f); +#endif /* Q_COMPILER_RVALUE_REFS */ + + friend Document libisds2document(const struct isds_document *id, + bool *ok); + + private: + QScopedPointer d_ptr; // std::unique_ptr ? + }; + + void swap(Document &first, Document &second) Q_DECL_NOTHROW; + + class MessagePrivate; + /*! + * @Brief Described in dmBaseTypes.xsd as type tReturnedMessage. + * pril_2/WS_ISDS_Manipulace_s_datovymi_zpravami.pdf + * section 2.1 (CreateMessage). + */ + class Message { + Q_DECLARE_PRIVATE(Message) + + public: + Message(void); + Message(const Message &other); +#ifdef Q_COMPILER_RVALUE_REFS + Message(Message &&other) Q_DECL_NOEXCEPT; +#endif /* Q_COMPILER_RVALUE_REFS */ + ~Message(void); + + Message &operator=(const Message &other) Q_DECL_NOTHROW; +#ifdef Q_COMPILER_RVALUE_REFS + Message &operator=(Message &&other) Q_DECL_NOTHROW; +#endif /* Q_COMPILER_RVALUE_REFS */ + + bool operator==(const Message &other) const; + bool operator!=(const Message &other) const; + + friend void swap(Message &first, Message &second) Q_DECL_NOTHROW; + + bool isNull(void) const; + + /* Raw message data. */ + const QByteArray &raw(void) const; + void setRaw(const QByteArray &r); +#ifdef Q_COMPILER_RVALUE_REFS + void setRaw(QByteArray &&r); +#endif /* Q_COMPILER_RVALUE_REFS */ + + enum Type::RawType rawType(void) const; + void setRawType(enum Type::RawType t); + + const Envelope &envelope(void) const; + void setEnvelope(const Envelope &e); +#ifdef Q_COMPILER_RVALUE_REFS + void setEnvelope(Envelope &&e); +#endif /* Q_COMPILER_RVALUE_REFS */ + + const QList &documents(void) const; + void setDocuments(const QList &dl); +#ifdef Q_COMPILER_RVALUE_REFS + void setDocuments(QList &&dl); +#endif /* Q_COMPILER_RVALUE_REFS */ + + friend Message libisds2message(const struct isds_message *im, + bool *ok); + + private: + QScopedPointer d_ptr; // std::unique_ptr ? + }; + + void swap(Message &first, Message &second) Q_DECL_NOTHROW; + +} diff --git a/src/datovka_shared/isds/type_conversion.cpp b/src/datovka_shared/isds/type_conversion.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5741c759f0a938e09dc2d5ba7f40edf17a520a15 --- /dev/null +++ b/src/datovka_shared/isds/type_conversion.cpp @@ -0,0 +1,622 @@ +/* + * 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 . + * + * 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/type_conversion.h" + +qint64 Isds::variant2nonNegativeLong(const QVariant &v) +{ + if (v.isNull()) { + return -1; + } + + bool ok = false; + qint64 num = v.toLongLong(&ok); + if ((!ok) || (num < 0)) { + return -1; + } + + return num; +} + +QVariant Isds::nonNegativeLong2Variant(qint64 i) +{ + return (i >= 0) ? QVariant(i) : QVariant(); +} + +enum Isds::Type::NilBool Isds::variant2NilBool(const QVariant &v) +{ + if (v.isNull()) { + return Type::BOOL_NULL; + } + + return v.toBool() ? Type::BOOL_TRUE : Type::BOOL_FALSE; +} + +QVariant Isds::nilBool2Variant(enum Type::NilBool b) +{ + if (b == Type::BOOL_NULL) { + return QVariant(); + } else { + return QVariant(b == Type::BOOL_TRUE); + } +} + +enum Isds::Type::DbType Isds::long2DbType(long int bt, bool *ok) +{ + bool iOk = true; + enum Type::DbType type = Type::BT_SYSTEM; + + switch (bt) { + case Type::BT_SYSTEM: type = Type::BT_SYSTEM; break; + case Type::BT_OVM: type = Type::BT_OVM; break; + case Type::BT_OVM_NOTAR: type = Type::BT_OVM_NOTAR; break; + case Type::BT_OVM_EXEKUT: type = Type::BT_OVM_EXEKUT; break; + case Type::BT_OVM_REQ: type = Type::BT_OVM_REQ; break; + case Type::BT_OVM_FO: type = Type::BT_OVM_FO; break; + case Type::BT_OVM_PFO: type = Type::BT_OVM_PFO; break; + case Type::BT_OVM_PO: type = Type::BT_OVM_PO; break; + case Type::BT_PO: type = Type::BT_PO; break; + case Type::BT_PO_ZAK: type = Type::BT_PO_ZAK; break; + case Type::BT_PO_REQ: type = Type::BT_PO_REQ; break; + case Type::BT_PFO: type = Type::BT_PFO; break; + case Type::BT_PFO_ADVOK: type = Type::BT_PFO_ADVOK; break; + case Type::BT_PFO_DANPOR: type = Type::BT_PFO_DANPOR; break; + case Type::BT_PFO_INSSPR: type = Type::BT_PFO_INSSPR; break; + case Type::BT_PFO_AUDITOR: type = Type::BT_PFO_AUDITOR; break; + case Type::BT_FO: type = Type::BT_FO; break; + default: + Q_ASSERT(0); + iOk = false; + break; + } + + if (ok != Q_NULLPTR) { + *ok = iOk; + } + return type; +} + +enum Isds::Type::DbType Isds::intVariant2DbType(const QVariant &v) +{ + if (v.isNull()) { + return Type::BT_NULL; + } + + bool ok = false; + qint64 num = v.toLongLong(&ok); + if (Q_UNLIKELY(!ok)) { + Q_ASSERT(0); + return Type::BT_NULL; + } + + return long2DbType(num); +} + +QVariant Isds::dbType2IntVariant(enum Type::DbType bt) +{ + if (bt == Type::BT_NULL) { + return QVariant(); + } else { + return QVariant((int)bt); + } +} + +static const QString strNull; + +/* + * OVM_MAIN is a special value introduced in git version of libisds. + * It appears not to be included in officially released source packages. + * TODO -- Check the function of OVM_MAIN. + */ +static const QString strOvmMain("OVM_MAIN"); /* hlavni schranky */ +static const QString strSystem("SYSTEM"), + strOvm("OVM"), strOvmNotar("OVM_NOTAR"), strOvmExekut("OVM_EXEKUT"), + strOvmReq("OVM_REQ"), strOvmFo("OVM_FO"), strOvmPfo("OVM_PFO"), + strOvmPo("OVM_PO"), strPo("PO"), strPoZak("PO_ZAK"), strPoReq("PO_REQ"), + strPfo("PFO"), strPfoAdvok("PFO_ADVOK"), strPfoDanpor("PFO_DANPOR"), + strPfoInsspr("PFO_INSSPR"), strPfoAuditor("PFO_AUDITOR"), strFo("FO"); + +enum Isds::Type::DbType Isds::str2DbType(const QString &s) +{ + if (s.isNull()) { + return Type::BT_NULL; + } else if (s == strSystem) { + return Type::BT_SYSTEM; + } else if (s == strOvm) { + return Type::BT_OVM; + } else if (s == strOvmNotar) { + return Type::BT_OVM_NOTAR; + } else if (s == strOvmExekut) { + return Type::BT_OVM_EXEKUT; + } else if (s == strOvmReq) { + return Type::BT_OVM_REQ; + } else if (s == strOvmFo) { + return Type::BT_OVM_FO; + } else if (s == strOvmPfo) { + return Type::BT_OVM_PFO; + } else if (s == strOvmPo) { + return Type::BT_OVM_PO; + } else if (s == strPo) { + return Type::BT_PO; + } else if (s == strPoZak) { + return Type::BT_PO_ZAK; + } else if (s == strPoReq) { + return Type::BT_PO_REQ; + } else if (s == strPfo) { + return Type::BT_PFO; + } else if (s == strPfoAdvok) { + return Type::BT_PFO_ADVOK; + } else if (s == strPfoDanpor) { + return Type::BT_PFO_DANPOR; + } else if (s == strPfoInsspr) { + return Type::BT_PFO_INSSPR; + } else if (s == strPfoAuditor) { + return Type::BT_PFO_AUDITOR; + } else if (s == strFo) { + return Type::BT_FO; + } else { + Q_ASSERT(0); + return Type::BT_NULL; + } +} + +const QString &Isds::dbType2Str(enum Type::DbType bt) +{ + switch (bt) { + case Type::BT_NULL: return strNull; break; + case Type::BT_SYSTEM: return strSystem; break; + case Type::BT_OVM: return strOvm; break; + case Type::BT_OVM_NOTAR: return strOvmNotar; break; + case Type::BT_OVM_EXEKUT: return strOvmExekut; break; + case Type::BT_OVM_REQ: return strOvmReq; break; + case Type::BT_OVM_FO: return strOvmFo; break; + case Type::BT_OVM_PFO: return strOvmPfo; break; + case Type::BT_OVM_PO: return strOvmPo; break; + case Type::BT_PO: return strPo; break; + case Type::BT_PO_ZAK: return strPoZak; break; + case Type::BT_PO_REQ: return strPoReq; break; + case Type::BT_PFO: return strPfo; break; + case Type::BT_PFO_ADVOK: return strPfoAdvok; break; + case Type::BT_PFO_DANPOR: return strPfoDanpor; break; + case Type::BT_PFO_INSSPR: return strPfoInsspr; break; + case Type::BT_PFO_AUDITOR: return strPfoAuditor; break; + case Type::BT_FO: return strFo; break; + default: + Q_ASSERT(0); + return strNull; + break; + } +} + +enum Isds::Type::DbType Isds::strVariant2DbType(const QVariant &v) +{ + if (!v.isNull()) { + return str2DbType(v.toString()); + } else { + return Type::BT_NULL; + } +} + +QVariant Isds::dbType2StrVariant(enum Type::DbType bt) +{ + if (bt != Type::BT_NULL) { + return QVariant(dbType2Str(bt)); + } else { + return QVariant(); + } +} + +enum Isds::Type::DbState Isds::long2DbState(long int bs, bool *ok) +{ + bool iOk = true; + enum Type::DbState state = Type::BS_ERROR; + + switch (bs) { + case Type::BS_ERROR: state = Type::BS_ERROR; break; + case Type::BS_ACCESSIBLE: state = Type::BS_ACCESSIBLE; break; + case Type::BS_TEMP_INACCESSIBLE: state = Type::BS_TEMP_INACCESSIBLE; break; + case Type::BS_NOT_YET_ACCESSIBLE: state = Type::BS_NOT_YET_ACCESSIBLE; break; + case Type::BS_PERM_INACCESSIBLE: state = Type::BS_PERM_INACCESSIBLE; break; + case Type::BS_REMOVED: state = Type::BS_REMOVED; break; + case Type::BS_TEMP_UNACCESSIBLE_LAW: state = Type::BS_TEMP_UNACCESSIBLE_LAW; break; + default: + Q_ASSERT(0); + iOk = false; + break; + } + + if (ok != Q_NULLPTR) { + *ok = iOk; + } + return state; +} + +enum Isds::Type::DbState Isds::variant2DbState(const QVariant &v) +{ + if (v.isNull()) { + return Type::BS_ERROR; + } + + bool ok = false; + qint64 num = v.toLongLong(&ok); + if (Q_UNLIKELY(!ok)) { + Q_ASSERT(0); + return Type::BS_ERROR; + } + + return long2DbState(num); +} + +QVariant Isds::dbState2Variant(enum Type::DbState bs) +{ + if (bs != Type::BS_ERROR) { + return QVariant((int)bs); + } else { + return QVariant(); + } +} + +Isds::Type::Privileges Isds::long2Privileges(long int p) +{ + Type::Privileges privileges = Type::PRIVIL_NONE; + if (p & Type::PRIVIL_READ_NON_PERSONAL) { + privileges |= Type::PRIVIL_READ_NON_PERSONAL; + } + if (p & Type::PRIVIL_READ_ALL) { + privileges |= Type::PRIVIL_READ_ALL; + } + if (p & Type::PRIVIL_CREATE_DM) { + privileges |= Type::PRIVIL_CREATE_DM; + } + if (p & Type::PRIVIL_VIEW_INFO) { + privileges |= Type::PRIVIL_VIEW_INFO; + } + if (p & Type::PRIVIL_SEARCH_DB) { + privileges |= Type::PRIVIL_SEARCH_DB; + } + if (p & Type::PRIVIL_OWNER_ADM) { + privileges |= Type::PRIVIL_OWNER_ADM; + } + if (p & Type::PRIVIL_READ_VAULT) { + privileges |= Type::PRIVIL_READ_VAULT; + } + if (p & Type::PRIVIL_ERASE_VAULT) { + privileges |= Type::PRIVIL_ERASE_VAULT; + } + return privileges; +} + +Isds::Type::Privileges Isds::variant2Privileges(const QVariant &v) +{ + if (v.isNull()) { + return Type::PRIVIL_NONE; + } + + bool ok = false; + qint64 num = v.toLongLong(&ok); + if (Q_UNLIKELY(!ok)) { + Q_ASSERT(0); + return Type::PRIVIL_NONE; + } + + return long2Privileges(num); +} + +QVariant Isds::privileges2Variant(Type::Privileges p) +{ + return QVariant((int)p); +} + +enum Isds::Type::DmState Isds::long2DmState(long int ms) +{ + switch (ms) { + case Type::MS_NULL: return Type::MS_NULL; break; + case Type::MS_POSTED: return Type::MS_POSTED; break; + case Type::MS_STAMPED: return Type::MS_STAMPED; break; + case Type::MS_INFECTED: return Type::MS_INFECTED; break; + case Type::MS_DELIVERED: return Type::MS_DELIVERED; break; + case Type::MS_ACCEPTED_FICT: return Type::MS_ACCEPTED_FICT; break; + case Type::MS_ACCEPTED: return Type::MS_ACCEPTED; break; + case Type::MS_READ: return Type::MS_READ; break; + case Type::MS_UNDELIVERABLE: return Type::MS_UNDELIVERABLE; break; + case Type::MS_REMOVED: return Type::MS_REMOVED; break; + case Type::MS_IN_VAULT: return Type::MS_IN_VAULT; break; + default: + Q_ASSERT(0); + return Type::MS_NULL; + break; + } +} + +enum Isds::Type::DmState Isds::variant2DmState(const QVariant &v) +{ + if (v.isNull()) { + return Type::MS_NULL; + } + + bool ok = false; + qint64 num = v.toLongLong(&ok); + if (Q_UNLIKELY(!ok)) { + Q_ASSERT(0); + return Type::MS_NULL; + } + + return long2DmState(num); +} + +QVariant Isds::dmState2Variant(enum Type::DmState ms) +{ + if (ms == Type::MS_NULL) { + return QVariant(); + } else { + return QVariant((int)ms); + } +} + +static const QString strPu("PRIMARY_USER"), strEu("ENTRUSTED_USER"), + strA("ADMINISTRATOR"), strOu("OFFICIAL_USER"), strOcu("OFFICIAL_CERT_USER"), + strL("LIQUIDATOR"), strR("RECEIVER"), strG("GUARDIAN"); + +enum Isds::Type::UserType Isds::str2UserType(const QString &s) +{ + if (s.isNull()) { + return Type::UT_NULL; + } else if (s == strPu) { + return Type::UT_PRIMARY; + } else if (s == strEu) { + return Type::UT_ENTRUSTED; + } else if (s == strA) { + return Type::UT_ADMINISTRATOR; + } else if (s == strOu) { + return Type::UT_OFFICIAL; + } else if (s == strOcu) { + return Type::UT_OFFICIAL_CERT; + } else if (s == strL) { + return Type::UT_LIQUIDATOR; + } else if (s == strR) { + return Type::UT_RECEIVER; + } else if (s == strG) { + return Type::UT_GUARDIAN; + } else { + Q_ASSERT(0); + return Type::UT_NULL; + } +} + +const QString &Isds::userType2Str(enum Type::UserType ut) +{ + switch (ut) { + case Type::UT_NULL: return strNull; break; + case Type::UT_PRIMARY: return strPu; break; + case Type::UT_ENTRUSTED: return strEu; break; + case Type::UT_ADMINISTRATOR: return strA; break; + case Type::UT_OFFICIAL: return strOu; break; + case Type::UT_OFFICIAL_CERT: return strOcu; break; + case Type::UT_LIQUIDATOR: return strL; break; + case Type::UT_RECEIVER: return strR; break; + case Type::UT_GUARDIAN: return strG; break; + default: + Q_ASSERT(0); + return strNull; + break; + } +} + +enum Isds::Type::UserType Isds::variant2UserType(const QVariant &v) +{ + if (v.isNull()) { + return Type::UT_NULL; + } + + return str2UserType(v.toString()); +} + +QVariant Isds::userType2Variant(enum Type::UserType ut) +{ + if (ut == Type::UT_NULL) { + return QVariant(); + } + + return QVariant(userType2Str(ut)); +} + +static const QString strO("OFFICIAL"), strV("VIRTUAL"), strOc("OFFICIAL_CERT"); + +enum Isds::Type::SenderType Isds::str2SenderType(const QString &s) +{ + if (s.isNull()) { + return Type::ST_NULL; + } else if (s == strPu) { + return Type::ST_PRIMARY; + } else if (s == strEu) { + return Type::ST_ENTRUSTED; + } else if (s == strA) { + return Type::ST_ADMINISTRATOR; + } else if (s == strO) { + return Type::ST_OFFICIAL; + } else if (s == strV) { + return Type::ST_VIRTUAL; + } else if (s == strOc) { + return Type::ST_OFFICIAL_CERT; + } else if (s == strL) { + return Type::ST_LIQUIDATOR; + } else if (s == strR) { + return Type::ST_RECEIVER; + } else if (s == strG) { + return Type::ST_GUARDIAN; + } else { + Q_ASSERT(0); + return Type::ST_NULL; + } +} + +const QString &Isds::senderType2Str(enum Type::SenderType st) +{ + switch (st) { + case Type::ST_NULL: return strNull; break; + case Type::ST_PRIMARY: return strPu; break; + case Type::ST_ENTRUSTED: return strEu; break; + case Type::ST_ADMINISTRATOR: return strA; break; + case Type::ST_OFFICIAL: return strO; break; + case Type::ST_VIRTUAL: return strV; break; + case Type::ST_OFFICIAL_CERT: return strOc; break; + case Type::ST_LIQUIDATOR: return strL; break; + case Type::ST_RECEIVER: return strR; break; + case Type::ST_GUARDIAN: return strG; break; + default: + Q_ASSERT(0); + return strNull; + break; + } +} + +enum Isds::Type::SenderType Isds::variant2SenderType(const QVariant &v) +{ + if (v.isNull()) { + return Type::ST_NULL; + } + + return str2SenderType(v.toString()); +} + +QVariant Isds::senderType2Variant(enum Type::SenderType st) +{ + if (st == Type::ST_NULL) { + return QVariant(); + } + + return QVariant(senderType2Str(st)); +} + +static const QString strMd5("MD5"), strSha1("SHA-1"), strSha224("SHA-224"), + strSha256("SHA-256"), strSha384("SHA-384"), strSha512("SHA-512"); + +enum Isds::Type::HashAlg Isds::str2HashAlg(const QString &s) +{ + if (s.isNull()) { + return Type::HA_UNKNOWN; + } else if (s == strMd5) { + return Type::HA_MD5; + } else if (s == strSha1) { + return Type::HA_SHA_1; + } else if (s == strSha224) { + return Type::HA_SHA_224; + } else if (s == strSha256) { + return Type::HA_SHA_256; + } else if (s == strSha384) { + return Type::HA_SHA_384; + } else if (s == strSha512) { + return Type::HA_SHA_512; + } else { + Q_ASSERT(0); + return Type::HA_UNKNOWN; + } +} + +const QString &Isds::hashAlg2Str(enum Type::HashAlg ha) +{ + switch (ha) { + case Type::HA_UNKNOWN: return strNull; break; + case Type::HA_MD5: return strMd5; break; + case Type::HA_SHA_1: return strSha1; break; + case Type::HA_SHA_224: return strSha224; break; + case Type::HA_SHA_256: return strSha256; break; + case Type::HA_SHA_384: return strSha384; break; + case Type::HA_SHA_512: return strSha512; break; + default: + Q_ASSERT(0); + return strNull; + break; + } +} + +enum Isds::Type::HashAlg Isds::variant2HashAlg(const QVariant &v) +{ + if (v.isNull()) { + return Type::HA_UNKNOWN; + } + + return str2HashAlg(v.toString()); +} + +QVariant Isds::hashAlg2Variant(enum Type::HashAlg ha) +{ + if (ha == Type::HA_UNKNOWN) { + return QVariant(); + } + + return QVariant(hashAlg2Str(ha)); +} + +static const QString strMain("main"), strEncl("encl"), strSign("sign"), strMeta("meta"); + +enum Isds::Type::FileMetaType Isds::str2FileMetaType(const QString &s) +{ + if (s.isNull()) { + return Type::FMT_UNKNOWN; + } else if (s == strMain) { + return Type::FMT_MAIN; + } else if (s == strEncl) { + return Type::FMT_ENCLOSURE; + } else if (s == strSign) { + return Type::FMT_SIGNATURE; + } else if (s == strMeta) { + return Type::FMT_META; + } else { + Q_ASSERT(0); + return Type::FMT_UNKNOWN; + } +} + +const QString &Isds::fileMetaType2Str(enum Type::FileMetaType fmt) +{ + switch (fmt) { + case Type::FMT_UNKNOWN: return strNull; break; + case Type::FMT_MAIN: return strMain; break; + case Type::FMT_ENCLOSURE: return strEncl; break; + case Type::FMT_SIGNATURE: return strSign; break; + case Type::FMT_META: return strMeta; break; + default: + Q_ASSERT(0); + return strNull; + break; + } +} + +enum Isds::Type::FileMetaType Isds::variant2FileMetaType(const QVariant &v) +{ + if (v.isNull()) { + return Type::FMT_UNKNOWN; + } + + return str2FileMetaType(v.toString()); +} + +QVariant Isds::fileMetaType2Variant(enum Type::FileMetaType fmt) +{ + if (fmt == Type::FMT_UNKNOWN) { + return QVariant(); + } + + return QVariant(fileMetaType2Str(fmt)); +} diff --git a/src/datovka_shared/isds/type_conversion.h b/src/datovka_shared/isds/type_conversion.h new file mode 100644 index 0000000000000000000000000000000000000000..24c3eab2fd72044c3f1ea6b779219ba3705f7ffa --- /dev/null +++ b/src/datovka_shared/isds/type_conversion.h @@ -0,0 +1,81 @@ +/* + * 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 . + * + * 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 +#include + +#include "src/datovka_shared/isds/types.h" + +namespace Isds { + + /* Negative values are converted to null variant. */ + qint64 variant2nonNegativeLong(const QVariant &v); + /* Null variant is converted to -1. */ + QVariant nonNegativeLong2Variant(qint64 i); + + enum Type::NilBool variant2NilBool(const QVariant &v); + QVariant nilBool2Variant(enum Type::NilBool b); + + enum Type::DbType long2DbType(long int bt, bool *ok = Q_NULLPTR); + enum Type::DbType intVariant2DbType(const QVariant &v); + QVariant dbType2IntVariant(enum Type::DbType bt); + enum Type::DbType str2DbType(const QString &s); + const QString &dbType2Str(enum Type::DbType bt); + enum Type::DbType strVariant2DbType(const QVariant &v); + QVariant dbType2StrVariant(enum Type::DbType bt); + + enum Type::DbState long2DbState(long int bs, bool *ok = Q_NULLPTR); + enum Type::DbState variant2DbState(const QVariant &v); + QVariant dbState2Variant(enum Type::DbState bs); + + Type::Privileges long2Privileges(long int p); + Type::Privileges variant2Privileges(const QVariant &v); + QVariant privileges2Variant(Type::Privileges p); + + enum Type::DmState long2DmState(long int ms); + enum Type::DmState variant2DmState(const QVariant &v); + QVariant dmState2Variant(enum Type::DmState ms); + + enum Type::UserType str2UserType(const QString &s); + const QString &userType2Str(enum Type::UserType ut); + enum Type::UserType variant2UserType(const QVariant &v); + QVariant userType2Variant(enum Type::UserType ut); + + enum Type::SenderType str2SenderType(const QString &s); + const QString &senderType2Str(enum Type::SenderType st); + enum Type::SenderType variant2SenderType(const QVariant &v); + QVariant senderType2Variant(enum Type::SenderType st); + + enum Type::HashAlg str2HashAlg(const QString &s); + const QString &hashAlg2Str(enum Type::HashAlg ha); + enum Type::HashAlg variant2HashAlg(const QVariant &v); + QVariant hashAlg2Variant(enum Type::HashAlg ha); + + enum Type::FileMetaType str2FileMetaType(const QString &s); + const QString &fileMetaType2Str(enum Type::FileMetaType fmt); + enum Type::FileMetaType variant2FileMetaType(const QVariant &v); + QVariant fileMetaType2Variant(enum Type::FileMetaType fmt); + +} diff --git a/src/datovka_shared/isds/types.h b/src/datovka_shared/isds/types.h new file mode 100644 index 0000000000000000000000000000000000000000..34d4ad7a57d3560a16afbbbd693c16c794cdb932 --- /dev/null +++ b/src/datovka_shared/isds/types.h @@ -0,0 +1,331 @@ +/* + * 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 . + * + * 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 + +/* + * wsdl2h -s -o dmBaseTypes.h dmBaseTypes.xsd + * wsdl2h -s -o dbTypes.h dbTypes.xsd + */ + +namespace Isds { + +/*! + * @brief Provides enumeration types based on dbTypes.xsd . + */ +class Type : public QObject { + Q_OBJECT + +private: + /*! + * @brief Private constructor. + */ + Type(QObject *parent = Q_NULLPTR); + +public: + /*! + * @brief Nullable bool. + * + * @note Should NULL value be treated as false? + */ + enum NilBool { + BOOL_NULL = -1, /*!< Convenience value, converted from/to NULL. */ + BOOL_FALSE = 0, + BOOL_TRUE = 1 + }; + + /*! + * @brief Data box type. + * + * @note Defined in dbTypes.xsd. Described in + * pril_3/WS_ISDS_Sprava_datovych_schranek.pdf + * (section 2.1 CreateDataBox). + */ + enum DbType { + BT_NULL = -1, /*!< Convenience value, converted from/to NULL. */ + BT_SYSTEM = 0, /*!< + * This value is not listed in dbTypes.xsd but is mentioned in + * pril_2/WS_ISDS_Manipulace_s_datovymi_zpravami.pdf + * (section 2.4.1 MessageDownload). + */ + BT_OVM = 10, /*!< Public authority. */ + BT_OVM_NOTAR = 11, /* This type has been replaced with OVM_PFO. */ + BT_OVM_EXEKUT = 12, /* This type has been replaced with OVM_PFO. */ + BT_OVM_REQ = 13, + BT_OVM_FO = 14, + BT_OVM_PFO = 15, + BT_OVM_PO = 16, + BT_PO = 20, + BT_PO_ZAK = 21, /* This type has been replaced with PO. */ + BT_PO_REQ = 22, + BT_PFO = 30, + BT_PFO_ADVOK = 31, + BT_PFO_DANPOR = 32, + BT_PFO_INSSPR = 33, + BT_PFO_AUDITOR = 34, + BT_FO = 40 + }; + + /*! + * @brief Data box accessibility state. + * + * @note Described in pril_3/WS_ISDS_Sprava_datovych_schranek.pdf + * (appendix 4). + */ + enum DbState { + BS_ERROR = 0, /* Error value, see documentation. */ /* Also converted ftom/to NULL. */ + BS_ACCESSIBLE = 1, + BS_TEMP_INACCESSIBLE = 2, + BS_NOT_YET_ACCESSIBLE = 3, + BS_PERM_INACCESSIBLE = 4, + BS_REMOVED = 5, + BS_TEMP_UNACCESSIBLE_LAW = 6 + }; + + /*! + * @brief User permissions. + * + * @note Described in + * pril_2/WS_ISDS_Manipulace_s_datovymi_zpravami.pdf (section 1.4), + * pril_3/WS_ISDS_Sprava_datovych_schranek.pdf (section 2.4 AddDataBoxUser) + */ + enum Privilege { + PRIVIL_NONE = 0x00, /* Added for convenience. */ + PRIVIL_READ_NON_PERSONAL = 0x01, + PRIVIL_READ_ALL = 0x02, + PRIVIL_CREATE_DM = 0x04, + PRIVIL_VIEW_INFO = 0x08, + PRIVIL_SEARCH_DB = 0x10, + PRIVIL_OWNER_ADM = 0x20, + PRIVIL_READ_VAULT = 0x40, /* zrušeno od července 2012 */ + PRIVIL_ERASE_VAULT = 0x80 + }; + Q_DECLARE_FLAGS(Privileges, Privilege) + Q_FLAG(Privileges) + + /* + * @brief Describes the message cycle. + * + * @note Described in + * pril_2/WS_ISDS_Manipulace_s_datovymi_zpravami.pdf (section 1.5). + */ + enum DmState { + MS_NULL = -1, /*!< Convenience value, converted from/to NULL. */ + MS_POSTED = 1, + MS_STAMPED = 2, + MS_INFECTED = 3, + MS_DELIVERED = 4, + MS_ACCEPTED_FICT = 5, + MS_ACCEPTED = 6, + MS_READ = 7, + MS_UNDELIVERABLE = 8, + MS_REMOVED = 9, + MS_IN_VAULT = 10 + }; + + /*! + * @brief Message filter status as used by GetListOfSentMessages and + * GetListOfReceivedMessages. + * + * @note Usage described in + * pril_2/WS_ISDS_Manipulace_s_datovymi_zpravami.pdf + * (section 2.8.2). + */ + enum DmFiltState { + MFS_POSTED = 0x02, + MFS_STAMPED = 0x04, + MFS_INFECTED = 0x08, + MFS_DELIVERED = 0x10, + MFS_ACCEPTED_FICT = 0x20, + MFS_ACCEPTED = 0x40, + MFS_READ = 0x80, + MFS_UNDELIVERABLE = 0x0100, + MFS_REMOVED = 0x0200, + MFS_IN_VAULT = 0x0400, + MFS_ANY = 0x07fe /* Convenience value. */ + }; + Q_DECLARE_FLAGS(DmFiltStates, DmFiltState) + Q_FLAG(DmFiltStates) + + /*! + * @brief Describes message type. + * + * @note See pril_2/WS_ISDS_Manipulace_s_datovymi_zpravami.pdf. + */ + enum DmType { + MT_UNKNOWN = -1, /*!< Convenience value, converted from/to NULL. */ + MT_I = 'I', /* Initiatory. */ + MT_K = 'K', /* Commercial. */ + MT_O = 'O', /* Commercial response paid by sender of initiatory. */ + MT_V = 'V', /* Non-commercial government message. */ + MT_A = 'A', /* Subsidised initiatory commercial, can pay a response. */ + MT_B = 'B', /* Subsidised initiatory commercial, has already paid the response. */ + MT_C = 'C', /* Subsidised initiatory commercial, response offer expired. */ + MT_D = 'D', /* Externally subsidised initiatory commercial. */ + MT_E = 'E', /* Stamp-prepaid commercial. */ + MT_G = 'G', /* Sponsor-prepaid commercial. */ + MT_X = 'X', /* Initiatory commercial, response offer expired. */ + MT_Y = 'Y', /* Initiatory commercial, has already paid the response. */ + MT_Z = 'Z' + }; + + /*! + * @brief User types tUserType (dbTypes.xsd). + * + * @note Described in + * pril_3/WS_ISDS_Sprava_datovych_schranek.pdf (section 2.4). + */ + enum UserType { + UT_NULL = -1, /*!< Convenience value, converted from/to NULL. */ + UT_PRIMARY, + UT_ENTRUSTED, + UT_ADMINISTRATOR, + UT_OFFICIAL, + UT_OFFICIAL_CERT, + UT_LIQUIDATOR, + UT_RECEIVER, + UT_GUARDIAN + }; + + /*! + * @brief Sender type as mentioned in response description of + * GetMessageAuthor. + * + * @note Described in pril_2/WS_ISDS_Manipulace_s_datovymi_zpravami.pdf + * (section 2.9). + * The values differ slightly from enum UserType. + */ + enum SenderType { + ST_NULL = -1, /*!< Convenience value, converted from/to NULL. */ + ST_PRIMARY, + ST_ENTRUSTED, + ST_ADMINISTRATOR, + ST_OFFICIAL, + ST_VIRTUAL, + ST_OFFICIAL_CERT, + ST_LIQUIDATOR, + ST_RECEIVER, + ST_GUARDIAN + }; + + /*! + * @brief Hash algorithm type. + * + * @todo Find definition in documentation. + */ + enum HashAlg { + HA_UNKNOWN = -1, /* Convenience value. */ + HA_MD5, + HA_SHA_1, + HA_SHA_224, + HA_SHA_256, + HA_SHA_384, + HA_SHA_512 + }; + + /*! + * @brief Message event. + * + * @note Described in pril_2/WS_ISDS_Manipulace_s_datovymi_zpravami.pdf, + * section 2.7.1. + */ + enum Event { + EV_UNKNOWN = -1, /* Convenience value. */ + EV_ENTERED = 0, /* Message came into being. */ + EV_DELIVERED = 5, /* Message was delivered into recipient's box. */ + EV_ACCEPTED_LOGIN = 1, /* Before 27.10.210, message was accepted by recipient logging in. */ + EV_PRIMARY_LOGIN = 11, /* Primary/competent (Czech: opravneny) user with capability to read has logged in. */ + EV_ENTRUSTED_LOGIN = 12, /* Entrusted (Czech: povereny) user with capability to read has logged in. */ + EV_SYSCERT_LOGIN = 13, /* Application authenticated using a system certificate has logged in. */ + EV_ACCEPTED_FICTION = 2, /* Message has been accepted by fiction. */ + EV_UNDELIVERABLE = 3, /* Recipient box made inaccessible, message is undeliverable. */ + EV_ACCEPTED_BY_RECIPIENT = 4, /* Before 11.2011, message has been delivered and accepted by recipient action. */ + EV_UNDELIVERED_AV_CHECK = 8 /* Message didn't mass antivirus check, message has been rejected. */ + }; + + /*! + * @brief Attachment type. + * + * @note Mentioned in pril_2/WS_ISDS_Manipulace_s_datovymi_zpravami.pdf + * section 2.1. + */ + enum FileMetaType { + FMT_UNKNOWN = -1, /* Convenience value. */ + FMT_MAIN, /* First in list of documents. */ + FMT_ENCLOSURE, /* Attachment. */ + FMT_SIGNATURE, /* Digital signature of another document. */ + FMT_META /* Special XML data for ESS (records management service). */ + }; + + /*! + * @brief Raw type. Convenience value, taken from libisds. + */ + enum RawType { + RT_UNKNOWN = -1, /* Convenience value. */ + RT_INCOMING_MESSAGE, + RT_PLAIN_SIGNED_INCOMING_MESSAGE, + RT_CMS_SIGNED_INCOMING_MESSAGE, + RT_PLAIN_SIGNED_OUTGOING_MESSAGE, + RT_CMS_SIGNED_OUTGOING_MESSAGE, + RT_DELIVERYINFO, + RT_PLAIN_SIGNED_DELIVERYINFO, + RT_CMS_SIGNED_DELIVERYINFO + }; + + /*! + * @brief Error value. Taken from libisds for compatibility. + */ + enum Error { + ERR_SUCCESS = 0, /* No error. */ + ERR_ERROR, /* Unspecified error. */ + ERR_NOTSUP, + ERR_INVAL, + ERR_INVALID_CONTEXT, + ERR_NOT_LOGGED_IN, + ERR_CONNECTION_CLOSED, + ERR_TIMED_OUT, + ERR_NOEXIST, + ERR_NOMEM, + ERR_NETWORK, + ERR_HTTP, + ERR_SOAP, + ERR_XML, + ERR_ISDS, + ERR_ENUM, + ERR_DATE, + ERR_2BIG, + ERR_2SMALL, + ERR_NOTUNIQ, + ERR_NOTEQUAL, + ERR_PARTIAL_SUCCESS, + ERR_ABORTED, + ERR_SECURITY + }; +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(Type::Privileges) +Q_DECLARE_OPERATORS_FOR_FLAGS(Type::DmFiltStates) + +} diff --git a/src/files.cpp b/src/files.cpp index 7c2775bd613d961c81453a22f30ee8e1bb45f6cb..822e15cea7c0ee2510d6b4cf8d5d4647ce889d83 100644 --- a/src/files.cpp +++ b/src/files.cpp @@ -36,14 +36,15 @@ #include "src/global.h" #include "src/io/filesystem.h" #include "src/models/accountmodel.h" -#include "src/net/xml_layer.h" -#include "src/qml_interaction/attachment_data.h" #include "src/qml_interaction/message_envelope.h" #include "src/settings.h" #include "src/sqlite/dbs.h" #include "src/sqlite/file_db_container.h" #include "src/sqlite/message_db_container.h" #include "src/sqlite/zfo_db.h" +#include "src/xml/xml_base.h" +#include "src/xml/xml_download_delivery_info.h" +#include "src/xml/xml_download_message.h" void Files::declareQML(void) { @@ -146,7 +147,7 @@ QByteArray Files::getFileRawContentFromDb(const QString &userName, int fileId) return QByteArray(); } - return base64ToRaw(fDb->getFileFromDb(fileId).content.toUtf8()); + return fDb->getFileFromDb(fileId).binaryContent(); } void Files::openAttachmentFromDb(const QString &userName, int fileId) @@ -169,9 +170,9 @@ void Files::openAttachmentFromDb(const QString &userName, int fileId) return; } - FileDb::FileData file = fDb->getFileFromDb(fileId); + Isds::Document document(fDb->getFileFromDb(fileId)); - openAttachment(file.filename, file.content.toUtf8()); + openAttachment(document.fileDescr(), document.base64Content().toUtf8()); } void Files::openAttachment(const QString &fileName, @@ -275,7 +276,7 @@ void Files::sendMsgFilesWithEmail(const QString &userName, qint64 msgId, return; } - QList filelist; + QList documents; /* Get attachment files from database if needed */ if (attachFlags & MSG_ATTACHS) { @@ -288,8 +289,8 @@ void Files::sendMsgFilesWithEmail(const QString &userName, qint64 msgId, return; } - filelist = fDb->getFilesFromDb(msgId); - if (filelist.isEmpty()) { + documents = fDb->getFilesFromDb(msgId); + if (documents.isEmpty()) { qCritical("Missing attachments for message '%s'.", QString::number(msgId).toUtf8().constData()); return; @@ -298,10 +299,10 @@ void Files::sendMsgFilesWithEmail(const QString &userName, qint64 msgId, /* Get zfo file from database if needed */ if (attachFlags & MSG_ZFO) { - FileDb::FileData msgData; - msgData.content = GlobInstcs::zfoDbPtr->getZfoContentFromDb( - msgId, (*GlobInstcs::acntMapPtr)[userName].isTestAccount()); - if (msgData.content.isEmpty()) { + Isds::Document document; + document.setBase64Content(GlobInstcs::zfoDbPtr->getZfoContentFromDb( + msgId, (*GlobInstcs::acntMapPtr)[userName].isTestAccount())); + if (document.binaryContent().isEmpty()) { qCritical("Missing zfo data for message '%s'.", QString::number(msgId).toUtf8().constData()); Dialogues::errorMessage(Dialogues::CRITICAL, @@ -311,8 +312,8 @@ void Files::sendMsgFilesWithEmail(const QString &userName, qint64 msgId, Q_ASSERT(0); return; } - msgData.filename = QString("DZ_%1.zfo").arg(msgId); - filelist.append(msgData); + document.setFileDescr(QString("DZ_%1.zfo").arg(msgId)); + documents.append(document); } /* Create email content, email attachment path, email eml content */ @@ -323,17 +324,17 @@ void Files::sendMsgFilesWithEmail(const QString &userName, qint64 msgId, QStringList filePathList; /* Write attachment files to email directory */ - foreach (const FileDb::FileData &file, filelist) { - QString fileName = file.filename; + foreach (const Isds::Document &document, documents) { + QString fileName = document.fileDescr(); if (fileName.isEmpty()) { qCritical("%s", "File name is empty."); return; } fileName = writeFile(targetPath, fileName, - base64ToRaw(file.content.toUtf8())); + document.binaryContent()); filePathList.append(fileName); - addAttachmentToEmailMessage(emailMessage, file.filename, - file.content.toUtf8(), boundary); + addAttachmentToEmailMessage(emailMessage, document.fileDescr(), + document.base64Content().toUtf8(), boundary); } finishEmailMessage(emailMessage, boundary); @@ -506,7 +507,7 @@ MsgInfo *Files::zfoData(const QVariant &attachModelVariant, bool ret = parseXmlData(&type, &idStr, &annot, &htmlDescr, FileListModel::fromVariant(attachModelVariant), - &emailBody, getXmlFromCms(rawZfoData)); + &emailBody, Xml::getXmlFromCms(rawZfoData)); return ret ? new (std::nothrow) MsgInfo(type, idStr, annot, htmlDescr, @@ -615,7 +616,7 @@ void Files::saveMsgFilesToDisk(const QString &userName, return; } - QList filelist; + QList documents; /* Get attachment files from database if needed */ if (attachFlags & MSG_ATTACHS) { @@ -628,8 +629,8 @@ void Files::saveMsgFilesToDisk(const QString &userName, return; } - filelist = fDb->getFilesFromDb(msgId); - if (filelist.isEmpty()) { + documents = fDb->getFilesFromDb(msgId); + if (documents.isEmpty()) { qCritical("Missing attachments for message '%s'.", QString::number(msgId).toUtf8().constData()); return; @@ -638,10 +639,10 @@ void Files::saveMsgFilesToDisk(const QString &userName, /* Get zfo file from database if needed */ if (attachFlags & MSG_ZFO) { - FileDb::FileData msgData; - msgData.content = GlobInstcs::zfoDbPtr->getZfoContentFromDb( - msgId, (*GlobInstcs::acntMapPtr)[userName].isTestAccount()); - if (msgData.content.isEmpty()) { + Isds::Document document; + document.setBase64Content(GlobInstcs::zfoDbPtr->getZfoContentFromDb( + msgId, (*GlobInstcs::acntMapPtr)[userName].isTestAccount())); + if (document.binaryContent().isEmpty()) { qCritical("Missing zfo data for message '%s'.", QString::number(msgId).toUtf8().constData()); Dialogues::errorMessage(Dialogues::CRITICAL, @@ -651,16 +652,16 @@ void Files::saveMsgFilesToDisk(const QString &userName, Q_ASSERT(0); return; } - msgData.filename = QString("DZ_%1.zfo").arg(msgId); - filelist.append(msgData); + document.setFileDescr(QString("DZ_%1.zfo").arg(msgId)); + documents.append(document); } QString filePath(appMsgAttachDirPath(msgIdStr)); QString destPath; - foreach (const FileDb::FileData &file, filelist) { - destPath = writeFile(filePath, file.filename, - base64ToRaw(file.content.toUtf8())); + foreach (const Isds::Document &document, documents) { + destPath = writeFile(filePath, document.fileDescr(), + document.binaryContent()); } attachmentSavingNotification(destPath); @@ -732,48 +733,6 @@ void Files::sendEmail(const QString &emailMessage, const QStringList &fileList, #endif } -QByteArray Files::getXmlFromCms(const QByteArray &rawData) -{ - qDebug("%s()", __func__); - - if (rawData.isEmpty()) { - Q_ASSERT(0); - qCritical() << "File content is empty!"; - return QByteArray(); - } - - /* Decode CMS and obtain message XML data - uses OpenSSL. */ - void *xmlContent = Q_NULLPTR; - size_t xmlContentLen = 0; - if (extract_cms_data(rawData.data(), rawData.length(), &xmlContent, - &xmlContentLen) != 0) { - return QByteArray(); - } - if (xmlContentLen == 0) { - free(xmlContent); xmlContent = Q_NULLPTR; - return QByteArray(); - } - - QByteArray soap((char *)xmlContent, xmlContentLen); - free(xmlContent); xmlContent = Q_NULLPTR; - - return soap; -} - -QByteArray Files::decodeZfoFile(const QByteArray &base64ZfoData) -{ - qDebug("%s()", __func__); - - if (base64ZfoData.isEmpty()) { - Q_ASSERT(0); - qCritical() << "File content is empty."; - return QByteArray(); - } - - /* decode signature from base64 and obtain something CMS message */ - return getXmlFromCms(base64ToRaw(base64ZfoData)); -} - bool Files::parseXmlData(enum MsgInfo::ZfoType *type, QString *idStr, QString *annotation, QString *msgDescrHtml, FileListModel *attachModel, QString *emailBody, QByteArray xmlData) @@ -785,13 +744,6 @@ bool Files::parseXmlData(enum MsgInfo::ZfoType *type, QString *idStr, return false; } - xmlData.prepend("" - "" - ""); - xmlData.append(""); - /* Test if zfo is message, delivery info or unknown format */ if (xmlData.contains(QByteArray("MessageDownloadResponse"))) { if (type != Q_NULLPTR) { @@ -821,107 +773,85 @@ bool Files::parseAndShowXmlData(enum MsgInfo::ZfoType type, QString *idStr, { qDebug("%s()", __func__); - QXmlStreamReader xml; - MsgEnvelope msg; - QList fileList; - QList eventList; - if (type == MsgInfo::TYPE_UNKNOWN) { Q_ASSERT(0); return false; } - /* parse message envelope and files */ - xml.addData(xmlData); - while(!xml.atEnd() && !xml.hasError()) { - QXmlStreamReader::TokenType token = xml.readNext(); - if (xml.error() != QXmlStreamReader::NoError) { - return false; - } - if (token == QXmlStreamReader::StartDocument) { - continue; - } - if (token == QXmlStreamReader::StartElement) { - if (xml.name() == "dmDm") { - XmlLayer::completeMessageParse(xml, msg, fileList); - } - } - } + Isds::Message message = Xml::parseCompleteMessage(xmlData); + QList events; if (type == MsgInfo::TYPE_DELIVERY_INFO) { - /* parse delivery info */ - xml.clear(); - xml.addData(xmlData); - while(!xml.atEnd() && !xml.hasError()){ - QXmlStreamReader::TokenType token = xml.readNext(); - if (token == QXmlStreamReader::StartDocument) { - continue; - } - if (token == QXmlStreamReader::StartElement) { - if (xml.name() == "dmEvent") { - eventList.append(XmlLayer::parseEvent(xml)); - } - } - } + events = Xml::parseDeliveryInfo(xmlData); } QString html = divStart; html += "

" + tr("General") + "

"; - html += strongInfoLine(tr("Subject"), msg.dmAnnotation()); - QString size = QString::number(msg.dmAttachmentSize()); + html += strongInfoLine(tr("Subject"), message.envelope().dmAnnotation()); + QString size = QString::number(message.envelope().dmAttachmentSize()); html += strongInfoLine(tr("Attachment size"), (size == "0") ? "<1 kB" : "~" + size + " kB"); html += strongInfoLine(tr("Personal delivery"), - (msg.dmPersonalDelivery()) ? tr("Yes") : tr("No")); + (message.envelope().dmPersonalDelivery()) ? tr("Yes") : tr("No")); html += strongInfoLine(tr("Delivery by fiction"), - (msg.dmAllowSubstDelivery()) ? tr("Yes") : tr("No")); + (message.envelope().dmAllowSubstDelivery()) ? tr("Yes") : tr("No")); html += "

" + tr("Sender") + "

"; - html += strongInfoLine(tr("Databox ID"), msg.dbIDSender()); - html += strongInfoLine(tr("Name"), msg.dmSender()); - html += strongInfoLine(tr("Address"),msg.dmSenderAddress()); + html += strongInfoLine(tr("Databox ID"), + message.envelope().dbIDSender()); + html += strongInfoLine(tr("Name"), + message.envelope().dmSender()); + html += strongInfoLine(tr("Address"), + message.envelope().dmSenderAddress()); html += "

" + tr("Recipient") + "

"; - html += strongInfoLine(tr("Databox ID"), msg.dbIDRecipient()); - html += strongInfoLine(tr("Name"), msg.dmRecipient()); - html += strongInfoLine(tr("Address"),msg.dmRecipientAddress()); - if (!msg.dmToHands().isEmpty()) { - html += strongInfoLine(tr("To hands"), msg.dmToHands()); + html += strongInfoLine(tr("Databox ID"), + message.envelope().dbIDRecipient()); + html += strongInfoLine(tr("Name"), message.envelope().dmRecipient()); + html += strongInfoLine(tr("Address"), + message.envelope().dmRecipientAddress()); + if (!message.envelope().dmToHands().isEmpty()) { + html += strongInfoLine(tr("To hands"), + message.envelope().dmToHands()); } QString tmpHtml; - if (!msg.dmSenderIdent().isEmpty()) { + if (!message.envelope().dmSenderIdent().isEmpty()) { tmpHtml += strongInfoLine(tr("Our file mark"), - msg.dmSenderIdent()); + message.envelope().dmSenderIdent()); } - if (!msg.dmSenderRefNumber().isEmpty()) { + if (!message.envelope().dmSenderRefNumber().isEmpty()) { tmpHtml += strongInfoLine(tr("Our reference number"), - msg.dmSenderRefNumber()); + message.envelope().dmSenderRefNumber()); } - if (!msg.dmRecipientIdent().isEmpty()) { + if (!message.envelope().dmRecipientIdent().isEmpty()) { tmpHtml += strongInfoLine(tr("Your file mark"), - msg.dmRecipientIdent()); + message.envelope().dmRecipientIdent()); } - if (!msg.dmRecipientRefNumber().isEmpty()) { + if (!message.envelope().dmRecipientRefNumber().isEmpty()) { tmpHtml += strongInfoLine(tr("Your reference number"), - msg.dmRecipientRefNumber()); + message.envelope().dmRecipientRefNumber()); } - if (!msg.dmLegalTitleLaw().isEmpty()) { - tmpHtml += strongInfoLine(tr("Law"), msg.dmLegalTitleLaw()); + if (!message.envelope().dmLegalTitleLawStr().isEmpty()) { + tmpHtml += strongInfoLine(tr("Law"), + message.envelope().dmLegalTitleLawStr()); } - if (!msg.dmLegalTitleYear().isEmpty()) { - tmpHtml += strongInfoLine(tr("Year"), msg.dmLegalTitleYear()); + if (!message.envelope().dmLegalTitleYearStr().isEmpty()) { + tmpHtml += strongInfoLine(tr("Year"), + message.envelope().dmLegalTitleYearStr()); } - if (!msg.dmLegalTitleSect().isEmpty()) { - tmpHtml += strongInfoLine(tr("Section"), msg.dmLegalTitleSect()); + if (!message.envelope().dmLegalTitleSect().isEmpty()) { + tmpHtml += strongInfoLine(tr("Section"), + message.envelope().dmLegalTitleSect()); } - if (!msg.dmLegalTitlePar().isEmpty()) { + if (!message.envelope().dmLegalTitlePar().isEmpty()) { tmpHtml += strongInfoLine(tr("Paragraph"), - msg.dmLegalTitlePar()); + message.envelope().dmLegalTitlePar()); } - if (!msg.dmLegalTitlePoint().isEmpty()) { - tmpHtml += strongInfoLine(tr("Letter"), msg.dmLegalTitlePoint()); + if (!message.envelope().dmLegalTitlePoint().isEmpty()) { + tmpHtml += strongInfoLine(tr("Letter"), + message.envelope().dmLegalTitlePoint()); } if (!tmpHtml.isEmpty()) { html += "

" + tr("Additional info") + "

"; @@ -931,22 +861,22 @@ bool Files::parseAndShowXmlData(enum MsgInfo::ZfoType type, QString *idStr, html += "

" + tr("Message state") + "

"; html += strongInfoLine(tr("Delivery time"), dateTimeStrFromDbFormat( - dateTimeStrToUTCDbFormat(msg.dmDeliveryTime()), + utcDateTimeToDbFormatStr(message.envelope().dmDeliveryTime()), DATETIME_QML_FORMAT)); html += strongInfoLine(tr("Accetance time"), dateTimeStrFromDbFormat( - dateTimeStrToUTCDbFormat(msg.dmAcceptanceTime()), + utcDateTimeToDbFormatStr(message.envelope().dmAcceptanceTime()), DATETIME_QML_FORMAT)); html += strongInfoLine(tr("Status"), - QString::number(msg.dmMessageStatus())); + QString::number(message.envelope().dmMessageStatus())); if (type == MsgInfo::TYPE_DELIVERY_INFO) { html += "

" + tr("Events") + "

"; - foreach (const Messages::Event &event, eventList) { + foreach (const Isds::Event &event, events) { html += divStart + strongInfoLine(dateTimeStrFromDbFormat( - dateTimeStrToUTCDbFormat(event.dmEventTime), - DATETIME_QML_FORMAT), event.dmEventDescr) + utcDateTimeToDbFormatStr(event.time()), + DATETIME_QML_FORMAT), event.descr()) + divEnd; } } @@ -954,27 +884,30 @@ bool Files::parseAndShowXmlData(enum MsgInfo::ZfoType type, QString *idStr, html += divEnd; // Create body for email - QString body = generateEmailBodyText(msg.dmID(), msg.dmSender(), - msg.dmRecipient(), dateTimeStrFromDbFormat( - dateTimeStrToUTCDbFormat(msg.dmAcceptanceTime()), + QString body = generateEmailBodyText(message.envelope().dmId(), + message.envelope().dmSender(), message.envelope().dmRecipient(), + dateTimeStrFromDbFormat( + utcDateTimeToDbFormatStr(message.envelope().dmAcceptanceTime()), DATETIME_QML_FORMAT)); if (idStr != Q_NULLPTR) { - *idStr = QString::number(msg.dmID()); + *idStr = QString::number(message.envelope().dmId()); } if (annotation != Q_NULLPTR) { - *annotation = msg.dmAnnotation(); + *annotation = message.envelope().dmAnnotation(); } if (msgDescrHtml != Q_NULLPTR) { *msgDescrHtml = html; } if (attachModel != Q_NULLPTR) { attachModel->clearAll(); - foreach (const AttachmentData &file, fileList) { + foreach (const Isds::Document &document, message.documents()) { attachModel->appendFileEntry( - FileListModel::Entry(-1, file.dmFileDescr(), - file._dmFileSize(), file._icon(), - file.dmEncodedContent(), QString())); + FileListModel::Entry(-1, document.fileDescr(), + approximateDataSize(document.binaryContent().size()), + getAttachmentFileIconFromFileExtension( + document.fileDescr()), + document.base64Content(), QString())); } } if (emailBody != Q_NULLPTR) { diff --git a/src/files.h b/src/files.h index 146ae0f6ab9c2cc66b8fccadaec00d4f74c1fd07..dcfc15eafc523caf935785d53c8a6580fc4044f4 100644 --- a/src/files.h +++ b/src/files.h @@ -318,24 +318,6 @@ private: void sendEmail(const QString &emailMessage, const QStringList &fileList, const QString &subject, const QString &body, qint64 msgId); - /*! - * @brief Decode XML data from CMS. - * - * @param[in] rawData File content. - * @return Decoded XML data or QByteArray(). - */ - static - QByteArray getXmlFromCms(const QByteArray &rawData); - - /*! - * @brief Decode data from ZFO file. - * - * @param[in] base64ZfoData Base64-encoded zfo file content. - * @return Decoded raw data or QByteArray(). - */ - static - QByteArray decodeZfoFile(const QByteArray &base64ZfoData); - /*! * @brief Parse xml data of zfo file. * diff --git a/src/isds/isds_type_conversion.cpp b/src/isds/isds_type_conversion.cpp new file mode 100644 index 0000000000000000000000000000000000000000..850d40014badedb78c8c829e64dcb78d804cb813 --- /dev/null +++ b/src/isds/isds_type_conversion.cpp @@ -0,0 +1,108 @@ +/* + * 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 . + * + * 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/isds/isds_type_conversion.h" + +static const QString strNull; +static const QString strTrue("true"), strFalse("false"); + +enum Isds::Type::NilBool Isds::str2BoolType(const QString &s) +{ + if (s.isEmpty()) { + return Type::BOOL_NULL; + } else if (s == strTrue) { + return Type::BOOL_TRUE; + } else if (s == strFalse) { + return Type::BOOL_FALSE; + } else { + Q_ASSERT(0); + return Type::BOOL_FALSE; + } +} + +const QString &Isds::boolType2Str(enum Type::NilBool b) +{ + switch (b) { + case Type::BOOL_NULL: return strNull; break; + case Type::BOOL_FALSE: return strFalse; break; + case Type::BOOL_TRUE: return strTrue; break; + default: + Q_ASSERT(0); + return strNull; + break; + } +} + +static const QString strMain("main"), strEncl("enclosure"), + strSign("signature"), strMeta("meta"); + +enum Isds::Type::FileMetaType Isds::m_str2FileMetaType(const QString &s) +{ + if (s.isEmpty()) { + return Type::FMT_UNKNOWN; + } else if (s == strMain) { + return Type::FMT_MAIN; + } else if (s == strEncl) { + return Type::FMT_ENCLOSURE; + } else if (s == strSign) { + return Type::FMT_SIGNATURE; + } else if (s == strMeta) { + return Type::FMT_META; + } else { + Q_ASSERT(0); + return Type::FMT_UNKNOWN; + } +} + +const QString &Isds::m_fileMetaType2Str(enum Type::FileMetaType fmt) +{ + switch (fmt) { + case Type::FMT_UNKNOWN: return strNull; break; + case Type::FMT_MAIN: return strMain; break; + case Type::FMT_ENCLOSURE: return strEncl; break; + case Type::FMT_SIGNATURE: return strSign; break; + case Type::FMT_META: return strMeta; break; + default: + Q_ASSERT(0); + return strNull; + break; + } +} + +enum Isds::Type::FileMetaType Isds::m_variant2FileMetaType(const QVariant &v) +{ + if (v.isNull()) { + return Type::FMT_UNKNOWN; + } + + return m_str2FileMetaType(v.toString()); +} + +QVariant Isds::m_fileMetaType2Variant(enum Type::FileMetaType fmt) +{ + if (fmt == Type::FMT_UNKNOWN) { + return QVariant(); + } + + return QVariant(m_fileMetaType2Str(fmt)); +} diff --git a/src/isds/isds_type_conversion.h b/src/isds/isds_type_conversion.h new file mode 100644 index 0000000000000000000000000000000000000000..456eb2248612475343cc2c4290fc2046c3569f78 --- /dev/null +++ b/src/isds/isds_type_conversion.h @@ -0,0 +1,40 @@ +/* + * 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 . + * + * 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 +#include + +#include "src/datovka_shared/isds/types.h" + +namespace Isds { + + enum Type::NilBool str2BoolType(const QString &s); + const QString &boolType2Str(enum Type::NilBool b); + + enum Type::FileMetaType m_str2FileMetaType(const QString &s); + const QString &m_fileMetaType2Str(enum Type::FileMetaType fmt); + enum Type::FileMetaType m_variant2FileMetaType(const QVariant &v); + QVariant m_fileMetaType2Variant(enum Type::FileMetaType fmt); +} diff --git a/src/main.cpp b/src/main.cpp index 8f637a7a745b0a676b5af0f1ae8da73d2d488572..ff958fe8e3509308156f990515b20e02f73d3a37 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -53,7 +53,6 @@ #if defined(Q_OS_ANDROID) #include "src/os_android.h" #endif /* defined(Q_OS_ANDROID) */ -#include "src/qml_interaction/attachment_data.h" #include "src/qml_interaction/image_provider.h" #include "src/qml_interaction/interaction_filesystem.h" #include "src/qml_interaction/interaction_zfo_file.h" @@ -365,7 +364,6 @@ int main(int argc, char *argv[]) /* Register types into QML. */ AccountListModel::declareQML(); - AttachmentData::declareQML(); DataboxListModel::declareQML(); DataboxModelEntry::declareQML(); Dialogues::declareQML(); diff --git a/src/messages.cpp b/src/messages.cpp index 0d0c3735d8c114f3c09a16c9b6d519494377962b..e8a61fd79ac8e79f12258cb72becd0c7ed4917a1 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -29,11 +29,13 @@ #include "src/dialogues/dialogues.h" #include "src/global.h" +#include "src/datovka_shared/isds/type_conversion.h" #include "src/messages.h" #include "src/models/accountmodel.h" #include "src/models/databoxmodel.h" #include "src/models/messagemodel.h" #include "src/settings.h" +#include "src/sqlite/dbs.h" #include "src/sqlite/message_db_container.h" #include "src/sqlite/file_db_container.h" @@ -185,35 +187,40 @@ MsgEnvelope *Messages::getMsgEnvelopeDataAndSetRecipient( return Q_NULLPTR; } - MsgEnvelope msg = msgDb->getMessageEnvelopeFromDb(msgId); + Isds::Envelope envelope = msgDb->getMessageEnvelopeFromDb(msgId); // Add recipient to model DataboxListModel *dbModel = DataboxListModel::fromVariant(dbModelVariant); if (dbModel != Q_NULLPTR) { DataboxModelEntry dbEntry; - dbEntry.setDbID(msg.dbIDSender()); - dbEntry.setDbName(msg.dmSender()); - dbEntry.setDbAddress(msg.dmSenderAddress()); + dbEntry.setDbID(envelope.dbIDSender()); + dbEntry.setDbName(envelope.dmSender()); + dbEntry.setDbAddress(envelope.dmSenderAddress()); dbModel->addEntry(dbEntry); } // Return message envelope data into QML - return new (std::nothrow) MsgEnvelope(msg.dmID(), msg.dmAnnotation(), - msg.dbIDSender(), msg.dmSender(), msg.dmSenderAddress(), - msg.dmSenderType(), msg.dmSenderOrgUnit(), msg.dmSenderOrgUnitNum(), - msg.dmSenderRefNumber(), msg.dmSenderIdent(), msg.dbIDRecipient(), - msg.dmRecipient(), msg.dmRecipientAddress(), - msg.dmRecipientOrgUnit(), msg.dmRecipientOrgUnitNum(), - msg.dmAmbiguousRecipient(), msg.dmRecipientRefNumber(), - msg.dmRecipientIdent(), msg.dmLegalTitleLaw(), - msg.dmLegalTitleYear(), msg.dmLegalTitleSect(), - msg.dmLegalTitlePar(), msg.dmLegalTitlePoint(), msg.dmToHands(), - msg.dmPersonalDelivery(), msg.dmAllowSubstDelivery(), - msg.dmQTimestamp(), msg.dmDeliveryTime(), msg.dmAcceptanceTime(), - msg.dmMessageStatus(), msg.dmAttachmentSize(), msg.dmType(), - msg._dmMessageType(), msg._dmDownloadDate(), msg._dmCustomData(), - msg._dmAttachDownloaded(), msg._dmReadLocally()); + return new (std::nothrow) MsgEnvelope(envelope.dmId(), + envelope.dmAnnotation(), envelope.dbIDSender(), envelope.dmSender(), + envelope.dmSenderAddress(), envelope.dmSenderType(), + envelope.dmSenderOrgUnit(), envelope.dmSenderOrgUnitNumStr(), + envelope.dmSenderRefNumber(), envelope.dmSenderIdent(), + envelope.dbIDRecipient(), envelope.dmRecipient(), + envelope.dmRecipientAddress(), envelope.dmRecipientOrgUnit(), + envelope.dmRecipientOrgUnitNumStr(), + envelope.dmAmbiguousRecipient() == Isds::Type::BOOL_TRUE, + envelope.dmRecipientRefNumber(), envelope.dmRecipientIdent(), + envelope.dmLegalTitleLawStr(), envelope.dmLegalTitleYearStr(), + envelope.dmLegalTitleSect(), envelope.dmLegalTitlePar(), + envelope.dmLegalTitlePoint(), envelope.dmToHands(), + envelope.dmPersonalDelivery() == Isds::Type::BOOL_TRUE, + envelope.dmAllowSubstDelivery() == Isds::Type::BOOL_TRUE, + envelope.dmQTimestamp(), + utcDateTimeToDbFormatStr(envelope.dmDeliveryTime()), + utcDateTimeToDbFormatStr(envelope.dmAcceptanceTime()), + Isds::dmState2Variant(envelope.dmMessageStatus()).toInt(), + envelope.dmAttachmentSize(), envelope.dmType()); } void Messages::markMessageAsLocallyRead(const QVariant &msgModelVariant, diff --git a/src/messages.h b/src/messages.h index 1a63d78e33947adf27a45e2c3395d3ff191c247c..8b8b365f657b30aa4da4ed011b7ba10520cebc13 100644 --- a/src/messages.h +++ b/src/messages.h @@ -185,13 +185,6 @@ public: */ void deleteExpiredMessagesFromDbs(int days); - // Holds message event inforamtion - class Event { - public: - QString dmEventTime; - QString dmEventDescr; - }; - signals: /*! diff --git a/src/net/db_wrapper.cpp b/src/net/db_wrapper.cpp index 86bad4520148601d52610e4cdfc499ba97a9ed1f..98d1c7c1d8703306868c3caf4ad760cf5ccc2310 100644 --- a/src/net/db_wrapper.cpp +++ b/src/net/db_wrapper.cpp @@ -108,7 +108,7 @@ QString DbWrapper::createAccountInfoStringForQml( bool DbWrapper::insertMessageListToDb(const QString &userName, enum MessageDb::MessageType messageType, - const QList &messages, + const QList &envelopes, QList &messageChangedStatusList, QString &txt, QList &listOfNewMsgIds) { @@ -128,42 +128,38 @@ bool DbWrapper::insertMessageListToDb(const QString &userName, } bool isSentMessage = (messageType == MessageDb::TYPE_SENT); - int newMsgs = 0; - int msgs = messages.count(); msgDb->beginTransaction(); - - for (int i = 0; i < msgs; ++i) { - + foreach (const Isds::Envelope &envelope, envelopes) { bool hasFiles; int msgStatus = - msgDb->getMessageStatusFromDb(messages.at(i).dmID(), hasFiles); + msgDb->getMessageStatusFromDb(envelope.dmId(), hasFiles); // -1 = message is not in the database, mesasge is new if (-1 == msgStatus) { newMsgs++; - if (!msgDb->insertOrUpdateMessageEnvelopeInDb(messages.at(i))) { + if (!msgDb->insertOrUpdateMessageEnvelopeInDb( + envelope.dmId(), messageType, envelope)) { txt = tr("Message %1 envelope insertion failed!"). - arg(messages.at(i).dmID()); + arg(envelope.dmId()); } else { // New message envelope has been saved into // database. Append message id to list // of complete messages to be downloaded. - listOfNewMsgIds.append(messages.at(i).dmID()); + listOfNewMsgIds.append(envelope.dmId()); } } else { - if (!msgDb->updateMessageEnvelopeInDb(messages.at(i))) { + if (!msgDb->updateMessageEnvelopeInDb(envelope)) { txt = tr("Message %1 envelope update failed!"). - arg(messages.at(i).dmID()); + arg(envelope.dmId()); } if (isSentMessage) { - if (msgStatus != messages.at(i).dmMessageStatus() && hasFiles) { - messageChangedStatusList.append(messages.at(i).dmID()); + if (msgStatus != envelope.dmMessageStatus() && hasFiles) { + messageChangedStatusList.append(envelope.dmId()); } } } } - msgDb->commitTransaction(); if (!isSentMessage) { @@ -178,8 +174,9 @@ bool DbWrapper::insertMessageListToDb(const QString &userName, return true; } -bool DbWrapper::insertCompleteMessageToDb(const QString &userName, - MsgEnvelope &msg, QList &fileList, QString &txt) +bool DbWrapper::insertCompleteMessageToDb(const QString &userName, qint64 dmId, + const Isds::Message &message, enum MessageDb::MessageType messageType, + QString &txt) { if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) || (GlobInstcs::messageDbsPtr == Q_NULLPTR) || @@ -202,11 +199,11 @@ bool DbWrapper::insertCompleteMessageToDb(const QString &userName, /* Insert or update files into files database */ fDb->beginTransaction(); - for (int i = 0; i < fileList.count(); ++i) { - if (!fDb->insertUpdateFileIntoDb(fileList.at(i))) { + foreach (const Isds::Document &document, message.documents()) { + if (!fDb->insertUpdateFileIntoDb(dmId, document)) { txt = tr("File %1 insertion failed!"). - arg(fileList.at(i).dmFileDescr()); - ret = ret * false; + arg(document.fileDescr()); + ret = false; } } fDb->commitTransaction(); @@ -222,17 +219,17 @@ bool DbWrapper::insertCompleteMessageToDb(const QString &userName, /* Update message envelope data in messages database */ if (ret) { - msg._setDmReadLocally(true); - msg._setDmAttachDownloaded(true); - if (!msgDb->insertOrUpdateMessageEnvelopeInDb(msg)) { + if (!msgDb->insertOrUpdateMessageEnvelopeInDb(dmId, messageType, + message.envelope())) { txt = tr("Message %1 envelope update failed!"). - arg(msg.dmID()); - ret = ret * false; + arg(dmId); + ret = false; } } if (ret) { - msgDb->setAttachmentDownloaded(msg.dmID(), true); + msgDb->markMessageLocallyRead(dmId, true); + msgDb->setAttachmentDownloaded(dmId, true); } txt = tr("Message has been downloaded"); @@ -303,7 +300,7 @@ bool DbWrapper::updateAuthorInfo(const QString &userName, } bool DbWrapper::insertMesasgeDeliveryInfoToDb(const QString &userName, - const QList &eventList, qint64 msgId, QString &txt) + const QList &events, qint64 msgId, QString &txt) { if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) || (GlobInstcs::messageDbsPtr == Q_NULLPTR) || @@ -322,11 +319,11 @@ bool DbWrapper::insertMesasgeDeliveryInfoToDb(const QString &userName, return false; } - ret = ret & msgDb->beginTransaction(); - foreach (const Messages::Event &event, eventList) { - ret = ret & msgDb->insertEventsIntoDb(msgId, event); + ret = ret && msgDb->beginTransaction(); + foreach (const Isds::Event &event, events) { + ret = ret && msgDb->insertEventsIntoDb(msgId, event); } - ret = ret & msgDb->commitTransaction(); + ret = ret && msgDb->commitTransaction(); return ret; } diff --git a/src/net/db_wrapper.h b/src/net/db_wrapper.h index 7005c045bdd46966512bd69b650de7e1b104b166..5ab3060aede39650b39cf7c65ae126fd33adcc10 100644 --- a/src/net/db_wrapper.h +++ b/src/net/db_wrapper.h @@ -21,11 +21,11 @@ * the two. */ -#ifndef _DB_WRAPPER_H_ -#define _DB_WRAPPER_H_ +#pragma once #include /* Q_DECLARE_TR_FUNCTIONS */ +#include "src/datovka_shared/isds/message_interface.h" #include "src/qml_interaction/message_envelope.h" #include "src/sqlite/message_db_container.h" #include "src/sqlite/file_db_container.h" @@ -113,7 +113,7 @@ public: * * @param[in] userName Account username string. * @param[in] messageType Message type. - * @param[in] messages List of message envelopes. + * @param[in] envelopes List of message envelopes. * @param[out] messageChangedStatusList List of message ids * where message status has changed. * @param[out] txt Error description if something fails. @@ -124,7 +124,7 @@ public: static bool insertMessageListToDb(const QString &userName, enum MessageDb::MessageType messageType, - const QList &messages, + const QList &envelopes, QList &messageChangedStatusList, QString &txt, QList &listOfNewMsgIds); @@ -132,14 +132,16 @@ public: * @brief Insert complete message to db. * * @param[in] userName Account username string. - * @param[in] msg Message envelope data. - * @param[in] fileList List of files. + * @param[in] dmId Message Id. + * @param[in] message Message data. + * @param[in] messageType Message type. * @param[out] txt Error description if something fails. * @return true if success. */ static bool insertCompleteMessageToDb(const QString &userName, - MsgEnvelope &msg, QList &fileList, + qint64 dmId, const Isds::Message &message, + enum MessageDb::MessageType messageType, QString &txt); /*! @@ -189,14 +191,14 @@ public: * @brief Insert or update delivery info to db. * * @param[in] userName Account username string. - * @param[in] eventList Event list. + * @param[in] events Event list. * @param[in] msgId Message ID. * @param[out] txt Error description if something fails. * @return true if success. */ static bool insertMesasgeDeliveryInfoToDb(const QString &userName, - const QList &eventList, qint64 msgId, + const QList &events, qint64 msgId, QString &txt); /*! @@ -218,6 +220,3 @@ private: */ DbWrapper(void); }; - - -#endif /* _DB_WRAPPER_H_ */ diff --git a/src/net/isds_wrapper.cpp b/src/net/isds_wrapper.cpp index a3b07cf4740fdfc4f2f3ddbfce6d958f0c3fde7c..847524ed7316d909416094cdefb6acfc4aa593dc 100644 --- a/src/net/isds_wrapper.cpp +++ b/src/net/isds_wrapper.cpp @@ -25,6 +25,9 @@ #include #include "src/auxiliaries/attachment_helper.h" +#include "src/datovka_shared/isds/message_interface.h" +#include "src/datovka_shared/isds/type_conversion.h" +#include "src/datovka_shared/isds/types.h" #include "src/datovka_shared/utility/strings.h" #include "src/datovka_shared/worker/pool.h" #include "src/dialogues/dialogues.h" @@ -616,22 +619,30 @@ void IsdsWrapper::sendMessage(const QString &userName, qint64 dmID, return; } - MsgEnvelope msg; + Isds::Envelope envelope; /* Fill message envelope */ - msg.setDmAnnotation(dmAnnotation); - msg.setDmLegalTitleLaw(dmLegalTitleLaw); - msg.setDmLegalTitleYear(dmLegalTitleYear); - msg.setDmLegalTitleSect(dmLegalTitleSect); - msg.setDmLegalTitlePar(dmLegalTitlePar); - msg.setDmLegalTitlePoint(dmLegalTitlePoint); - msg.setDmToHands(dmToHands); - msg.setDmRecipientRefNumber(dmRecipientRefNumber); - msg.setDmRecipientIdent(dmRecipientIdent); - msg.setDmSenderRefNumber(dmSenderRefNumber); - msg.setDmSenderIdent(dmSenderIdent); - msg.setDmAllowSubstDelivery(dmAllowSubstDelivery); - msg.setDmPersonalDelivery(dmPersonalDelivery); - msg.setDmType(dmType); + envelope.setDmAnnotation(dmAnnotation); + envelope.setDmLegalTitleLawStr(dmLegalTitleLaw); + envelope.setDmLegalTitleYearStr(dmLegalTitleYear); + envelope.setDmLegalTitleSect(dmLegalTitleSect); + envelope.setDmLegalTitlePar(dmLegalTitlePar); + envelope.setDmLegalTitlePoint(dmLegalTitlePoint); + envelope.setDmToHands(dmToHands); + envelope.setDmRecipientRefNumber(dmRecipientRefNumber); + envelope.setDmRecipientIdent(dmRecipientIdent); + envelope.setDmSenderRefNumber(dmSenderRefNumber); + envelope.setDmSenderIdent(dmSenderIdent); + envelope.setDmAllowSubstDelivery(dmAllowSubstDelivery ? + Isds::Type::BOOL_TRUE : Isds::Type::BOOL_FALSE); + envelope.setDmPersonalDelivery(dmPersonalDelivery ? + Isds::Type::BOOL_TRUE : Isds::Type::BOOL_FALSE); + envelope.setDmType(dmType.isEmpty() ? QChar() : dmType[0]); + envelope.setDmMessageStatus(Isds::Type::MS_POSTED); + envelope.setDmOVM(dmOVM ? Isds::Type::BOOL_TRUE : + Isds::Type::BOOL_FALSE); + envelope.setDmPublishOwnID(dmPublishOwnID ? Isds::Type::BOOL_TRUE : + Isds::Type::BOOL_FALSE); + int totalAttachmentSizeKBs = 0; FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb( @@ -645,24 +656,33 @@ void IsdsWrapper::sendMessage(const QString &userName, qint64 dmID, return; } - QList attachList; + QList documents; + Isds::Type::FileMetaType fileMetaType = Isds::Type::FMT_MAIN; /* Load file contents from storage or database to file structure */ foreach (const FileListModel::Entry &file, attachModel->allEntries()) { - AttachmentData attach; - attach.setDmFileDescr(file.dmFileDescr()); + Isds::Document document; + document.setFileDescr(file.dmFileDescr()); + document.setFileMetaType(fileMetaType); + + /* + * Since 2011 Mime Type can be empty and MIME type will + * be filled up on the ISDS server. It allows sending files + * with special mime types without recognition by application. + */ + document.setMimeType(QStringLiteral("")); if (file.fileId() > 0) { // load file content from database, valid file ID - FileDb::FileData fileData = fDb->getFileFromDb(file.fileId()); - attach.setDmEncodedContent(fileData.content); - totalAttachmentSizeKBs += fileData.content.length() / 1024; + document = fDb->getFileFromDb(file.fileId()); + document.setFileMetaType(fileMetaType); + totalAttachmentSizeKBs += document.binaryContent().size() / 1024; } else if (file.fileId() == Files::DB_ZFO_ID) { // load zfo content from zfo database - attach.setDmEncodedContent( + document.setBase64Content( GlobInstcs::zfoDbPtr->getZfoContentFromDb(dmID, (*GlobInstcs::acntMapPtr)[userName].isTestAccount())); - totalAttachmentSizeKBs += attach.dmEncodedContent().length() / 1024; + totalAttachmentSizeKBs += document.binaryContent().size() / 1024; GlobInstcs::zfoDbPtr->updateZfoLastAccessTime(dmID, (*GlobInstcs::acntMapPtr)[userName].isTestAccount()); } else if (!file.filePath().isEmpty()) { @@ -676,20 +696,18 @@ void IsdsWrapper::sendMessage(const QString &userName, qint64 dmID, file.filePath()); return; } - attach.setDmEncodedContent(fin.readAll().toBase64()); + document.setBinaryContent(fin.readAll()); } else { Dialogues::errorMessage(Dialogues::CRITICAL, tr("Error"), tr("No file to sending."), tr("Internal error")); return; } - - attach._setDmFileSize(getApproximatelyAttachmentFileSizeFromBase64(attach.dmEncodedContent().length())); - attach._setIcon(getAttachmentFileIconFromFileExtension(attach.dmFileDescr())); - attachList.append(attach); + documents.append(document); + fileMetaType = Isds::Type::FMT_ENCLOSURE; } - msg.setDmAttachmentSize(totalAttachmentSizeKBs); + envelope.setDmAttachmentSize(totalAttachmentSizeKBs); /* Test if total attachment size is above the limit */ if (totalAttachmentSizeKBs > SEND_ATTACH_SIZE_LIMIT_KB) { @@ -723,17 +741,20 @@ void IsdsWrapper::sendMessage(const QString &userName, qint64 dmID, emit statusBarTextChanged(tr("%1: sending message").arg(userName), true, true); + Isds::Message message; + message.setDocuments(documents); + /* Send message to all recipients. */ for (int i = 0; i < dbList.size(); ++i) { const DataboxModelEntry &db(dbList.at(i)); - msg.setDbIDRecipient(db.dbID()); - msg.setDmRecipient(db.dbName()); - msg.setDmRecipientAddress(db.dbAddress()); + envelope.setDbIDRecipient(db.dbID()); + envelope.setDmRecipient(db.dbName()); + envelope.setDmRecipientAddress(db.dbAddress()); + message.setEnvelope(envelope); TaskSendMessage *task; task = new (std::nothrow) TaskSendMessage( m_isdsSession.isdsCtxMap[userName], &m_netLayer, - msg, attachList, dmOVM, dmPublishOwnID, - taskIdentifiers.at(i)); + message, taskIdentifiers.at(i)); task->setAutoDelete(true); GlobInstcs::workPoolPtr->assignHi(task); } diff --git a/src/net/xml_layer.cpp b/src/net/xml_layer.cpp index 9c8a035c32fedb583af33d2e476a14dd5a6a1e90..4000810b14daa0bb4a17a32ba007d5f5e56d7a1d 100644 --- a/src/net/xml_layer.cpp +++ b/src/net/xml_layer.cpp @@ -24,48 +24,10 @@ #include #include #include -#include -#include "src/auxiliaries/attachment_helper.h" -#include "src/crypto/crypto.h" #include "src/net/isds_const.h" #include "src/net/xml_layer.h" -QByteArray XmlLayer::xmlCreateAuthenticateMessageSoapRequest( - const QByteArray &msg) -{ - QString xmlContent(""); - xmlContent.append(msg); - xmlContent.append(""); - xmlContent.append(""); - return xmlCreateSoapEnvelope(xmlContent); -} - -QByteArray XmlLayer::xmlCreateDownloadMessageSoapRequest(qint64 msgId, - enum Messages::MessageType msgDirect) -{ - QString xmlContent; - if (Messages::TYPE_RECEIVED == msgDirect) { - xmlContent.append(""); - xmlContent.append(QString::number(msgId)); - xmlContent.append(""); - - if (Messages::TYPE_RECEIVED == msgDirect) { - xmlContent.append(""); - } else { - xmlContent.append(""); - } - - return xmlCreateSoapEnvelope(xmlContent); -} - QByteArray XmlLayer::xmlCreateFindDataBoxSoapRequest(const QString &dbID, const QString &dbType) { @@ -88,49 +50,6 @@ QByteArray XmlLayer::xmlCreateFindDataBoxSoapRequest(const QString &dbID, return xmlCreateSoapEnvelope(xmlContent); } -QByteArray XmlLayer::xmlCreateGetMessageAuthorSoapRequest(qint64 msgId) -{ - QString xmlContent(""); - xmlContent.append(QString::number(msgId)); - xmlContent.append(""); - return xmlCreateSoapEnvelope(xmlContent); -} - -QByteArray XmlLayer::xmlCreateGetMessageListSoapRequest( - enum Messages::MessageType msgDirect, uint dmStatusFilter, uint dmOffset, - uint dmLimit) -{ - QString xmlContent; - if (Messages::TYPE_RECEIVED == msgDirect) { - xmlContent.append(""); - - if (Messages::TYPE_RECEIVED == msgDirect) { - xmlContent.append(""); - } else { - xmlContent.append(""); - } - - xmlContent.append(QString("%1").arg(dmStatusFilter)); - xmlContent.append(QString("%1").arg(dmOffset)); - xmlContent.append(QString("%1").arg(dmLimit)); - - if (Messages::TYPE_RECEIVED == msgDirect) { - xmlContent.append(""); - } else { - xmlContent.append(""); - } - - return xmlCreateSoapEnvelope(xmlContent); -} - QByteArray XmlLayer::xmlCreateGetPasswordInfoSoapRequest(void) { QString xmlContent(""); - xmlContent.append(QString::number(msgId)); - xmlContent.append(""); - return xmlCreateSoapEnvelope(xmlContent); -} - -QByteArray XmlLayer::xmlCreateSendMessageSoapRequest(const MsgEnvelope &msg, - const QList &fileList, bool dmOVM, bool dmPublishOwnID) -{ - QString xmlContent(""); - - if (msg.dmType().isEmpty()) { - xmlContent.append(""); - } else { - xmlContent.append(""); - } - xmlContent.append(""); - xmlContent.append(""); - xmlContent.append(msg.dbIDRecipient()); - xmlContent.append(""); - xmlContent.append(""); - if (msg.dmToHands().isEmpty()) { - xmlContent.append(""); - } else { - xmlContent.append(""); - xmlContent.append(msg.dmToHands()); - xmlContent.append(""); - } - xmlContent.append(""); - xmlContent.append(msg.dmAnnotation()); - xmlContent.append(""); - if (msg.dmRecipientRefNumber().isEmpty()) { - xmlContent.append(""); - } else { - xmlContent.append(""); - xmlContent.append(msg.dmRecipientRefNumber()); - xmlContent.append(""); - } - if (msg.dmSenderRefNumber().isEmpty()) { - xmlContent.append(""); - } else { - xmlContent.append(""); - xmlContent.append(msg.dmSenderRefNumber()); - xmlContent.append(""); - } - if (msg.dmRecipientIdent().isEmpty()) { - xmlContent.append(""); - } else { - xmlContent.append(""); - xmlContent.append(msg.dmRecipientIdent()); - xmlContent.append(""); - } - if (msg.dmSenderIdent().isEmpty()) { - xmlContent.append(""); - } else { - xmlContent.append(""); - xmlContent.append(msg.dmSenderIdent()); - xmlContent.append(""); - } - if (msg.dmLegalTitleLaw().isEmpty()) { - xmlContent.append(""); - } else { - xmlContent.append(""); - xmlContent.append(msg.dmLegalTitleLaw()); - xmlContent.append(""); - } - if (msg.dmLegalTitleYear().isEmpty()) { - xmlContent.append(""); - } else { - xmlContent.append(""); - xmlContent.append(msg.dmLegalTitleYear()); - xmlContent.append(""); - } - if (msg.dmLegalTitleSect().isEmpty()) { - xmlContent.append(""); - } else { - xmlContent.append(""); - xmlContent.append(msg.dmLegalTitleSect()); - xmlContent.append(""); - } - if (msg.dmLegalTitlePar().isEmpty()) { - xmlContent.append(""); - } else { - xmlContent.append(""); - xmlContent.append(msg.dmLegalTitlePar()); - xmlContent.append(""); - } - if (msg.dmLegalTitlePoint().isEmpty()) { - xmlContent.append(""); - } else { - xmlContent.append(""); - xmlContent.append(msg.dmLegalTitlePoint()); - xmlContent.append(""); - } - xmlContent.append(""); - xmlContent.append((msg.dmPersonalDelivery())?"true":"false"); - xmlContent.append(""); - - xmlContent.append(""); - xmlContent.append((msg.dmAllowSubstDelivery())?"true":"false"); - xmlContent.append(""); - - xmlContent.append(""); - xmlContent.append((dmOVM)?"true":"false"); - xmlContent.append(""); - - xmlContent.append(""); - xmlContent.append((dmPublishOwnID)?"true":"false"); - xmlContent.append(""); - - xmlContent.append(""); - - xmlContent.append(""); - for (int i = 0; i < fileList.count(); ++i) { - xmlContent.append(" 0) ? xmlContent.append("enclosure") : xmlContent.append("main"); - xmlContent.append("\" dmFileDescr=\""); - xmlContent.append(fileList.at(i).dmFileDescr()); - xmlContent.append("\">"); - xmlContent.append(""); - xmlContent.append(fileList.at(i).dmEncodedContent()); - xmlContent.append(""); - xmlContent.append(""); - } - xmlContent.append(""); - - xmlContent.append(""); - - return xmlCreateSoapEnvelope(xmlContent); -} - QByteArray XmlLayer::xmlCreateSendSMSSoapRequest(void) { QString xmlContent(""); - xmlContent.append(QString::number(msgId)); - xmlContent.append(""); - return xmlCreateSoapEnvelope(xmlContent); -} - QByteArray XmlLayer::xmlCreateSoapEnvelope(const QString &xmlContent) { QString requestContent; @@ -380,197 +150,6 @@ QByteArray XmlLayer::xmlCreateSoapEnvelope(const QString &xmlContent) return requestContent.toUtf8(); } -bool XmlLayer::completeMessageParse(QXmlStreamReader &xml, - MsgEnvelope &msg, QList &fileList) -{ - qDebug("%s()", __func__); - - bool ret = true; - - if (msg.dmType().isNull()) { - msg.setDmType("V"); - } - - while ((xml.tokenType() != QXmlStreamReader::StartElement) - && (xml.name() != "dmDm")) { - return false; - } - - xml.readNext(); - - /* Parse first part of xml response */ - while (!(xml.tokenType() == QXmlStreamReader::EndElement - && xml.name() == "dmDm")) { - if (xml.tokenType() == QXmlStreamReader::StartElement) { - if (xml.name() == "dmID") { - xml.readNext(); - msg.setDmID(xml.text().toLongLong()); - } else - if (xml.name() == "dbIDSender") { - xml.readNext(); - msg.setDbIDSender(xml.text().toString()); - } else - if (xml.name() == "dmSender") { - xml.readNext(); - msg.setDmSender(xml.text().toString()); - } else - if (xml.name() == "dmSenderAddress") { - xml.readNext(); - msg.setDmSenderAddress(xml.text().toString()); - } else - if (xml.name() == "dmSenderType") { - xml.readNext(); - msg.setDmSenderType(xml.text().toInt()); - } else - if (xml.name() == "dmRecipient") { - xml.readNext(); - msg.setDmRecipient(xml.text().toString()); - } else - if (xml.name() == "dmRecipientAddress") { - xml.readNext(); - msg.setDmRecipientAddress(xml.text().toString()); - } else - if (xml.name() == "dmSenderOrgUnit") { - xml.readNext(); - msg.setDmSenderOrgUnit(xml.text().toString()); - } else - if (xml.name() == "dmSenderOrgUnitNum") { - xml.readNext(); - msg.setDmSenderOrgUnitNum(xml.text().toString()); - } else - if (xml.name() == "dbIDRecipient") { - xml.readNext(); - msg.setDbIDRecipient(xml.text().toString()); - } else - if (xml.name() == "dmRecipientOrgUnit") { - xml.readNext(); - msg.setDmRecipientOrgUnit(xml.text().toString()); - } else - if (xml.name() == "dmRecipientOrgUnitNum") { - xml.readNext(); - msg.setDmRecipientOrgUnitNum(xml.text().toString()); - } else - if (xml.name() == "dmToHands") { - xml.readNext(); - msg.setDmToHands(xml.text().toString()); - } else - if (xml.name() == "dmAnnotation") { - xml.readNext(); - msg.setDmAnnotation(xml.text().toString()); - } else - if (xml.name() == "dmRecipientRefNumber") { - xml.readNext(); - msg.setDmRecipientRefNumber(xml.text().toString()); - } else - if (xml.name() == "dmSenderRefNumber") { - xml.readNext(); - msg.setDmSenderRefNumber(xml.text().toString()); - } else - if (xml.name() == "dmRecipientIdent") { - xml.readNext(); - msg.setDmRecipientIdent(xml.text().toString()); - } else - if (xml.name() == "dmSenderIdent") { - xml.readNext(); - msg.setDmSenderIdent(xml.text().toString()); - } else - if (xml.name() == "dmLegalTitleLaw") { - xml.readNext(); - msg.setDmLegalTitleLaw(xml.text().toString()); - } else - if (xml.name() == "dmLegalTitleYear") { - xml.readNext(); - msg.setDmLegalTitleYear(xml.text().toString()); - } else - if (xml.name() == "dmLegalTitleSect") { - xml.readNext(); - msg.setDmLegalTitleSect(xml.text().toString()); - } else - if (xml.name() == "dmLegalTitlePar") { - xml.readNext(); - msg.setDmLegalTitlePar(xml.text().toString()); - } else - if (xml.name() == "dmLegalTitlePoint") { - xml.readNext(); - msg.setDmLegalTitlePoint(xml.text().toString()); - } else - if (xml.name() == "dmPersonalDelivery") { - xml.readNext(); - msg.setDmPersonalDelivery(false); - if (xml.text().toString() == "true") { - msg.setDmPersonalDelivery(true); - } - } else - if (xml.name() == "dmAllowSubstDelivery") { - xml.readNext(); - msg.setDmAllowSubstDelivery(false); - if (xml.text().toString() == "true") { - msg.setDmAllowSubstDelivery(true); - } - } else - /* Parse file part of xml response */ - if (xml.name() == "dmFiles") { - xml.readNext(); - while (!(xml.tokenType() == QXmlStreamReader::EndElement - && xml.name() == "dmFiles")) { - fileList.append(parseFile(xml, msg.dmID())); - xml.readNext(); - } - } - } - xml.readNext(); - } - - /* Parse other parts of xml response */ - while (!(xml.tokenType() == QXmlStreamReader::EndElement - && xml.name() == "dmReturnedMessage")) { - if (xml.error() != QXmlStreamReader::NoError) { - return false; - } - if (xml.tokenType() == QXmlStreamReader::StartElement) { - if (xml.name() == "dmDeliveryTime") { - xml.readNext(); - msg.setDmDeliveryTime(xml.text().toString()); - } else - if (xml.name() == "dmAcceptanceTime") { - xml.readNext(); - msg.setDmAcceptanceTime(xml.text().toString()); - } else - if (xml.name() == "dmMessageStatus") { - xml.readNext(); - msg.setDmMessageStatus(xml.text().toInt()); - } else - if (xml.name() == "dmAttachmentSize") { - xml.readNext(); - msg.setDmAttachmentSize(xml.text().toInt()); - } - } - xml.readNext(); - } - - return ret; -} - -Messages::Event XmlLayer::parseEvent(QXmlStreamReader &xml) -{ - Messages::Event event; - while (!(xml.tokenType() == QXmlStreamReader::EndElement - && xml.name() == "dmEvent")) { - if (xml.tokenType() == QXmlStreamReader::StartElement) { - if (xml.name() == "dmEventTime") { - xml.readNext(); - event.dmEventTime = xml.text().toString(); - } else if (xml.name() == "dmEventDescr") { - xml.readNext(); - event.dmEventDescr = xml.text().toString(); - } - } - xml.readNext(); - } - - return event; -} - bool XmlLayer::parseDmStatusFromXml(const QByteArray &xmlData, QString &txt) { QXmlStreamReader xml; @@ -643,164 +222,11 @@ bool XmlLayer::parseDbStatusFromXml(const QByteArray &xmlData, QString &txt) return (dbStatusCode == "0000"); } -bool XmlLayer::parseSentMessageStatusFromXml(const QByteArray &xmlData, - qint64 &msgID, QString &txt) -{ - QXmlStreamReader xml; - xml.addData(xmlData); - QString dmStatusCode = "-1"; - - while(!xml.atEnd() && !xml.hasError()) { - QXmlStreamReader::TokenType token = xml.readNext(); - if (token == QXmlStreamReader::StartDocument) { - continue; - } - if (token == QXmlStreamReader::StartElement) { - if (xml.name() == "dmStatus") { - /* Parse first part of xml response */ - while (!(xml.tokenType() == QXmlStreamReader::EndElement - && xml.name() == "dmStatus")) { - if (xml.tokenType() == - QXmlStreamReader::StartElement) { - if (xml.name() == "dmStatusCode") { - xml.readNext(); - dmStatusCode = - xml.text().toString(); - } else if (xml.name() == "dmStatusMessage") { - xml.readNext(); - txt = xml.text().toString(); - } - } - xml.readNext(); - } - } - if (xml.name() == "dmID") { - xml.readNext(); - msgID = xml.text().toLongLong(); - } - } - } - - return (dmStatusCode == "0000"); -} - bool XmlLayer::parseLoginResponse(const QByteArray &xmlData, QString &txt) { return parseDmStatusFromXml(xmlData, txt); } -bool XmlLayer::parseSignedMessageDownloadResponse(const QByteArray &xmlData, - MsgEnvelope &msg, QList &fileList, QString &txt, - QByteArray &zfoData) -{ - qDebug("%s()", __func__); - - if (!parseDmStatusFromXml(xmlData, txt)) { - return false; - } - - QXmlStreamReader xml1; - xml1.addData(xmlData); - QByteArray signature; - - /* parse signature from XML */ - while(!xml1.atEnd() && !xml1.hasError()) { - QXmlStreamReader::TokenType token = xml1.readNext(); - if (token == QXmlStreamReader::StartDocument) { - continue; - } - if (token == QXmlStreamReader::StartElement) { - if (xml1.name() == "dmSignature") { - xml1.readNext(); - signature = xml1.text().toUtf8(); - } - } - } - - /* decode signature from base64 and obtain something cms message */ - QByteArray cmsData = QByteArray::fromBase64(signature); - - zfoData = cmsData; - - /* decode cms and obtain message xml data - used openssl */ - void *xmlContent = NULL; - size_t xmlContentLen = 0; - if (extract_cms_data(cmsData.data(), cmsData.length(), &xmlContent, - &xmlContentLen) != 0) { - return false; - } - if (xmlContentLen == 0) { - free(xmlContent); xmlContent = NULL; - return false; - } - QByteArray soap((char*)xmlContent, xmlContentLen); - free(xmlContent); xmlContent = NULL; - - /* add xml SOAP header anf footer */ - soap.prepend("" - "" - ""); - soap.append(""); - - /* Parse XML */ - QXmlStreamReader xml; - xml.addData(soap); - - while(!xml.atEnd() && !xml.hasError()) { - QXmlStreamReader::TokenType token = xml.readNext(); - if (xml.error() != QXmlStreamReader::NoError) { - return false; - } - if (token == QXmlStreamReader::StartDocument) { - continue; - } - if (token == QXmlStreamReader::StartElement) { - if (xml.name() == "dmReturnedMessage") { - foreach (const QXmlStreamAttribute &attr, xml.attributes()) { - if (attr.name() == "dmType") { - msg.setDmType(attr.value().toString()); - } - } - } - if (xml.name() == "dmDm") { - completeMessageParse(xml, msg, fileList); - } - } - } - - return true; -} - -bool XmlLayer::parseGetListOfMessagesResponse(enum MessageDb::MessageType messageType, - const QByteArray &xmlData, QList &messages, QString &txt) -{ - qDebug("%s()", __func__); - - if (!parseDmStatusFromXml(xmlData, txt)) { - return false; - } - - QXmlStreamReader xml; - xml.addData(xmlData); - - while(!xml.atEnd() && !xml.hasError()){ - QXmlStreamReader::TokenType token = xml.readNext(); - if (token == QXmlStreamReader::StartDocument) { - continue; - } - if (token == QXmlStreamReader::StartElement) { - if (xml.name() == "dmRecord") { - messages.append(msgEnvelopeParse(xml, - messageType)); - } - } - } - - return true; -} - bool XmlLayer::parseGetOwnerInfoFromLogin(const QByteArray &xmlData, DbWrapper::AccountInfo &accountInfo, QString &txt) { @@ -1093,109 +519,6 @@ bool XmlLayer::dbUserInfoParse(QXmlStreamReader &xml, return true; } -bool XmlLayer::parseGetAuthorInfo(const QByteArray &xmlData, QString &userType, - QString &authorName, QString &txt) -{ - qDebug("%s()", __func__); - - if (!parseDmStatusFromXml(xmlData, txt)) { - return false; - } - - QXmlStreamReader xml; - xml.addData(xmlData); - - while(!xml.atEnd() && !xml.hasError()){ - QXmlStreamReader::TokenType token = xml.readNext(); - if (token == QXmlStreamReader::StartDocument) { - continue; - } - if (token == QXmlStreamReader::StartElement) { - if (xml.name() == "userType") { - xml.readNext(); - userType = xml.text().toString(); - } else - if (xml.name() == "authorName") { - xml.readNext(); - authorName = xml.text().toString(); - } - } - } - - return true; -} - -bool XmlLayer::parseGetSignedMsgDeliveryInfoResponse(const QByteArray &xmlData, - QList &eventList, QString &txt) -{ - qDebug("%s()", __func__); - - if (!parseDmStatusFromXml(xmlData, txt)) { - return false; - } - - QXmlStreamReader xml1; - xml1.addData(xmlData); - QByteArray signature; - - /* parse signature from XML */ - while(!xml1.atEnd() && !xml1.hasError()) { - QXmlStreamReader::TokenType token = xml1.readNext(); - if (token == QXmlStreamReader::StartDocument) { - continue; - } - if (token == QXmlStreamReader::StartElement) { - if (xml1.name() == "dmSignature") { - xml1.readNext(); - signature = xml1.text().toUtf8(); - } - } - } - - /* decode signature from base64 and obtain something cms message */ - QByteArray cmsData = QByteArray::fromBase64(signature); - - /* decode cms and obtain message xml data - used openssl */ - void *xmlContent = NULL; - size_t xmlContentLen = 0; - if (extract_cms_data(cmsData.data(), cmsData.length(), &xmlContent, - &xmlContentLen) != 0) { - return false; - } - if (xmlContentLen == 0) { - free(xmlContent); xmlContent = NULL; - return false; - } - QByteArray soap((char*)xmlContent, xmlContentLen); - free(xmlContent); xmlContent = NULL; - - /* add xml SOAP header anf footer */ - soap.prepend("" - "" - ""); - soap.append(""); - - /* Parse XML */ - QXmlStreamReader xml; - xml.addData(soap); - - while(!xml.atEnd() && !xml.hasError()){ - QXmlStreamReader::TokenType token = xml.readNext(); - if (token == QXmlStreamReader::StartDocument) { - continue; - } - if (token == QXmlStreamReader::StartElement) { - if (xml.name() == "dmEvent") { - eventList.append(parseEvent(xml)); - } - } - } - - return true; -} - bool XmlLayer::parseISDSSearch2SoapResponse(const QByteArray &xmlData, QList &dbList, int &totalCount, int ¤tCount, int &position, bool &lastPage, QString &txt) @@ -1240,169 +563,6 @@ bool XmlLayer::parseISDSSearch2SoapResponse(const QByteArray &xmlData, return true; } -MsgEnvelope XmlLayer::msgEnvelopeParse(QXmlStreamReader &xml, - enum MessageDb::MessageType messageType) -{ - MsgEnvelope msg; - - while ((xml.tokenType() != QXmlStreamReader::StartElement) - && (xml.name() != "dmRecord")) { - return msg; - } - - foreach (const QXmlStreamAttribute &attr, xml.attributes()) { - if (attr.name() == "dmType") { - msg.setDmType(attr.value().toString()); - } - } - - xml.readNext(); - - while (!(xml.tokenType() == QXmlStreamReader::EndElement - && xml.name() == "dmRecord")) { - if (xml.tokenType() == QXmlStreamReader::StartElement) { - if (xml.name() == "dmOrdinal") { - xml.readNext(); - } - if (xml.name() == "dmID") { - xml.readNext(); - msg.setDmID(xml.text().toLongLong()); - } else - if (xml.name() == "dbIDSender") { - xml.readNext(); - msg.setDbIDSender(xml.text().toString()); - } else - if (xml.name() == "dmSender") { - xml.readNext(); - msg.setDmSender(xml.text().toString()); - } else - if (xml.name() == "dmSenderAddress") { - xml.readNext(); - msg.setDmSenderAddress(xml.text().toString()); - } else - if (xml.name() == "dmSenderType") { - xml.readNext(); - msg.setDmSenderType(xml.text().toInt()); - } else - if (xml.name() == "dmRecipient") { - xml.readNext(); - msg.setDmRecipient(xml.text().toString()); - } else - if (xml.name() == "dmRecipientAddress") { - xml.readNext(); - msg.setDmRecipientAddress(xml.text().toString()); - } else - if (xml.name() == "dmSenderOrgUnit") { - xml.readNext(); - msg.setDmSenderOrgUnit(xml.text().toString()); - } else - if (xml.name() == "dmSenderOrgUnitNum") { - xml.readNext(); - msg.setDmSenderOrgUnitNum(xml.text().toString()); - } else - if (xml.name() == "dbIDRecipient") { - xml.readNext(); - msg.setDbIDRecipient(xml.text().toString()); - } else - if (xml.name() == "dmRecipientOrgUnit") { - xml.readNext(); - msg.setDmRecipientOrgUnit(xml.text().toString()); - } else - if (xml.name() == "dmRecipientOrgUnitNum") { - xml.readNext(); - msg.setDmRecipientOrgUnitNum(xml.text().toString()); - } else - if (xml.name() == "dmToHands") { - xml.readNext(); - msg.setDmToHands(xml.text().toString()); - } else - if (xml.name() == "dmAnnotation") { - xml.readNext(); - msg.setDmAnnotation(xml.text().toString()); - } else - if (xml.name() == "dmRecipientRefNumber") { - xml.readNext(); - msg.setDmRecipientRefNumber(xml.text().toString()); - } else - if (xml.name() == "dmSenderRefNumber") { - xml.readNext(); - msg.setDmSenderRefNumber(xml.text().toString()); - } else - if (xml.name() == "dmRecipientIdent") { - xml.readNext(); - msg.setDmRecipientIdent(xml.text().toString()); - } else - if (xml.name() == "dmSenderIdent") { - xml.readNext(); - msg.setDmSenderIdent(xml.text().toString()); - } else - if (xml.name() == "dmLegalTitleLaw") { - xml.readNext(); - msg.setDmLegalTitleLaw(xml.text().toString()); - } else - if (xml.name() == "dmLegalTitleYear") { - xml.readNext(); - msg.setDmLegalTitleYear(xml.text().toString()); - } else - if (xml.name() == "dmLegalTitleSect") { - xml.readNext(); - msg.setDmLegalTitleSect(xml.text().toString()); - } else - if (xml.name() == "dmLegalTitlePar") { - xml.readNext(); - msg.setDmLegalTitlePar(xml.text().toString()); - } else - if (xml.name() == "dmLegalTitlePoint") { - xml.readNext(); - msg.setDmLegalTitlePoint(xml.text().toString()); - } else - if (xml.name() == "dmPersonalDelivery") { - xml.readNext(); - msg.setDmPersonalDelivery(false); - if (xml.text().toString() == "true") { - msg.setDmPersonalDelivery(true); - } - } else - if (xml.name() == "dmAllowSubstDelivery") { - xml.readNext(); - msg.setDmAllowSubstDelivery(false); - if (xml.text().toString() == "true") { - msg.setDmAllowSubstDelivery(true); - } - } else - if (xml.name() == "dmMessageStatus") { - xml.readNext(); - msg.setDmMessageStatus(xml.text().toInt()); - } else - if (xml.name() == "dmAttachmentSize") { - xml.readNext(); - msg.setDmAttachmentSize(xml.text().toInt()); - } else - if (xml.name() == "dmDeliveryTime") { - xml.readNext(); - msg.setDmDeliveryTime(xml.text().toString()); - } else - if (xml.name() == "dmAcceptanceTime") { - xml.readNext(); - msg.setDmAcceptanceTime(xml.text().toString()); - } - } - xml.readNext(); - } - - if (msg.dmType().isNull()) { - msg.setDmType("V"); - } - - msg.setDmQTimestamp(QString()); - msg._setDmMessageType(messageType); - msg._setDmReadLocally(false); - msg._setDmCustomData(QString()); - msg._setDmAttachDownloaded(false); - - return msg; -} - DataboxModelEntry XmlLayer::parseDataboxData(QXmlStreamReader &xml) { while ((xml.tokenType() != QXmlStreamReader::StartElement) @@ -1454,44 +614,6 @@ DataboxModelEntry XmlLayer::parseDataboxData(QXmlStreamReader &xml) dbEffectiveOVM, dbSendOptions); } -AttachmentData XmlLayer::parseFile(QXmlStreamReader &xml, const qint64 msgId) -{ - qDebug("%s()", __func__); - - AttachmentData file; - file.setDmId(msgId); - - while (!(xml.tokenType() == QXmlStreamReader::EndElement - && xml.name() == "dmFile")) { - if ((xml.tokenType() == QXmlStreamReader::StartElement) - && (xml.name() == "dmFile")) { - foreach(const QXmlStreamAttribute &attr, xml.attributes()) { - if (attr.name() == "dmFileDescr") { - file.setDmFileDescr(attr.value().toString()); - } else if (attr.name() == "dmUpFileGuid") { - file.setDmUpFileGuid(attr.value().toString()); - } else if (attr.name() == "dmFileGuid") { - file.setDmFileGuid(attr.value().toString()); - } else if (attr.name() == "dmMimeType") { - file.setDmMimeType(attr.value().toString()); - } else if (attr.name() == "dmFormat") { - file.setDmFormat(attr.value().toString()); - } else if (attr.name() == "dmFileMetaType") { - file.setDmFileMetaType(attr.value().toString()); - } - } - } else if ((xml.tokenType() == QXmlStreamReader::StartElement) - && (xml.name() == "dmEncodedContent")) { - xml.readNext(); - file.setDmEncodedContent(xml.text().toString()); - file._setDmFileSize(getApproximatelyAttachmentFileSizeFromBase64(file.dmEncodedContent().length())); - file._setIcon(getAttachmentFileIconFromFileExtension(file.dmFileDescr())); - } - xml.readNext(); - } - return file; -} - bool XmlLayer::parseFindDataBoxSoapResponse(const QByteArray &xmlData, QString &dbInfo, QString &txt) { @@ -1513,93 +635,3 @@ bool XmlLayer::parseFindDataBoxSoapResponse(const QByteArray &xmlData, return ret; } - -bool XmlLayer::parseZFO(const QByteArray &content, MsgEnvelope &msg, - QList &fileList, QString &txt) -{ - qDebug("%s()", __func__); - - QByteArray cmsData = content; - - /* decode cms and obtain message xml data - used openssl */ - void *xmlContent = NULL; - size_t xmlContentLen = 0; - if (extract_cms_data(cmsData.data(), cmsData.length(), &xmlContent, - &xmlContentLen) != 0) { - txt = tr("ZFO format invalid."); - return false; - } - if (xmlContentLen == 0) { - free(xmlContent); xmlContent = NULL; - txt = tr("ZFO format invalid."); - return false; - } - QByteArray soap((char*)xmlContent, xmlContentLen); - free(xmlContent); xmlContent = NULL; - - /* add xml SOAP header anf footer */ - soap.prepend("" - "" - ""); - soap.append(""); - - /* Parse XML */ - QXmlStreamReader xml; - xml.addData(soap); - - while(!xml.atEnd() && !xml.hasError()) { - QXmlStreamReader::TokenType token = xml.readNext(); - if (xml.error() != QXmlStreamReader::NoError) { - return false; - } - if (token == QXmlStreamReader::StartDocument) { - continue; - } - if (token == QXmlStreamReader::StartElement) { - if (xml.name() == "dmReturnedMessage") { - foreach (const QXmlStreamAttribute &attr, xml.attributes()) { - if (attr.name() == "dmType") { - msg.setDmType(attr.value().toString()); - } - } - } - if (xml.name() == "dmDm") { - completeMessageParse(xml, msg, fileList); - } - } - } - - return true; -} - -bool XmlLayer::parseAuthenticateMessage(const QByteArray &xmlData, QString &txt) -{ - qDebug("%s()", __func__); - - if (!parseDmStatusFromXml(xmlData, txt)) { - return false; - } - - QXmlStreamReader xml; - xml.addData(xmlData); - bool isValid = false; - - while(!xml.atEnd() && !xml.hasError()){ - QXmlStreamReader::TokenType token = xml.readNext(); - if (token == QXmlStreamReader::StartDocument) { - continue; - } - if (token == QXmlStreamReader::StartElement) { - if (xml.name() == "dmAuthResult") { - xml.readNext(); - if (xml.text().toString() == "true") { - isValid = true; - } - } - } - } - - return isValid; -} diff --git a/src/net/xml_layer.h b/src/net/xml_layer.h index 26618583c655004156eb5ba0144f2dafc50114fc..4c423781d760c5db4fdaad298afb808bf97ec75a 100644 --- a/src/net/xml_layer.h +++ b/src/net/xml_layer.h @@ -21,16 +21,13 @@ * the two. */ -#ifndef _XML_LAYER_H_ -#define _XML_LAYER_H_ +#pragma once #include /* Q_DECLARE_TR_FUNCTIONS */ -#include #include #include "src/models/databoxmodel.h" #include "src/net/db_wrapper.h" -#include "src/qml_interaction/message_envelope.h" /* * Class XmlLayer realizes XML layer of SOAP. @@ -40,27 +37,6 @@ class XmlLayer { Q_DECLARE_TR_FUNCTIONS(XmlLayer) public: - /*! - * @brief Create authenticate message soap request. - * - * @param[in] msg Message content. - * @return Soap request string as byte array. - */ - static - QByteArray xmlCreateAuthenticateMessageSoapRequest( - const QByteArray &msg); - - /*! - * @brief Create download message soap request. - * - * @param[in] msgId Message ID. - * @param[in] msgDirect Message orientation. - * @return Soap request string as byte array. - */ - static - QByteArray xmlCreateDownloadMessageSoapRequest(qint64 msgId, - enum Messages::MessageType msgDirect); - /*! * @brief Create find databox info soap request. * @@ -72,29 +48,6 @@ public: QByteArray xmlCreateFindDataBoxSoapRequest(const QString &dbID, const QString &dbType); - /*! - * @brief Create get message author soap request. - * - * @param[in] msgId Message ID. - * @return Soap request string as byte array. - */ - static - QByteArray xmlCreateGetMessageAuthorSoapRequest(qint64 msgId); - - /*! - * @brief Create get message list soap request. - * - * @param[in] msgDirect Message orientation. - * @param[in] dmStatusFilter Message filter (see ISDS manual). - * @param[in] dmOffset Message offset (see ISDS manual). - * @param[in] dmLimit Message limit to by downloaded. - * @return Soap request string as byte array. - */ - static - QByteArray xmlCreateGetMessageListSoapRequest( - enum Messages::MessageType msgDirect, uint dmStatusFilter, - uint dmOffset, uint dmLimit); - /*! * @brief Create get password expiration soap request. * @@ -168,28 +121,6 @@ public: static QByteArray xmlCreateLoginPingSoapRequest(void); - /*! - * @brief Create mark message as downloaded soap request. - * - * @param[in] msgId Message ID. - * @return Soap request string as byte array. - */ - static - QByteArray xmlCreateMarkMessageAsDownloadedSoapRequest(qint64 msgId); - - /*! - * @brief Create send message soap request. - * - * @param[in] msg Message envelope. - * @param[in] fileList List of files. - * @param[in] dmOVM True if send message as OVM. - * @param[in] dmPublishOwnID True if add sender name to message. - * @return Soap request string as byte array. - */ - static - QByteArray xmlCreateSendMessageSoapRequest(const MsgEnvelope &msg, - const QList &fileList, bool dmOVM, bool dmPublishOwnID); - /*! * @brief Create send SMS soap request. * @@ -198,15 +129,6 @@ public: static QByteArray xmlCreateSendSMSSoapRequest(void); - /*! - * @brief Create signed deliveriy info soap request. - * - * @param[in] msgId Message ID. - * @return Soap request string as byte array. - */ - static - QByteArray xmlCreateSignedDeliveryInfoSoapRequest(qint64 msgId); - /*! * @brief Create SOAP envelope over xml data. * @@ -216,27 +138,6 @@ public: static QByteArray xmlCreateSoapEnvelope(const QString &xmlContent); - /*! - * @brief Parse completeMessageParse XML. - * - * @param[in] xml Xml data for parsing. - * @param[out] msg Envelope message structure. - * @param[out] fileList List of files structure. - * @return true if success. - */ - static - bool completeMessageParse(QXmlStreamReader &xml, MsgEnvelope &msg, - QList &fileList); - - /*! - * @brief Parse event from XML. - * - * @param[in] xml Xml data for parsing. - * @return Event structure. - */ - static - Messages::Event parseEvent(QXmlStreamReader &xml); - /*! * @brief Parse dmStatus from XML response. * @@ -257,18 +158,6 @@ public: static bool parseDbStatusFromXml(const QByteArray &xmlData, QString &txt); - /*! - * @brief Parse send message status and message ID from XML response. - * - * @param[in] xmlData Xml data for parsing. - * @param[out] msgID Sent message ID. - * @param[out] txt Error description if something failed. - * @return true if success. - */ - static - bool parseSentMessageStatusFromXml(const QByteArray &xmlData, - qint64 &msgID, QString &txt); - /*! * @brief Parse loginResponse XML. * @@ -279,34 +168,6 @@ public: static bool parseLoginResponse(const QByteArray &xmlData, QString &txt); - /*! - * @brief Parse getListOfMessagesResponse XML. - * - * @param[in] messageType Message type (sent/received). - * @param[in] xmlData Xml Data for parsing. - * @param[out] txt Error description if something failed. - * @return true if success. - */ - static - bool parseGetListOfMessagesResponse(enum MessageDb::MessageType messageType, - const QByteArray &xmlData, QList &messages, - QString &txt); - - /*! - * @brief Parse SignedMessageDownloadResponse XML. - * - * @param[in] xmlData Xml Data for parsing. - * @param[out] msg Envelope message structure. - * @param[out] fileList List of files structure. - * @param[out] txt Error description if something failed. - * @param[out] zfoData ZFO file content. - * @return true if success. - */ - static - bool parseSignedMessageDownloadResponse(const QByteArray &xmlData, - MsgEnvelope &msg, QList &fileList, QString &txt, - QByteArray &zfoData); - /*! * @brief Parse getOwnerInfoFromLogin XML. * @@ -366,31 +227,6 @@ public: bool dbUserInfoParse(QXmlStreamReader &xml, DbWrapper::UserInfo &userInfo); - /*! - * @brief Parse message author xml data. - * - * @param[in] xmlData Sml Data for parsing. - * @param[out] userType Author type string. - * @param[out] authorName Author name string. - * @param[out] txt Error description if something failed. - * @return true if success. - */ - static - bool parseGetAuthorInfo(const QByteArray &xmlData, QString &userType, - QString &authorName, QString &txt); - - /*! - * @brief Parse signed message delivery info xml. - * - * @param[in] xmlData Xml Data for parsing. - * @param[out] eventList List of message events. - * @param[out] txt Error description if something failed. - * @return true if success. - */ - static - bool parseGetSignedMsgDeliveryInfoResponse(const QByteArray &xmlData, - QList &eventList, QString &txt); - /*! * @brief Parse idsd search 2 xml. * @@ -407,16 +243,6 @@ public: bool parseISDSSearch2SoapResponse(const QByteArray &xmlData, QList &dbList, int &totalCount, int ¤tCount, int &position, bool &lastPage, QString &txt); - /*! - * @brief Parse message envleope xml data. - * - * @param[in] xml Xml Data for parsing. - * @param[in] messageType Message type. - * @return Message envelope structure. - */ - static - MsgEnvelope msgEnvelopeParse(QXmlStreamReader &xml, - enum MessageDb::MessageType messageType); /*! * @brief Parse databox xml data. @@ -427,16 +253,6 @@ public: static DataboxModelEntry parseDataboxData(QXmlStreamReader &xml); - /*! - * @brief Parse message file xml data . - * - * @param[in] xml Xml Data for parsing. - * @param[in] msgId Message id. - * @return File structure. - */ - static - AttachmentData parseFile(QXmlStreamReader &xml, const qint64 msgId); - /*! * @brief Parse find databox info xml data. * @@ -449,34 +265,9 @@ public: bool parseFindDataBoxSoapResponse(const QByteArray &xmlData, QString &dbInfo, QString &txt); - /*! - * @brief Parse ZFO file xml data . - * - * @param[in] content ZFO content for parsing. - * @param[out] msg Message enevelope structure. - * @param[out] fileList List of attachments. - * @param[out] txt Error description. - * @return true if success. - */ - static - bool parseZFO(const QByteArray &content, - MsgEnvelope &msg, QList &fileList, QString &txt); - - /*! - * @brief Parse authenticate messagee xml data. - * - * @param[in] xmlData Xml Data for parsing. - * @param[out] txt Error description if something failed. - * @return true if success. - */ - static - bool parseAuthenticateMessage(const QByteArray &xmlData, QString &txt); - private: /*! * @brief Private constructor. */ XmlLayer(void); }; - -#endif /* _XML_LAYER_H_ */ diff --git a/src/qml_interaction/attachment_data.cpp b/src/qml_interaction/attachment_data.cpp deleted file mode 100644 index c2080b3e1ec678a963ec5ce6826f27dab8778471..0000000000000000000000000000000000000000 --- a/src/qml_interaction/attachment_data.cpp +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (C) 2014-2017 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 . - * - * 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 /* qmlRegisterType */ - -#include "src/qml_interaction/attachment_data.h" - -void AttachmentData::declareQML(void) -{ - qmlRegisterType("cz.nic.mobileDatovka.attachmentData", 1, 0, "AttachmentData"); - qRegisterMetaType(); -} - -AttachmentData::AttachmentData(QObject *parent) - : QObject(parent), - m_fileId(0), - m_dmId(0), - m_dmFileDescr(), - m_dmUpFileGuid(), - m_dmFileGuid(), - m_dmMimeType(), - m_dmFormat(), - m_dmFileMetaType(), - m_dmEncodedContent(), - m_dmFileSize(), - m_dmDownloadDate(), - m_icon() -{ -} - -AttachmentData::AttachmentData(const AttachmentData &data) - : QObject(), - m_fileId(data.m_fileId), - m_dmId(data.m_dmId), - m_dmFileDescr(data.m_dmFileDescr), - m_dmUpFileGuid(data.m_dmUpFileGuid), - m_dmFileGuid(data.m_dmFileGuid), - m_dmMimeType(data.m_dmMimeType), - m_dmFormat(data.m_dmFormat), - m_dmFileMetaType(data.m_dmFileMetaType), - m_dmEncodedContent(data.m_dmEncodedContent), - m_dmFileSize(data.m_dmFileSize), - m_dmDownloadDate(data.m_dmDownloadDate), - m_icon(data.m_icon) -{ -} - -AttachmentData::AttachmentData(int fileId, qint64 dmId, - const QString &dmFileDescr, const QString &dmUpFileGuid, - const QString &dmFileGuid, const QString &dmMimeType, const QString &dmFormat, - const QString &dmFileMetaType, const QString &dmEncodedContent, - const QString &_dmFileSize, const QString &_dmDownloadDate, - const QString &_icon, QObject *parent) - : QObject(parent), - m_fileId(fileId), - m_dmId(dmId), - m_dmFileDescr(dmFileDescr), - m_dmUpFileGuid(dmUpFileGuid), - m_dmFileGuid(dmFileGuid), - m_dmMimeType(dmMimeType), - m_dmFormat(dmFormat), - m_dmFileMetaType(dmFileMetaType), - m_dmEncodedContent(dmEncodedContent), - m_dmFileSize(_dmFileSize), - m_dmDownloadDate(_dmDownloadDate), - m_icon(_icon) -{ -} - -int AttachmentData::fileId(void) const -{ - return m_fileId; -} - -void AttachmentData::setFileId(int fileId) -{ - m_fileId = fileId; -} - -qint64 AttachmentData::dmId(void) const -{ - return m_dmId; -} - -void AttachmentData::setDmId(qint64 dmId) -{ - m_dmId = dmId; -} - -QString AttachmentData::dmFileDescr(void) const -{ - return m_dmFileDescr; -} - -void AttachmentData::setDmFileDescr(const QString &dmFileDescr) -{ - m_dmFileDescr = dmFileDescr; -} - -QString AttachmentData::dmUpFileGuid(void) const -{ - return m_dmUpFileGuid; -} - -void AttachmentData::setDmUpFileGuid(const QString &dmUpFileGuid) -{ - m_dmUpFileGuid = dmUpFileGuid; -} - -QString AttachmentData::dmFileGuid(void) const -{ - return m_dmFileGuid; -} - -void AttachmentData::setDmFileGuid(const QString &dmFileGuid) -{ - m_dmFileGuid = dmFileGuid; -} - -QString AttachmentData::dmMimeType(void) const -{ - return m_dmMimeType; -} - -void AttachmentData::setDmMimeType(const QString &dmMimeType) -{ - m_dmMimeType = dmMimeType; -} - - -QString AttachmentData::dmFormat(void) const -{ - return m_dmFormat; -} - -void AttachmentData::setDmFormat(const QString &dmFormat) -{ - m_dmFormat = dmFormat; -} - -QString AttachmentData::dmFileMetaType(void) const -{ - return m_dmFileMetaType; -} - -void AttachmentData::setDmFileMetaType(const QString &dmFileMetaType) -{ - m_dmFileMetaType = dmFileMetaType; -} - -QString AttachmentData::dmEncodedContent(void) const -{ - return m_dmEncodedContent; -} - -void AttachmentData::setDmEncodedContent(const QString &dmEncodedContent) -{ - m_dmEncodedContent = dmEncodedContent; -} - -QString AttachmentData::_dmFileSize(void) const -{ - return m_dmFileSize; -} - -void AttachmentData::_setDmFileSize(const QString &_dmFileSize) -{ - m_dmFileSize = _dmFileSize; -} - -QString AttachmentData::_dmDownloadDate(void) const -{ - return m_dmDownloadDate; -} - -void AttachmentData::_setDmDownloadDate(const QString &_dmDownloadDate) -{ - m_dmDownloadDate = _dmDownloadDate; -} - -QString AttachmentData::_icon(void) const -{ - return m_icon; -} - -void AttachmentData::_setIcon(const QString &_icon) -{ - m_icon = _icon; -} - -AttachmentData *AttachmentData::fromVariant(const QVariant &attachDataVariant) -{ - if (!attachDataVariant.canConvert()) { - return Q_NULLPTR; - } - QObject *obj = qvariant_cast(attachDataVariant); - return qobject_cast(obj); -} diff --git a/src/qml_interaction/attachment_data.h b/src/qml_interaction/attachment_data.h deleted file mode 100644 index c353d7d4b0c69a8882fb59bce72213c55c70e279..0000000000000000000000000000000000000000 --- a/src/qml_interaction/attachment_data.h +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (C) 2014-2017 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 . - * - * 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. - */ - -#ifndef _ATTACHMENT_DATA_H_ -#define _ATTACHMENT_DATA_H_ - -#include -#include - -/*! - * @brief Class holds attachment data. - */ -class AttachmentData : public QObject { - Q_OBJECT - Q_PROPERTY(int fileId READ fileId WRITE setFileId) - Q_PROPERTY(qint64 dmId READ dmId WRITE setDmId) - Q_PROPERTY(QString dmFileDescr READ dmFileDescr WRITE setDmFileDescr) - Q_PROPERTY(QString dmUpFileGuid READ dmUpFileGuid WRITE setDmUpFileGuid) - Q_PROPERTY(QString dmFileGuid READ dmFileGuid WRITE setDmFileGuid) - Q_PROPERTY(QString dmMimeType READ dmMimeType WRITE setDmMimeType) - Q_PROPERTY(QString dmFormat READ dmFormat WRITE setDmFormat) - Q_PROPERTY(QString dmFileMetaType READ dmFileMetaType WRITE setDmFileMetaType) - Q_PROPERTY(QString dmEncodedContent READ dmEncodedContent WRITE setDmEncodedContent) - - Q_PROPERTY(QString _dmFileSize READ _dmFileSize WRITE _setDmFileSize) - Q_PROPERTY(QString _dmDownloadDate READ _dmDownloadDate WRITE _setDmDownloadDate) - Q_PROPERTY(QString _icon READ _icon WRITE _setIcon) - -public: - - /* Don't forget to declare various properties to the QML system. */ - static - void declareQML(void); - - /*! - * @brief Constructor. - * - * @param[in] parent Parent object. - */ - explicit AttachmentData(QObject *parent = Q_NULLPTR); - - /*! - * @brief Copy constructor. - * - * @note Needed for QVariant conversion. - * - * @param[in] info Attachment data to be copied. - */ - AttachmentData(const AttachmentData &data); - - AttachmentData(int fileId, qint64 dmId, const QString &dmFileDescr, - const QString &dmUpFileGuid, const QString &dmFileGuid, - const QString &dmMimeType, const QString &dmFormat, - const QString &dmFileMetaType, const QString &dmEncodedContent, - const QString &_dmFileSize, const QString &_dmDownloadDate, - const QString &_icon, QObject *parent = Q_NULLPTR); - - /*! - * @brief Assignment operator. - * - * @note gcc 5.4 bitches about missing operator= declaration. - * - * @param[in] data Attachment data. - * @return Reference to itself. - */ - AttachmentData &operator=(const AttachmentData &data); - - int fileId(void) const; - void setFileId(int fileId); - qint64 dmId(void) const; - void setDmId(qint64 dmId); - QString dmFileDescr(void) const; - void setDmFileDescr(const QString &dmFileDescr); - QString dmUpFileGuid(void) const; - void setDmUpFileGuid(const QString &dmUpFileGuid); - QString dmFileGuid(void) const; - void setDmFileGuid(const QString &dmFileGuid); - QString dmMimeType(void) const; - void setDmMimeType(const QString &dmMimeType); - QString dmFormat(void) const; - void setDmFormat(const QString &dmFormat); - QString dmFileMetaType(void) const; - void setDmFileMetaType(const QString &dmFileMetaType); - QString dmEncodedContent(void) const; - void setDmEncodedContent(const QString &dmEncodedContent); - - QString _dmFileSize(void) const; - void _setDmFileSize(const QString &_dmFileSize); - QString _dmDownloadDate(void) const; - void _setDmDownloadDate(const QString &_dmDownloadDate); - QString _icon(void) const; - void _setIcon(const QString &_icon); - - /*! - * @brief Converts QVariant obtained from QML into data pointer. - * - * @note Some weird stuff happens in QML when passing attachment data - * directly as constant reference. Wrong constructors are called - * and no data are passed. That's because we are using a QVariant. - * This function does not allocate a new data. - * - * @param[in] attachDataVariant QVariant holding the attachment data. - * @return Pointer to data if it could be acquired, Q_NULLPTR else. - */ - static - AttachmentData *fromVariant(const QVariant &attachDataVariant); - -private: - - int m_fileId; /*!< File identifier. */ - qint64 m_dmId; /*!< Message identifier. */ - QString m_dmFileDescr; /*!< File name. */ - QString m_dmUpFileGuid; /*!< ISDS guid. */ - QString m_dmFileGuid; /*!< File guid. */ - QString m_dmMimeType; /*!< File mime type. */ - QString m_dmFormat; /*!< File format. */ - QString m_dmFileMetaType; /*!< File meta mime type. */ - QString m_dmEncodedContent; /*!< Base64 file content. */ - - QString m_dmFileSize; /*!< File size string in kB. */ - QString m_dmDownloadDate; /*!< File download date. */ - QString m_icon; /*!< File icon resource. */ -}; - -/* QML passes its arguments via QVariant. */ -Q_DECLARE_METATYPE(AttachmentData) - -#endif /* _ATTACHMENT_DATA_H_ */ diff --git a/src/qml_interaction/message_envelope.cpp b/src/qml_interaction/message_envelope.cpp index eceff0d5bed0a64251004fa77af90b4db4c37f99..c9b9d190d6877ef8a0dd395859e2bd5d756b875d 100644 --- a/src/qml_interaction/message_envelope.cpp +++ b/src/qml_interaction/message_envelope.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014-2017 CZ.NIC + * 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 @@ -48,7 +48,7 @@ MsgEnvelope::MsgEnvelope(QObject *parent) m_dmRecipientAddress(), m_dmRecipientOrgUnit(), m_dmRecipientOrgUnitNum(), - m_dmAmbiguousRecipient(), + m_dmAmbiguousRecipient(false), m_dmRecipientRefNumber(), m_dmRecipientIdent(), m_dmLegalTitleLaw(), @@ -64,12 +64,7 @@ MsgEnvelope::MsgEnvelope(QObject *parent) m_dmAcceptanceTime(), m_dmMessageStatus(0), m_dmAttachmentSize(0), - m_dmType(), - m_dmMessageType(0), - m_dmDownloadDate(), - m_dmCustomData(), - m_dmAttachDownloaded(false), - m_dmReadLocally(false) + m_dmType() { } @@ -106,12 +101,7 @@ MsgEnvelope::MsgEnvelope(const MsgEnvelope &data) m_dmAcceptanceTime(data.m_dmAcceptanceTime), m_dmMessageStatus(data.m_dmMessageStatus), m_dmAttachmentSize(data.m_dmAttachmentSize), - m_dmType(data.m_dmType), - m_dmMessageType(data.m_dmMessageType), - m_dmDownloadDate(data.m_dmDownloadDate), - m_dmCustomData(data.m_dmCustomData), - m_dmAttachDownloaded(data.m_dmAttachDownloaded), - m_dmReadLocally(data.m_dmReadLocally) + m_dmType(data.m_dmType) { } @@ -122,7 +112,7 @@ MsgEnvelope::MsgEnvelope(qint64 dmID, const QString &dmAnnotation, const QString &dmSenderRefNumber, const QString &dmSenderIdent, const QString &dbIDRecipient, const QString &dmRecipient, const QString &dmRecipientAddress, const QString &dmRecipientOrgUnit, - const QString &dmRecipientOrgUnitNum, const QString &dmAmbiguousRecipient, + const QString &dmRecipientOrgUnitNum, bool dmAmbiguousRecipient, const QString &dmRecipientRefNumber, const QString &dmRecipientIdent, const QString &dmLegalTitleLaw, const QString &dmLegalTitleYear, const QString &dmLegalTitleSect, const QString &dmLegalTitlePar, @@ -130,8 +120,7 @@ MsgEnvelope::MsgEnvelope(qint64 dmID, const QString &dmAnnotation, bool dmPersonalDelivery, bool dmAllowSubstDelivery, const QString &dmQTimestamp, const QString &dmDeliveryTime, const QString &dmAcceptanceTime, int dmMessageStatus, int dmAttachmentSize, - const QString &dmType, int _dmMessageType, const QString &_dmDownloadDate, - const QString &_dmCustomData, bool _dmAttachDownloaded, bool _dmReadLocally, + const QString &dmType, QObject *parent) : QObject(parent), m_dmID(dmID), @@ -165,12 +154,7 @@ MsgEnvelope::MsgEnvelope(qint64 dmID, const QString &dmAnnotation, m_dmAcceptanceTime(dmAcceptanceTime), m_dmMessageStatus(dmMessageStatus), m_dmAttachmentSize(dmAttachmentSize), - m_dmType(dmType), - m_dmMessageType(_dmMessageType), - m_dmDownloadDate(_dmDownloadDate), - m_dmCustomData(_dmCustomData), - m_dmAttachDownloaded(_dmAttachDownloaded), - m_dmReadLocally(_dmReadLocally) + m_dmType(dmType) { } @@ -324,12 +308,12 @@ void MsgEnvelope::setDmRecipientOrgUnitNum(const QString &dmRecipientOrgUnitNum) m_dmRecipientOrgUnitNum = dmRecipientOrgUnitNum; } -QString MsgEnvelope::dmAmbiguousRecipient(void) const +bool MsgEnvelope::dmAmbiguousRecipient(void) const { return m_dmAmbiguousRecipient; } -void MsgEnvelope::setDmAmbiguousRecipient(const QString &dmAmbiguousRecipient) +void MsgEnvelope::setDmAmbiguousRecipient(bool dmAmbiguousRecipient) { m_dmAmbiguousRecipient = dmAmbiguousRecipient; } @@ -493,54 +477,6 @@ void MsgEnvelope::setDmType(const QString &dmType) m_dmType = dmType; } -int MsgEnvelope::_dmMessageType(void) const -{ - return m_dmMessageType; -} - -void MsgEnvelope::_setDmMessageType(int _dmMessageType) -{ - m_dmMessageType = _dmMessageType; -} - -QString MsgEnvelope::_dmDownloadDate(void) const -{ - return m_dmDownloadDate; -} - -void MsgEnvelope::_setDmDownloadDate(const QString &_dmDownloadDate) -{ - m_dmDownloadDate = _dmDownloadDate; -} - -QString MsgEnvelope::_dmCustomData(void) const -{ - return m_dmCustomData; -} -void MsgEnvelope::_setDmCustomData(const QString &_dmCustomData) -{ - m_dmCustomData = _dmCustomData; -} - -bool MsgEnvelope::_dmAttachDownloaded(void) const -{ - return m_dmAttachDownloaded; -} -void MsgEnvelope::_setDmAttachDownloaded(bool _dmAttachDownloaded) -{ - m_dmAttachDownloaded = _dmAttachDownloaded; -} - -bool MsgEnvelope::_dmReadLocally(void) const -{ - return m_dmReadLocally; -} - -void MsgEnvelope::_setDmReadLocally(bool _dmReadLocally) -{ - m_dmReadLocally = _dmReadLocally; -} - MsgEnvelope *MsgEnvelope::fromVariant(const QVariant &msgEnvelDataVariant) { if (!msgEnvelDataVariant.canConvert()) { diff --git a/src/qml_interaction/message_envelope.h b/src/qml_interaction/message_envelope.h index dd48b92bd3f8ba075123099ec28ef7173aa0ed42..d4165cfc7002252a383d6ea0295a8b97496b1663 100644 --- a/src/qml_interaction/message_envelope.h +++ b/src/qml_interaction/message_envelope.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014-2017 CZ.NIC + * 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 @@ -21,8 +21,7 @@ * the two. */ -#ifndef _MESSAGE_ENVELOPE_H_ -#define _MESSAGE_ENVELOPE_H_ +#pragma once #include #include @@ -50,7 +49,7 @@ class MsgEnvelope : public QObject { Q_PROPERTY(QString dmRecipientAddress READ dmRecipientAddress WRITE setDmRecipientAddress) Q_PROPERTY(QString dmRecipientOrgUnit READ dmRecipientOrgUnit WRITE setDmRecipientOrgUnit) Q_PROPERTY(QString dmRecipientOrgUnitNum READ dmRecipientOrgUnitNum WRITE setDmRecipientOrgUnitNum) - Q_PROPERTY(QString dmAmbiguousRecipient READ dmAmbiguousRecipient WRITE setDmAmbiguousRecipient) + Q_PROPERTY(bool dmAmbiguousRecipient READ dmAmbiguousRecipient WRITE setDmAmbiguousRecipient) Q_PROPERTY(QString dmRecipientRefNumber READ dmRecipientRefNumber WRITE setDmRecipientRefNumber) Q_PROPERTY(QString dmRecipientIdent READ dmRecipientIdent WRITE setDmRecipientIdent) @@ -70,12 +69,6 @@ class MsgEnvelope : public QObject { Q_PROPERTY(int dmAttachmentSize READ dmAttachmentSize WRITE setDmAttachmentSize) Q_PROPERTY(QString dmType READ dmType WRITE setDmType) - Q_PROPERTY(int _dmMessageType READ _dmMessageType WRITE _setDmMessageType) - Q_PROPERTY(QString _dmDownloadDate READ _dmDownloadDate WRITE _setDmDownloadDate) - Q_PROPERTY(QString _dmCustomData READ _dmCustomData WRITE _setDmCustomData) - Q_PROPERTY(bool _dmAttachDownloaded READ _dmAttachDownloaded WRITE _setDmAttachDownloaded) - Q_PROPERTY(bool _dmReadLocally READ _dmReadLocally WRITE _setDmReadLocally) - public: /* Don't forget to declare various properties to the QML system. */ @@ -116,7 +109,7 @@ public: const QString &dmRecipientAddress, const QString &dmRecipientOrgUnit, const QString &dmRecipientOrgUnitNum, - const QString &dmAmbiguousRecipient, + bool dmAmbiguousRecipient, const QString &dmRecipientRefNumber, const QString &dmRecipientIdent, @@ -136,11 +129,6 @@ public: int dmAttachmentSize, const QString &dmType, - int _dmMessageType, - const QString &_dmDownloadDate, - const QString &_dmCustomData, - bool _dmAttachDownloaded, - bool _dmReadLocally, QObject *parent = Q_NULLPTR); /*! @@ -185,8 +173,8 @@ public: void setDmRecipientOrgUnit(const QString &dmRecipientOrgUnit); QString dmRecipientOrgUnitNum(void) const; void setDmRecipientOrgUnitNum(const QString &dmRecipientOrgUnitNum); - QString dmAmbiguousRecipient(void) const; - void setDmAmbiguousRecipient(const QString &dmAmbiguousRecipient); + bool dmAmbiguousRecipient(void) const; + void setDmAmbiguousRecipient(bool dmAmbiguousRecipient); QString dmRecipientRefNumber(void) const; void setDmRecipientRefNumber(const QString &dmRecipientRefNumber); QString dmRecipientIdent(void) const; @@ -222,17 +210,6 @@ public: QString dmType(void) const; void setDmType(const QString &dmType); - int _dmMessageType(void) const; - void _setDmMessageType(int _dmMessageType); - QString _dmDownloadDate(void) const; - void _setDmDownloadDate(const QString &_dmDownloadDate); - QString _dmCustomData(void) const; - void _setDmCustomData(const QString &_dmCustomData); - bool _dmAttachDownloaded(void) const; - void _setDmAttachDownloaded(bool _dmAttachDownloaded); - bool _dmReadLocally(void) const; - void _setDmReadLocally(bool _dmReadLocally); - /*! * @brief Converts QVariant obtained from QML into data pointer. * @@ -266,7 +243,7 @@ private: QString m_dmRecipientAddress; QString m_dmRecipientOrgUnit; QString m_dmRecipientOrgUnitNum; - QString m_dmAmbiguousRecipient; + bool m_dmAmbiguousRecipient; QString m_dmRecipientRefNumber; QString m_dmRecipientIdent; @@ -285,15 +262,7 @@ private: int m_dmMessageStatus; int m_dmAttachmentSize; QString m_dmType; - - int m_dmMessageType; - QString m_dmDownloadDate; - QString m_dmCustomData; - bool m_dmAttachDownloaded; - bool m_dmReadLocally; }; /* QML passes its arguments via QVariant. */ Q_DECLARE_METATYPE(MsgEnvelope) - -#endif /* _MESSAGE_ENVELOPE_H_ */ diff --git a/src/sqlite/dbs.cpp b/src/sqlite/dbs.cpp index 4fd607b73d92e60c1e428abc7480204f8d099d79..6dea75b3d63383d6d15a917a6fdcb1d9d89be187 100644 --- a/src/sqlite/dbs.cpp +++ b/src/sqlite/dbs.cpp @@ -21,24 +21,12 @@ * the two. */ -#include -#include - #include "src/sqlite/dbs.h" -/*! - * @brief Date/time format stored in db. - * - * @note Old implementation of datovka is likely to contain a bug. - * Milliseconds are probably stored as microseconds. - */ -static const QString dbDateTimeFormat("yyyy-MM-dd HH:mm:ss.zzz"); -static const QString dbShortDateTimeFormat("yyyy-MM-dd HH:mm:ss"); - QDateTime dateTimeFromDbFormat(const QString &dateTimeDbStr) { QDateTime dateTime = QDateTime::fromString(dateTimeDbStr, - dbDateTimeFormat); + DATETIME_DB_FORMAT); dateTime.setTimeSpec(Qt::UTC); return dateTime.toLocalTime(); } @@ -47,7 +35,6 @@ QString dateTimeStrFromDbFormat(const QString &dateTimeDbStr, const QString &tgtFmt) { QDateTime dateTime = dateTimeFromDbFormat(dateTimeDbStr); - if (dateTime.isValid()) { return dateTime.toString(tgtFmt); } else { @@ -59,9 +46,28 @@ QString dateTimeStrToUTCDbFormat(const QString &dateTimeStr) { QDateTime dateTime = QDateTime::fromString(dateTimeStr, Qt::ISODate); dateTime = dateTime.toTimeSpec(Qt::UTC); + if (dateTime.isValid()) { + return dateTime.toString(DATETIME_DB_FORMAT); + } else { + return QString(); + } +} +QDateTime isoDateTimeStrToUtcDateTime(const QString &dateTimeStr) +{ + QDateTime dateTime = QDateTime::fromString(dateTimeStr, Qt::ISODate); + dateTime = dateTime.toTimeSpec(Qt::UTC); + if (dateTime.isValid()) { + return dateTime; + } else { + return QDateTime(); + } +} + +QString utcDateTimeToDbFormatStr(const QDateTime &dateTime) +{ if (dateTime.isValid()) { - return dateTime.toString(dbDateTimeFormat); + return dateTime.toString(DATETIME_DB_FORMAT); } else { return QString(); } diff --git a/src/sqlite/dbs.h b/src/sqlite/dbs.h index 13d8d8a6c3de97d437384adc836675e382344018..837ca3dc4669951ad8a7c8b758272f0a28b30a14 100644 --- a/src/sqlite/dbs.h +++ b/src/sqlite/dbs.h @@ -23,7 +23,6 @@ #pragma once -#include #include #include @@ -47,3 +46,13 @@ QString dateTimeStrFromDbFormat(const QString &dateTimeDbStr, * @brief Converts date and time to UTC for database store. */ QString dateTimeStrToUTCDbFormat(const QString &dateTimeStr); + +/*! + * @brief Converts ISDS ISO datetime string to UTC datetime. + */ +QDateTime isoDateTimeStrToUtcDateTime(const QString &dateTimeStr); + +/*! + * @brief Converts UTC datetime to database datetime string. + */ +QString utcDateTimeToDbFormatStr(const QDateTime &dateTime); diff --git a/src/sqlite/file_db.cpp b/src/sqlite/file_db.cpp index 010dabb702be3e7599f39f38d68a0181871ddecf..0264cf30ae1ea241bdc7fcbed764916a1a076ff7 100644 --- a/src/sqlite/file_db.cpp +++ b/src/sqlite/file_db.cpp @@ -29,8 +29,11 @@ #include #include +#include "src/auxiliaries/attachment_helper.h" #include "src/common.h" +#include "src/datovka_shared/isds/type_conversion.h" #include "src/io/filesystem.h" +#include "src/isds/isds_type_conversion.h" #include "src/sqlite/file_db.h" #include "src/sqlite/db_tables.h" #include "src/sqlite/dbs.h" @@ -140,65 +143,78 @@ void FileDb::setFileModelFromDb(FileListModel &model, const qint64 dmId) const } } -FileDb::FileData FileDb::getFileFromDb(int fileId) const +Isds::Document FileDb::getFileFromDb(int fileId) const { QSqlQuery query(m_db); - FileDb::FileData filedata; + Isds::Document document; - QString queryStr = "SELECT dmFileDescr, dmEncodedContent " + QString queryStr = "SELECT dmFileDescr, dmUpFileGuid, dmFileGuid, " + "dmMimeType, dmFormat, dmFileMetaType, dmEncodedContent " "FROM files WHERE id = :id"; if (!query.prepare(queryStr)) { qCritical() << "Cannot prepare SQL query:" << query.lastError().text().toUtf8().constData(); - return FileDb::FileData(); + goto fail; } query.bindValue(":id", fileId); - if (query.exec() && query.isActive() && query.first() && query.isValid()) { - filedata.filename = query.value(0).toString(); - filedata.content = query.value(1).toString(); - return filedata; + document.setFileDescr(query.value(0).toString()); + document.setUpFileGuid(query.value(1).toString()); + document.setFileGuid(query.value(2).toString()); + document.setMimeType(query.value(3).toString()); + document.setFormat(query.value(4).toString()); + document.setFileMetaType( + Isds::m_variant2FileMetaType(query.value(5))); + document.setBase64Content(query.value(6).toString()); + return document; } else { qCritical() << "Cannot execute SQL query:" << query.lastError().text().toUtf8().constData(); } - return FileDb::FileData(); +fail: + return Isds::Document(); } -QList FileDb::getFilesFromDb(qint64 dmId) const +QList FileDb::getFilesFromDb(qint64 dmId) const { QSqlQuery query(m_db); - FileDb::FileData filedata; - QList filelist; + QList documents; - QString queryStr = "SELECT dmFileDescr, dmEncodedContent " + QString queryStr = "SELECT dmFileDescr, dmUpFileGuid, dmFileGuid, " + "dmMimeType, dmFormat, dmFileMetaType, dmEncodedContent " "FROM files WHERE dmID = :dmID"; if (!query.prepare(queryStr)) { qCritical() << "Cannot prepare SQL query:" << query.lastError().text().toUtf8().constData(); - return QList(); + goto fail; } query.bindValue(":dmID", dmId); - if (query.exec() && query.isActive()) { query.first(); while (query.isValid()) { - filedata.filename = query.value(0).toString(); - filedata.content = query.value(1).toString(); - filelist.append(filedata); + Isds::Document document; + document.setFileDescr(query.value(0).toString()); + document.setUpFileGuid(query.value(1).toString()); + document.setFileGuid(query.value(2).toString()); + document.setMimeType(query.value(3).toString()); + document.setFormat(query.value(4).toString()); + document.setFileMetaType( + Isds::m_variant2FileMetaType(query.value(5))); + document.setBase64Content(query.value(6).toString()); + documents.append(document); query.next(); } + return documents; } else { qCritical() << "Cannot execute SQL query:" << query.lastError().text().toUtf8().constData(); - return QList(); } - - return filelist; +fail: + return QList(); } -bool FileDb::insertUpdateFileIntoDb(const AttachmentData &fileData) +bool FileDb::insertUpdateFileIntoDb(qint64 dmId, const Isds::Document &document) { QSqlQuery query(m_db); int id = -1; @@ -210,8 +226,8 @@ bool FileDb::insertUpdateFileIntoDb(const AttachmentData &fileData) query.lastError().text().toUtf8().constData(); goto fail; } - query.bindValue(":dmID", fileData.dmId()); - query.bindValue(":dmFileDescr", fileData.dmFileDescr()); + query.bindValue(":dmID", dmId); + query.bindValue(":dmFileDescr", document.fileDescr()); if (query.exec() && query.isActive()) { query.first(); if (query.isValid()) { @@ -248,17 +264,21 @@ bool FileDb::insertUpdateFileIntoDb(const AttachmentData &fileData) goto fail; } - query.bindValue(":dmID", fileData.dmId()); - query.bindValue(":dmFileDescr", fileData.dmFileDescr()); - query.bindValue(":dmUpFileGuid", fileData.dmUpFileGuid()); - query.bindValue(":dmFileGuid", fileData.dmFileGuid()); - query.bindValue(":dmMimeType", fileData.dmMimeType()); - query.bindValue(":dmFormat", fileData.dmFormat()); - query.bindValue(":dmFileMetaType", fileData.dmFileMetaType()); - query.bindValue(":dmEncodedContent", fileData.dmEncodedContent()); - query.bindValue(":_dmFileSize", fileData._dmFileSize()); - query.bindValue(":_dmDownloadDate", QDate::currentDate().toString(DATE_DB_FORMAT)); - query.bindValue(":_icon", fileData._icon()); + query.bindValue(":dmID", dmId); + query.bindValue(":dmFileDescr", document.fileDescr()); + query.bindValue(":dmUpFileGuid", document.upFileGuid()); + query.bindValue(":dmFileGuid", document.fileGuid()); + query.bindValue(":dmMimeType", document.mimeType()); + query.bindValue(":dmFormat", document.format()); + query.bindValue(":dmFileMetaType", + Isds::m_fileMetaType2Variant(document.fileMetaType())); + query.bindValue(":dmEncodedContent", document.base64Content()); + query.bindValue(":_dmFileSize", + approximateDataSize(document.binaryContent().size())); + query.bindValue(":_dmDownloadDate", + QDate::currentDate().toString(DATE_DB_FORMAT)); + query.bindValue(":_icon", + getAttachmentFileIconFromFileExtension(document.fileDescr())); if (-1 != id) { query.bindValue(":id", id); } diff --git a/src/sqlite/file_db.h b/src/sqlite/file_db.h index 95ea5946bd52745325525017eee77c902bd5cd70..f339ccb195b8b2ab53aca56d0921477f5e27f490 100644 --- a/src/sqlite/file_db.h +++ b/src/sqlite/file_db.h @@ -27,10 +27,10 @@ #include #include "src/datovka_shared/io/sqlite/db.h" +#include "src/datovka_shared/isds/message_interface.h" #include "src/files.h" #include "src/messages.h" #include "src/models/filemodel.h" -#include "src/qml_interaction/attachment_data.h" /*! * @brief Encapsulates message database. @@ -39,14 +39,6 @@ class FileDb : public SQLiteDb { public: - /*! - * @brief Structure holds file name and its content. - */ - struct FileData { - public: QString filename; - QString content; - }; - explicit FileDb(const QString &connectionName); /*! @@ -94,17 +86,17 @@ public: * @brief Get file content from db. * * @param[in] fileId File Id. - * @return File name and content. + * @return File data. */ - FileDb::FileData getFileFromDb(int fileId) const; + Isds::Document getFileFromDb(int fileId) const; /*! * @brief Get list of files from db. * * @param[in] dmId Message Id. - * @return List of files (name and content). + * @return List of files. */ - QList getFilesFromDb(qint64 dmId) const; + QList getFilesFromDb(qint64 dmId) const; /*! * @brief Set attachment model from db - for QML listview. @@ -117,10 +109,11 @@ public: /*! * @brief Insert or update file data into files table. * - * @param[in] fileData Struct holds file data (name and content). + * @param[in] dmId Message Id. + * @param[in] document Struct holds file data. * @return True on success. */ - bool insertUpdateFileIntoDb(const AttachmentData &fileData); + bool insertUpdateFileIntoDb(qint64 dmId, const Isds::Document &document); /*! * @brief Open database file. diff --git a/src/sqlite/message_db.cpp b/src/sqlite/message_db.cpp index 20ae42e78656d714b0ed2e574f4e601c5d77475d..a2219ceeaa44f6b549adf00bff0af66af26acb37 100644 --- a/src/sqlite/message_db.cpp +++ b/src/sqlite/message_db.cpp @@ -33,6 +33,7 @@ #include "src/auxiliaries/email_helper.h" #include "src/common.h" #include "src/datovka_shared/io/records_management_db.h" +#include "src/datovka_shared/isds/type_conversion.h" #include "src/global.h" #include "src/io/filesystem.h" #include "src/isds/isds_conversion.h" @@ -278,11 +279,11 @@ int MessageDb::getMessageCountFromDb(enum MessageType messageType) return 0; } -MsgEnvelope MessageDb::getMessageEnvelopeFromDb(qint64 dmId) +Isds::Envelope MessageDb::getMessageEnvelopeFromDb(qint64 dmId) { QSqlQuery query(m_db); QString queryStr; - MsgEnvelope msgEnvel; + Isds::Envelope envelope; queryStr = "SELECT dmAnnotation, " "dbIDSender, dmSender, dmSenderAddress, dmSenderType, " @@ -293,58 +294,61 @@ MsgEnvelope MessageDb::getMessageEnvelopeFromDb(qint64 dmId) "dmLegalTitleYear, dmLegalTitleSect, dmLegalTitlePar, " "dmLegalTitlePoint, dmToHands, dmPersonalDelivery, " "dmAllowSubstDelivery, dmQTimestamp, dmDeliveryTime, " - "dmAcceptanceTime, dmMessageStatus, dmAttachmentSize, dmType, " - "_dmMessageType, _dmDownloadDate, _dmCustomData, " - "_dmAttachDownloaded, _dmReadLocally " + "dmAcceptanceTime, dmMessageStatus, dmAttachmentSize, dmType " "FROM messages WHERE dmID = :dmID"; if (!query.prepare(queryStr)) { - return msgEnvel; + return Isds::Envelope(); } query.bindValue(":dmID", dmId); if (query.exec() && query.isActive() && query.first() && query.isValid()) { - msgEnvel.setDmID(dmId); - msgEnvel.setDmAnnotation(query.value(0).toString()); - msgEnvel.setDbIDSender(query.value(1).toString()); - msgEnvel.setDmSender(query.value(2).toString()); - msgEnvel.setDmSenderAddress(query.value(3).toString()); - msgEnvel.setDmSenderType(query.value(4).toInt()); - msgEnvel.setDmSenderOrgUnit(query.value(5).toString()); - msgEnvel.setDmSenderOrgUnitNum(query.value(6).toString()); - msgEnvel.setDmSenderRefNumber(query.value(7).toString()); - msgEnvel.setDmSenderIdent(query.value(8).toString()); - msgEnvel.setDbIDRecipient(query.value(9).toString()); - msgEnvel.setDmRecipient(query.value(10).toString()); - msgEnvel.setDmRecipientAddress(query.value(11).toString()); - msgEnvel.setDmRecipientOrgUnit(query.value(12).toString()); - msgEnvel.setDmRecipientOrgUnitNum(query.value(13).toString()); - msgEnvel.setDmAmbiguousRecipient(query.value(14).toString()); - msgEnvel.setDmRecipientRefNumber(query.value(15).toString()); - msgEnvel.setDmRecipientIdent(query.value(16).toString()); - msgEnvel.setDmLegalTitleLaw(query.value(17).toString()); - msgEnvel.setDmLegalTitleYear(query.value(18).toString()); - msgEnvel.setDmLegalTitleSect(query.value(19).toString()); - msgEnvel.setDmLegalTitlePar(query.value(20).toString()); - msgEnvel.setDmLegalTitlePoint(query.value(21).toString()); - msgEnvel.setDmToHands(query.value(22).toString()); - msgEnvel.setDmPersonalDelivery(query.value(23).toBool()); - msgEnvel.setDmAllowSubstDelivery(query.value(24).toBool()); - msgEnvel.setDmQTimestamp(query.value(25).toString()); - msgEnvel.setDmDeliveryTime(query.value(26).toString()); - msgEnvel.setDmAcceptanceTime(query.value(27).toString()); - msgEnvel.setDmMessageStatus(query.value(28).toInt()); - msgEnvel.setDmAttachmentSize(query.value(29).toInt()); - msgEnvel.setDmType(query.value(30).toString()); - msgEnvel._setDmMessageType(query.value(31).toInt()); - msgEnvel._setDmDownloadDate(query.value(32).toString()); - msgEnvel._setDmCustomData(query.value(33).toString()); - msgEnvel._setDmAttachDownloaded(query.value(34).toBool()); - msgEnvel._setDmReadLocally(query.value(35).toBool()); - } - - return msgEnvel; + envelope.setDmId(dmId); + envelope.setDmID(QString::number(dmId)); + envelope.setDmAnnotation(query.value(0).toString()); + envelope.setDbIDSender(query.value(1).toString()); + envelope.setDmSender(query.value(2).toString()); + envelope.setDmSenderAddress(query.value(3).toString()); + envelope.setDmSenderType( + Isds::intVariant2DbType(query.value(4))); + envelope.setDmSenderOrgUnit(query.value(5).toString()); + envelope.setDmSenderOrgUnitNumStr(query.value(6).toString()); + envelope.setDmSenderRefNumber(query.value(7).toString()); + envelope.setDmSenderIdent(query.value(8).toString()); + envelope.setDbIDRecipient(query.value(9).toString()); + envelope.setDmRecipient(query.value(10).toString()); + envelope.setDmRecipientAddress(query.value(11).toString()); + envelope.setDmRecipientOrgUnit(query.value(12).toString()); + envelope.setDmRecipientOrgUnitNumStr( + query.value(13).toString()); + envelope.setDmAmbiguousRecipient( + Isds::variant2NilBool(query.value(14))); + envelope.setDmRecipientRefNumber(query.value(15).toString()); + envelope.setDmRecipientIdent(query.value(16).toString()); + envelope.setDmLegalTitleLawStr(query.value(17).toString()); + envelope.setDmLegalTitleYearStr(query.value(18).toString()); + envelope.setDmLegalTitleSect(query.value(19).toString()); + envelope.setDmLegalTitlePar(query.value(20).toString()); + envelope.setDmLegalTitlePoint(query.value(21).toString()); + envelope.setDmToHands(query.value(22).toString()); + envelope.setDmPersonalDelivery( + Isds::variant2NilBool(query.value(23))); + envelope.setDmAllowSubstDelivery( + Isds::variant2NilBool(query.value(24))); + envelope.setDmQTimestamp(query.value(25).toByteArray()); + envelope.setDmDeliveryTime( + dateTimeFromDbFormat(query.value(26).toString())); + envelope.setDmAcceptanceTime( + dateTimeFromDbFormat(query.value(27).toString())); + envelope.setDmMessageStatus( + Isds::variant2DmState(query.value(28))); + envelope.setDmAttachmentSize(query.value(29).toLongLong()); + envelope.setDmType((!query.value(30).isNull()) ? + query.value(30).toChar() : QChar()); + } + + return envelope; } bool MessageDb::getMessageEmailDataFromDb(qint64 dmId, QString &body, @@ -533,7 +537,7 @@ fail: return QString(); } -bool MessageDb::insertEventsIntoDb(qint64 msgId, const Messages::Event &event) +bool MessageDb::insertEventsIntoDb(qint64 msgId, const Isds::Event &event) { QSqlQuery query(m_db); int id = -1; @@ -546,8 +550,8 @@ bool MessageDb::insertEventsIntoDb(qint64 msgId, const Messages::Event &event) goto fail; } query.bindValue(":dmID", msgId); - query.bindValue(":dmEventTime", dateTimeStrToUTCDbFormat( - event.dmEventTime)); + query.bindValue(":dmEventTime", utcDateTimeToDbFormatStr( + event.time())); if (query.exec() && query.isActive()) { query.first(); if (query.isValid()) { @@ -574,9 +578,9 @@ bool MessageDb::insertEventsIntoDb(qint64 msgId, const Messages::Event &event) goto fail; } query.bindValue(":dmID", msgId); - query.bindValue(":dmEventTime", dateTimeStrToUTCDbFormat( - event.dmEventTime)); - query.bindValue(":dmEventDescr", event.dmEventDescr); + query.bindValue(":dmEventTime", utcDateTimeToDbFormatStr( + event.time())); + query.bindValue(":dmEventDescr", event.descr()); if (-1 != id) { query.bindValue(":id", id); } @@ -591,8 +595,8 @@ fail: return false; } -bool MessageDb::insertOrUpdateMessageEnvelopeInDb( - const MsgEnvelope &msgEnvelopeData) +bool MessageDb::insertOrUpdateMessageEnvelopeInDb(qint64 msgId, + enum MessageType messageType, const Isds::Envelope &envelope) { QSqlQuery query(m_db); qint64 dmID = -1; @@ -603,7 +607,7 @@ bool MessageDb::insertOrUpdateMessageEnvelopeInDb( query.lastError().text().toUtf8().constData(); goto fail; } - query.bindValue(":dmID", msgEnvelopeData.dmID()); + query.bindValue(":dmID", msgId); if (query.exec() && query.isActive()) { query.first(); if (query.isValid()) { @@ -617,7 +621,7 @@ bool MessageDb::insertOrUpdateMessageEnvelopeInDb( // update message envelope if (-1 != dmID) { - return updateMessageEnvelopeInDb(msgEnvelopeData); + return updateMessageEnvelopeInDb(envelope); } queryStr = "INSERT INTO messages (" @@ -652,43 +656,43 @@ bool MessageDb::insertOrUpdateMessageEnvelopeInDb( query.lastError().text().toUtf8().constData(); goto fail; } - query.bindValue(":dmID", msgEnvelopeData.dmID()); - query.bindValue(":dbIDSender", msgEnvelopeData.dbIDSender()); - query.bindValue(":dmSender", msgEnvelopeData.dmSender()); - query.bindValue(":dmSenderAddress", msgEnvelopeData.dmSenderAddress()); - query.bindValue(":dmSenderType", msgEnvelopeData.dmSenderType()); - query.bindValue(":dmRecipient", msgEnvelopeData.dmRecipient()); - query.bindValue(":dmRecipientAddress", msgEnvelopeData.dmRecipientAddress()); - query.bindValue(":dmAmbiguousRecipient", msgEnvelopeData.dmAmbiguousRecipient()); - query.bindValue(":dmSenderOrgUnit", msgEnvelopeData.dmSenderOrgUnit()); - query.bindValue(":dmSenderOrgUnitNum", msgEnvelopeData.dmSenderOrgUnitNum()); - query.bindValue(":dbIDRecipient", msgEnvelopeData.dbIDRecipient()); - query.bindValue(":dmRecipientOrgUnit", msgEnvelopeData.dmRecipientOrgUnit()); - query.bindValue(":dmRecipientOrgUnitNum", msgEnvelopeData.dmRecipientOrgUnitNum()); - query.bindValue(":dmToHands", msgEnvelopeData.dmToHands()); - query.bindValue(":dmAnnotation", msgEnvelopeData.dmAnnotation()); - query.bindValue(":dmRecipientRefNumber", msgEnvelopeData.dmRecipientRefNumber()); - query.bindValue(":dmSenderRefNumber", msgEnvelopeData.dmSenderRefNumber()); - query.bindValue(":dmRecipientIdent", msgEnvelopeData.dmRecipientIdent()); - query.bindValue(":dmSenderIdent", msgEnvelopeData.dmSenderIdent()); - query.bindValue(":dmLegalTitleLaw", msgEnvelopeData.dmLegalTitleLaw()); - query.bindValue(":dmLegalTitleYear", msgEnvelopeData.dmLegalTitleYear()); - query.bindValue(":dmLegalTitleSect", msgEnvelopeData.dmLegalTitleSect()); - query.bindValue(":dmLegalTitlePar", msgEnvelopeData.dmLegalTitlePar()); - query.bindValue(":dmLegalTitlePoint", msgEnvelopeData.dmLegalTitlePoint()); - query.bindValue(":dmPersonalDelivery", msgEnvelopeData.dmPersonalDelivery()); - query.bindValue(":dmAllowSubstDelivery", msgEnvelopeData.dmAllowSubstDelivery()); - query.bindValue(":dmQTimestamp", msgEnvelopeData.dmQTimestamp()); - query.bindValue(":dmDeliveryTime", dateTimeStrToUTCDbFormat(msgEnvelopeData.dmDeliveryTime())); - query.bindValue(":dmAcceptanceTime", dateTimeStrToUTCDbFormat(msgEnvelopeData.dmAcceptanceTime())); - query.bindValue(":dmMessageStatus", msgEnvelopeData.dmMessageStatus()); - query.bindValue(":dmAttachmentSize", msgEnvelopeData.dmAttachmentSize()); - query.bindValue(":dmType", msgEnvelopeData.dmType()); - query.bindValue(":_dmMessageType", msgEnvelopeData._dmMessageType()); + query.bindValue(":dmID", msgId); + query.bindValue(":dbIDSender", envelope.dbIDSender()); + query.bindValue(":dmSender", envelope.dmSender()); + query.bindValue(":dmSenderAddress", envelope.dmSenderAddress()); + query.bindValue(":dmSenderType", Isds::dbType2IntVariant(envelope.dmSenderType())); + query.bindValue(":dmRecipient", envelope.dmRecipient()); + query.bindValue(":dmRecipientAddress", envelope.dmRecipientAddress()); + query.bindValue(":dmAmbiguousRecipient", Isds::nilBool2Variant(envelope.dmAmbiguousRecipient())); + query.bindValue(":dmSenderOrgUnit", envelope.dmSenderOrgUnit()); + query.bindValue(":dmSenderOrgUnitNum", envelope.dmSenderOrgUnitNumStr()); + query.bindValue(":dbIDRecipient", envelope.dbIDRecipient()); + query.bindValue(":dmRecipientOrgUnit", envelope.dmRecipientOrgUnit()); + query.bindValue(":dmRecipientOrgUnitNum", envelope.dmRecipientOrgUnitNumStr()); + query.bindValue(":dmToHands", envelope.dmToHands()); + query.bindValue(":dmAnnotation", envelope.dmAnnotation()); + query.bindValue(":dmRecipientRefNumber", envelope.dmRecipientRefNumber()); + query.bindValue(":dmSenderRefNumber", envelope.dmSenderRefNumber()); + query.bindValue(":dmRecipientIdent", envelope.dmRecipientIdent()); + query.bindValue(":dmSenderIdent", envelope.dmSenderIdent()); + query.bindValue(":dmLegalTitleLaw", envelope.dmLegalTitleLawStr()); + query.bindValue(":dmLegalTitleYear", envelope.dmLegalTitleYearStr()); + query.bindValue(":dmLegalTitleSect", envelope.dmLegalTitleSect()); + query.bindValue(":dmLegalTitlePar", envelope.dmLegalTitlePar()); + query.bindValue(":dmLegalTitlePoint", envelope.dmLegalTitlePoint()); + query.bindValue(":dmPersonalDelivery", envelope.dmPersonalDelivery()); + query.bindValue(":dmAllowSubstDelivery", envelope.dmAllowSubstDelivery()); + query.bindValue(":dmQTimestamp", envelope.dmQTimestamp()); + query.bindValue(":dmDeliveryTime", utcDateTimeToDbFormatStr(envelope.dmDeliveryTime())); + query.bindValue(":dmAcceptanceTime", utcDateTimeToDbFormatStr(envelope.dmAcceptanceTime())); + query.bindValue(":dmMessageStatus", Isds::dmState2Variant(envelope.dmMessageStatus())); + query.bindValue(":dmAttachmentSize", Isds::nonNegativeLong2Variant(envelope.dmAttachmentSize())); + query.bindValue(":dmType", (!envelope.dmType().isNull()) ? envelope.dmType() : QVariant()); + query.bindValue(":_dmMessageType", messageType); query.bindValue(":_dmDownloadDate", QDateTime::currentDateTime().toString(DATETIME_DB_FORMAT)); - query.bindValue(":_dmCustomData", msgEnvelopeData._dmCustomData()); - query.bindValue(":_dmAttachDownloaded", msgEnvelopeData._dmAttachDownloaded()); - query.bindValue(":_dmReadLocally", msgEnvelopeData._dmReadLocally()); + query.bindValue(":_dmCustomData", QString()); + query.bindValue(":_dmAttachDownloaded", false); + query.bindValue(":_dmReadLocally", false); if (!query.exec()) { qCritical() << "Cannot execute SQL query:" << @@ -867,8 +871,7 @@ bool MessageDb::updateMessageAuthorInfoInDb(qint64 msgId, const QString &data) return true; } -bool MessageDb::updateMessageEnvelopeInDb( - const MsgEnvelope &msgEnvelopeData) +bool MessageDb::updateMessageEnvelopeInDb(const Isds::Envelope &envelope) { QSqlQuery query(m_db); @@ -908,38 +911,38 @@ bool MessageDb::updateMessageEnvelopeInDb( query.lastError().text().toUtf8().constData(); goto fail; } - query.bindValue(":dmID", msgEnvelopeData.dmID()); - query.bindValue(":dbIDSender", msgEnvelopeData.dbIDSender()); - query.bindValue(":dmSender", msgEnvelopeData.dmSender()); - query.bindValue(":dmSenderAddress", msgEnvelopeData.dmSenderAddress()); - query.bindValue(":dmSenderType", msgEnvelopeData.dmSenderType()); - query.bindValue(":dmRecipient", msgEnvelopeData.dmRecipient()); - query.bindValue(":dmRecipientAddress", msgEnvelopeData.dmRecipientAddress()); - query.bindValue(":dmAmbiguousRecipient", msgEnvelopeData.dmAmbiguousRecipient()); - query.bindValue(":dmSenderOrgUnit", msgEnvelopeData.dmSenderOrgUnit()); - query.bindValue(":dmSenderOrgUnitNum", msgEnvelopeData.dmSenderOrgUnitNum()); - query.bindValue(":dbIDRecipient", msgEnvelopeData.dbIDRecipient()); - query.bindValue(":dmRecipientOrgUnit", msgEnvelopeData.dmRecipientOrgUnit()); - query.bindValue(":dmRecipientOrgUnitNum", msgEnvelopeData.dmRecipientOrgUnitNum()); - query.bindValue(":dmToHands", msgEnvelopeData.dmToHands()); - query.bindValue(":dmAnnotation", msgEnvelopeData.dmAnnotation()); - query.bindValue(":dmRecipientRefNumber", msgEnvelopeData.dmRecipientRefNumber()); - query.bindValue(":dmSenderRefNumber", msgEnvelopeData.dmSenderRefNumber()); - query.bindValue(":dmRecipientIdent", msgEnvelopeData.dmRecipientIdent()); - query.bindValue(":dmSenderIdent", msgEnvelopeData.dmSenderIdent()); - query.bindValue(":dmLegalTitleLaw", msgEnvelopeData.dmLegalTitleLaw()); - query.bindValue(":dmLegalTitleYear", msgEnvelopeData.dmLegalTitleYear()); - query.bindValue(":dmLegalTitleSect", msgEnvelopeData.dmLegalTitleSect()); - query.bindValue(":dmLegalTitlePar", msgEnvelopeData.dmLegalTitlePar()); - query.bindValue(":dmLegalTitlePoint", msgEnvelopeData.dmLegalTitlePoint()); - query.bindValue(":dmPersonalDelivery", msgEnvelopeData.dmPersonalDelivery()); - query.bindValue(":dmAllowSubstDelivery", msgEnvelopeData.dmAllowSubstDelivery()); - query.bindValue(":dmQTimestamp", msgEnvelopeData.dmQTimestamp()); - query.bindValue(":dmDeliveryTime", dateTimeStrToUTCDbFormat(msgEnvelopeData.dmDeliveryTime())); - query.bindValue(":dmAcceptanceTime", dateTimeStrToUTCDbFormat(msgEnvelopeData.dmAcceptanceTime())); - query.bindValue(":dmMessageStatus", msgEnvelopeData.dmMessageStatus()); - query.bindValue(":dmAttachmentSize", msgEnvelopeData.dmAttachmentSize()); - query.bindValue(":dmType", msgEnvelopeData.dmType()); + query.bindValue(":dmID", envelope.dmId()); + query.bindValue(":dbIDSender", envelope.dbIDSender()); + query.bindValue(":dmSender", envelope.dmSender()); + query.bindValue(":dmSenderAddress", envelope.dmSenderAddress()); + query.bindValue(":dmSenderType", Isds::dbType2IntVariant(envelope.dmSenderType())); + query.bindValue(":dmRecipient", envelope.dmRecipient()); + query.bindValue(":dmRecipientAddress", envelope.dmRecipientAddress()); + query.bindValue(":dmAmbiguousRecipient", Isds::nilBool2Variant(envelope.dmAmbiguousRecipient())); + query.bindValue(":dmSenderOrgUnit", envelope.dmSenderOrgUnit()); + query.bindValue(":dmSenderOrgUnitNum", envelope.dmSenderOrgUnitNumStr()); + query.bindValue(":dbIDRecipient", envelope.dbIDRecipient()); + query.bindValue(":dmRecipientOrgUnit", envelope.dmRecipientOrgUnit()); + query.bindValue(":dmRecipientOrgUnitNum", envelope.dmRecipientOrgUnitNumStr()); + query.bindValue(":dmToHands", envelope.dmToHands()); + query.bindValue(":dmAnnotation", envelope.dmAnnotation()); + query.bindValue(":dmRecipientRefNumber", envelope.dmRecipientRefNumber()); + query.bindValue(":dmSenderRefNumber", envelope.dmSenderRefNumber()); + query.bindValue(":dmRecipientIdent", envelope.dmRecipientIdent()); + query.bindValue(":dmSenderIdent", envelope.dmSenderIdent()); + query.bindValue(":dmLegalTitleLaw", envelope.dmLegalTitleLawStr()); + query.bindValue(":dmLegalTitleYear", envelope.dmLegalTitleYearStr()); + query.bindValue(":dmLegalTitleSect", envelope.dmLegalTitleSect()); + query.bindValue(":dmLegalTitlePar", envelope.dmLegalTitlePar()); + query.bindValue(":dmLegalTitlePoint", envelope.dmLegalTitlePoint()); + query.bindValue(":dmPersonalDelivery", envelope.dmPersonalDelivery()); + query.bindValue(":dmAllowSubstDelivery", envelope.dmAllowSubstDelivery()); + query.bindValue(":dmQTimestamp", envelope.dmQTimestamp()); + query.bindValue(":dmDeliveryTime", utcDateTimeToDbFormatStr(envelope.dmDeliveryTime())); + query.bindValue(":dmAcceptanceTime", utcDateTimeToDbFormatStr(envelope.dmAcceptanceTime())); + query.bindValue(":dmMessageStatus", Isds::dmState2Variant(envelope.dmMessageStatus())); + query.bindValue(":dmAttachmentSize", Isds::nonNegativeLong2Variant(envelope.dmAttachmentSize())); + query.bindValue(":dmType", (!envelope.dmType().isNull()) ? envelope.dmType() : QVariant()); if (!query.exec()) { qCritical() << "Cannot execute SQL query:" << diff --git a/src/sqlite/message_db.h b/src/sqlite/message_db.h index dfa60477697949bfd8de2d2028fed0449bad8499..09bcb57128c16aaff34a52141eea2d32f501819c 100644 --- a/src/sqlite/message_db.h +++ b/src/sqlite/message_db.h @@ -27,6 +27,7 @@ #include #include "src/datovka_shared/io/sqlite/db.h" +#include "src/datovka_shared/isds/message_interface.h" #include "src/messages.h" #include "src/models/databoxmodel.h" #include "src/qml_interaction/message_envelope.h" @@ -130,7 +131,7 @@ public: * @param[in] dmId Message identifier. * @return Message envelope data structure. */ - MsgEnvelope getMessageEnvelopeFromDb(qint64 dmId); + Isds::Envelope getMessageEnvelopeFromDb(qint64 dmId); /*! * @brief Set message list model from db for QML. @@ -178,16 +179,18 @@ public: * @param[in] event Event structure. * @return True on success. */ - bool insertEventsIntoDb(qint64 msgId, const Messages::Event &event); + bool insertEventsIntoDb(qint64 msgId, const Isds::Event &event); /*! * @brief Insert or update message envelope into messages table. * - * @param[in] msgEnvelopeData Contains message envelope data. + * @param[in] msgId Message Id. + * @param[in] messageType Received or sent. + * @param[in] envelope Contains message envelope data. * @return True on success. */ - bool insertOrUpdateMessageEnvelopeInDb( - const MsgEnvelope &msgEnvelopeData); + bool insertOrUpdateMessageEnvelopeInDb(qint64 msgId, + enum MessageType messageType, const Isds::Envelope &envelope); /*! * @brief Set message in database as localy read. @@ -258,10 +261,10 @@ public: /*! * @brief Update message envelope in messages table. * - * @param[in] msgEnvelopeData Contains message envelope data. + * @param[in] envelope Contains message envelope data. * @return True on success. */ - bool updateMessageEnvelopeInDb(const MsgEnvelope &msgEnvelopeData); + bool updateMessageEnvelopeInDb(const Isds::Envelope &envelope); protected: /*! diff --git a/src/worker/task_download_delivery_info.cpp b/src/worker/task_download_delivery_info.cpp index a851dab04395da008d6572cf435f530f84196b7a..dcff78993e622076fbd61020140443d4c1937083 100644 --- a/src/worker/task_download_delivery_info.cpp +++ b/src/worker/task_download_delivery_info.cpp @@ -27,9 +27,9 @@ #include "src/log/log.h" #include "src/net/db_wrapper.h" #include "src/net/isds_const.h" -#include "src/net/xml_layer.h" #include "src/worker/emitter.h" #include "src/worker/task_download_delivery_info.h" +#include "src/xml/xml_download_delivery_info.h" TaskDownloadDeliveryInfo::TaskDownloadDeliveryInfo(IsdsSession::IsdsContext &ctx, NetLayer *netLayer, qint64 msgId) @@ -82,25 +82,22 @@ enum TaskDownloadDeliveryInfo::Result TaskDownloadDeliveryInfo::downloadDelivery } QByteArray xmlDataOut; - QList eventList; /* Send SOAP request */ if (!netLayer->sendSoapRequest(ctx, MESSAGE_SERVICE, - XmlLayer::xmlCreateSignedDeliveryInfoSoapRequest(msgId), - xmlDataOut)) { + Xml::xmlCreateSignedDeliveryInfoSoapRequest(msgId), xmlDataOut)) { return DL_ISDS_ERROR; } /* Parse SOAP response */ - if (!XmlLayer::parseGetSignedMsgDeliveryInfoResponse(xmlDataOut, - eventList, ctx.last_isds_msg)) { - return DL_XML_ERROR; - } + QList events = + Xml::parseGetSignedMsgDeliveryInfoResponse(xmlDataOut, + ctx.last_isds_msg); /* Store data into db */ - if (!eventList.isEmpty()) { + if (!events.isEmpty()) { if (!DbWrapper::insertMesasgeDeliveryInfoToDb(ctx.username, - eventList, msgId, ctx.last_isds_msg)) { + events, msgId, ctx.last_isds_msg)) { return DL_DB_INS_ERR; } } diff --git a/src/worker/task_download_message.cpp b/src/worker/task_download_message.cpp index 5c7c7b40a007e4bfdba26be48ea9e3aa21907a42..5eea5843f07e51c1d3f9130daf530ab38ad621ae 100644 --- a/src/worker/task_download_message.cpp +++ b/src/worker/task_download_message.cpp @@ -26,13 +26,17 @@ #include "src/global.h" #include "src/log/log.h" #include "src/io/filesystem.h" +#include "src/messages.h" #include "src/net/db_wrapper.h" #include "src/net/isds_const.h" -#include "src/net/xml_layer.h" #include "src/qml_interaction/message_envelope.h" #include "src/worker/emitter.h" #include "src/worker/task_download_message.h" #include "src/sqlite/message_db_container.h" +#include "src/xml/xml_download_delivery_info.h" +#include "src/xml/xml_download_message.h" +#include "src/xml/xml_download_message_author.h" +#include "src/xml/xml_mark_message_as_read.h" TaskDownloadMessage::TaskDownloadMessage(IsdsSession::IsdsContext &ctx, NetLayer *netLayer, qint64 msgId, @@ -99,33 +103,50 @@ enum TaskDownloadMessage::Result TaskDownloadMessage::downloadMessage( return DL_ERR; } - MsgEnvelope msg; QByteArray xmlDataOut; - QList fileList; - QList eventList; QString userType, authorName; QByteArray zfoData; /* Send SOAP request to download complete message */ if (!netLayer->sendSoapRequest(ctx, LOGIN_SERVICE, - XmlLayer::xmlCreateDownloadMessageSoapRequest(msgId, msgDirect), + Xml::xmlCreateDownloadMessageSoapRequest(msgId, msgDirect), xmlDataOut)) { return DL_ISDS_ERROR; } /* Parse SOAP response */ - if (!XmlLayer::parseSignedMessageDownloadResponse(xmlDataOut, msg, - fileList, ctx.last_isds_msg, zfoData)) { + Isds::Message message = Xml::parseSignedMessageDownloadResponse( + xmlDataOut, ctx.last_isds_msg, zfoData); + + if (message.isNull()) { return DL_XML_ERROR; } - if (fileList.isEmpty()) { + if (message.documents().isEmpty()) { return DL_ERR; } + enum MessageDb::MessageType msgType = MessageDb::TYPE_RECEIVED; + switch (msgDirect) { + case Messages::TYPE_RECEIVED: + msgType = MessageDb::TYPE_RECEIVED; + break; + case Messages::TYPE_SENT: + msgType = MessageDb::TYPE_SENT; + break; + default: + /* + * Any other translates to sent, but forces the application to + * crash in debugging mode. + */ + Q_ASSERT(0); + msgType = MessageDb::TYPE_SENT; + break; + } + /* Store data into db */ - if (!DbWrapper::insertCompleteMessageToDb(ctx.username, msg, - fileList, ctx.last_isds_msg)) { + if (!DbWrapper::insertCompleteMessageToDb(ctx.username, msgId, message, + msgType, ctx.last_isds_msg)) { return DL_DB_INS_ERR; } @@ -142,11 +163,10 @@ enum TaskDownloadMessage::Result TaskDownloadMessage::downloadMessage( /* Send SOAP request to download message author info */ netLayer->sendSoapRequest(ctx, MESSAGE_SERVICE, - XmlLayer::xmlCreateGetMessageAuthorSoapRequest(msgId), xmlDataOut); + Xml::xmlCreateGetMessageAuthorSoapRequest(msgId), xmlDataOut); /* Parse SOAP response */ - XmlLayer::parseGetAuthorInfo(xmlDataOut, userType, authorName, - ctx.last_isds_msg); + Xml::parseGetAuthorInfo(xmlDataOut, userType, authorName, ctx.last_isds_msg); /* Store data into db */ DbWrapper::updateAuthorInfo(ctx.username, userType, authorName, @@ -155,24 +175,23 @@ enum TaskDownloadMessage::Result TaskDownloadMessage::downloadMessage( /* Send SOAP request mark message as read (only for received message) */ if (Messages::TYPE_RECEIVED == msgDirect) { netLayer->sendSoapRequest(ctx, MESSAGE_SERVICE, - XmlLayer::xmlCreateMarkMessageAsDownloadedSoapRequest(msgId), + Xml::xmlCreateMarkMessageAsDownloadedSoapRequest(msgId), xmlDataOut); } /* Send delivery info SOAP request */ netLayer->sendSoapRequest(ctx, MESSAGE_SERVICE, - XmlLayer::xmlCreateSignedDeliveryInfoSoapRequest(msgId), + Xml::xmlCreateSignedDeliveryInfoSoapRequest(msgId), xmlDataOut); /* Parse delivery info SOAP response */ - XmlLayer::parseGetSignedMsgDeliveryInfoResponse(xmlDataOut, - eventList, ctx.last_isds_msg); + QList events = Xml::parseGetSignedMsgDeliveryInfoResponse( + xmlDataOut, ctx.last_isds_msg); /* Store delivery info into db */ - if (!eventList.isEmpty()) { + if (!events.isEmpty()) { DbWrapper::insertMesasgeDeliveryInfoToDb( - ctx.username, eventList, msgId, - ctx.last_isds_msg); + ctx.username, events, msgId, ctx.last_isds_msg); } /* Save message ZFO to zfo database */ diff --git a/src/worker/task_download_message_list.cpp b/src/worker/task_download_message_list.cpp index 48b3458681838b0a3d7d689474e13277386f1ff0..fe33c4320b795d0298930d2635a348369db528ed 100644 --- a/src/worker/task_download_message_list.cpp +++ b/src/worker/task_download_message_list.cpp @@ -28,12 +28,13 @@ #include "src/log/log.h" #include "src/net/db_wrapper.h" #include "src/net/isds_const.h" -#include "src/net/xml_layer.h" #include "src/qml_interaction/message_envelope.h" #include "src/worker/emitter.h" #include "src/worker/task_download_message.h" #include "src/worker/task_download_message_list.h" #include "src/sqlite/message_db_container.h" +#include "src/xml/xml_download_delivery_info.h" +#include "src/xml/xml_download_message_list.h" TaskDownloadMessageList::TaskDownloadMessageList(IsdsSession::IsdsContext &ctx, NetLayer *netLayer, enum Messages::MessageType msgDirect, @@ -122,28 +123,30 @@ enum TaskDownloadMessageList::Result TaskDownloadMessageList::downloadMessageLis } QByteArray xmlDataOut; - QList messages; - QList listOfNewMsgIds; /* Send SOAP request */ if (!netLayer->sendSoapRequest(ctx, MESSAGE_SERVICE, - XmlLayer::xmlCreateGetMessageListSoapRequest(msgDirect, + Xml::xmlCreateGetMessageListSoapRequest(msgDirect, dmStatusFilter, dmOffset, dmLimit), xmlDataOut)) { return DL_ISDS_ERROR; } /* Parse SOAP response */ - if (!XmlLayer::parseGetListOfMessagesResponse( - (Messages::TYPE_RECEIVED == msgDirect) ? MessageDb::TYPE_RECEIVED : MessageDb::TYPE_SENT, - xmlDataOut, messages, ctx.last_isds_msg)) { - return DL_XML_ERROR; + QList envelopes = Xml::parseGetListOfMessagesResponse( + xmlDataOut, ctx.last_isds_msg); + + if (envelopes.isEmpty()) { + return DL_SUCCESS; } /* Store data into db */ + QList listOfNewMsgIds; QList messageChangedStatusList; + if (!DbWrapper::insertMessageListToDb(ctx.username, - (Messages::TYPE_RECEIVED == msgDirect) ? MessageDb::TYPE_RECEIVED : MessageDb::TYPE_SENT, - messages, messageChangedStatusList, ctx.last_isds_msg, + (Messages::TYPE_RECEIVED == msgDirect) ? MessageDb::TYPE_RECEIVED + : MessageDb::TYPE_SENT, + envelopes, messageChangedStatusList, ctx.last_isds_msg, listOfNewMsgIds)) { return DL_DB_INS_ERR; } @@ -159,8 +162,6 @@ enum TaskDownloadMessageList::Result TaskDownloadMessageList::downloadMessageLis foreach (qint64 msgId, messageChangedStatusList) { - QList eventList; - /* * Following functions don't have to check return values * because they are complementary actions for message @@ -169,17 +170,18 @@ enum TaskDownloadMessageList::Result TaskDownloadMessageList::downloadMessageLis /* Send delivery info SOAP request */ netLayer->sendSoapRequest(ctx, MESSAGE_SERVICE, - XmlLayer::xmlCreateSignedDeliveryInfoSoapRequest(msgId), + Xml::xmlCreateSignedDeliveryInfoSoapRequest(msgId), xmlDataOut); /* Parse delivery info SOAP response */ - XmlLayer::parseGetSignedMsgDeliveryInfoResponse(xmlDataOut, - eventList, ctx.last_isds_msg); + QList events = + Xml::parseGetSignedMsgDeliveryInfoResponse( + xmlDataOut, ctx.last_isds_msg); /* Store delivery info into db */ - if (!eventList.isEmpty()) { + if (!events.isEmpty()) { DbWrapper::insertMesasgeDeliveryInfoToDb( - ctx.username, eventList, msgId, + ctx.username, events, msgId, ctx.last_isds_msg); } } diff --git a/src/worker/task_import_zfo.cpp b/src/worker/task_import_zfo.cpp index 9c21b061f69741272a1f6cd33dfd9afa7a616512..6f2abe58fef3396189bcd4035e38f7e747bddb9d 100644 --- a/src/worker/task_import_zfo.cpp +++ b/src/worker/task_import_zfo.cpp @@ -29,10 +29,11 @@ #include "src/log/log.h" #include "src/net/db_wrapper.h" #include "src/net/isds_const.h" -#include "src/net/xml_layer.h" #include "src/sqlite/account_db.h" #include "src/worker/emitter.h" #include "src/worker/task_import_zfo.h" +#include "src/xml/xml_authenticate_message.h" +#include "src/xml/xml_parse_zfo.h" TaskImportZfo::TaskImportZfo(IsdsSession *isdsSession, NetLayer *netLayer, const QStringList &userNameList, @@ -108,13 +109,12 @@ enum TaskImportZfo::Result TaskImportZfo::importZfo(IsdsSession *isdsSession, QByteArray zfoContent = file.readAll(); /* Parse zfo content and detect valid ZFO format */ - MsgEnvelope msgEnvelope; - QList fileList; - if (!XmlLayer::parseZFO(zfoContent, msgEnvelope, fileList, errText)) { + Isds::Message messsage = Xml::parseZfo(zfoContent); + if (messsage.isNull()) { errText = setErrorTextAndColor(QObject::tr("Wrong message format of ZFO file '%1'.").arg(fileName)); return IMP_ZFO_FORMAT_ERR; } - if (fileList.isEmpty()) { + if (messsage.documents().isEmpty()) { errText = setErrorTextAndColor(QObject::tr("Wrong message data of ZFO file '%1'.").arg(fileName)); return IMP_ZFO_DATA_ERR; } @@ -125,10 +125,10 @@ enum TaskImportZfo::Result TaskImportZfo::importZfo(IsdsSession *isdsSession, // names from uNameList. foreach (const QString &user, userNameList) { QString dbId(GlobInstcs::accountDbPtr->dbId(user)); - if (dbId == msgEnvelope.dbIDRecipient()) { + if (dbId == messsage.envelope().dbIDRecipient()) { isSentList.append(false); usrNameList.append(user); - } else if (dbId == msgEnvelope.dbIDSender()) { + } else if (dbId == messsage.envelope().dbIDSender()) { isSentList.append(true); usrNameList.append(user); } @@ -153,13 +153,13 @@ enum TaskImportZfo::Result TaskImportZfo::importZfo(IsdsSession *isdsSession, if (!netLayer->sendSoapRequest( isdsSession->isdsCtxMap[usrNameList.at(0)], LOGIN_SERVICE, - XmlLayer::xmlCreateAuthenticateMessageSoapRequest(zfoContent.toBase64()), + Xml::xmlCreateAuthenticateMessageSoapRequest(zfoContent.toBase64()), xmlDataOut)) { errText = setErrorTextAndColor(QObject::tr("Cannot authenticate the ZFO file '%1'.").arg(fileName)); return IMP_ISDS_ERR; } /* Parse SOAP response */ - if (!XmlLayer::parseAuthenticateMessage(xmlDataOut, errText)) { + if (!Xml::parseAuthenticateMessage(xmlDataOut, errText)) { errText = setErrorTextAndColor(QObject::tr("ZFO file '%1' is not authentic (returns ISDS)!").arg(fileName)); return IMP_AUTH_ERR; } @@ -167,10 +167,11 @@ enum TaskImportZfo::Result TaskImportZfo::importZfo(IsdsSession *isdsSession, /* Store message into accounts database */ for (int i = 0; i < usrNameList.count(); ++i) { - (isSentList.at(i)) ? msgEnvelope._setDmMessageType(MessageDb::MessageType::TYPE_SENT) - : msgEnvelope._setDmMessageType(MessageDb::MessageType::TYPE_RECEIVED); - if (!DbWrapper::insertCompleteMessageToDb(usrNameList.at(i), - msgEnvelope, fileList, errText)) { + if (!DbWrapper::insertCompleteMessageToDb( + usrNameList.at(i), messsage.envelope().dmId(), + messsage, (isSentList.at(i)) ? + MessageDb::MessageType::TYPE_SENT + : MessageDb::MessageType::TYPE_RECEIVED, errText)) { errText = setErrorTextAndColor(QObject::tr("Cannot store the ZFO file '%1' to local database.").arg(fileName)); return IMP_DB_INS_ERR; } @@ -178,8 +179,8 @@ enum TaskImportZfo::Result TaskImportZfo::importZfo(IsdsSession *isdsSession, #if 0 /* Save ZFO to zfo database */ - DbWrapper::insertZfoToDb(msgEnvelope.dmID(), true, zfoContent.size(), - zfoContent.toBase64()); + DbWrapper::insertZfoToDb(messsage.envelope().dmId(), true, + zfoContent.size(), zfoContent.toBase64()); #endif errText = QObject::tr("ZFO file '%1' has been imported.").arg(fileName); diff --git a/src/worker/task_send_message.cpp b/src/worker/task_send_message.cpp index 146a29b430d255ee796bbb5ece1127b07e9dc98d..d9ffc2e6b7fec67f27c63a69dee2fa2e167e6dd9 100644 --- a/src/worker/task_send_message.cpp +++ b/src/worker/task_send_message.cpp @@ -28,9 +28,9 @@ #include "src/log/log.h" #include "src/net/db_wrapper.h" #include "src/net/isds_const.h" -#include "src/net/xml_layer.h" #include "src/worker/emitter.h" #include "src/worker/task_send_message.h" +#include "src/xml/xml_send_message.h" TaskSendMessage::ResultData::ResultData(void) : result(false), @@ -52,18 +52,13 @@ TaskSendMessage::ResultData::ResultData(bool res, const QString &eInfo, } TaskSendMessage::TaskSendMessage(IsdsSession::IsdsContext &ctx, - NetLayer *netLayer, MsgEnvelope &msg, - QList &fileList, bool dmOVM, bool dmPublishOwnID, - const QString &transactId) + NetLayer *netLayer, const Isds::Message &message, const QString &transactId) : m_result(DL_ERR), - m_msgID(0), + m_dmId(0), m_lastError(), m_ctx(ctx), m_netLayer(netLayer), - m_msg(msg), - m_fileList(fileList), - m_dmOVM(dmOVM), - m_dmPublishOwnID(dmPublishOwnID), + m_message(message), m_transactId(transactId) { } @@ -85,15 +80,16 @@ void TaskSendMessage::run(void) m_ctx.account_name.toUtf8().constData()); logDebugLv1NL("%s", "-----------------------------------------------"); - m_result = sendMessage(m_ctx, m_netLayer, m_msg, m_fileList, - m_dmOVM, m_dmPublishOwnID, m_msgID, m_lastError); + m_result = sendMessage(m_ctx, m_netLayer, m_message, + m_dmId, m_lastError); /* ### Worker task end. ### */ if (GlobInstcs::msgProcEmitterPtr != Q_NULLPTR) { emit GlobInstcs::msgProcEmitterPtr->sendMessageFinishedSignal( - m_ctx.username, m_transactId, m_msg.dbIDRecipient(), - m_msg.dmRecipient(), m_msgID, + m_ctx.username, m_transactId, + m_message.envelope().dbIDRecipient(), + m_message.envelope().dmRecipient(), m_dmId, TaskSendMessage::DL_SUCCESS == m_result, m_lastError); } @@ -103,8 +99,7 @@ void TaskSendMessage::run(void) enum TaskSendMessage::Result TaskSendMessage::sendMessage( IsdsSession::IsdsContext &ctx, NetLayer *netLayer, - MsgEnvelope &msg, QList &fileList, - bool dmOVM, bool dmPublishOwnID, qint64 &msgID, QString &lastError) + const Isds::Message &message, qint64 &dmId, QString &lastError) { if (ctx.username.isEmpty()) { Q_ASSERT(0); @@ -116,15 +111,14 @@ enum TaskSendMessage::Result TaskSendMessage::sendMessage( /* Send SOAP request */ if (!netLayer->sendSoapRequest(ctx, LOGIN_SERVICE, - XmlLayer::xmlCreateSendMessageSoapRequest(msg, fileList, - dmOVM, dmPublishOwnID), xmlDataOut)) { + Xml::xmlCreateSendMessageSoapRequest(message), xmlDataOut)) { lastError = ctx.last_isds_msg; return DL_ISDS_ERROR; } /* Parse SOAP response */ - if (!XmlLayer::parseSentMessageStatusFromXml(xmlDataOut, msgID, - ctx.last_isds_msg)) { + dmId = Xml::parseSentMessageStatusFromXml(xmlDataOut, ctx.last_isds_msg); + if (dmId == -1) { lastError = ctx.last_isds_msg; return DL_XML_ERROR; } @@ -132,23 +126,15 @@ enum TaskSendMessage::Result TaskSendMessage::sendMessage( lastError = ctx.last_isds_msg; /* Fill missing message envelope data */ - msg.setDmID(msgID); - msg.setDmQTimestamp(""); - msg.setDmMessageStatus(1); +/* msg._setDmCustomData(""); msg._setDmReadLocally(true); msg._setDmAttachDownloaded(true); msg._setDmMessageType(Messages::TYPE_SENT); - - /* Fill missing message id to file list */ - QList::iterator it_file; - for (it_file = fileList.begin(); it_file != fileList.end(); ++it_file) { - it_file->setDmId(msgID); - } - +*/ /* Store data into db */ - if (!DbWrapper::insertCompleteMessageToDb(ctx.username, msg, - fileList, ctx.last_isds_msg)) { + if (!DbWrapper::insertCompleteMessageToDb(ctx.username, dmId, message, + MessageDb::TYPE_SENT, ctx.last_isds_msg)) { return DL_DB_INS_ERR; } diff --git a/src/worker/task_send_message.h b/src/worker/task_send_message.h index 27a9fcf7a96c228c4588dcdfa4f494e1ee9fafd0..32c0a7438856711f281415b1bf007d77b9bda1de 100644 --- a/src/worker/task_send_message.h +++ b/src/worker/task_send_message.h @@ -21,12 +21,11 @@ * the two. */ -#ifndef _TASK_SEND_MESSAGE_H_ -#define _TASK_SEND_MESSAGE_H_ +#pragma once +#include "src/datovka_shared/isds/message_interface.h" #include "src/net/isds_session.h" #include "src/net/net_layer.h" -#include "src/qml_interaction/attachment_data.h" #include "src/qml_interaction/message_envelope.h" #include "src/worker/task.h" @@ -70,16 +69,12 @@ public: * * @param[in] ctx Account isds context (include username). * @param[in] netLayer Pointer to network manager. - * @param[in] msg Message envelope. - * @param[in] fileList List of files. - * @param[in] dmOVM True if send message as OVM. - * @param[in] dmPublishOwnID True if add sender name to message. + * @param[in] message Message. * @param[in] transactId Unique transaction identifier. */ explicit TaskSendMessage(IsdsSession::IsdsContext &ctx, - NetLayer *netLayer, - MsgEnvelope &msg, QList &fileList, - bool dmOVM, bool dmPublishOwnID, const QString &transactId); + NetLayer *netLayer, const Isds::Message &message, + const QString &transactId); /*! * @brief Performs actual send message. @@ -96,18 +91,17 @@ public: * @param[in] fileList List of files. * @param[in] dmOVM True if send message as OVM. * @param[in] dmPublishOwnID True if add sender name to message. - * @param[out] msgID Sent message ID. + * @param[out] dmId Sent message ID. * @param[out] lastError Last ISDS error message. * @return Error state. */ static enum Result sendMessage(IsdsSession::IsdsContext &ctx, - NetLayer *netLayer, MsgEnvelope &msg, - QList &fileList, bool dmOVM, bool dmPublishOwnID, - qint64 &msgID, QString &lastError); + NetLayer *netLayer, const Isds::Message &message, + qint64 &dmId, QString &lastError); enum Result m_result; /*!< Return state. */ - qint64 m_msgID; /*!< Sent message ID. */ + qint64 m_dmId; /*!< Sent message ID. */ QString m_lastError; /*!< Last ISDS error message. */ private: @@ -119,11 +113,6 @@ private: IsdsSession::IsdsContext m_ctx; /*!< Account isds context. */ NetLayer *m_netLayer; /*!< Pointer to network manager to send request. */ - MsgEnvelope m_msg; /*!< Message subject string. */ - QList m_fileList; /*!< List of files. */ - bool m_dmOVM; /*!< True if send message as OVM. */ - bool m_dmPublishOwnID; /*!< True if add sender name to message. */ + Isds::Message m_message; /*!< Message subject string. */ const QString m_transactId; /*!< Unique transaction identifier. */ }; - -#endif /* _TASK_SEND_MESSAGE_H_ */ diff --git a/src/xml/xml_authenticate_message.cpp b/src/xml/xml_authenticate_message.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8d12f1657929df23963a1bb79f740def716f6eb5 --- /dev/null +++ b/src/xml/xml_authenticate_message.cpp @@ -0,0 +1,67 @@ +/* + * 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 . + * + * 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 + +#include "src/net/isds_const.h" +#include "src/xml/xml_authenticate_message.h" +#include "src/xml/xml_base.h" + +QByteArray Xml::xmlCreateAuthenticateMessageSoapRequest( + const QByteArray &message) +{ + QString xmlContent(""); + xmlContent.append(message); + xmlContent.append(""); + xmlContent.append(""); + return Xml::xmlCreateSoapEnvelopeHeader(xmlContent); +} + +bool Xml::parseAuthenticateMessage(const QByteArray &xmlData, QString &txt) +{ + if (!parseDmStatusFromXml(xmlData, txt)) { + return false; + } + + QXmlStreamReader xml; + xml.addData(xmlData); + bool isValid = false; + + while(!xml.atEnd() && !xml.hasError()){ + QXmlStreamReader::TokenType token = xml.readNext(); + if (token == QXmlStreamReader::StartDocument) { + continue; + } + if (token == QXmlStreamReader::StartElement) { + if (xml.name() == "dmAuthResult") { + xml.readNext(); + if (xml.text().toString() == "true") { + isValid = true; + } + } + } + } + return isValid; +} diff --git a/src/xml/xml_authenticate_message.h b/src/xml/xml_authenticate_message.h new file mode 100644 index 0000000000000000000000000000000000000000..d0ecb35c2d6a54af47ec857028de4d4b493bb9bd --- /dev/null +++ b/src/xml/xml_authenticate_message.h @@ -0,0 +1,48 @@ +/* + * 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 . + * + * 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 +#include + +namespace Xml { + + /*! + * @brief Create authenticate message soap request. + * + * @param[in] message Message content. + * @return Soap request string as byte array. + */ + QByteArray xmlCreateAuthenticateMessageSoapRequest( + const QByteArray &message); + + /*! + * @brief Parse authenticate messagee xml data. + * + * @param[in] xmlData Xml Data for parsing. + * @param[out] txt Error description if something failed. + * @return true if message is valid. + */ + bool parseAuthenticateMessage(const QByteArray &xmlData, QString &txt); +} diff --git a/src/xml/xml_base.cpp b/src/xml/xml_base.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cd576f59c23736a7e8e26541cba422e1519a8d4b --- /dev/null +++ b/src/xml/xml_base.cpp @@ -0,0 +1,141 @@ +/* + * 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 . + * + * 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 + +#include "src/crypto/crypto.h" +#include "src/xml/xml_base.h" + +/* XML SOAP envelope constants */ +#define XML_VERSION_ENCODING "" +#define XML_ENVELOPE_HEADER "" +#define XML_ENVELOPE_FOOTER "" + +QByteArray Xml::xmlCreateSoapEnvelopeHeader(const QString &xmlSoapService) +{ + QString requestContent; + requestContent.append(XML_VERSION_ENCODING); + requestContent.append(XML_ENVELOPE_HEADER); + requestContent.append(xmlSoapService); + requestContent.append(XML_ENVELOPE_FOOTER); + return requestContent.toUtf8(); +} + +bool Xml::parseDmStatusFromXml(const QByteArray &xmlData, + QString &dmStatusMessage) +{ + QXmlStreamReader xml; + xml.addData(xmlData); + QString dmStatusCode = "-1"; + + while (!xml.atEnd() && !xml.hasError()) { + QXmlStreamReader::TokenType token = xml.readNext(); + if (token == QXmlStreamReader::StartDocument) { + continue; + } + if (token == QXmlStreamReader::StartElement) { + if (xml.name() == "dmStatus") { + /* Parse first part of xml response */ + while (!(xml.tokenType() == QXmlStreamReader::EndElement + && xml.name() == "dmStatus")) { + if (xml.tokenType() == + QXmlStreamReader::StartElement) { + if (xml.name() == "dmStatusCode") { + xml.readNext(); + dmStatusCode = + xml.text().toString(); + } else if (xml.name() == "dmStatusMessage") { + xml.readNext(); + dmStatusMessage = xml.text().toString(); + } + } + xml.readNext(); + } + } + } + } + return (dmStatusCode == "0000"); +} + +bool Xml::parseDbStatusFromXml(const QByteArray &xmlData, + QString &dbStatusMessage) +{ + QXmlStreamReader xml; + xml.addData(xmlData); + QString dbStatusCode = "-1"; + + while (!xml.atEnd() && !xml.hasError()) { + QXmlStreamReader::TokenType token = xml.readNext(); + if (token == QXmlStreamReader::StartDocument) { + continue; + } + if (token == QXmlStreamReader::StartElement) { + if (xml.name() == "dbStatus") { + /* Parse first part of xml response */ + while (!(xml.tokenType() == QXmlStreamReader::EndElement + && xml.name() == "dbStatus")) { + if (xml.tokenType() == + QXmlStreamReader::StartElement) { + if (xml.name() == "dbStatusCode") { + xml.readNext(); + dbStatusCode = + xml.text().toString(); + } else if (xml.name() == "dbStatusMessage") { + xml.readNext(); + dbStatusMessage = xml.text().toString(); + } + } + xml.readNext(); + } + } + } + } + return (dbStatusCode == "0000"); +} + +QByteArray Xml::getXmlFromCms(const QByteArray &cmsData) +{ + /* decode cms and obtain message xml data - used openssl */ + void *xmlContent = NULL; + size_t xmlContentLen = 0; + if (extract_cms_data(cmsData.data(), cmsData.length(), &xmlContent, + &xmlContentLen) != 0) { + return QByteArray(); + } + if (xmlContentLen == 0) { + free(xmlContent); xmlContent = NULL; + return QByteArray(); + } + QByteArray soap((char*)xmlContent, xmlContentLen); + free(xmlContent); xmlContent = NULL; + + /* add xml SOAP header anf footer */ + soap.prepend("" + "" + ""); + soap.append(""); + + return soap; +} diff --git a/src/xml/xml_base.h b/src/xml/xml_base.h new file mode 100644 index 0000000000000000000000000000000000000000..7ee7392eb5a11eec5452f452a0167fc290d425dd --- /dev/null +++ b/src/xml/xml_base.h @@ -0,0 +1,66 @@ +/* + * 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 . + * + * 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 +#include + +namespace Xml { + + /*! + * @brief Create envelope header over xml data. + * + * @param[in] xmlSoapService Xml soap service request. + * @return Xml Soap request with header envelope. + */ + QByteArray xmlCreateSoapEnvelopeHeader(const QString &xmlSoapService); + + /*! + * @brief Parse dmStatus from XML response. + * + * @param[in] xmlData Xml data for parsing. + * @param[out] dmStatusMessage Status or error info if something failed. + * @return True if operation was successed. + */ + bool parseDmStatusFromXml(const QByteArray &xmlData, + QString &dmStatusMessage); + + /*! + * @brief Parse dbStatus from XML response. + * + * @param[in] xmlData Xml Data for parsing. + * @param[out] dmStatusMessage Status or error info if something failed. + * @return True if operation was successed. + */ + bool parseDbStatusFromXml(const QByteArray &xmlData, + QString &dbStatusMessage); + + /*! + * @brief Decode CMS message - requires OpenSsl + * + * @param[in] cmsData Message cms data. + * @return XML message data. + */ + QByteArray getXmlFromCms(const QByteArray &msgCmsData); +} diff --git a/src/xml/xml_download_delivery_info.cpp b/src/xml/xml_download_delivery_info.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b1d11637b0476aa721a2bbd7edaa185035bfccc6 --- /dev/null +++ b/src/xml/xml_download_delivery_info.cpp @@ -0,0 +1,117 @@ +/* + * 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 . + * + * 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 + +#include "src/datovka_shared/isds/type_conversion.h" +#include "src/isds/isds_type_conversion.h" +#include "src/net/isds_const.h" +#include "src/sqlite/dbs.h" +#include "src/xml/xml_base.h" +#include "src/xml/xml_download_delivery_info.h" + +Isds::Event parseMessageEvent(QXmlStreamReader &xml) +{ + Isds::Event event; + while (!(xml.tokenType() == QXmlStreamReader::EndElement + && xml.name() == "dmEvent")) { + if (xml.tokenType() == QXmlStreamReader::StartElement) { + if (xml.name() == "dmEventTime") { + xml.readNext(); + event.setTime(isoDateTimeStrToUtcDateTime(xml.text().toString())); + } else if (xml.name() == "dmEventDescr") { + xml.readNext(); + event.setDescr(xml.text().toString()); + } + } + xml.readNext(); + } + return event; +} + +QByteArray Xml::xmlCreateSignedDeliveryInfoSoapRequest(qint64 msgId) +{ + QString xmlContent(""); + xmlContent.append(QString::number(msgId)); + xmlContent.append(""); + return Xml::xmlCreateSoapEnvelopeHeader(xmlContent); +} + +QList Xml::parseGetSignedMsgDeliveryInfoResponse( + const QByteArray &xmlData, QString &txt) +{ + qDebug("%s()", __func__); + + if (!parseDmStatusFromXml(xmlData, txt)) { + return QList(); + } + + QXmlStreamReader xml; + xml.addData(xmlData); + QByteArray signature; + + /* parse signature from XML */ + while (!xml.atEnd() && !xml.hasError()) { + QXmlStreamReader::TokenType token = xml.readNext(); + if (token == QXmlStreamReader::StartDocument) { + continue; + } + if (token == QXmlStreamReader::StartElement) { + if (xml.name() == "dmSignature") { + xml.readNext(); + signature = xml.text().toUtf8(); + } + } + } + + /* decode signature from base64 and obtain cms message */ + QByteArray cmsData = QByteArray::fromBase64(signature); + QByteArray soap = getXmlFromCms(cmsData); + return Xml::parseDeliveryInfo(soap); +} + +QList Xml::parseDeliveryInfo(const QByteArray &soap) +{ + if (soap.isNull()) { + return QList(); + } + + QList events; + QXmlStreamReader xml; + xml.addData(soap); + + while (!xml.atEnd() && !xml.hasError()){ + QXmlStreamReader::TokenType token = xml.readNext(); + if (token == QXmlStreamReader::StartDocument) { + continue; + } + if (token == QXmlStreamReader::StartElement) { + if (xml.name() == "dmEvent") { + events.append(parseMessageEvent(xml)); + } + } + } + return events; +} diff --git a/src/xml/xml_download_delivery_info.h b/src/xml/xml_download_delivery_info.h new file mode 100644 index 0000000000000000000000000000000000000000..0eb017065fa7eff43d64a0735da6966e5202b02e --- /dev/null +++ b/src/xml/xml_download_delivery_info.h @@ -0,0 +1,59 @@ +/* + * 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 . + * + * 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 +#include +#include + +#include "src/datovka_shared/isds/message_interface.h" + +namespace Xml { + + /*! + * @brief Create signed deliveriy info soap request. + * + * @param[in] msgId Message ID. + * @return Soap request string as byte array. + */ + QByteArray xmlCreateSignedDeliveryInfoSoapRequest(qint64 msgId); + + /*! + * @brief Parse signed message delivery info. + * + * @param[in] xmlData Xml signed delivery info for parsing. + * @param[out] txt Error description if something failed. + * @return List of delivery events. + */ + QList parseGetSignedMsgDeliveryInfoResponse( + const QByteArray &xmlData, QString &txt); + + /*! + * @brief Parse xml message delivery info. + * + * @param[in] soap Xml delivery data for parsing. + * @return List of delivery events. + */ + QList parseDeliveryInfo(const QByteArray &soap); +} diff --git a/src/xml/xml_download_message.cpp b/src/xml/xml_download_message.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f14527a7290955f0b2dbfa485998b4ad2398341e --- /dev/null +++ b/src/xml/xml_download_message.cpp @@ -0,0 +1,341 @@ +/* + * 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 . + * + * 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 + +#include "src/datovka_shared/isds/type_conversion.h" +#include "src/isds/isds_type_conversion.h" +#include "src/net/isds_const.h" +#include "src/sqlite/dbs.h" +#include "src/xml/xml_base.h" +#include "src/xml/xml_download_message.h" + +Isds::Document parseMessageDocument(QXmlStreamReader &xml) +{ + qDebug("%s()", __func__); + + Isds::Document document; + + while (!(xml.tokenType() == QXmlStreamReader::EndElement + && xml.name() == "dmFile")) { + if ((xml.tokenType() == QXmlStreamReader::StartElement) + && (xml.name() == "dmFile")) { + foreach (const QXmlStreamAttribute &attr, xml.attributes()) { + if (attr.name() == "dmFileDescr") { + document.setFileDescr(attr.value().toString()); + } else if (attr.name() == "dmUpFileGuid") { + document.setUpFileGuid(attr.value().toString()); + } else if (attr.name() == "dmFileGuid") { + document.setFileGuid(attr.value().toString()); + } else if (attr.name() == "dmMimeType") { + document.setMimeType(attr.value().toString()); + } else if (attr.name() == "dmFormat") { + document.setFormat(attr.value().toString()); + } else if (attr.name() == "dmFileMetaType") { + document.setFileMetaType( + Isds::m_str2FileMetaType( + attr.value().toString())); + } + } + } else if ((xml.tokenType() == QXmlStreamReader::StartElement) + && (xml.name() == "dmEncodedContent")) { + xml.readNext(); + document.setBase64Content(xml.text().toString()); + } + xml.readNext(); + } + return document; +} + +Isds::Message parseMessageData(QXmlStreamReader &xml, const QString &dmType) +{ + qDebug("%s()", __func__); + + Isds::Message message; + Isds::Envelope envelope; + QList documents; + + if (!dmType.isNull() && dmType.length() == 1) { + envelope.setDmType(Isds::Envelope::char2DmType(dmType[0])); + } else { + envelope.setDmType(Isds::Type::MT_V); + } + + while ((xml.tokenType() != QXmlStreamReader::StartElement) + && (xml.name() != "dmDm")) { + goto fail; + } + + xml.readNext(); + + /* Parse first part of xml response */ + while (!(xml.tokenType() == QXmlStreamReader::EndElement + && xml.name() == "dmDm")) { + if (xml.tokenType() == QXmlStreamReader::StartElement) { + if (xml.name() == "dmID") { + xml.readNext(); + envelope.setDmId(xml.text().toLongLong()); + envelope.setDmID(xml.text().toString()); + } else + if (xml.name() == "dbIDSender") { + xml.readNext(); + envelope.setDbIDSender(xml.text().toString()); + } else + if (xml.name() == "dmSender") { + xml.readNext(); + envelope.setDmSender(xml.text().toString()); + } else + if (xml.name() == "dmSenderAddress") { + xml.readNext(); + envelope.setDmSenderAddress(xml.text().toString()); + } else + if (xml.name() == "dmSenderType") { + xml.readNext(); + envelope.setDmSenderType(Isds::intVariant2DbType(xml.text().toInt())); + } else + if (xml.name() == "dmRecipient") { + xml.readNext(); + envelope.setDmRecipient(xml.text().toString()); + } else + if (xml.name() == "dmRecipientAddress") { + xml.readNext(); + envelope.setDmRecipientAddress(xml.text().toString()); + } else + if (xml.name() == "dmAmbiguousRecipient") { + xml.readNext(); + envelope.setDmAmbiguousRecipient(Isds::str2BoolType(xml.text().toString())); + } else + if (xml.name() == "dmSenderOrgUnit") { + xml.readNext(); + envelope.setDmSenderOrgUnit(xml.text().toString()); + } else + if (xml.name() == "dmSenderOrgUnitNum") { + xml.readNext(); + envelope.setDmSenderOrgUnitNum(xml.text().toLongLong()); + envelope.setDmSenderOrgUnitNumStr(xml.text().toString()); + } else + if (xml.name() == "dbIDRecipient") { + xml.readNext(); + envelope.setDbIDRecipient(xml.text().toString()); + } else + if (xml.name() == "dmRecipientOrgUnit") { + xml.readNext(); + envelope.setDmRecipientOrgUnit(xml.text().toString()); + } else + if (xml.name() == "dmRecipientOrgUnitNum") { + xml.readNext(); + envelope.setDmRecipientOrgUnitNum(xml.text().toLongLong()); + envelope.setDmRecipientOrgUnitNumStr(xml.text().toString()); + } else + if (xml.name() == "dmToHands") { + xml.readNext(); + envelope.setDmToHands(xml.text().toString()); + } else + if (xml.name() == "dmAnnotation") { + xml.readNext(); + envelope.setDmAnnotation(xml.text().toString()); + } else + if (xml.name() == "dmRecipientRefNumber") { + xml.readNext(); + envelope.setDmRecipientRefNumber(xml.text().toString()); + } else + if (xml.name() == "dmSenderRefNumber") { + xml.readNext(); + envelope.setDmSenderRefNumber(xml.text().toString()); + } else + if (xml.name() == "dmRecipientIdent") { + xml.readNext(); + envelope.setDmRecipientIdent(xml.text().toString()); + } else + if (xml.name() == "dmSenderIdent") { + xml.readNext(); + envelope.setDmSenderIdent(xml.text().toString()); + } else + if (xml.name() == "dmLegalTitleLaw") { + xml.readNext(); + envelope.setDmLegalTitleLaw(xml.text().toLongLong()); + envelope.setDmLegalTitleLawStr(xml.text().toString()); + } else + if (xml.name() == "dmLegalTitleYear") { + xml.readNext(); + envelope.setDmLegalTitleYear(xml.text().toLongLong()); + envelope.setDmLegalTitleYearStr(xml.text().toString()); + } else + if (xml.name() == "dmLegalTitleSect") { + xml.readNext(); + envelope.setDmLegalTitleSect(xml.text().toString()); + } else + if (xml.name() == "dmLegalTitlePar") { + xml.readNext(); + envelope.setDmLegalTitlePar(xml.text().toString()); + } else + if (xml.name() == "dmLegalTitlePoint") { + xml.readNext(); + envelope.setDmLegalTitlePoint(xml.text().toString()); + } else + if (xml.name() == "dmPersonalDelivery") { + xml.readNext(); + envelope.setDmPersonalDelivery(Isds::str2BoolType(xml.text().toString())); + } else + if (xml.name() == "dmAllowSubstDelivery") { + xml.readNext(); + envelope.setDmAllowSubstDelivery(Isds::str2BoolType(xml.text().toString())); + } else + /* Parse file part of xml response */ + if (xml.name() == "dmFiles") { + xml.readNext(); + while (!(xml.tokenType() == QXmlStreamReader::EndElement + && xml.name() == "dmFiles")) { + documents.append(parseMessageDocument(xml)); + xml.readNext(); + } + } + } + xml.readNext(); + } + + /* Parse other parts of xml envelope */ + while (!(xml.tokenType() == QXmlStreamReader::EndElement + && xml.name() == "dmReturnedMessage")) { + if (xml.error() != QXmlStreamReader::NoError) { + goto fail; + } + if (xml.tokenType() == QXmlStreamReader::StartElement) { + if (xml.name() == "dmDeliveryTime") { + xml.readNext(); + envelope.setDmDeliveryTime(isoDateTimeStrToUtcDateTime(xml.text().toString())); + } else + if (xml.name() == "dmAcceptanceTime") { + xml.readNext(); + envelope.setDmAcceptanceTime(isoDateTimeStrToUtcDateTime(xml.text().toString())); + } else + if (xml.name() == "dmMessageStatus") { + xml.readNext(); + envelope.setDmMessageStatus(Isds::variant2DmState(QVariant(xml.text().toString()))); + } else + if (xml.name() == "dmAttachmentSize") { + xml.readNext(); + envelope.setDmAttachmentSize(xml.text().toLongLong()); + } + } + xml.readNext(); + } + + message.setEnvelope(envelope); + message.setDocuments(documents); + return message; +fail: + return Isds::Message(); +} + +QByteArray Xml::xmlCreateDownloadMessageSoapRequest(qint64 msgId, + enum Messages::MessageType msgDirect) +{ + QString xmlContent; + if (Messages::TYPE_RECEIVED == msgDirect) { + xmlContent.append(""); + xmlContent.append(QString::number(msgId)); + xmlContent.append(""); + + if (Messages::TYPE_RECEIVED == msgDirect) { + xmlContent.append(""); + } else { + xmlContent.append(""); + } + + return Xml::xmlCreateSoapEnvelopeHeader(xmlContent); +} + +Isds::Message Xml::parseSignedMessageDownloadResponse( + const QByteArray &xmlData, QString &txt, QByteArray &zfoData) +{ + qDebug("%s()", __func__); + + if (!Xml::parseDmStatusFromXml(xmlData, txt)) { + return Isds::Message(); + } + + QXmlStreamReader xml; + xml.addData(xmlData); + QByteArray signature; + + /* parse signature from XML */ + while (!xml.atEnd() && !xml.hasError()) { + QXmlStreamReader::TokenType token = xml.readNext(); + if (token == QXmlStreamReader::StartDocument) { + continue; + } + if (token == QXmlStreamReader::StartElement) { + if (xml.name() == "dmSignature") { + xml.readNext(); + signature = xml.text().toUtf8(); + } + } + } + + /* decode signature from base64 and obtain cms message */ + QByteArray cmsData = QByteArray::fromBase64(signature); + QByteArray soap = getXmlFromCms(cmsData); + if (soap.isNull()) { + return Isds::Message(); + } + + zfoData = cmsData; + return Xml::parseCompleteMessage(soap); +} + +Isds::Message Xml::parseCompleteMessage(const QByteArray &soap) +{ + /* Parse XML */ + QString dmType; + QXmlStreamReader xml; + xml.addData(soap); + + while(!xml.atEnd() && !xml.hasError()) { + QXmlStreamReader::TokenType token = xml.readNext(); + if (xml.error() != QXmlStreamReader::NoError) { + return Isds::Message(); + } + if (token == QXmlStreamReader::StartDocument) { + continue; + } + if (token == QXmlStreamReader::StartElement) { + if (xml.name() == "dmReturnedMessage") { + foreach (const QXmlStreamAttribute &attr, xml.attributes()) { + if (attr.name() == "dmType") { + dmType = attr.value().toString(); + } + } + } + if (xml.name() == "dmDm") { + return parseMessageData(xml, dmType); + } + } + } + return Isds::Message(); +} diff --git a/src/xml/xml_download_message.h b/src/xml/xml_download_message.h new file mode 100644 index 0000000000000000000000000000000000000000..ee439bf88f59fe34deae4d5adf5f9cb46c5b3526 --- /dev/null +++ b/src/xml/xml_download_message.h @@ -0,0 +1,62 @@ +/* + * 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 . + * + * 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 +#include + +#include "src/datovka_shared/isds/message_interface.h" +#include "src/messages.h" + +namespace Xml { + + /*! + * @brief Create download message soap request. + * + * @param[in] msgId Message ID. + * @param[in] msgDirect Message orientation. + * @return Soap request string as byte array. + */ + QByteArray xmlCreateDownloadMessageSoapRequest(qint64 msgId, + enum Messages::MessageType msgDirect); + + /*! + * @brief Parse SignedMessageDownloadResponse XML. + * + * @param[in] xmlData Xml Data for parsing. + * @param[out] txt Error description if something failed. + * @param[out] zfoData ZFO file content. + * @return Message structure. + */ + Isds::Message parseSignedMessageDownloadResponse( + const QByteArray &xmlData, QString &txt, QByteArray &zfoData); + + /*! + * @brief Parse complete message XML. + * + * @param[in] soap Xml message data for parsing. + * @return Message structure. + */ + Isds::Message parseCompleteMessage(const QByteArray &soap); +} diff --git a/src/xml/xml_download_message_author.cpp b/src/xml/xml_download_message_author.cpp new file mode 100644 index 0000000000000000000000000000000000000000..636b9a4e1b53e2433ee23f882e57d0f7b941ea82 --- /dev/null +++ b/src/xml/xml_download_message_author.cpp @@ -0,0 +1,69 @@ +/* + * 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 . + * + * 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 + +#include "src/net/isds_const.h" +#include "src/xml/xml_base.h" +#include "src/xml/xml_download_message_author.h" + +QByteArray Xml::xmlCreateGetMessageAuthorSoapRequest(qint64 msgId) +{ + QString xmlContent(""); + xmlContent.append(QString::number(msgId)); + xmlContent.append(""); + return Xml::xmlCreateSoapEnvelopeHeader(xmlContent); +} + +bool Xml::parseGetAuthorInfo(const QByteArray &xmlData, QString &userType, + QString &authorName, QString &txt) +{ + qDebug("%s()", __func__); + + if (!parseDmStatusFromXml(xmlData, txt)) { + return false; + } + + QXmlStreamReader xml; + xml.addData(xmlData); + + while(!xml.atEnd() && !xml.hasError()){ + QXmlStreamReader::TokenType token = xml.readNext(); + if (token == QXmlStreamReader::StartDocument) { + continue; + } + if (token == QXmlStreamReader::StartElement) { + if (xml.name() == "userType") { + xml.readNext(); + userType = xml.text().toString(); + } else + if (xml.name() == "authorName") { + xml.readNext(); + authorName = xml.text().toString(); + } + } + } + return true; +} diff --git a/src/xml/xml_download_message_author.h b/src/xml/xml_download_message_author.h new file mode 100644 index 0000000000000000000000000000000000000000..785f811ccd820b26b5fa6ca412efd3ad465dcd06 --- /dev/null +++ b/src/xml/xml_download_message_author.h @@ -0,0 +1,50 @@ +/* + * 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 . + * + * 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 +#include + +namespace Xml { + + /*! + * @brief Create get message author soap request. + * + * @param[in] msgId Message ID. + * @return Soap request string as byte array. + */ + QByteArray xmlCreateGetMessageAuthorSoapRequest(qint64 msgId); + + /*! + * @brief Parse message author xml data. + * + * @param[in] xmlData Sml Data for parsing. + * @param[out] userType Author type string. + * @param[out] authorName Author name string. + * @param[out] txt Error description if something failed. + * @return True if success. + */ + bool parseGetAuthorInfo(const QByteArray &xmlData, QString &userType, + QString &authorName, QString &txt); +} diff --git a/src/xml/xml_download_message_list.cpp b/src/xml/xml_download_message_list.cpp new file mode 100644 index 0000000000000000000000000000000000000000..95daa372ff180f98c323e99027a635237c8ce592 --- /dev/null +++ b/src/xml/xml_download_message_list.cpp @@ -0,0 +1,251 @@ +/* + * 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 . + * + * 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 + +#include "src/datovka_shared/isds/type_conversion.h" +#include "src/isds/isds_type_conversion.h" +#include "src/net/isds_const.h" +#include "src/sqlite/dbs.h" +#include "src/xml/xml_base.h" +#include "src/xml/xml_download_message_list.h" + +Isds::Envelope parseMessageEnvelope(QXmlStreamReader &xml) +{ + while ((xml.tokenType() != QXmlStreamReader::StartElement) + && (xml.name() != "dmRecord")) { + return Isds::Envelope(); + } + + Isds::Envelope envelope; + QString dmType; + + foreach (const QXmlStreamAttribute &attr, xml.attributes()) { + if (attr.name() == "dmType") { + dmType = attr.value().toString(); + } + } + + if (!dmType.isNull() && dmType.length() == 1) { + envelope.setDmType(Isds::Envelope::char2DmType(dmType[0])); + } else { + envelope.setDmType(Isds::Type::MT_V); + } + + xml.readNext(); + + while (!(xml.tokenType() == QXmlStreamReader::EndElement + && (xml.name() == "dmRecord"))) { + if (xml.tokenType() == QXmlStreamReader::StartElement) { + if (xml.name() == "dmOrdinal") { + xml.readNext(); + envelope.setDmOrdinal(xml.text().toLongLong()); + } + if (xml.name() == "dmID") { + xml.readNext(); + envelope.setDmId(xml.text().toLongLong()); + envelope.setDmID(xml.text().toString()); + } else + if (xml.name() == "dbIDSender") { + xml.readNext(); + envelope.setDbIDSender(xml.text().toString()); + } else + if (xml.name() == "dmSender") { + xml.readNext(); + envelope.setDmSender(xml.text().toString()); + } else + if (xml.name() == "dmSenderAddress") { + xml.readNext(); + envelope.setDmSenderAddress(xml.text().toString()); + } else + if (xml.name() == "dmSenderType") { + xml.readNext(); + envelope.setDmSenderType(Isds::intVariant2DbType(xml.text().toInt())); + } else + if (xml.name() == "dmRecipient") { + xml.readNext(); + envelope.setDmRecipient(xml.text().toString()); + } else + if (xml.name() == "dmRecipientAddress") { + xml.readNext(); + envelope.setDmRecipientAddress(xml.text().toString()); + } else + if (xml.name() == "dmAmbiguousRecipient") { + xml.readNext(); + envelope.setDmAmbiguousRecipient(Isds::str2BoolType(xml.text().toString())); + } else + if (xml.name() == "dmSenderOrgUnit") { + xml.readNext(); + envelope.setDmSenderOrgUnit(xml.text().toString()); + } else + if (xml.name() == "dmSenderOrgUnitNum") { + xml.readNext(); + envelope.setDmSenderOrgUnitNum(xml.text().toLongLong()); + envelope.setDmSenderOrgUnitNumStr(xml.text().toString()); + } else + if (xml.name() == "dbIDRecipient") { + xml.readNext(); + envelope.setDbIDRecipient(xml.text().toString()); + } else + if (xml.name() == "dmRecipientOrgUnit") { + xml.readNext(); + envelope.setDmRecipientOrgUnit(xml.text().toString()); + } else + if (xml.name() == "dmRecipientOrgUnitNum") { + xml.readNext(); + envelope.setDmRecipientOrgUnitNum(xml.text().toLongLong()); + envelope.setDmRecipientOrgUnitNumStr(xml.text().toString()); + } else + if (xml.name() == "dmToHands") { + xml.readNext(); + envelope.setDmToHands(xml.text().toString()); + } else + if (xml.name() == "dmAnnotation") { + xml.readNext(); + envelope.setDmAnnotation(xml.text().toString()); + } else + if (xml.name() == "dmRecipientRefNumber") { + xml.readNext(); + envelope.setDmRecipientRefNumber(xml.text().toString()); + } else + if (xml.name() == "dmSenderRefNumber") { + xml.readNext(); + envelope.setDmSenderRefNumber(xml.text().toString()); + } else + if (xml.name() == "dmRecipientIdent") { + xml.readNext(); + envelope.setDmRecipientIdent(xml.text().toString()); + } else + if (xml.name() == "dmSenderIdent") { + xml.readNext(); + envelope.setDmSenderIdent(xml.text().toString()); + } else + if (xml.name() == "dmLegalTitleLaw") { + xml.readNext(); + envelope.setDmLegalTitleLaw(xml.text().toLongLong()); + envelope.setDmLegalTitleLawStr(xml.text().toString()); + } else + if (xml.name() == "dmLegalTitleYear") { + xml.readNext(); + envelope.setDmLegalTitleYear(xml.text().toLongLong()); + envelope.setDmLegalTitleYearStr(xml.text().toString()); + } else + if (xml.name() == "dmLegalTitleSect") { + xml.readNext(); + envelope.setDmLegalTitleSect(xml.text().toString()); + } else + if (xml.name() == "dmLegalTitlePar") { + xml.readNext(); + envelope.setDmLegalTitlePar(xml.text().toString()); + } else + if (xml.name() == "dmLegalTitlePoint") { + xml.readNext(); + envelope.setDmLegalTitlePoint(xml.text().toString()); + } else + if (xml.name() == "dmPersonalDelivery") { + xml.readNext(); + envelope.setDmPersonalDelivery(Isds::str2BoolType(xml.text().toString())); + } else + if (xml.name() == "dmAllowSubstDelivery") { + xml.readNext(); + envelope.setDmAllowSubstDelivery(Isds::str2BoolType(xml.text().toString())); + } else + if (xml.name() == "dmDeliveryTime") { + xml.readNext(); + envelope.setDmDeliveryTime(isoDateTimeStrToUtcDateTime(xml.text().toString())); + } else + if (xml.name() == "dmAcceptanceTime") { + xml.readNext(); + envelope.setDmAcceptanceTime(isoDateTimeStrToUtcDateTime(xml.text().toString())); + } else + if (xml.name() == "dmMessageStatus") { + xml.readNext(); + envelope.setDmMessageStatus(Isds::variant2DmState(QVariant(xml.text().toString()))); + } else + if (xml.name() == "dmAttachmentSize") { + xml.readNext(); + envelope.setDmAttachmentSize(xml.text().toLongLong()); + } + } + xml.readNext(); + } + return envelope; +} + +QByteArray Xml::xmlCreateGetMessageListSoapRequest( + enum Messages::MessageType msgDirect, uint dmStatusFilter, uint dmOffset, + uint dmLimit) +{ + QString xmlContent; + if (Messages::TYPE_RECEIVED == msgDirect) { + xmlContent.append(""); + + if (Messages::TYPE_RECEIVED == msgDirect) { + xmlContent.append(""); + } else { + xmlContent.append(""); + } + + xmlContent.append(QString("%1").arg(dmStatusFilter)); + xmlContent.append(QString("%1").arg(dmOffset)); + xmlContent.append(QString("%1").arg(dmLimit)); + + if (Messages::TYPE_RECEIVED == msgDirect) { + xmlContent.append(""); + } else { + xmlContent.append(""); + } + + return Xml::xmlCreateSoapEnvelopeHeader(xmlContent); +} + +QList Xml::parseGetListOfMessagesResponse( + const QByteArray &xmlData, QString &txt) +{ + if (!parseDmStatusFromXml(xmlData, txt)) { + return QList(); + } + + QList envelopes; + QXmlStreamReader xml; + xml.addData(xmlData); + + while(!xml.atEnd() && !xml.hasError()){ + QXmlStreamReader::TokenType token = xml.readNext(); + if (token == QXmlStreamReader::StartDocument) { + continue; + } + if (token == QXmlStreamReader::StartElement) { + if (xml.name() == "dmRecord") { + envelopes.append(parseMessageEnvelope(xml)); + } + } + } + return envelopes; +} diff --git a/src/xml/xml_download_message_list.h b/src/xml/xml_download_message_list.h new file mode 100644 index 0000000000000000000000000000000000000000..8087ea183674ba6b7d41a4dc64a88a7973fb8d72 --- /dev/null +++ b/src/xml/xml_download_message_list.h @@ -0,0 +1,57 @@ +/* + * 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 . + * + * 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 +#include +#include + +#include "src/datovka_shared/isds/message_interface.h" +#include "src/messages.h" + +namespace Xml { + + /*! + * @brief Create get message list soap request. + * + * @param[in] msgDirect Message orientation. + * @param[in] dmStatusFilter Message filter (see ISDS manual). + * @param[in] dmOffset Message offset (see ISDS manual). + * @param[in] dmLimit Message limit to by downloaded. + * @return Soap request string as byte array. + */ + QByteArray xmlCreateGetMessageListSoapRequest( + enum Messages::MessageType msgDirect, uint dmStatusFilter, + uint dmOffset, uint dmLimit); + + /*! + * @brief Parse getListOfMessagesResponse XML. + * + * @param[in] xmlData Xml Data for parsing. + * @param[out] txt Error description if something failed. + * @return List of message envelope. + */ + QList parseGetListOfMessagesResponse( + const QByteArray &xmlData, QString &txt); +} diff --git a/src/xml/xml_isds_const.h b/src/xml/xml_isds_const.h new file mode 100644 index 0000000000000000000000000000000000000000..2eb44074e266f6fdbf97e217a74f9727050232dc --- /dev/null +++ b/src/xml/xml_isds_const.h @@ -0,0 +1,29 @@ +/* + * 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 . + * + * 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 + +/* XML SOAP envelope constants */ +#define XML_VERSION_ENCODING "" +#define XML_ENVELOPE_HEADER "" +#define XML_ENVELOPE_FOOTER "" diff --git a/src/xml/xml_mark_message_as_read.cpp b/src/xml/xml_mark_message_as_read.cpp new file mode 100644 index 0000000000000000000000000000000000000000..81097742332699ad795bc47e237cd4d95728439e --- /dev/null +++ b/src/xml/xml_mark_message_as_read.cpp @@ -0,0 +1,36 @@ +/* + * 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 . + * + * 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/net/isds_const.h" +#include "src/xml/xml_base.h" +#include "src/xml/xml_mark_message_as_read.h" + +QByteArray Xml::xmlCreateMarkMessageAsDownloadedSoapRequest(qint64 msgId) +{ + QString xmlContent(""); + xmlContent.append(QString::number(msgId)); + xmlContent.append(""); + return Xml::xmlCreateSoapEnvelopeHeader(xmlContent); +} diff --git a/src/xml/xml_mark_message_as_read.h b/src/xml/xml_mark_message_as_read.h new file mode 100644 index 0000000000000000000000000000000000000000..43d30d6327a3322a202fee5320e45fd99f2a7ae6 --- /dev/null +++ b/src/xml/xml_mark_message_as_read.h @@ -0,0 +1,37 @@ +/* + * 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 . + * + * 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 + +namespace Xml { + + /*! + * @brief Create mark message as downloaded soap request. + * + * @param[in] msgId Message ID. + * @return Soap request string as byte array. + */ + QByteArray xmlCreateMarkMessageAsDownloadedSoapRequest(qint64 msgId); +} diff --git a/src/xml/xml_parse_zfo.cpp b/src/xml/xml_parse_zfo.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a03dedeae6159d451ecc557cc4ac3edb4e448f69 --- /dev/null +++ b/src/xml/xml_parse_zfo.cpp @@ -0,0 +1,37 @@ +/* + * 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 . + * + * 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/xml/xml_base.h" +#include "src/xml/xml_download_message.h" +#include "src/xml/xml_parse_zfo.h" + +Isds::Message Xml::parseZfo(const QByteArray &zfoContent) +{ + qDebug("%s()", __func__); + + QByteArray soap = Xml::getXmlFromCms(zfoContent); + if (soap.isNull()) { + return Isds::Message(); + } + return Xml::parseCompleteMessage(soap); +} diff --git a/src/xml/xml_parse_zfo.h b/src/xml/xml_parse_zfo.h new file mode 100644 index 0000000000000000000000000000000000000000..cbee6cbc6037c97ffd4f3beb9f0a270d5b95c3f0 --- /dev/null +++ b/src/xml/xml_parse_zfo.h @@ -0,0 +1,40 @@ +/* + * 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 . + * + * 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 +#include + +#include "src/datovka_shared/isds/message_interface.h" + +namespace Xml { + + /*! + * @brief Parse ZFO file data. + * + * @param[in] zfoContent ZFO content for parsing. + * @return Message structure if success. + */ + Isds::Message parseZfo(const QByteArray &zfoContent); +} diff --git a/src/xml/xml_send_message.cpp b/src/xml/xml_send_message.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9f739c720696ce2ec321363795bbf4037c022c1e --- /dev/null +++ b/src/xml/xml_send_message.cpp @@ -0,0 +1,202 @@ +/* + * 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 . + * + * 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 + +#include "src/datovka_shared/isds/type_conversion.h" +#include "src/isds/isds_type_conversion.h" +#include "src/net/isds_const.h" +#include "src/xml/xml_base.h" +#include "src/xml/xml_send_message.h" + +QByteArray Xml::xmlCreateSendMessageSoapRequest(const Isds::Message &message) +{ + QString xmlContent(""); + + if (message.envelope().dmType().isNull()) { + xmlContent.append(""); + } else { + xmlContent.append(""); + } + xmlContent.append(""); + xmlContent.append(""); + xmlContent.append(message.envelope().dbIDRecipient()); + xmlContent.append(""); + xmlContent.append(""); + if (message.envelope().dmToHands().isEmpty()) { + xmlContent.append(""); + } else { + xmlContent.append(""); + xmlContent.append(message.envelope().dmToHands()); + xmlContent.append(""); + } + xmlContent.append(""); + xmlContent.append(message.envelope().dmAnnotation()); + xmlContent.append(""); + if (message.envelope().dmRecipientRefNumber().isEmpty()) { + xmlContent.append(""); + } else { + xmlContent.append(""); + xmlContent.append(message.envelope().dmRecipientRefNumber()); + xmlContent.append(""); + } + if (message.envelope().dmSenderRefNumber().isEmpty()) { + xmlContent.append(""); + } else { + xmlContent.append(""); + xmlContent.append(message.envelope().dmSenderRefNumber()); + xmlContent.append(""); + } + if (message.envelope().dmRecipientIdent().isEmpty()) { + xmlContent.append(""); + } else { + xmlContent.append(""); + xmlContent.append(message.envelope().dmRecipientIdent()); + xmlContent.append(""); + } + if (message.envelope().dmSenderIdent().isEmpty()) { + xmlContent.append(""); + } else { + xmlContent.append(""); + xmlContent.append(message.envelope().dmSenderIdent()); + xmlContent.append(""); + } + if (message.envelope().dmLegalTitleLawStr().isEmpty()) { + xmlContent.append(""); + } else { + xmlContent.append(""); + xmlContent.append(message.envelope().dmLegalTitleLawStr()); + xmlContent.append(""); + } + if (message.envelope().dmLegalTitleYearStr().isEmpty()) { + xmlContent.append(""); + } else { + xmlContent.append(""); + xmlContent.append(message.envelope().dmLegalTitleYearStr()); + xmlContent.append(""); + } + if (message.envelope().dmLegalTitleSect().isEmpty()) { + xmlContent.append(""); + } else { + xmlContent.append(""); + xmlContent.append(message.envelope().dmLegalTitleSect()); + xmlContent.append(""); + } + if (message.envelope().dmLegalTitlePar().isEmpty()) { + xmlContent.append(""); + } else { + xmlContent.append(""); + xmlContent.append(message.envelope().dmLegalTitlePar()); + xmlContent.append(""); + } + if (message.envelope().dmLegalTitlePoint().isEmpty()) { + xmlContent.append(""); + } else { + xmlContent.append(""); + xmlContent.append(message.envelope().dmLegalTitlePoint()); + xmlContent.append(""); + } + xmlContent.append(""); + xmlContent.append(Isds::boolType2Str( + message.envelope().dmPersonalDelivery())); + xmlContent.append(""); + + xmlContent.append(""); + xmlContent.append(Isds::boolType2Str( + message.envelope().dmAllowSubstDelivery())); + xmlContent.append(""); + + xmlContent.append(""); + xmlContent.append(Isds::boolType2Str(message.envelope().dmOVM())); + xmlContent.append(""); + + xmlContent.append(""); + xmlContent.append(Isds::boolType2Str( + message.envelope().dmPublishOwnID())); + xmlContent.append(""); + + xmlContent.append(""); + + xmlContent.append(""); + foreach (const Isds::Document &document, message.documents()) { + xmlContent.append(""); + xmlContent.append(""); + xmlContent.append(document.base64Content()); + xmlContent.append(""); + xmlContent.append(""); + } + xmlContent.append(""); + + xmlContent.append(""); + + return Xml::xmlCreateSoapEnvelopeHeader(xmlContent); +} + +qint64 Xml::parseSentMessageStatusFromXml(const QByteArray &xmlData, + QString &dmStatusMessage) +{ + qint64 msgId = -1; + QXmlStreamReader xml; + xml.addData(xmlData); + QString dmStatusCode = "-1"; + + while (!xml.atEnd() && !xml.hasError()) { + QXmlStreamReader::TokenType token = xml.readNext(); + if (token == QXmlStreamReader::StartDocument) { + continue; + } + if (token == QXmlStreamReader::StartElement) { + if (xml.name() == "dmStatus") { + /* Parse first part of xml response */ + while (!(xml.tokenType() == QXmlStreamReader::EndElement + && xml.name() == "dmStatus")) { + if (xml.tokenType() == + QXmlStreamReader::StartElement) { + if (xml.name() == "dmStatusCode") { + xml.readNext(); + dmStatusCode = + xml.text().toString(); + } else if (xml.name() == "dmStatusMessage") { + xml.readNext(); + dmStatusMessage = xml.text().toString(); + } + } + xml.readNext(); + } + } + if (xml.name() == "dmID") { + xml.readNext(); + msgId = xml.text().toLongLong(); + } + } + } + return msgId; +} diff --git a/src/xml/xml_send_message.h b/src/xml/xml_send_message.h new file mode 100644 index 0000000000000000000000000000000000000000..745fb36debe2f53ef1cab6b3751d9d0abd457198 --- /dev/null +++ b/src/xml/xml_send_message.h @@ -0,0 +1,50 @@ +/* + * 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 . + * + * 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 +#include + +#include "src/datovka_shared/isds/message_interface.h" + +namespace Xml { + + /*! + * @brief Create send message soap request. + * + * @param[in] message Message data. + * @return Soap request string as byte array. + */ + QByteArray xmlCreateSendMessageSoapRequest(const Isds::Message &message); + + /*! + * @brief Parse send message status and message ID from XML response. + * + * @param[in] xmlData Xml data for parsing. + * @param[out] dmStatusMessage Status or error info if something failed. + * @return Message ID if operation was successed or -1. + */ + qint64 parseSentMessageStatusFromXml(const QByteArray &xmlData, + QString &dmStatusMessage); +}