[xmltooling] 28/65: SSPCPP-684 Wire CloneInputStream into URLInputSource
Ferenc Wágner
wferi-guest at moszumanska.debian.org
Thu Jun 30 13:07:37 UTC 2016
This is an automated email from the git hooks/post-receive script.
wferi-guest pushed a commit to branch debian/master
in repository xmltooling.
commit 7ad9bc00b175b44bb2ce6cff24bcaba1f6a582cb
Author: Rod Widdowson <rdw at steadingsoftware.com>
Date: Sat Jun 4 16:15:53 2016 +0100
SSPCPP-684 Wire CloneInputStream into URLInputSource
https://issues.shibboleth.net/jira/browse/SSPCPP-684
CloneInputStream has to get a BinaryInputStream* and take
owner ship of it's deletion.
URLInputSource gains yet another optional constructor parameter
being the name of the file we want to write to.
---
.../vc14/xmltoolingtest/xmltoolingtest.vcxproj.filters | 2 +-
xmltooling/util/CloneInputStream.cpp | 5 +++--
xmltooling/util/CloneInputStream.h | 13 +++++++------
xmltooling/util/ParserPool.cpp | 18 ++++++++++--------
xmltooling/util/ParserPool.h | 8 ++++++--
xmltoolingtest/CloneInputStreamTest.h | 2 +-
6 files changed, 28 insertions(+), 20 deletions(-)
diff --git a/Projects/vc14/xmltoolingtest/xmltoolingtest.vcxproj.filters b/Projects/vc14/xmltoolingtest/xmltoolingtest.vcxproj.filters
index 1ecb743..e9f6032 100644
--- a/Projects/vc14/xmltoolingtest/xmltoolingtest.vcxproj.filters
+++ b/Projects/vc14/xmltoolingtest/xmltoolingtest.vcxproj.filters
@@ -63,7 +63,7 @@
<Filter>Generated Code</Filter>
</ClCompile>
<ClCompile Include="CloneInputStreamTest.cpp">
- <Filter>Unit Tests</Filter>
+ <Filter>Generated Code</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
diff --git a/xmltooling/util/CloneInputStream.cpp b/xmltooling/util/CloneInputStream.cpp
index a481615..43bf95e 100644
--- a/xmltooling/util/CloneInputStream.cpp
+++ b/xmltooling/util/CloneInputStream.cpp
@@ -34,7 +34,7 @@ using namespace xmltooling;
using namespace xercesc;
using namespace std;
-CloneInputStream::CloneInputStream(BinInputStream& stream, std::string backingFile)
+CloneInputStream::CloneInputStream(BinInputStream* stream, std::string backingFile)
: m_log(logging::Category::getInstance(XMLTOOLING_LOGCAT ".util.CloneInputStream"))
, m_input(stream)
, m_backingStream(backingFile.c_str(), ofstream::binary)
@@ -46,11 +46,12 @@ CloneInputStream::~CloneInputStream()
{
m_log.debug("deleted");
m_backingStream.close();
+ delete m_input;
}
XMLSize_t CloneInputStream::readBytes(XMLByte* const toFill, const XMLSize_t maxToRead)
{
- auto bytesRead = m_input.readBytes(toFill, maxToRead);
+ auto bytesRead = m_input->readBytes(toFill, maxToRead);
if (bytesRead) m_backingStream.write((char*)toFill, bytesRead);
diff --git a/xmltooling/util/CloneInputStream.h b/xmltooling/util/CloneInputStream.h
index 3304741..e18e4b1 100644
--- a/xmltooling/util/CloneInputStream.h
+++ b/xmltooling/util/CloneInputStream.h
@@ -41,24 +41,25 @@ namespace xmltooling {
/**
* Constructor.
*
- * @param TBD
- * @param TBD
+ * @param stream a stream that we will read from
+ * @param backingFele the name of a file to write every byte we read, as we read it.
+ * we take ownership of this, arranging to delete it in our destructor.
*/
- CloneInputStream(xercesc::BinInputStream &stream, std::string backingFile);
+ CloneInputStream(xercesc::BinInputStream *stream, std::string backingFile);
virtual ~CloneInputStream();
virtual XMLSize_t readBytes(XMLByte* const toFill, const XMLSize_t maxToRead);
- virtual XMLFilePos curPos() const {return m_input.curPos();};
+ virtual XMLFilePos curPos() const {return m_input->curPos();};
- virtual const XMLCh* getContentType() const {return m_input.getContentType();};
+ virtual const XMLCh* getContentType() const {return m_input->getContentType();};
private :
std::ofstream m_backingStream;
logging::Category& m_log;
- xercesc::BinInputStream& m_input;
+ xercesc::BinInputStream* m_input;
};
};
diff --git a/xmltooling/util/ParserPool.cpp b/xmltooling/util/ParserPool.cpp
index 71a36f5..bd08346 100644
--- a/xmltooling/util/ParserPool.cpp
+++ b/xmltooling/util/ParserPool.cpp
@@ -27,6 +27,7 @@
#include "internal.h"
#include "exceptions.h"
#include "logging.h"
+#include "util/CloneInputStream.h"
#include "util/CurlURLInputStream.h"
#include "util/NDC.h"
#include "util/PathResolver.h"
@@ -546,11 +547,11 @@ xsecsize_t StreamInputSource::StreamBinInputStream::readBytes(XMLByte* const toF
#ifdef XMLTOOLING_LITE
-URLInputSource::URLInputSource(const XMLCh* url, const char* systemId, string* cacheTag) : InputSource(systemId), m_url(url)
+URLInputSource::URLInputSource(const XMLCh* url, const char* systemId, string* cacheTag, std::string backingFile) : InputSource(systemId), m_url(url), m_backingFile(backingFile)
{
}
-URLInputSource::URLInputSource(const DOMElement* e, const char* systemId, string* cacheTag) : InputSource(systemId)
+URLInputSource::URLInputSource(const DOMElement* e, const char* systemId, string* cacheTag, std::string backingFile) : InputSource(systemId), m_backingFile(backingFile)
{
static const XMLCh uri[] = UNICODE_LITERAL_3(u,r,i);
static const XMLCh url[] = UNICODE_LITERAL_3(u,r,l);
@@ -568,24 +569,25 @@ URLInputSource::URLInputSource(const DOMElement* e, const char* systemId, string
BinInputStream* URLInputSource::makeStream() const
{
// Ask the URL to create us an appropriate input stream
- return m_url.makeNewStream();
+ return ("" == m_backingFile) ? m_url.makeNewStream() : new CloneInputStream(m_url.makeNewStream(), m_backingFile);
}
#else
-URLInputSource::URLInputSource(const XMLCh* url, const char* systemId, string* cacheTag)
- : InputSource(systemId), m_cacheTag(cacheTag), m_url(url), m_root(nullptr)
+URLInputSource::URLInputSource(const XMLCh* url, const char* systemId, string* cacheTag, std::string backingFile)
+ : InputSource(systemId), m_cacheTag(cacheTag), m_url(url), m_root(nullptr), m_backingFile(backingFile)
{
}
-URLInputSource::URLInputSource(const DOMElement* e, const char* systemId, string* cacheTag)
- : InputSource(systemId), m_cacheTag(cacheTag), m_root(e)
+URLInputSource::URLInputSource(const DOMElement* e, const char* systemId, string* cacheTag, std::string backingFile)
+ : InputSource(systemId), m_cacheTag(cacheTag), m_root(e), m_backingFile(backingFile)
{
}
BinInputStream* URLInputSource::makeStream() const
{
- return m_root ? new CurlURLInputStream(m_root, m_cacheTag) : new CurlURLInputStream(m_url.get(), m_cacheTag);
+ BinInputStream* stream = m_root ? new CurlURLInputStream(m_root, m_cacheTag) : new CurlURLInputStream(m_url.get(), m_cacheTag);
+ return ("" == m_backingFile) ? stream : new CloneInputStream(stream, m_backingFile);
}
#endif
diff --git a/xmltooling/util/ParserPool.h b/xmltooling/util/ParserPool.h
index 1fd127d..ce167c7 100644
--- a/xmltooling/util/ParserPool.h
+++ b/xmltooling/util/ParserPool.h
@@ -255,8 +255,9 @@ namespace xmltooling {
* @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
+ * @param backingFile optional name of file to save inout stream to.
*/
- URLInputSource(const XMLCh* url, const char* systemId=nullptr, std::string* cacheTag=nullptr);
+ URLInputSource(const XMLCh* url, const char* systemId=nullptr, std::string* cacheTag=nullptr, std::string backingFile="");
/**
* Constructor taking a DOM element supporting the following content:
@@ -273,8 +274,9 @@ namespace xmltooling {
* @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
+ * @param backingFile optional name of file to save inout stream to.
*/
- URLInputSource(const xercesc::DOMElement* e, const char* systemId=nullptr, std::string* cacheTag=nullptr);
+ URLInputSource(const xercesc::DOMElement* e, const char* systemId=nullptr, std::string* cacheTag=nullptr, std::string backingFile="");
/// @cond off
virtual xercesc::BinInputStream* makeStream() const;
@@ -286,12 +288,14 @@ namespace xmltooling {
/** Element name used to signal a non-successful response when fetching a remote document. */
static const XMLCh utf16StatusCodeElementName[];
private:
+ std::string m_backingFile;
#ifdef XMLTOOLING_LITE
xercesc::XMLURL m_url;
#else
std::string* m_cacheTag;
xmltooling::auto_ptr_char m_url;
const xercesc::DOMElement* m_root;
+
#endif
};
};
diff --git a/xmltoolingtest/CloneInputStreamTest.h b/xmltoolingtest/CloneInputStreamTest.h
index fa82348..b19df62 100644
--- a/xmltoolingtest/CloneInputStreamTest.h
+++ b/xmltoolingtest/CloneInputStreamTest.h
@@ -39,7 +39,7 @@ public:
xercesc::LocalFileInputSource src(widenitSrc.get());
BinInputStream* srcStream = src.makeStream();
- CloneInputStream clone(*srcStream, data_path + "clonedfile.xml");
+ CloneInputStream clone(srcStream, data_path + "clonedfile.xml");
XMLByte buffer[1024];
XMLSize_t sz;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-shibboleth/xmltooling.git
More information about the Pkg-shibboleth-devel
mailing list