X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltooling%2Futil%2FParserPool.h;h=c3067ac6b12621977ce2494e5bde3c809dacfb91;hb=81b488b2790e7bdeb2f43560b1d4a7d22c3dfdf5;hp=ebc7bf11820cd5f13b2fbb889e815e775aed2043;hpb=aff64904d1663ea3770daa633a80f64d205fbb2f;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltooling/util/ParserPool.h b/xmltooling/util/ParserPool.h index ebc7bf1..c3067ac 100644 --- a/xmltooling/util/ParserPool.h +++ b/xmltooling/util/ParserPool.h @@ -1,37 +1,47 @@ -/* - * Copyright 2001-2007 Internet2 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at +/** + * Licensed to the University Corporation for Advanced Internet + * Development, Inc. (UCAID) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + * + * UCAID licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the + * License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. */ /** * @file xmltooling/util/ParserPool.h - * - * A thread-safe pool of DOMBuilders that share characteristics. + * + * A thread-safe pool of parsers that share characteristics. */ #ifndef __xmltooling_pool_h__ #define __xmltooling_pool_h__ #include -#include #include #include +#include #include #include #include #include +#include +#include + +#ifndef XMLTOOLING_NO_XMLSEC +# include +#endif #if defined (_MSC_VER) #pragma warning( push ) @@ -40,16 +50,23 @@ namespace xmltooling { + class XMLTOOL_API Mutex; + /** * A thread-safe pool of DOMBuilders that share characteristics. */ - class XMLTOOL_API ParserPool : public xercesc::DOMEntityResolver, xercesc::DOMErrorHandler + class XMLTOOL_API ParserPool : +#ifdef XMLTOOLING_XERCESC_COMPLIANT_DOMLS + public xercesc::DOMLSResourceResolver +#else + public xercesc::DOMEntityResolver +#endif { MAKE_NONCOPYABLE(ParserPool); public: /** * Constructs a new pool - * + * * @param namespaceAware indicates whether parsers should be namespace-aware or not * @param schemaAware indicates whether parsers should be schema-validating or not */ @@ -58,24 +75,30 @@ namespace xmltooling { /** * Creates a new document using a parser from this pool. - * + * * @return new XML document - * + * */ xercesc::DOMDocument* newDocument(); /** * Parses a document using a pooled parser with the proper settings - * - * @param domsrc A DOM source containing the content to be parsed + * + * @param domsrc An input source containing the content to be parsed * @return The DOM document resulting from the parse * @throws XMLParserException thrown if there was a problem reading, parsing, or validating the XML */ - xercesc::DOMDocument* parse(xercesc::DOMInputSource& domsrc); + xercesc::DOMDocument* parse( +#ifdef XMLTOOLING_XERCESC_COMPLIANT_DOMLS + xercesc::DOMLSInput& domsrc +#else + xercesc::DOMInputSource& domsrc +#endif + ); /** * Parses a document using a pooled parser with the proper settings - * + * * @param is An input stream containing the content to be parsed * @return The DOM document resulting from the parse * @throws XMLParserException thrown if there was a problem reading, parsing, or validating the XML @@ -84,21 +107,21 @@ namespace xmltooling { /** * Load an OASIS catalog file to map schema namespace URIs to filenames. - * + * * This does not provide real catalog support; only the <uri> element * is supported to map from a namespace URI to a relative path or file:// URI. - * + * * @param pathname path to a catalog file * @return true iff the catalog was successfully processed */ bool loadCatalog(const XMLCh* pathname); - + /** * Load a schema explicitly from a local file. - * + * * Note that "successful processing" does not imply that the schema is valid, * only that a reference to it was successfully registered with the pool. - * + * * @param nsURI XML namespace to load * @param pathname path to schema file * @return true iff the schema was successfully processed @@ -108,28 +131,42 @@ namespace xmltooling { /** * Supplies all external entities (primarily schemas) to the parser */ - xercesc::DOMInputSource* resolveEntity(const XMLCh* const publicId, const XMLCh* const systemId, const XMLCh* const baseURI); - - /** - * Handles parsing errors - */ - bool handleError(const xercesc::DOMError& e); +#ifdef XMLTOOLING_XERCESC_COMPLIANT_DOMLS + xercesc::DOMLSInput* resolveResource( + const XMLCh *const resourceType, + const XMLCh *const namespaceUri, + const XMLCh *const publicId, + const XMLCh *const systemId, + const XMLCh *const baseURI + ); +#else + xercesc::DOMInputSource* resolveEntity( + const XMLCh* const publicId, const XMLCh* const systemId, const XMLCh* const baseURI + ); +#endif private: +#ifdef XMLTOOLING_XERCESC_COMPLIANT_DOMLS + xercesc::DOMLSParser* createBuilder(); + xercesc::DOMLSParser* checkoutBuilder(); + void checkinBuilder(xercesc::DOMLSParser* builder); +#else xercesc::DOMBuilder* createBuilder(); xercesc::DOMBuilder* checkoutBuilder(); void checkinBuilder(xercesc::DOMBuilder* builder); +#endif -#ifdef HAVE_GOOD_STL xstring m_schemaLocations; std::map m_schemaLocMap; -#else - std::string m_schemaLocations; - std::map m_schemaLocMap; -#endif + bool m_namespaceAware,m_schemaAware; +#ifdef XMLTOOLING_XERCESC_COMPLIANT_DOMLS + std::stack m_pool; +#else std::stack m_pool; +#endif Mutex* m_lock; + xercesc::SecurityManager* m_security; }; /** @@ -141,13 +178,13 @@ namespace xmltooling { public: /** * Constructs an input source around an input stream reference. - * + * * @param is reference to an input stream * @param systemId optional system identifier to attach to the stream */ - StreamInputSource(std::istream& is, const char* systemId=NULL) : xercesc::InputSource(systemId), m_is(is) {} + StreamInputSource(std::istream& is, const char* systemId=nullptr); /// @cond off - virtual xercesc::BinInputStream* makeStream() const { return new StreamBinInputStream(m_is); } + xercesc::BinInputStream* makeStream() const; /// @endcond /** @@ -158,22 +195,80 @@ namespace xmltooling { public: /** * Constructs a Xerces input stream around a C++ input stream reference. - * - * @param is reference to an input stream + * + * @param is reference to an input stream */ - StreamBinInputStream(std::istream& is) : m_is(is), m_pos(0) {} + StreamBinInputStream(std::istream& is); /// @cond off - virtual unsigned int curPos() const { return m_pos; } - virtual unsigned int readBytes(XMLByte* const toFill, const unsigned int maxToRead); +#ifdef XMLTOOLING_XERCESC_64BITSAFE + XMLFilePos curPos() const; + const XMLCh* getContentType() const; +#else + unsigned int curPos() const; +#endif + xsecsize_t readBytes(XMLByte* const toFill, const xsecsize_t maxToRead); /// @endcond private: std::istream& m_is; - unsigned int m_pos; + xsecsize_t m_pos; }; private: std::istream& m_is; }; + + /** + * A URL-based parser source that supports a more advanced input stream. + */ + class XMLTOOL_API URLInputSource : public xercesc::InputSource + { + MAKE_NONCOPYABLE(URLInputSource); + public: + /** + * Constructor. + * + * @param url source of input + * @param systemId optional system identifier to attach to the source + * @param cacheTag optional pointer to string used for cache management + */ + URLInputSource(const XMLCh* url, const char* systemId=nullptr, std::string* cacheTag=nullptr); + + /** + * Constructor taking a DOM element supporting the following content: + * + *
+ *
uri | url
+ *
identifies the remote resource
+ *
verifyHost
+ *
true iff name of host should be matched against TLS/SSL certificate
+ *
TransportOption elements, like so:
+ *
<TransportOption provider="CURL" option="150">0</TransportOption>
+ *
+ * + * @param e DOM to supply configuration + * @param systemId optional system identifier to attach to the source + * @param cacheTag optional pointer to string used for cache management + */ + URLInputSource(const xercesc::DOMElement* e, const char* systemId=nullptr, std::string* cacheTag=nullptr); + + /// @cond off + virtual xercesc::BinInputStream* makeStream() const; + /// @endcond + + /** Element name used to signal a non-successful response when fetching a remote document. */ + static const char asciiStatusCodeElementName[]; + + /** Element name used to signal a non-successful response when fetching a remote document. */ + static const XMLCh utf16StatusCodeElementName[]; + private: +#ifdef XMLTOOLING_LITE + xercesc::XMLURL m_url; +#else + std::string* m_cacheTag; + xmltooling::auto_ptr_char m_url; + const xercesc::DOMElement* m_root; +#endif + }; }; #if defined (_MSC_VER)