Commit graph

43 commits

Author SHA1 Message Date
Berthold Stoeger
7c64822b9b Cleanup: remove "sha1.h" include in "dive.h"
No point in pulling that in for all users of "dive.h"

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Dirk Hohndel
87eb95d004 Core: fix missing argument to report_error
The format requires a string argument.

Found via LGTM.com

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-03-17 11:23:49 -07:00
Dirk Hohndel
ae653703a5 prefs: git_local_only is not a preference
It's the current state of the app, so it should be a global variable, not a
preference.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-10 16:26:49 -07:00
jan Iversen
061be82e31 core: replace (void) with UNUSED(x) and include ssrf.h
Unused parameters in C are "silenced" by adding UNUSED(x)

Signed-off-by: Jan Iversen <jani@apache.org>
2018-05-24 08:34:14 -07:00
Dirk Hohndel
826c01d0a0 Core: don't inline rarely used function
This is only used by one caller and there doesn't appear to be a reason
to inline it in the first place.

Suggested-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-14 10:13:39 -07:00
Dirk Hohndel
543cefa61e Android: build fix
On other OSs this compiles fine without adding this header, but Android
is special...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-14 10:13:39 -07:00
Dirk Hohndel
ea83b5ed37 Core: remove dive.h from files that don't need it
Of course, quite a few of them indirectly get it through other header
files.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-14 10:13:39 -07:00
Dirk Hohndel
d577467f97 Core: introduce new subsurface-string header
First small step to shrinking dive.h.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-14 10:13:39 -07:00
Berthold Stoeger
cd5e17cf79 Cleanup: Unify qthelper.h and qthelperfromc.h
Since all qt-helpers are defined in qthelper.cpp, there seems to be
no reason to have two include files. By unifying the two files,
duplication and inconsistencies are removed. The C++-only part is
simply compiled away with #ifdefs.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-26 19:06:02 +02:00
Berthold Stoeger
5c248d91cd Coding-style: remove superfluous parentheses
Mostly replace "return (expression);" by "return expression;" and one
case of "function((parameter))" by "function(parameter)".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-17 19:38:52 -08:00
Berthold Stoeger
7594e7ca7f Unify username handling of remote git repositories
The username was extracted from https:// urls but not from ssh://
urls. Unify this by extracting the username from any remote url.
This is done with regard to unifying the file handling in the
frontend.

For this approach to work, the credential callback of the ssh://
transport had to be adapted. It now also supports username/password
in addition to private-key authentication.

Currently, the only way the user can use the username/password
authentication is by deleting a potential public key.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-19 09:45:08 +02:00
Berthold Stoeger
5a767ce964 Support non-https:// repositories for saving
On saving to a remote git repository, the transport was set to https://,
which broke saving to ssh:// repositories. Instead determine the
transport from the remote url.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-19 09:45:08 +02:00
Berthold Stoeger
cec642b4d2 Create local cache and push to remote for any remote repository
This used to be done only for cloud repositories.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-19 09:45:08 +02:00
Berthold Stoeger
0b0eacce30 Check cloudserver availability only for cloud repositories
The check used to be done for any https:// repository.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-19 09:45:08 +02:00
Berthold Stoeger
b188f00587 Factor out counting of authentication attempts into function
Moreover, make the maximum number of authentication attempts a
const variable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-19 09:45:08 +02:00
Berthold Stoeger
2d24dceafa Use format_string() in core/git_access.c
Since this helper-function exists, we might just use it. A subtle
reuse of a buffer (string of second use was known to be shorter than
string of first use) was replaced by a separate allocation.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-17 21:45:48 +02:00
Berthold Stoeger
daede13571 Fix leak(s) in core/git-access.c
The libgit2 functions git_cred_ssh_key_new() and git_cred_userpass_plaintext_new()
copy their arguments. Therefore, free the string arguments or don't
copy them in the first place.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-13 21:55:33 +01:00
Berthold Stoeger
35b5b9282f Enter offline mode if sync with cloud failed
In case syncing with the online repository failed, enter offline mode.
This reflects the message sent to the user ("working with local copy").

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-08 12:00:42 +01:00
Dirk Hohndel
2fed7a9441 Cleanup: avoid memory leak
No point in doing the strdup of the password if we then bail.

