From d3a104d576bad0d0f1b69787a67c6e494d8915be Mon Sep 17 00:00:00 2001 From: ericmenezesn@gmail.com Date: Tue, 12 Aug 2014 12:52:28 -0300 Subject: [PATCH] Conexão ssl, test ssl, nova funcao de auxilio json, tipo de lista de networkInterfaces alterada --- cacic-teste/testcacic.cpp | 33 ++++++++++++++++++++------------- cacic-teste/testcacic.h | 1 + src/cacic_comm.h | 3 ++- src/cacic_computer.cpp | 28 +++++++++++++++++----------- src/cacic_computer.h | 6 +++--- src/ccacic.cpp | 5 +++++ src/ccacic.h | 6 +++++- 7 files changed, 53 insertions(+), 29 deletions(-) diff --git a/cacic-teste/testcacic.cpp b/cacic-teste/testcacic.cpp index b45c873..02881aa 100644 --- a/cacic-teste/testcacic.cpp +++ b/cacic-teste/testcacic.cpp @@ -24,6 +24,7 @@ void CTestCacic::initTestCase() "2.5.1.1.256.32", "2.8.1.7", "2.8.1.6"); + OCacicComm.setUrlSsl("https://10.1.0.137/cacic/web/app_dev.php"); this->testPath = QDir::currentPath() + "/teste"; this->testIniPath = testPath + "/teste.ini"; QVariantMap json; @@ -92,7 +93,7 @@ void CTestCacic::testDeCrypt(){ } void CTestCacic::testInterfaceDeRede(){ - // qDebug() << QString::fromStdString(OCacicComp.getNetworkInterface().at(0).at(0)); +// qDebug() << OCacicComp.getNetworkInterface().at(0)["nome"].toString(); QVERIFY2(!OCacicComp.getNetworkInterface().empty(), "Nenhuma interface de rede encontrada."); } @@ -105,22 +106,28 @@ void CTestCacic::testPegarUsu(){ } void CTestCacic::testLogin(){ - QJsonObject sessionjson = OCacicComm.login(); - QJsonValue session_str = sessionjson["codestatus"]; - // qDebug() << session_str.toVariant().toString(); - QVERIFY(!session_str.isNull()); + + QVariantMap login; + login["user"] = "eric"; + login["password"] = "612ef9b1"; + OCacicComm.setUrlSsl("https://10.1.0.137/cacic/web/app_dev.php"); + QJsonObject json = OCacicComm.comm("/ws/neo/login", QJsonObject::fromVariantMap(login), true); + QJsonValue sessionvalue = OCacic.jsonValueFromJsonString(json["reply"].toString(), "session"); +// qDebug() << sessionvalue.toString(); + QVERIFY(!sessionvalue.isNull()); } void CTestCacic::testSslConnection() { - QVariantMap login; - login["user"] = "cacic"; - login["password"] = "cacic"; - OCacicComm.setUrlSsl("https://teste.cacic.cc"); - QJsonObject json = OCacicComm.comm("", QJsonObject::fromVariantMap(login), true); - QJsonValue jsonvalue = json["reply"]; -// qDebug() << jsonvalue.toVariant().toString(); - QVERIFY(!jsonvalue.isNull()); + QJsonObject json = OCacicComm.comm("", QJsonObject(), true); + QJsonValue jsonvalue = json["codestatus"]; +// qDebug() << jsonvalue.toString(); + QVERIFY(jsonvalue.toString() == "200" || jsonvalue.toString() == "302"); +} + +void CTestCacic::testJsonValueFromJsonString() +{ + QVERIFY(OCacic.jsonValueFromJsonString("{\"nome\":\"teste\"}", "nome").toString() == "teste"); } void CTestCacic::cleanupTestCase() diff --git a/cacic-teste/testcacic.h b/cacic-teste/testcacic.h index a4b3691..5b4799c 100644 --- a/cacic-teste/testcacic.h +++ b/cacic-teste/testcacic.h @@ -47,6 +47,7 @@ private slots: void testpegarOS(); void testLogin(); void testSslConnection(); + void testJsonValueFromJsonString(); void cleanupTestCase(); }; diff --git a/src/cacic_comm.h b/src/cacic_comm.h index 2376a2e..0fe1396 100644 --- a/src/cacic_comm.h +++ b/src/cacic_comm.h @@ -22,6 +22,7 @@ private: // FIXME: Get from configuration QString usuario = "user"; QString password = "123456"; + std::string session; public: CacicComm (){ @@ -34,7 +35,6 @@ public: QString so, QString cacicVersion, QString gercolsVersion) { this->urlGerente = urlGerente; - params.addQueryItem("OperatingSystem", operatingSystem); params.addQueryItem("ComputerSystem",computerSystem); params.addQueryItem("cs_cipher",csCipher); @@ -94,6 +94,7 @@ public: QVariantMap replyValue; //grava o código de retorno replyValue["codestatus"] = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString(); +// qDebug() << "code: " << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString(); if (reply->error() == QNetworkReply::NoError) { //se não houver erro, grava o retorno; diff --git a/src/cacic_computer.cpp b/src/cacic_computer.cpp index d749ceb..efae2f2 100644 --- a/src/cacic_computer.cpp +++ b/src/cacic_computer.cpp @@ -14,32 +14,38 @@ CACIC_Computer::CACIC_Computer() * outra lista que conterá todas as interfaces. * */ -QList> CACIC_Computer::networkInterfacesRunning(){ +QList CACIC_Computer::networkInterfacesRunning(){ QNetworkInterface interface; - QList lista; - QList> todasInterfaces; + QVariantMap mapInterface; + QList listaMap; foreach (QNetworkInterface in, interface.allInterfaces()) { if (!(bool)(in.flags() & QNetworkInterface::IsLoopBack) && !(bool)(in.flags() & QNetworkInterface::IsPointToPoint) && (bool)(in.flags() & QNetworkInterface::IsRunning)){ // qDebug() << in.humanReadableName() << "\n"; - lista.append(in.humanReadableName().toStdString()); + mapInterface["nome"] = in.humanReadableName(); // qDebug() << in.hardwareAddress() << "\n"; - lista.append(in.hardwareAddress().toStdString()); + mapInterface["mac"] = in.hardwareAddress(); foreach (QNetworkAddressEntry ae, in.addressEntries()){ if (ae.ip().scopeId() == ""){ - lista.append(ae.ip().toString().toStdString()); + mapInterface["ipv4"] = ae.ip().toString(); } else { - lista.append(ae.ip().toString().toStdString()); + mapInterface["ipv6"] = ae.ip().toString(); } // qDebug() << ae.ip().toString() << "\n"; } - todasInterfaces.append(lista); - lista.clear(); + listaMap.append(mapInterface); + mapInterface.clear(); } } - return todasInterfaces; +// foreach (QVariantMap each, listaMap){ + +// foreach (QVariant eachValue, each.values()) +// qDebug() << eachValue.toString(); +// } + + return listaMap; } /*pegarOS @@ -93,7 +99,7 @@ std::string CACIC_Computer::getUser() const { return usu; } -QList> CACIC_Computer::getNetworkInterface() const +QList CACIC_Computer::getNetworkInterface() const { return networkInterface; } diff --git a/src/cacic_computer.h b/src/cacic_computer.h index 49c85d6..36f5572 100644 --- a/src/cacic_computer.h +++ b/src/cacic_computer.h @@ -17,11 +17,11 @@ public: std::string pegarUsu(); int getOs() const; std::string getUser() const; - QList> getNetworkInterface() const; - QList> networkInterfacesRunning(); + QList getNetworkInterface() const; + QList networkInterfacesRunning(); private: - QList> networkInterface; + QList networkInterface; int os; std::string usu; diff --git a/src/ccacic.cpp b/src/ccacic.cpp index b3ec8cd..257f44c 100644 --- a/src/ccacic.cpp +++ b/src/ccacic.cpp @@ -103,6 +103,11 @@ bool CCacic::deleteFile(QString path) return true; } +QJsonValue CCacic::jsonValueFromJsonString(QString json, QString key) +{ + return QJsonDocument::fromJson(json.toUtf8()).object()[key]; +} + /*enCrypt * @parameter std::string str_in: string que será encriptada (url). * std::string key: chave utilizada na encriptação (32 caracteres) 32*8 = 256 bits diff --git a/src/ccacic.h b/src/ccacic.h index 88c5d97..9028a53 100644 --- a/src/ccacic.h +++ b/src/ccacic.h @@ -14,7 +14,10 @@ #include #include #include -//#include +#include +#include +#include + class CCacic : public QObject { Q_OBJECT @@ -28,6 +31,7 @@ public: bool createFolder(QString path); bool deleteFolder(QString path); bool deleteFile(QString path); + QJsonValue jsonValueFromJsonString(QString json, QString key); //Geters/seters: -- libgit2 0.21.2