[xmltooling] 23/65: SSPCPP-684 Cloning xercesc::BinInputStream

Ferenc Wágner wferi-guest at moszumanska.debian.org
Thu Jun 30 13:07:35 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 e5b2f140d159ce3497029de765feaa3a8a0c835f
Author: Rod Widdowson <rdw at steadingsoftware.com>
Date:   Tue May 31 14:56:19 2016 +0100

    SSPCPP-684 Cloning xercesc::BinInputStream
    
    https://issues.shibboleth.net/jira/browse/SSPCPP-684
    
    Introduce a new class xmltooling::CloneInputStream
    
    This is plug compatible with the URL and curl input
    streams but this one spools data away into a local file.
    
    Outer code can then call this a backup file (or delete it).
    
    For my sanity also introduce unit test.
---
 Projects/vc10/xmltooling/xmltooling.vcxproj        |  6 +-
 .../vc10/xmltooling/xmltooling.vcxproj.filters     | 12 +++-
 .../vc10/xmltoolingtest/xmltoolingtest.vcxproj     | 15 +++++
 Projects/vc14/xmltooling/xmltooling.vcxproj        |  6 +-
 .../vc14/xmltooling/xmltooling.vcxproj.filters     | 10 ++-
 xmltooling/util/CloneInputStream.cpp               | 58 +++++++++++++++++
 xmltooling/util/CloneInputStream.h                 | 65 +++++++++++++++++++
 xmltoolingtest/CloneInputStreamTest.h              | 72 ++++++++++++++++++++++
 8 files changed, 235 insertions(+), 9 deletions(-)

diff --git a/Projects/vc10/xmltooling/xmltooling.vcxproj b/Projects/vc10/xmltooling/xmltooling.vcxproj
index f69f937..2320132 100644
--- a/Projects/vc10/xmltooling/xmltooling.vcxproj
+++ b/Projects/vc10/xmltooling/xmltooling.vcxproj
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup Label="ProjectConfigurations">
     <ProjectConfiguration Include="Debug|Win32">
@@ -196,6 +196,7 @@
     <ClCompile Include="..\..\..\XMLTooling\QName.cpp" />
     <ClCompile Include="..\..\..\XMLTooling\security\impl\PKIXPathValidator.cpp" />
     <ClCompile Include="..\..\..\XMLTooling\unicode.cpp" />
+    <ClCompile Include="..\..\..\XMLTooling\util\CloneInputStream.cpp" />
     <ClCompile Include="..\..\..\XMLTooling\version.cpp" />
     <ClCompile Include="..\..\..\XMLTooling\XMLObjectBuilder.cpp" />
     <ClCompile Include="..\..\..\XMLTooling\XMLToolingConfig.cpp" />
@@ -273,6 +274,7 @@
     <ClInclude Include="..\..\..\XMLTooling\security\PathValidator.h" />
     <ClInclude Include="..\..\..\XMLTooling\security\PKIXPathValidatorParams.h" />
     <ClInclude Include="..\..\..\XMLTooling\unicode.h" />
+    <ClInclude Include="..\..\..\xmltooling\util\CloneInputStream.h" />
     <ClInclude Include="..\..\..\XMLTooling\version.h" />
     <ClInclude Include="..\..\..\XMLTooling\XMLObject.h" />
     <ClInclude Include="..\..\..\XMLTooling\XMLObjectBuilder.h" />
@@ -344,4 +346,4 @@
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/Projects/vc10/xmltooling/xmltooling.vcxproj.filters b/Projects/vc10/xmltooling/xmltooling.vcxproj.filters
index 670536a..bee07e2 100644
--- a/Projects/vc10/xmltooling/xmltooling.vcxproj.filters
+++ b/Projects/vc10/xmltooling/xmltooling.vcxproj.filters
@@ -267,6 +267,9 @@
     <ClCompile Include="..\..\..\XMLTooling\security\impl\PKIXPathValidator.cpp">
       <Filter>Source Files\security\impl</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\..\XMLTooling\util\CloneInputStream.cpp">
