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 <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-06-15 06:05:00 -07:00
parent 617b105458
commit c593dea119
6 changed files with 12 additions and 13 deletions

3
file.c
View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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()));

View file

@ -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;
}

View file

@ -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);
}
}