Skip to content

Commit 9fd134b

Browse files
committed
Implement Inspire extensions for WFS 2.0
1 parent 3841065 commit 9fd134b

16 files changed

+380
-93
lines changed

mapio.c

+54-2
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,57 @@ void msIO_installStdoutToBuffer()
650650
&group->stderr_context );
651651
}
652652

653+
654+
/************************************************************************/
655+
/* msIO_pushStdoutToBufferAndGetOldContext() */
656+
/* */
657+
/* This function installs a temporary buffer I/O context and returns */
658+
/* previously installed stdout handler. This previous stdout handler */
659+
/* should later be restored with msIO_restoreOldStdoutContext(). */
660+
/* This function can be for example used when wanting to ingest into */
661+
/* libxml objects XML generated by msIO_fprintf() */
662+
/************************************************************************/
663+
664+
msIOContext* msIO_pushStdoutToBufferAndGetOldContext()
665+
666+
{
667+
msIOContextGroup *group = msIO_GetContextGroup();
668+
msIOContext *old_context;
669+
670+
/* Backup current context */
671+
old_context = (msIOContext*) msSmallMalloc(sizeof(msIOContext));
672+
memcpy(old_context, &group->stdout_context, sizeof(msIOContext));
673+
674+
msIO_installStdoutToBuffer();
675+
676+
return old_context;
677+
}
678+
679+
/************************************************************************/
680+
/* msIO_restoreOldStdoutContext() */
681+
/************************************************************************/
682+
683+
void msIO_restoreOldStdoutContext(msIOContext *context_to_restore)
684+
{
685+
msIOContextGroup *group = msIO_GetContextGroup();
686+
msIOContext *prev_context = &group->stdout_context;
687+
msIOBuffer* buffer;
688+
689+
/* Free memory associated to our temporary context */
690+
assert( strcmp(prev_context->label, "buffer") == 0 );
691+
692+
buffer = (msIOBuffer* )prev_context->cbData;
693+
msFree(buffer->data);
694+
msFree(buffer);
695+
696+
/* Restore old context */
697+
msIO_installHandlers( &group->stdin_context,
698+
context_to_restore,
699+
&group->stderr_context );
700+
701+
msFree(context_to_restore);
702+
}
703+
653704
/************************************************************************/
654705
/* msIO_installStdinFromBuffer() */
655706
/************************************************************************/
@@ -847,9 +898,9 @@ int msIO_bufferWrite( void *cbData, void *data, int byteCount )
847898
msIOBuffer *buf = (msIOBuffer *) cbData;
848899

