Commit graph

399 commits

Author SHA1 Message Date
Dirk Hohndel
2e6afb8e89 Correctly handle the webservice userid in preferences
Because of the way that the webservice userid can be saved both in the
preferences and in a data file it was treated differently than other
preferences settings - which prevented the reset of the preferences from
actually clearing it.

This patch makes sure that if the preferences are reset the preferences UI
reflects that. To make this work the data file loading functions can no
longer be allowed to just simply clear out the userid preference value
just in case they might load a new one.

Fixes #939

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-06 08:53:54 +01:00
Anton Lundin
331a340780 Correct sign on Divesoft Freedom timestamps
I managed somehow to miss-read and by accident told Linus that the
timestamp was signed.

It is a unsigned uint32_t, so this corrects the mistake i tricked Linus
into making.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-04 16:29:35 +01:00
Linus Torvalds
769365b4db Clean up Divesoft Freedome time parsing
So Anton Lundin says that the 32-bit timestamp for the Divesoft Freedom
is indeed a signed offset from Jan 1, 2000.

This does that, but also extracts the whole thing into a helper function
and makes sure that there are no overflows at any point by using
"timestamp_t" in the whole series, and all the operations are "obviously
safe" in their types (ie no "unsigned char gets widened to 'int' and
then we shift it left by 24 bits").

Signed-off-by: Linus Torvalds <torvalds@linux-fundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-03 10:41:03 -04:00
Linus Torvalds
e964f533ff Fix 32-bit overflow in Divesoft Freedom time handling
Commit 31fb2e4c62 ("Avoid possible sign extension") handled the
problem when a "unsigned char" is shifted 24 bits left, and becomes a
"signed int".  By casting the result to uint32_t, that signed case won't
happen.

However, there were two bugs in that fix.

The first is the comment.  It's not that "timestamp_t" is signed that is
the problem.  No, the problem is inherent in the C expression

    (ptr[11] << 24)

where "ptr[11]" is an unsigned char.  In C arithmetic, unsigned char is
implicitly type-expanded to "int", so while it has a value between
0..255, when you shift it left by 24, you can get a *negative* "int" as
a result.

So it's actually "ptr[11]" that should have been cast to "unsigned", but
it so happens that you can do all the shifting and adding in "int", and
then cast the end result to "uint32_t" and you'll get the same value.
But at no point did "timestamp_t" matter.

The other bug was pre-existing and just not fixed.  When the code does
the "+ 946684800" (to turn the timestamp to be seconds from the start of
2000, into seconds since the "unix epoch", ie 1970) that arithmetic is
now done in that "uint32_t" (and used to be done in "int").

Which means that the addition can overflow in 32 bits *before* it is
cast to timestamp_t (which is 64 bits).

Admittedly that 32-bit overflow happens a bit later than the sign bit
gets set, but if we're worried aboout overflows, let's just do this
right.

In other words, we have a 32-bit unsigned offset since Jan 1, 2000, and
for the full range we need to do the epoch correction in 32 bits.
Because otherwise you fail in the year 2106 (32-bit unsigned unix epoch
time limit), even though the 32-bit seconds *should* work all the way
until the year 2136.

Of course, I'll be rather surprised if people still use the Divesoft
Freedom in the year 2106.  Or rather, I won't be surprised, because I'll
be dead.

But if we think that the signed problem matters (in the year 2068), then
dammit, we can extend it another 30 years.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-03 00:05:40 -04:00
Dirk Hohndel
31fb2e4c62 Avoid possible sign extension
Interesting theoretical bug (it'll be a while before we run into this
one).

Coverity CID 1307979

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-02 15:48:50 -04:00
Linus Torvalds
b5b7bdda81 Make add_single_dive() grow the divelist allocation if necessary
We only made sure the divelist allocation was big enough in
"record_dive_to_table()", but add_single_dive() can add entries too.

Now, in practice that never bit anybody, since

 (a) we allocate extra entries anyway, and it would be very unusual that
     the divelist table was exactly full

 (b) most "malloc()" implementations end up having their own slop on top
     of that

 (c) add_single_dive() was only used for merging dives, which actually
     ends up removing more divex than it adds (but it does add one first)

but when I'm starting to split dives, this will be a bigger issue in
practice.  And it was wrong.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-01 22:28:04 -04:00
Dirk Hohndel
edac07554c Make sure we don't create multiple dive sites with the same uuid
This shouldn't happen, but in case there is a logic error higher up in the
code somewhere, this will prevent it from happening, period.

