[SCM] PostGIS branch stable-2.5 updated. 2.5.9-1-gca800d25e
git at osgeo.org
git at osgeo.org
Tue Feb 6 13:03:33 PST 2024
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".
The branch, stable-2.5 has been updated
via ca800d25ecada7540cb7cc02d69d85d9d4a5948b (commit)
from 2b018b93a36534f19d16e3e5bc8c87c4a57bd5f8 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit ca800d25ecada7540cb7cc02d69d85d9d4a5948b
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date: Tue Feb 6 13:03:20 2024 -0800
XML parser breaks for RHEL systems, references #5662
diff --git a/NEWS b/NEWS
index 88a8effe9..5a24db573 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,10 @@
+
+PostGIS 2.5.10
+2024/02/06
+This emergency release addresses a behaviour change in RHEL libxml2
+
+ - #5662, Change XML parsers to SAX2 (Paul Ramsey)
+
PostGIS 2.5.9
2022/11/11
This release works for PostgreSQL 9.4 thru PostgreSQL 12 and is the End-Of-Life release
diff --git a/postgis/lwgeom_in_gml.c b/postgis/lwgeom_in_gml.c
index b4e8dee95..a79a4c7bf 100644
--- a/postgis/lwgeom_in_gml.c
+++ b/postgis/lwgeom_in_gml.c
@@ -129,6 +129,28 @@ Datum geom_from_gml(PG_FUNCTION_ARGS)
}
+static inline bool
+is_gml_element(xmlNodePtr xn, const char *gml_name)
+{
+ char *colon_pos;
+ char *node_name;
+
+ /* Not an element node, can't do anything */
+ if (!xn || xn->type != XML_ELEMENT_NODE)
+ return false;
+
+ /* If there's a colon in the element name, */
+ /* move past it before checking for equality with */
+ /* the element name we are looking for */
+ node_name = (char*)xn->name;
+ colon_pos = strchr(node_name, ':');
+ if (colon_pos)
+ node_name = colon_pos + 1;
+
+ return strcmp(node_name, gml_name) == 0;
+}
+
+
/**
* Return false if current element namespace is not a GML one
* Return true otherwise.
@@ -178,9 +200,10 @@ static bool is_gml_namespace(xmlNodePtr xnode, bool is_strict)
* Retrieve a GML property from a node or NULL otherwise
* Respect namespaces if presents in the node element
*/
-static xmlChar *gmlGetProp(xmlNodePtr xnode, xmlChar *prop)
+static xmlChar *gmlGetProp(xmlNodePtr xnode, const char *charProp)
{
xmlChar *value;
+ xmlChar *prop = (xmlChar*)charProp;
if (!is_gml_namespace(xnode, true))
return xmlGetProp(xnode, prop);
@@ -283,7 +306,7 @@ static xmlNodePtr get_xlink_node(xmlNodePtr xnode)
for (node = xnode ; node != NULL ; node = node->parent)
{
if (node->type != XML_ELEMENT_NODE) continue;
- node_id = gmlGetProp(node, (xmlChar *) "id");
+ node_id = gmlGetProp(node, "id");
if (node_id != NULL)
{
if (!xmlStrcmp(node_id, p))
@@ -377,7 +400,7 @@ static void parse_gml_srs(xmlNodePtr xnode, gmlSrs *srs)
char sep = ':';
node = xnode;
- srsname = gmlGetProp(node, (xmlChar *) "srsName");
+ srsname = gmlGetProp(node, "srsName");
/*printf("srsname %s\n",srsname);*/
if (!srsname)
{
@@ -546,7 +569,7 @@ static POINTARRAY* parse_gml_coordinates(xmlNodePtr xnode, bool *hasz)
*/
/* Retrieve separator between coordinates tuples */
- gml_ts = gmlGetProp(xnode, (xmlChar *) "ts");
+ gml_ts = gmlGetProp(xnode, "ts");
if (gml_ts == NULL) ts = ' ';
else
{
@@ -557,7 +580,7 @@ static POINTARRAY* parse_gml_coordinates(xmlNodePtr xnode, bool *hasz)
}
/* Retrieve separator between each coordinate */
- gml_cs = gmlGetProp(xnode, (xmlChar *) "cs");
+ gml_cs = gmlGetProp(xnode, "cs");
if (gml_cs == NULL) cs = ',';
else
{
@@ -568,7 +591,7 @@ static POINTARRAY* parse_gml_coordinates(xmlNodePtr xnode, bool *hasz)
}
/* Retrieve decimal separator */
- gml_dec = gmlGetProp(xnode, (xmlChar *) "decimal");
+ gml_dec = gmlGetProp(xnode, "decimal");
if (gml_dec == NULL) dec = '.';
else
{
@@ -658,7 +681,7 @@ static POINTARRAY* parse_gml_coord(xmlNodePtr xnode, bool *hasz)
if (xyz->type != XML_ELEMENT_NODE) continue;
if (!is_gml_namespace(xyz, false)) continue;
- if (!strcmp((char *) xyz->name, "X"))
+ if (is_gml_element(xyz, "X"))
{
if (x) gml_lwpgerror("invalid GML representation", 21);
c = xmlNodeGetContent(xyz);
@@ -666,7 +689,7 @@ static POINTARRAY* parse_gml_coord(xmlNodePtr xnode, bool *hasz)
x = true;
xmlFree(c);
}
- else if (!strcmp((char *) xyz->name, "Y"))
+ else if (is_gml_element(xyz, "Y"))
{
if (y) gml_lwpgerror("invalid GML representation", 22);
c = xmlNodeGetContent(xyz);
@@ -674,7 +697,7 @@ static POINTARRAY* parse_gml_coord(xmlNodePtr xnode, bool *hasz)
y = true;
xmlFree(c);
}
- else if (!strcmp((char *) xyz->name, "Z"))
+ else if (is_gml_element(xyz, "Z"))
{
if (z) gml_lwpgerror("invalid GML representation", 23);
c = xmlNodeGetContent(xyz);
@@ -708,9 +731,9 @@ static POINTARRAY* parse_gml_pos(xmlNodePtr xnode, bool *hasz)
/* HasZ, !HasM, 1 Point */
dpa = ptarray_construct_empty(1, 0, 1);
- dimension = gmlGetProp(xnode, (xmlChar *) "srsDimension");
+ dimension = gmlGetProp(xnode, "srsDimension");
if (dimension == NULL) /* in GML 3.0.0 it was dimension */
- dimension = gmlGetProp(xnode, (xmlChar *) "dimension");
+ dimension = gmlGetProp(xnode, "dimension");
if (dimension == NULL) dim = 2; /* We assume that we are in 2D */
else
{
@@ -773,9 +796,9 @@ static POINTARRAY* parse_gml_poslist(xmlNodePtr xnode, bool *hasz)
bool digit;
/* Retrieve gml:srsDimension attribute if any */
- dimension = gmlGetProp(xnode, (xmlChar *) "srsDimension");
+ dimension = gmlGetProp(xnode, "srsDimension");
if (dimension == NULL) /* in GML 3.0.0 it was dimension */
- dimension = gmlGetProp(xnode, (xmlChar *) "dimension");
+ dimension = gmlGetProp(xnode, "dimension");
if (dimension == NULL) dim = 2; /* We assume that we are in common 2D */
else
{
@@ -855,44 +878,43 @@ static POINTARRAY* parse_gml_data(xmlNodePtr xnode, bool *hasz, int *root_srid)
if (!is_gml_namespace(xa, false)) continue;
if (xa->name == NULL) continue;
- if (!strcmp((char *) xa->name, "pos"))
+ if (is_gml_element(xa, "pos"))
{
tmp_pa = parse_gml_pos(xa, hasz);
if (pa == NULL) pa = tmp_pa;
else pa = ptarray_merge(pa, tmp_pa);
}
- else if (!strcmp((char *) xa->name, "posList"))
+ else if (is_gml_element(xa, "posList"))
{
tmp_pa = parse_gml_poslist(xa, hasz);
if (pa == NULL) pa = tmp_pa;
else pa = ptarray_merge(pa, tmp_pa);
}
- else if (!strcmp((char *) xa->name, "coordinates"))
+ else if (is_gml_element(xa, "coordinates"))
{
tmp_pa = parse_gml_coordinates(xa, hasz);
if (pa == NULL) pa = tmp_pa;
else pa = ptarray_merge(pa, tmp_pa);
}
- else if (!strcmp((char *) xa->name, "coord"))
+ else if (is_gml_element(xa, "coord"))
{
tmp_pa = parse_gml_coord(xa, hasz);
if (pa == NULL) pa = tmp_pa;
else pa = ptarray_merge(pa, tmp_pa);
}
- else if (!strcmp((char *) xa->name, "pointRep") ||
- !strcmp((char *) xa->name, "pointProperty"))
+ else if (is_gml_element(xa, "pointRep") ||
+ is_gml_element(xa, "pointProperty"))
{
-
found = false;
for (xb = xa->children ; xb != NULL ; xb = xb->next)
{
if (xb->type != XML_ELEMENT_NODE) continue;
if (!is_gml_namespace(xb, false)) continue;
- if (!strcmp((char *) xb->name, "Point"))
+ if (is_gml_element(xb, "Point"))
{
found = true;
break;
@@ -1017,7 +1039,7 @@ static LWGEOM* parse_gml_curve(xmlNodePtr xnode, bool *hasz, int *root_srid)
{
if (xa->type != XML_ELEMENT_NODE) continue;
if (!is_gml_namespace(xa, false)) continue;
- if (!strcmp((char *) xa->name, "segments"))
+ if (is_gml_element(xa, "segments"))
{
found = true;
break;
@@ -1032,10 +1054,11 @@ static LWGEOM* parse_gml_curve(xmlNodePtr xnode, bool *hasz, int *root_srid)
{
if (xa->type != XML_ELEMENT_NODE) continue;
if (!is_gml_namespace(xa, false)) continue;
- if (strcmp((char *) xa->name, "LineStringSegment")) continue;
+
+ if (!is_gml_element(xa, "LineStringSegment")) continue;
/* GML SF is restricted to linear interpolation */
- interpolation = gmlGetProp(xa, (xmlChar *) "interpolation");
+ interpolation = gmlGetProp(xa, "interpolation");
if (interpolation != NULL)
{
if (strcmp((char *) interpolation, "linear"))
@@ -1163,14 +1186,15 @@ static LWGEOM* parse_gml_polygon(xmlNodePtr xnode, bool *hasz, int *root_srid)
/* Polygon/exterior -> GML 3.1.1 */
if (xa->type != XML_ELEMENT_NODE) continue;
if (!is_gml_namespace(xa, false)) continue;
- if (strcmp((char *) xa->name, "outerBoundaryIs") &&
- strcmp((char *) xa->name, "exterior")) continue;
+ if (!(is_gml_element(xa, "outerBoundaryIs") ||
+ is_gml_element(xa, "exterior")))
+ continue;
for (xb = xa->children ; xb != NULL ; xb = xb->next)
{
if (xb->type != XML_ELEMENT_NODE) continue;
if (!is_gml_namespace(xb, false)) continue;
- if (strcmp((char *) xb->name, "LinearRing")) continue;
+ if (!is_gml_element(xb, "LinearRing")) continue;
ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
ppa[0] = parse_gml_data(xb->children, hasz, root_srid);
@@ -1194,14 +1218,15 @@ static LWGEOM* parse_gml_polygon(xmlNodePtr xnode, bool *hasz, int *root_srid)
/* Polygon/interior -> GML 3.1.1 */
if (xa->type != XML_ELEMENT_NODE) continue;
if (!is_gml_namespace(xa, false)) continue;
- if (strcmp((char *) xa->name, "innerBoundaryIs") &&
- strcmp((char *) xa->name, "interior")) continue;
+ if (!(is_gml_element(xa, "innerBoundaryIs") ||
+ is_gml_element(xa, "interior")))
+ continue;
for (xb = xa->children ; xb != NULL ; xb = xb->next)
{
if (xb->type != XML_ELEMENT_NODE) continue;
if (!is_gml_namespace(xb, false)) continue;
- if (strcmp((char *) xb->name, "LinearRing")) continue;
+ if (!is_gml_element(xb, "LinearRing")) continue;
ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa,
sizeof(POINTARRAY*) * (ring + 1));
@@ -1250,7 +1275,7 @@ static LWGEOM* parse_gml_triangle(xmlNodePtr xnode, bool *hasz, int *root_srid)
/* GML SF is restricted to planar interpolation
NOTA: I know Triangle is not part of SF, but
we have to be consistent with other surfaces */
- interpolation = gmlGetProp(xnode, (xmlChar *) "interpolation");
+ interpolation = gmlGetProp(xnode, "interpolation");
if (interpolation != NULL)
{
if (strcmp((char *) interpolation, "planar"))
@@ -1265,14 +1290,14 @@ static LWGEOM* parse_gml_triangle(xmlNodePtr xnode, bool *hasz, int *root_srid)
/* Triangle/exterior */
if (xa->type != XML_ELEMENT_NODE) continue;
if (!is_gml_namespace(xa, false)) continue;
- if (strcmp((char *) xa->name, "exterior")) continue;
+ if (!is_gml_element(xa, "exterior")) continue;
for (xb = xa->children ; xb != NULL ; xb = xb->next)
{
/* Triangle/exterior/LinearRing */
if (xb->type != XML_ELEMENT_NODE) continue;
if (!is_gml_namespace(xb, false)) continue;
- if (strcmp((char *) xb->name, "LinearRing")) continue;
+ if (!is_gml_element(xb, "LinearRing")) continue;
pa = (POINTARRAY*) lwalloc(sizeof(POINTARRAY));
pa = parse_gml_data(xb->children, hasz, root_srid);
@@ -1311,11 +1336,11 @@ static LWGEOM* parse_gml_patch(xmlNodePtr xnode, bool *hasz, int *root_srid)
gmlSrs srs;
/* PolygonPatch */
- if (strcmp((char *) xnode->name, "PolygonPatch"))
+ if (!is_gml_element(xnode, "PolygonPatch"))
gml_lwpgerror("invalid GML representation", 48);
/* GML SF is restricted to planar interpolation */
- interpolation = gmlGetProp(xnode, (xmlChar *) "interpolation");
+ interpolation = gmlGetProp(xnode, "interpolation");
if (interpolation != NULL)
{
if (strcmp((char *) interpolation, "planar"))
@@ -1329,14 +1354,14 @@ static LWGEOM* parse_gml_patch(xmlNodePtr xnode, bool *hasz, int *root_srid)
for (xa = xnode->children ; xa != NULL ; xa = xa->next)
{
if (!is_gml_namespace(xa, false)) continue;
- if (strcmp((char *) xa->name, "exterior")) continue;
+ if (!is_gml_element(xa, "exterior")) continue;
/* PolygonPatch/exterior/LinearRing */
for (xb = xa->children ; xb != NULL ; xb = xb->next)
{
if (xb->type != XML_ELEMENT_NODE) continue;
if (!is_gml_namespace(xb, false)) continue;
- if (strcmp((char *) xb->name, "LinearRing")) continue;
+ if (!is_gml_element(xb, "LinearRing")) continue;
ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
ppa[0] = parse_gml_data(xb->children, hasz, root_srid);
@@ -1360,13 +1385,13 @@ static LWGEOM* parse_gml_patch(xmlNodePtr xnode, bool *hasz, int *root_srid)
{
if (xa->type != XML_ELEMENT_NODE) continue;
if (!is_gml_namespace(xa, false)) continue;
- if (strcmp((char *) xa->name, "interior")) continue;
+ if (!is_gml_element(xa, "interior")) continue;
/* PolygonPatch/interior/LinearRing */
for (xb = xa->children ; xb != NULL ; xb = xb->next)
{
if (xb->type != XML_ELEMENT_NODE) continue;
- if (strcmp((char *) xb->name, "LinearRing")) continue;
+ if (!is_gml_element(xb, "LinearRing")) continue;
ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa,
sizeof(POINTARRAY*) * (ring + 1));
@@ -1415,7 +1440,7 @@ static LWGEOM* parse_gml_surface(xmlNodePtr xnode, bool *hasz, int *root_srid)
{
if (xa->type != XML_ELEMENT_NODE) continue;
if (!is_gml_namespace(xa, false)) continue;
- if (!strcmp((char *) xa->name, "patches"))
+ if (is_gml_element(xa, "patches"))
{
found = true;
break;
@@ -1428,7 +1453,7 @@ static LWGEOM* parse_gml_surface(xmlNodePtr xnode, bool *hasz, int *root_srid)
{
if (xa->type != XML_ELEMENT_NODE) continue;
if (!is_gml_namespace(xa, false)) continue;
- if (strcmp((char *) xa->name, "PolygonPatch")) continue;
+ if (!is_gml_element(xa, "PolygonPatch")) continue;
patch++;
/* SQL/MM define ST_CurvePolygon as a single patch only,
@@ -1476,8 +1501,8 @@ static LWGEOM* parse_gml_tin(xmlNodePtr xnode, bool *hasz, int *root_srid)
{
if (xa->type != XML_ELEMENT_NODE) continue;
if (!is_gml_namespace(xa, false)) continue;
- if (!strcmp((char *) xa->name, "patches") ||
- !strcmp((char *) xa->name, "trianglePatches"))
+ if (is_gml_element(xa, "patches") ||
+ is_gml_element(xa, "trianglePatches"))
{
found = true;
break;
@@ -1490,7 +1515,7 @@ static LWGEOM* parse_gml_tin(xmlNodePtr xnode, bool *hasz, int *root_srid)
{
if (xa->type != XML_ELEMENT_NODE) continue;
if (!is_gml_namespace(xa, false)) continue;
- if (strcmp((char *) xa->name, "Triangle")) continue;
+ if (!is_gml_element(xa, "Triangle")) continue;
if (xa->children != NULL)
geom = (LWGEOM*) lwtin_add_lwtriangle((LWTIN *) geom,
@@ -1526,7 +1551,7 @@ static LWGEOM* parse_gml_mpoint(xmlNodePtr xnode, bool *hasz, int *root_srid)
/* MultiPoint/pointMember */
if (xa->type != XML_ELEMENT_NODE) continue;
if (!is_gml_namespace(xa, false)) continue;
- if (!strcmp((char *) xa->name, "pointMembers"))
+ if (is_gml_element(xa, "pointMembers"))
{
for (xb = xa->children ; xb != NULL ; xb = xb->next)
{
@@ -1535,7 +1560,7 @@ static LWGEOM* parse_gml_mpoint(xmlNodePtr xnode, bool *hasz, int *root_srid)
(LWPOINT*)parse_gml(xb, hasz, root_srid));
}
}
- else if (!strcmp((char *) xa->name, "pointMember"))
+ else if (is_gml_element(xa, "pointMember"))
{
if (xa->children != NULL)
geom = (LWGEOM*)lwmpoint_add_lwpoint((LWMPOINT*)geom,
@@ -1572,7 +1597,7 @@ static LWGEOM* parse_gml_mline(xmlNodePtr xnode, bool *hasz, int *root_srid)
/* MultiLineString/lineStringMember */
if (xa->type != XML_ELEMENT_NODE) continue;
if (!is_gml_namespace(xa, false)) continue;
- if (strcmp((char *) xa->name, "lineStringMember")) continue;
+ if (!is_gml_element(xa, "lineStringMember")) continue;
if (xa->children != NULL)
geom = (LWGEOM*)lwmline_add_lwline((LWMLINE*)geom,
(LWLINE*)parse_gml(xa->children, hasz, root_srid));
@@ -1608,7 +1633,7 @@ static LWGEOM* parse_gml_mcurve(xmlNodePtr xnode, bool *hasz, int *root_srid)
/* MultiCurve/curveMember */
if (xa->type != XML_ELEMENT_NODE) continue;
if (!is_gml_namespace(xa, false)) continue;
- if (!strcmp((char *) xa->name, "curveMembers"))
+ if (is_gml_element(xa, "curveMembers"))
{
for (xb = xa->children ; xb != NULL ; xb = xb->next)
{
@@ -1617,7 +1642,7 @@ static LWGEOM* parse_gml_mcurve(xmlNodePtr xnode, bool *hasz, int *root_srid)
(LWLINE*)parse_gml(xb, hasz, root_srid));
}
}
- else if (!strcmp((char *) xa->name, "curveMember"))
+ else if (is_gml_element(xa, "curveMember"))
{
if (xa->children != NULL)
geom = (LWGEOM*)lwmline_add_lwline((LWMLINE*)geom,
@@ -1654,7 +1679,7 @@ static LWGEOM* parse_gml_mpoly(xmlNodePtr xnode, bool *hasz, int *root_srid)
/* MultiPolygon/polygonMember */
if (xa->type != XML_ELEMENT_NODE) continue;
if (!is_gml_namespace(xa, false)) continue;
- if (strcmp((char *) xa->name, "polygonMember")) continue;
+ if (!is_gml_element(xa, "polygonMember")) continue;
if (xa->children != NULL)
geom = (LWGEOM*)lwmpoly_add_lwpoly((LWMPOLY*)geom,
(LWPOLY*)parse_gml(xa->children, hasz, root_srid));
@@ -1689,7 +1714,7 @@ static LWGEOM* parse_gml_msurface(xmlNodePtr xnode, bool *hasz, int *root_srid)
/* MultiSurface/surfaceMember */
if (xa->type != XML_ELEMENT_NODE) continue;
if (!is_gml_namespace(xa, false)) continue;
- if (!strcmp((char *) xa->name, "surfaceMembers"))
+ if (is_gml_element(xa, "surfaceMembers"))
{
for (xb = xa->children ; xb != NULL ; xb = xb->next)
{
@@ -1698,7 +1723,7 @@ static LWGEOM* parse_gml_msurface(xmlNodePtr xnode, bool *hasz, int *root_srid)
(LWPOLY*)parse_gml(xb, hasz, root_srid));
}
}
- else if (!strcmp((char *) xa->name, "surfaceMember"))
+ else if (is_gml_element(xa, "surfaceMember"))
{
if (xa->children != NULL)
geom = (LWGEOM*)lwmpoly_add_lwpoly((LWMPOLY*)geom,
@@ -1737,7 +1762,7 @@ static LWGEOM* parse_gml_psurface(xmlNodePtr xnode, bool *hasz, int *root_srid)
{
if (xa->type != XML_ELEMENT_NODE) continue;
if (!is_gml_namespace(xa, false)) continue;
- if (!strcmp((char *) xa->name, "polygonPatches"))
+ if (is_gml_element(xa, "polygonPatches"))
{
found = true;
break;
@@ -1750,7 +1775,7 @@ static LWGEOM* parse_gml_psurface(xmlNodePtr xnode, bool *hasz, int *root_srid)
/* PolyhedralSurface/polygonPatches/PolygonPatch */
if (xa->type != XML_ELEMENT_NODE) continue;
if (!is_gml_namespace(xa, false)) continue;
- if (strcmp((char *) xa->name, "PolygonPatch")) continue;
+ if (!is_gml_element(xa, "PolygonPatch")) continue;
geom = (LWGEOM*)lwpsurface_add_lwpoly((LWPSURFACE*)geom,
(LWPOLY*)parse_gml_patch(xa, hasz, root_srid));
@@ -1790,10 +1815,10 @@ static LWGEOM* parse_gml_coll(xmlNodePtr xnode, bool *hasz, int *root_srid)
* polygonMember are parts of geometryMember
* substitution group
*/
- if ( !strcmp((char *) xa->name, "pointMember")
- || !strcmp((char *) xa->name, "lineStringMember")
- || !strcmp((char *) xa->name, "polygonMember")
- || !strcmp((char *) xa->name, "geometryMember"))
+ if ( is_gml_element(xa, "pointMember")
+ || is_gml_element(xa, "lineStringMember")
+ || is_gml_element(xa, "polygonMember")
+ || is_gml_element(xa, "geometryMember"))
{
if (xa->children == NULL) break;
geom = (LWGEOM*)lwcollection_add_lwgeom((LWCOLLECTION *)geom,
@@ -1862,8 +1887,12 @@ static LWGEOM* parse_gml(xmlNodePtr xnode, bool *hasz, int *root_srid)
xmlNodePtr xa = xnode;
gmlSrs srs;
- while (xa != NULL && (xa->type != XML_ELEMENT_NODE
- || !is_gml_namespace(xa, false))) xa = xa->next;
+ /* Scroll forward to the root node */
+ while (xa != NULL &&
+ (xa->type != XML_ELEMENT_NODE || !is_gml_namespace(xa, false)))
+ {
+ xa = xa->next;
+ }
if (xa == NULL) gml_lwpgerror("invalid GML representation", 55);
@@ -1873,50 +1902,50 @@ static LWGEOM* parse_gml(xmlNodePtr xnode, bool *hasz, int *root_srid)
*root_srid = srs.srid;
}
- if (!strcmp((char *) xa->name, "Point"))
+ if (is_gml_element(xa, "Point"))
return parse_gml_point(xa, hasz, root_srid);
- if (!strcmp((char *) xa->name, "LineString"))
+ if (is_gml_element(xa, "LineString"))
return parse_gml_line(xa, hasz, root_srid);
- if (!strcmp((char *) xa->name, "Curve"))
+ if (is_gml_element(xa, "Curve"))
return parse_gml_curve(xa, hasz, root_srid);
- if (!strcmp((char *) xa->name, "LinearRing"))
+ if (is_gml_element(xa, "LinearRing"))
return parse_gml_linearring(xa, hasz, root_srid);
- if (!strcmp((char *) xa->name, "Polygon"))
+ if (is_gml_element(xa, "Polygon"))
return parse_gml_polygon(xa, hasz, root_srid);
- if (!strcmp((char *) xa->name, "Triangle"))
+ if (is_gml_element(xa, "Triangle"))
return parse_gml_triangle(xa, hasz, root_srid);
- if (!strcmp((char *) xa->name, "Surface"))
+ if (is_gml_element(xa, "Surface"))
return parse_gml_surface(xa, hasz, root_srid);
- if (!strcmp((char *) xa->name, "MultiPoint"))
+ if (is_gml_element(xa, "MultiPoint"))
return parse_gml_mpoint(xa, hasz, root_srid);
- if (!strcmp((char *) xa->name, "MultiLineString"))
+ if (is_gml_element(xa, "MultiLineString"))
return parse_gml_mline(xa, hasz, root_srid);
- if (!strcmp((char *) xa->name, "MultiCurve"))
+ if (is_gml_element(xa, "MultiCurve"))
return parse_gml_mcurve(xa, hasz, root_srid);
- if (!strcmp((char *) xa->name, "MultiPolygon"))
+ if (is_gml_element(xa, "MultiPolygon"))
return parse_gml_mpoly(xa, hasz, root_srid);
- if (!strcmp((char *) xa->name, "MultiSurface"))
+ if (is_gml_element(xa, "MultiSurface"))
return parse_gml_msurface(xa, hasz, root_srid);
- if (!strcmp((char *) xa->name, "PolyhedralSurface"))
+ if (is_gml_element(xa, "PolyhedralSurface"))
return parse_gml_psurface(xa, hasz, root_srid);
- if ((!strcmp((char *) xa->name, "Tin")) ||
- !strcmp((char *) xa->name, "TriangulatedSurface" ))
+ if (is_gml_element(xa, "Tin") ||
+ is_gml_element(xa, "TriangulatedSurface"))
return parse_gml_tin(xa, hasz, root_srid);
- if (!strcmp((char *) xa->name, "MultiGeometry"))
+ if (is_gml_element(xa, "MultiGeometry"))
return parse_gml_coll(xa, hasz, root_srid);
gml_lwpgerror("invalid GML representation", 56);
diff --git a/postgis/lwgeom_in_kml.c b/postgis/lwgeom_in_kml.c
index 8daa58a51..aa05c78bd 100644
--- a/postgis/lwgeom_in_kml.c
+++ b/postgis/lwgeom_in_kml.c
@@ -67,6 +67,28 @@ static LWGEOM* parse_kml(xmlNodePtr xnode, bool *hasz);
#define KML_NS ((char *) "http://www.opengis.net/kml/2.2")
+static inline bool
+is_kml_element(xmlNodePtr xn, const char *kml_name)
+{
+ char *colon_pos;
+ char *node_name;
+
+ /* Not an element node, can't do anything */
+ if (!xn || xn->type != XML_ELEMENT_NODE)
+ return false;
+
+ /* If there's a colon in the element name, */
+ /* move past it before checking for equality with */
+ /* the element name we are looking for */
+ node_name = (char*)xn->name;
+ colon_pos = strchr(node_name, ':');
+ if (colon_pos)
+ node_name = colon_pos + 1;
+
+ return strcmp(node_name, kml_name) == 0;
+}
+
+
/**
* Ability to parse KML geometry fragment and to return an LWGEOM
* or an error message.
@@ -92,7 +114,8 @@ Datum geom_from_kml(PG_FUNCTION_ARGS)
/* Begin to Parse XML doc */
xmlInitParser();
- xmldoc = xmlReadMemory(xml, xml_size, NULL, NULL, XML_PARSE_SAX1);
+ xmldoc = xmlReadMemory(xml, xml_size, NULL, NULL, 0);
+ // xmldoc = xmlReadMemory(xml, xml_size, NULL, NULL, XML_PARSE_SAX1);
if (!xmldoc || (xmlroot = xmlDocGetRootElement(xmldoc)) == NULL)
{
xmlFreeDoc(xmldoc);
@@ -294,7 +317,7 @@ static POINTARRAY* parse_kml_coordinates(xmlNodePtr xnode, bool *hasz)
{
if (xnode->type != XML_ELEMENT_NODE) continue;
if (!is_kml_namespace(xnode, false)) continue;
- if (strcmp((char *) xnode->name, "coordinates")) continue;
+ if (!is_kml_element(xnode, "coordinates")) continue;
found = true;
break;
@@ -410,14 +433,14 @@ static LWGEOM* parse_kml_polygon(xmlNodePtr xnode, bool *hasz)
/* Polygon/outerBoundaryIs */
if (xa->type != XML_ELEMENT_NODE) continue;
if (!is_kml_namespace(xa, false)) continue;
- if (strcmp((char *) xa->name, "outerBoundaryIs")) continue;
+ if (!is_kml_element(xa, "outerBoundaryIs")) continue;
for (xb = xa->children ; xb != NULL ; xb = xb->next)
{
if (xb->type != XML_ELEMENT_NODE) continue;
if (!is_kml_namespace(xb, false)) continue;
- if (strcmp((char *) xb->name, "LinearRing")) continue;
+ if (!is_kml_element(xb, "LinearRing")) continue;
ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
ppa[0] = parse_kml_coordinates(xb->children, hasz);
@@ -446,14 +469,14 @@ static LWGEOM* parse_kml_polygon(xmlNodePtr xnode, bool *hasz)
/* Polygon/innerBoundaryIs */
if (xa->type != XML_ELEMENT_NODE) continue;
if (!is_kml_namespace(xa, false)) continue;
- if (strcmp((char *) xa->name, "innerBoundaryIs")) continue;
+ if (!is_kml_element(xa, "innerBoundaryIs")) continue;
for (xb = xa->children ; xb != NULL ; xb = xb->next)
{
if (xb->type != XML_ELEMENT_NODE) continue;
if (!is_kml_namespace(xb, false)) continue;
- if (strcmp((char *) xb->name, "LinearRing")) continue;
+ if (!is_kml_element(xb, "LinearRing")) continue;
ppa = (POINTARRAY**) lwrealloc(ppa, sizeof(POINTARRAY*) * (ring + 1));
ppa[ring] = parse_kml_coordinates(xb->children, hasz);
@@ -497,10 +520,10 @@ static LWGEOM* parse_kml_multi(xmlNodePtr xnode, bool *hasz)
if (xa->type != XML_ELEMENT_NODE) continue;
if (!is_kml_namespace(xa, false)) continue;
- if ( !strcmp((char *) xa->name, "Point")
- || !strcmp((char *) xa->name, "LineString")
- || !strcmp((char *) xa->name, "Polygon")
- || !strcmp((char *) xa->name, "MultiGeometry"))
+ if ( is_kml_element(xa, "Point")
+ || is_kml_element(xa, "LineString")
+ || is_kml_element(xa, "Polygon")
+ || is_kml_element(xa, "MultiGeometry"))
{
if (xa->children == NULL) break;
@@ -524,16 +547,16 @@ static LWGEOM* parse_kml(xmlNodePtr xnode, bool *hasz)
if (xa == NULL) lwpgerror("invalid KML representation");
- if (!strcmp((char *) xa->name, "Point"))
+ if (is_kml_element(xa, "Point"))
return parse_kml_point(xa, hasz);
- if (!strcmp((char *) xa->name, "LineString"))
+ if (is_kml_element(xa, "LineString"))
return parse_kml_line(xa, hasz);
- if (!strcmp((char *) xa->name, "Polygon"))
+ if (is_kml_element(xa, "Polygon"))
return parse_kml_polygon(xa, hasz);
- if (!strcmp((char *) xa->name, "MultiGeometry"))
+ if (is_kml_element(xa, "MultiGeometry"))
return parse_kml_multi(xa, hasz);
lwpgerror("invalid KML representation");
-----------------------------------------------------------------------
Summary of changes:
NEWS | 7 ++
postgis/lwgeom_in_gml.c | 181 ++++++++++++++++++++++++++++--------------------
postgis/lwgeom_in_kml.c | 51 ++++++++++----
3 files changed, 149 insertions(+), 90 deletions(-)
hooks/post-receive
--
PostGIS
More information about the postgis-tickets
mailing list