~ubuntu-branches/ubuntu/saucy/mapserver/saucy-security

« back to all changes in this revision

Viewing changes to mapwfs11.c

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2011-12-23 14:02:06 UTC
  • mfrom: (26.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20111223140206-n3h9t2hsa8hyslmu
Tags: 6.0.1-2
Added missed stuff for libmapscript-perl.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**********************************************************************
2
 
 * $Id: mapwfs11.c 9498 2009-10-20 13:38:46Z aboudreault $
3
 
 *
4
 
 * Project:  MapServer
5
 
 * Purpose:  OGC WFS 1.1.0 implementation. This file holds some WFS 1.1.0 
6
 
 *           specific functions but other parts are still implemented in mapwfs.c.
7
 
 * Author:   Y. Assefa, DM Solutions Group (assefa@dmsolutions.ca)
8
 
 *
9
 
 **********************************************************************
10
 
 * Copyright (c) 2008, Y. Assefa, DM Solutions Group Inc
11
 
 *
12
 
 * Permission is hereby granted, free of charge, to any person obtaining a
13
 
 * copy of this software and associated documentation files (the "Software"),
14
 
 * to deal in the Software without restriction, including without limitation
15
 
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16
 
 * and/or sell copies of the Software, and to permit persons to whom the
17
 
 * Software is furnished to do so, subject to the following conditions:
18
 
 * 
19
 
 * The above copyright notice and this permission notice shall be included in 
20
 
 * all copies of this Software or works derived from this Software.
21
 
 * 
22
 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
25
 
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27
 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
28
 
 ****************************************************************************/
29
 
 
30
 
#include "mapserver.h"
31
 
#include "mapows.h"
32
 
 
33
 
MS_CVSID("$Id: mapwfs11.c 9498 2009-10-20 13:38:46Z aboudreault $")
34
 
 
35
 
#if defined(USE_WFS_SVR) && defined(USE_LIBXML2)
36
 
#include "maplibxml2.h"
37
 
#include "mapowscommon.h"
38
 
#include "mapogcfilter.h"
39
 
 
40
 
 
41
 
int msWFSException11(mapObj *map, const char *locator, 
42
 
                     const char *exceptionCode, const char *version)
43
 
{
44
 
    int size = 0;
45
 
    char *errorString     = NULL;
46
 
    char *errorMessage    = NULL;
47
 
    char *schemasLocation = NULL;
48
 
    const char *encoding;
49
 
 
50
 
    xmlDocPtr  psDoc      = NULL;   
51
 
    xmlNodePtr psRootNode = NULL;
52
 
    xmlNsPtr   psNsOws    = NULL;
53
 
    xmlChar *buffer       = NULL;
54
 
    
55
 
    if (version == NULL)
56
 
       version = "1.1.0";
57
 
 
58
 
    psNsOws = xmlNewNs(NULL, BAD_CAST "http://www.opengis.net/ows", BAD_CAST "ows");
59
 
 
60
 
    encoding = msOWSLookupMetadata(&(map->web.metadata), "FO", "encoding");
61
 
 
62
 
    errorString = msGetErrorString("\n");
63
 
    errorMessage = msEncodeHTMLEntities(errorString);
64
 
    schemasLocation = msEncodeHTMLEntities(msOWSGetSchemasLocation(map));
65
 
 
66
 
    psDoc = xmlNewDoc(BAD_CAST "1.0");
67
 
 
68
 
    psRootNode = msOWSCommonExceptionReport(psNsOws, OWS_1_0_0, schemasLocation, version, msOWSGetLanguage(map, "exception"), exceptionCode, locator, errorMessage);
69
 
 
70
 
    xmlDocSetRootElement(psDoc, psRootNode);
71
 
 
72
 
    psNsOws = xmlNewNs(psRootNode, BAD_CAST "http://www.opengis.net/ows", BAD_CAST "ows");
73
 
 
74
 
    if (encoding)
75
 
        msIO_printf("Content-type: text/xml; charset=%s%c%c", encoding,10,10);
76
 
    else
77
 
        msIO_printf("Content-type: text/xml%c%c",10,10);
78
 
 
79
 
    xmlDocDumpFormatMemoryEnc(psDoc, &buffer, &size, (encoding ? encoding : "ISO-8859-1"), 1);
80
 
    
81
 
    msIO_printf("%s", buffer);
82
 
 
83
 
    /*free buffer and the document */
84
 
    free(errorString);
85
 
    free(errorMessage);
86
 
    free(schemasLocation);
87
 
    xmlFree(buffer);
88
 
    xmlFreeDoc(psDoc);
89
 
 
90
 
    /* clear error since we have already reported it */
91
 
    msResetErrorList();
92
 
 
93
 
    return MS_FAILURE;
94
 
}
95
 
    
96
 
 
97
 
/************************************************************************/
98
 
/*                             msWFSDumpLayer11                         */
99
 
/************************************************************************/
100
 
static xmlNodePtr msWFSDumpLayer11(mapObj *map, layerObj *lp, xmlNsPtr psNsOws)
101
 
{
102
 
    rectObj ext;
103
 
   
104
 
    xmlNodePtr psRootNode, psNode;
105
 
    const char *value    = NULL;
106
 
 
107
 
    psRootNode = xmlNewNode(NULL, BAD_CAST "FeatureType");
108
 
 
109
 
    psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "Name", BAD_CAST lp->name);
110
 
 
111
 
    if (lp->name && strlen(lp->name) > 0 &&
112
 
        (msIsXMLTagValid(lp->name) == MS_FALSE || isdigit(lp->name[0])))
113
 
      xmlAddSibling(psNode,
114
 
                    xmlNewComment(BAD_CAST "WARNING: The layer name '%s' might contain spaces or "
115
 
                                  "invalid characters or may start with a number. This could lead to potential problems"));
116
 
   
117
 
    value = msOWSLookupMetadata(&(lp->metadata), "FO", "title");
118
 
    if (value)
119
 
      psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "Title", BAD_CAST value);
120
 
    else
121
 
      psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "Title", BAD_CAST lp->name);
122
 
 
123
 
 
124
 
    value = msOWSLookupMetadata(&(lp->metadata), "FO", "abstract");
125
 
    if (value)
126
 
      psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "Abstract", BAD_CAST value);
127
 
 
128
 
 
129
 
    value = msOWSLookupMetadata(&(lp->metadata), "FO", "keywordlist");
130
 
 
131
 
    if (value)
132
 
        msLibXml2GenerateList(
133
 
            xmlNewChild(psRootNode, psNsOws, BAD_CAST "Keywords", NULL),
134
 
            NULL, "Keyword", value, ',' );
