summaryrefslogtreecommitdiffstats
path: root/checkcloudconnection.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2015-09-02 20:52:34 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-10-30 10:36:48 -0700
commit4c0156e3d51b389db8eccc3fa3da4b8f248f9b13 (patch)
tree966868d29150fdba13a5a56fb4305bc432ec7a72 /checkcloudconnection.cpp
parenta0798214231c652ac6142228f5ddfc4b65c921f8 (diff)
downloadsubsurface-4c0156e3d51b389db8eccc3fa3da4b8f248f9b13.tar.gz
Move all core-functionality to subsurface-core
And adapt a new CMakeLists.txt file for it. On the way I've also found out that we where double-compilling a few files. I've also set the subsurface-core as a include_path but that was just to reduce the noise on this commit, since I plan to remove it from the include path to make it obligatory to specify something like include "subsurface-core/dive.h" for the header files. Since the app is growing quite a bit we ended up having a few different files with almost same name that did similar things, I want to kill that (for instance Dive.h, dive.h, PrintDive.h and such). Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'checkcloudconnection.cpp')
-rw-r--r--checkcloudconnection.cpp95
1 files changed, 0 insertions, 95 deletions
diff --git a/checkcloudconnection.cpp b/checkcloudconnection.cpp
deleted file mode 100644
index be2a2fa18..000000000
--- a/checkcloudconnection.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-#include <QObject>
-#include <QTimer>
-#include <QNetworkAccessManager>
-#include <QNetworkReply>
-#include <QEventLoop>
-
-#include "pref.h"
-#include "helpers.h"
-
-#include "checkcloudconnection.h"
-
-
-CheckCloudConnection::CheckCloudConnection(QObject *parent) :
- QObject(parent),
- reply(0)
-{
-
-}
-
-#define TEAPOT "/make-latte?number-of-shots=3"
-#define HTTP_I_AM_A_TEAPOT 418
-#define MILK "Linus does not like non-fat milk"
-bool CheckCloudConnection::checkServer()
-{
- QTimer timer;
- timer.setSingleShot(true);
- QEventLoop loop;
- QNetworkRequest request;
- request.setRawHeader("Accept", "text/plain");
- request.setRawHeader("User-Agent", getUserAgent().toUtf8());
- request.setUrl(QString(prefs.cloud_base_url) + TEAPOT);
- QNetworkAccessManager *mgr = new QNetworkAccessManager();
- reply = mgr->get(request);
- connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
- connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
- connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>)));
- timer.start(5000); // wait five seconds
- loop.exec();
- if (timer.isActive()) {
- // didn't time out, did we get the right response?
- timer.stop();
- if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == HTTP_I_AM_A_TEAPOT &&
- reply->readAll() == QByteArray(MILK)) {
- reply->deleteLater();
- mgr->deleteLater();
- if (verbose > 1)
- qWarning() << "Cloud storage: successfully checked connection to cloud server";
- return true;
- }
- } else {
- disconnect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
- reply->abort();
- }
- if (verbose)
- qDebug() << "connection test to cloud server failed" <<
- reply->error() << reply->errorString() <<
- reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() <<
- reply->readAll();
- reply->deleteLater();
- mgr->deleteLater();
- if (verbose)
- qWarning() << "Cloud storage: unable to connect to cloud server";
- return false;
-}
-
-void CheckCloudConnection::sslErrors(QList<QSslError> errorList)
-{
- if (verbose) {
- qDebug() << "Received error response trying to set up https connection with cloud storage backend:";
- Q_FOREACH (QSslError err, errorList) {
- qDebug() << err.errorString();
- }
- }
- QSslConfiguration conf = reply->sslConfiguration();
- QSslCertificate cert = conf.peerCertificate();
- QByteArray hexDigest = cert.digest().toHex();
- if (reply->url().toString().contains(prefs.cloud_base_url) &&
- hexDigest == "13ff44c62996cfa5cd69d6810675490e") {
- if (verbose)
- qDebug() << "Overriding SSL check as I recognize the certificate digest" << hexDigest;
- reply->ignoreSslErrors();
- } else {
- if (verbose)
- qDebug() << "got invalid SSL certificate with hex digest" << hexDigest;
- }
-}
-
-// helper to be used from C code
-extern "C" bool canReachCloudServer()
-{
- if (verbose)
- qWarning() << "Cloud storage: checking connection to cloud server";
- CheckCloudConnection *checker = new CheckCloudConnection;
- return checker->checkServer();
-}