task_send_sms.cpp 2.61 KB
Newer Older
1
/*
2
 * Copyright (C) 2014-2019 CZ.NIC
3 4 5 6 7 8 9 10
 *
 * 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
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 13 14
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17 18 19 20 21 22 23
 *
 * 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.
 */

24 25
#include <QThread>

26
#include "src/datovka_shared/log/log.h"
27 28
#include "src/net/isds_const.h"
#include "src/worker/task_send_sms.h"
29 30
#include "src/xml/xml_base.h"
#include "src/xml/xml_login.h"
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

TaskSendSMS::TaskSendSMS(IsdsSession::IsdsContext &ctx, NetLayer *netLayer)
    : m_result(DL_ERR),
    m_ctx(ctx),
    m_netLayer(netLayer)
{
}

void TaskSendSMS::run(void)
{
	if (Q_NULLPTR == m_netLayer) {
		Q_ASSERT(0);
		return;
	}

	/* ### Worker task begin. ### */

48 49
	logDebugLv0NL("%s", "-----------------SEND SMS TASK-----------------");
	logDebugLv0NL("Starting in thread '%p'", QThread::currentThreadId());
50 51 52

	m_result = sendSMS(m_ctx, m_netLayer);

53 54
	logDebugLv0NL("Finished in thread '%p'", QThread::currentThreadId());
	logDebugLv0NL("%s", "-----------------------------------------------");
55

56
	/* ### Worker task end. ### */
57 58 59 60 61 62
}

enum TaskSendSMS::Result TaskSendSMS::sendSMS(
    IsdsSession::IsdsContext &ctx, NetLayer *netLayer)
{
	if (ctx.username.isEmpty()) {
63
		logErrorNL("%s", "Account user name missing!");
64 65 66 67
		Q_ASSERT(0);
		return DL_ERR;
	}

68 69 70
	logDebugLv1NL("Sending SMS for account '%s'",
	    ctx.account_name.toUtf8().constData());

71 72 73
	QByteArray xmlDataOut;

	/* Send SOAP request */
74
	if (!netLayer->createChangePwdRequest(ctx, OTP_CHNG_PWD_SERVICE,
75
	    Xml::xmlCreateSendSMSSoapRequest(), xmlDataOut)) {
76 77
		logErrorNL("ISDS returns: '%s'",
		     ctx.last_isds_msg.toUtf8().constData());
78 79 80 81
		return DL_ISDS_ERROR;
	}

	/* Parse SOAP response */
82
	if (!Xml::parseDbStatusFromXml(xmlDataOut, ctx.last_isds_msg)) {
83 84
		logErrorNL("ISDS returns: '%s'",
		     ctx.last_isds_msg.toUtf8().constData());
85 86 87
		return DL_XML_ERROR;
	}

88 89
	logDebugLv1NL("%s", "SMS has been sent");

90 91
	return DL_SUCCESS;
}