+      <Filter>Source Files\util</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\..\XMLTooling\AbstractAttributeExtensibleXMLObject.h">
@@ -515,14 +518,17 @@
     <ClInclude Include="..\..\..\XMLTooling\security\PKIXPathValidatorParams.h">
       <Filter>Header Files\security</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\..\XMLTooling\util\CloneInputStream.h">
+      <Filter>Header Files\util</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
-    <ResourceCompile Include="xmltooling.rc">
+    <ResourceCompile Include="..\..\..\XMLTooling\xmltooling.rc">
       <Filter>Resource Files</Filter>
     </ResourceCompile>
   </ItemGroup>
   <ItemGroup>
-    <None Include="config_pub.h.in" />
-    <None Include="Makefile.am" />
+    <None Include="..\..\..\XMLTooling\config_pub.h.in" />
+    <None Include="..\..\..\XMLTooling\Makefile.am" />
   </ItemGroup>
 </Project>
diff --git a/Projects/vc10/xmltoolingtest/xmltoolingtest.vcxproj b/Projects/vc10/xmltoolingtest/xmltoolingtest.vcxproj
index 09f873b..8399157 100644
--- a/Projects/vc10/xmltoolingtest/xmltoolingtest.vcxproj
+++ b/Projects/vc10/xmltoolingtest/xmltoolingtest.vcxproj
@@ -170,6 +170,7 @@
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClCompile Include="CloneInputStreamTest.cpp" />
     <ClCompile Include="ComplexXMLObjectTest.cpp" />
     <ClCompile Include="DateTimeTest.cpp" />
     <ClCompile Include="EncryptionTest.cpp" />
@@ -189,6 +190,20 @@
     <ClCompile Include="xmltoolingtest.cpp" />
   </ItemGroup>
   <ItemGroup>
+    <CustomBuild Include="..\..\..\XMLToolingTest\CloneInputStreamTest.h">
+      <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">perl.exe -w $(CxxTestRoot)\cxxtestgen.pl --part --have-eh --have-std --abort-on-fail -o "%(Filename)".cpp "%(FullPath)"
+</Command>
+      <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Filename).cpp;%(Outputs)</Outputs>
+      <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">perl.exe -w $(CxxTestRoot)\cxxtestgen.pl --part --have-eh --have-std --abort-on-fail -o "%(Filename)".cpp "%(FullPath)"
+</Command>
+      <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).cpp;%(Outputs)</Outputs>
+      <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">perl.exe -w $(CxxTestRoot)\cxxtestgen.pl --part --have-eh --have-std --abort-on-fail -o "%(Filename)".cpp "%(FullPath)"
+</Command>
+      <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(Filename).cpp;%(Outputs)</Outputs>
+      <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">perl.exe -w $(CxxTestRoot)\cxxtestgen.pl --part --have-eh --have-std --abort-on-fail -o "%(Filename)".cpp "%(FullPath)"
+</Command>
+      <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).cpp;%(Outputs)</Outputs>
+    </CustomBuild>
     <CustomBuild Include="..\..\..\XMLToolingTest\ComplexXMLObjectTest.h">
       <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">perl.exe -w $(CxxTestRoot)\cxxtestgen.pl --part --have-eh --have-std --abort-on-fail -o "%(Filename)".cpp "%(FullPath)"
 </Command>
diff --git a/Projects/vc14/xmltooling/xmltooling.vcxproj b/Projects/vc14/xmltooling/xmltooling.vcxproj
index 4214a67..1d8c788 100644
--- a/Projects/vc14/xmltooling/xmltooling.vcxproj
+++ b/Projects/vc14/xmltooling/xmltooling.vcxproj
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup Label="ProjectConfigurations">
     <ProjectConfiguration Include="Debug|Win32">
