Commit 0ba311ff authored by Martin Straka's avatar Martin Straka

Added get message list task and download complete message task

parent f8ebb5ba
......@@ -118,7 +118,11 @@ SOURCES += \
src/sqlite/file_db.cpp \
src/sqlite/message_db_container.cpp \
src/sqlite/message_db.cpp \
src/worker/pool.cpp
src/worker/pool.cpp \
src/worker/task.cpp \
src/worker/task_download_message.cpp \
src/worker/task_download_message_list.cpp \
src/worker/task_keep_alive.cpp
HEADERS += \
src/accounts.h \
......@@ -157,7 +161,11 @@ HEADERS += \
src/sqlite/file_db.h \
src/sqlite/message_db_container.h \
src/sqlite/message_db.h \
src/worker/pool.h
src/worker/pool.h \
src/worker/task.h \
src/worker/task_download_message.h \
src/worker/task_download_message_list.h \
src/worker/task_keep_alive.h
android {
SOURCES += \
......
......@@ -79,5 +79,19 @@
#define OTP_ERROR_NOT_SEND "authentication.info.totpNotSended"
#define OTP_ERROR_NOT_ORDERED "authentication.info.totpNotOrdered"
/*!
* @brief Maximum length of message list to be downloaded.
*/
#define MESSAGE_LIST_LIMIT 100000
/*!
* @brief ISDS filter value to download only newer messages.
*/
#define DOWNLOAD_NEW_MESSAGES 1022
/*!
* @brief ISDS filter value to download all messages (include long term storage).
*/
#define DOWNLOAD_ALL_MESSAGES 2046
#endif // _ISDS_CONST_H_
......@@ -28,6 +28,10 @@
#include "src/models/accountmodel.h"
#include "src/models/messagemodel.h"
#include "src/settings.h"
#include "src/worker/task_download_message.h"
#include "src/worker/task_download_message_list.h"
#include "src/worker/task_keep_alive.h"
IsdsWrapper::IsdsWrapper(QObject *parent)
: QObject(parent),
......@@ -81,6 +85,8 @@ bool IsdsWrapper::syncOneAccount(const QVariant &acntModelVariant,
bool IsdsWrapper::syncSingleAccountReceived(const QVariant &acntModelVariant,
const QVariant &msgModelVariant, const QString &userName)
{
qDebug("%s()", __func__);
if (userName.isEmpty()) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Error"), tr("Empty user name"), tr("Internal error"));
......@@ -96,12 +102,20 @@ bool IsdsWrapper::syncSingleAccountReceived(const QVariant &acntModelVariant,
emit statusBarTextChanged(tr("%1: downloading received").arg(userName),
true, true);
QList<qint64> receivedMsgIds;
TaskDownloadMessageList *task;
task = new (std::nothrow) TaskDownloadMessageList(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, &m_dbWrapper,
Messages::TYPE_RECEIVED,
(globSet.downloadOnlyNewMsgs) ? DOWNLOAD_NEW_MESSAGES : DOWNLOAD_ALL_MESSAGES,
1, MESSAGE_LIST_LIMIT);
task->setAutoDelete(false);
m_workPool.runSingle(task);
QList<qint64> receivedMsgIds = task->m_msgIds;
bool success = TaskDownloadMessageList::DL_SUCCESS == task->m_result;
delete task;
/* I don't like the following function. */
if (!m_xmlLayer.isdsGetReceivedMessageList(
m_isdsSession.isdsCtxMap[userName],
globSet.downloadOnlyNewMsgs, receivedMsgIds)) {
if (!success) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("%1: received messages").arg(userName),
tr("Failed to download list of received messages for user name '%1'.").arg(userName),
......@@ -120,8 +134,14 @@ bool IsdsWrapper::syncSingleAccountReceived(const QVariant &acntModelVariant,
}
foreach (qint64 msgId, receivedMsgIds) {
downloadMessage(messageModel, userName,
MessageDb::TYPE_RECEIVED, msgId);
TaskDownloadMessage *task;
task = new (std::nothrow) TaskDownloadMessage(
m_isdsSession.isdsCtxMap[userName], &m_netLayer,
&m_dbWrapper, msgId,
Messages::TYPE_RECEIVED, messageModel);
task->setAutoDelete(true);
m_workPool.assignLo(task, WorkerPool::PREPEND);
}
}
......@@ -141,7 +161,7 @@ bool IsdsWrapper::syncSingleAccountReceived(const QVariant &acntModelVariant,
}
}
return true;
return success;
}
bool IsdsWrapper::syncSingleAccountSent(const QVariant &acntModelVariant,
......@@ -162,11 +182,20 @@ bool IsdsWrapper::syncSingleAccountSent(const QVariant &acntModelVariant,
emit statusBarTextChanged(tr("%1: downloading sent").arg(userName),
true, true);
QList<qint64> sentMsgIds;
TaskDownloadMessageList *task;
task = new (std::nothrow) TaskDownloadMessageList(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, &m_dbWrapper,
Messages::TYPE_SENT,
(globSet.downloadOnlyNewMsgs) ? DOWNLOAD_NEW_MESSAGES : DOWNLOAD_ALL_MESSAGES,
1, MESSAGE_LIST_LIMIT);
task->setAutoDelete(false);
m_workPool.runSingle(task);
if (!m_xmlLayer.isdsGetSentMessageList(
m_isdsSession.isdsCtxMap[userName],
globSet.downloadOnlyNewMsgs, sentMsgIds)) {
QList<qint64> sentMsgIds = task->m_msgIds;
bool success = TaskDownloadMessageList::DL_SUCCESS == task->m_result;
delete task;
if (!success) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("%1: sent messages").arg(userName),
tr("Failed to download list of sent messages for user name %1.").arg(userName),
......@@ -185,8 +214,14 @@ bool IsdsWrapper::syncSingleAccountSent(const QVariant &acntModelVariant,
}
foreach (qint64 msgId, sentMsgIds) {
downloadMessage(messageModel, userName,
MessageDb::TYPE_SENT, msgId);
TaskDownloadMessage *task;
task = new (std::nothrow) TaskDownloadMessage(
m_isdsSession.isdsCtxMap[userName], &m_netLayer,
&m_dbWrapper, msgId,
Messages::TYPE_SENT, messageModel);
task->setAutoDelete(true);
m_workPool.assignHi(task);
}
}
......@@ -206,12 +241,13 @@ bool IsdsWrapper::syncSingleAccountSent(const QVariant &acntModelVariant,
}
}
return true;
return success;
}
bool IsdsWrapper::getAccountInfo(const QString &userName, bool isFirstLogin)
{
qDebug("%s()", __func__);
bool success = true;
QString errTxt = tr("Wrong username");
......@@ -495,14 +531,20 @@ void IsdsWrapper::downloadMessage(MessageListModel *messageModel,
emit statusBarTextChanged(tr("Downloading message %1").
arg(QString::number(msgId)), true, true);
bool success = false;
if (messageType == MessageDb::TYPE_RECEIVED) {
/*
* NOTE: Method isdsGetCompleteMsgWithoutCms() is obsolete
* according ISDS specification. Not used now.
* The isdsGetCompleteReceivedMsgWithCms() method is used.
*/
if (!m_xmlLayer.isdsGetCompleteReceivedMsgWithCms(
m_isdsSession.isdsCtxMap[userName], msgId)) {
TaskDownloadMessage *task;
task = new (std::nothrow) TaskDownloadMessage(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, &m_dbWrapper,
msgId, Messages::TYPE_RECEIVED, messageModel);
task->setAutoDelete(false);
m_workPool.runSingle(task);
success = TaskDownloadMessage::DL_SUCCESS == task->m_result;
delete task;
if (!success) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Downloading message: %1").arg(userName),
tr("Failed to download complete received message %1.").arg(msgId),
......@@ -510,8 +552,18 @@ void IsdsWrapper::downloadMessage(MessageListModel *messageModel,
return;
}
} else {
if (!m_xmlLayer.isdsGetCompleteSentMsgWithCms(
m_isdsSession.isdsCtxMap[userName], msgId)) {
TaskDownloadMessage *task;
task = new (std::nothrow) TaskDownloadMessage(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, &m_dbWrapper,
msgId, Messages::TYPE_SENT, messageModel);
task->setAutoDelete(false);
m_workPool.runSingle(task);
success = TaskDownloadMessage::DL_SUCCESS == task->m_result;
delete task;
if (!success) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Downloading message: %1").arg(userName),
tr("Failed to download complete sent message %1.").arg(msgId),
......@@ -520,11 +572,6 @@ void IsdsWrapper::downloadMessage(MessageListModel *messageModel,
}
}
/* Downloading complete message succeeded. */
if (messageModel != Q_NULLPTR) {
messageModel->overrideDownloaded(msgId, true);
}
m_xmlLayer.isdsGetMsgAuthorInfo(m_isdsSession.isdsCtxMap[userName], msgId);
m_xmlLayer.isdsMarkMsgAsDownloaded(m_isdsSession.isdsCtxMap[userName],
msgId);
......
......@@ -26,6 +26,7 @@
#include <QObject>
#include "src/net/isds_const.h"
#include "src/net/isds_session.h"
#include "src/net/xml_layer.h"
#include "src/worker/pool.h"
......@@ -250,12 +251,18 @@ private:
bool loginToIsds(IsdsSession::IsdsContext &ctx);
/*!
* @brief Instance of XmlLayer class (xml_layer.h).
* @brief Instance of DbWrapper class (db_wrapper.h).
*
* Class IsdsSession realizes XML layer over netmanager.
* Creates SOAP envelopes of services and parse SOAP responses.
* Object DbWrapper stores response data to database.
*/
XmlLayer m_xmlLayer;
DbWrapper m_dbWrapper;
/*!
* @brief Instance of NetLayer class (net_layer.h).
*
* Object NetLayer realizes POST/GET requests and net management.
*/
NetLayer m_netLayer;
/*!
* @brief Instance of IsdsSession class (isds_session.h).
......@@ -268,6 +275,12 @@ private:
* @brief Worker pool instance.
*/
WorkerPool m_workPool;
/*!
* TODO - will be removed in the future.
*/
XmlLayer m_xmlLayer;
};
#endif // _ISDS_WRAPPER_H_
......@@ -192,6 +192,39 @@ bool XmlLayer::isdsGetReceivedMessageList(IsdsSession::IsdsContext &ctx,
ctx.last_isds_msg);
}
QByteArray XmlLayer::xmlCreateGetMessageListSoapRequest(
enum Messages::MessageType msgDirect, uint dmStatusFilter, uint dmOffset,
uint dmLimit)
{
QString xmlBodyContent;
if (Messages::TYPE_RECEIVED == msgDirect) {
xmlBodyContent.append("<GetListOfReceivedMessages xmlns=\"");
} else {
xmlBodyContent.append("<GetListOfSentMessages xmlns=\"");
}
xmlBodyContent.append(ISDS_NS);
xmlBodyContent.append("\"><dmFromTime/><dmToTime/>");
if (Messages::TYPE_RECEIVED == msgDirect) {
xmlBodyContent.append("<dmRecipientOrgUnitNum/>");
} else {
xmlBodyContent.append("<dmSenderOrgUnitNum/>");
}
xmlBodyContent.append(QString("<dmStatusFilter>%1</dmStatusFilter>").arg(dmStatusFilter));
xmlBodyContent.append(QString("<dmOffset>%1</dmOffset>").arg(dmOffset));
xmlBodyContent.append(QString("<dmLimit>%1</dmLimit>").arg(dmLimit));
if (Messages::TYPE_RECEIVED == msgDirect) {
xmlBodyContent.append("</GetListOfReceivedMessages>");
} else {
xmlBodyContent.append("</GetListOfSentMessages>");
}
return createEnvelope(xmlBodyContent);
}
bool XmlLayer::isdsGetSentMessageList(IsdsSession::IsdsContext &ctx,
bool only90Days, QList<qint64> &msgIds)
{
......@@ -278,6 +311,31 @@ bool XmlLayer::isdsGetCompleteMsgWithoutCms(IsdsSession::IsdsContext &ctx,
fileList, ctx.last_isds_msg);
}
QByteArray XmlLayer::xmlCreateDownloadMessageSoapRequest(qint64 msgID,
enum Messages::MessageType msgDirect)
{
QString xmlBodyContent;
if (Messages::TYPE_RECEIVED == msgDirect) {
xmlBodyContent.append("<SignedMessageDownload xmlns=\"");
} else {
xmlBodyContent.append("<SignedSentMessageDownload xmlns=\"");
}
xmlBodyContent.append(ISDS_NS);
xmlBodyContent.append("\"><dmID>");
xmlBodyContent.append(QString::number(msgID));
xmlBodyContent.append("</dmID>");
if (Messages::TYPE_RECEIVED == msgDirect) {
xmlBodyContent.append("</SignedMessageDownload>");
} else {
xmlBodyContent.append("</SignedSentMessageDownload>");
}
return createEnvelope(xmlBodyContent);
}
bool XmlLayer::isdsGetCompleteReceivedMsgWithCms(IsdsSession::IsdsContext &ctx,
qint64 msgID)
{
......
......@@ -94,6 +94,16 @@ public:
bool isdsGetReceivedMessageList(IsdsSession::IsdsContext &ctx,
bool only90Days, QList<qint64> &msgIds);
static
QByteArray xmlCreateGetMessageListSoapRequest(
enum Messages::MessageType msgDirect, uint dmStatusFilter,
uint dmOffset, uint dmLimit);
static
QByteArray xmlCreateDownloadMessageSoapRequest(qint64 msgID,
enum Messages::MessageType msgDirect);
/*!
* @brief Get list of outcoming (addressed from you) messages.
*
......@@ -211,6 +221,7 @@ public:
* @param[out] fileList List of files structure.
* @return true if success.
*/
static
bool completeMessageParse(QXmlStreamReader &xml, Messages::Message &msg,
QList<Files::File> &fileList);
......@@ -220,16 +231,16 @@ public:
* @param[in] xml Xml data for parsing.
* @return Event structure.
*/
static
Messages::Event parseEvent(QXmlStreamReader &xml);
private:
/*!
* @brief Create xml envelope.
*
* @param[in] xmlBodyContent Content body.
* @return Xml bytearray with envelope.
*/
static
QByteArray createEnvelope(const QString &xmlBodyContent);
/*!
......@@ -238,6 +249,7 @@ private:
* @param[in] userName Account username.
* @return true if success.
*/
static
QString getFileSizeFromBase64(int fileLen);
/*!
......@@ -246,6 +258,7 @@ private:
* @param[in] fileName Filename with ext.
* @return true icon filename.
*/
static
QString getFileIconFromFileName(QString fileName);
/*!
......@@ -255,6 +268,7 @@ private:
* @param[out] txt Error description if something failed.
* @return true if login success.
*/
static
bool parseDmStatusFromXml(const QByteArray &xmlData, QString &txt);
/*!
......@@ -264,6 +278,7 @@ private:
* @param[out] txt Error description if something failed.
* @return true if login success.
*/
static
bool parseDbStatusFromXml(const QByteArray &xmlData, QString &txt);
/*!
......@@ -273,6 +288,7 @@ private:
* @param[out] txt Error description if something failed.
* @return true if login success.
*/
static
bool parseLoginResponse(const QByteArray &xmlData, QString &txt);
/*!
......@@ -283,6 +299,7 @@ private:
* @param[out] txt Error description if something failed.
* @return true if success.
*/
static
bool parseGetListOfMessagesResponse(enum MessageDb::MessageType messageType,
const QByteArray &xmlData, QList<Messages::Message> &messages,
QString &txt);
......@@ -296,6 +313,7 @@ private:
* @param[out] txt Error description if something failed.
* @return true if success.
*/
static
bool parseMessageDownloadResponse(const QByteArray &xmlData,
Messages::Message &msg, QList<Files::File> &fileList, QString &txt);
......@@ -308,6 +326,7 @@ private:
* @param[out] txt Error description if something failed.
* @return true if success.
*/
static
bool parseSignedMessageDownloadResponse(const QByteArray &xmlData,
Messages::Message &msg, QList<Files::File> &fileList, QString &txt);
......@@ -319,6 +338,7 @@ private:
* @param[out] txt Error description if something failed.
* @return true if success.
*/
static
bool parseGetOwnerInfoFromLogin(const QByteArray &xmlData,
DbWrapper::AccountInfo &accountInfo, QString &txt);
......@@ -330,6 +350,7 @@ private:
* @param[out] txt Error description if something failed.
* @return true if success.
*/
static
bool parseGetUserInfoFromLogin(const QByteArray &xmlData,
DbWrapper::UserInfo &userInfo, QString &txt);
......@@ -341,6 +362,7 @@ private:
* @param[out] txt Error description if something failed.
* @return true if success.
*/
static
bool parseGetPasswordInfo(const QByteArray &xmlData,
QString &expirDate, QString &txt);
......@@ -351,6 +373,7 @@ private:
* @param[out] accountInfo Account info structures.
* @return true if success.
*/
static
bool dbOwnerInfoParse(QXmlStreamReader &xml,
DbWrapper::AccountInfo &accountInfo);
......@@ -362,6 +385,7 @@ private:
* @param[out] txt Error description if something failed.
* @return true if success.
*/
static
bool dbUserInfoParse(QXmlStreamReader &xml,
DbWrapper::UserInfo &userInfo);
......@@ -374,6 +398,7 @@ private:
* @param[out] txt Error description if something failed.
* @return true if success.
*/
static
bool parseGetAuthorInfo(const QByteArray &xmlData, QString &userType,
QString &authorName, QString &txt);
......@@ -385,6 +410,7 @@ private:
* @param[out] txt Error description if something failed.
* @return true if success.
*/
static
bool parseGetMsgDeliveryInfoResponse(const QByteArray &xmlData,
QList<Messages::Event> &eventList, QString &txt);
......@@ -396,6 +422,7 @@ private:
* @param[out] txt Error description if something failed.
* @return true if success.
*/
static
bool parseGetSignedMsgDeliveryInfoResponse(const QByteArray &xmlData,
QList<Messages::Event> &eventList, QString &txt);
......@@ -406,6 +433,7 @@ private:
* @param[in] messageType Message type.
* @return Message envelope structure.
*/
static
Messages::Message msgEnvelopeParse(QXmlStreamReader &xml,
enum MessageDb::MessageType messageType);
......@@ -417,6 +445,7 @@ private:
* @param[in] downloadDate Datetime when complete message was downloaded.
* @return File structure.
*/
static
Files::File parseFile(QXmlStreamReader &xml, const qint64 msgId,
const QString &downloadDate);
......
......@@ -108,7 +108,7 @@ void WorkerPool::wait(void)
void WorkerPool::assignLo(QRunnable *task, enum WorkerPool::EnqueueOrder order)
{
if (0 == task) {
if (Q_NULLPTR == task) {
return;
}
......@@ -124,7 +124,7 @@ void WorkerPool::assignLo(QRunnable *task, enum WorkerPool::EnqueueOrder order)
void WorkerPool::assignHi(QRunnable *task, enum WorkerPool::EnqueueOrder order)
{
if (0 == task) {
if (Q_NULLPTR == task) {
return;
}
......@@ -140,7 +140,7 @@ void WorkerPool::assignHi(QRunnable *task, enum WorkerPool::EnqueueOrder order)
void WorkerPool::runSingle(QRunnable *task)
{
if (0 == task) {
if (Q_NULLPTR == task) {
return;
}
......@@ -200,7 +200,7 @@ bool WorkerPool::working(void)
void WorkerPool::run(WorkerPool *pool)
{
Q_ASSERT(0 != pool);
Q_ASSERT(Q_NULLPTR != pool);
pool->m_lock.lock();
......@@ -209,7 +209,7 @@ void WorkerPool::run(WorkerPool *pool)
break;
}
QRunnable *task = 0;
QRunnable *task = Q_NULLPTR;
if (!pool->m_suspended) {
if ((0 != pool->m_singleTask) && (PENDING == pool->m_singleState)) {
task = pool->m_singleTask;
......
/*
* Copyright (C) 2014-2015 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#include <cinttypes>
#include "src/worker/task.h"
/*
* 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 <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#ifndef _TASK_H_
#define _TASK_H_
#include <QRunnable>
#include <QString>
/*!
* @brief This class contains generic functions that can be used in derived
* classes.
*/
class Task : public QRunnable {
public:
/*!
* @brief Method to be implemented in derived classes.
*/
virtual
void run(void) = 0;
};
#endif /* _TASK_H_ */
/*
* 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 <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#include "src/log/log.h"
#include "src/net/isds_const.h"
#include "src/net/xml_layer.h"
#include "src/worker/pool.h" /* List with whole messages. */
#include "src/worker/task_download_message.h"
#include "src/sqlite/message_db_container.h"
TaskDownloadMessage::TaskDownloadMessage(IsdsSession::IsdsContext &ctx,
NetLayer *netLayer, DbWrapper *dbWrapper, qint64 msgId,
enum Messages::MessageType msgDirect, MessageListModel *messageModel)
: m_result(DL_ERR),
m_ctx(ctx),
m_netLayer(netLayer),
m_dbWrapper(dbWrapper),
m_msgId(msgId),
m_msgDirect(msgDirect),
m_messageModel(messageModel)
{
}
void TaskDownloadMessage::run(void)
{
if (Q_NULLPTR == m_netLayer) {
Q_ASSERT(0);
return;
}
if (Q_NULLPTR == m_dbWrapper) {
Q_ASSERT(0);
return;
}
if ((Messages::TYPE_RECEIVED != m_msgDirect)
&& (Messages::TYPE_SENT != m_msgDirect)) {
Q_ASSERT(0);
return;
}
logDebugLv0NL("Starting download message task in thread '%p'",
(void *) QThread::currentThreadId());
/* ### Worker task begin. ### */
logDebugLv1NL("%s", "-----------------------------------------------");
logDebugLv1NL("Downloading %s message for account '%s'.",
(Messages::TYPE_RECEIVED == m_msgDirect) ? "received" : "sent",
m_ctx.account_name.toUtf8().constData());
logDebugLv1NL("%s", "-----------------------------------------------");
m_result = downloadMessage(m_ctx, m_netLayer, m_dbWrapper, m_msgId,
m_msgDirect, m_messageModel);
/* ### Worker task end. ### */
logDebugLv0NL("Download message task finished in thread '%p'",
(void *) QThread::currentThreadId());
}
enum TaskDownloadMessage::Result TaskDownloadMessage::downloadMessage(
IsdsSession::IsdsContext &ctx, NetLayer *netLayer, DbWrapper *dbWrapper,
qint64 msgId, enum Messages::MessageType msgDirect, MessageListModel *messageModel)
{
if (ctx.username.isEmpty()) {
Q_ASSERT(0);
return DL_ERR;
}
QByteArray xmlDataOut;
Messages::Message msg;
QList<Files::File> fileList;
/* Send SOAP request */
if (!netLayer->sendSoapRequest(ctx, LOGIN_SERVICE,
XmlLayer::xmlCreateDownloadMessageSoapRequest(msgId, msgDirect),
xmlDataOut)) {
return DL_ISDS_ERROR;
}
/* Parse SOAP response */
if (!XmlLayer::parseSignedMessageDownloadResponse(xmlDataOut, msg,
fileList, ctx.last_isds_msg)) {
return DL_XML_ERROR;
}
if (fileList.isEmpty()) {
return DL_ERR;
}
/* Store data into db */
if (!dbWrapper->insertCompleteMessageToDb(ctx.username, msg,
fileList, ctx.last_isds_msg)) {
return DL_DB_INS_ERR;
}