summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-02-28 22:45:17 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-04-12 18:19:07 +0300
commit37146c5742503becf75468fb07aab56011cb9101 (patch)
tree666e4d609b3d9b882082fcc258d6d153c6c68fa5 /core
parent926b6895bbce7cc539ca4d0c3a425876dfa33d6b (diff)
downloadsubsurface-37146c5742503becf75468fb07aab56011cb9101.tar.gz
Parser: parse into custom dive site table
To extend the undo system to dive sites, the importers and downloaders must not parse directly into the global dive site table. Instead, pass a dive_site_table argument to parse into. For now, always pass the global dive_site_table so that this commit should not cause any functional change. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r--core/cochran.c3
-rw-r--r--core/datatrak.c10
-rw-r--r--core/dive.h18
-rw-r--r--core/divelist.c9
-rw-r--r--core/divesite.h1
-rw-r--r--core/downloadfromdcthread.cpp3
-rw-r--r--core/downloadfromdcthread.h1
-rw-r--r--core/file.c54
-rw-r--r--core/file.h10
-rw-r--r--core/import-cobalt.c5
-rw-r--r--core/import-csv.c35
-rw-r--r--core/import-csv.h10
-rw-r--r--core/import-divinglog.c5
-rw-r--r--core/import-shearwater.c6
-rw-r--r--core/import-suunto.c6
-rw-r--r--core/libdivecomputer.c6
-rw-r--r--core/libdivecomputer.h1
-rw-r--r--core/liquivision.c8
-rw-r--r--core/ostctools.c5
-rw-r--r--core/parse-xml.c44
-rw-r--r--core/parse.c10
-rw-r--r--core/parse.h1
-rw-r--r--core/uemis-downloader.c12
23 files changed, 147 insertions, 116 deletions
diff --git a/core/cochran.c b/core/cochran.c
index d89617431..5f7955fa5 100644
--- a/core/cochran.c
+++ b/core/cochran.c
@@ -791,10 +791,11 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
free(buf);
}
-int try_to_open_cochran(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips)
+int try_to_open_cochran(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
UNUSED(filename);
UNUSED(trips);
+ UNUSED(sites);
unsigned int i;
unsigned int mod;
unsigned int *offsets, dive1, dive2;
diff --git a/core/datatrak.c b/core/datatrak.c
index 4c2a910bc..312268d44 100644
--- a/core/datatrak.c
+++ b/core/datatrak.c
@@ -138,7 +138,7 @@ static dc_status_t dt_libdc_buffer(unsigned char *ptr, int prf_length, int dc_mo
* Parses a mem buffer extracting its data and filling a subsurface's dive structure.
* Returns a pointer to last position in buffer, or NULL on failure.
*/
-static unsigned char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive, long maxbuf)
+static unsigned char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive, struct dive_site_table *sites, long maxbuf)
{
int rc, profile_length, libdc_model;
char *tmp_notes_str = NULL;
@@ -193,10 +193,10 @@ static unsigned char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive
* Locality and Dive points.
*/
snprintf(buffer, sizeof(buffer), "%s, %s", locality, dive_point);
- ds = get_dive_site_by_name(buffer, &dive_site_table);
+ ds = get_dive_site_by_name(buffer, sites);
dt_dive->dive_site = ds;
if (!dt_dive->dive_site)
- dt_dive->dive_site = create_dive_site(buffer, dt_dive->when, &dive_site_table);
+ dt_dive->dive_site = create_dive_site(buffer, dt_dive->when, sites);
free(locality);
locality = NULL;
free(dive_point);
@@ -560,7 +560,7 @@ bail:
* Main function call from file.c memblock is allocated (and freed) there.
* If parsing is aborted due to errors, stores correctly parsed dives.
*/
-int datatrak_import(struct memblock *mem, struct dive_table *table, struct trip_table *trips)
+int datatrak_import(struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
UNUSED(trips);
unsigned char *runner;
@@ -582,7 +582,7 @@ int datatrak_import(struct memblock *mem, struct dive_table *table, struct trip_
while ((i < numdives) && ((long) runner < maxbuf)) {
struct dive *ptdive = alloc_dive();
- runner = dt_dive_parser(runner, ptdive, maxbuf);
+ runner = dt_dive_parser(runner, ptdive, sites, maxbuf);
if (runner == NULL) {
report_error(translate("gettextFromC", "Error: no dive"));
free(ptdive);
diff --git a/core/dive.h b/core/dive.h
index 874f724c7..d40e53043 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -475,19 +475,19 @@ struct dive *find_dive_n_near(timestamp_t when, int n, timestamp_t offset);
extern int match_one_dc(const struct divecomputer *a, const struct divecomputer *b);
extern void parse_xml_init(void);
-extern int parse_xml_buffer(const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, const char **params);
+extern int parse_xml_buffer(const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, const char **params);
extern void parse_xml_exit(void);
extern void set_filename(const char *filename);
-extern int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips);
-extern int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips);
-extern int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips);
-extern int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips);
-extern int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips);
-extern int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips);
-extern int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *table, struct trip_table *trips);
+extern int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
+extern int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
+extern int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
+extern int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
+extern int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
+extern int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
+extern int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
-extern int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips);
+extern int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
extern int save_dives(const char *filename);
extern int save_dives_logic(const char *filename, bool select_only, bool anonymize);
extern int save_dive(FILE *f, struct dive *dive, bool anonymize);
diff --git a/core/divelist.c b/core/divelist.c
index 0b772f201..8e1ba1628 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -1365,7 +1365,7 @@ static void insert_dive(struct dive_table *table, struct dive *d)
}
/*
- * Clear a dive_table and a trip_table. Think about generating these with macros.
+ * Clear a dive_table, trip_table and dive_site_table. Think about generating these with macros.
*/
void clear_table(struct dive_table *table)
{
@@ -1381,6 +1381,13 @@ static void clear_trip_table(struct trip_table *table)
table->nr = 0;
}
+void clear_dive_site_table(struct dive_site_table *ds_table)
+{
+ for (int i = 0; i < ds_table->nr; i++)
+ free_dive_site(ds_table->dive_sites[i]);
+ ds_table->nr = 0;
+}
+
/*
* Try to merge a new dive into the dive at position idx. Return
* true on success. On success, the old dive will be added to the
diff --git a/core/divesite.h b/core/divesite.h
index aca00f9b0..ba4cd32a5 100644
--- a/core/divesite.h
+++ b/core/divesite.h
@@ -64,6 +64,7 @@ unsigned int get_distance(const location_t *loc1, const location_t *loc2);
struct dive_site *find_or_create_dive_site_with_name(const char *name, timestamp_t divetime, struct dive_site_table *ds_table);
void merge_dive_sites(struct dive_site *ref, struct dive_site *dive_sites[], int count);
void purge_empty_dive_sites(struct dive_site_table *ds_table);
+void clear_dive_site_table(struct dive_site_table *ds_table);
#ifdef __cplusplus
}
diff --git a/core/downloadfromdcthread.cpp b/core/downloadfromdcthread.cpp
index 03268a0f0..5b336dee5 100644
--- a/core/downloadfromdcthread.cpp
+++ b/core/downloadfromdcthread.cpp
@@ -60,6 +60,7 @@ static void updateRememberedDCs()
DownloadThread::DownloadThread() : downloadTable({ 0 }),
+ diveSiteTable({ 0 }),
m_data(DCDeviceData::instance())
{
}
@@ -69,6 +70,7 @@ void DownloadThread::run()
auto internalData = m_data->internalData();
internalData->descriptor = descriptorLookup[m_data->vendor() + m_data->product()];
internalData->download_table = &downloadTable;
+ internalData->sites = &diveSiteTable;
internalData->btname = strdup(m_data->devBluetoothName().toUtf8());
if (!internalData->descriptor) {
qDebug() << "No download possible when DC type is unknown";
@@ -81,6 +83,7 @@ void DownloadThread::run()
#endif
qDebug() << "Starting download from " << (internalData->bluetooth_mode ? "BT" : internalData->devname);
clear_table(&downloadTable);
+ clear_dive_site_table(&diveSiteTable);
Q_ASSERT(internalData->download_table != nullptr);
const char *errorText;
diff --git a/core/downloadfromdcthread.h b/core/downloadfromdcthread.h
index 62d86ae67..e4cfb2351 100644
--- a/core/downloadfromdcthread.h
+++ b/core/downloadfromdcthread.h
@@ -70,6 +70,7 @@ public:
private:
struct dive_table downloadTable;
+ struct dive_site_table diveSiteTable;
DCDeviceData *m_data;
};
diff --git a/core/file.c b/core/file.c
index 89338e167..8a1a1ec1e 100644
--- a/core/file.c
+++ b/core/file.c
@@ -75,7 +75,7 @@ out:
}
-static void zip_read(struct zip_file *file, const char *filename, struct dive_table *table, struct trip_table *trips)
+static void zip_read(struct zip_file *file, const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
int size = 1024, n, read = 0;
char *mem = malloc(size);
@@ -86,11 +86,11 @@ static void zip_read(struct zip_file *file, const char *filename, struct dive_ta
mem = realloc(mem, size);
}
mem[read] = 0;
- (void) parse_xml_buffer(filename, mem, read, table, trips, NULL);
+ (void) parse_xml_buffer(filename, mem, read, table, trips, sites, NULL);
free(mem);
}
-int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips)
+int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
int success = 0;
/* Grr. libzip needs to re-open the file, it can't take a buffer */
@@ -105,7 +105,7 @@ int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_
/* skip parsing the divelogs.de pictures */
if (strstr(zip_get_name(zip, index, 0), "pictures/"))
continue;
- zip_read(file, filename, table, trips);
+ zip_read(file, filename, table, trips, sites);
zip_fclose(file);
success++;
}
@@ -126,7 +126,7 @@ static int db_test_func(void *param, int columns, char **data, char **column)
}
-static int try_to_open_db(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips)
+static int try_to_open_db(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
sqlite3 *handle;
char dm4_test[] = "select count(*) from sqlite_master where type='table' and name='Dive' and sql like '%ProfileBlob%'";
@@ -147,7 +147,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
/* Testing if DB schema resembles Suunto DM5 database format */
retval = sqlite3_exec(handle, dm5_test, &db_test_func, 0, NULL);
if (!retval) {
- retval = parse_dm5_buffer(handle, filename, mem->buffer, mem->size, table, trips);
+ retval = parse_dm5_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites);
sqlite3_close(handle);
return retval;
}
@@ -155,7 +155,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
/* Testing if DB schema resembles Suunto DM4 database format */
retval = sqlite3_exec(handle, dm4_test, &db_test_func, 0, NULL);
if (!retval) {
- retval = parse_dm4_buffer(handle, filename, mem->buffer, mem->size, table, trips);
+ retval = parse_dm4_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites);
sqlite3_close(handle);
return retval;
}
@@ -163,7 +163,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
/* Testing if DB schema resembles Shearwater database format */
retval = sqlite3_exec(handle, shearwater_test, &db_test_func, 0, NULL);
if (!retval) {
- retval = parse_shearwater_buffer(handle, filename, mem->buffer, mem->size, table, trips);
+ retval = parse_shearwater_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites);
sqlite3_close(handle);
return retval;
}
@@ -171,7 +171,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
/* Testing if DB schema resembles Shearwater cloud database format */
retval = sqlite3_exec(handle, shearwater_cloud_test, &db_test_func, 0, NULL);
if (!retval) {
- retval = parse_shearwater_cloud_buffer(handle, filename, mem->buffer, mem->size, table, trips);
+ retval = parse_shearwater_cloud_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites);
sqlite3_close(handle);
return retval;
}
@@ -179,7 +179,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
/* Testing if DB schema resembles Atomic Cobalt database format */
retval = sqlite3_exec(handle, cobalt_test, &db_test_func, 0, NULL);
if (!retval) {
- retval = parse_cobalt_buffer(handle, filename, mem->buffer, mem->size, table, trips);
+ retval = parse_cobalt_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites);
sqlite3_close(handle);
return retval;
}
@@ -187,7 +187,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
/* Testing if DB schema resembles Divinglog database format */
retval = sqlite3_exec(handle, divinglog_test, &db_test_func, 0, NULL);
if (!retval) {
- retval = parse_divinglog_buffer(handle, filename, mem->buffer, mem->size, table, trips);
+ retval = parse_divinglog_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites);
sqlite3_close(handle);
return retval;
}
@@ -214,7 +214,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
* Followed by the data values (all comma-separated, all one long line).
*/
static int open_by_filename(const char *filename, const char *fmt, struct memblock *mem,
- struct dive_table *table, struct trip_table *trips)
+ struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
// hack to be able to provide a comment for the translated string
static char *csv_warning = QT_TRANSLATE_NOOP3("gettextFromC",
@@ -223,38 +223,38 @@ static int open_by_filename(const char *filename, const char *fmt, struct memblo
/* Suunto Dive Manager files: SDE, ZIP; divelogs.de files: DLD */
if (!strcasecmp(fmt, "SDE") || !strcasecmp(fmt, "ZIP") || !strcasecmp(fmt, "DLD"))
- return try_to_open_zip(filename, table, trips);
+ return try_to_open_zip(filename, table, trips, sites);
/* CSV files */
if (!strcasecmp(fmt, "CSV"))
return report_error(translate("gettextFromC", csv_warning), filename);
/* Truly nasty intentionally obfuscated Cochran Anal software */
if (!strcasecmp(fmt, "CAN"))
- return try_to_open_cochran(filename, mem, table, trips);
+ return try_to_open_cochran(filename, mem, table, trips, sites);
/* Cochran export comma-separated-value files */
if (!strcasecmp(fmt, "DPT"))
- return try_to_open_csv(mem, CSV_DEPTH, table, trips);
+ return try_to_open_csv(mem, CSV_DEPTH, table, trips, sites);
if (!strcasecmp(fmt, "LVD"))
- return try_to_open_liquivision(filename, mem, table, trips);
+ return try_to_open_liquivision(filename, mem, table, trips, sites);
if (!strcasecmp(fmt, "TMP"))
- return try_to_open_csv(mem, CSV_TEMP, table, trips);
+ return try_to_open_csv(mem, CSV_TEMP, table, trips, sites);
if (!strcasecmp(fmt, "HP1"))
- return try_to_open_csv(mem, CSV_PRESSURE, table, trips);
+ return try_to_open_csv(mem, CSV_PRESSURE, table, trips, sites);
return 0;
}
-static int parse_file_buffer(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips)
+static int parse_file_buffer(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
int ret;
char *fmt = strrchr(filename, '.');
- if (fmt && (ret = open_by_filename(filename, fmt + 1, mem, table, trips)) != 0)
+ if (fmt && (ret = open_by_filename(filename, fmt + 1, mem, table, trips, sites)) != 0)
return ret;
if (!mem->size || !mem->buffer)
return report_error("Out of memory parsing file %s\n", filename);
- return parse_xml_buffer(filename, mem->buffer, mem->size, table, trips, NULL);
+ return parse_xml_buffer(filename, mem->buffer, mem->size, table, trips, sites, NULL);
}
int check_git_sha(const char *filename, struct git_repository **git_p, const char **branch_p)
@@ -291,7 +291,7 @@ int check_git_sha(const char *filename, struct git_repository **git_p, const cha
return 1;
}
-int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips)
+int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
struct git_repository *git;
const char *branch = NULL;
@@ -337,7 +337,7 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
fmt = strrchr(filename, '.');
if (fmt && (!strcasecmp(fmt + 1, "DB") || !strcasecmp(fmt + 1, "BAK") || !strcasecmp(fmt + 1, "SQL"))) {
- if (!try_to_open_db(filename, &mem, table, trips)) {
+ if (!try_to_open_db(filename, &mem, table, trips, sites)) {
free(mem.buffer);
return 0;
}
@@ -345,14 +345,14 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
/* Divesoft Freedom */
if (fmt && (!strcasecmp(fmt + 1, "DLF"))) {
- ret = parse_dlf_buffer(mem.buffer, mem.size, table, trips);
+ ret = parse_dlf_buffer(mem.buffer, mem.size, table, trips, sites);
free(mem.buffer);
return ret;
}
/* DataTrak/Wlog */
if (fmt && !strcasecmp(fmt + 1, "LOG")) {
- ret = datatrak_import(&mem, table, trips);
+ ret = datatrak_import(&mem, table, trips, sites);
free(mem.buffer);
return ret;
}
@@ -360,11 +360,11 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
/* OSTCtools */
if (fmt && (!strcasecmp(fmt + 1, "DIVE"))) {
free(mem.buffer);
- ostctools_import(filename, table, trips);
+ ostctools_import(filename, table, trips, sites);
return 0;
}
- ret = parse_file_buffer(filename, &mem, table, trips);
+ ret = parse_file_buffer(filename, &mem, table, trips, sites);
free(mem.buffer);
return ret;
}
diff --git a/core/file.h b/core/file.h
index d16a94f40..a570e1330 100644
--- a/core/file.h
+++ b/core/file.h
@@ -10,13 +10,13 @@ struct memblock {
#ifdef __cplusplus
extern "C" {
#endif
-extern int try_to_open_cochran(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips);
-extern int try_to_open_liquivision(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips);
-extern int datatrak_import(struct memblock *mem, struct dive_table *table, struct trip_table *trips);
-extern void ostctools_import(const char *file, struct dive_table *table, struct trip_table *trips);
+extern int try_to_open_cochran(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
+extern int try_to_open_liquivision(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
+extern int datatrak_import(struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
+extern void ostctools_import(const char *file, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
extern int readfile(const char *filename, struct memblock *mem);
-extern int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips);
+extern int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
#ifdef __cplusplus
}
#endif
diff --git a/core/import-cobalt.c b/core/import-cobalt.c
index 9bb78d6fd..0836a9c00 100644
--- a/core/import-cobalt.c
+++ b/core/import-cobalt.c
@@ -197,7 +197,7 @@ static int cobalt_dive(void *param, int columns, char **data, char **column)
return 1;
}
sprintf(tmp, "%s / %s", location, location_site);
- state->cur_dive->dive_site = find_or_create_dive_site_with_name(tmp, state->cur_dive->when, &dive_site_table);
+ state->cur_dive->dive_site = find_or_create_dive_site_with_name(tmp, state->cur_dive->when, state->sites);
free(tmp);
}
free(location);
@@ -217,7 +217,7 @@ static int cobalt_dive(void *param, int columns, char **data, char **column)
int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
- struct dive_table *table, struct trip_table *trips)
+ struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
UNUSED(buffer);
UNUSED(size);
@@ -229,6 +229,7 @@ int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buffer, in
init_parser_state(&state);
state.target_table = table;
state.trips = trips;
+ state.sites = sites;
state.sql_handle = handle;
char get_dives[] = "select Id,strftime('%s',DiveStartTime),LocationId,'buddy','notes',Units,(MaxDepthPressure*10000/SurfacePressure)-10000,DiveMinutes,SurfacePressure,SerialNumber,'model' from Dive where IsViewDeleted = 0";
diff --git a/core/import-csv.c b/core/import-csv.c
index 341375851..998d0d2e6 100644
--- a/core/import-csv.c
+++ b/core/import-csv.c
@@ -3,6 +3,7 @@
#include <libdivecomputer/parser.h>
#include "dive.h"
+#include "ssrf.h"
#include "subsurface-string.h"
#include "divelist.h"
#include "file.h"
@@ -101,7 +102,8 @@ static char *parse_dan_new_line(char *buf, const char *NL)
}
static int try_to_xslt_open_csv(const char *filename, struct memblock *mem, const char *tag);
-static int parse_dan_format(const char *filename, char **params, int pnr, struct dive_table *table, struct trip_table *trips)
+static int parse_dan_format(const char *filename, char **params, int pnr, struct dive_table *table,
+ struct trip_table *trips, struct dive_site_table *sites)
{
int ret = 0, i;
size_t end_ptr = 0;
@@ -211,7 +213,7 @@ static int parse_dan_format(const char *filename, char **params, int pnr, struct
}
}
params[pnr_local] = NULL;
- ret |= parse_xml_buffer(filename, "<csv></csv>", 11, table, trips, (const char **)params);
+ ret |= parse_xml_buffer(filename, "<csv></csv>", 11, table, trips, sites, (const char **)params);
continue;
}
@@ -268,7 +270,7 @@ static int parse_dan_format(const char *filename, char **params, int pnr, struct
if (try_to_xslt_open_csv(filename, &mem_csv, "csv"))
return -1;
- ret |= parse_xml_buffer(filename, mem_csv.buffer, mem_csv.size, table, trips, (const char **)params);
+ ret |= parse_xml_buffer(filename, mem_csv.buffer, mem_csv.size, table, trips, sites, (const char **)params);
end_ptr += ptr - (char *)mem_csv.buffer;
free(mem_csv.buffer);
}
@@ -280,7 +282,8 @@ static int parse_dan_format(const char *filename, char **params, int pnr, struct
return ret;
}
-int parse_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate, struct dive_table *table, struct trip_table *trips)
+int parse_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate,
+ struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
int ret, i;
struct memblock mem;
@@ -300,7 +303,7 @@ int parse_csv_file(const char *filename, char **params, int pnr, const char *csv
mem.size = 0;
if (!strcmp("DL7", csvtemplate)) {
- return parse_dan_format(filename, params, pnr, table, trips);
+ return parse_dan_format(filename, params, pnr, table, trips, sites);
} else if (strcmp(params[0], "date")) {
time(&now);
timep = localtime(&now);
@@ -335,7 +338,7 @@ int parse_csv_file(const char *filename, char **params, int pnr, const char *csv
fprintf(stderr, "%s/xslt/csv2xml.xslt -\n", SUBSURFACE_SOURCE);
}
#endif
- ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, (const char **)params);
+ ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, (const char **)params);
free(mem.buffer);
for (i = 0; params[i]; i += 2)
@@ -394,8 +397,9 @@ static int try_to_xslt_open_csv(const char *filename, struct memblock *mem, cons
return 0;
}
-int try_to_open_csv(struct memblock *mem, enum csv_format type, struct dive_table *table, struct trip_table *trips)
+int try_to_open_csv(struct memblock *mem, enum csv_format type, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
+ UNUSED(sites);
char *p = mem->buffer;
char *header[8];
int i, time;
@@ -486,8 +490,9 @@ static char *next_mkvi_key(const char *haystack)
return ret;
}
-int parse_txt_file(const char *filename, const char *csv, struct dive_table *table, struct trip_table *trips)
+int parse_txt_file(const char *filename, const char *csv, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
+ UNUSED(sites);
struct memblock memtxt, memcsv;
if (readfile(filename, &memtxt) < 0) {
@@ -779,15 +784,15 @@ int parse_txt_file(const char *filename, const char *csv, struct dive_table *tab
#define SBPARAMS 40
static int parse_seabear_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate,
- struct dive_table *table, struct trip_table *trips);
-int parse_seabear_log(const char *filename, struct dive_table *table, struct trip_table *trips)
+ struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
+int parse_seabear_log(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
char *params[SBPARAMS];
int pnr = 0;
pnr = parse_seabear_header(filename, params, pnr);
- if (parse_seabear_csv_file(filename, params, pnr, "csv", table, trips) < 0) {
+ if (parse_seabear_csv_file(filename, params, pnr, "csv", table, trips, sites) < 0) {
return -1;
}
@@ -796,7 +801,7 @@ int parse_seabear_log(const char *filename, struct dive_table *table, struct tri
static int parse_seabear_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate,
- struct dive_table *table, struct trip_table *trips)
+ struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
int ret, i;
struct memblock mem;
@@ -915,7 +920,7 @@ static int parse_seabear_csv_file(const char *filename, char **params, int pnr,
fprintf(stderr, "xslt/csv2xml.xslt\n");
}
- ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, (const char **)params);
+ ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, (const char **)params);
free(mem.buffer);
for (i = 0; params[i]; i += 2)
free(params[i + 1]);
@@ -923,7 +928,7 @@ static int parse_seabear_csv_file(const char *filename, char **params, int pnr,
return ret;
}
-int parse_manual_file(const char *filename, char **params, int pnr, struct dive_table *table, struct trip_table *trips)
+int parse_manual_file(const char *filename, char **params, int pnr, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
struct memblock mem;
time_t now;
@@ -962,7 +967,7 @@ int parse_manual_file(const char *filename, char **params, int pnr, struct dive_
fprintf(stderr, "%s/xslt/manualcsv2xml.xslt -\n", SUBSURFACE_SOURCE);
}
#endif
- ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, (const char **)params);
+ ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, (const char **)params);
free(mem.buffer);
for (i = 0; i < pnr - 2; ++i)
diff --git a/core/import-csv.h b/core/import-csv.h
index 2ae9cffdf..38bd30b62 100644
--- a/core/import-csv.h
+++ b/core/import-csv.h
@@ -21,12 +21,12 @@ enum csv_format {
extern "C" {
#endif
-int parse_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate, struct dive_table *table, struct trip_table *trips);
-int try_to_open_csv(struct memblock *mem, enum csv_format type, struct dive_table *table, struct trip_table *trips);
-int parse_txt_file(const char *filename, const char *csv, struct dive_table *table, struct trip_table *trips);
+int parse_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
+int try_to_open_csv(struct memblock *mem, enum csv_format type, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
+int parse_txt_file(const char *filename, const char *csv, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
-int parse_seabear_log(const char *filename, struct dive_table *table, struct trip_table *trips);
-int parse_manual_file(const char *filename, char **params, int pnr, struct dive_table *table, struct trip_table *trips);
+int parse_seabear_log(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
+int parse_manual_file(const char *filename, char **params, int pnr, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
#ifdef __cplusplus
}
diff --git a/core/import-divinglog.c b/core/import-divinglog.c
index 59ed75404..9ebd2b8ed 100644
--- a/core/import-divinglog.c
+++ b/core/import-divinglog.c
@@ -287,7 +287,7 @@ static int divinglog_dive(void *param, int columns, char **data, char **column)
state->cur_dive->when = (time_t)(atol(data[1]));
if (data[2])
- state->cur_dive->dive_site = find_or_create_dive_site_with_name(data[2], state->cur_dive->when, &dive_site_table);
+ state->cur_dive->dive_site = find_or_create_dive_site_with_name(data[2], state->cur_dive->when, state->sites);
if (data[3])
utf8_string(data[3], &state->cur_dive->buddy);
@@ -397,7 +397,7 @@ static int divinglog_dive(void *param, int columns, char **data, char **column)
int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
- struct dive_table *table, struct trip_table *trips)
+ struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
UNUSED(buffer);
UNUSED(size);
@@ -409,6 +409,7 @@ int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buffer,
init_parser_state(&state);
state.target_table = table;
state.trips = trips;
+ state.sites = sites;
state.sql_handle = handle;
char get_dives[] = "select Number,strftime('%s',Divedate || ' ' || ifnull(Entrytime,'00:00')),Country || ' - ' || City || ' - ' || Place,Buddy,Comments,Depth,Divetime,Divemaster,Airtemp,Watertemp,Weight,Divesuit,Computer,ID,Visibility,SupplyType from Logbook where UUID not in (select UUID from DeletedRecords)";
diff --git a/core/import-shearwater.c b/core/import-shearwater.c
index b4815d960..285b5034d 100644
--- a/core/import-shearwater.c
+++ b/core/import-shearwater.c
@@ -438,7 +438,7 @@ static int shearwater_cloud_dive(void *param, int columns, char **data, char **c
}
int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
- struct dive_table *table, struct trip_table *trips)
+ struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
UNUSED(buffer);
UNUSED(size);
@@ -450,6 +450,7 @@ int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer
init_parser_state(&state);
state.target_table = table;
state.trips = trips;
+ state.sites = sites;
state.sql_handle = handle;
// So far have not seen any sample rate in Shearwater Desktop
@@ -469,7 +470,7 @@ int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer
}
int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
- struct dive_table *table, struct trip_table *trips)
+ struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
UNUSED(buffer);
UNUSED(size);
@@ -481,6 +482,7 @@ int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *
init_parser_state(&state);
state.target_table = table;
state.trips = trips;
+ state.sites = sites;
state.sql_handle = handle;
char get_dives[] = "select l.number,strftime('%s', DiveDate),location||' / '||site,buddy,notes,imperialUnits,maxDepth,maxTime,startSurfacePressure,computerSerial,computerModel,d.diveId,l.sampleRateMs FROM dive_details AS d JOIN dive_logs AS l ON d.diveId=l.diveId";
diff --git a/core/import-suunto.c b/core/import-suunto.c
index df59fcc46..078593700 100644
--- a/core/import-suunto.c
+++ b/core/import-suunto.c
@@ -289,7 +289,7 @@ static int dm4_dive(void *param, int columns, char **data, char **column)
}
int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
- struct dive_table *table, struct trip_table *trips)
+ struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
UNUSED(buffer);
UNUSED(size);
@@ -301,6 +301,7 @@ int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buffer, int s
init_parser_state(&state);
state.target_table = table;
state.trips = trips;
+ state.sites = sites;
state.sql_handle = handle;
/* StartTime is converted from Suunto's nano seconds to standard
@@ -558,7 +559,7 @@ static int dm5_dive(void *param, int columns, char **data, char **column)
}
int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buffer, int size,
- struct dive_table *table, struct trip_table *trips)
+ struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
UNUSED(buffer);
UNUSED(size);
@@ -570,6 +571,7 @@ int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buffer, int s
init_parser_state(&state);
state.target_table = table;
state.trips = trips;
+ state.sites = sites;
state.sql_handle = handle;
/* StartTime is converted from Suunto's nano seconds to standard
diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c
index 668661ce8..0008f0dee 100644
--- a/core/libdivecomputer.c
+++ b/core/libdivecomputer.c
@@ -571,7 +571,7 @@ static void set_dc_serial(struct divecomputer *dc, const char *serial)
extern void parse_location(char *, location_t *);
-static void parse_string_field(struct dive *dive, dc_field_string_t *str)
+static void parse_string_field(device_data_t *devdata, struct dive *dive, dc_field_string_t *str)
{
// Our dive ID is the string hash of the "Dive ID" string
if (!strcmp(str->desc, "Dive ID")) {
@@ -596,7 +596,7 @@ static void parse_string_field(struct dive *dive, dc_field_string_t *str)
parse_location(line, &location);
if (location.lat.udeg && location.lon.udeg)
- dive->dive_site = create_dive_site_with_gps(str->value, &location, time(NULL), &dive_site_table);
+ dive->dive_site = create_dive_site_with_gps(str->value, &location, time(NULL), devdata->sites);
}
}
#endif
@@ -712,7 +712,7 @@ static dc_status_t libdc_header_parser(dc_parser_t *parser, device_data_t *devda
break;
if (!str.desc || !str.value)
break;
- parse_string_field(dive, &str);
+ parse_string_field(devdata, dive, &str);
}
#endif
diff --git a/core/libdivecomputer.h b/core/libdivecomputer.h
index 25c968afc..d3aafc87b 100644
--- a/core/libdivecomputer.h
+++ b/core/libdivecomputer.h
@@ -42,6 +42,7 @@ typedef struct dc_user_device_t
bool bluetooth_mode;
FILE *libdc_logfile;
struct dive_table *download_table;
+ struct dive_site_table *sites;
} device_data_t;
const char *errmsg (dc_status_t rc);
diff --git a/core/liquivision.c b/core/liquivision.c
index bec4b771b..019f7613c 100644
--- a/core/liquivision.c
+++ b/core/liquivision.c
@@ -132,7 +132,7 @@ static int handle_event_ver3(int code, const unsigned char *ps, unsigned int ps_
return skip;
}
-static void parse_dives (int log_version, const unsigned char *buf, unsigned int buf_size, struct dive_table *table)
+static void parse_dives(int log_version, const unsigned char *buf, unsigned int buf_size, struct dive_table *table, struct dive_site_table *sites)
{
unsigned int ptr = 0;
unsigned char model;
@@ -227,7 +227,7 @@ static void parse_dives (int log_version, const unsigned char *buf, unsigned int
// now that we have the dive time we can store the divesite
// (we need the dive time to create deterministic uuids)
if (found_divesite) {
- dive->dive_site = find_or_create_dive_site_with_name(location, dive->when, &dive_site_table);
+ dive->dive_site = find_or_create_dive_site_with_name(location, dive->when, sites);
free(location);
}
//unsigned int end_time = array_uint32_le(buf + ptr);
@@ -441,7 +441,7 @@ static void parse_dives (int log_version, const unsigned char *buf, unsigned int
free(dive);
}
-int try_to_open_liquivision(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips)
+int try_to_open_liquivision(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
UNUSED(filename);
UNUSED(trips);
@@ -466,7 +466,7 @@ int try_to_open_liquivision(const char *filename, struct memblock *mem, struct d
}
ptr += 4;
- parse_dives(log_version, buf + ptr, buf_size - ptr, table);
+ parse_dives(log_version, buf + ptr, buf_size - ptr, table, sites);
return 1;
}
diff --git a/core/ostctools.c b/core/ostctools.c
index f0fa6a634..21c58e537 100644
--- a/core/ostctools.c
+++ b/core/ostctools.c
@@ -4,6 +4,7 @@
#include <string.h>
#include "dive.h"
+#include "ssrf.h"
#include "subsurface-string.h"
#include "gettext.h"
#include "divelist.h"
@@ -35,8 +36,10 @@ static int ostc_prepare_data(int data_model, dc_family_t dc_fam, device_data_t *
* each file. So it's not necessary to iterate once and again on a parsing
* function. Actually there's only one kind of archive for every DC model.
*/
-void ostctools_import(const char *file, struct dive_table *divetable)
+void ostctools_import(const char *file, struct dive_table *divetable, struct trip_table *trips, struct dive_site_table *sites)
{
+ UNUSED(trips);
+ UNUSED(sites);
FILE *archive;
device_data_t *devdata = calloc(1, sizeof(device_data_t));
dc_family_t dc_fam;
diff --git a/core/parse-xml.c b/core/parse-xml.c
index 68b78a861..47b7c2296 100644
--- a/core/parse-xml.c
+++ b/core/parse-xml.c
@@ -558,11 +558,11 @@ static void hex_value(char *buffer, uint32_t *i)
*i = strtoul(buffer, NULL, 16);
}
-static void dive_site(char *buffer, struct dive_site **ds)
+static void dive_site(char *buffer, struct dive_site **ds, struct parser_state *state)
{
uint32_t uuid;
hex_value(buffer, &uuid);
- *ds = get_dive_site_by_uuid(uuid, &dive_site_table);
+ *ds = get_dive_site_by_uuid(uuid, state->sites);
}
static void get_notrip(char *buffer, bool *notrip)
@@ -983,9 +983,9 @@ static void divinglog_place(char *place, struct dive_site **ds, struct parser_st
state->city ? state->city : "",
state->country ? ", " : "",
state->country ? state->country : "");
- *ds = get_dive_site_by_name(buffer, &dive_site_table);
+ *ds = get_dive_site_by_name(buffer, state->sites);
if (!*ds)
- *ds = create_dive_site(buffer, state->cur_dive->when, &dive_site_table);
+ *ds = create_dive_site(buffer, state->cur_dive->when, state->sites);
// TODO: capture the country / city info in the taxonomy instead
free(state->city);
@@ -1129,7 +1129,7 @@ static degrees_t parse_degrees(char *buf, char **end)
return ret;
}
-static void gps_lat(char *buffer, struct dive *dive)
+static void gps_lat(char *buffer, struct dive *dive, struct parser_state *state)
{
char *end;
location_t location = { };
@@ -1137,7 +1137,7 @@ static void gps_lat(char *buffer, struct dive *dive)
location.lat = parse_degrees(buffer, &end);
if (!ds) {
- dive->dive_site = create_dive_site_with_gps(NULL, &location, dive->when, &dive_site_table);
+ dive->dive_site = create_dive_site_with_gps(NULL, &location, dive->when, state->sites);
} else {
if (ds->location.lat.udeg && ds->location.lat.udeg != location.lat.udeg)
fprintf(stderr, "Oops, changing the latitude of existing dive site id %8x name %s; not good\n", ds->uuid, ds->name ?: "(unknown)");
@@ -1145,7 +1145,7 @@ static void gps_lat(char *buffer, struct dive *dive)
}
}
-static void gps_long(char *buffer, struct dive *dive)
+static void gps_long(char *buffer, struct dive *dive, struct parser_state *state)
{
char *end;
location_t location = { };
@@ -1153,13 +1153,12 @@ static void gps_long(char *buffer, struct dive *dive)
location.lon = parse_degrees(buffer, &end);
if (!ds) {
- dive->dive_site = create_dive_site_with_gps(NULL, &location, dive->when, &dive_site_table);
+ dive->dive_site = create_dive_site_with_gps(NULL, &location, dive->when, state->sites);
} else {
if (ds->location.lon.udeg && ds->location.lon.udeg != location.lon.udeg)
fprintf(stderr, "Oops, changing the longitude of existing dive site id %8x name %s; not good\n", ds->uuid, ds->name ?: "(unknown)");
ds->location.lon = location.lon;
}
-
}
/* We allow either spaces or a comma between the decimal degrees */
@@ -1184,7 +1183,7 @@ static void gps_in_dive(char *buffer, struct dive *dive, struct parser_state *st
parse_location(buffer, &location);
if (!ds) {
// check if we have a dive site within 20 meters of that gps fix
- ds = get_dive_site_by_gps_proximity(&location, 20, &dive_site_table);
+ ds = get_dive_site_by_gps_proximity(&location, 20, state->sites);
if (ds) {
// found a site nearby; in case it turns out this one had a different name let's
@@ -1192,7 +1191,7 @@ static void gps_in_dive(char *buffer, struct dive *dive, struct parser_state *st
state->cur_location = location;
dive->dive_site = ds;
} else {
- dive->dive_site = create_dive_site_with_gps("", &location, dive->when, &dive_site_table);
+ dive->dive_site = create_dive_site_with_gps("", &location, dive->when, state->sites);
}
} else {
if (dive_site_has_gps_location(ds) &&
@@ -1235,7 +1234,7 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf, str
default:
break;
}
- if (MATCH("divesiteid", dive_site, &dive->dive_site))
+ if (MATCH_STATE("divesiteid", dive_site, &dive->dive_site))
return;
if (MATCH("number", get_index, &dive->number))
return;
@@ -1275,17 +1274,17 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf, str
return;
if (MATCH_STATE("Place", gps_in_dive, dive))
return;
- if (MATCH("latitude", gps_lat, dive))
+ if (MATCH_STATE("latitude", gps_lat, dive))
return;
- if (MATCH("sitelat", gps_lat, dive))
+ if (MATCH_STATE("sitelat", gps_lat, dive))
return;
- if (MATCH("lat", gps_lat, dive))
+ if (MATCH_STATE("lat", gps_lat, dive))
return;
- if (MATCH("longitude", gps_long, dive))
+ if (MATCH_STATE("longitude", gps_long, dive))
return;
- if (MATCH("sitelon", gps_long, dive))
+ if (MATCH_STATE("sitelon", gps_long, dive))
return;
- if (MATCH("lon", gps_long, dive))
+ if (MATCH_STATE("lon", gps_long, dive))
return;
if (MATCH_STATE("location", add_dive_site, dive))
return;
@@ -1636,7 +1635,8 @@ static const char *preprocess_divelog_de(const char *buffer)
}
int parse_xml_buffer(const char *url, const char *buffer, int size,
- struct dive_table *table, struct trip_table *trips, const char **params)
+ struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
+ const char **params)
{
UNUSED(size);
xmlDoc *doc;
@@ -1647,6 +1647,7 @@ int parse_xml_buffer(const char *url, const char *buffer, int size,
init_parser_state(&state);
state.target_table = table;
state.trips = trips;
+ state.sites = sites;
doc = xmlReadMemory(res, strlen(res), url, NULL, 0);
if (!doc)
doc = xmlReadMemory(res, strlen(res), url, "latin1", 0);
@@ -1688,7 +1689,7 @@ static timestamp_t parse_dlf_timestamp(unsigned char *buffer)
return offset + 946684800;
}
-int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *table, struct trip_table *trips)
+int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
unsigned char *ptr = buffer;
unsigned char event;
@@ -1710,6 +1711,7 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *tabl
init_parser_state(&state);
state.target_table = table;
state.trips = trips;
+ state.sites = sites;
// Check for the correct file magic
if (ptr[0] != 'D' || ptr[1] != 'i' || ptr[2] != 'v' || ptr[3] != 'E')
@@ -2120,7 +2122,7 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *tabl
/* Measure GPS */
state.cur_location.lat.udeg = (int)((ptr[7] << 24) + (ptr[6] << 16) + (ptr[5] << 8) + (ptr[4] << 0));
state.cur_location.lon.udeg = (int)((ptr[11] << 24) + (ptr[10] << 16) + (ptr[9] << 8) + (ptr[8] << 0));
- state.cur_dive->dive_site = create_dive_site_with_gps("DLF imported", &state.cur_location, state.cur_dive->when, &dive_site_table);
+ state.cur_dive->dive_site = create_dive_site_with_gps("DLF imported", &state.cur_location, state.cur_dive->when, state.sites);
break;
default:
break;
diff --git a/core/parse.c b/core/parse.c
index ba12cfddc..2763628f9 100644
--- a/core/parse.c
+++ b/core/parse.c
@@ -225,7 +225,7 @@ void dive_site_end(struct parser_state *state)
state->cur_dive_site->taxonomy.category = NULL;
}
if (state->cur_dive_site->uuid) {
- struct dive_site *ds = alloc_or_get_dive_site(state->cur_dive_site->uuid, &dive_site_table);
+ struct dive_site *ds = alloc_or_get_dive_site(state->cur_dive_site->uuid, state->sites);
merge_dive_site(ds, state->cur_dive_site);
if (verbose > 3)
@@ -419,7 +419,7 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state)
struct dive_site *ds = dive->dive_site;
if (!ds) {
// if the dive doesn't have a uuid, check if there's already a dive site by this name
- ds = get_dive_site_by_name(buffer, &dive_site_table);
+ ds = get_dive_site_by_name(buffer, state->sites);
}
if (ds) {
// we have a uuid, let's hope there isn't a different name
@@ -430,11 +430,11 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state)
// but wait, we could have gotten this one based on GPS coords and could
// have had two different names for the same site... so let's search the other
// way around
- struct dive_site *exact_match = get_dive_site_by_gps_and_name(buffer, &ds->location, &dive_site_table);
+ struct dive_site *exact_match = get_dive_site_by_gps_and_name(buffer, &ds->location, state->sites);
if (exact_match) {
dive->dive_site = exact_match;
} else {
- struct dive_site *newds = create_dive_site(buffer, dive->when, &dive_site_table);
+ struct dive_site *newds = create_dive_site(buffer, dive->when, state->sites);
dive->dive_site = newds;
if (has_location(&state->cur_location)) {
// we started this uuid with GPS data, so lets use those
@@ -449,7 +449,7 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state)
dive->dive_site = ds;
}
} else {
- dive->dive_site = create_dive_site(buffer, dive->when, &dive_site_table);
+ dive->dive_site = create_dive_site(buffer, dive->when, state->sites);
}
}
free(to_free);
diff --git a/core/parse.h b/core/parse.h
index f49fd96bc..eb07d9404 100644
--- a/core/parse.h
+++ b/core/parse.h
@@ -60,6 +60,7 @@ struct parser_state {
struct units xml_parsing_units;
struct dive_table *target_table; /* non-owning */
struct trip_table *trips; /* non-owning */
+ struct dive_site_table *sites; /* non-owning */
sqlite3 *sql_handle; /* for SQL based parsers */
event_allocation_t event_allocation;
diff --git a/core/uemis-downloader.c b/core/uemis-downloader.c
index 36cac2c5a..ef7e070ce 100644
--- a/core/uemis-downloader.c
+++ b/core/uemis-downloader.c
@@ -993,7 +993,7 @@ static bool process_raw_buffer(device_data_t *devdata, uint32_t deviceid, char *
} else if (!is_log && dive && !strcmp(tag, "divespot_id")) {
int divespot_id = atoi(val);
if (divespot_id != -1) {
- struct dive_site *ds = create_dive_site("from Uemis", dive->when, &dive_site_table);
+ struct dive_site *ds = create_dive_site("from Uemis", dive->when, devdata->sites);
dive->dive_site = ds;
uemis_mark_divelocation(dive->dc.diveid, divespot_id, ds);
}
@@ -1174,7 +1174,7 @@ static bool load_uemis_divespot(const char *mountpath, int divespot_id)
return false;
}
-static void get_uemis_divespot(const char *mountpath, int divespot_id, struct dive *dive)
+static void get_uemis_divespot(device_data_t *devdata, const char *mountpath, int divespot_id, struct dive *dive)
{
struct dive_site *nds = dive->dive_site;
@@ -1191,11 +1191,11 @@ static void get_uemis_divespot(const char *mountpath, int divespot_id, struct di
* we search all existing divesites if we have one with the same name already. The function
* returns the first found which is luckily not the newly created.
*/
- ods = get_dive_site_by_name(nds->name, &dive_site_table);
+ ods = get_dive_site_by_name(nds->name, devdata->sites);
if (ods) {
/* if the uuid's are the same, the new site is a duplicate and can be deleted */
if (nds->uuid != ods->uuid) {
- delete_dive_site(nds, &dive_site_table);
+ delete_dive_site(nds, devdata->sites);
dive->dive_site = ods;
}
}
@@ -1204,7 +1204,7 @@ static void get_uemis_divespot(const char *mountpath, int divespot_id, struct di
/* if we can't load the dive site details, delete the site we
* created in process_raw_buffer
*/
- delete_dive_site(dive->dive_site, &dive_site_table);
+ delete_dive_site(dive->dive_site, devdata->sites);
}
}
}
@@ -1257,7 +1257,7 @@ static bool get_matching_dive(int idx, char *newmax, int *uemis_mem_status, devi
#endif
int divespot_id = uemis_get_divespot_id_by_diveid(dive->dc.diveid);
if (divespot_id >= 0)
- get_uemis_divespot(mountpath, divespot_id, dive);
+ get_uemis_divespot(data, mountpath, divespot_id, dive);
} else {
/* in this case we found a deleted file, so let's increment */