135
 
 
136
 
    /*srs only supposrt DefaultSRS with the same logic as for wfs1.0
137
 
      TODO support OtherSRS*/
138
 
    value = msOWSGetEPSGProj(&(map->projection),&(map->web.metadata),"FO",MS_TRUE);
139
 
    if (!value)
140
 
      value =  msOWSGetEPSGProj(&(lp->projection), &(lp->metadata), "FO", MS_TRUE);
141
 
  
142
 
    psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "DefaultSRS", BAD_CAST value);
143
 
    if (!value)
144
 
      xmlAddSibling(psNode,
145
 
                    xmlNewComment(BAD_CAST "WARNING: Mandatory mapfile parameter: (at least one of) MAP.PROJECTION, LAYER.PROJECTION or wfs/ows_srs metadata was missing in this context."));
146
 
 
147
 
    /*TODO: adevertize only gml3?*/
148
 
    psNode = xmlNewNode(NULL, BAD_CAST "OutputFormats");
149
 
    xmlAddChild(psRootNode, psNode);
150
 
    xmlNewChild(psNode, NULL, BAD_CAST "Format", BAD_CAST "text/xml; subtype=gml/3.1.1");
151
 
  
152
 
    /*bbox*/
153
 
    if (msOWSGetLayerExtent(map, lp, "FO", &ext) == MS_SUCCESS)
154
 
    {   
155
 
        /*convert to latlong*/
156
 
        if (lp->projection.numargs > 0)
157
 
        {
158
 
            if (!pj_is_latlong(&lp->projection.proj))
159
 
              msProjectRect(&lp->projection, NULL, &ext);
160
 
        }
161
 
        else if (map->projection.numargs > 0 && !pj_is_latlong(&map->projection.proj))
162
 
          msProjectRect(&map->projection, NULL, &ext);
163
 
 
164
 
        xmlAddChild(psRootNode,
165
 
                    msOWSCommonWGS84BoundingBox( psNsOws, 2,
166
 
                                                 ext.minx, ext.miny,
167
 
                                                 ext.maxx, ext.maxy));
168
 
    }
169
 
    else
170
 
    {
171
 
        xmlNewChild(psRootNode, psNsOws, BAD_CAST "WGS84BoundingBox", NULL);
172
 
        xmlAddSibling(psNode,
173
 
                      xmlNewComment(BAD_CAST "WARNING: Optional WGS84BoundingBox could not be established for this layer.  Consider setting the EXTENT in the LAYER object, or wfs_extent metadata. Also check that your data exists in the DATA statement"));
174
 
    }
175
 
 
176
 
    value = msOWSLookupMetadata(&(lp->metadata), "FO", "metadataurl_href");
177
 
 
178
 
    if (value)
179
 
    {
180
 
        psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "MetadataURL", BAD_CAST value);
181
 
 
182
 
        value = msOWSLookupMetadata(&(lp->metadata), "FO", "metadataurl_format");
183
 
 
184
 
        if (!value)
185
 
          value = strdup("text/html"); /* default */
186
 
 
187
 
        xmlNewProp(psNode, BAD_CAST "format", BAD_CAST value);
188
 
 
189
 
        value = msOWSLookupMetadata(&(lp->metadata), "FO", "metadataurl_type");
190
 
 
191
 
        if (!value)
192
 
          value = strdup("FGDC"); /* default */
193
 
 
194
 
        xmlNewProp(psNode, BAD_CAST "type", BAD_CAST value);
195
 
    }
196
 
 
197
 
    return psRootNode;
198
 
}
199
 
 
200
 
/************************************************************************/
201
 
/*                          msWFSGetCapabilities11                      */
202
 
/*                                                                      */
203
 
/*      Return the capabilities document for wfs 1.1.0                  */
204
 
/************************************************************************/
205
 
int msWFSGetCapabilities11(mapObj *map, wfsParamsObj *params, 
206
 
                         cgiRequestObj *req) 
207
 
