[Libreoffice-commits] core.git: xmlsecurity/Library_xmlsecurity.mk xmlsecurity/source xmlsecurity/util

Miklos Vajna vmiklos at collabora.co.uk
Wed Feb 7 08:24:58 UTC 2018


 xmlsecurity/Library_xmlsecurity.mk                    |    1 
 xmlsecurity/source/component/certificatecontainer.cxx |   70 +++++++++++++---
 xmlsecurity/source/component/certificatecontainer.hxx |   78 ------------------
 xmlsecurity/source/component/registerservices.cxx     |   61 --------------
 xmlsecurity/util/xmlsecurity.component                |    5 -
 5 files changed, 60 insertions(+), 155 deletions(-)

New commits:
commit 0833bab20bc3a6b7a9842307e4bd62f408ae37d3
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Feb 6 15:18:52 2018 +0100

    xmlsecurity: create CertificateContainer instances with a constructor
    
    Change-Id: I42f0218a46c67062ea6eb0845d978f2630793ec0
    Reviewed-on: https://gerrit.libreoffice.org/49304
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/xmlsecurity/Library_xmlsecurity.mk b/xmlsecurity/Library_xmlsecurity.mk
index 22d27c717155..1c30ab25817c 100644
--- a/xmlsecurity/Library_xmlsecurity.mk
+++ b/xmlsecurity/Library_xmlsecurity.mk
@@ -48,7 +48,6 @@ $(eval $(call gb_Library_use_libraries,xmlsecurity,\
 $(eval $(call gb_Library_add_exception_objects,xmlsecurity,\
 	xmlsecurity/source/component/certificatecontainer \
 	xmlsecurity/source/component/documentdigitalsignatures \
-	xmlsecurity/source/component/registerservices \
 	xmlsecurity/source/dialogs/certificatechooser \
 	xmlsecurity/source/dialogs/certificateviewer \
 	xmlsecurity/source/dialogs/digitalsignaturesdialog \
diff --git a/xmlsecurity/source/component/certificatecontainer.cxx b/xmlsecurity/source/component/certificatecontainer.cxx
index bdbaa68b0a94..1e6c4facc8b2 100644
--- a/xmlsecurity/source/component/certificatecontainer.cxx
+++ b/xmlsecurity/source/component/certificatecontainer.cxx
@@ -17,8 +17,15 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-#include "certificatecontainer.hxx"
+#include <map>
+
+#include <cppuhelper/implbase.hxx>
+#include <com/sun/star/security/XCertificateContainer.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
+
 #include <cppuhelper/supportsservice.hxx>
+#include <rtl/ref.hxx>
 
 #include <sal/config.h>
 
@@ -26,6 +33,34 @@ using namespace ::com::sun::star;
 using namespace ::com::sun::star::lang;
 using namespace ::com::sun::star::uno;
 
+class CertificateContainer
+    : public ::cppu::WeakImplHelper<css::lang::XServiceInfo, css::security::XCertificateContainer>
+{
+private:
+    typedef std::map<OUString, OUString> Map;
+    Map certMap;
+    Map certTrustMap;
+
+    static bool searchMap(const OUString& url, const OUString& certificate_name, Map& _certMap);
+    /// @throws css::uno::RuntimeException
+    bool isTemporaryCertificate(const OUString& url, const OUString& certificate_name);
+    /// @throws css::uno::RuntimeException
+    bool isCertificateTrust(const OUString& url, const OUString& certificate_name);
+
+public:
+    explicit CertificateContainer(const uno::Reference<uno::XComponentContext>&) {}
+    virtual sal_Bool SAL_CALL addCertificate(const OUString& url, const OUString& certificate_name,
+                                             sal_Bool trust) override;
+    virtual css::security::CertificateContainerStatus SAL_CALL
+    hasCertificate(const OUString& url, const OUString& certificate_name) override;
+
+    // XServiceInfo
+    virtual OUString SAL_CALL getImplementationName() override;
+    virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
+
+    virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
+};
+
 bool
 CertificateContainer::searchMap( const OUString & url, const OUString & certificate_name, Map &_certMap )
 {
@@ -86,7 +121,7 @@ CertificateContainer::hasCertificate( const OUString & url, const OUString & cer
 OUString SAL_CALL
 CertificateContainer::getImplementationName( )
 {
-    return impl_getStaticImplementationName();
+    return OUString("com.sun.star.security.CertificateContainer");
 }
 
 sal_Bool SAL_CALL
@@ -98,25 +133,34 @@ CertificateContainer::supportsService( const OUString& ServiceName )
 Sequence< OUString > SAL_CALL
 CertificateContainer::getSupportedServiceNames(  )
 {
-    return impl_getStaticSupportedServiceNames();
-}
-
-Sequence< OUString >
-CertificateContainer::impl_getStaticSupportedServiceNames(  )
-{
     Sequence< OUString > aRet { "com.sun.star.security.CertificateContainer" };
     return aRet;
 }
 
-OUString
-CertificateContainer::impl_getStaticImplementationName()
+namespace
 {
-    return OUString("com.sun.star.security.CertificateContainer");
+struct Instance
+{
+    explicit Instance(css::uno::Reference<css::uno::XComponentContext> const& context)
+        : instance(new CertificateContainer(context))
+    {
+    }
+
+    rtl::Reference<CertificateContainer> instance;
+};
+
+struct Singleton
+    : public rtl::StaticWithArg<Instance, css::uno::Reference<css::uno::XComponentContext>,
+                                Singleton>
+{
+};
 }
 
-Reference< XInterface > CertificateContainer::impl_createInstance( const Reference< XMultiServiceFactory >& xServiceManager )
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+com_sun_star_security_CertificateContainer_get_implementation(
+    css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
 {
-    return Reference< XInterface >( *new CertificateContainer( xServiceManager ) );
+    return cppu::acquire(Singleton::get(context).instance.get());
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmlsecurity/source/component/certificatecontainer.hxx b/xmlsecurity/source/component/certificatecontainer.hxx
deleted file mode 100644
index 58c3ef82d00a..000000000000
--- a/xmlsecurity/source/component/certificatecontainer.hxx
+++ /dev/null
@@ -1,78 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF 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 .
- */
-
-#ifndef INCLUDED_XMLSECURITY_SOURCE_COMPONENT_CERTIFICATECONTAINER_HXX
-#define INCLUDED_XMLSECURITY_SOURCE_COMPONENT_CERTIFICATECONTAINER_HXX
-
-#include <com/sun/star/lang/XServiceInfo.hpp>
-#include <com/sun/star/lang/XSingleServiceFactory.hpp>
-#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#include <cppuhelper/factory.hxx>
-#include <cppuhelper/implbase.hxx>
-
-#include <com/sun/star/security/XCertificateContainer.hpp>
-#include <com/sun/star/security/CertificateContainerStatus.hpp>
-
-#include <vector>
-#include <map>
-
-class CertificateContainer : public ::cppu::WeakImplHelper< css::lang::XServiceInfo, css::security::XCertificateContainer >
-{
-    private:
-        typedef std::map< OUString, OUString > Map;
-        Map certMap;
-        Map certTrustMap;
-
-        static bool searchMap( const OUString & url, const OUString & certificate_name, Map &_certMap  );
-        /// @throws css::uno::RuntimeException
-        bool isTemporaryCertificate( const OUString & url, const OUString & certificate_name );
-        /// @throws css::uno::RuntimeException
-        bool isCertificateTrust( const OUString & url, const OUString & certificate_name );
-
-    public:
-
-        explicit CertificateContainer(const css::uno::Reference< css::lang::XMultiServiceFactory >& ) {}
-
-        virtual sal_Bool SAL_CALL addCertificate( const OUString & url, const OUString & certificate_name, sal_Bool trust ) override;
-        virtual css::security::CertificateContainerStatus SAL_CALL hasCertificate( const OUString & url, const OUString & certificate_name ) override;
-
-        // provide factory
-        /// @throws css::uno::RuntimeException
-        static OUString impl_getStaticImplementationName( );
-
-        /// @throws css::uno::RuntimeException
-        static css::uno::Sequence< OUString >
-                    impl_getStaticSupportedServiceNames(  );
-
-        /// @throws css::uno::RuntimeException
-        static css::uno::Reference< css::uno::XInterface >
-                    impl_createInstance( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager );
-
-        // XServiceInfo
-        virtual OUString SAL_CALL getImplementationName(  ) override;
-        virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
-
-        virtual css::uno::Sequence< OUString > SAL_CALL
-                    getSupportedServiceNames(  ) override;
-
-};
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmlsecurity/source/component/registerservices.cxx b/xmlsecurity/source/component/registerservices.cxx
deleted file mode 100644
index 9c0c91d7d015..000000000000
--- a/xmlsecurity/source/component/registerservices.cxx
+++ /dev/null
@@ -1,61 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF 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 .
- */
-
-
-#include <com/sun/star/lang/XSingleServiceFactory.hpp>
-
-#include <cppuhelper/factory.hxx>
-
-#include "certificatecontainer.hxx"
-
-using namespace ::com::sun::star;
-using namespace ::com::sun::star::uno;
-
-extern "C"
-{
-SAL_DLLPUBLIC_EXPORT void* xmlsecurity_component_getFactory( const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ )
-{
-    void* pRet = nullptr;
-    uno::Reference< XInterface > xFactory;
-
-    //Decryptor
-    OUString implName = OUString::createFromAscii( pImplName );
-
-    if (pServiceManager && implName == CertificateContainer::impl_getStaticImplementationName())
-    {
-        // CertificateContainer
-        xFactory = cppu::createOneInstanceFactory(
-            static_cast< lang::XMultiServiceFactory * >( pServiceManager ),
-            OUString::createFromAscii( pImplName ),
-            CertificateContainer::impl_createInstance,
-            CertificateContainer::impl_getStaticSupportedServiceNames() );
-    }
-
-     if (xFactory.is())
-    {
-        xFactory->acquire();
-        pRet = xFactory.get();
-    }
-    return pRet;
-}
-
-}   // extern "C"
-
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmlsecurity/util/xmlsecurity.component b/xmlsecurity/util/xmlsecurity.component
index 383572bff403..adb647f20491 100644
--- a/xmlsecurity/util/xmlsecurity.component
+++ b/xmlsecurity/util/xmlsecurity.component
@@ -18,8 +18,9 @@
  -->
 
 <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
-    prefix="xmlsecurity" xmlns="http://openoffice.org/2010/uno-components">
-  <implementation name="com.sun.star.security.CertificateContainer">
+    xmlns="http://openoffice.org/2010/uno-components">
+  <implementation name="com.sun.star.security.CertificateContainer"
+      constructor="com_sun_star_security_CertificateContainer_get_implementation">
     <service name="com.sun.star.security.CertificateContainer"/>
   </implementation>
   <implementation name="com.sun.star.security.DocumentDigitalSignatures"


More information about the Libreoffice-commits mailing list