From 0e8988e849e26ad23014f14feed28579b3d9d1b9 Mon Sep 17 00:00:00 2001 From: ericmenezesn@gmail.com Date: Wed, 27 Aug 2014 18:45:04 -0300 Subject: [PATCH] Começo do wmi --- cacic-teste/cacic-teste.pro | 4 +++- cacic-teste/testcacic.cpp | 10 ++++++++++ cacic-teste/testcacic.h | 1 + src/cacic_comm.h | 33 ++++++--------------------------- src/cacic_hardware.cpp | 52 +++++++++++++++++++++++++++++++++------------------- src/cacic_hardware.h | 2 +- 6 files changed, 54 insertions(+), 48 deletions(-) diff --git a/cacic-teste/cacic-teste.pro b/cacic-teste/cacic-teste.pro index 295c43f..953ed89 100644 --- a/cacic-teste/cacic-teste.pro +++ b/cacic-teste/cacic-teste.pro @@ -6,8 +6,10 @@ QT += testlib QT += network -QT += axcontainer + TARGET = cacic-teste + +QT += axcontainer CONFIG -= app_bundle CONFIG += c++11 TEMPLATE = app diff --git a/cacic-teste/testcacic.cpp b/cacic-teste/testcacic.cpp index 2c7ee30..816b16c 100644 --- a/cacic-teste/testcacic.cpp +++ b/cacic-teste/testcacic.cpp @@ -158,6 +158,7 @@ void CTestCacic::testDeCrypt(){ void CTestCacic::testCacicCompToJsonObject() { // qDebug() << OCacicComp.toJsonObject(); +// OCacic.setJsonToFile(OCacicComp.toJsonObject(), "jsoncomp.json"); QVERIFY(!OCacicComp.toJsonObject().empty()); } @@ -238,6 +239,15 @@ void CTestCacic::testConvertDouble() QVERIFY(converted.toDouble() == number); } +void CTestCacic::testGetTest() +{ + bool ok; + QJsonObject envio; + envio["computador"] = OCacicComp.toJsonObject(); + OCacicComm.setUrlGerente("http://10.1.0.137/cacic/web/app_dev.php"); + QVERIFY(ok); +} + void CTestCacic::cleanupTestCase() { OCacic.deleteFile("configRequest.json"); diff --git a/cacic-teste/testcacic.h b/cacic-teste/testcacic.h index 2972872..e77cceb 100644 --- a/cacic-teste/testcacic.h +++ b/cacic-teste/testcacic.h @@ -70,6 +70,7 @@ private slots: void testColetaSoftware(); void testColetaHardware(); void testConvertDouble(); + void testGetTest(); void cleanupTestCase(); }; diff --git a/src/cacic_comm.h b/src/cacic_comm.h index ce17f29..ceaa423 100644 --- a/src/cacic_comm.h +++ b/src/cacic_comm.h @@ -19,7 +19,6 @@ private: QUrlQuery params; QString urlGerente; QString urlSsl; - // FIXME: Get from configuration QString usuario; QString password; QString session; @@ -67,35 +66,27 @@ public: url = "http://" + urlGerente + route; req.setUrl(url); req.setHeader(QNetworkRequest::LocationHeader, "Cacic Agente"); - if (json.empty()) - { + if (json.empty()){ //se não for passado QJson, será mandado os valores do get/test antigo. (Será retirado depois) req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); data.append(params.toString()); } else { // Add JSON QJsonDocument d(json); - data.append(d.toVariant().toString()); + data.append(d.toJson()); req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); } -// qDebug() << QString::fromUtf8(d.toJson().trimmed()); - // cria um event-loop temporario QEventLoop eventLoop; - // "quit()" o event-loop, when the network request "finished()" QNetworkAccessManager mgr; QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit())); - // a requisição HTTP - QNetworkReply *reply = mgr.post(req, data); if (!reply->sslConfiguration().isNull()){ -// qDebug() << "Eh ssl"; reply->ignoreSslErrors(); } eventLoop.exec(); // sai do looping chamando o "finished()". - //grava codigo de retorno + jsonObj.insert("codestatus", QJsonValue::fromVariant(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute))); -// qDebug() << "code: " << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString(); if (reply->error() == QNetworkReply::NoError) { //se não houver erro, grava o retorno; @@ -104,20 +95,13 @@ public: jsonObj["reply"] = (!replyDocument.isNull()) ? replyDocument.object() : QJsonValue::fromVariant(replyVariant.toString()); -// qDebug() << "Response:" << jsonObj["reply"]; -// qDebug() << "Response:" << strReply; *ok = true; delete reply; } else { - //failure -// qDebug() << "Failure" <errorString(); strReply = reply->errorString(); jsonObj.insert("error", QJsonValue::fromVariant(strReply)); delete reply; - - } - //retorna o json; return jsonObj; } @@ -154,7 +138,6 @@ public: /* login * realiza login com usuario e senha * @return retorna json com sessão e chave de criptografia - * exemplo: 200 OK */ QJsonObject login(bool *ok) { *ok = false; @@ -162,10 +145,8 @@ public: QVariantMap login; login["user"] = this->usuario; login["password"] = this->password; -// QJsonValue sessionvalue = OCacic.jsonValueFromJsonString(json["reply"].toString(), "session"); // Cria conexão e retorna Json da sessão -// qDebug() << "Conectando."; - QJsonObject retorno = this->comm("/ws/neo/login", ok, QJsonObject::fromVariantMap(login), true); + QJsonObject retorno = this->comm("/ws/neo/getLogin", ok, QJsonObject::fromVariantMap(login), true); if (*ok) this->session = retorno["reply"].toObject()["session"].toString(); return retorno; @@ -184,10 +165,8 @@ public: } void setUrlGerente(QString value){ - if (value.contains("http://", Qt::CaseInsensitive)){ - value = value.mid(value.indexOf("http://") + 7); - } else if (value.contains("https://", Qt::CaseInsensitive)){ - value = value.mid(value.indexOf("https://") + 8); + if (value.contains("://", Qt::CaseInsensitive)){ + value = value.mid(value.indexOf("://") + 3); } if (value.endsWith("/")){ value.remove(value.size()-1, 1); diff --git a/src/cacic_hardware.cpp b/src/cacic_hardware.cpp index 5c6a62a..1d1c5d9 100644 --- a/src/cacic_hardware.cpp +++ b/src/cacic_hardware.cpp @@ -13,25 +13,39 @@ void cacic_hardware::iniciaColeta() } #ifdef Q_OS_WIN QJsonObject cacic_hardware::coletaWin() -{ -// QAxObject *objIWbemLocator = new QAxObject("WbemScripting.SWbemLocator"); -// QAxObject *objWMIService = objIWbemLocator->querySubObject("ConnectServer(QString&,QString&)",QString("."),QString("root\\cimv2")); -// if (objWMIService->isNull()) -// { -// return QJsonObject(); -// } -// QAxObject *returnList = objWMIService->querySubObject("ExecQuery(QString&)",QString("select SystemType from win32_computersystem")); -// QAxObject *enum1 = returnList->querySubObject("_NewEnum"); -// IEnumVARIANT* enumInterface; //to get this, include -// enum1->queryInterface(IID_IEnumVARIANT, (void**)&enumInterface); -// enumInterface->Reset(); //start at the beginning of the list. -// for (int i=0;idynamicCall("Count").toInt();i++){ -// VARIANT *theItem; -// enumInterface->Next(1,theItem,NULL); -// QAxObject *item = new QAxObject((IUnknown *)theItem->punkVal); -// qDebug() << item->dynamicCall("Caption"); -// } - +{ + QAxObject *objIWbemLocator = new QAxObject("WbemScripting.SWbemLocator"); + QAxObject *objWMIService = objIWbemLocator->querySubObject("ConnectServer(QString&,QString&)", + QString("."), + QString("root\\CIMV2") + ); + QAxObject* returnList = objWMIService->querySubObject("ExecQuery(QString&)", + QString("SELECT * FROM Win32_ComputerSystem") + ); + QAxObject *enum1 = returnList->querySubObject("_NewEnum"); + //ui->textBrowser_4->setHtml(enum1->generateDocumentation()); + IEnumVARIANT* enumInterface = 0; + enum1->queryInterface(IID_IEnumVARIANT, (void**)&enumInterface); + + //ui->textBrowser_4->setHtml(enumInterface->); + enumInterface->Reset(); + // QAxObject *item = 0; + + //qDebug()<<"the count of objinterlist is "<dynamicCall("Count").toInt()); + for (int i = 0; i < returnList->dynamicCall("Count").toInt(); i++) { + VARIANT *theItem = (VARIANT*)malloc(sizeof(VARIANT)); + if (enumInterface->Next(1,theItem,NULL) != S_FALSE){ + QAxObject *item = new QAxObject((IUnknown *)theItem->punkVal); + + if(item){ + qDebug() <<" string is "<dynamicCall("ProcessorId").toString(); + qDebug() <<" string is "<dynamicCall("GetText_(WbemObjectTextFormatEnum)", QVariant(1)).toString(); + } + // item-> + //QString val = + qDebug()<<"item name is "<< item->property("objectName").toString(); + } + } return QJsonObject(); } #elif Q_OS_LINUX diff --git a/src/cacic_hardware.h b/src/cacic_hardware.h index 61173ee..682feb0 100644 --- a/src/cacic_hardware.h +++ b/src/cacic_hardware.h @@ -8,8 +8,8 @@ #include #include #ifdef Q_OS_WIN -// #include #include + #include #endif class cacic_hardware -- libgit2 0.21.2