From c593dea119b4c5fa77a8b2cc129d048d7d56afa4 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 15 Jun 2015 06:05:00 -0700 Subject: [PATCH] Cloud storage: use preference member instead of hard coded strings This creates the basis to allow other backends to be used with the cloud storage infrastructure. So far this should all just transparently continue to work. A user would have to manually add the cloud_base_url entry to the CloudStorage section in their config file in order to use a different backend server. Signed-off-by: Dirk Hohndel --- file.c | 3 +-- git-access.c | 4 ++-- qt-ui/mainwindow.cpp | 2 +- qt-ui/subsurfacewebservices.cpp | 10 +++++----- qthelper.cpp | 4 ++-- save-git.c | 2 +- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/file.c b/file.c index f3c697b0d..be8935a88 100644 --- a/file.c +++ b/file.c @@ -428,8 +428,7 @@ int parse_file(const char *filename) int ret; git = is_git_repository(filename, &branch, NULL); - if (strstr(filename, "https://cloud.subsurface-divelog.org/git") - && git == dummy_git_repository) + if (strstr(filename, prefs.cloud_git_url) && git == dummy_git_repository) /* opening the cloud storage repository failed for some reason * give up here and don't send errors about git repositories */ return 0; diff --git a/git-access.c b/git-access.c index 94f12c5ea..b86805994 100644 --- a/git-access.c +++ b/git-access.c @@ -374,12 +374,12 @@ static git_repository *create_local_repo(const char *localdir, const char *remot int len = sizeof("Reference 'refs/remotes/origin/' not found" + strlen(branch)); char *pattern = malloc(len); snprintf(pattern, len, "Reference 'refs/remotes/origin/%s' not found", branch); - if (strstr(remote, "https://cloud.subsurface-divelog.org/git") && strstr(msg, pattern)) { + if (strstr(remote, prefs.cloud_git_url) && strstr(msg, pattern)) { /* we're trying to open the remote branch that corresponds * to our cloud storage and the branch doesn't exist. * So we need to create the branch and push it to the remote */ cloned_repo = create_and_push_remote(localdir, remote, branch); - } else if (strstr(remote, "https://cloud.subsurface-divelog.org/git")) { + } else if (strstr(remote, prefs.cloud_git_url)) { report_error(translate("gettextFromC", "Error connecting to Subsurface cloud storage")); } else { report_error(translate("gettextFromC", "git clone of %s failed (%s)"), remote, msg); diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index fb62f4de2..de7cdbdc1 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -1433,7 +1433,7 @@ QString MainWindow::displayedFilename(QString fullFilename) QFileInfo fileInfo(f); QString fileName(fileInfo.fileName()); - if (fullFilename.contains("https://cloud.subsurface-divelog.org")) + if (fullFilename.contains(prefs.cloud_git_url)) return tr("[cloud storage for] %1").arg(fileName.left(fileName.indexOf('['))); else return fileName; diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp index dfaf69468..665bcf43a 100644 --- a/qt-ui/subsurfacewebservices.cpp +++ b/qt-ui/subsurfacewebservices.cpp @@ -946,9 +946,9 @@ CloudStorageAuthenticate::CloudStorageAuthenticate(QObject *parent) : QObject(pa userAgent = getUserAgent(); } -#define CLOUDURL "https://cloud.subsurface-divelog.org/" -#define CLOUDBACKENDSTORAGE CLOUDURL "storage" -#define CLOUDBACKENDVERIFY CLOUDURL "verify" +#define CLOUDURL QString(prefs.cloud_base_url) +#define CLOUDBACKENDSTORAGE CLOUDURL + "/storage" +#define CLOUDBACKENDVERIFY CLOUDURL + "/verify" QNetworkReply* CloudStorageAuthenticate::authenticate(QString email, QString password, QString pin) { @@ -1013,7 +1013,7 @@ CheckCloudConnection::CheckCloudConnection(QObject *parent) } -#define TEAPOT "https://cloud.subsurface-divelog.org/make-latte?number-of-shots=3" +#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() @@ -1024,7 +1024,7 @@ bool CheckCloudConnection::checkServer() QNetworkRequest request; request.setRawHeader("Accept", "text/plain"); request.setRawHeader("User-Agent", getUserAgent().toUtf8()); - request.setUrl(QString(TEAPOT)); + request.setUrl(QString(prefs.cloud_base_url) + TEAPOT); QNetworkAccessManager *mgr = new QNetworkAccessManager(); QNetworkReply *reply = mgr->get(request); connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); diff --git a/qthelper.cpp b/qthelper.cpp index 39c259992..9d907edf9 100644 --- a/qthelper.cpp +++ b/qthelper.cpp @@ -1038,7 +1038,7 @@ int getCloudURL(QString &filename) free(prefs.cloud_storage_email_encoded); prefs.cloud_storage_email_encoded = strdup(qPrintable(email)); } - filename = QString("https://cloud.subsurface-divelog.org/git/%1[%1]").arg(email); + filename = QString(QString(prefs.cloud_git_url) + "/%1[%1]").arg(email); return 0; } @@ -1047,7 +1047,7 @@ extern "C" bool isCloudUrl(const char *filename) QString email = QString(prefs.cloud_storage_email); email.replace(QRegularExpression("[^a-zA-Z0-9@._+-]"), ""); if (!email.isEmpty() && - QString("https://cloud.subsurface-divelog.org/git/%1[%1]").arg(email) == filename) + QString(QString(prefs.cloud_git_url) + "/%1[%1]").arg(email) == filename) return true; return false; } diff --git a/save-git.c b/save-git.c index d4247c0d0..6e44b0851 100644 --- a/save-git.c +++ b/save-git.c @@ -1141,7 +1141,7 @@ int do_git_save(git_repository *repo, const char *branch, const char *remote, bo if (prefs.cloud_background_sync) { /* now sync the tree with the cloud server */ - if (strstr(remote, "https://cloud.subsurface-divelog.org")) { + if (strstr(remote, prefs.cloud_git_url)) { return sync_with_remote(repo, remote, branch, RT_HTTPS); } }