{
208
 
    xmlDocPtr psDoc = NULL;       /* document pointer */
209
 
    xmlNodePtr psRootNode, psMainNode, psNode, psFtNode;
210
 
    xmlNodePtr psTmpNode;
211
 
    const char *updatesequence=NULL;
212
 
    xmlNsPtr psNsOws, psNsXLink, psNsOgc;
213
 
    char *schemalocation = NULL;
214
 
    char *xsi_schemaLocation = NULL;
215
 
 
216
 
    char *script_url=NULL, *script_url_encoded=NULL;
217
 
    const char *value = NULL;
218
 
    const char *encoding;
219
 
 
220
 
    xmlChar *buffer = NULL;
221
 
    int size = 0, i;
222
 
    msIOContext *context = NULL;
223
 
 
224
 
    int ows_version = OWS_1_0_0;
225
 
 
226
 
/* -------------------------------------------------------------------- */
227
 
/*      Handle updatesequence                                           */
228
 
/* -------------------------------------------------------------------- */
229
 
 
230
 
    updatesequence = msOWSLookupMetadata(&(map->web.metadata), "FO", "updatesequence");
231
 
 
232
 
    encoding = msOWSLookupMetadata(&(map->web.metadata), "FO", "encoding");
233
 
 
234
 
    if (params->pszUpdateSequence != NULL) {
235
 
      i = msOWSNegotiateUpdateSequence(params->pszUpdateSequence, updatesequence);
236
 
      if (i == 0) { /* current */
237
 
          msSetError(MS_WFSERR, "UPDATESEQUENCE parameter (%s) is equal to server (%s)", "msWFSGetCapabilities11()", params->pszUpdateSequence, updatesequence);
238
 
          return msWFSException11(map, "updatesequence", "CurrentUpdateSequence", params->pszVersion);
239
 
      }
240
 
      if (i > 0) { /* invalid */
241
 
          msSetError(MS_WFSERR, "UPDATESEQUENCE parameter (%s) is higher than server (%s)", "msWFSGetCapabilities11()", params->pszUpdateSequence, updatesequence);
242
 
          return msWFSException11(map, "updatesequence", "InvalidUpdateSequence", params->pszVersion);
243
 
      }
244
 
    }
245
 
 
246
 
 
247
 
/* -------------------------------------------------------------------- */
248
 
/*      Create document.                                                */
249
 
/* -------------------------------------------------------------------- */
250
 
    psDoc = xmlNewDoc(BAD_CAST "1.0");
251
 
 
252
 
    psRootNode = xmlNewNode(NULL, BAD_CAST "WFS_Capabilities");
253
 
 
254
 
    xmlDocSetRootElement(psDoc, psRootNode);
255
 
 
256
 
/* -------------------------------------------------------------------- */
257
 
/*      Name spaces                                                     */
258
 
/* -------------------------------------------------------------------- */
259
 
    /*default name space*/      
260
 
    xmlNewProp(psRootNode, BAD_CAST "xmlns", BAD_CAST "http://www.opengis.net/wfs");
261
 
    
262
 
    xmlSetNs(psRootNode, xmlNewNs(psRootNode, BAD_CAST "http://www.opengis.net/gml", BAD_CAST "gml"));
263
 
    xmlSetNs(psRootNode, xmlNewNs(psRootNode, BAD_CAST "http://www.opengis.net/wfs", BAD_CAST "wfs"));
264
 
    
265
 
    psNsOws = xmlNewNs(psRootNode, BAD_CAST MS_OWSCOMMON_OWS_NAMESPACE_URI, BAD_CAST MS_OWSCOMMON_OWS_NAMESPACE_PREFIX);
266
 
    psNsXLink = xmlNewNs(psRootNode, BAD_CAST MS_OWSCOMMON_W3C_XLINK_NAMESPACE_URI, BAD_CAST MS_OWSCOMMON_W3C_XLINK_NAMESPACE_PREFIX);
267
 
    xmlNewNs(psRootNode, BAD_CAST MS_OWSCOMMON_W3C_XSI_NAMESPACE_URI, BAD_CAST MS_OWSCOMMON_W3C_XSI_NAMESPACE_PREFIX);
268
 
    xmlNewNs(psRootNode, BAD_CAST MS_OWSCOMMON_OGC_NAMESPACE_URI, BAD_CAST MS_OWSCOMMON_OGC_NAMESPACE_PREFIX );
269
 
 
270
 
    xmlNewProp(psRootNode, BAD_CAST "version", BAD_CAST params->pszVersion );
271
 
 
272
 
    updatesequence = msOWSLookupMetadata(&(map->web.metadata), "FO", "updatesequence");
273
 
 
274
 
    if (updatesequence)
275
 
      xmlNewProp(psRootNode, BAD_CAST "updateSequence", BAD_CAST updatesequence);
276
 
 
277
 
    /*schema*/
278
 
    schemalocation = msEncodeHTMLEntities( msOWSGetSchemasLocation(map) );
279
 
    xsi_schemaLocation = strdup("http://www.opengis.net/wfs");
280
 
    xsi_schemaLocation = msStringConcatenate(xsi_schemaLocation, " ");
281
 
    xsi_schemaLocation = msStringConcatenate(xsi_schemaLocation, schemalocation);
282
 
    xsi_schemaLocation = msStringConcatenate(xsi_schemaLocation, "/wfs/1.1.0/wfs.xsd");
283
 
    xmlNewNsProp(psRootNode, NULL, BAD_CAST "xsi:schemaLocation", BAD_CAST xsi_schemaLocation);
284
 
 
285
 
/* -------------------------------------------------------------------- */
286
 
/*      Service metadata.                                               */
287
 
/* -------------------------------------------------------------------- */
288
 
 
289
 
    psTmpNode = xmlAddChild(psRootNode, 
290
 
                            msOWSCommonServiceIdentification(psNsOws, map, "OGC WFS", params->pszVersion, "FO"));
291
 
 
292
 
    /*service provider*/
293
 
    psTmpNode = xmlAddChild(psRootNode, msOWSCommonServiceProvider(
294
 
                                psNsOws, psNsXLink, map, "FO"));
295
 
 
296
 
    /*operation metadata */
297
 
    if ((script_url=msOWSGetOnlineResource(map, "FO", "onlineresource", req)) == NULL 
298
 
        || (script_url_encoded = msEncodeHTMLEntities(script_url)) == NULL)
299
 
    {
300
 
        msSetError(MS_WFSERR, "Server URL not found", "msWFSGetCapabilities11()");
301
 
        return msWFSException11(map, "mapserv", "NoApplicableCode", params->pszVersion);
302
 
    }
303
 
 
304
 
/* -------------------------------------------------------------------- */
305
 
/*      Operations metadata.                                            */
306
 
/* -------------------------------------------------------------------- */
307
 
    psMainNode= xmlAddChild(psRootNode,msOWSCommonOperationsMetadata(psNsOws));
308
 
 
309
 
/* -------------------------------------------------------------------- */
310
 
/*      GetCapabilities                                                 */
311
 
/* -------------------------------------------------------------------- */
312
 
    psNode = xmlAddChild(psMainNode, 
313
 
                         msOWSCommonOperationsMetadataOperation(psNsOws,psNsXLink,"GetCapabilities", 
314
 
                                                                OWS_METHOD_GETPOST, script_url_encoded));
315
 
    
316
 
    xmlAddChild(psMainNode, psNode);
317
 
    xmlAddChild(psNode, msOWSCommonOperationsMetadataDomainType(
318
 
                    ows_version, psNsOws, "Parameter", "service", "WFS"));
319
 
    /*accept version*/
320
 
    xmlAddChild(psNode, msOWSCommonOperationsMetadataDomainType(ows_version, psNsOws, 
321
 
                                                                "Parameter", "AcceptVersions", 
322
 
                                                                "1.0.0, 1.1.0"));
323
 
    /*format*/
324
 
    xmlAddChild(psNode, msOWSCommonOperationsMetadataDomainType(ows_version, psNsOws, 
325
 
                                                                "Parameter", "AcceptFormats", 
326
 
                                                                "text/xml"));
327
 
 
328
 
 
329
 
/* -------------------------------------------------------------------- */
330
 
/*      DescribeFeatureType                                             */
331
 
/* -------------------------------------------------------------------- */
332
 
     psNode = xmlAddChild(psMainNode, 
333
 
                          msOWSCommonOperationsMetadataOperation(psNsOws,psNsXLink,"DescribeFeatureType", 
334
 
                                                                 OWS_METHOD_GETPOST, script_url_encoded));
335
 
     xmlAddChild(psMainNode, psNode);
336
 
 
337
 
     /*output format*/
338
 
      xmlAddChild(psNode, msOWSCommonOperationsMetadataDomainType(ows_version, psNsOws, 
339
 
                                                                  "Parameter", "outputFormat", 
340
 
                                                                  "XMLSCHEMA,text/xml; subtype=gml/2.1.2,text/xml; subtype=gml/3.1.1"));
341
 
 
342
 
/* -------------------------------------------------------------------- */
343
 
/*      GetFeature                                                      */
344
 
/* -------------------------------------------------------------------- */
345
 
      psNode = xmlAddChild(psMainNode, 
346
 
                          msOWSCommonOperationsMetadataOperation(psNsOws,psNsXLink,"GetFeature", 
347
 
                                                                 OWS_METHOD_GETPOST, script_url_encoded));
348
 
     xmlAddChild(psMainNode, psNode);
349
 
 
350
 
     /*resultType: TODO support hits*/
351
 
     xmlAddChild(psNode, msOWSCommonOperationsMetadataDomainType(ows_version, psNsOws, 
352
 
                                                                "Parameter", "resultType", 
353
 
                                                                "results"));
354
 
     /*
355
 
     xmlAddChild(psNode, msOWSCommonOperationsMetadataDomainType(ows_version, psNsOws, 
356
 
                                                                 "Parameter", "resultType", 
357
 
                                                                 "results, hits"));
358
 
     */
359
 
     xmlAddChild(psNode, msOWSCommonOperationsMetadataDomainType(ows_version, psNsOws, 
360
 
                                                                  "Parameter", "outputFormat", 
361
 
                                                                  "text/xml; subtype=gml/3.1.1"));
362
 
 
363
 
     value = msOWSLookupMetadata(&(map->web.metadata), "FO", "maxfeatures");
364
 
 
365
 
    if (value) {
366
 
         xmlAddChild(psMainNode, msOWSCommonOperationsMetadataDomainType(ows_version, psNsOws,
367
 
                                                                  "Constraint", "DefaultMaxFeatures",
368
 
                                                                  (char *)value));
369
 
    }
370
 
 
371
 
/* -------------------------------------------------------------------- */
372
 
/*      FeatureTypeList                                                 */
373
 
/* -------------------------------------------------------------------- */
374
 
     
375
 
     psFtNode = xmlNewNode(NULL, BAD_CAST "FeatureTypeList");
376
 
     xmlAddChild(psRootNode, psFtNode);
377
 
     psNode = xmlNewChild(psFtNode, NULL, BAD_CAST "Operations", NULL);
378
 
     xmlNewChild(psNode, NULL, BAD_CAST "Operation", BAD_CAST "Query");
379
 
     
380
 
     for(i=0; i<map->numlayers; i++)
381
 
     {
382
 
         layerObj *lp;
383
 
         lp = GET_LAYER(map, i);
384
 
 
385
 
         /* List only vector layers in which DUMP=TRUE */
386
 
         if (msWFSIsLayerSupported(lp))
387
 
           xmlAddChild(psFtNode, msWFSDumpLayer11(map, lp, psNsOws));
388
 
     }
389
 
     
390
 
     
391
 
     
392
 
     
393
 
     
394
 
/* -------------------------------------------------------------------- */
395
 
/*      Filter capabilities.                                            */
396
 
/* -------------------------------------------------------------------- */
397
 
 
398
 
     psNsOgc = xmlNewNs(NULL, BAD_CAST MS_OWSCOMMON_OGC_NAMESPACE_URI, BAD_CAST MS_OWSCOMMON_OGC_NAMESPACE_PREFIX);
399
 
     xmlAddChild(psRootNode, FLTGetCapabilities(psNsOgc, psNsOgc, MS_FALSE));
400
 
/* -------------------------------------------------------------------- */
401
 
/*      Write out the document.                                         */
402
 
/* -------------------------------------------------------------------- */
403
 
 
404
 
    if( msIO_needBinaryStdout() == MS_FAILURE )
405
 
        return MS_FAILURE;
406
 
     
407
 
    if (encoding)
408
 
        msIO_printf("Content-type: text/xml; charset=%s%c%c", encoding,10,10);
409
 
    else
410
 
        msIO_printf("Content-type: text/xml%c%c",10,10);
411
 
    
412
 
    context = msIO_getHandler(stdout);
413
 
 
414
 
    xmlDocDumpFormatMemoryEnc(psDoc, &buffer, &size, (encoding ? encoding : "ISO-8859-1"), 1);
415
 
    msIO_contextWrite(context, buffer, size);
416
 
    xmlFree(buffer);
417
 
 
418
 
    /*free buffer and the document */
419
 
    /*xmlFree(buffer);*/
420
 
    xmlFreeDoc(psDoc);
421
 
    xmlFreeNs(psNsOgc);
422
 
 
423
 
    free(script_url);   
424
 
     free(script_url_encoded);
425
 
    free(xsi_schemaLocation);
426
 
    free(schemalocation);
427
 
 
428
 
    xmlCleanupParser();
429
 
 
430
 
    return(MS_SUCCESS);
431
 
}
432
 
    
433
 
 
434
 