If the code asks for a new dive site with a specific uuid, simply return
the existing dive site with that uuid.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-29 12:58:16 -04:00
Anton Lundin
647645d6e4 Better import of libdivecomputer universal xml
This teaches subsurface how to understand more fields in the xml that
libdivecomputers's universal tool generates.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-08 12:30:17 -07:00
Tim Wootton
5d92e2898c Capitalistion of GPS
Signed-off-by: Tim Wootton <tim@tee-jay.org.uk>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-05 07:43:12 -07:00
Dirk Hohndel
e0587cb6df Fix subtle bug in dive site import from V2 file
Assume your V2 file contains two locations with different name but
identical GPS location. "Blue Corner" and "Blue Corner, Palau". And you
have many dives there.

When reading a V2 file the GPS is read first and a dive site is looked up
based on that. Let's assume the lookup by gps finds "Blue Corner, Palau".

Now every time we get the "Blue Corner" site in the V2 file we look  up
the GPS, get "Blue Corner, Palau" as dive site, then read the name "Blue
Corner" and say "oops, different site" and create a new one. Resulting in
several dive sites named "Blue Corner" with identical GPS but different
UUID (as we add the dive time into the SHA for the deterministic UUID).

With this commit, if we have a dive site that matches the GPS but has a
different name, we check if we happen to have an exact match for the dive
site information from the XML file (and use it, if we have it) before
creating a new dive site.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-30 10:14:50 -07:00
Dirk Hohndel
e03b553e80 Make created dive site uuid deterministic
Having random uuids seemed like a good idea, but there are several
situations where they really cause problems. One is merging dive file
imports from V2 logfiles. Another is testing such imports.

Instead of making the uuid random we now hash the name and add the
timestamp of the first dive associated with this dive site to the hash
(first in this context is "first encountered" with no guarantee that it is
the chronologically first). This way V2 imports create deterministic uuids
but uuid conflicts are still extremely unlikely, even if the user has
multiple dive sites with the same name.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-25 10:43:48 -07:00
Miika Turkia
1bea48f9bd Fix bit shift on Suunto DB import
Let's do the bit shift properly and not by block size.