@@ -204,6 +204,7 @@
     <ClCompile Include="..\..\..\XMLTooling\QName.cpp" />
     <ClCompile Include="..\..\..\XMLTooling\security\impl\PKIXPathValidator.cpp" />
     <ClCompile Include="..\..\..\XMLTooling\unicode.cpp" />
+    <ClCompile Include="..\..\..\XMLTooling\util\CloneInputStream.cpp" />
     <ClCompile Include="..\..\..\XMLTooling\version.cpp" />
     <ClCompile Include="..\..\..\XMLTooling\XMLObjectBuilder.cpp" />
     <ClCompile Include="..\..\..\XMLTooling\XMLToolingConfig.cpp" />
@@ -291,6 +292,7 @@
     <ClInclude Include="..\..\..\XMLTooling\security\PathValidator.h" />
     <ClInclude Include="..\..\..\XMLTooling\security\PKIXPathValidatorParams.h" />
     <ClInclude Include="..\..\..\XMLTooling\unicode.h" />
+    <ClInclude Include="..\..\..\XMLTooling\util\CloneInputStream.h" />
     <ClInclude Include="..\..\..\XMLTooling\version.h" />
     <ClInclude Include="..\..\..\XMLTooling\XMLObject.h" />
     <ClInclude Include="..\..\..\XMLTooling\XMLObjectBuilder.h" />
@@ -362,4 +364,4 @@
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/Projects/vc14/xmltooling/xmltooling.vcxproj.filters b/Projects/vc14/xmltooling/xmltooling.vcxproj.filters
index ec308ec..40ac451 100644
--- a/Projects/vc14/xmltooling/xmltooling.vcxproj.filters
+++ b/Projects/vc14/xmltooling/xmltooling.vcxproj.filters
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup>
     <Filter Include="Source Files">
@@ -267,6 +267,9 @@
     <ClCompile Include="..\..\..\XMLTooling\security\impl\PKIXPathValidator.cpp">
       <Filter>Source Files\security\impl</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\..\XMLTooling\util\CloneInputStream.cpp">
+      <Filter>Source Files\util</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\..\XMLTooling\AbstractAttributeExtensibleXMLObject.h">
@@ -515,6 +518,9 @@
     <ClInclude Include="..\..\..\XMLTooling\security\PKIXPathValidatorParams.h">
       <Filter>Header Files\security</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\..\XMLTooling\util\CloneInputStream.h">
+      <Filter>Header Files\util</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="..\..\..\XMLTooling\xmltooling.rc">
@@ -525,4 +531,4 @@
     <None Include="..\..\..\XMLTooling\config_pub.h.in" />
     <None Include="..\..\..\XMLTooling\Makefile.am" />
   </ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/xmltooling/util/CloneInputStream.cpp b/xmltooling/util/CloneInputStream.cpp
