diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-01-05 16:24:12 -0800 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-01-05 16:24:12 -0800 |
| commit | a19c19c58c91b02042e6b92e1d1358244247397b (patch) | |
| tree | 8f294d73a6571b177a30c62345b2587bc05146ce /ZeroTierUI | |
| parent | 67a71868cb5f0bfed14cbaa2100fe03a3998f1c6 (diff) | |
| download | infinitytier-a19c19c58c91b02042e6b92e1d1358244247397b.tar.gz infinitytier-a19c19c58c91b02042e6b92e1d1358244247397b.zip | |
Refactor SoftwareUpdate to make .nfo parse and signature check code easily reusable so it can be used from the Qt GUI code.
Diffstat (limited to 'ZeroTierUI')
| -rw-r--r-- | ZeroTierUI/installdialog.cpp | 37 | ||||
| -rw-r--r-- | ZeroTierUI/installdialog.h | 11 |
2 files changed, 43 insertions, 5 deletions
diff --git a/ZeroTierUI/installdialog.cpp b/ZeroTierUI/installdialog.cpp index ad575770..83820e88 100644 --- a/ZeroTierUI/installdialog.cpp +++ b/ZeroTierUI/installdialog.cpp @@ -3,6 +3,7 @@ #include "ui_installdialog.h" #include "../node/Defaults.hpp" +#include "../node/SoftwareUpdater.hpp" #include <QMainWindow> #include <QMessageBox> @@ -12,7 +13,8 @@ InstallDialog::InstallDialog(QWidget *parent) : QDialog(parent), ui(new Ui::InstallDialog), - nam(new QNetworkAccessManager(this)) + nam(new QNetworkAccessManager(this)), + phase(FETCHING_NFO) { ui->setupUi(this); QObject::connect(nam,SIGNAL(finished(QNetworkReply*)),this,SLOT(on_networkReply(QNetworkReply*))); @@ -40,16 +42,41 @@ void InstallDialog::on_networkReply(QNetworkReply *reply) if (reply->error() != QNetworkReply::NoError) { QMessageBox::critical(this,"Download Failed",QString("Download failed: ") + reply->errorString(),QMessageBox::Ok,QMessageBox::NoButton); QApplication::exit(1); - return; } else { if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) == 200) { QByteArray installerData(reply->readAll()); - installerData.append((char)0); - printf("%s\n",installerData.data()); + + switch(phase) { + case FETCHING_NFO: { + unsigned int vMajor = 0,vMinor = 0,vRevision = 0; + installerData.append((char)0); + const char *err = ZeroTier::SoftwareUpdater::parseNfo(installerData.data(),vMajor,vMinor,vRevision,signedBy,signature,url); + + if (err) { + QMessageBox::critical(this,"Download Failed","Download failed: there is a problem with the software update web site.\nTry agian later. (invalid .nfo file)",QMessageBox::Ok,QMessageBox::NoButton); + QApplication::exit(1); + return; + } + + phase = FETCHING_INSTALLER; + reply = nam->get(QNetworkRequest(QUrl(url.c_str()))); + QObject::connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(on_downloadProgress(qint64,qint64))); + } break; + case FETCHING_INSTALLER: { + if (!ZeroTier::SoftwareUpdater::validateUpdate(installerData.data(),installerData.length(),signedBy,signature)) { + QMessageBox::critical(this,"Download Failed","Download failed: there is a problem with the software update web site.\nTry agian later. (failed signature check)",QMessageBox::Ok,QMessageBox::NoButton); + QApplication::exit(1); + return; + } + } break; + } + + ui->progressBar->setMinimum(0); + ui->progressBar->setMaximum(100); + ui->progressBar->setValue(0); } else { QMessageBox::critical(this,"Download Failed",QString("Download failed: HTTP status code ") + reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString(),QMessageBox::Ok,QMessageBox::NoButton); QApplication::exit(1); - return; } } } diff --git a/ZeroTierUI/installdialog.h b/ZeroTierUI/installdialog.h index 19c7a89a..f2f5ed90 100644 --- a/ZeroTierUI/installdialog.h +++ b/ZeroTierUI/installdialog.h @@ -7,6 +7,10 @@ #include <QNetworkRequest> #include <QNetworkReply> +#include <string> + +#include "../node/Address.hpp" + namespace Ui { class InstallDialog; } @@ -28,6 +32,13 @@ private slots: private: Ui::InstallDialog *ui; QNetworkAccessManager *nam; + enum { + FETCHING_NFO, + FETCHING_INSTALLER + } phase; + + ZeroTier::Address signedBy; + std::string url,signature; }; #endif // INSTALLDIALOG_H |
