summaryrefslogtreecommitdiffstats
path: root/core
AgeCommit message (Collapse)Author
2018-10-29Dive site: return pointer to dive_site in get_dive_site_*()Gravatar Berthold Stoeger
As a first step in removing dive-site uuids, change the interface of the get_dive_site_*() functions to return pointers instead of uuids. This makes code a bit more complicated in places where the uuid is extracted afterwards (needed NULL check). Nevertheless, these places should disappear once pointers instead of uuids are stored in the dive-structures. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-27qPref: reduce recompiles with every commitGravatar Dirk Hohndel
Including ssrf-version.h in an include file that a lot of files depend on caused a ton of unnecessary recompiles with every commit. This should reduce that problem. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-26Cleanup: remove dead code in qthelper.cppGravatar Berthold Stoeger
The reverseGeoLookup() function defined in qthelper.cpp has long ago moved to its own compilation unit. It is not even defined in the headers anymore. Remove it and the now unnecessary <QNetwork*> includes. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-25core: use nr of dives shown in tripMeta infoGravatar Dirk Hohndel
When creating a trip header (as it is used in the mobile app right now), we need to show the number of dives shown, not the total number of dives in that trip. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-25core: add seperate number of dives shown to the trip structureGravatar Dirk Hohndel
We assume that any dive that gets added to a trip initially gets shown. The filter logic then needs to make sure it adjusts this number (which then makes it easy to tell the user how many dives of that trip are visible with the current filter). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-25core: add ability to get underlying dive to DiveObjectHelperGravatar Dirk Hohndel
This feels a bit like cheating, but if we need to be able to make modifications to the underlying dive and only have the helper object (for example inside of a view model), doing everything through the helper object can turn into a real performance issue. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-23Mobile/filtering: add fullTextNoNotes to the dive object helperGravatar Dirk Hohndel
This way we can filter with and without the notes. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-23Mobile/filtering: add two preferences for filteringGravatar Dirk Hohndel
With this we can make it configurable if the search should include the notes field and if the search should be case sensitive or not. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-23Mobile/filter: add marker between entries in full text searchGravatar Dirk Hohndel
Otherwise we could match the end of one string and the beginning of the next, so having a buddy name Linus and a dive master named Alvin would be matched by USA. Also add Notes to the full text search (I had forgotten those earlier). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-23Mobile/filtering: full text filter, instead of just dive siteGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-23Parser: remove static variable location in import-cobalt.cGravatar Berthold Stoeger
A static variable was used to collect two parts of the location string. Instead, explicitly store these two parts in two different strings and concetenate them. One fewer variable and the program flow is thus hopefully more clear. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-23Parser: make parser (mostly) reentrantGravatar Berthold Stoeger
Introduce a parser_state structure, which describes (most) of the global parser state. Create such a structure in the entry routines to the parser and pass it down to the individual functions. The parser state is initialized and freed with the init_parser_state() and free_parser_state() functions. The main benefits are: 1) Isolation of parser state. 2) Keeping the global name space tidy. 3) Prevent memory leaks which could happen in truncated files by freeing all the parser state after parse. A somewhat controversial point might be that the individual parsing functions are split in those that need parser-state and those that don't. This means that there are now two versions of the MATCH macro, viz. one for the former and one for the latter. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-23Core: accept NULL-pointer in free_trip() and free_divesite()Gravatar Berthold Stoeger
This is consistent with most other free_*() functions in the core code and will make cleanup of parser state less verbose. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-23Core: export free_picture()Gravatar Berthold Stoeger
Export the free_picture() function from dive.c. The parser may need this in case of truncated files to free its temporary resources. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-22Parser: remove webservice related codeGravatar Berthold Stoeger
Recently, the subsurface webservice was removed. Remove the corresponding code in the parser. This removes a static variable, which was used to generate unique dive-site ids. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-21Parser: free city and country after useGravatar Berthold Stoeger
The variables country and city used in divinglog_place() were never freed. Free them when the pointers are reset. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-21Parser: free old string in utf8_stringGravatar Berthold Stoeger
The utf8_string() function is used to extract whitespace-trimmed strings. The function would happily overwrite the pointer to the old string, which could therefore leak (suppose an XML has redundant attributes). Therefore preemtively free the string output parameter. This makes it of course necessary to only pass in NULL-initialized pointers or pointers to owned string. The code survives the current set of parser-tests. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-21Add 'location_t' data structureGravatar Linus Torvalds
Instead of having people treat latitude and longitude as separate things, just add a 'location_t' data structure that contains both. Almost all cases want to always act on them together. This is really just prep-work for adding a few more locations that we track: I want to add a entry/exit location to each dive (independent of the dive site) because of how the Garmin Descent gives us the information (and hopefully, some day, other dive computers too). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-19Preferences: wire-up the deco parametersGravatar Jan Mulder
The deco parameters need special treatment to wire them up to the underlying deco model code. And with the new preferences setup this is a lot of boilerplate. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-10-16Parser: don't leak extra data key/value pairsGravatar Berthold Stoeger
On parsing of dive computer extra data, key/value pairs are stored in global state. They are added to the dive computer with add_extra_data(), which makes a copy of the string. The local copies of the strings are never freed. free() the strings after storing them. The data still leaks in case of unfinished parsing of extra_data tags, but this will be taken care of in a subsequent commit. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-16Core: use free_dc_contents() in delete_current_divecomputer()Gravatar Berthold Stoeger
delete_current_divecomputer() had some duplicate code to release dive-computer resources. Use the free_dc_contents() function instead. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-16Core: copy / free serial and fw_version items of struct divecomputerGravatar Berthold Stoeger
The serial and fw_version strings of struct divecomputer were copied by pointer. This worked because they were never freed or modified. Instead, do a deep copy of the strings and free them when appropriate. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-16Core: copy and free extra_data of dive computer structureGravatar Berthold Stoeger
On dive computer copy, the extra data (a list of key/value pairs) was simply copied as a pointer. This worked because the list was never freed nor modified. Copy and free the list on dive computer copy and free, respectively. This made it necessary to move the STRUCTURE_LIST_* macros up in the dive.c file. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-15Core: fix broken commit e5dca8228eGravatar Berthold Stoeger
In commit e5dca8228e6b60cac5957726700c66d0565c064e a fixed order of the arguments to merge_dives() was introduced: first dive old, second dive downloaded. This made the dl variable, which pointed to the downloaded dive useless. One instance was forgotten, which led to a null-dereference. Remove. Reported-by: Dirk Hohndel <dirk@hohndel.org> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-15Cleanup: make xml_parsing_units local to parse-xml.cGravatar Berthold Stoeger
xml_parsing_units stores the units of the currently parsed XML file. It is not used outside of parse-xml.c. Therefore, make it of static linkage and remove the declaration from dive.h. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-15Cleanup: remove apparently dead code in sanitize_cylinder_type()Gravatar Berthold Stoeger
sanitize_cylinder_type(), which is indirectly called from fixup_dive(), had ft^3 -> mliter conversion code, which was executed on the condition "xml_parsing_units.volume == CUFT". But nowhere in the code base would xml_parsing_units.volume ever be set to non-metric. Moreover, xml_parsing_units reflects the units of the latest parsed XML file, but fixup_dive() is called in numerous contexts not related to XML parsing. Therefore, the whole piece of code seems highly questionable. Remove this code. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-15Parser: fix leakage of dive-site and dive dataGravatar Berthold Stoeger
Dive site data was collected in "cur_dive_site", which was then merged into an existing or a new dive site. But only the struct dive_site pointed to by "cur_dive_site" and the taxonomy data were freed, not the textual data such as name or description. Therefore, split out the approrpriate free-ing from the delete_dive_site() function and call that instead of a simple free(). A similar situation occured for dives that would not be added to the dive-table because they were deemed incomplete. Use free_dive() here instead of a simple free() too. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-15deco: _really_ make sure the deco state is fully initializedGravatar Linus Torvalds
I incorrectly thought that 'ci_pointing_to_guiding_tissue' was the only missing initialization, because that is the only one valgrind pointed at. ... that is, until I started looking at a few more dives, which showed that there were other parts tht weren't initialized either, like double tolerated_by_tissue[16]; double tissue_inertgas_saturation[16]; double crushing_onset_tension[16]; // total inert gas tension in the t* moment so just make sure to clear the whole data structure, to avoid any random behavior due to uninitialized deco state. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-15Selection: always make newly selected dive the current diveGravatar Berthold Stoeger
In select_dive(), the selected dive would only be made the current dive, if it wasn't previously selected. If multiple dives were selected and the user clicked on one of them which is not the current dive, then the current dive would be deselected and thus not be the current dive anymore. The only remaining dive would not be made the current dive, because it was already selected. End result: null dive shown. Therefore, always make the selected dive the current dive, even if it is already selected. Fixes #1792 Reported-by: Jan Mulder <jlmulder@xs4all.nl> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-15Core: copy whole list in copy_dc_renumber()Gravatar Berthold Stoeger
copy_dc_renumber() is an internal function to copy dive computers and renumber the cylinders. Since only the structure was copied, in the case of multi-dc dives, the merged dives shared the same computer. If one of them was freed, use-after-free crashes would happen. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-15deco: make sure deco state is fully initializedGravatar Linus Torvalds
This shouldn't have caused any issues, but it made for valgrind noise. So fix it. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-15Bluetooth cleanup: remove pointless download_modeGravatar Dirk Hohndel
This was used to track whether we had selected the native BT mode in the download dialog. But the information is redundant as we can tell from the device name whether this is a BT/BLE download or not. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-15Dive import: reset current_dive in process_imported_dives()Gravatar Berthold Stoeger
process_imported_dives() might delete the currently selected dives. This could lead to use-after-free problems. Therefore, reset the currently selected dive to the last dive. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-15Dive import: remove dive-to-be added from trip before deletionGravatar Berthold Stoeger
On dive import, dives to be added may be merged into already existing dives. In such a case, the dive to be added is deleted. Before doing so, it must be removed from the trip is belongs to to avoid corruption of the trip-list. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-15Dive list: make deep copy of picture list on mergeGravatar Berthold Stoeger
On merging make a deep copy of the picture list, to avoid a use-after-free crash after the orginal dive is deleted. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-15Dive list: fix crash on dive importGravatar Berthold Stoeger
In commit 8c2383b4952fa22d41745d29484462ed6a67112b dive merging was changed to not modify the original dive. On import, dives were then merged and the original deleted. The merge_weightsystem_info() was not adapted accordingly (deep copy of string instead of pointer), leading to a use-after-free crash. Resolve this by doing a deep copy. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-14Cleanup: constify get_dive_gas() and get_dive_gas_string()Gravatar Berthold Stoeger
There's no reason for the dive input-parameter being non-const. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-14Cleanup: free all data in clear_table()Gravatar Berthold Stoeger
Instead of calling free() on all dives, call free_dive() which also frees additional allocated data, not only the dive struct. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-14Cleanup: move clear_table() to divesite.cGravatar Berthold Stoeger
There were two declaration of clear_table(), one in dive.h and one in parse.h. The definition was in parse.c. Since the parser doesn't even use the function, move the function and its declaration to divelist.[ch] and remove the redundant declaration in dive.h. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-14Parser: remove global variable dive_idGravatar Berthold Stoeger
This variable was only used in the divinglog_dive() function. There, it was initialized right at the beginning and therefore there seems to be no point in conserving its value across function-calls. Make the variable local and remove the global version. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-14Cleanup: remove rebasing artefactsGravatar Berthold Stoeger
Embarrassingly, the header-comment in divelist.c contained a rebasing artefact. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-14Autogroup only when selectedGravatar Jan Mulder
Comits f427226b3b and 43c3885249f of the undo series introduced 2 calls of autogroup_dives() without checking the autogroup global boolean. This is a bug. An import from DC (for example) then triggers an autogrouping, the divelist is autogrouped, and the UI button is off. This commit solves this. I've chosen for a guard in the autogroup_dives() that now is a no-op when called when the user did not select autogrouping. In additon, simplified the other calls to this function, as we do not need to check before calling any more. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-10-13Dive site: use own copy of taxonomy in dive-site-edit widgetGravatar Berthold Stoeger
The dive-site-edit widget uses a copy of the to-be-edited site to compare with old values. Generally, this seems overkill (the original dive-site can be used for such a comparison). But one place where it can't simply be removed is the taxonomy, because the widget needs a place to store the unsaved data. Change the code to use an explicit taxonomy structure instead of the one provided in the copy. This should ultimately allow removal of the latter. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-13Dive site: un-globalize displayed_dive_siteGravatar Berthold Stoeger
The global object displayed_dive_site is used a a backing-store by the dive-site-edit widget. All external accesses were removed, therefore make the object local to the widget. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-13Dive site: explicitly init displayed_dive_site on show widgetGravatar Berthold Stoeger
The global object "displayed_dive_site" is used to store the old dive site data for the edit-dive-site widget. The fields of the widget were initialized from this object in the show event. Therefore the object was updated in numerous parts of the code to make sure that it was up-to-date. Instead, move the initialization of the object to the function that also initiatlizes the fields. Call this function explicitly before showing the widget. This makes the data-fow distinctly easier to understand. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-12core: recognize Aqualung i770R over BLEGravatar Dirk Hohndel
The name seems crazy until you realize that FQ is 0x4651 which is the model number of the i770R. And the six digits are the serial number of the device. Still crazy, but at least now you understand WHY. Thanks to Jef for decoding that. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-12Bluetooth: add helper to separate BT name and addressGravatar Dirk Hohndel
And restructure the existing "isBtAddress()" function in the process. Also add more tests. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-12Bluetooth: restart scan for different device on macOSGravatar Dirk Hohndel
This makes no sense, but apparently we need to start a fresh scan in order to be able to talk to a different BLE dive computer on the Mac. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-12Bluetooth: wait until we actually have device infoGravatar Dirk Hohndel
On macOS, we cannot connect to a BT/BLE device until we have scanned it. Right now this just sits quietly and waits, which given how long this can take is rather unsatisfying and might look like Subsurface is hung. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-12Bluetooth: start discovery if address isn't already knownGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>