diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-06-09 12:50:17 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-06-09 12:50:17 -0700 |
commit | 53806c265c9ed1b60f7591d9250dfab76fb5d8e6 (patch) | |
tree | 04fd755b6ea69aa36289b3f91df396414a1e2cb5 /parse-xml.c | |
parent | d88da535864dde8206359bcdbdda78e7b0847c9c (diff) | |
download | subsurface-53806c265c9ed1b60f7591d9250dfab76fb5d8e6.tar.gz |
Create unique dive sites when downloading from webservice
The Subsurface Webservice (as backend for the companion app) will usually
send a lot of gps fixes encoded as dives, all with the same dive site
name. When parsing the XML file it sends we need to make the dive site
names unique so that we can then match them to the existing dives.
The fake dives with all the dives sites will all be discarded, but without
creating the unique dive sites we can't successfully add the GPS
coordinates to the existing dives.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'parse-xml.c')
-rw-r--r-- | parse-xml.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/parse-xml.c b/parse-xml.c index 1fbde0bf0..f9e5296ff 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -170,6 +170,7 @@ static enum import_source { LIBDIVECOMPUTER, DIVINGLOG, UDDF, + SSRF_WS, } import_source; static void divedate(const char *buffer, timestamp_t *when) @@ -1209,8 +1210,10 @@ static void gps_in_dive(char *buffer, struct dive *dive) add_geo_information_for_lookup(latitude, longitude, dive->dive_site_uuid); } -static void add_dive_site(char *buffer, struct dive *dive) +static void add_dive_site(char *ds_name, struct dive *dive) { + static long suffix = 1; + char *buffer = ds_name; fprintf(stderr, "add_dive_site with name %s\n", buffer); int size = trimspace(buffer); if(size) { @@ -1221,9 +1224,22 @@ static void add_dive_site(char *buffer, struct dive *dive) fprintf(stderr, "dive contains a non-existing dive site uuid %x\n", dive->dive_site_uuid); uuid = 0; } - if (!uuid) + if (!uuid) { // if the dive doesn't have a uuid, check if there's already a dive site by this name uuid = get_dive_site_uuid_by_name(buffer, &ds); + if (uuid && import_source == SSRF_WS) { + // when downloading GPS fixes from the Subsurface webservice we will often + // get a lot of dives with identical names (the autogenerated fixes). + // So in this case modify the name to make it unique + int name_size = strlen(buffer) + 10; // 8 digits - enough for 100 million sites + buffer = malloc(name_size); + do { + suffix++; + snprintf(buffer, name_size, "%s %8d", ds_name, suffix); + } while (get_dive_site_uuid_by_name(buffer, NULL) != 0); + ds = NULL; + } + } if (ds) { // we have a uuid, let's hope there isn't a different name fprintf(stderr, "have existing site with name {%s} gps %f/%f ", ds->name, ds->latitude.udeg / 1000000.0, ds->longitude.udeg / 1000000.0); @@ -1824,6 +1840,11 @@ static void uddf_importer(void) xml_parsing_units.temperature = KELVIN; } +static void subsurface_webservice(void) +{ + import_source = SSRF_WS; +} + /* * I'm sure this could be done as some fancy DTD rules. * It's just not worth the headache. @@ -1856,6 +1877,7 @@ static struct nesting { /* Import type recognition */ { "Divinglog", DivingLog_importer }, { "uddf", uddf_importer }, + { "output", subsurface_webservice }, { NULL, } }; |