849900
/*
850-
** Grow buffer if needed.
901+
** Grow buffer if needed (reserve one extra byte to put nul character)
851902
*/
852-
if( buf->data_offset + byteCount > buf->data_len ) {
903+
if( buf->data_offset + byteCount >= buf->data_len ) {
853904
buf->data_len = buf->data_len * 2 + byteCount + 100;
854905
if( buf->data == NULL )
855906
buf->data = (unsigned char *) malloc(buf->data_len);
@@ -871,6 +922,7 @@ int msIO_bufferWrite( void *cbData, void *data, int byteCount )
871922

872923
memcpy( buf->data + buf->data_offset, data, byteCount );
873924
buf->data_offset += byteCount;
925+
buf->data[buf->data_offset] = '\0';
874926

875927
return byteCount;
876928
}

mapio.h

+3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ extern "C" {
104104
void MS_DLL_EXPORT msIO_Cleanup(void);
105105
char MS_DLL_EXPORT *msIO_stripStdoutBufferContentType(void);
106106
void MS_DLL_EXPORT msIO_stripStdoutBufferContentHeaders(void);
107+
108+
msIOContext *msIO_pushStdoutToBufferAndGetOldContext(void);
109+
void msIO_restoreOldStdoutContext(msIOContext *context_to_restore);
107110

108111
/* this is just for setting normal stdout's to binary mode on windows */
109112

mapogcsos.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1240,10 +1240,10 @@ int msSOSGetCapabilities(mapObj *map, sosParamsObj *sosparams, cgiRequestObj *re
12401240
xmlAddChild(psRootNode, xmlNewComment(BAD_CAST msGetVersion()));
12411241

12421242
/*service identification*/
1243-
xmlAddChild(psRootNode, msOWSCommonServiceIdentification(psNsOws, map, "SOS", pszSOSVersion, "SO"));
1243+
xmlAddChild(psRootNode, msOWSCommonServiceIdentification(psNsOws, map, "SOS", pszSOSVersion, "SO", NULL));
12441244

12451245
/*service provider*/
1246-
xmlAddChild(psRootNode, msOWSCommonServiceProvider(psNsOws, psNsXLink, map, "SO"));
1246+
xmlAddChild(psRootNode, msOWSCommonServiceProvider(psNsOws, psNsXLink, map, "SO", NULL));
12471247

12481248
/*operation metadata */
12491249

mapows.c

+34-8
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,26 @@ const char *msOWSGetSchemasLocation(mapObj *map)
11571157
return schemas_location;
11581158
}
11591159

1160+
/* msOWSGetInspireSchemasLocation()
1161+
**
1162+
** schemas location is the root of the web tree where all Inspire-related
1163+
** schemas can be found on this server. These URLs must exist in order
1164+
** to validate xml.
1165+
**
1166+
** Use value of "inspire_schemas_location" metadata
1167+
*/
1168+
const char *msOWSGetInspireSchemasLocation(mapObj *map)
1169+
{
1170+
const char *schemas_location;
1171+
1172+
schemas_location = msLookupHashTable(&(map->web.metadata),
1173+
"inspire_schemas_location");
1174+
if (schemas_location == NULL)
1175+
schemas_location = "http://inspire.ec.europa.eu/schemas";
1176+
1177+
return schemas_location;
1178+
}
1179+
11601180
/* msOWSGetLanguage()
11611181
**
11621182
** returns the language via MAP/WEB/METADATA/ows_language
@@ -1252,16 +1272,19 @@ char *msOWSGetLanguageFromList(mapObj *map, const char *namespaces, const char *
12521272
** Returns a status code; MS_NOERR if all ok, action_if_not_found otherwise
12531273
*/
12541274
int msOWSPrintInspireCommonExtendedCapabilities(FILE *stream, mapObj *map, const char *namespaces,
1255-
int action_if_not_found, const char *tag_name,
1256-
const char *validated_language, const int service)
1275+
int action_if_not_found, const char *tag_name, const char* tag_ns,
1276+
const char *validated_language, const OWSServiceType service)
12571277
{
12581278

12591279
int metadataStatus = 0;
12601280
int languageStatus = 0;
12611281

1262-
msIO_fprintf(stream, " <%s>\n", tag_name);
1282+
if( tag_ns )
1283+
msIO_fprintf(stream, " <%s %s>\n", tag_name, tag_ns);
1284+
else
1285+
msIO_fprintf(stream, " <%s>\n", tag_name);
12631286

1264-
metadataStatus = msOWSPrintInspireCommonMetadata(stream, map, namespaces, action_if_not_found);
1287+
metadataStatus = msOWSPrintInspireCommonMetadata(stream, map, namespaces, action_if_not_found, service);
12651288
languageStatus = msOWSPrintInspireCommonLanguages(stream, map, namespaces, action_if_not_found, validated_language);
12661289

12671290
msIO_fprintf(stream, " </%s>\n", tag_name);
@@ -1276,7 +1299,7 @@ int msOWSPrintInspireCommonExtendedCapabilities(FILE *stream, mapObj *map, const
12761299
** Returns a status code; MS_NOERR if all OK, action_if_not_found otherwise
12771300
*/
12781301
int msOWSPrintInspireCommonMetadata(FILE *stream, mapObj *map, const char *namespaces,
1279-
int action_if_not_found)
1302+
int action_if_not_found, const OWSServiceType service)
12801303
{
12811304

12821305
int status = MS_NOERR;
@@ -1303,7 +1326,7 @@ int msOWSPrintInspireCommonMetadata(FILE *stream, mapObj *map, const char *names
13031326
}
13041327
}
13051328
} else if (strcasecmp("embed",inspire_capabilities) == 0) {
1306-
msOWSPrintEncodeMetadata(stream, &(map->web.metadata), namespaces, "inspire_resourcelocator", OWS_NOERR, " <inspire_common:ResourceLocator>\n <inspire_common:URL>%s</inspire_common:URL>\n </inspire_common:ResourceLocator>\n", NULL);
1329+
msOWSPrintEncodeMetadata(stream, &(map->web.metadata), namespaces, "inspire_resourcelocator", OWS_WARN, " <inspire_common:ResourceLocator>\n <inspire_common:URL>%s</inspire_common:URL>\n </inspire_common:ResourceLocator>\n", NULL);
13071330
msIO_fprintf(stream," <inspire_common:ResourceType>service</inspire_common:ResourceType>\n");
13081331
msOWSPrintEncodeMetadata(stream, &(map->web.metadata), namespaces, "inspire_temporal_reference", OWS_WARN, " <inspire_common:TemporalReference>\n <inspire_common:DateOfLastRevision>%s</inspire_common:DateOfLastRevision>\n </inspire_common:TemporalReference>\n", "");
13091332
msIO_fprintf(stream, " <inspire_common:Conformity>\n");
@@ -1318,7 +1341,10 @@ int msOWSPrintInspireCommonMetadata(FILE *stream, mapObj *map, const char *names
13181341
msOWSPrintEncodeMetadata(stream, &(map->web.metadata), namespaces, "inspire_mpoc_email", OWS_WARN, " <inspire_common:EmailAddress>%s</inspire_common:EmailAddress>\n", "");
13191342
msIO_fprintf(stream, " </inspire_common:MetadataPointOfContact>\n");
13201343
msOWSPrintEncodeMetadata(stream, &(map->web.metadata), namespaces, "inspire_metadatadate", OWS_WARN, " <inspire_common:MetadataDate>%s</inspire_common:MetadataDate>\n", "");
1321-
msIO_fprintf(stream," <inspire_common:SpatialDataServiceType>view</inspire_common:SpatialDataServiceType>\n");
1344+
if( service == OWS_WFS )
1345+
msIO_fprintf(stream," <inspire_common:SpatialDataServiceType>download</inspire_common:SpatialDataServiceType>\n");
1346+
else
1347+
msIO_fprintf(stream," <inspire_common:SpatialDataServiceType>view</inspire_common:SpatialDataServiceType>\n");
13221348
msOWSPrintEncodeMetadata(stream, &(map->web.metadata), namespaces, "inspire_keyword", OWS_WARN, " <inspire_common:MandatoryKeyword xsi:type='inspire_common:classificationOfSpatialDataService'>\n <inspire_common:KeywordValue>%s</inspire_common:KeywordValue>\n </inspire_common:MandatoryKeyword>\n", "");
13231349
} else {
13241350
status = action_if_not_found;
@@ -2023,7 +2049,7 @@ void msOWSPrintEX_GeographicBoundingBox(FILE *stream, const char *tabspace,
20232049
*/
20242050
void msOWSPrintLatLonBoundingBox(FILE *stream, const char *tabspace,
20252051
rectObj *extent, projectionObj *srcproj,
2026-
projectionObj *wfsproj, int nService)
2052+
projectionObj *wfsproj, OWSServiceType nService)
20272053
{
20282054
const char *pszTag = "LatLonBoundingBox"; /* The default for WMS */
20292055
rectObj ext;

mapows.h

+13-8
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ typedef struct {
5555
char *pszGeometryName;
5656
int nMaxFeatures;
5757
char *pszBbox; /* only used with a Get Request */
58-
char *pszOutputFormat; /* only used with DescibeFeatureType */
58+
char *pszOutputFormat;
5959
char *pszFeatureId;
6060
char *pszSrs;
6161
char *pszResultType;
@@ -64,6 +64,7 @@ typedef struct {
6464
char *pszAcceptVersions;
6565
char *pszSections;
6666
char *pszSortBy; /* Not implemented yet */
67+
char *pszLanguage;
6768
} wfsParamsObj;
6869

6970
/*
@@ -164,6 +165,7 @@ MS_DLL_EXPORT char *msOWSTerminateOnlineResource(const char *src_url);
164165
MS_DLL_EXPORT char *msOWSGetOnlineResource(mapObj *map, const char *namespaces, const char *metadata_name, cgiRequestObj *req);
165166
MS_DLL_EXPORT char *msOWSGetOnlineResource2(mapObj *map, const char *namespaces, const char *metadata_name, cgiRequestObj *req, const char *validated_language);
166167
MS_DLL_EXPORT const char *msOWSGetSchemasLocation(mapObj *map);
168+
MS_DLL_EXPORT const char *msOWSGetInspireSchemasLocation(mapObj *map);
167169
MS_DLL_EXPORT const char *msOWSGetLanguage(mapObj *map, const char *context);
168170
MS_DLL_EXPORT char **msOWSGetLanguageList(mapObj *map, const char *namespaces, int *numitems);
169171
MS_DLL_EXPORT char *msOWSGetLanguageFromList(mapObj *map, const char *namespaces, const char *requested_language);
@@ -175,14 +177,17 @@ MS_DLL_EXPORT char *msOWSGetLanguageFromList(mapObj *map, const char *namespaces
175177

176178
/* OWS_WMS and OWS_WFS used for functions that differ in behavior between */
177179
/* WMS and WFS services (e.g. msOWSPrintLatLonBoundingBox()) */
178-
#define OWS_WMS 1
179-
#define OWS_WFS 2
180+
typedef enum
181+
{
182+
OWS_WMS = 1,
183+
OWS_WFS = 2
184+
} OWSServiceType;
180185

181186
MS_DLL_EXPORT int msOWSPrintInspireCommonExtendedCapabilities(FILE *stream, mapObj *map, const char *namespaces,
182-
const int action_if_not_found, const char *tag_name,
183-
const char *validated_language, const int service);
187+
const int action_if_not_found, const char *tag_name, const char* tag_ns,
188+
const char *validated_language, const OWSServiceType service);
184189
int msOWSPrintInspireCommonMetadata(FILE *stream, mapObj *map, const char *namespaces,
185-
int action_if_not_found);
190+
int action_if_not_found, const OWSServiceType service);
186191
int msOWSPrintInspireCommonLanguages(FILE *stream, mapObj *map, const char *namespaces,
187192
int action_if_not_found, const char *validated_language);
188193

@@ -252,7 +257,7 @@ int msOWSPrintEncodeParamList(FILE *stream, const char *name,
252257
void msOWSProjectToWGS84(projectionObj *srcproj, rectObj *ext);
253258
void msOWSPrintLatLonBoundingBox(FILE *stream, const char *tabspace,
254259
rectObj *extent, projectionObj *srcproj,
255-
projectionObj *wfsproj, int nService);
260+
projectionObj *wfsproj, OWSServiceType nService);
256261
void msOWSPrintEX_GeographicBoundingBox(FILE *stream, const char *tabspace,
257262
rectObj *extent, projectionObj *srcproj);
258263

@@ -460,7 +465,7 @@ int msWFSGetCapabilities11(mapObj *map, wfsParamsObj *wfsparams,
460465
#ifdef USE_LIBXML2
461466
#include<libxml/tree.h>
462467
xmlNodePtr msWFSDumpLayer11(mapObj *map, layerObj *lp, xmlNsPtr psNsOws,
463-
int nWFSVersion);
468+
int nWFSVersion, const char* validate_language);
464469
#endif
465470
char *msWFSGetOutputFormatList(mapObj *map, layerObj *layer, int nWFSVersion);
466471

0 commit comments

Comments
 (0)