From 912b7852e9e0855714f7b4634b07254a3018c4a3 Mon Sep 17 00:00:00 2001 From: ericmenezesn@gmail.com Date: Mon, 11 Aug 2014 11:20:38 -0300 Subject: [PATCH] Pequenas alterações --- cacic-teste/cacic-teste.pro | 9 ++++++--- cacic-teste/testcacic.cpp | 11 +++++++++++ cacic-teste/testcacic.h | 1 + src/cacic_comm.h | 25 ++++++++++++++++++++++--- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/cacic-teste/cacic-teste.pro b/cacic-teste/cacic-teste.pro index c33fce5..8ded4a7 100644 --- a/cacic-teste/cacic-teste.pro +++ b/cacic-teste/cacic-teste.pro @@ -20,13 +20,16 @@ win32 { SOURCES += \ testcacic.cpp \ ../src/ccacic.cpp \ - ../src/cacic_computer.cpp + ../src/cacic_computer.cpp \ + ../src/sslclient.cpp HEADERS += \ testcacic.h \ ../src/ccacic.h \ ../src/cacic_computer.h \ - ../src/cacic_comm.h + ../src/cacic_comm.h \ + ../src/sslclient.h -INCLUDEPATH += ../src +INCLUDEPATH += ../src \ + ../src/crypto++/include/ diff --git a/cacic-teste/testcacic.cpp b/cacic-teste/testcacic.cpp index 7b8b0c2..1bcd2e2 100644 --- a/cacic-teste/testcacic.cpp +++ b/cacic-teste/testcacic.cpp @@ -108,6 +108,17 @@ void CTestCacic::testLogin(){ QVERIFY(!session_str.isNull()); } +void CTestCacic::testSslConnection() +{ + QVariantMap login; + login["user"] = "cacic"; + login["password"] = "cacic"; + QJsonObject json = OCacicComm.comm("/ws/get/test", QJsonObject::fromVariantMap(login), true); + QJsonValue jsonvalue = json["key"]; +// qDebug() << jsonvalue.toVariant().toString(); + QVERIFY(!jsonvalue.isNull()); +} + void CTestCacic::cleanupTestCase() { diff --git a/cacic-teste/testcacic.h b/cacic-teste/testcacic.h index 8d1ef11..a36a08d 100644 --- a/cacic-teste/testcacic.h +++ b/cacic-teste/testcacic.h @@ -45,6 +45,7 @@ private slots: void testInterfaceDeRede(); void testpegarOS(); void testLogin(); + void testSslConnection(); void cleanupTestCase(); }; diff --git a/src/cacic_comm.h b/src/cacic_comm.h index 36eaaa8..b1c3830 100644 --- a/src/cacic_comm.h +++ b/src/cacic_comm.h @@ -12,6 +12,7 @@ #include #include #include +#include class CacicComm { @@ -49,14 +50,18 @@ public: params.addQueryItem("te_so",so); params.addQueryItem("te_versao_cacic",cacicVersion); params.addQueryItem("te_versao_gercols",gercolsVersion); + + } - QJsonObject comm(QString route, const QJsonObject &json = QJsonObject()) + QJsonObject comm(QString route, const QJsonObject &json = QJsonObject(), bool isSsl = false) { QByteArray data; QUrl url = urlGerente + route; QNetworkRequest req(url); req.setHeader(QNetworkRequest::LocationHeader, "Cacic Agente"); + if (isSsl) + req.setSslConfiguration(QSslConfiguration::defaultConfiguration()); if (json.empty()) { //se não for passado QJson, será mandado os valores do get/test antigo. (Será retirado depois) @@ -79,11 +84,12 @@ public: QNetworkReply *reply = mgr.post(req, data); eventLoop.exec(); // sai do looping chamando o "finished()". - QVariantMap replyValue; + //grava o código de retorno replyValue["codestatus"] = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString(); if (reply->error() == QNetworkReply::NoError) { + //se não houver erro, grava o retorno; QString strReply = (QString)reply->readAll(); replyValue["reply"] = strReply; //parse json @@ -98,6 +104,7 @@ public: } + //retorna o json; QJsonObject jsonObj = QJsonObject::fromVariantMap(replyValue); return jsonObj; } @@ -117,6 +124,7 @@ public: // a requisição HTTP QUrl url = urlGerente; QNetworkRequest req( url ); + req.setHeader(QNetworkRequest::LocationHeader, "Cacic Agente"); QNetworkReply *reply = mgr.get(req); eventLoop.exec(); // sai do looping chamando o "finished()". @@ -145,8 +153,19 @@ public: } + bool sslConnection(QString host, int port) { + //cria dados para conexão + SslClient client; + client.setHost(host); + client.setPort(port); + + return client.start(); + //cria conexão e retorna json + + } + signals: void finished(QNetworkReply* reply); -}; +}; #endif // CACIC_COMM_H -- libgit2 0.21.2