|
|
|
@ -6,12 +6,9 @@
|
|
|
|
|
#include "eettemplate.h"
|
|
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QFile>
|
|
|
|
|
#include <QDomNode>
|
|
|
|
|
#include <QDomDocument>
|
|
|
|
|
#include <QXmlQuery>
|
|
|
|
|
#include <QXmlResultItems>
|
|
|
|
|
#include <QNetworkConfiguration>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
|
|
const QString EetSender::ms_nsDef = "declare namespace eet = \"http://fs.mfcr.cz/eet/schema/v3\";\n"
|
|
|
|
|
"declare namespace ds = \"http://www.w3.org/2000/09/xmldsig#\";\n"
|
|
|
|
@ -20,24 +17,36 @@ const QString EetSender::ms_nsDef = "declare namespace eet = \"http://fs.mfcr.cz
|
|
|
|
|
"declare namespace senc = \"http://schemas.xmlsoap.org/soap/encoding/\";\n"
|
|
|
|
|
"declare namespace senv = \"http://schemas.xmlsoap.org/soap/envelope/\";\n";
|
|
|
|
|
|
|
|
|
|
bool EetSender::m_online = true;
|
|
|
|
|
|
|
|
|
|
EetSender::EetSender(QObject *parent) : QObject(parent)
|
|
|
|
|
{
|
|
|
|
|
m_signer = nullptr;
|
|
|
|
|
m_resut = nullptr;
|
|
|
|
|
m_checkSignature = true;
|
|
|
|
|
|
|
|
|
|
m_resut = new EetResult(this);
|
|
|
|
|
|
|
|
|
|
m_manager = new QNetworkAccessManager(this);
|
|
|
|
|
connect(m_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
|
|
|
|
|
connect(m_manager, &QNetworkAccessManager::sslErrors, [this](QNetworkReply *rep, QList<QSslError> errs){
|
|
|
|
|
emit serviceCertError();
|
|
|
|
|
connect(m_manager, &QNetworkAccessManager::sslErrors, [this](QNetworkReply *rep, QList<QSslError>){
|
|
|
|
|
m_resut->setStatus(EetResult::SSL_ERROR);
|
|
|
|
|
emit sendFinished();
|
|
|
|
|
rep->deleteLater();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
m_serviceUrl = PRODUCTION_URL;
|
|
|
|
|
m_timer = new QTimer(this);
|
|
|
|
|
m_timer->setInterval(1000);
|
|
|
|
|
m_timer->setSingleShot(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EetSender::sendRequest(EetRequest *request)
|
|
|
|
|
{
|
|
|
|
|
if (m_signer == nullptr)
|
|
|
|
|
{
|
|
|
|
|
emit certError();
|
|
|
|
|
m_resut->setStatus(EetResult::USER_CERT_ERROR);
|
|
|
|
|
emit sendFinished();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -45,6 +54,7 @@ void EetSender::sendRequest(EetRequest *request)
|
|
|
|
|
|
|
|
|
|
EetTemplate tempBody(BODY_TEMPLATE);
|
|
|
|
|
tempBody.setSigner(m_signer);
|
|
|
|
|
tempBody.setResult(m_resut);
|
|
|
|
|
QString strBody = tempBody.fillTemplate(request);
|
|
|
|
|
|
|
|
|
|
QByteArray digest = m_signer->sha256HashData(strBody.toUtf8());
|
|
|
|
@ -61,12 +71,26 @@ void EetSender::sendRequest(EetRequest *request)
|
|
|
|
|
|
|
|
|
|
QString strRequest = tempRequest.fillTemplate(val);
|
|
|
|
|
|
|
|
|
|
QNetworkRequest req(QUrl("https://pg.eet.cz/eet/services/EETServiceSOAP/v3"));
|
|
|
|
|
m_manager->post(req, strRequest.toUtf8());
|
|
|
|
|
QNetworkRequest req(QUrl(m_serviceUrl.toStdString().c_str()));
|
|
|
|
|
|
|
|
|
|
QFile file("/home/pepa/Dokumenty/dev/eet/req.xml");
|
|
|
|
|
file.open(QIODevice::WriteOnly);
|
|
|
|
|
file.write(strRequest.toUtf8());
|
|
|
|
|
qDebug() << strRequest;
|
|
|
|
|
|
|
|
|
|
if (m_online)
|
|
|
|
|
{
|
|
|
|
|
QNetworkReply *rep = m_manager->post(req, strRequest.toUtf8());
|
|
|
|
|
m_timer->start();
|
|
|
|
|
connect(m_timer, &QTimer::timeout, [this, rep](){
|
|
|
|
|
rep->abort();
|
|
|
|
|
m_resut->setStatus(EetResult::TIMEDOUT);
|
|
|
|
|
emit sendFinished();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_resut->setStatus(EetResult::OFFLINE);
|
|
|
|
|
m_timer->stop();
|
|
|
|
|
emit sendFinished();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EetSender::setupSigner(const QString &certPath, const QString &passwd)
|
|
|
|
@ -90,11 +114,21 @@ bool EetSender::checkSignature() const
|
|
|
|
|
return m_checkSignature;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EetSender::setPlayground(bool pg)
|
|
|
|
|
{
|
|
|
|
|
m_serviceUrl = (pg ? PLAYGROUND_URL : PRODUCTION_URL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EetResult *EetSender::resut() const
|
|
|
|
|
{
|
|
|
|
|
return m_resut;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EetSender::setTimeout(int timeout)
|
|
|
|
|
{
|
|
|
|
|
m_timer->setInterval(timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool EetSender::verifySignature(const QByteArray &repData)
|
|
|
|
|
{
|
|
|
|
|
QString queryString("//senv:Envelope/senv:Header/wsse:Security/ds:Signature/ds:SignedInfo");
|
|
|
|
@ -130,7 +164,7 @@ bool EetSender::verifySignature(const QByteArray &repData)
|
|
|
|
|
|
|
|
|
|
if (res != QCA::ConvertGood)
|
|
|
|
|
{
|
|
|
|
|
emit serviceCertError();
|
|
|
|
|
m_resut->setStatus(EetResult::SERVICE_CERT_ERROR);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -138,7 +172,7 @@ bool EetSender::verifySignature(const QByteArray &repData)
|
|
|
|
|
|
|
|
|
|
if (!pubKey.canVerify())
|
|
|
|
|
{
|
|
|
|
|
emit serviceCertError();
|
|
|
|
|
m_resut->setStatus(EetResult::SERVICE_CERT_ERROR);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -146,7 +180,7 @@ bool EetSender::verifySignature(const QByteArray &repData)
|
|
|
|
|
|
|
|
|
|
if (!signValid)
|
|
|
|
|
{
|
|
|
|
|
emit signInvalid();
|
|
|
|
|
m_resut->setStatus(EetResult::INVALID_SIGNATURE);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -155,38 +189,66 @@ bool EetSender::verifySignature(const QByteArray &repData)
|
|
|
|
|
|
|
|
|
|
void EetSender::replyFinished(QNetworkReply *reply)
|
|
|
|
|
{
|
|
|
|
|
m_timer->stop();
|
|
|
|
|
if (reply->error() != QNetworkReply::NoError)
|
|
|
|
|
{
|
|
|
|
|
emit sendError();
|
|
|
|
|
m_resut->setStatus(EetResult::SERVER_ERROR);
|
|
|
|
|
emit sendFinished();
|
|
|
|
|
reply->deleteLater();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QByteArray repData = reply->readAll();
|
|
|
|
|
|
|
|
|
|
/*QFile file("/home/pepa/Dokumenty/dev/eet/reply.xml");
|
|
|
|
|
file.open(QIODevice::ReadOnly);
|
|
|
|
|
repData = file.readAll();*/
|
|
|
|
|
|
|
|
|
|
if (m_checkSignature && !verifySignature(repData))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
qDebug() << QString(repData);
|
|
|
|
|
|
|
|
|
|
QXmlQuery q;
|
|
|
|
|
q.setFocus(QString(repData));
|
|
|
|
|
|
|
|
|
|
QXmlResultItems items;
|
|
|
|
|
QString result;
|
|
|
|
|
QString queryString("//senv:Envelope/senv:Body/eet:Odpoved/eet:Hlavicka/@uuid_zpravy/data(.)");
|
|
|
|
|
QString queryString = "//senv:Envelope/senv:Body/eet:Odpoved/eet:Chyba";
|
|
|
|
|
q.setQuery(ms_nsDef + queryString);
|
|
|
|
|
q.evaluateTo(&result);
|
|
|
|
|
result = result.trimmed();
|
|
|
|
|
q.evaluateTo(&items);
|
|
|
|
|
|
|
|
|
|
if (m_resut == nullptr)
|
|
|
|
|
EetMessageList errors;
|
|
|
|
|
QXmlItem item = items.next();
|
|
|
|
|
while (!item.isNull())
|
|
|
|
|
{
|
|
|
|
|
m_resut = new EetResult(this);
|
|
|
|
|
EetMessage *mesg = new EetMessage(m_resut);
|
|
|
|
|
queryString = "./@kod/data(.)";
|
|
|
|
|
q.setQuery(ms_nsDef + queryString);
|
|
|
|
|
q.setFocus(item);
|
|
|
|
|
q.evaluateTo(&result);
|
|
|
|
|
result = result.trimmed();
|
|
|
|
|
|
|
|
|
|
mesg->setCode(result.toInt());
|
|
|
|
|
|
|
|
|
|
queryString = "./string()";
|
|
|
|
|
q.setQuery(ms_nsDef + queryString);
|
|
|
|
|
q.setFocus(item);
|
|
|
|
|
q.evaluateTo(&result);
|
|
|
|
|
result = result.trimmed();
|
|
|
|
|
|
|
|
|
|
mesg->setMessage(result);
|
|
|
|
|
errors.append(mesg);
|
|
|
|
|
|
|
|
|
|
item = items.next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_resut->setErrors(errors);
|
|
|
|
|
|
|
|
|
|
if (m_checkSignature && errors.isEmpty() && !verifySignature(repData))
|
|
|
|
|
{
|
|
|
|
|
emit sendFinished();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
queryString = "//senv:Envelope/senv:Body/eet:Odpoved/eet:Hlavicka/@uuid_zpravy/data(.)";
|
|
|
|
|
q.setQuery(ms_nsDef + queryString);
|
|
|
|
|
q.evaluateTo(&result);
|
|
|
|
|
result = result.trimmed();
|
|
|
|
|
|
|
|
|
|
m_resut->setUuid(QUuid(result));
|
|
|
|
|
|
|
|
|
|
queryString = "//senv:Envelope/senv:Body/eet:Odpoved/eet:Hlavicka/@dat_prij/data(.)";
|
|
|
|
@ -201,13 +263,12 @@ void EetSender::replyFinished(QNetworkReply *reply)
|
|
|
|
|
result = result.trimmed();
|
|
|
|
|
m_resut->setFik(result);
|
|
|
|
|
|
|
|
|
|
QXmlResultItems items;
|
|
|
|
|
queryString = "//senv:Envelope/senv:Body/eet:Odpoved/eet:Varovani";
|
|
|
|
|
q.setQuery(ms_nsDef + queryString);
|
|
|
|
|
q.evaluateTo(&items);
|
|
|
|
|
|
|
|
|
|
EetMessageList warnings;
|
|
|
|
|
QXmlItem item = items.next();
|
|
|
|
|
item = items.next();
|
|
|
|
|
while (!item.isNull())
|
|
|
|
|
{
|
|
|
|
|
EetMessage *mesg = new EetMessage(m_resut);
|
|
|
|
@ -219,7 +280,7 @@ void EetSender::replyFinished(QNetworkReply *reply)
|
|
|
|
|
|
|
|
|
|
mesg->setCode(result.toInt());
|
|
|
|
|
|
|
|
|
|
queryString = "./text(.)";
|
|
|
|
|
queryString = "./string()";
|
|
|
|
|
q.setQuery(ms_nsDef + queryString);
|
|
|
|
|
q.setFocus(item);
|
|
|
|
|
q.evaluateTo(&result);
|
|
|
|
@ -233,37 +294,16 @@ void EetSender::replyFinished(QNetworkReply *reply)
|
|
|
|
|
|
|
|
|
|
m_resut->setWarnings(warnings);
|
|
|
|
|
|
|
|
|
|
queryString = "//senv:Envelope/senv:Body/eet:Odpoved/eet:Chyba";
|
|
|
|
|
q.setQuery(ms_nsDef + queryString);
|
|
|
|
|
q.evaluateTo(&items);
|
|
|
|
|
|
|
|
|
|
EetMessageList errors;
|
|
|
|
|
item = items.next();
|
|
|
|
|
while (!item.isNull())
|
|
|
|
|
if (errors.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
EetMessage *mesg = new EetMessage(m_resut);
|
|
|
|
|
queryString = "./@kod/data(.)";
|
|
|
|
|
q.setQuery(ms_nsDef + queryString);
|
|
|
|
|
q.setFocus(item);
|
|
|
|
|
q.evaluateTo(&result);
|
|
|
|
|
result = result.trimmed();
|
|
|
|
|
|
|
|
|
|
mesg->setCode(result.toInt());
|
|
|
|
|
|
|
|
|
|
queryString = "./text(.)";
|
|
|
|
|
q.setQuery(ms_nsDef + queryString);
|
|
|
|
|
q.setFocus(item);
|
|
|
|
|
q.evaluateTo(&result);
|
|
|
|
|
result = result.trimmed();
|
|
|
|
|
|
|
|
|
|
mesg->setMessage(result);
|
|
|
|
|
errors.append(mesg);
|
|
|
|
|
|
|
|
|
|
item = items.next();
|
|
|
|
|
m_resut->setReciveDate(QDateTime::currentDateTime());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_resut->setStatus(EetResult::DATA_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_resut->setErrors(errors);
|
|
|
|
|
emit responseRecieved(m_resut);
|
|
|
|
|
emit sendFinished();
|
|
|
|
|
|
|
|
|
|
reply->deleteLater();
|
|
|
|
|
}
|
|
|
|
|