new file mode 100644
index 0000000..1b0e647
--- /dev/null
+++ b/xmltooling/util/CloneInputStream.cpp
@@ -0,0 +1,58 @@
+/**
+ * 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
+ *
+ * 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.
+ */
+
+/**
+ * xmltooling/util/CloneInputStream.cpp
+ *
+ * InputStream that wraps an InputStream and forks data into a backup file.
+ */
+
+#include "internal.h"
+
+#include <xmltooling/util/CloneInputStream.h>
+#include <xmltooling/util/ParserPool.h>
+#include <xmltooling/util/XMLHelper.h>
+
+using namespace xmltooling;
+using namespace xercesc;
+using namespace std;
+
+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)
+{
+    m_log.debug("initialized");
+}
+
+CloneInputStream::~CloneInputStream()
+{
+    m_log.debug("deleted");
+    m_backingStream.close();
+}
+
+XMLSize_t CloneInputStream::readBytes(XMLByte* const toFill, const XMLSize_t maxToRead)
+{
+    auto bytesRead = m_input->readBytes(toFill, maxToRead);
+
+    if (bytesRead) m_backingStream.write((char*)toFill, bytesRead);
+
+    return bytesRead;
+}
\ No newline at end of file
diff --git a/xmltooling/util/CloneInputStream.h b/xmltooling/util/CloneInputStream.h
new file mode 100644
index 0000000..1a31de5
--- /dev/null
+++ b/xmltooling/util/CloneInputStream.h
@@ -0,0 +1,65 @@
+/**
+ * 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
+ *
+ * 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/CloneInputStream.h
+ *
+ * InputStream that wraps an InputStream and forks data into a backup file.
+ */
+
+#if !defined(__xmltooling_cloneinstr_h__)
+#define __xmltooling_cloneinstr_h__
+
+#include <xercesc/util/BinInputStream.hpp>
+#include <xmltooling/logging.h>
+
+#include <string>
+#include <fstream>
+
+namespace xmltooling {
+
+    class XMLTOOL_API CloneInputStream : public xercesc::BinInputStream
+    {
+    public :
+        /**
+         * Constructor.
+         *
+         * @param TBD
+         * @param TBD
+         */
+        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 const XMLCh* getContentType() const {return m_input->getContentType();};
+
+
+    private :
+        std::ofstream            m_backingStream;
+        logging::Category&       m_log;
+	    xercesc::BinInputStream* m_input;
+    };
+};
+
+#endif // __xmltooling_curlinstr_h__
diff --git a/xmltoolingtest/CloneInputStreamTest.h b/xmltoolingtest/CloneInputStreamTest.h
new file mode 100644
index 0000000..b19df62
--- /dev/null
+++ b/xmltoolingtest/CloneInputStreamTest.h
@@ -0,0 +1,72 @@
+/**
+ * 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
+ *
+ * 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.
+ */
+
+#include "XMLObjectBaseTestCase.h"
+#include <xercesc/framework/LocalFileInputSource.hpp>
+#include <xmltooling/util/CloneInputStream.h>
+#include <xmltooling/util/CurlURLInputStream.h>
+
+extern std::string data_path;
+
+class CloneInputStreamTest : public CxxTest::TestSuite {
+public:
+    void setUp() {
+    }
+
+    void tearDown() {
+    }
+
+    void testClone() {
+        {
+            auto_ptr_XMLCh widenitSrc((data_path + "SimpleXMLObjectWithChildren.xml").c_str());
+            xercesc::LocalFileInputSource src(widenitSrc.get());
+            BinInputStream* srcStream = src.makeStream();
+
+            CloneInputStream clone(srcStream, data_path + "clonedfile.xml");
+            XMLByte buffer[1024];
+            XMLSize_t sz;
+
+            do {
+                sz = clone.readBytes(buffer, 1024);
+            } while (sz > 0);
+        }
+        auto_ptr_XMLCh widenitSrc((data_path + "SimpleXMLObjectWithChildren.xml").c_str());
+        LocalFileInputSource src(widenitSrc.get());
+        BinInputStream* srcStream = src.makeStream(); 
+
+        auto_ptr_XMLCh widenitDst((data_path + "clonedfile.xml").c_str());
+        LocalFileInputSource dst(widenitDst.get());
+        BinInputStream* dstStream = dst.makeStream(); 
+        XMLSize_t sz1;
+        while (true) {
+            XMLByte buffer1[1024], buffer2[1024];
+            XMLSize_t sz2;
+            sz1 = srcStream->readBytes(buffer1, 1024);
+            sz2 = dstStream->readBytes(buffer2, 1024);
+            TSM_ASSERT("Size difference", sz1 == sz2);
+            if (sz1 <= 0) break;
+            size_t cmp = memcmp(buffer1, buffer2, sz1);
+            TSM_ASSERT("Buffer difference", 0 == cmp);
+        }
+        delete srcStream;
+        delete dstStream;
+    }
+
+};

-- 
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