#endif /*defined(USE_WFS_SVR) && defined(USE_LIBXML2)*/
435
 
 
436
 
#if defined(USE_WFS_SVR) && !defined(USE_LIBXML2)
437
 
 
438
 
 
439
 
 
440
 
int msWFSGetCapabilities11(mapObj *map, wfsParamsObj *params, 
441
 
                           cgiRequestObj *req)
442
 
 
443
 
{
444
 
    msSetError( MS_WFSERR,
445
 
                "WFS 1.1 request made, but mapserver requires libxml2 for WFS 1.1 services and this is not configured.",
446
 
                "msWFSGetCapabilities11()", "NoApplicableCode" );
447
 
 
448
 
    return msWFSException11(map, "mapserv", "NoApplicableCode", params->pszVersion);
449
 
}
450
 
 
451
 
int msWFSException11(mapObj *map, const char *locator, const char *exceptionCode, const char *version) {
452
 
    /* fallback to reporting using 1.0 style exceptions. */
453
 
    return msWFSException( map, locator, exceptionCode, "1.0.0" );
454
 
}
455
 
 
456
 
#endif /* defined(USE_WFS_SVR) && !defined(USE_LIBXML2) */
 
1
/**********************************************************************
 
2
 * $Id: mapwfs11.c 11503 2011-04-07 19:56:16Z dmorissette $
 
3
 *
 
4
 * Project:  MapServer
 
5
 * Purpose:  OGC WFS 1.1.0 implementation. This file holds some WFS 1.1.0 
 
6
 *           specific functions but other parts are still implemented in mapwfs.c.
 
7
 * Author:   Y. Assefa, DM Solutions Group (assefa@dmsolutions.ca)
 
8
 *
 
9
 **********************************************************************
 
10
 * Copyright (c) 2008, Y. Assefa, DM Solutions Group Inc
 
11
 *
 
12
 * Permission is hereby granted, free of charge, to any person obtaining a
 
13
 * copy of this software and associated documentation files (the "Software"),
 
14
 * to deal in the Software without restriction, including without limitation
 
15
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
16
 * and/or sell copies of the Software, and to permit persons to whom the
 
17
 * Software is furnished to do so, subject to the following conditions:
 
18
 * 
 
19
 * The above copyright notice and this permission notice shall be included in 
 
20
 * all copies of this Software or works derived from this Software.
 
21
 * 
 
22
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
23
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
24
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 
25
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
26
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
27
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 
28
 ****************************************************************************/
 