Coverity CID 208316
Coverity CID 209293

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 15:57:31 -08:00
Berthold Stoeger
d4cd4a96ea Gracefully handle cloud authentication failure in verbose mode
If the credential functions return GIT_EUSER, a call to git_remote_fetch
fails, but giterr_last() may return NULL. This led to a crash in
verbose mode.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-05 11:31:39 -08:00
Berthold Stoeger
fd34cd4830 Free unused git repository in git_create_local_repo()
In this function, a repository is created, but the returned object
is not used. Might just as well free it.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-03 19:07:03 -08:00
Berthold Stoeger
137e83f7f2 Fix file:// handling for git access.
Currently, in is_remote_git_repository(), git URLs of the form
"file://..." are recognized as local and the "file://" prefix is
removed. The shortened URL is then processed as if it was a remote
URL, which of course has to fail. So far so good - this is not
a remote repository after all. But the removal of the prefix is
not propagated to the calling is_git_repository() function and
handling as a local git repository therefore fails likewise.

To fix this issue, move removal of the "file://" prefix one level
up to the is_git_repository() function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-02 08:18:42 -08:00
Dirk Hohndel
38c4dfd45c Add a useful error message if we fail to connect to cloud server
Because now we are trying to open a URL as if it was a local file.
Again, the goal is to accelerated debugging if things go wrong.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-30 12:27:29 -07:00
Dirk Hohndel
2878f32a22 Improve parsing of git error message
This is rather fragile code, and the capitalization of the error message
in libgit2 changed at some point. But commit 794739b4c0 ("strstr is a
case sensitive compare") didn't really fix the problem - as it broke
that same check for older libgit2 versions.

Instead use our new helper function to make it work with libgit2 old and
new.

Also, add some more error output so the next time we run into this it's
more obvious what broke and where.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-30 12:27:29 -07:00
Jan Mulder
e76f527fe5 Correctly create cloud account from mobile
The creation of a cloud account from mobile was broken. This fixes
it. Basically, we need to go online for a moment, and setup a correct
local and remote repo for the cloud storage.

Tested for the following scenarios: 1) inital account creation
including PIN handling from mobile, from a clean install .
2) open an already validated cloud account from a clean install.
3) open no-cloud style local account.
4) Switch between 2 already validated could accounts.
5) Try to create a cloud account without data connection.

Notice that scenario 4) does not work perfectly. A restart of
the app is needed to see the new logbook. So that is to be fixed.

Scenario 5) seems a non realistic corner case. This does not work
in a gracefull way. The user needs to remove the app, install it
again, and retry with data connection.

Further notice this is backgroud/core processing only. So no QML UI
changes as proposed (for example) bij Davide.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-07-29 08:30:08 -07:00
Jan Mulder
794739b4c0 strstr is a case sensitive compare
strstr is a case sensitive compare and the string reported from
libgit2 reads "reference" and not "Reference". Further investigation
reveals commit 909d5494368a0080 of libgit2. Here, the change is
made from Reference to reference, breaking our rather poor way
of detecting something from an error string. So, to be future-proof
to more libgit2 oddities, it might be wise to use strcasestr
in this situation. But this seems a not fully supported variant of
strstr, so leave it at this point.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-07-29 08:30:08 -07:00
Jan Mulder
44e8d302ef Fix small memory leak
Add 2 forgotten free() statements for the temporary used string
buffers.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-07-29 08:30:08 -07:00
Dirk Hohndel
2b01ab7d50 Clean up git storage update messages
Translate all of them, but also remove some redundant or possibly
misleading messages. These are now seen by users, not just developers
trying to debug the code.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-18 01:00:30 -07:00
Dirk Hohndel
b2b51c833a QML UI: redesign the user notification
The old system of cloud access updates with fake percentages just wasn't
helpful. Even worse, it hid a lot important information from the user.
This should be more useful (but it will require that we localize the
messages sent from the git progress notifications and make them more
'user ready').

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-17 23:22:37 -07:00
Dirk Hohndel
6399eaf271 Add SPDX header to core C files
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-29 13:32:55 -07:00
Miika Turkia
1d0281c923 Fix a crash when git init fails
This can occur e.g. if directory permissions prevent one from writing to
the local cloud storage directory. (Such a crash was discussed on
mailing list.) The error message on GUI is misleading, claiming that
cloud connection failed...

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
---
We probably should check the return value of other git operations as
well, but going for bare minimum for now.
2017-03-28 11:12:36 -07:00
Lubomir I. Ivanov
bcad5ddd38 Only enable -Wmissing-field-initializers for Clang
The following pragma is Clang specific:

