Commit 912b7852e9e0855714f7b4634b07254a3018c4a3

Authored by Eric Menezes Noronha
1 parent e9c282ff
Exists in master

Pequenas alterações

cacic-teste/cacic-teste.pro
@@ -20,13 +20,16 @@ win32 { @@ -20,13 +20,16 @@ win32 {
20 SOURCES += \ 20 SOURCES += \
21 testcacic.cpp \ 21 testcacic.cpp \
22 ../src/ccacic.cpp \ 22 ../src/ccacic.cpp \
23 - ../src/cacic_computer.cpp 23 + ../src/cacic_computer.cpp \
  24 + ../src/sslclient.cpp
24 25
25 26
26 HEADERS += \ 27 HEADERS += \
27 testcacic.h \ 28 testcacic.h \
28 ../src/ccacic.h \ 29 ../src/ccacic.h \
29 ../src/cacic_computer.h \ 30 ../src/cacic_computer.h \
30 - ../src/cacic_comm.h 31 + ../src/cacic_comm.h \
  32 + ../src/sslclient.h
31 33
32 -INCLUDEPATH += ../src 34 +INCLUDEPATH += ../src \
  35 + ../src/crypto++/include/
cacic-teste/testcacic.cpp
@@ -108,6 +108,17 @@ void CTestCacic::testLogin(){ @@ -108,6 +108,17 @@ void CTestCacic::testLogin(){
108 QVERIFY(!session_str.isNull()); 108 QVERIFY(!session_str.isNull());
109 } 109 }
110 110
  111 +void CTestCacic::testSslConnection()
  112 +{
  113 + QVariantMap login;
  114 + login["user"] = "cacic";
  115 + login["password"] = "cacic";
  116 + QJsonObject json = OCacicComm.comm("/ws/get/test", QJsonObject::fromVariantMap(login), true);
  117 + QJsonValue jsonvalue = json["key"];
  118 +// qDebug() << jsonvalue.toVariant().toString();
  119 + QVERIFY(!jsonvalue.isNull());
  120 +}
  121 +
111 void CTestCacic::cleanupTestCase() 122 void CTestCacic::cleanupTestCase()
112 { 123 {
113 124
cacic-teste/testcacic.h
@@ -45,6 +45,7 @@ private slots: @@ -45,6 +45,7 @@ private slots:
45 void testInterfaceDeRede(); 45 void testInterfaceDeRede();
46 void testpegarOS(); 46 void testpegarOS();
47 void testLogin(); 47 void testLogin();
  48 + void testSslConnection();
48 void cleanupTestCase(); 49 void cleanupTestCase();
49 }; 50 };
50 51
src/cacic_comm.h
@@ -12,6 +12,7 @@ @@ -12,6 +12,7 @@
12 #include <QUrlQuery> 12 #include <QUrlQuery>
13 #include <QJsonObject> 13 #include <QJsonObject>
14 #include <QJsonDocument> 14 #include <QJsonDocument>
  15 +#include <sslclient.h>
15 16
16 17
17 class CacicComm { 18 class CacicComm {
@@ -49,14 +50,18 @@ public: @@ -49,14 +50,18 @@ public:
49 params.addQueryItem("te_so",so); 50 params.addQueryItem("te_so",so);
50 params.addQueryItem("te_versao_cacic",cacicVersion); 51 params.addQueryItem("te_versao_cacic",cacicVersion);
51 params.addQueryItem("te_versao_gercols",gercolsVersion); 52 params.addQueryItem("te_versao_gercols",gercolsVersion);
  53 +
  54 +
52 } 55 }
53 56
54 - QJsonObject comm(QString route, const QJsonObject &json = QJsonObject()) 57 + QJsonObject comm(QString route, const QJsonObject &json = QJsonObject(), bool isSsl = false)
55 { 58 {
56 QByteArray data; 59 QByteArray data;
57 QUrl url = urlGerente + route; 60 QUrl url = urlGerente + route;
58 QNetworkRequest req(url); 61 QNetworkRequest req(url);
59 req.setHeader(QNetworkRequest::LocationHeader, "Cacic Agente"); 62 req.setHeader(QNetworkRequest::LocationHeader, "Cacic Agente");
  63 + if (isSsl)
  64 + req.setSslConfiguration(QSslConfiguration::defaultConfiguration());
60 if (json.empty()) 65 if (json.empty())
61 { 66 {
62 //se não for passado QJson, será mandado os valores do get/test antigo. (Será retirado depois) 67 //se não for passado QJson, será mandado os valores do get/test antigo. (Será retirado depois)
@@ -79,11 +84,12 @@ public: @@ -79,11 +84,12 @@ public:
79 84
80 QNetworkReply *reply = mgr.post(req, data); 85 QNetworkReply *reply = mgr.post(req, data);
81 eventLoop.exec(); // sai do looping chamando o "finished()". 86 eventLoop.exec(); // sai do looping chamando o "finished()".
82 -  
83 QVariantMap replyValue; 87 QVariantMap replyValue;
  88 + //grava o código de retorno
84 replyValue["codestatus"] = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString(); 89 replyValue["codestatus"] = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString();
85 90
86 if (reply->error() == QNetworkReply::NoError) { 91 if (reply->error() == QNetworkReply::NoError) {
  92 + //se não houver erro, grava o retorno;
87 QString strReply = (QString)reply->readAll(); 93 QString strReply = (QString)reply->readAll();
88 replyValue["reply"] = strReply; 94 replyValue["reply"] = strReply;
89 //parse json 95 //parse json
@@ -98,6 +104,7 @@ public: @@ -98,6 +104,7 @@ public:
98 104
99 105
100 } 106 }
  107 + //retorna o json;
101 QJsonObject jsonObj = QJsonObject::fromVariantMap(replyValue); 108 QJsonObject jsonObj = QJsonObject::fromVariantMap(replyValue);
102 return jsonObj; 109 return jsonObj;
103 } 110 }
@@ -117,6 +124,7 @@ public: @@ -117,6 +124,7 @@ public:
117 // a requisição HTTP 124 // a requisição HTTP
118 QUrl url = urlGerente; 125 QUrl url = urlGerente;
119 QNetworkRequest req( url ); 126 QNetworkRequest req( url );
  127 + req.setHeader(QNetworkRequest::LocationHeader, "Cacic Agente");
120 QNetworkReply *reply = mgr.get(req); 128 QNetworkReply *reply = mgr.get(req);
121 eventLoop.exec(); // sai do looping chamando o "finished()". 129 eventLoop.exec(); // sai do looping chamando o "finished()".
122 130
@@ -145,8 +153,19 @@ public: @@ -145,8 +153,19 @@ public:
145 153
146 } 154 }
147 155
  156 + bool sslConnection(QString host, int port) {
  157 + //cria dados para conexão
  158 + SslClient client;
  159 + client.setHost(host);
  160 + client.setPort(port);
  161 +
  162 + return client.start();
  163 + //cria conexão e retorna json
  164 +
  165 + }
  166 +
148 signals: 167 signals:
149 void finished(QNetworkReply* reply); 168 void finished(QNetworkReply* reply);
150 -};  
151 169
  170 +};
152 #endif // CACIC_COMM_H 171 #endif // CACIC_COMM_H