29
 
 
30
#include "mapserver.h"
 
31
#include "mapows.h"
 
32
 
 
33
MS_CVSID("$Id: mapwfs11.c 11503 2011-04-07 19:56:16Z dmorissette $")
 
34
 
 
35
#if defined(USE_WFS_SVR) && defined(USE_LIBXML2)
 
36
#include "maplibxml2.h"
 
37
#include "mapowscommon.h"
 
38
#include "mapogcfilter.h"
 
39
 
 
40
/************************************************************************/
 
41
/*                          msWFSException11()                          */
 
42
/************************************************************************/
 
43
 
 
44
int msWFSException11(mapObj *map, const char *locator, 
 
45
                     const char *exceptionCode, const char *version)
 
46
{
 
47
    int size = 0;
 
48
    char *errorString     = NULL;
 
49
    char *errorMessage    = NULL;
 
50
    char *schemasLocation = NULL;
 
51
    const char *encoding;
 
52
 
 
53
    xmlDocPtr  psDoc      = NULL;   
 
54
    xmlNodePtr psRootNode = NULL;
 
55
    xmlNsPtr   psNsOws    = NULL;
 
56
    xmlChar *buffer       = NULL;
 
57
    
 
58
    if (version == NULL)
 
59
       version = "1.1.0";
 
60
 
 
61
    psNsOws = xmlNewNs(NULL, BAD_CAST "http://www.opengis.net/ows", BAD_CAST "ows");
 
62
 
 
63
    encoding = msOWSLookupMetadata(&(map->web.metadata), "FO", "encoding");
 
64
 
 
65
    errorString = msGetErrorString("\n");
 
66
    errorMessage = msEncodeHTMLEntities(errorString);
 
67
    schemasLocation = msEncodeHTMLEntities(msOWSGetSchemasLocation(map));
 
68
 
 
69
    psDoc = xmlNewDoc(BAD_CAST "1.0");
 
70
 
 
71
    psRootNode = msOWSCommonExceptionReport(psNsOws, OWS_1_0_0, schemasLocation, version, msOWSGetLanguage(map, "exception"), exceptionCode, locator, errorMessage);
 
72
 
 
73
    xmlDocSetRootElement(psDoc, psRootNode);
 
74
 
 
75
    xmlNewNs(psRootNode, BAD_CAST "http://www.opengis.net/ows", BAD_CAST "ows");
 
76
 
 
77
    if (encoding)
 
78
        msIO_printf("Content-type: text/xml; charset=%s%c%c", encoding,10,10);
 
79
    else
 
80
        msIO_printf("Content-type: text/xml%c%c",10,10);
 
81
 
 
82
    xmlDocDumpFormatMemoryEnc(psDoc, &buffer, &size, (encoding ? encoding : "ISO-8859-1"), 1);
 
83
    
 
84
    msIO_printf("%s", buffer);
 
85
 
 
86
    /*free buffer and the document */
 
87
    free(errorString);
 
88
    free(errorMessage);
 
89
    free(schemasLocation);
 
90
    xmlFree(buffer);
 
91
    xmlFreeDoc(psDoc);
 
92
    xmlFreeNs(psNsOws);
 
93
 
 
94
    /* clear error since we have already reported it */
 
95
    msResetErrorList();
 
96
 
 
97
    return MS_FAILURE;
 
98
}
 
99
    
 
100
 
 
101
/************************************************************************/
 
102
/*                             msWFSDumpLayer11                         */
 
103
/************************************************************************/
 
104
static xmlNodePtr msWFSDumpLayer11(mapObj *map, layerObj *lp, xmlNsPtr psNsOws)
 
105
{
 
106
    rectObj ext;
 
107
   
 
108
    xmlNodePtr psRootNode, psNode;
 
109
    const char *value    = NULL;
 
110
    const char *encoding = NULL;
 
111
    char *encoded=NULL;
 
112
    char *valueToFree;
 
113
    char **tokens;
 
114
    int n=0,i=0;      
 
115
 
 
116
    encoding = msOWSLookupMetadata(&(map->web.metadata), "FO", "encoding");
 
117
    if (!encoding)
 
118
      encoding = "ISO-8859-1";
 
119
 
 
120
    psRootNode = xmlNewNode(NULL, BAD_CAST "FeatureType");
 
121
 
 
122
    /*if there is an encoding using it on some of the items*/
 
123
    psNode = msOWSCommonxmlNewChildEncoded(psRootNode, NULL, "Name", lp->name, encoding);
 
124
 
 
125
 
 
126
    if (lp->name && strlen(lp->name) > 0 &&
 
127
        (msIsXMLTagValid(lp->name) == MS_FALSE || isdigit(lp->name[0])))
 
128
      xmlAddSibling(psNode,
 
129
                    xmlNewComment(BAD_CAST "WARNING: The layer name '%s' might contain spaces or "
 
130
                                  "invalid characters or may start with a number. This could lead to potential problems"));
 
131
   
 
132
    value = msOWSLookupMetadata(&(lp->metadata), "FO", "title");
 
133
    if (!value)
 
134
      value =(const char*)lp->name;
 
135
 
 
136
    psNode = msOWSCommonxmlNewChildEncoded(psRootNode, NULL, "Title", value, encoding);
 
137
 
 
138
 
 
139
    value = msOWSLookupMetadata(&(lp->metadata), "FO", "abstract");
 
140
    if (value)
 
141
      psNode = msOWSCommonxmlNewChildEncoded(psRootNode, NULL, "Abstract", value, encoding);
 
142
 
 
143
 
 
144
 
 
145
    value = msOWSLookupMetadata(&(lp->metadata), "FO", "keywordlist");
 
146
 
 
147
    if (value)
 
148
    {
 
149
        if (encoding)
 
150
          encoded = msGetEncodedString(value, encoding);
 
151
        else
 
152
          encoded = msGetEncodedString(value, "ISO-8859-1");
 
153
 
 
154
        msLibXml2GenerateList(
 
155
            xmlNewChild(psRootNode, psNsOws, BAD_CAST "Keywords", NULL),
 
156
            NULL, "Keyword", encoded, ',' );
 
157
        msFree(encoded);
 
158
    }
 
159
      /*support DefaultSRS and OtherSRS*/
 
160
    valueToFree = msOWSGetProjURN(&(map->projection),&(map->web.metadata),"FO",MS_FALSE);
 
161
    if (!valueToFree)
 
162
      valueToFree = msOWSGetProjURN(&(lp->projection), &(lp->metadata), "FO", MS_FALSE);
 
163
 
 
164
    if (valueToFree)
 
165
    {
 
166
        tokens = msStringSplit(valueToFree, ' ', &n);
 
167
        if (tokens && n > 0)
 
168
        {
 
169
            psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "DefaultSRS", BAD_CAST tokens[0]);
 
170
            for (i=1; i<n; i++)
 
171
              psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "OtherSRS", BAD_CAST tokens[i]);
 
172
 
 
173
            msFreeCharArray(tokens, n);
 
174
        }
 
