42
42
#include "mapowscommon.h"
43
43
#include "maplibxml2.h"
45
MS_CVSID("$Id: mapowscommon.c 8170 2008-12-02 17:28:34Z tomkralidis $")
48
* msOWSCommonNegotiateVersion()
50
* returns a supported version as per subclause 7.3.2
52
* @param requested_version the version passed by the client
53
* @param supported_versions an array of supported versions
54
* @param num_supported_versions size of supported_versions
56
* @return supported version integer, or -1 on error
60
int msOWSCommonNegotiateVersion(int requested_version, int supported_versions[], int num_supported_versions) {
63
/* if version is not set return error */
64
if (! requested_version)
67
/* return the first entry that's equal to the requested version */
68
for (i = 0; i < num_supported_versions; i++) {
69
if (supported_versions[i] == requested_version)
70
return supported_versions[i];
73
/* no match; calling code should throw an exception */
45
MS_CVSID("$Id: mapowscommon.c 10772 2010-11-29 18:27:02Z aboudreault $")
487
458
xmlNewProp(psRootNode, BAD_CAST "xml:lang", BAD_CAST language);
490
xsi_schemaLocation = strdup((char *)psNsOws->href);
461
xsi_schemaLocation = msStrdup((char *)psNsOws->href);
491
462
xsi_schemaLocation = msStringConcatenate(xsi_schemaLocation, " ");
492
463
xsi_schemaLocation = msStringConcatenate(xsi_schemaLocation, (char *)schemas_location);
493
464
xsi_schemaLocation = msStringConcatenate(xsi_schemaLocation, "/ows/");
563
534
/* add attributes to the root element */
564
535
xmlNewProp(psRootNode, BAD_CAST "crs", BAD_CAST crs);
566
sprintf( dim_string, "%d", dimensions );
537
snprintf( dim_string, sizeof(dim_string), "%d", dimensions );
567
538
xmlNewProp(psRootNode, BAD_CAST "dimensions", BAD_CAST dim_string);
569
sprintf(LowerCorner, "%.15g %.15g", minx, miny);
570
sprintf(UpperCorner, "%.15g %.15g", maxx, maxy);
540
snprintf(LowerCorner, sizeof(LowerCorner), "%.15g %.15g", minx, miny);
541
snprintf(UpperCorner, sizeof(UpperCorner), "%.15g %.15g", maxx, maxy);
572
543
/* add child elements */
573
544
xmlNewChild(psRootNode, psNsOws,BAD_CAST "LowerCorner",BAD_CAST LowerCorner);
604
575
/* create element name */
605
576
psRootNode = xmlNewNode(psNsOws, BAD_CAST "WGS84BoundingBox");
607
sprintf( dim_string, "%d", dimensions );
578
snprintf( dim_string, sizeof(dim_string), "%d", dimensions );
608
579
xmlNewProp(psRootNode, BAD_CAST "dimensions", BAD_CAST dim_string);
610
sprintf(LowerCorner, "%.15g %.15g", minx, miny);
611
sprintf(UpperCorner, "%.15g %.15g", maxx, maxy);
581
snprintf(LowerCorner, sizeof(LowerCorner), "%.15g %.15g", minx, miny);
582
snprintf(UpperCorner, sizeof(UpperCorner), "%.15g %.15g", maxx, maxy);
613
584
/* add child elements */
614
585
xmlNewChild(psRootNode, psNsOws,BAD_CAST "LowerCorner",BAD_CAST LowerCorner);
631
602
int _validateNamespace(xmlNsPtr psNsOws) {
632
603
char namespace_prefix[10];
633
sprintf(namespace_prefix, "%s", psNsOws->prefix);
604
snprintf(namespace_prefix, sizeof(namespace_prefix), "%s", psNsOws->prefix);
634
605
if (strcmp(namespace_prefix, MS_OWSCOMMON_OWS_NAMESPACE_PREFIX) == 0)
635
606
return MS_SUCCESS;
637
608
return MS_FAILURE;
611
xmlNodePtr msOWSCommonxmlNewChildEncoded( xmlNodePtr psParent, xmlNsPtr psNs, const char* name,
612
const char *content, const char *encoding)
614
char *encoded = NULL;
617
if (encoding && content)
619
encoded = msGetEncodedString(content, encoding);
620
psNode = xmlNewChild(psParent, psNs, BAD_CAST name, BAD_CAST encoded);
625
return xmlNewChild(psParent, psNs, BAD_CAST name, BAD_CAST content);
629
* Valid an xml string against an XML schema
630
* Inpired from: http://xml.developpez.com/sources/?page=validation#validate_XSD_CppCLI_2
631
* taken from tinyows.org
633
int msOWSSchemaValidation(const char* xml_schema, const char* xml)
636
xmlSchemaParserCtxtPtr ctxt;
637
xmlSchemaValidCtxtPtr validctxt;
641
if (!xml_schema || !xml)
648
/* Open XML Schema File */
649
ctxt = xmlSchemaNewParserCtxt(xml_schema);
651
else ctxt = xmlSchemaNewMemParserCtxt(xml_schema);
654
xmlSchemaSetParserErrors(ctxt,
655
(xmlSchemaValidityErrorFunc) libxml2_callback,
656
(xmlSchemaValidityWarningFunc) libxml2_callback, stderr);
659
schema = xmlSchemaParse(ctxt);
660
xmlSchemaFreeParserCtxt(ctxt);
662
/* If XML Schema hasn't been rightly loaded */
663
if (schema == NULL) {
664
xmlSchemaCleanupTypes();
670
doc = xmlParseDoc((xmlChar *)xml);
673
/* Loading XML Schema content */
674
validctxt = xmlSchemaNewValidCtxt(schema);
676
xmlSchemaSetValidErrors(validctxt,
677
(xmlSchemaValidityErrorFunc) libxml2_callback,
678
(xmlSchemaValidityWarningFunc) libxml2_callback, stderr);
681
ret = xmlSchemaValidateDoc(validctxt, doc);
682
xmlSchemaFreeValidCtxt(validctxt);
685
xmlSchemaFree(schema);
640
692
#endif /* defined(USE_LIBXML2) */
696
* msOWSCommonNegotiateVersion()
698
* returns a supported version as per subclause 7.3.2
700
* @param requested_version the version passed by the client
701
* @param supported_versions an array of supported versions
702
* @param num_supported_versions size of supported_versions
704
* @return supported version integer, or -1 on error
708
int msOWSCommonNegotiateVersion(int requested_version, int supported_versions[], int num_supported_versions) {
711
/* if version is not set return error */
712
if (! requested_version)
715
/* return the first entry that's equal to the requested version */
716
for (i = 0; i < num_supported_versions; i++) {
717
if (supported_versions[i] == requested_version)
718
return supported_versions[i];
721
/* no match; calling code should throw an exception */