It produces a warning:
warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]

Only enable it for Clang by checking the __clang__ macro.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-03-12 09:18:59 -07:00
Jeremie Guichard
5ed93a9d9e Fix "Load/Save to cloudstorage" for non-ASCII user names
On Windows that would fail because stat() doesn't deal well with our
utf8 strings.

Added new subsurface_stat() portability function to replace stat().
Added Windows implementation of subsurface_stat() using wstat(),
with conversion to ut16 of the inputed path.
Other platform implementations (linux, android) make use of the normal stat().

Added non ASCII test case in TestGitStorage::testGitStorageLocal()

Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2017-02-24 01:10:22 -08:00
Linus Torvalds
777cbd9cfe Fix cloud storage authentication attempt counting
The authentication count was a static counter in the authentication
callback, which gets incremented until we consider the authentication to
have failed.

The problem with that is that it doesn't get incremented for just _one_
authentication operation, it gets incremented each time you try to load
or save, so eventually the code considers authentication to have failed
even if nothing ever went wrong.

This fixes it by making it static to the whole git-access file, and have
each operation clear it before starting a new remote access.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-08-14 10:22:35 -07:00
Anton Lundin
7c7588a986 Support libgit2 api 0.24
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-06-23 16:35:39 -07:00
Dirk Hohndel
241dd7cb81 Merge branch 'offlineDefault' 2016-04-30 12:40:52 -07:00
Dirk Hohndel
05a51f7984 Only create the path to no cloud local storage once
This required a small change to the helper function, but this seemed
totally worth it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-30 09:46:29 -07:00
Dirk Hohndel
9ba090c31f git storage: init local repository
So far we didn't do that at all, we either relied on the user manually
creating a local repo, or we cloned a remote repo.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-27 15:05:37 -07:00
Miika Turkia
90db7d3a50 Abort git authentication attempt
If we have incorrect cloud credentials, we need to return an error on
git authentication call back in order to avoid endless authentication
loop. This might well happen e.g. when changing the password on desktop
and then on laptop Subsurface still thinks the credentials are validated
and ends up in the authentication loop.

The authentication call back on libgit is intended to be used to ask for
user credentials, and as we handle credentials elsewhere, we just need
to fail the authentication attempts. (The threshold for bail out could
have been 1 attempt...)

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-25 09:58:57 -07:00
Dirk Hohndel
a1ec0d6724 git storage: only sync with remote if git_local_only isn't set
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-08 12:29:17 -07:00
Dirk Hohndel
922c945f5a QML UI: more hacking around with git progress reporting
I gave up on the magic numbers and instead report simply linear progress.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-05 23:39:54 -07:00
Dirk Hohndel
f869ce51b4 git storage: add explanation for fast forward to remote
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-05 21:13:27 -07:00
Dirk Hohndel
7be962bfc2 Move subsurface-core to core and qt-mobile to mobile-widgets
Having subsurface-core as a directory name really messes with
autocomplete and is obviously redundant. Simmilarly, qt-mobile caused an
autocomplete conflict and also was inconsistent with the desktop-widget
name for the directory containing the "other" UI.

And while cleaning up the resulting change in the path name for include
files, I decided to clean up those even more to make them consistent
overall.

This could have been handled in more commits, but since this requires a
make clean before the build, it seemed more sensible to do it all in one.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-04 22:33:58 -07:00
Renamed from subsurface-core/git-access.c (Browse further)