Remove singleton pattern on xmlSec 90/107290/1
authorsangwan.kwon <sangwan.kwon@samsung.com>
Tue, 27 Dec 2016 10:14:53 +0000 (19:14 +0900)
committersangwan.kwon <sangwan.kwon@samsung.com>
Tue, 27 Dec 2016 10:14:53 +0000 (19:14 +0900)
[AS-IS]
* For performance, singleton pattern is adopted on xmlSec.
* This makes issue which xmlSec's dtor is not called.

[TO-BE]
* Remove singletone pattern on xmlSec class.

Change-Id: Ibaaff16277ca7e97bd328e9899ee0dda596b5dea
Signed-off-by: sangwan.kwon <sangwan.kwon@samsung.com>
src/vcore/BaseValidator.cpp
src/vcore/BaseValidator.h
src/vcore/XmlsecAdapter.cpp
src/vcore/XmlsecAdapter.h

index e978fb7..717ad32 100644 (file)
@@ -317,7 +317,7 @@ VCerr BaseValidator::baseCheck(const std::string &contentPath,
                        m_context.allowBrokenChain = true;
 
                // XmlSec validate
-               XmlSecSingleton::Instance().validate(m_context);
+               m_xmlSec.validate(m_context);
                // Check reference of 'Object' tag - OID
                m_data.setReference(m_context.referenceSet);
 
@@ -387,9 +387,9 @@ VCerr BaseValidator::baseCheckList(bool checkOcsp, const UriList &uriList)
 
                // XmlSec validate
                if (uriList.size() == 0)
-                       XmlSecSingleton::Instance().validateNoHash(m_context);
+                       m_xmlSec.validateNoHash(m_context);
                else
-                       XmlSecSingleton::Instance().validatePartialHash(m_context, uriList);
+                       m_xmlSec.validatePartialHash(m_context, uriList);
 
                if (checkOcsp && Ocsp::check(m_data) == Ocsp::Result::REVOKED) {
                        LogError("Certificate is Revoked by OCSP server.");
index 2a084a7..57db716 100644 (file)
@@ -71,6 +71,7 @@ private:
        bool checkObjectReferences(void);
 
        PluginHandler m_pluginHandler;
+       XmlSec m_xmlSec;
 };
 
 } // namespace ValidationCore
index 7705613..ed86288 100644 (file)
 
 #include <dpl/assert.h>
 #include <dpl/log/log.h>
-#include <dpl/singleton_impl.h>
 
 #include <vcore/XmlsecAdapter.h>
 
 #define VCORE_ERRORS_BUFFER_SIZE 1024
 
-IMPLEMENT_SINGLETON(ValidationCore::XmlSec)
-
 namespace {
 
 struct FileWrapper {
@@ -168,9 +165,7 @@ void LogDebugPrint(const char *file,
                LogDebug(buff);
 }
 
-XmlSec::XmlSec()
-       : m_initialized(false)
-       , m_pList(nullptr)
+XmlSec::XmlSec() : m_pList(nullptr)
 {
        LIBXML_TEST_VERSION
        xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
@@ -213,15 +208,10 @@ XmlSec::XmlSec()
                ThrowMsg(Exception::InternalError,
                                 "Xmlsec-crypto initialization failed.");
        }
-
-       m_initialized = true;
 }
 
 XmlSec::~XmlSec()
 {
-       if (m_initialized)
-               return;
-
        xmlSecCryptoShutdown();
        xmlSecCryptoAppShutdown();
        xmlSecShutdown();
@@ -229,7 +219,6 @@ XmlSec::~XmlSec()
        xsltCleanupGlobals();
 #endif
        s_prefixPath.clear();
-       m_initialized = false;
 }
 
 void XmlSec::validateFile(XmlSecContext &context, xmlSecKeysMngrPtr mngrPtr)
@@ -405,9 +394,6 @@ void XmlSec::validateInternal(XmlSecContext &context)
        Assert(!!context.certificatePtr || !context.certificatePath.empty());
        xmlSecErrorsSetCallback(LogDebugPrint);
 
-       if (!m_initialized)
-               ThrowMsg(Exception::InternalError, "XmlSec is not initialized");
-
        std::unique_ptr<xmlSecKeysMngr, std::function<void(xmlSecKeysMngrPtr)>>
                mngrPtr(xmlSecKeysMngrCreate(), xmlSecKeysMngrDestroy);
 
index 269ebd9..f59cda2 100644 (file)
@@ -28,7 +28,6 @@
 #include <xmlsec/keysmngr.h>
 
 #include <dpl/exception.h>
-#include <dpl/singleton.h>
 
 #include <vcore/Certificate.h>
 #include <vcore/SignatureData.h>
@@ -127,7 +126,6 @@ private:
        };
 
        ValidateMode m_mode;
-       bool m_initialized;
        const std::list<std::string> *m_pList;
 
        void loadDERCertificateMemory(XmlSecContext &context, xmlSecKeysMngrPtr mngr);
@@ -143,6 +141,4 @@ private:
        static void fileExtractPrefix(XmlSecContext &context);
 };
 
-typedef VcoreDPL::Singleton<XmlSec> XmlSecSingleton;
-
 } // namespace ValidationCore