175
    }
 
176
    else
 
177
      xmlAddSibling(psNode,
 
178
                    xmlNewComment(BAD_CAST "WARNING: Mandatory mapfile parameter: (at least one of) MAP.PROJECTION, LAYER.PROJECTION or wfs/ows_srs metadata was missing in this context."));
 
179
 
 
180
    free(valueToFree);
 
181
    valueToFree = NULL;
 
182
 
 
183
    /*TODO: adevertize only gml3?*/
 
184
    psNode = xmlNewNode(NULL, BAD_CAST "OutputFormats");
 
185
    xmlAddChild(psRootNode, psNode);
 
186
 
 
187
    {
 
188
        char *formats_list = msWFSGetOutputFormatList( map, lp, "1.1.0" );
 
189
        int iformat, n;
 
190
        char **tokens;
 
191
 
 
192
        n = 0;
 
193
        tokens = msStringSplit(formats_list, ',', &n);
 
194
 
 
195
        for( iformat = 0; iformat < n; iformat++ )
 
196
            xmlNewChild(psNode, NULL, BAD_CAST "Format", 
 
197
                        BAD_CAST tokens[iformat] );
 
198
        msFree( formats_list );
 
199
        msFreeCharArray( tokens, n );
 
200
    }
 
201
  
 
202
    /*bbox*/
 
203
    if (msOWSGetLayerExtent(map, lp, "FO", &ext) == MS_SUCCESS)
 
204
    {   
 
205
        /*convert to latlong*/
 
206
        if (lp->projection.numargs > 0)
 
207
        {
 
208
            if (!pj_is_latlong(&lp->projection.proj))
 
209
              msProjectRect(&lp->projection, NULL, &ext);
 
210
        }
 
211
        else if (map->projection.numargs > 0 && !pj_is_latlong(&map->projection.proj))
 
212
          msProjectRect(&map->projection, NULL, &ext);
 
213
 
 
214
        xmlAddChild(psRootNode,
 
215
                    msOWSCommonWGS84BoundingBox( psNsOws, 2,
 
216
                                                 ext.minx, ext.miny,
 
217
                                                 ext.maxx, ext.maxy));
 
218
    }
 
219
    else
 
220
    {
 
221
        xmlNewChild(psRootNode, psNsOws, BAD_CAST "WGS84BoundingBox", NULL);
 
222
        xmlAddSibling(psNode,
 
223
                      xmlNewComment(BAD_CAST "WARNING: Optional WGS84BoundingBox could not be established for this layer.  Consider setting the EXTENT in the LAYER object, or wfs_extent metadata. Also check that your data exists in the DATA statement"));
 
224
    }
 
225
 
 
226
    value = msOWSLookupMetadata(&(lp->metadata), "FO", "metadataurl_href");
 
227
 
 
228
    if (value)
 
229
    {
 
230
        psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "MetadataURL", BAD_CAST value);
 
231
 
 
232
        value = msOWSLookupMetadata(&(lp->metadata), "FO", "metadataurl_format");
 
233
 
 
234
        if (!value)
 
235
          value = msStrdup("text/html"); /* default */
 
236
 
 
237
        xmlNewProp(psNode, BAD_CAST "format", BAD_CAST value);
 
238
 
 
239
        value = msOWSLookupMetadata(&(lp->metadata), "FO", "metadataurl_type");
 
240
 
 
241
        if (!value)
 
242
          value = msStrdup("FGDC"); /* default */
 
243
 
 
244
        xmlNewProp(psNode, BAD_CAST "type", BAD_CAST value);
 
245
    }
 
246
 
 
247
    return psRootNode;
 
248
}
 
249
 
 
250
/************************************************************************/
 
251
/*                          msWFSGetCapabilities11                      */
 
252
/*                                                                      */
 
253
/*      Return the capabilities document for wfs 1.1.0                  */
 
254
/************************************************************************/
 
255
int msWFSGetCapabilities11(mapObj *map, wfsParamsObj *params, 
 
256
                           cgiRequestObj *req, owsRequestObj *ows_request) 
 