Fixes #906

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-09 23:55:03 -07:00
Miika Turkia
abbebef997 Divinglog import: ignore unsupported cylinders
Subsurface supports currently 8 cylinders, thus we should not attempt to
add more.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-03 22:21:19 -07:00
Salvador Cuñat
25f3038d40 RBT - Add save/load in xml file support
Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-30 07:43:16 -07:00
Miika Turkia
76fe262a0f Allow creating new dive site with specific uuid
Test cases require deterministic results and thus we should allow uuid
to be specified when needed.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-24 13:20:57 -07:00
Miika Turkia
0d2d91a28c Cobalt import: use find or create divesite
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-24 13:20:40 -07:00
Miika Turkia
c2b45ab1e2 Divinglog import: find or create divesite
We obviously should lookup if the dive site already exist before
creating a new one.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-24 13:20:31 -07:00
Miika Turkia
aa4ed491fd Divinglog import: fix maximum depth
Max depth is recorded in floating point in metadata.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-23 06:30:39 -07:00
Miika Turkia
5d12723656 Divinglog import: update O2sensors and dive mode
This is my best guess, and I have no sample logs that would prove my
assumption.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-17 08:51:04 -07:00
Miika Turkia
6e109a2129 Divinglog import: added setpoint
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-17 08:51:01 -07:00
Miika Turkia
5e439cef63 Divinglog import: add cns value
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-17 08:50:57 -07:00
Miika Turkia
70198ef11b Divinglog import: ppo2 sensor readings
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-17 08:50:49 -07:00
Miika Turkia
2ace3195f4 Divinglog import: stop (deco) time added
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-13 15:21:30 -07:00
Miika Turkia
2ec9002beb Divinglog import: include NDL information
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-13 15:21:30 -07:00
Miika Turkia
5dd0b1bad5 Divinglog import: show stop depth / ceiling
This shows the ceiling as stored by Divinglog. (I am not sure if it is
DC reported ceiling, or just a calculated one.)

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-13 15:21:30 -07:00
Miika Turkia
669a8085d9 Divinglog import: include heartbeat info
Note, that this patch is not tested with real data as I do not have log
that would include heartbeat available.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-13 15:21:30 -07:00
Dirk Hohndel
3478943f2f Fix memory handling for taxonomy data
The way we freed things and cleared out the variables potentially left
dangling data behind and could end up calling free on garbage data,
leading to random crashes.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-13 07:09:55 -07:00
Miika Turkia
c41fd91261 Divinglog import: generate gaschange events
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-12 13:58:17 -07:00
Miika Turkia
7fffe8aba0 Divinglog import: adding pressure samples
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-12 13:58:17 -07:00
Miika Turkia
e53897cd15 Divinglog import: grab information for cylinder 0
Cylinder 0 is stored on the Logbook table along with other dive metadata
(not in Tank table).

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-12 13:58:17 -07:00
Miika Turkia
c91ee860f2 Divinglog import: use dive ID as identifier
Since mapping cylinders requires use of dive ID, we might as well use
the ID to map the profile also.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-12 13:58:17 -07:00
Miika Turkia
a52fc86a1c Divinglog import: get cylinder information
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-12 13:58:17 -07:00
Miika Turkia
22b665cc14 Divinglog import: import temperature graph
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-12 13:58:17 -07:00
Miika Turkia
17bc868531 Divinglog import: add workload warning
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-12 13:58:17 -07:00
Miika Turkia
5bc4f974c5 Divinglog import: deco stop ignored event added
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-12 13:58:17 -07:00
Miika Turkia
0011d43711 Divinglog import: ascent warning added
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-12 13:58:16 -07:00
Miika Turkia
c91ecb62af Divinglog import: RBT warning event added
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-12 13:58:16 -07:00
Miika Turkia
495aab8f20 Divinglog import: in deco?
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-12 13:58:16 -07:00
Miika Turkia
90f7a6930a Divinglog import: parse depth from database
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-12 13:58:16 -07:00
Miika Turkia
c87d7d96b5 Divinglog import: import a bit more data from DB
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-12 13:58:16 -07:00
Miika Turkia
e98cbdf020 Divinglog import: basic dive info for DB import
This parses the basic metadata of a dive when importing Divinglog
database. (Discarding deleted dives is my best guess as I do not have
that in my sample dive.)

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-12 13:58:16 -07:00
Dirk Hohndel
08a451d24a More debug message cleanup
Remove several very noise messages on dive site handling (this seems to
work well now, so I think we can remove most of them - a couple were left
that indicate actual issues).

And also remove all the calls to "translate" when outputting data to
stderr. Error messages that indicate issues where the user will basically
have to come and ask the developers for help shouldn't be localized. They
should be in English to make it easier for us to figure out what's going
on.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-02 11:22:22 -07:00
Dirk Hohndel
bc8c54f1ee Rename enum values for taxonomy
This avoids confusion and namespace collisions.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-02 10:22:31 -07:00
Dirk Hohndel
f7b7d4c2df Geo taxonomy: save and load the taxonomy data with XML
If taxonomy data are available we are switching a dive site entry from
single item with attributes to an item that has children. This is
backwards compatible and older versions will simply ignore the children.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-01 12:38:40 -07:00
Tomaz Canabrava
7071bf0e23 Do not mess with dive location automatically
This might be what the user wanted, but also might not
be it. So wait for the user to request it manually.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-22 17:01:52 -07:00
Dirk Hohndel
2c0223fbb2 Fix missing curly braces that change control flow
Indentation thankfully is not the same as scope.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-21 22:00:21 -07:00
Dirk Hohndel
66375689b8 Prevent null dereference
In each case there are scenarios where we would have dereferenced NULL.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-21 21:53:53 -07:00
Dirk Hohndel
f5726c3d18 Fix a number of resource leaks
Free memory returned from parse_mkvi_value()
Free memory returned from printGPSCoords()
Free memory allocated in added_list and removed_list
Free memory allocated when adding suffix to dive site name
Free memory allocated in cache_deco_state()
Free memory allocated in build_filename()
Free memory allocated in get_utf8()
Free memory allocated in alloc_dive()
Free memory allocated as cache but never used

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-21 21:13:32 -07:00
Dirk Hohndel
de35c88683 Track minimum datafile version
Add infrastructure and helper functions to track minimum datafile version.
To make this information useful we need to keep the XML and git data
format versions in track moving forward.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-20 06:45:12 -07:00
Dirk Hohndel
c897b857fb We don't really need a long to count the dive sites
At least I hope not.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-17 11:42:15 -07:00