Added parsing of warnings and errors.

master
Josef Rokos 8 years ago
parent 1c4976cb0b
commit f7abd0b228

@ -22,6 +22,7 @@ int main(int argc, char *argv[])
request.setRezim(EetRequest::STANDARD);
EetSender sender;
sender.setPlayground(true);
sender.setupSigner("/home/pepa/Dokumenty/dev/eet/121212.p12", "eet");
sender.sendRequest(&request);

@ -35,7 +35,10 @@ public:
{
RESPONSE_OK = 0,
DATA_ERROR,
USER_CERT_ERROR,
SERVER_ERROR,
SERVICE_CERT_ERROR,
INVALID_SIGNATURE,
SSL_ERROR,
TIMEDOUT
};

@ -5,12 +5,8 @@
#include "eetsigner.h"
#include <QDebug>
#include <QFile>
#include <QDomNode>
#include <QDomDocument>
#include <QXmlQuery>
#include <QXmlResultItems>
#include <QNetworkConfiguration>
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"
@ -25,18 +21,25 @@ EetSender::EetSender(QObject *parent) : QObject(parent)
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(m_resut);
rep->deleteLater();
});
m_serviceUrl = PRODUCTION_URL;
}
void EetSender::sendRequest(EetRequest *request)
{
if (m_signer == nullptr)
{
emit certError();
m_resut->setStatus(EetResult::USER_CERT_ERROR);
emit sendFinished(m_resut);
return;
}
@ -60,12 +63,8 @@ void EetSender::sendRequest(EetRequest *request)
QString strRequest = tempRequest.fillTemplate(val);
QNetworkRequest req(QUrl("https://pg.eet.cz/eet/services/EETServiceSOAP/v3"));
QNetworkRequest req(QUrl(m_serviceUrl.toStdString().c_str()));
m_manager->post(req, strRequest.toUtf8());
QFile file("/home/pepa/Dokumenty/dev/eet/req.xml");
file.open(QIODevice::WriteOnly);
file.write(strRequest.toUtf8());
}
void EetSender::setupSigner(const QString &certPath, const QString &passwd)
@ -89,6 +88,11 @@ 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;
@ -129,7 +133,7 @@ bool EetSender::verifySignature(const QByteArray &repData)
if (res != QCA::ConvertGood)
{
emit serviceCertError();
m_resut->setStatus(EetResult::SERVICE_CERT_ERROR);
return false;
}
@ -137,7 +141,7 @@ bool EetSender::verifySignature(const QByteArray &repData)
if (!pubKey.canVerify())
{
emit serviceCertError();
m_resut->setStatus(EetResult::SERVICE_CERT_ERROR);
return false;
}
@ -145,7 +149,7 @@ bool EetSender::verifySignature(const QByteArray &repData)
if (!signValid)
{
emit signInvalid();
m_resut->setStatus(EetResult::INVALID_SIGNATURE);
return false;
}
@ -156,19 +160,17 @@ void EetSender::replyFinished(QNetworkReply *reply)
{
if (reply->error() != QNetworkReply::NoError)
{
emit sendError();
m_resut->setStatus(EetResult::SERVER_ERROR);
emit sendFinished(m_resut);
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))
{
emit sendFinished(m_resut);
return;
}
@ -181,11 +183,6 @@ void EetSender::replyFinished(QNetworkReply *reply)
q.evaluateTo(&result);
result = result.trimmed();
if (m_resut == nullptr)
{
m_resut = new EetResult(this);
}
m_resut->setUuid(QUuid(result));
queryString = "//senv:Envelope/senv:Body/eet:Odpoved/eet:Hlavicka/@dat_prij/data(.)";
@ -262,7 +259,7 @@ void EetSender::replyFinished(QNetworkReply *reply)
}
m_resut->setErrors(errors);
emit responseRecieved(m_resut);
emit sendFinished(m_resut);
reply->deleteLater();
}

@ -8,6 +8,9 @@
#include "eettemplate.h"
#include "eetresult.h"
#define PRODUCTION_URL "https://prod.eet.cz/eet/services/EETServiceSOAP/v3"
#define PLAYGROUND_URL "https://pg.eet.cz/eet/services/EETServiceSOAP/v3"
class QNetworkAccessManager;
class QNetworkReply;
@ -23,6 +26,8 @@ public:
void setCheckSignature(bool checkSignature);
bool checkSignature() const;
void setPlayground(bool pg);
EetResult *resut() const;
private:
@ -31,6 +36,7 @@ private:
QNetworkAccessManager *m_manager;
bool m_checkSignature;
EetResult *m_resut;
QString m_serviceUrl;
bool verifySignature(const QByteArray &repData);
@ -38,11 +44,7 @@ private slots:
void replyFinished(QNetworkReply *reply);
signals:
void certError();
void sendError();
void responseRecieved(EetRequest *result);
void signInvalid();
void serviceCertError();
void sendFinished(EetResult *result);
public slots:
};

@ -4,7 +4,7 @@
#
#-------------------------------------------------
QT += network xml xmlpatterns
QT += network xmlpatterns
QT -= gui

Loading…
Cancel
Save