257
{
 
258
    xmlDocPtr psDoc = NULL;       /* document pointer */
 
259
    xmlNodePtr psRootNode, psMainNode, psNode, psFtNode;
 
260
    xmlNodePtr psTmpNode;
 
261
    const char *updatesequence=NULL;
 
262
    xmlNsPtr psNsOws, psNsXLink, psNsOgc;
 
263
    char *schemalocation = NULL;
 
264
    char *xsi_schemaLocation = NULL;
 
265
 
 
266
    char *script_url=NULL, *script_url_encoded=NULL, *formats_list;
 
267
    const char *value = NULL;
 
268
    const char *encoding;
 
269
 
 
270
    xmlChar *buffer = NULL;
 
271
    int size = 0, i;
 
272
    msIOContext *context = NULL;
 
273
 
 
274
    int ows_version = OWS_1_0_0;
 
275
 
 
276
/* -------------------------------------------------------------------- */
 
277
/*      Handle updatesequence                                           */
 
278
/* -------------------------------------------------------------------- */
 
279
 
 
280
    updatesequence = msOWSLookupMetadata(&(map->web.metadata), "FO", "updatesequence");
 
281
 
 
282
    encoding = msOWSLookupMetadata(&(map->web.metadata), "FO", "encoding");
 
283
 
 
284
    if (params->pszUpdateSequence != NULL) {
 
285
      i = msOWSNegotiateUpdateSequence(params->pszUpdateSequence, updatesequence);
 
286
      if (i == 0) { /* current */
 
287
          msSetError(MS_WFSERR, "UPDATESEQUENCE parameter (%s) is equal to server (%s)", "msWFSGetCapabilities11()", params->pszUpdateSequence, updatesequence);
 
288
          return msWFSException11(map, "updatesequence", "CurrentUpdateSequence", params->pszVersion);
 
289
      }
 
290
      if (i > 0) { /* invalid */
 
291
          msSetError(MS_WFSERR, "UPDATESEQUENCE parameter (%s) is higher than server (%s)", "msWFSGetCapabilities11()", params->pszUpdateSequence, updatesequence);
 
292
          return msWFSException11(map, "updatesequence", "InvalidUpdateSequence", params->pszVersion);
 
293
      }
 
294
    }
 
295
 
 
296
/* -------------------------------------------------------------------- */
 
297
/*      Create document.                                                */
 
298
/* -------------------------------------------------------------------- */
 
299
    psDoc = xmlNewDoc(BAD_CAST "1.0");
 
300
 
 
301
    psRootNode = xmlNewNode(NULL, BAD_CAST "WFS_Capabilities");
 
302
 
 
303
    xmlDocSetRootElement(psDoc, psRootNode);
 
304
 
 
305
/* -------------------------------------------------------------------- */
 
306
/*      Name spaces                                                     */
 
307
/* -------------------------------------------------------------------- */
 
308
    /*default name space*/      
 
309
    xmlNewProp(psRootNode, BAD_CAST "xmlns", BAD_CAST "http://www.opengis.net/wfs");
 
310
    
 
311
    xmlSetNs(psRootNode, xmlNewNs(psRootNode, BAD_CAST "http://www.opengis.net/gml", BAD_CAST "gml"));
 
312
    xmlSetNs(psRootNode, xmlNewNs(psRootNode, BAD_CAST "http://www.opengis.net/wfs", BAD_CAST "wfs"));
 
313
    
 
314
    psNsOws = xmlNewNs(psRootNode, BAD_CAST MS_OWSCOMMON_OWS_NAMESPACE_URI, BAD_CAST MS_OWSCOMMON_OWS_NAMESPACE_PREFIX);
 
315
    psNsXLink = xmlNewNs(psRootNode, BAD_CAST MS_OWSCOMMON_W3C_XLINK_NAMESPACE_URI, BAD_CAST MS_OWSCOMMON_W3C_XLINK_NAMESPACE_PREFIX);
 
316
    xmlNewNs(psRootNode, BAD_CAST MS_OWSCOMMON_W3C_XSI_NAMESPACE_URI, BAD_CAST MS_OWSCOMMON_W3C_XSI_NAMESPACE_PREFIX);
 
317
    xmlNewNs(psRootNode, BAD_CAST MS_OWSCOMMON_OGC_NAMESPACE_URI, BAD_CAST MS_OWSCOMMON_OGC_NAMESPACE_PREFIX );
 
318
 
 
319
    xmlNewProp(psRootNode, BAD_CAST "version", BAD_CAST params->pszVersion );
 
320
 
 
321
    updatesequence = msOWSLookupMetadata(&(map->web.metadata), "FO", "updatesequence");
 
322
 
 
323
    if (updatesequence)
 
324
      xmlNewProp(psRootNode, BAD_CAST "updateSequence", BAD_CAST updatesequence);
 
325
 
 
326
    /*schema*/
 
327
    schemalocation = msEncodeHTMLEntities( msOWSGetSchemasLocation(map) );
 
328
    xsi_schemaLocation = msStrdup("http://www.opengis.net/wfs");
 
329
    xsi_schemaLocation = msStringConcatenate(xsi_schemaLocation, " ");
 
330
    xsi_schemaLocation = msStringConcatenate(xsi_schemaLocation, schemalocation);
 
331
    xsi_schemaLocation = msStringConcatenate(xsi_schemaLocation, "/wfs/1.1.0/wfs.xsd");
 
332
    xmlNewNsProp(psRootNode, NULL, BAD_CAST "xsi:schemaLocation", BAD_CAST xsi_schemaLocation);
 
333
 
 
334
/* -------------------------------------------------------------------- */
 
335
/*      Service metadata.                                               */
 
336
/* -------------------------------------------------------------------- */
 
337
 
 
338
    psTmpNode = xmlAddChild(psRootNode, 
 
339
                            msOWSCommonServiceIdentification(psNsOws, map, "OGC WFS", params->pszVersion, "FO"));
 
340
 
 
341
    /*service provider*/
 
342
    psTmpNode = xmlAddChild(psRootNode, msOWSCommonServiceProvider(
 
343
                                psNsOws, psNsXLink, map, "FO"));
 
344
 
 
345
    /*operation metadata */
 
346
    if ((script_url=msOWSGetOnlineResource(map, "FO", "onlineresource", req)) == NULL 
 
347
        || (script_url_encoded = msEncodeHTMLEntities(script_url)) == NULL)
 
348
    {
 
349
        msSetError(MS_WFSERR, "Server URL not found", "msWFSGetCapabilities11()");
 
350
        return msWFSException11(map, "mapserv", "NoApplicableCode", params->pszVersion);
 
351
    }
 
352
 
 
353
/* -------------------------------------------------------------------- */
 
354
/*      Operations metadata.                                            */
 
355
/* -------------------------------------------------------------------- */
 
356
    psMainNode= xmlAddChild(psRootNode,msOWSCommonOperationsMetadata(psNsOws));
 
357
 
 
358
/* -------------------------------------------------------------------- */
 
359
/*      GetCapabilities                                                 */
 
360
/* -------------------------------------------------------------------- */
 
361
    psNode = xmlAddChild(psMainNode, 
 
362
                         msOWSCommonOperationsMetadataOperation(psNsOws,psNsXLink,"GetCapabilities", 
 
363
                                                                OWS_METHOD_GETPOST, script_url_encoded));
 
364
    
 
365
    xmlAddChild(psMainNode, psNode);
 
366
    xmlAddChild(psNode, msOWSCommonOperationsMetadataDomainType(
 
367
                    ows_version, psNsOws, "Parameter", "service", "WFS"));
 
368
    /*accept version*/
 
369
    xmlAddChild(psNode, msOWSCommonOperationsMetadataDomainType(ows_version, psNsOws, 
 
370
                                                                "Parameter", "AcceptVersions", 
 
371
                                                                "1.0.0,1.1.0"));
 
372
    /*format*/
 
373
    xmlAddChild(psNode, msOWSCommonOperationsMetadataDomainType(ows_version, psNsOws, 
 
374
                                                                "Parameter", "AcceptFormats", 
 
375
                                                                "text/xml"));
 
376
 
 
377
 
 
378
/* -------------------------------------------------------------------- */
 
379
/*      DescribeFeatureType                                             */
 
380
/* -------------------------------------------------------------------- */
 
381
    if (msOWSRequestIsEnabled(map, NULL, "F", "DescribeFeatureType", MS_TRUE)) 
 
382
    {
 
383
        psNode = xmlAddChild(psMainNode, 
 
384
                             msOWSCommonOperationsMetadataOperation(psNsOws,psNsXLink,"DescribeFeatureType", 
 
385
                                                                 OWS_METHOD_GETPOST, script_url_encoded));
 
386
        xmlAddChild(psMainNode, psNode);
 
387
        
 
388
        /*output format*/
 
389
        xmlAddChild(psNode, msOWSCommonOperationsMetadataDomainType(ows_version, psNsOws, 
 
390
                                                                    "Parameter", "outputFormat", 
 
391
                                                                    "XMLSCHEMA,text/xml; subtype=gml/2.1.2,text/xml; subtype=gml/3.1.1"));
 
392
    }
 
393
 
 
394
/* -------------------------------------------------------------------- */
 
395
/*      GetFeature                                                      */
 
396
/* -------------------------------------------------------------------- */
 
397
    if (msOWSRequestIsEnabled(map, NULL, "F", "GetFeature", MS_TRUE)) 
 
398
    {
 
399
 
 
400
        psNode = xmlAddChild(psMainNode, 
 
401
                             msOWSCommonOperationsMetadataOperation(psNsOws,psNsXLink,"GetFeature", 
 
402
                                                                 OWS_METHOD_GETPOST, script_url_encoded));
 
403
        xmlAddChild(psMainNode, psNode);
 
404
        
 
405
        xmlAddChild(psNode, msOWSCommonOperationsMetadataDomainType(ows_version, psNsOws,
 
406
                                                                    "Parameter", "resultType", 
 
407
                                                                    "results,hits"));
 
408
 
 
409
        formats_list = msWFSGetOutputFormatList( map, NULL, "1.1.0" );
 
410
        xmlAddChild(psNode, msOWSCommonOperationsMetadataDomainType(ows_version, psNsOws, 
 
411
                                                                    "Parameter", "outputFormat", 
 
412
                                                                    formats_list));
 
413
        msFree( formats_list );
 
414
 
 
415
        value = msOWSLookupMetadata(&(map->web.metadata), "FO", "maxfeatures");
 
416
 
 
417
        if (value) {
 
418
            xmlAddChild(psMainNode, msOWSCommonOperationsMetadataDomainType(ows_version, psNsOws,
 
419
                                                                            "Constraint", "DefaultMaxFeatures",
 
420
                                                                            (char *)value));
 
421
        }
 
422
    }
 
423
 
 
424
/* -------------------------------------------------------------------- */
 
425
/*      FeatureTypeList                                                 */
 
426
/* -------------------------------------------------------------------- */
 
427
     
 
428
     psFtNode = xmlNewNode(NULL, BAD_CAST "FeatureTypeList");
 
429
     xmlAddChild(psRootNode, psFtNode);
 
430
     psNode = xmlNewChild(psFtNode, NULL, BAD_CAST "Operations", NULL);
 
431
     xmlNewChild(psNode, NULL, BAD_CAST "Operation", BAD_CAST "Query");
 
432
     
 
433
     for(i=0; i<map->numlayers; i++)
 
434
     {
 
435
         layerObj *lp;
 
436
         lp = GET_LAYER(map, i);
 
437
         
 
438
         if (!msIntegerInArray(lp->index, ows_request->enabled_layers, ows_request->numlayers))
 
439
             continue;
 
440
 
 
441
         /* List only vector layers in which DUMP=TRUE */
 
442
         if (msWFSIsLayerSupported(lp))
 
443
           xmlAddChild(psFtNode, msWFSDumpLayer11(map, lp, psNsOws));
 
444
     }
 
445
     
 
446
     
 
447
     
 
448
     
 
449
     
 
450
/* -------------------------------------------------------------------- */
 
451
/*      Filter capabilities.                                            */
 
452
/* -------------------------------------------------------------------- */
 
453
 
 
454
     psNsOgc = xmlNewNs(NULL, BAD_CAST MS_OWSCOMMON_OGC_NAMESPACE_URI, BAD_CAST MS_OWSCOMMON_OGC_NAMESPACE_PREFIX);
 
455
     xmlAddChild(psRootNode, FLTGetCapabilities(psNsOgc, psNsOgc, MS_FALSE));
 
456
/* -------------------------------------------------------------------- */
 
457
/*      Write out the document.                                         */
 
458
/* -------------------------------------------------------------------- */
 
459
 
 
460
    if( msIO_needBinaryStdout() == MS_FAILURE )
 
461
        return MS_FAILURE;
 
462
     
 
463
    if (encoding)
 
464
        msIO_printf("Content-type: text/xml; charset=%s%c%c", encoding,10,10);
 
465
    else
 
466
        msIO_printf("Content-type: text/xml%c%c",10,10);
 
467
    
 
468
    context = msIO_getHandler(stdout);
 
469
 
 
470
    xmlDocDumpFormatMemoryEnc(psDoc, &buffer, &size, (encoding ? encoding : "ISO-8859-1"), 1);
 
471
    msIO_contextWrite(context, buffer, size);
 
472
    xmlFree(buffer);
 
473
 
 
474
    /*free buffer and the document */
 
475
    /*xmlFree(buffer);*/
 
476
    xmlFreeDoc(psDoc);
 
477
    xmlFreeNs(psNsOgc);
 
478
 
 
479
    free(script_url);   
 
480
     free(script_url_encoded);
 
481
    free(xsi_schemaLocation);
 
482
    free(schemalocation);
 
483
 
 
484
    xmlCleanupParser();
 
485
 
 
486
    return(MS_SUCCESS);
 
487
}
 
488
    
 
489
 
 
490
#endif /*defined(USE_WFS_SVR) && defined(USE_LIBXML2)*/
 
491
 
 
492
#if defined(USE_WFS_SVR) && !defined(USE_LIBXML2)
 
493
 
 
494
 
 
495
 
 
496
int msWFSGetCapabilities11(mapObj *map, wfsParamsObj *params, 
 
497
                           cgiRequestObj *req)
 
498
 
 
499
{
 
500
    msSetError( MS_WFSERR,
 
501
                "WFS 1.1 request made, but mapserver requires libxml2 for WFS 1.1 services and this is not configured.",
 
502
                "msWFSGetCapabilities11()", "NoApplicableCode" );
 
503
 
 
504
    return msWFSException11(map, "mapserv", "NoApplicableCode", params->pszVersion);
 
505
}
 
506
 
 
507
int msWFSException11(mapObj *map, const char *locator, const char *exceptionCode, const char *version) {
 
508
    /* fallback to reporting using 1.0 style exceptions. */
 
509
    return msWFSException( map, locator, exceptionCode, "1.0.0" );
 
510
}
 
511
 
 
512
#endif /* defined(USE_WFS_SVR) && !defined(USE_LIBXML2) */