mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
617b105458
commit
c593dea119
6 changed files with 12 additions and 13 deletions
3
file.c
3
file.c
|
@ -428,8 +428,7 @@ int parse_file(const char *filename)
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
git = is_git_repository(filename, &branch, NULL);
|
git = is_git_repository(filename, &branch, NULL);
|
||||||
if (strstr(filename, "https://cloud.subsurface-divelog.org/git")
|
if (strstr(filename, prefs.cloud_git_url) && git == dummy_git_repository)
|
||||||
&& git == dummy_git_repository)
|
|
||||||
/* opening the cloud storage repository failed for some reason
|
/* opening the cloud storage repository failed for some reason
|
||||||
* give up here and don't send errors about git repositories */
|
* give up here and don't send errors about git repositories */
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -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));
|
int len = sizeof("Reference 'refs/remotes/origin/' not found" + strlen(branch));
|
||||||
char *pattern = malloc(len);
|
char *pattern = malloc(len);
|
||||||
snprintf(pattern, len, "Reference 'refs/remotes/origin/%s' not found", branch);
|
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
|
/* we're trying to open the remote branch that corresponds
|
||||||
* to our cloud storage and the branch doesn't exist.
|
* to our cloud storage and the branch doesn't exist.
|
||||||
* So we need to create the branch and push it to the remote */
|
* So we need to create the branch and push it to the remote */
|
||||||
cloned_repo = create_and_push_remote(localdir, remote, branch);
|
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"));
|
report_error(translate("gettextFromC", "Error connecting to Subsurface cloud storage"));
|
||||||
} else {
|
} else {
|
||||||
report_error(translate("gettextFromC", "git clone of %s failed (%s)"), remote, msg);
|
report_error(translate("gettextFromC", "git clone of %s failed (%s)"), remote, msg);
|
||||||
|
|
|
@ -1433,7 +1433,7 @@ QString MainWindow::displayedFilename(QString fullFilename)
|
||||||
QFileInfo fileInfo(f);
|
QFileInfo fileInfo(f);
|
||||||
QString fileName(fileInfo.fileName());
|
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('[')));
|
return tr("[cloud storage for] %1").arg(fileName.left(fileName.indexOf('[')));
|
||||||
else
|
else
|
||||||
return fileName;
|
return fileName;
|
||||||
|
|
|
@ -946,9 +946,9 @@ CloudStorageAuthenticate::CloudStorageAuthenticate(QObject *parent) : QObject(pa
|
||||||
userAgent = getUserAgent();
|
userAgent = getUserAgent();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CLOUDURL "https://cloud.subsurface-divelog.org/"
|
#define CLOUDURL QString(prefs.cloud_base_url)
|
||||||
#define CLOUDBACKENDSTORAGE CLOUDURL "storage"
|
#define CLOUDBACKENDSTORAGE CLOUDURL + "/storage"
|
||||||
#define CLOUDBACKENDVERIFY CLOUDURL "verify"
|
#define CLOUDBACKENDVERIFY CLOUDURL + "/verify"
|
||||||
|
|
||||||
QNetworkReply* CloudStorageAuthenticate::authenticate(QString email, QString password, QString pin)
|
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 HTTP_I_AM_A_TEAPOT 418
|
||||||
#define MILK "Linus does not like non-fat milk"
|
#define MILK "Linus does not like non-fat milk"
|
||||||
bool CheckCloudConnection::checkServer()
|
bool CheckCloudConnection::checkServer()
|
||||||
|
@ -1024,7 +1024,7 @@ bool CheckCloudConnection::checkServer()
|
||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
request.setRawHeader("Accept", "text/plain");
|
request.setRawHeader("Accept", "text/plain");
|
||||||
request.setRawHeader("User-Agent", getUserAgent().toUtf8());
|
request.setRawHeader("User-Agent", getUserAgent().toUtf8());
|
||||||
request.setUrl(QString(TEAPOT));
|
request.setUrl(QString(prefs.cloud_base_url) + TEAPOT);
|
||||||
QNetworkAccessManager *mgr = new QNetworkAccessManager();
|
QNetworkAccessManager *mgr = new QNetworkAccessManager();
|
||||||
QNetworkReply *reply = mgr->get(request);
|
QNetworkReply *reply = mgr->get(request);
|
||||||
connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
|
connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
|
||||||
|
|
|
@ -1038,7 +1038,7 @@ int getCloudURL(QString &filename)
|
||||||
free(prefs.cloud_storage_email_encoded);
|
free(prefs.cloud_storage_email_encoded);
|
||||||
prefs.cloud_storage_email_encoded = strdup(qPrintable(email));
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1047,7 +1047,7 @@ extern "C" bool isCloudUrl(const char *filename)
|
||||||
QString email = QString(prefs.cloud_storage_email);
|
QString email = QString(prefs.cloud_storage_email);
|
||||||
email.replace(QRegularExpression("[^a-zA-Z0-9@._+-]"), "");
|
email.replace(QRegularExpression("[^a-zA-Z0-9@._+-]"), "");
|
||||||
if (!email.isEmpty() &&
|
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 true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1141,7 +1141,7 @@ int do_git_save(git_repository *repo, const char *branch, const char *remote, bo
|
||||||
|
|
||||||
if (prefs.cloud_background_sync) {
|
if (prefs.cloud_background_sync) {
|
||||||
/* now sync the tree with the cloud server */
|
/* 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);
|
return sync_with_remote(repo, remote, branch, RT_HTTPS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue