/** 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,
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. */
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;
data->state = ERROR;
} else
MACRO_SET_UNKNOWN();
- break;
+ break;
case INSIDE_PATH_POINT:
if (!strcmp((gchar *) name, "time"))
data->state = INSIDE_PATH_POINT_TIME;
data->state = INSIDE_PATH_POINT_NAME;
else
MACRO_SET_UNKNOWN();
- break;
+ break;
case UNKNOWN:
data->unknown_depth++;
- break;
+ break;
default:
;
}
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;
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)
g_string_free(data.chars, TRUE);
if (data.state != FINISH) {
+ g_debug("GPX: Parser stopped in error state %d", data.state);
return FALSE;
}
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;