]> err.no Git - mapper/commitdiff
Handle gpx metadata section, just skip over it. Ignore contents of name tag for now.
authorKaj-Michael Lang <milang@onion.tal.org>
Mon, 18 Feb 2008 12:05:14 +0000 (14:05 +0200)
committerKaj-Michael Lang <milang@onion.tal.org>
Mon, 18 Feb 2008 12:05:14 +0000 (14:05 +0200)
src/gpx.c

index ad78c188141a63829139479c391a8163edd848b1..405ae26e9a05c89e4611047909659d8c7c7c46d0 100644 (file)
--- 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;