From: Kaj-Michael Lang Date: Mon, 18 Feb 2008 12:05:14 +0000 (+0200) Subject: Handle gpx metadata section, just skip over it. Ignore contents of name tag for now. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd52e21bf26ffa99a1b551eb2d5761900f295695;p=mapper Handle gpx metadata section, just skip over it. Ignore contents of name tag for now. --- diff --git a/src/gpx.c b/src/gpx.c index ad78c18..405ae26 100644 --- a/src/gpx.c +++ b/src/gpx.c @@ -74,8 +74,9 @@ /** This enum defines the states of the SAX parsing state machine. */ typedef enum { - START, - INSIDE_GPX, + START=1, + INSIDE_GPX=100, + INSIDE_METADATA, INSIDE_PATH, INSIDE_PATH_SEGMENT, INSIDE_PATH_POINT, @@ -83,9 +84,9 @@ typedef enum { INSIDE_PATH_POINT_TIME, INSIDE_PATH_POINT_DESC, INSIDE_PATH_POINT_NAME, - FINISH, - UNKNOWN, - ERROR, + FINISH=5000, + UNKNOWN=6666, + ERROR=9999, } SaxState; /** Data used during the SAX parsing operation. */ @@ -220,29 +221,34 @@ write_gpx(Path * path, GnomeVFSHandle * handle) static void gpx_start_element(SaxData * data, const xmlChar * name, const xmlChar ** attrs) { - g_debug("GPX-START: %s", name); + g_debug("GPX-START: %s (%d)", name, data->state); switch (data->state) { case ERROR: - break; + break; case START: if (!strcmp((gchar *) name, "gpx")) data->state = INSIDE_GPX; else MACRO_SET_UNKNOWN(); - break; + break; case INSIDE_GPX: if (!strcmp((gchar *) name, "trk")) data->state = INSIDE_PATH; + else if (!strcmp((gchar *) name, "metadata")) + data->state = INSIDE_METADATA; else MACRO_SET_UNKNOWN(); - break; + break; + case INSIDE_METADATA: + + break; case INSIDE_PATH: if (!strcmp((gchar *) name, "trkseg")) { data->state = INSIDE_PATH_SEGMENT; data->at_least_one_trkpt = FALSE; } else MACRO_SET_UNKNOWN(); - break; + break; case INSIDE_PATH_SEGMENT: if (!strcmp((gchar *) name, "trkpt")) { const xmlChar **curr_attr; @@ -274,7 +280,7 @@ gpx_start_element(SaxData * data, const xmlChar * name, const xmlChar ** attrs) data->state = ERROR; } else MACRO_SET_UNKNOWN(); - break; + break; case INSIDE_PATH_POINT: if (!strcmp((gchar *) name, "time")) data->state = INSIDE_PATH_POINT_TIME; @@ -286,10 +292,10 @@ gpx_start_element(SaxData * data, const xmlChar * name, const xmlChar ** attrs) data->state = INSIDE_PATH_POINT_NAME; else MACRO_SET_UNKNOWN(); - break; + break; case UNKNOWN: data->unknown_depth++; - break; + break; default: ; } @@ -317,6 +323,10 @@ gpx_end_element(SaxData * data, const xmlChar * name) else data->state = ERROR; break; + case INSIDE_METADATA: + if (!strcmp((gchar *) name, "metadata")) + data->state = INSIDE_GPX; + break; case INSIDE_PATH: if (!strcmp((gchar *) name, "trk")) data->state = INSIDE_GPX; @@ -414,7 +424,10 @@ gpx_end_element(SaxData * data, const xmlChar * name) data->state = ERROR; break; case INSIDE_PATH_POINT_NAME: - + /* Just ignore these for now */ + g_string_free(data->chars, FALSE); + data->chars = g_string_new(""); + data->state = INSIDE_PATH_POINT; break; case UNKNOWN: if (!--data->unknown_depth) @@ -496,6 +509,7 @@ parse_gpx(Path * to_replace, gchar * buffer, gint size, gint policy_old) g_string_free(data.chars, TRUE); if (data.state != FINISH) { + g_debug("GPX: Parser stopped in error state %d", data.state); return FALSE; } @@ -555,10 +569,8 @@ parse_gpx(Path * to_replace, gchar * buffer, gint size, gint policy_old) MACRO_PATH_FREE((*to_replace)); /* Overwrite with data.route. */ (*to_replace) = data.path; - path_resize(to_replace, - to_replace->tail - to_replace->head + 1); - path_wresize(to_replace, - to_replace->wtail - to_replace->whead + 1); + path_resize(to_replace, to_replace->tail - to_replace->head + 1); + path_wresize(to_replace, to_replace->wtail - to_replace->whead + 1); } return TRUE;