diff options
36 files changed, 216 insertions, 185 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 */ diff --git a/desktop-widgets/divelogimportdialog.cpp b/desktop-widgets/divelogimportdialog.cpp index 6965da06c..f1e616514 100644 --- a/desktop-widgets/divelogimportdialog.cpp +++ b/desktop-widgets/divelogimportdialog.cpp @@ -905,10 +905,10 @@ void DiveLogImportDialog::on_buttonBox_accepted() if (ui->knownImports->currentText() != "Manual import") { for (int i = 0; i < fileNames.size(); ++i) { if (ui->knownImports->currentText() == "Seabear CSV") { - parse_seabear_log(qPrintable(fileNames[i]), &table, &trips); + parse_seabear_log(qPrintable(fileNames[i]), &table, &trips, &dive_site_table); } else if (ui->knownImports->currentText() == "Poseidon MkVI") { QPair<QString, QString> pair = poseidonFileNames(fileNames[i]); - parse_txt_file(qPrintable(pair.second), qPrintable(pair.first), &table, &trips); + parse_txt_file(qPrintable(pair.second), qPrintable(pair.first), &table, &trips, &dive_site_table); } else { char *params[49]; int pnr = 0; @@ -925,7 +925,7 @@ void DiveLogImportDialog::on_buttonBox_accepted() pnr = setup_csv_params(r, params, pnr); parse_csv_file(qPrintable(fileNames[i]), params, pnr - 1, specialCSV.contains(ui->knownImports->currentIndex()) ? qPrintable(CSVApps[ui->knownImports->currentIndex()].name) : "csv", - &table, &trips); + &table, &trips, &dive_site_table); } } } else { @@ -989,7 +989,7 @@ void DiveLogImportDialog::on_buttonBox_accepted() params[pnr++] = intdup(r.indexOf(tr("Rating"))); params[pnr++] = NULL; - parse_manual_file(qPrintable(fileNames[i]), params, pnr - 1, &table, &trips); + parse_manual_file(qPrintable(fileNames[i]), params, pnr - 1, &table, &trips, &dive_site_table); } else { char *params[51]; int pnr = 0; @@ -1006,7 +1006,7 @@ void DiveLogImportDialog::on_buttonBox_accepted() pnr = setup_csv_params(r, params, pnr); parse_csv_file(qPrintable(fileNames[i]), params, pnr - 1, specialCSV.contains(ui->knownImports->currentIndex()) ? qPrintable(CSVApps[ui->knownImports->currentIndex()].name) : "csv", - &table, &trips); + &table, &trips, &dive_site_table); } } } @@ -1019,7 +1019,7 @@ TagDragDelegate::TagDragDelegate(QObject *parent) : QStyledItemDelegate(parent) { } -QSize TagDragDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const +QSize TagDragDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const { QSize originalSize = QStyledItemDelegate::sizeHint(option, index); return originalSize + QSize(5,5); diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 5095ab130..8483dc3c4 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -551,7 +551,7 @@ void MainWindow::on_actionCloudstorageopen_triggered() showProgressBar(); QByteArray fileNamePtr = QFile::encodeName(filename); - if (!parse_file(fileNamePtr.data(), &dive_table, &trip_table)) + if (!parse_file(fileNamePtr.data(), &dive_table, &trip_table, &dive_site_table)) setCurrentFile(fileNamePtr.data()); process_loaded_dives(); Command::clear(); @@ -1651,7 +1651,7 @@ void MainWindow::importFiles(const QStringList fileNames) for (int i = 0; i < fileNames.size(); ++i) { fileNamePtr = QFile::encodeName(fileNames.at(i)); - parse_file(fileNamePtr.data(), &table, &trips); + parse_file(fileNamePtr.data(), &table, &trips, &dive_site_table); } QString source = fileNames.size() == 1 ? fileNames[0] : tr("multiple files"); Command::importDives(&table, &trips, IMPORT_MERGE_ALL_TRIPS, source); @@ -1668,7 +1668,7 @@ void MainWindow::loadFiles(const QStringList fileNames) showProgressBar(); for (int i = 0; i < fileNames.size(); ++i) { fileNamePtr = QFile::encodeName(fileNames.at(i)); - if (!parse_file(fileNamePtr.data(), &dive_table, &trip_table)) { + if (!parse_file(fileNamePtr.data(), &dive_table, &trip_table, &dive_site_table)) { setCurrentFile(fileNamePtr.data()); addRecentFile(fileNamePtr, false); } diff --git a/desktop-widgets/subsurfacewebservices.cpp b/desktop-widgets/subsurfacewebservices.cpp index 3d65d7686..4d438aa28 100644 --- a/desktop-widgets/subsurfacewebservices.cpp +++ b/desktop-widgets/subsurfacewebservices.cpp @@ -771,7 +771,7 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton *button) /* parse file and import dives */ struct dive_table table = { 0 }; struct trip_table trips = { 0 }; - parse_file(QFile::encodeName(zipFile.fileName()), &table, &trips); + parse_file(QFile::encodeName(zipFile.fileName()), &table, &trips, &dive_site_table); Command::importDives(&table, &trips, IMPORT_MERGE_ALL_TRIPS, QStringLiteral("divelogs.de")); /* store last entered user/pass in config */ diff --git a/export-html.cpp b/export-html.cpp index e6dabdc54..b0ee229f1 100644 --- a/export-html.cpp +++ b/export-html.cpp @@ -41,7 +41,7 @@ int main(int argc, char **argv) qDebug() << "need --source and --output"; exit(1); } - int ret = parse_file(qPrintable(source), &dive_table, &trip_table); + int ret = parse_file(qPrintable(source), &dive_table, &trip_table, &dive_site_table); if (ret) { fprintf(stderr, "parse_file returned %d\n", ret); exit(1); diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 8239bfc7a..9603a2ad0 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -272,7 +272,7 @@ void QMLManager::openLocalThenRemote(QString url) QByteArray fileNamePrt = QFile::encodeName(url); bool glo = git_local_only; git_local_only = true; - int error = parse_file(fileNamePrt.data(), &dive_table, &trip_table); + int error = parse_file(fileNamePrt.data(), &dive_table, &trip_table, &dive_site_table); git_local_only = glo; if (error) { appendTextToLog(QStringLiteral("loading dives from cache failed %1").arg(error)); @@ -341,7 +341,7 @@ void QMLManager::mergeLocalRepo() char *filename = NOCLOUD_LOCALSTORAGE; struct dive_table table = { 0 }; struct trip_table trips = { 0 }; - parse_file(filename, &table, &trips); + parse_file(filename, &table, &trips, &dive_site_table); add_imported_dives(&table, &trips, IMPORT_MERGE_ALL_TRIPS); } @@ -406,7 +406,7 @@ void QMLManager::finishSetup() QMLPrefs::instance()->setCredentialStatus(qPrefCloudStorage::CS_NOCLOUD); saveCloudCredentials(); appendTextToLog(tr("working in no-cloud mode")); - int error = parse_file(existing_filename, &dive_table, &trip_table); + int error = parse_file(existing_filename, &dive_table, &trip_table, &dive_site_table); if (error) { // we got an error loading the local file setNotificationText(tr("Error parsing local storage, giving up")); @@ -666,7 +666,7 @@ void QMLManager::loadDivesWithValidCredentials() error = git_load_dives(git, branch); } else { appendTextToLog(QString("didn't receive valid git repo, try again")); - error = parse_file(fileNamePrt.data(), &dive_table, &trip_table); + error = parse_file(fileNamePrt.data(), &dive_table, &trip_table, &dive_site_table); } if (!error) { report_error("filename is now %s", fileNamePrt.data()); diff --git a/tests/testdivesiteduplication.cpp b/tests/testdivesiteduplication.cpp index f70da5621..4b770d311 100644 --- a/tests/testdivesiteduplication.cpp +++ b/tests/testdivesiteduplication.cpp @@ -5,7 +5,7 @@ void TestDiveSiteDuplication::testReadV2() { - QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TwoTimesTwo.ssrf", &dive_table, &trip_table), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TwoTimesTwo.ssrf", &dive_table, &trip_table, &dive_site_table), 0); QCOMPARE(dive_site_table.nr, 2); } diff --git a/tests/testgitstorage.cpp b/tests/testgitstorage.cpp index dfe64a3b3..e4b22a713 100644 --- a/tests/testgitstorage.cpp +++ b/tests/testgitstorage.cpp @@ -79,7 +79,7 @@ void TestGitStorage::testGitStorageLocal() // test writing and reading back from local git storage git_repository *repo; git_libgit2_init(); - QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &dive_table, &trip_table), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &dive_table, &trip_table, &dive_site_table), 0); QFETCH(QString, testDirName); QFETCH(QString, prefixRead); QFETCH(QString, prefixWrite); @@ -92,7 +92,7 @@ void TestGitStorage::testGitStorageLocal() QCOMPARE(save_dives(qPrintable(repoNameWrite + "[test]")), 0); QCOMPARE(save_dives("./SampleDivesV3.ssrf"), 0); clear_dive_file_data(); - QCOMPARE(parse_file(qPrintable(repoNameRead + "[test]"), &dive_table, &trip_table), 0); + QCOMPARE(parse_file(qPrintable(repoNameRead + "[test]"), &dive_table, &trip_table, &dive_site_table), 0); QCOMPARE(save_dives("./SampleDivesV3viagit.ssrf"), 0); QFile org("./SampleDivesV3.ssrf"); org.open(QFile::ReadOnly); @@ -111,10 +111,10 @@ void TestGitStorage::testGitStorageCloud() // connect to the ssrftest repository on the cloud server // and repeat the same test as before with the local git storage QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]"); - QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &dive_table, &trip_table), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &dive_table, &trip_table, &dive_site_table), 0); QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0); clear_dive_file_data(); - QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table), 0); + QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0); QCOMPARE(save_dives("./SampleDivesV3viacloud.ssrf"), 0); QFile org("./SampleDivesV3.ssrf"); org.open(QFile::ReadOnly); @@ -135,8 +135,8 @@ void TestGitStorage::testGitStorageCloudOfflineSync() QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org")); QString localCacheRepo = localCacheDir + "[ssrftest@hohndel.org]"; // read the local repo from the previous test and add dive 10 - QCOMPARE(parse_file(qPrintable(localCacheRepo), &dive_table, &trip_table), 0); - QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test10.xml", &dive_table, &trip_table), 0); + QCOMPARE(parse_file(qPrintable(localCacheRepo), &dive_table, &trip_table, &dive_site_table), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test10.xml", &dive_table, &trip_table, &dive_site_table), 0); // calling process_loaded_dives() sorts the table, but calling add_imported_dives() // causes it to try to update the window title... let's not do that process_loaded_dives(); @@ -145,7 +145,7 @@ void TestGitStorage::testGitStorageCloudOfflineSync() QCOMPARE(save_dives("./SampleDivesV3plus10local.ssrf"), 0); clear_dive_file_data(); // open the cloud storage and compare - QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table), 0); + QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0); QCOMPARE(save_dives("./SampleDivesV3plus10viacloud.ssrf"), 0); QFile org("./SampleDivesV3plus10local.ssrf"); org.open(QFile::ReadOnly); @@ -163,7 +163,7 @@ void TestGitStorage::testGitStorageCloudOfflineSync() QDir localCacheDirectorySave(localCacheDir + "save"); QCOMPARE(localCacheDirectorySave.removeRecursively(), true); QCOMPARE(localCacheDirectory.rename(localCacheDir, localCacheDir + "save"), true); - QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table), 0); + QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0); QCOMPARE(save_dives("./SampleDivesV3plus10fromcloud.ssrf"), 0); org.close(); org.open(QFile::ReadOnly); @@ -184,15 +184,15 @@ void TestGitStorage::testGitStorageCloudMerge() QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]"); QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org")); QString localCacheRepoSave = localCacheDir + "save[ssrftest@hohndel.org]"; - QCOMPARE(parse_file(qPrintable(localCacheRepoSave), &dive_table, &trip_table), 0); - QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table, &trip_table), 0); + QCOMPARE(parse_file(qPrintable(localCacheRepoSave), &dive_table, &trip_table, &dive_site_table), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table, &trip_table, &dive_site_table), 0); process_loaded_dives(); QCOMPARE(save_dives(qPrintable(localCacheRepoSave)), 0); clear_dive_file_data(); // now we open the cloud storage repo and add a different dive to it - QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table), 0); - QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &dive_table, &trip_table), 0); + QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &dive_table, &trip_table, &dive_site_table), 0); process_loaded_dives(); QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0); clear_dive_file_data(); @@ -203,13 +203,13 @@ void TestGitStorage::testGitStorageCloudMerge() QCOMPARE(localCacheDirectory.removeRecursively(), true); QDir localCacheDirectorySave(localCacheDir + "save"); QCOMPARE(localCacheDirectory.rename(localCacheDir + "save", localCacheDir), true); - QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table), 0); + QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0); QCOMPARE(save_dives("./SampleDivesV3plus10-11-12-merged.ssrf"), 0); clear_dive_file_data(); - QCOMPARE(parse_file("./SampleDivesV3plus10local.ssrf", &dive_table, &trip_table), 0); - QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table, &trip_table), 0); + QCOMPARE(parse_file("./SampleDivesV3plus10local.ssrf", &dive_table, &trip_table, &dive_site_table), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table, &trip_table, &dive_site_table), 0); process_loaded_dives(); - QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &dive_table, &trip_table), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &dive_table, &trip_table, &dive_site_table), 0); process_loaded_dives(); QCOMPARE(save_dives("./SampleDivesV3plus10-11-12.ssrf"), 0); QFile org("./SampleDivesV3plus10-11-12-merged.ssrf"); @@ -231,7 +231,7 @@ void TestGitStorage::testGitStorageCloudMerge2() QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]"); QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org")); QString localCacheRepo = localCacheDir + "[ssrftest@hohndel.org]"; - QCOMPARE(parse_file(qPrintable(localCacheRepo), &dive_table, &trip_table), 0); + QCOMPARE(parse_file(qPrintable(localCacheRepo), &dive_table, &trip_table, &dive_site_table), 0); process_loaded_dives(); struct dive *dive = get_dive(1); delete_single_dive(1); @@ -247,7 +247,7 @@ void TestGitStorage::testGitStorageCloudMerge2() QCOMPARE(localCacheDirectory.rename(localCacheDir, localCacheDir + "save"), true); } // now we open the cloud storage repo and modify that first dive - QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table), 0); + QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0); process_loaded_dives(); dive = get_dive(1); QVERIFY(dive != NULL); @@ -263,7 +263,7 @@ void TestGitStorage::testGitStorageCloudMerge2() QCOMPARE(localCacheDirectory.removeRecursively(), true); QCOMPARE(localCacheDirectorySave.rename(localCacheDir + "save", localCacheDir), true); - QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table), 0); + QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0); QCOMPARE(save_dives("./SampleDivesMinus1-merged.ssrf"), 0); QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0); QFile org("./SampleDivesMinus1-merged.ssrf"); @@ -287,7 +287,7 @@ void TestGitStorage::testGitStorageCloudMerge3() QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]"); QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org")); QString localCacheRepo = localCacheDir + "[ssrftest@hohndel.org]"; - QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table), 0); + QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0); process_loaded_dives(); struct dive *dive = get_dive(0); QVERIFY(dive != 0); @@ -299,7 +299,7 @@ void TestGitStorage::testGitStorageCloudMerge3() QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0); clear_dive_file_data(); - QCOMPARE(parse_file(qPrintable(localCacheRepo), &dive_table, &trip_table), 0); + QCOMPARE(parse_file(qPrintable(localCacheRepo), &dive_table, &trip_table, &dive_site_table), 0); process_loaded_dives(); dive = get_dive(0); dive->notes = strdup("Create multi line dive notes\nDifferent line 2 and removed 3-5\n\nThat should be enough"); @@ -318,7 +318,7 @@ void TestGitStorage::testGitStorageCloudMerge3() QCOMPARE(localCacheDirectory.rename(localCacheDir, localCacheDir + "save"), true); } // now we open the cloud storage repo and modify those first dive notes differently - QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table), 0); + QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0); process_loaded_dives(); dive = get_dive(0); dive->notes = strdup("Completely different dive notes\nBut also multi line"); @@ -336,7 +336,7 @@ void TestGitStorage::testGitStorageCloudMerge3() QCOMPARE(localCacheDirectory.removeRecursively(), true); QCOMPARE(localCacheDirectorySave.rename(localCacheDir + "save", localCacheDir), true); - QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table), 0); + QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0); QCOMPARE(save_dives("./SampleDivesMerge3.ssrf"), 0); // we are not trying to compare this to a pre-determined result... what this test // checks is that there are no parsing errors with the merge diff --git a/tests/testmerge.cpp b/tests/testmerge.cpp index 7b1e84149..70f22ee73 100644 --- a/tests/testmerge.cpp +++ b/tests/testmerge.cpp @@ -23,9 +23,9 @@ void TestMerge::testMergeEmpty() */ struct dive_table table = { 0 }; struct trip_table trips = { 0 }; - QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table, &trips), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table, &trips, &dive_site_table), 0); add_imported_dives(&table, &trips, IMPORT_MERGE_ALL_TRIPS); - QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table, &trips), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table, &trips, &dive_site_table), 0); add_imported_dives(&table, &trips, IMPORT_MERGE_ALL_TRIPS); QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0); QFile org(SUBSURFACE_TEST_DATA "/dives/test47+48.xml"); @@ -48,9 +48,9 @@ void TestMerge::testMergeBackwards() */ struct dive_table table = { 0 }; struct trip_table trips = { 0 }; - QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table, &trips), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table, &trips, &dive_site_table), 0); add_imported_dives(&table, &trips, IMPORT_MERGE_ALL_TRIPS); - QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table, &trips), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table, &trips, &dive_site_table), 0); add_imported_dives(&table, &trips, IMPORT_MERGE_ALL_TRIPS); QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0); QFile org(SUBSURFACE_TEST_DATA "/dives/test47+48.xml"); diff --git a/tests/testparse.cpp b/tests/testparse.cpp index 2a90f5a0f..0a751cf11 100644 --- a/tests/testparse.cpp +++ b/tests/testparse.cpp @@ -107,7 +107,7 @@ int TestParse::parseCSV(int units, std::string file) params[pnr++] = intdup(-1); params[pnr++] = NULL; - return parse_manual_file(file.c_str(), params, pnr - 1, &dive_table, &trip_table); + return parse_manual_file(file.c_str(), params, pnr - 1, &dive_table, &trip_table, &dive_site_table); } int TestParse::parseDivingLog() @@ -118,7 +118,7 @@ int TestParse::parseDivingLog() int ret = sqlite3_open(SUBSURFACE_TEST_DATA "/dives/TestDivingLog4.1.1.sql", &_sqlite3_handle); if (ret == 0) - ret = parse_divinglog_buffer(_sqlite3_handle, 0, 0, 0, &dive_table, &trip_table); + ret = parse_divinglog_buffer(_sqlite3_handle, 0, 0, 0, &dive_table, &trip_table, &dive_site_table); else fprintf(stderr, "Can't open sqlite3 db: " SUBSURFACE_TEST_DATA "/dives/TestDivingLog4.1.1.sql"); @@ -128,13 +128,13 @@ int TestParse::parseDivingLog() int TestParse::parseV2NoQuestion() { // parsing of a V2 file should work - return parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table); + return parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, &dive_site_table); } int TestParse::parseV3() { // parsing of a V3 files should succeed - return parse_file(SUBSURFACE_TEST_DATA "/dives/test42.xml", &dive_table, &trip_table); + return parse_file(SUBSURFACE_TEST_DATA "/dives/test42.xml", &dive_table, &trip_table, &dive_site_table); } void TestParse::testParse() @@ -159,7 +159,7 @@ void TestParse::testParse() void TestParse::testParseDM4() { QCOMPARE(sqlite3_open(SUBSURFACE_TEST_DATA "/dives/TestDiveDM4.db", &_sqlite3_handle), 0); - QCOMPARE(parse_dm4_buffer(_sqlite3_handle, 0, 0, 0, &dive_table, &trip_table), 0); + QCOMPARE(parse_dm4_buffer(_sqlite3_handle, 0, 0, 0, &dive_table, &trip_table, &dive_site_table), 0); QCOMPARE(save_dives("./testdm4out.ssrf"), 0); FILE_COMPARE("./testdm4out.ssrf", @@ -169,7 +169,7 @@ void TestParse::testParseDM4() void TestParse::testParseDM5() { QCOMPARE(sqlite3_open(SUBSURFACE_TEST_DATA "/dives/TestDiveDM5.db", &_sqlite3_handle), 0); - QCOMPARE(parse_dm5_buffer(_sqlite3_handle, 0, 0, 0, &dive_table, &trip_table), 0); + QCOMPARE(parse_dm5_buffer(_sqlite3_handle, 0, 0, 0, &dive_table, &trip_table, &dive_site_table), 0); QCOMPARE(save_dives("./testdm5out.ssrf"), 0); FILE_COMPARE("./testdm5out.ssrf", @@ -216,7 +216,7 @@ void TestParse::testParseHUDC() params[pnr++] = NULL; QCOMPARE(parse_csv_file(SUBSURFACE_TEST_DATA "/dives/TestDiveSeabearHUDC.csv", - params, pnr - 1, "csv", &dive_table, &trip_table), + params, pnr - 1, "csv", &dive_table, &trip_table, &dive_site_table), 0); QCOMPARE(dive_table.nr, 1); @@ -261,7 +261,7 @@ void TestParse::testParseNewFormat() "/dives/") .append(files.at(i)) .toLatin1() - .data(), &dive_table, &trip_table), + .data(), &dive_table, &trip_table, &dive_site_table), 0); QCOMPARE(dive_table.nr, i + 1); } @@ -280,7 +280,7 @@ void TestParse::testParseDLD() QString filename = SUBSURFACE_TEST_DATA "/dives/TestDiveDivelogsDE.DLD"; QVERIFY(readfile(filename.toLatin1().data(), &mem) > 0); - QVERIFY(try_to_open_zip(filename.toLatin1().data(), &dive_table, &trip_table) > 0); + QVERIFY(try_to_open_zip(filename.toLatin1().data(), &dive_table, &trip_table, &dive_site_table) > 0); fprintf(stderr, "number of dives from DLD: %d \n", dive_table.nr); @@ -300,8 +300,8 @@ void TestParse::testParseMerge() /* * check that we correctly merge mixed cylinder dives */ - QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/ostc.xml", &dive_table, &trip_table), 0); - QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/vyper.xml", &dive_table, &trip_table), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/ostc.xml", &dive_table, &trip_table, &dive_site_table), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/vyper.xml", &dive_table, &trip_table, &dive_site_table), 0); QCOMPARE(save_dives("./testmerge.ssrf"), 0); FILE_COMPARE("./testmerge.ssrf", SUBSURFACE_TEST_DATA "/dives/mergedVyperOstc.xml"); @@ -367,12 +367,12 @@ int TestParse::parseCSVmanual(int units, std::string file) params[pnr++] = intdup(units); params[pnr++] = NULL; - return parse_manual_file(file.c_str(), params, pnr - 1, &dive_table, &trip_table); + return parse_manual_file(file.c_str(), params, pnr - 1, &dive_table, &trip_table, &dive_site_table); } void TestParse::exportCSVDiveDetails() { - parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table); + parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, &dive_site_table); export_dives_xslt("testcsvexportmanual.csv", 0, 0, "xml2manualcsv.xslt", false); export_dives_xslt("testcsvexportmanualimperial.csv", 0, 1, "xml2manualcsv.xslt", false); @@ -416,12 +416,12 @@ int TestParse::parseCSVprofile(int units, std::string file) params[pnr++] = intdup(units); params[pnr++] = NULL; - return parse_csv_file(file.c_str(), params, pnr - 1, "csv", &dive_table, &trip_table); + return parse_csv_file(file.c_str(), params, pnr - 1, "csv", &dive_table, &trip_table, &dive_site_table); } void TestParse::exportCSVDiveProfile() { - parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table); + parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, &dive_site_table); export_dives_xslt("testcsvexportprofile.csv", 0, 0, "xml2csv.xslt", false); export_dives_xslt("testcsvexportprofileimperial.csv", 0, 1, "xml2csv.xslt", false); @@ -439,13 +439,13 @@ void TestParse::exportCSVDiveProfile() void TestParse::exportUDDF() { - parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table); + parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, &dive_site_table); export_dives_xslt("testuddfexport.uddf", 0, 1, "uddf-export.xslt", false); clear_dive_file_data(); - parse_file("testuddfexport.uddf", &dive_table, &trip_table); + parse_file("testuddfexport.uddf", &dive_table, &trip_table, &dive_site_table); export_dives_xslt("testuddfexport2.uddf", 0, 1, "uddf-export.xslt", false); FILE_COMPARE("testuddfexport.uddf", @@ -510,7 +510,7 @@ void TestParse::parseDL7() clear_dive_file_data(); QCOMPARE(parse_csv_file(SUBSURFACE_TEST_DATA "/dives/DL7.zxu", - params, pnr - 1, "DL7", &dive_table, &trip_table), + params, pnr - 1, "DL7", &dive_table, &trip_table, &dive_site_table), 0); QCOMPARE(dive_table.nr, 3); diff --git a/tests/testparseperformance.cpp b/tests/testparseperformance.cpp index c850892ff..64625f269 100644 --- a/tests/testparseperformance.cpp +++ b/tests/testparseperformance.cpp @@ -63,7 +63,7 @@ void TestParsePerformance::parseSsrf() return; } QBENCHMARK { - parse_file(SUBSURFACE_TEST_DATA "/dives/large-anon.ssrf", &dive_table, &trip_table); + parse_file(SUBSURFACE_TEST_DATA "/dives/large-anon.ssrf", &dive_table, &trip_table, &dive_site_table); } } @@ -74,12 +74,12 @@ void TestParsePerformance::parseGit() // first parse this once to populate the local cache - this way network // effects don't dominate the parse time - parse_file(LARGE_TEST_REPO "[git]", &dive_table, &trip_table); + parse_file(LARGE_TEST_REPO "[git]", &dive_table, &trip_table, &dive_site_table); cleanup(); QBENCHMARK { - parse_file(LARGE_TEST_REPO "[git]", &dive_table, &trip_table); + parse_file(LARGE_TEST_REPO "[git]", &dive_table, &trip_table, &dive_site_table); } } diff --git a/tests/testpicture.cpp b/tests/testpicture.cpp index 4bb33bd84..0e369b937 100644 --- a/tests/testpicture.cpp +++ b/tests/testpicture.cpp @@ -23,7 +23,7 @@ void TestPicture::addPicture() struct picture *pic1, *pic2; verbose = 1; - QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test44.xml", &dive_table, &trip_table), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test44.xml", &dive_table, &trip_table, &dive_site_table), 0); dive = get_dive(0); // Pictures will be added to selected dives dive->selected = true; diff --git a/tests/testprofile.cpp b/tests/testprofile.cpp index 48483f9ff..a093c9fe9 100644 --- a/tests/testprofile.cpp +++ b/tests/testprofile.cpp @@ -4,7 +4,7 @@ void TestProfile::testRedCeiling() { - parse_file("../dives/deep.xml", &dive_table, &trip_table); + parse_file("../dives/deep.xml", &dive_table, &trip_table, &dive_site_table); } QTEST_GUILESS_MAIN(TestProfile) diff --git a/tests/testrenumber.cpp b/tests/testrenumber.cpp index 0b766f3cb..d674c4922 100644 --- a/tests/testrenumber.cpp +++ b/tests/testrenumber.cpp @@ -7,7 +7,7 @@ void TestRenumber::setup() { - QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &dive_table, &trip_table), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &dive_table, &trip_table, &dive_site_table), 0); process_loaded_dives(); } @@ -15,7 +15,7 @@ void TestRenumber::testMerge() { struct dive_table table = { 0 }; struct trip_table trips = { 0 }; - QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47b.xml", &table, &trip_table), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47b.xml", &table, &trip_table, &dive_site_table), 0); add_imported_dives(&table, &trips, IMPORT_MERGE_ALL_TRIPS); QCOMPARE(dive_table.nr, 1); QCOMPARE(unsaved_changes(), 1); @@ -26,7 +26,7 @@ void TestRenumber::testMergeAndAppend() { struct dive_table table = { 0 }; struct trip_table trips = { 0 }; - QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47c.xml", &table, &trip_table), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47c.xml", &table, &trip_table, &dive_site_table), 0); add_imported_dives(&table, &trips, IMPORT_MERGE_ALL_TRIPS); QCOMPARE(dive_table.nr, 2); QCOMPARE(unsaved_changes(), 1); |