summaryrefslogtreecommitdiffstats
path: root/parse-xml.c
diff options
context:
space:
mode:
Diffstat (limited to 'parse-xml.c')
-rw-r--r--parse-xml.c26
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, }
};