Skip to content

Commit

Permalink
Add WFS Client Test (MapServer#6909)
Browse files Browse the repository at this point in the history
and fix memory leak related to CURL headers.
  • Loading branch information
geographika authored Dec 14, 2023
1 parent 1df4a96 commit ecdfaa0
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 9 deletions.
52 changes: 52 additions & 0 deletions msautotest/wxs/expected/wfs_client_100.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version='1.0' encoding="UTF-8" ?>
<wfs:FeatureCollection
xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:gml="http://www.opengis.net/gml"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd
http://mapserver.gis.umn.edu/mapserver http://localhost/wfsclient?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=continents&amp;OUTPUTFORMAT=XMLSCHEMA">
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates>-86.923950,46.381596 -60.381756,65.176476</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<gml:featureMember>
<ms:continents>
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates>-60.393715,46.381596 -60.381756,46.394154</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<ms:msGeometry>
<gml:Polygon srsName="EPSG:4326">
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coordinates>-60.393715,46.386185 -60.387363,46.393707 -60.382725,46.394154 -60.381756,46.391628 -60.390778,46.381596 -60.393715,46.386185 </gml:coordinates>
</gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon>
</ms:msGeometry>
</ms:continents>
</gml:featureMember>
<gml:featureMember>
<ms:continents>
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates>-86.923950,65.167961 -86.892601,65.176476</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<ms:msGeometry>
<gml:Polygon srsName="EPSG:4326">
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coordinates>-86.903679,65.171326 -86.896553,65.171494 -86.892601,65.169724 -86.905548,65.167961 -86.923950,65.173294 -86.921654,65.176186 -86.906311,65.176476 -86.903679,65.171326 </gml:coordinates>
</gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon>
</ms:msGeometry>
</ms:continents>
</gml:featureMember>
</wfs:FeatureCollection>

54 changes: 54 additions & 0 deletions msautotest/wxs/wfs_client_100.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#
# Test WFS 1.0.0 Client
#
# REQUIRES: OUTPUT=PNG SUPPORTS=WFS_CLIENT SUPPORTS=WFS
# GetFeature
# RUN_PARMS: wfs_client_100.xml [MAPSERV] -conf ../etc/mapserv.conf QUERY_STRING="map=[MAPFILE]&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=continents" > [RESULT_DEMIME]

MAP
NAME WFS_CLIENT_TEST_100
STATUS ON
SIZE 400 300
EXTENT -180 -90 180 90
UNITS DD
PROJECTION
"init=epsg:4326"
END
SYMBOLSET etc/symbols.sym
FONTSET etc/fonts.txt

WEB
IMAGEPATH "./tmp"
METADATA
"ows_updatesequence" "123"
"wfs_title" "Test WFS 1.0.0 client"
"wfs_srs" "EPSG:4326"
"ows_enable_request" "*"
"ows_onlineresource" "http://localhost/wfsclient?"
END
END

LAYER
NAME "continents"
TYPE POLYGON
STATUS ON
CONNECTION "https://demo.mapserver.org/cgi-bin/wfs?"
CONNECTIONTYPE WFS
METADATA
"wfs_typename" "continents"
"wfs_version" "1.0.0"
"wfs_connectiontimeout" "60"
"wfs_maxfeatures" "2"
END
PROJECTION
"init=epsg:4326"
END
CLASS
NAME "Continents"
STYLE
COLOR 255 128 128
OUTLINECOLOR 96 96 96
END
END
END # Layer
END
16 changes: 9 additions & 7 deletions src/maphttp.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,10 @@ int msHTTPAuthProxySetup(hashTableObj *mapmd, hashTableObj *lyrmd,
* Fetch a map slide via HTTP request and save to specified temp file.
*
* If bCheckLocalCache==MS_TRUE then if the pszOutputfile already exists
* then is is not downloaded again, and status 242 is returned.
* then it is not downloaded again, and status 242 is returned.
*
* Return value:
* MS_SUCCESS if all requests completed succesfully.
* MS_SUCCESS if all requests completed successfully.
* MS_FAILURE if a fatal error happened
* MS_DONE if some requests failed with 40x status for instance (not fatal)
**********************************************************************/
Expand Down Expand Up @@ -682,22 +682,23 @@ int msHTTPExecuteRequests(httpRequestObj *pasReqInfo, int numRequests,
unchecked_curl_easy_setopt(http_handle, CURLOPT_ERRORBUFFER,
pasReqInfo[i].pszErrBuf);

pasReqInfo[i].curl_headers = NULL;

if (pasReqInfo[i].pszPostRequest != NULL) {
char szBuf[100];

struct curl_slist *headers = NULL;
snprintf(szBuf, 100, "Content-Type: %s",
pasReqInfo[i].pszPostContentType);
headers = curl_slist_append(headers, szBuf);
pasReqInfo[i].curl_headers = curl_slist_append(NULL, szBuf);

unchecked_curl_easy_setopt(http_handle, CURLOPT_POST, 1);
unchecked_curl_easy_setopt(http_handle, CURLOPT_POSTFIELDS,
pasReqInfo[i].pszPostRequest);
if (debug) {
msDebug("HTTP: POST = %s", pasReqInfo[i].pszPostRequest);
}
unchecked_curl_easy_setopt(http_handle, CURLOPT_HTTPHEADER, headers);
/* curl_slist_free_all(headers); */ /* free the header list */
unchecked_curl_easy_setopt(http_handle, CURLOPT_HTTPHEADER,
pasReqInfo[i].curl_headers);
}

/* Added by RFC-42 HTTP Cookie Forwarding */
Expand Down Expand Up @@ -765,7 +766,7 @@ int msHTTPExecuteRequests(httpRequestObj *pasReqInfo, int numRequests,
/* it is called the second time and all the calls after */
/* that. This causes an infinite loop. */
/* I do not really know why. */
/* To sovle the problem the break frop case -1 has been removed. */
/* To solve the problem the break from case -1 has been removed. */
/* ==================================================================== */
#ifndef _WIN32
break;
Expand Down Expand Up @@ -916,6 +917,7 @@ int msHTTPExecuteRequests(httpRequestObj *pasReqInfo, int numRequests,
curl_multi_remove_handle(multi_handle, http_handle);
curl_easy_cleanup(http_handle);
psReq->curl_handle = NULL;
curl_slist_free_all(psReq->curl_headers); // free the header list
}

/* Cleanup multi handle, each handle had to be cleaned up individually */
Expand Down
5 changes: 3 additions & 2 deletions src/maphttp.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ typedef struct http_request_info {
int debug; /* Debug mode? MS_TRUE/MS_FALSE */

/* Private members */
void *curl_handle; /* CURLM * handle */
FILE *fp; /* FILE * used during download */
void *curl_headers; /* property to store a curl_slist handle */
void *curl_handle; /* CURLM * handle */
FILE *fp; /* FILE * used during download */

char *result_data; /* output if pszOutputFile is NULL */
int result_size;
Expand Down

0 comments on commit ecdfaa0

Please sign in to comment.