diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/datatrak.c | 2 | ||||
-rw-r--r-- | core/dive.c | 2 | ||||
-rw-r--r-- | core/divesite.c | 38 | ||||
-rw-r--r-- | core/divesite.h | 6 | ||||
-rw-r--r-- | core/gpslocation.cpp | 2 | ||||
-rw-r--r-- | core/import-cobalt.c | 2 | ||||
-rw-r--r-- | core/import-divinglog.c | 2 | ||||
-rw-r--r-- | core/libdivecomputer.c | 2 | ||||
-rw-r--r-- | core/liquivision.c | 13 | ||||
-rw-r--r-- | core/load-git.c | 4 | ||||
-rw-r--r-- | core/parse-xml.c | 10 | ||||
-rw-r--r-- | core/parse.c | 4 | ||||
-rw-r--r-- | core/uemis-downloader.c | 2 |
13 files changed, 33 insertions, 56 deletions
diff --git a/core/datatrak.c b/core/datatrak.c index 312268d44..fa5f3cbcd 100644 --- a/core/datatrak.c +++ b/core/datatrak.c @@ -196,7 +196,7 @@ static unsigned char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive 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, sites); + dt_dive->dive_site = create_dive_site(buffer, sites); free(locality); locality = NULL; free(dive_point); diff --git a/core/dive.c b/core/dive.c index 832f83759..bd7181361 100644 --- a/core/dive.c +++ b/core/dive.c @@ -4033,7 +4033,7 @@ static void dive_set_geodata_from_picture(struct dive *dive, struct picture *pic if (ds) { ds->location = picture->location; } else { - dive->dive_site = create_dive_site_with_gps("", &picture->location, dive->when, table); + dive->dive_site = create_dive_site_with_gps("", &picture->location, table); invalidate_dive_cache(dive); } } diff --git a/core/divesite.c b/core/divesite.c index 884ac9a7d..a71780faf 100644 --- a/core/divesite.c +++ b/core/divesite.c @@ -143,7 +143,7 @@ struct dive_site *alloc_dive_site() return ds; } -/* we never allow a second dive site with the same uuid */ +/* when parsing, dive sites are identified by uuid */ struct dive_site *alloc_or_get_dive_site(uint32_t uuid, struct dive_site_table *ds_table) { struct dive_site *ds; @@ -229,44 +229,27 @@ void delete_dive_site(struct dive_site *ds, struct dive_site_table *ds_table) free_dive_site(ds); } -static uint32_t create_divesite_uuid(const char *name, timestamp_t divetime) -{ - if (name == NULL) - name =""; - union { - unsigned char hash[20]; - uint32_t i; - } u; - SHA_CTX ctx; - SHA1_Init(&ctx); - SHA1_Update(&ctx, &divetime, sizeof(timestamp_t)); - SHA1_Update(&ctx, name, strlen(name)); - SHA1_Final(u.hash, &ctx); - // now return the first 32 of the 160 bit hash - return u.i; -} - /* allocate a new site and add it to the table */ -struct dive_site *create_dive_site(const char *name, timestamp_t divetime, struct dive_site_table *ds_table) +struct dive_site *create_dive_site(const char *name, struct dive_site_table *ds_table) { - uint32_t uuid = create_divesite_uuid(name, divetime); - struct dive_site *ds = alloc_or_get_dive_site(uuid, ds_table); + struct dive_site *ds = alloc_dive_site(); ds->name = copy_string(name); + add_dive_site_to_table(ds, ds_table); return ds; } /* same as before, but with GPS data */ -struct dive_site *create_dive_site_with_gps(const char *name, const location_t *loc, timestamp_t divetime, struct dive_site_table *ds_table) +struct dive_site *create_dive_site_with_gps(const char *name, const location_t *loc, struct dive_site_table *ds_table) { - uint32_t uuid = create_divesite_uuid(name, divetime); - struct dive_site *ds = alloc_or_get_dive_site(uuid, ds_table); + struct dive_site *ds = alloc_dive_site(); ds->name = copy_string(name); ds->location = *loc; + add_dive_site_to_table(ds, ds_table); return ds; } -/* a uuid is always present - but if all the other fields are empty, the dive site is pointless */ +/* if all fields are empty, the dive site is pointless */ bool dive_site_is_empty(struct dive_site *ds) { return !ds || @@ -286,7 +269,6 @@ void copy_dive_site(struct dive_site *orig, struct dive_site *copy) copy->name = copy_string(orig->name); copy->notes = copy_string(orig->notes); copy->description = copy_string(orig->description); - copy->uuid = orig->uuid; copy_taxonomy(&orig->taxonomy, ©->taxonomy); } @@ -370,7 +352,7 @@ void merge_dive_sites(struct dive_site *ref, struct dive_site *dive_sites[], int mark_divelist_changed(true); } -struct dive_site *find_or_create_dive_site_with_name(const char *name, timestamp_t divetime, struct dive_site_table *ds_table) +struct dive_site *find_or_create_dive_site_with_name(const char *name, struct dive_site_table *ds_table) { int i; struct dive_site *ds; @@ -380,7 +362,7 @@ struct dive_site *find_or_create_dive_site_with_name(const char *name, timestamp } if (ds) return ds; - return create_dive_site(name, divetime, ds_table); + return create_dive_site(name, ds_table); } void purge_empty_dive_sites(struct dive_site_table *ds_table) diff --git a/core/divesite.h b/core/divesite.h index b31bf3940..09e86bb8c 100644 --- a/core/divesite.h +++ b/core/divesite.h @@ -55,8 +55,8 @@ int nr_of_dives_at_dive_site(struct dive_site *ds, bool select_only); bool is_dive_site_used(struct dive_site *ds, bool select_only); void free_dive_site(struct dive_site *ds); void delete_dive_site(struct dive_site *ds, struct dive_site_table *ds_table); -struct dive_site *create_dive_site(const char *name, timestamp_t divetime, struct dive_site_table *ds_table); -struct dive_site *create_dive_site_with_gps(const char *name, const location_t *, timestamp_t divetime, struct dive_site_table *ds_table); +struct dive_site *create_dive_site(const char *name, struct dive_site_table *ds_table); +struct dive_site *create_dive_site_with_gps(const char *name, const location_t *, struct dive_site_table *ds_table); struct dive_site *get_dive_site_by_name(const char *name, struct dive_site_table *ds_table); struct dive_site *get_dive_site_by_gps(const location_t *, struct dive_site_table *ds_table); struct dive_site *get_dive_site_by_gps_and_name(char *name, const location_t *, struct dive_site_table *ds_table); @@ -67,7 +67,7 @@ void copy_dive_site_taxonomy(struct dive_site *orig, struct dive_site *copy); void copy_dive_site(struct dive_site *orig, struct dive_site *copy); void merge_dive_site(struct dive_site *a, struct dive_site *b); 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); +struct dive_site *find_or_create_dive_site_with_name(const char *name, 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); diff --git a/core/gpslocation.cpp b/core/gpslocation.cpp index 6271f42c4..8a2719a8b 100644 --- a/core/gpslocation.cpp +++ b/core/gpslocation.cpp @@ -211,7 +211,7 @@ static void copy_gps_location(struct gpsTracker &gps, struct dive *d) { struct dive_site *ds = d->dive_site; if (!ds) { - ds = create_dive_site(qPrintable(gps.name), gps.when, &dive_site_table); + ds = create_dive_site(qPrintable(gps.name), &dive_site_table); d->dive_site = ds; } ds->location = gps.location; diff --git a/core/import-cobalt.c b/core/import-cobalt.c index 0836a9c00..ce5048244 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, state->sites); + state->cur_dive->dive_site = find_or_create_dive_site_with_name(tmp, state->sites); free(tmp); } free(location); diff --git a/core/import-divinglog.c b/core/import-divinglog.c index 9ebd2b8ed..7716ddf8e 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, state->sites); + state->cur_dive->dive_site = find_or_create_dive_site_with_name(data[2], state->sites); if (data[3]) utf8_string(data[3], &state->cur_dive->buddy); diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c index 0008f0dee..e391bcbfb 100644 --- a/core/libdivecomputer.c +++ b/core/libdivecomputer.c @@ -596,7 +596,7 @@ static void parse_string_field(device_data_t *devdata, struct dive *dive, dc_fie parse_location(line, &location); if (location.lat.udeg && location.lon.udeg) - dive->dive_site = create_dive_site_with_gps(str->value, &location, time(NULL), devdata->sites); + dive->dive_site = create_dive_site_with_gps(str->value, &location, devdata->sites); } } #endif diff --git a/core/liquivision.c b/core/liquivision.c index 019f7613c..bfe970e15 100644 --- a/core/liquivision.c +++ b/core/liquivision.c @@ -143,7 +143,6 @@ static void parse_dives(int log_version, const unsigned char *buf, unsigned int while (ptr < buf_size) { int i; - bool found_divesite = false; dive = alloc_dive(); memset(&sensor_ids, 0, sizeof(sensor_ids)); dc = &dive->dc; @@ -191,8 +190,10 @@ static void parse_dives(int log_version, const unsigned char *buf, unsigned int } /* Store the location only if we have one */ - if (len || place_len) - found_divesite = true; + if (len || place_len) { + dive->dive_site = find_or_create_dive_site_with_name(location, sites); + free(location); + } ptr += len + 4 + place_len; @@ -224,12 +225,6 @@ static void parse_dives(int log_version, const unsigned char *buf, unsigned int dive->when = array_uint32_le(buf + ptr); ptr += 4; - // 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, sites); - free(location); - } //unsigned int end_time = array_uint32_le(buf + ptr); ptr += 4; diff --git a/core/load-git.c b/core/load-git.c index be8a839da..5ed6ca07d 100644 --- a/core/load-git.c +++ b/core/load-git.c @@ -159,7 +159,7 @@ static void parse_dive_gps(char *line, struct membuffer *str, void *_dive) if (!ds) { ds = get_dive_site_by_gps(&location, &dive_site_table); if (!ds) - dive->dive_site = create_dive_site_with_gps("", &location, dive->when, &dive_site_table); + dive->dive_site = create_dive_site_with_gps("", &location, &dive_site_table); else dive->dive_site = ds; } else { @@ -183,7 +183,7 @@ static void parse_dive_location(char *line, struct membuffer *str, void *_dive) if (!ds) { ds = get_dive_site_by_name(name, &dive_site_table); if (!ds) - dive->dive_site = create_dive_site(name, dive->when, &dive_site_table); + dive->dive_site = create_dive_site(name, &dive_site_table); else dive->dive_site = ds; } else { diff --git a/core/parse-xml.c b/core/parse-xml.c index 47b7c2296..fb2982986 100644 --- a/core/parse-xml.c +++ b/core/parse-xml.c @@ -985,7 +985,7 @@ static void divinglog_place(char *place, struct dive_site **ds, struct parser_st state->country ? state->country : ""); *ds = get_dive_site_by_name(buffer, state->sites); if (!*ds) - *ds = create_dive_site(buffer, state->cur_dive->when, state->sites); + *ds = create_dive_site(buffer, state->sites); // TODO: capture the country / city info in the taxonomy instead free(state->city); @@ -1137,7 +1137,7 @@ static void gps_lat(char *buffer, struct dive *dive, struct parser_state *state) location.lat = parse_degrees(buffer, &end); if (!ds) { - dive->dive_site = create_dive_site_with_gps(NULL, &location, dive->when, state->sites); + dive->dive_site = create_dive_site_with_gps(NULL, &location, 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)"); @@ -1153,7 +1153,7 @@ static void gps_long(char *buffer, struct dive *dive, struct parser_state *state location.lon = parse_degrees(buffer, &end); if (!ds) { - dive->dive_site = create_dive_site_with_gps(NULL, &location, dive->when, state->sites); + dive->dive_site = create_dive_site_with_gps(NULL, &location, 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)"); @@ -1191,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, state->sites); + dive->dive_site = create_dive_site_with_gps("", &location, state->sites); } } else { if (dive_site_has_gps_location(ds) && @@ -2122,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, state.sites); + state.cur_dive->dive_site = create_dive_site_with_gps("DLF imported", &state.cur_location, state.sites); break; default: break; diff --git a/core/parse.c b/core/parse.c index 2763628f9..5dceef0f9 100644 --- a/core/parse.c +++ b/core/parse.c @@ -434,7 +434,7 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state) if (exact_match) { dive->dive_site = exact_match; } else { - struct dive_site *newds = create_dive_site(buffer, dive->when, state->sites); + struct dive_site *newds = create_dive_site(buffer, 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, state->sites); + dive->dive_site = create_dive_site(buffer, state->sites); } } free(to_free); diff --git a/core/uemis-downloader.c b/core/uemis-downloader.c index ef7e070ce..30ad972cc 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, devdata->sites); + struct dive_site *ds = create_dive_site("from Uemis", devdata->sites); dive->dive_site = ds; uemis_mark_divelocation(dive->dc.diveid, divespot_id, ds); } |