[Libreoffice-commits] core.git: connectivity/Library_mozbootstrap.mk connectivity/Module_connectivity.mk connectivity/source include/sal postprocess/Rdb_services.mk Repository.mk solenv/clang-format

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Fri Feb 5 09:12:16 UTC 2021


 Repository.mk                                                      |    1 
 connectivity/Library_mozbootstrap.mk                               |   35 +
 connectivity/Module_connectivity.mk                                |    8 
 connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.cxx  |  139 ++++++
 connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.hxx  |   81 +++
 connectivity/source/drivers/mozab/bootstrap/MNSFolders.cxx         |  159 +++++++
 connectivity/source/drivers/mozab/bootstrap/MNSFolders.hxx         |   31 +
 connectivity/source/drivers/mozab/bootstrap/MNSINIParser.cxx       |   93 ++++
 connectivity/source/drivers/mozab/bootstrap/MNSINIParser.hxx       |   57 ++
 connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.cxx |  209 ++++++++++
 connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.hxx |   80 +++
 connectivity/source/drivers/mozab/bootstrap/README                 |    3 
 connectivity/source/drivers/mozab/bootstrap/mozbootstrap.component |   26 +
 include/sal/log-areas.dox                                          |    1 
 postprocess/Rdb_services.mk                                        |    6 
 solenv/clang-format/excludelist                                    |    7 
 16 files changed, 936 insertions(+)

New commits:
commit 47448aaff96536fa76588ee6de4164109df5d420
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Thu Feb 4 12:41:54 2021 +0000
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Fri Feb 5 10:11:28 2021 +0100

    restore com.sun.star.mozilla.MozillaBootstrap
    
    its used to find mozilla profile dirs for cert-related reasons
    
    removed overzealously with...
    
    commit ee9ed2192b56c98e5b8ee9890ddb4c533117332a
    Date:   Thu Dec 10 18:39:26 2020 +0100
    
        tdf#138715 remove mork driver
    
    Change-Id: I52f1ace5d4aac100c7652dc499ffe9c8312c9474
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110413
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/Repository.mk b/Repository.mk
index d75ec8796695..b207902fe1a5 100644
--- a/Repository.mk
+++ b/Repository.mk
@@ -383,6 +383,7 @@ $(eval $(call gb_Helper_register_libraries_for_install,OOOLIBS,ooo, \
 	$(if $(MERGELIBS),merged) \
 	migrationoo2 \
 	migrationoo3 \
+	mozbootstrap \
 	msfilter \
 	$(call gb_Helper_optional,SCRIPTING,msforms) \
 	mtfrenderer \
diff --git a/connectivity/Library_mozbootstrap.mk b/connectivity/Library_mozbootstrap.mk
new file mode 100644
index 000000000000..237726caf8a8
--- /dev/null
+++ b/connectivity/Library_mozbootstrap.mk
@@ -0,0 +1,35 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# 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/.
+#
+
+$(eval $(call gb_Library_Library,mozbootstrap))
+
+$(eval $(call gb_Library_set_componentfile,mozbootstrap,connectivity/source/drivers/mozab/bootstrap/mozbootstrap))
+
+$(eval $(call gb_Library_set_include,mozbootstrap,\
+	-I$(SRCDIR)/connectivity/source/drivers/mozab \
+	$$(INCLUDE) \
+))
+
+$(eval $(call gb_Library_use_sdk_api,mozbootstrap))
+
+$(eval $(call gb_Library_use_libraries,mozbootstrap,\
+	comphelper \
+	cppu \
+	cppuhelper \
+	sal \
+))
+
+$(eval $(call gb_Library_add_exception_objects,mozbootstrap,\
+	connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap \
+	connectivity/source/drivers/mozab/bootstrap/MNSFolders \
+	connectivity/source/drivers/mozab/bootstrap/MNSINIParser \
+	connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/connectivity/Module_connectivity.mk b/connectivity/Module_connectivity.mk
index faac5a8827a1..a02ec9b7332f 100644
--- a/connectivity/Module_connectivity.mk
+++ b/connectivity/Module_connectivity.mk
@@ -99,6 +99,14 @@ $(eval $(call gb_Module_add_targets,connectivity,\
 ))
 endif
 
+ifneq (,$(filter DESKTOP,$(BUILD_TYPE)))
+
+$(eval $(call gb_Module_add_targets,connectivity,\
+	Library_mozbootstrap \
+))
+
+endif
+
 ifeq ($(OS),WNT)
 # "ADO is not available on 64bit" said the commit
 ifneq ($(CPUNAME),X86_64)
diff --git a/connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.cxx b/connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.cxx
new file mode 100644
index 000000000000..71cb17b0f4ec
--- /dev/null
+++ b/connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.cxx
@@ -0,0 +1,139 @@
+/* -*- 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/XMultiServiceFactory.hpp>
+#include <cppuhelper/factory.hxx>
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#include <cppuhelper/supportsservice.hxx>
+#include <cppuhelper/weak.hxx>
+#include "MMozillaBootstrap.hxx"
+#include "MNSProfileDiscover.hxx"
+
+using namespace com::sun::star::uno;
+using namespace com::sun::star::lang;
+using namespace com::sun::star::mozilla;
+using namespace connectivity::mozab;
+
+using ::com::sun::star::uno::Reference;
+using ::com::sun::star::uno::Sequence;
+using ::com::sun::star::lang::XSingleServiceFactory;
+using ::com::sun::star::lang::XMultiServiceFactory;
+
+MozillaBootstrap::MozillaBootstrap()
+    : OMozillaBootstrap_BASE(m_aMutex)
+{
+    m_ProfileAccess.reset(new ProfileAccess);
+    bootupProfile(css::mozilla::MozillaProductType_Mozilla,OUString());
+}
+
+MozillaBootstrap::~MozillaBootstrap()
+{
+}
+
+void MozillaBootstrap::disposing()
+{
+    ::osl::MutexGuard aGuard(m_aMutex);
+    OMozillaBootstrap_BASE::disposing();
+}
+
+OUString SAL_CALL MozillaBootstrap::getImplementationName(  )
+{
+    return "com.sun.star.comp.mozilla.MozillaBootstrap";
+}
+
+sal_Bool SAL_CALL MozillaBootstrap::supportsService( const OUString& _rServiceName )
+{
+    return cppu::supportsService(this, _rServiceName);
+}
+
+Sequence< OUString > SAL_CALL MozillaBootstrap::getSupportedServiceNames(  )
+{
+    // which service is supported
+    // for more information @see com.sun.star.mozilla.MozillaBootstrap
+    return { "com.sun.star.mozilla.MozillaBootstrap" };
+}
+
+
+// XProfileDiscover
+::sal_Int32 SAL_CALL MozillaBootstrap::getProfileCount( css::mozilla::MozillaProductType product)
+{
+    return m_ProfileAccess->getProfileCount(product);
+}
+::sal_Int32 SAL_CALL MozillaBootstrap::getProfileList( css::mozilla::MozillaProductType product, css::uno::Sequence< OUString >& list )
+{
+    return m_ProfileAccess->getProfileList(product,list);
+}
+OUString SAL_CALL MozillaBootstrap::getDefaultProfile( css::mozilla::MozillaProductType product )
+{
+    return m_ProfileAccess->getDefaultProfile(product);
+}
+OUString SAL_CALL MozillaBootstrap::getProfilePath( css::mozilla::MozillaProductType product, const OUString& profileName )
+{
+    return m_ProfileAccess->getProfilePath(product,profileName);
+}
+sal_Bool SAL_CALL MozillaBootstrap::isProfileLocked( css::mozilla::MozillaProductType /*product*/, const OUString& /*profileName*/ )
+{
+    return true;
+}
+sal_Bool SAL_CALL MozillaBootstrap::getProfileExists( css::mozilla::MozillaProductType product, const OUString& profileName )
+{
+    return m_ProfileAccess->getProfileExists(product,profileName);
+}
+
+// XProfileManager
+::sal_Int32 SAL_CALL MozillaBootstrap::bootupProfile( css::mozilla::MozillaProductType, const OUString& )
+{
+        return -1;
+}
+::sal_Int32 SAL_CALL MozillaBootstrap::shutdownProfile(  )
+{
+    return -1;
+}
+css::mozilla::MozillaProductType SAL_CALL MozillaBootstrap::getCurrentProduct(  )
+{
+    return css::mozilla::MozillaProductType_Default;
+}
+OUString SAL_CALL MozillaBootstrap::getCurrentProfile(  )
+{
+    return OUString();
+}
+sal_Bool SAL_CALL MozillaBootstrap::isCurrentProfileLocked(  )
+{
+    return true;
+}
+OUString SAL_CALL MozillaBootstrap::setCurrentProfile( css::mozilla::MozillaProductType, const OUString& )
+{
+    return OUString();
+}
+
+// XProxyRunner
+::sal_Int32 SAL_CALL MozillaBootstrap::Run( const css::uno::Reference< css::mozilla::XCodeProxy >& )
+{
+    return -1;
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+connectivity_moz_MozillaBootstrap_get_implementation(
+    css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
+{
+    return cppu::acquire(
+        static_cast<cppu::OWeakObject*>(new connectivity::mozab::MozillaBootstrap()));
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.hxx b/connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.hxx
new file mode 100644
index 000000000000..e3d3fa7e4aac
--- /dev/null
+++ b/connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.hxx
@@ -0,0 +1,81 @@
+/* -*- 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_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_BOOTSTRAP_MMOZILLABOOTSTRAP_HXX
+#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_BOOTSTRAP_MMOZILLABOOTSTRAP_HXX
+
+#include <sal/config.h>
+
+#include <memory>
+
+#include <com/sun/star/mozilla/XMozillaBootstrap.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <cppuhelper/compbase.hxx>
+
+
+namespace connectivity::mozab
+{
+        typedef ::cppu::WeakComponentImplHelper<   css::mozilla::XMozillaBootstrap,
+                                                   css::lang::XServiceInfo > OMozillaBootstrap_BASE;
+        class ProfileAccess;
+        class ProfileManager;
+        class MozillaBootstrap : public OMozillaBootstrap_BASE
+        {
+        private:
+            ::osl::Mutex                m_aMutex;       // mutex is need to control member access
+            virtual ~MozillaBootstrap() override;
+            std::unique_ptr<ProfileAccess> m_ProfileAccess;
+        public:
+
+            MozillaBootstrap();
+
+            // OComponentHelper
+            virtual void SAL_CALL disposing() 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;
+
+            // XMozillaBootstrap
+
+            // XProfileDiscover
+            virtual ::sal_Int32 SAL_CALL getProfileCount( css::mozilla::MozillaProductType product) override;
+            virtual ::sal_Int32 SAL_CALL getProfileList( css::mozilla::MozillaProductType product, css::uno::Sequence< OUString >& list ) override;
+            virtual OUString SAL_CALL getDefaultProfile( css::mozilla::MozillaProductType product ) override;
+            virtual OUString SAL_CALL getProfilePath( css::mozilla::MozillaProductType product, const OUString& profileName ) override;
+            virtual sal_Bool SAL_CALL isProfileLocked( css::mozilla::MozillaProductType product, const OUString& profileName ) override;
+            virtual sal_Bool SAL_CALL getProfileExists( css::mozilla::MozillaProductType product, const OUString& profileName ) override;
+
+            // XProfileManager
+            virtual ::sal_Int32 SAL_CALL bootupProfile( css::mozilla::MozillaProductType product, const OUString& profileName ) override;
+            virtual ::sal_Int32 SAL_CALL shutdownProfile(  ) override;
+            virtual css::mozilla::MozillaProductType SAL_CALL getCurrentProduct(  ) override;
+            virtual OUString SAL_CALL getCurrentProfile(  ) override;
+            virtual sal_Bool SAL_CALL isCurrentProfileLocked(  ) override;
+            virtual OUString SAL_CALL setCurrentProfile( css::mozilla::MozillaProductType product, const OUString& profileName ) override;
+
+            // XProxyRunner
+            virtual ::sal_Int32 SAL_CALL Run( const css::uno::Reference< css::mozilla::XCodeProxy >& aCode ) override;
+        };
+
+}
+
+#endif // CONNECTIVITY_SMozillaBootstrap_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/drivers/mozab/bootstrap/MNSFolders.cxx b/connectivity/source/drivers/mozab/bootstrap/MNSFolders.cxx
new file mode 100644
index 000000000000..71c70c641b30
--- /dev/null
+++ b/connectivity/source/drivers/mozab/bootstrap/MNSFolders.cxx
@@ -0,0 +1,159 @@
+/* -*- 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 "MNSFolders.hxx"
+
+#ifdef UNIX
+#include <string.h>
+#endif // End UNIX
+
+#ifdef _WIN32
+#if !defined WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+#endif
+#include <windows.h>
+#include <stdlib.h>
+#include <shlobj.h>
+#include <objidl.h>
+#endif // End _WIN32
+#include <osl/security.hxx>
+#include <osl/file.hxx>
+#include <osl/thread.h>
+
+using namespace ::com::sun::star::mozilla;
+
+namespace
+{
+
+    OUString lcl_getUserDataDirectory()
+    {
+        ::osl::Security   aSecurity;
+        OUString   aConfigPath;
+
+    #if defined(_WIN32) || defined(MACOSX)
+        aSecurity.getConfigDir( aConfigPath );
+    #else
+        //This is to find the dir under which .mozilla/.thunderbird is created.
+        //mozilla doesn't honour XDG_CONFIG_HOME, so raw home dir required here
+        //not xdg-config dir
+        aSecurity.getHomeDir( aConfigPath );
+    #endif
+
+        return aConfigPath + "/";
+    }
+
+
+    const size_t NB_PRODUCTS = 3;
+    const size_t NB_CANDIDATES = 4;
+
+    // The order (index) of entries in DefaultProductDir and
+    // ProductRootEnvironmentVariable *must* match the constants
+    // (minus 1) in offapi/com/sun/star/mozilla/MozillaProductType.idl
+    // DO NOT CHANGE THE ORDER; ADD ONLY TO THE END
+    const char* DefaultProductDir[NB_PRODUCTS][NB_CANDIDATES] =
+    {
+    #if defined(_WIN32)
+        { "Mozilla/SeaMonkey/", nullptr, nullptr, nullptr },
+        { "Mozilla/Firefox/", nullptr, nullptr, nullptr },
+        { "Thunderbird/", "Mozilla/Thunderbird/", nullptr, nullptr }
+    #elif defined(MACOSX)
+        { "../Mozilla/SeaMonkey/", nullptr, nullptr, nullptr },
+        { "Firefox/", nullptr, nullptr, nullptr },
+        { "../Thunderbird/", nullptr, nullptr, nullptr }
+    #else
+        { ".mozilla/seamonkey/", nullptr, nullptr, nullptr },
+        { ".mozilla/firefox/", nullptr, nullptr, nullptr },
+        { ".thunderbird/", ".mozilla-thunderbird/", ".mozilla/thunderbird/", ".icedove/" }
+    #endif
+    };
+
+    const char* ProductRootEnvironmentVariable[NB_PRODUCTS] =
+    {
+        "MOZILLA_PROFILE_ROOT",
+        "MOZILLA_FIREFOX_PROFILE_ROOT",
+        "MOZILLA_THUNDERBIRD_PROFILE_ROOT",
+    };
+
+
+    OUString const & lcl_guessProfileRoot( MozillaProductType _product )
+    {
+        size_t productIndex = static_cast<int>(_product) - 1;
+
+        static OUString s_productDirectories[NB_PRODUCTS];
+
+        if ( s_productDirectories[ productIndex ].isEmpty() )
+        {
+            OUString sProductPath;
+
+            // check whether we have an environment variable which help us
+            const char* pProfileByEnv = getenv( ProductRootEnvironmentVariable[ productIndex ] );
+            if ( pProfileByEnv )
+            {
+                sProductPath = OUString( pProfileByEnv, rtl_str_getLength( pProfileByEnv ), osl_getThreadTextEncoding() );
+                // assume that this is fine, no further checks
+            }
+            else
+            {
+                OUString sProductDirCandidate;
+                const char pProfileRegistry[] = "profiles.ini";
+
+                // check all possible candidates
+                for ( size_t i=0; i<NB_CANDIDATES; ++i )
+                {
+                    if ( nullptr == DefaultProductDir[ productIndex ][ i ] )
+                        break;
+
+                    sProductDirCandidate = lcl_getUserDataDirectory() +
+                        OUString::createFromAscii( DefaultProductDir[ productIndex ][ i ] );
+
+                    // check existence
+                    ::osl::DirectoryItem aRegistryItem;
+                    ::osl::FileBase::RC result = ::osl::DirectoryItem::get( sProductDirCandidate + pProfileRegistry, aRegistryItem );
+                    if ( result == ::osl::FileBase::E_None  )
+                    {
+                        ::osl::FileStatus aStatus( osl_FileStatus_Mask_Validate );
+                        result = aRegistryItem.getFileStatus( aStatus );
+                        if ( result == ::osl::FileBase::E_None  )
+                        {
+                            // the registry file exists
+                            break;
+                        }
+                    }
+                }
+
+                ::osl::FileBase::getSystemPathFromFileURL( sProductDirCandidate, sProductPath );
+            }
+
+            s_productDirectories[ productIndex ] = sProductPath;
+        }
+
+        return s_productDirectories[ productIndex ];
+    }
+}
+
+
+OUString getRegistryDir(MozillaProductType product)
+{
+    if (product == MozillaProductType_Default)
+        return OUString();
+
+    return lcl_guessProfileRoot( product );
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/drivers/mozab/bootstrap/MNSFolders.hxx b/connectivity/source/drivers/mozab/bootstrap/MNSFolders.hxx
new file mode 100644
index 000000000000..50c992f230af
--- /dev/null
+++ b/connectivity/source/drivers/mozab/bootstrap/MNSFolders.hxx
@@ -0,0 +1,31 @@
+/* -*- 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_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_BOOTSTRAP_MNSFOLDERS_HXX
+#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_BOOTSTRAP_MNSFOLDERS_HXX
+
+#include <com/sun/star/mozilla/MozillaProductType.hpp>
+
+#include <rtl/ustring.hxx>
+
+OUString getRegistryDir(css::mozilla::MozillaProductType product);
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/drivers/mozab/bootstrap/MNSINIParser.cxx b/connectivity/source/drivers/mozab/bootstrap/MNSINIParser.cxx
new file mode 100644
index 000000000000..ae775b6fca01
--- /dev/null
+++ b/connectivity/source/drivers/mozab/bootstrap/MNSINIParser.cxx
@@ -0,0 +1,93 @@
+/* -*- 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 "MNSINIParser.hxx"
+#include <com/sun/star/io/IOException.hpp>
+#include <osl/file.h>
+#include <rtl/byteseq.hxx>
+#include <sal/log.hxx>
+
+IniParser::IniParser(OUString const & rIniName)
+{
+    OUString iniUrl;
+    if (osl_File_E_None != osl_getFileURLFromSystemPath(rIniName.pData, &iniUrl.pData))
+        return;
+
+
+    oslFileHandle handle=nullptr;
+    oslFileError fileError = osl_File_E_INVAL;
+    try{
+        if (!iniUrl.isEmpty())
+            fileError = osl_openFile(iniUrl.pData, &handle, osl_File_OpenFlag_Read);
+    }
+    catch(const css::io::IOException&)
+    {
+        SAL_WARN("connectivity.mozab", "couldn't open file: " << iniUrl );
+    }
+
+    if (osl_File_E_None == fileError)
+    {
+        rtl::ByteSequence seq;
+        sal_uInt64 nSize = 0;
+
+        osl_getFileSize(handle, &nSize);
+        OUString sectionName(  "no name section" );
+        while (true)
+        {
+            sal_uInt64 nPos;
+            if (osl_File_E_None != osl_getFilePos(handle, &nPos) || nPos >= nSize)
+                break;
+            if (osl_File_E_None != osl_readLine(handle, reinterpret_cast<sal_Sequence **>(&seq)))
+                break;
+            OString line(reinterpret_cast<const char *>(seq.getConstArray()), seq.getLength() );
+            sal_Int32 nIndex = line.indexOf('=');
+            if (nIndex >= 1)
+            {
+                ini_Section *aSection = &mAllSection[sectionName];
+                struct ini_NameValue nameValue;
+                nameValue.sName = OStringToOUString(
+                    line.copy(0,nIndex).trim(), RTL_TEXTENCODING_ASCII_US );
+                nameValue.sValue = OStringToOUString(
+                    line.copy(nIndex+1).trim(), RTL_TEXTENCODING_UTF8 );
+
+                aSection->vVector.push_back(nameValue);
+
+            }
+            else
+            {
+                sal_Int32 nIndexStart = line.indexOf('[');
+                sal_Int32 nIndexEnd = line.indexOf(']');
+                if ( nIndexEnd > nIndexStart && nIndexStart >=0)
+                {
+                    sectionName =  OStringToOUString(
+                        line.copy(nIndexStart + 1,nIndexEnd - nIndexStart -1).trim(), RTL_TEXTENCODING_ASCII_US );
+                    if (sectionName.isEmpty())
+                        sectionName = "no name section";
+                }
+            }
+        }
+        osl_closeFile(handle);
+    }
+    else
+    {
+        SAL_INFO("connectivity.mozab", "couldn't open file: " << iniUrl );
+    }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/drivers/mozab/bootstrap/MNSINIParser.hxx b/connectivity/source/drivers/mozab/bootstrap/MNSINIParser.hxx
new file mode 100644
index 000000000000..210553b73bcc
--- /dev/null
+++ b/connectivity/source/drivers/mozab/bootstrap/MNSINIParser.hxx
@@ -0,0 +1,57 @@
+/* -*- 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_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_BOOTSTRAP_MNSINIPARSER_HXX
+#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_BOOTSTRAP_MNSINIPARSER_HXX
+
+#include <rtl/ustring.hxx>
+
+#include <map>
+#include <vector>
+
+struct ini_NameValue
+{
+    OUString sName;
+    OUString sValue;
+};
+
+typedef std::vector<
+    ini_NameValue
+> NameValueVector;
+
+struct ini_Section
+{
+    NameValueVector vVector;
+};
+typedef std::map<OUString,
+                ini_Section
+                >IniSectionMap;
+
+
+class IniParser
+{
+    IniSectionMap mAllSection;
+public:
+    IniSectionMap& getAllSection() { return mAllSection; }
+    /// @throws css::io::IOException
+    explicit IniParser(OUString const & rIniName);
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.cxx b/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.cxx
new file mode 100644
index 000000000000..4dd9110a6f0f
--- /dev/null
+++ b/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.cxx
@@ -0,0 +1,209 @@
+/* -*- 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 "MNSProfileDiscover.hxx"
+#include "MNSFolders.hxx"
+#include "MNSINIParser.hxx"
+
+namespace connectivity::mozab
+{
+        ProfileStruct::ProfileStruct()
+        {
+        }
+
+        ProfileStruct::ProfileStruct(const OUString& aProfileName,
+                                     const OUString& aProfilePath)
+            : profileName(aProfileName)
+            , profilePath(aProfilePath)
+        {
+        }
+
+        const OUString& ProfileStruct::getProfilePath() const
+        {
+            return profilePath;
+        }
+
+        ProfileAccess::~ProfileAccess()
+        {
+        }
+
+        ProfileAccess::ProfileAccess()
+        {
+            LoadProductsInfo();
+        }
+
+        void ProfileAccess::LoadProductsInfo()
+        {
+            //tdf#39279: LO should search Thunderbird first then Seamonkey and finally Firefox
+            //load thunderbird profiles to m_ProductProfileList
+            LoadXPToolkitProfiles(MozillaProductType_Thunderbird);
+
+            //load SeaMonkey 2 profiles to m_ProductProfileList
+            LoadXPToolkitProfiles(MozillaProductType_Mozilla);
+
+            //load firefox profiles to m_ProductProfileList
+            //firefox profile does not contain address book, but maybe others need them
+            LoadXPToolkitProfiles(MozillaProductType_Firefox);
+        }
+        //Thunderbird and firefox profiles are saved in profiles.ini
+        void ProfileAccess::LoadXPToolkitProfiles(MozillaProductType product)
+        {
+            sal_Int32 index=static_cast<sal_Int32>(product);
+            ProductStruct &rProduct = m_ProductProfileList[index];
+
+            OUString regDir = getRegistryDir(product);
+            OUString profilesIni = regDir + "profiles.ini";
+            IniParser parser( profilesIni );
+            IniSectionMap &rAllSection = parser.getAllSection();
+
+            for(auto& rSection : rAllSection)
+            {
+                ini_Section *aSection = &rSection.second;
+                OUString profileName;
+                OUString profilePath;
+                OUString sIsRelative;
+                OUString sIsDefault;
+
+                for(auto& rValue : aSection->vVector)
+                {
+                    struct ini_NameValue * aValue = &rValue;
+                    if ( aValue->sName == "Name" )
+                    {
+                        profileName = aValue->sValue;
+                    }
+                    else if ( aValue->sName == "IsRelative" )
+                    {
+                        sIsRelative = aValue->sValue;
+                    }
+                    else if ( aValue->sName == "Path" )
+                    {
+                        profilePath = aValue->sValue;
+                    }
+                    else if ( aValue->sName == "Default" )
+                    {
+                        sIsDefault = aValue->sValue;
+                    }
+                }
+                if (!(profileName.isEmpty() && profilePath.isEmpty()))
+                {
+                    sal_Int32 isRelative = 0;
+                    if (!sIsRelative.isEmpty())
+                    {
+                        isRelative = sIsRelative.toInt32();
+                    }
+
+                    OUString fullProfilePath;
+                    if(isRelative)
+                    {
+                        fullProfilePath = regDir + profilePath;
+                    }
+                    else
+                    {
+                        fullProfilePath = profilePath;
+                    }
+
+                    rProduct.mProfileList[profileName] = ProfileStruct(profileName,fullProfilePath);
+
+                    sal_Int32 isDefault = 0;
+                    if (!sIsDefault.isEmpty())
+                    {
+                        isDefault = sIsDefault.toInt32();
+                    }
+                    if (isDefault)
+                        rProduct.mCurrentProfileName = profileName;
+
+                }
+
+                // Depending on TB versions, some generate "default" profile
+                // others "default-release" profile
+                // See https://support.mozilla.org/gl/questions/1264072
+                // for some background info (the link quotes Firefox but it seems
+                // the same for TB).
+                if (profileName == "default-release")
+                {
+                    rProduct.mCurrentProfileName = profileName;
+                    break;
+                }
+            }
+        }
+
+        OUString ProfileAccess::getProfilePath( css::mozilla::MozillaProductType product, const OUString& profileName )
+        {
+            sal_Int32 index=static_cast<sal_Int32>(product);
+            ProductStruct &rProduct = m_ProductProfileList[index];
+            if (rProduct.mProfileList.empty() || rProduct.mProfileList.find(profileName) == rProduct.mProfileList.end())
+            {
+                //Profile not found
+                return OUString();
+            }
+            else
+                return rProduct.mProfileList[profileName].getProfilePath();
+        }
+
+        ::sal_Int32 ProfileAccess::getProfileCount( css::mozilla::MozillaProductType product)
+        {
+            sal_Int32 index=static_cast<sal_Int32>(product);
+            ProductStruct &rProduct = m_ProductProfileList[index];
+            return static_cast< ::sal_Int32 >(rProduct.mProfileList.size());
+        }
+        ::sal_Int32 ProfileAccess::getProfileList( css::mozilla::MozillaProductType product, css::uno::Sequence< OUString >& list )
+        {
+            sal_Int32 index=static_cast<sal_Int32>(product);
+            ProductStruct &rProduct = m_ProductProfileList[index];
+            list.realloc(static_cast<sal_Int32>(rProduct.mProfileList.size()));
+            sal_Int32 i=0;
+            for(const auto& rEntry : rProduct.mProfileList)
+            {
+                const ProfileStruct& rProfile = rEntry.second;
+                list[i] = rProfile.getProfileName();
+                i++;
+            }
+
+            return static_cast< ::sal_Int32 >(rProduct.mProfileList.size());
+        }
+
+        OUString ProfileAccess::getDefaultProfile( css::mozilla::MozillaProductType product )
+        {
+            sal_Int32 index=static_cast<sal_Int32>(product);
+            ProductStruct &rProduct = m_ProductProfileList[index];
+            if (!rProduct.mCurrentProfileName.isEmpty())
+            {
+                //default profile set in mozilla registry
+                return rProduct.mCurrentProfileName;
+            }
+            if (rProduct.mProfileList.empty())
+            {
+                //there are not any profiles
+                return OUString();
+            }
+            const ProfileStruct& rProfile = (*rProduct.mProfileList.begin()).second;
+            return rProfile.getProfileName();
+        }
+
+        bool ProfileAccess::getProfileExists( css::mozilla::MozillaProductType product, const OUString& profileName )
+        {
+            sal_Int32 index=static_cast<sal_Int32>(product);
+            ProductStruct &rProduct = m_ProductProfileList[index];
+            return rProduct.mProfileList.find(profileName) != rProduct.mProfileList.end();
+        }
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.hxx b/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.hxx
new file mode 100644
index 000000000000..a5f271183b27
--- /dev/null
+++ b/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.hxx
@@ -0,0 +1,80 @@
+/* -*- 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 .
+ */
+
+#pragma once
+
+#include <sal/types.h>
+#include <com/sun/star/mozilla/MozillaProductType.hpp>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <rtl/ustring.hxx>
+
+#include <vector>
+#include <map>
+
+using namespace com::sun::star::mozilla;
+namespace connectivity::mozab { class ProfileStruct; }
+
+typedef std::map<OUString, ::connectivity::mozab::ProfileStruct> ProfileList;
+namespace connectivity::mozab
+    {
+        class ProfileStruct
+        {
+        public:
+            ProfileStruct();
+            ProfileStruct(const OUString& aProfileName, const OUString &aProfilePath);
+            const OUString& getProfileName() const { return profileName;}
+            const OUString& getProfilePath() const;
+        private:
+            OUString profileName;
+            OUString profilePath;
+        };
+
+        class ProductStruct
+        {
+        public:
+            OUString mCurrentProfileName;
+            ProfileList mProfileList;
+        };
+
+        //Used to query profiles information
+        class ProfileAccess final
+        {
+        public:
+            ~ProfileAccess();
+            ProfileAccess();
+            /// @throws css::uno::RuntimeException
+            OUString getProfilePath( css::mozilla::MozillaProductType product, const OUString& profileName );
+            /// @throws css::uno::RuntimeException
+            ::sal_Int32 getProfileCount( css::mozilla::MozillaProductType product );
+            /// @throws css::uno::RuntimeException
+            ::sal_Int32 getProfileList( css::mozilla::MozillaProductType product, css::uno::Sequence< OUString >& list );
+            /// @throws css::uno::RuntimeException
+            OUString getDefaultProfile( css::mozilla::MozillaProductType product );
+            /// @throws css::uno::RuntimeException
+            bool getProfileExists( css::mozilla::MozillaProductType product, const OUString& profileName );
+        private:
+            ProductStruct m_ProductProfileList[4];
+            void      LoadProductsInfo();
+            void      LoadXPToolkitProfiles(MozillaProductType product);
+        };
+
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/drivers/mozab/bootstrap/README b/connectivity/source/drivers/mozab/bootstrap/README
new file mode 100644
index 000000000000..cea68d86cc56
--- /dev/null
+++ b/connectivity/source/drivers/mozab/bootstrap/README
@@ -0,0 +1,3 @@
+this provides com.sun.star.mozilla.MozillaBootstrap which is used by at least
+xmlsecurity/source/xmlsec/nss/nssinitializer.cxx to find a user's
+firefox/thunderbird profile to use its certs
diff --git a/connectivity/source/drivers/mozab/bootstrap/mozbootstrap.component b/connectivity/source/drivers/mozab/bootstrap/mozbootstrap.component
new file mode 100644
index 000000000000..bfc0afe389ef
--- /dev/null
+++ b/connectivity/source/drivers/mozab/bootstrap/mozbootstrap.component
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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 .
+ -->
+
+<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
+    xmlns="http://openoffice.org/2010/uno-components">
+  <implementation name="com.sun.star.comp.mozilla.MozillaBootstrap"
+    constructor="connectivity_moz_MozillaBootstrap_get_implementation" single-instance="true">
+    <service name="com.sun.star.mozilla.MozillaBootstrap"/>
+  </implementation>
+</component>
diff --git a/include/sal/log-areas.dox b/include/sal/log-areas.dox
index 647f5c1902ec..48b42ea4b958 100644
--- a/include/sal/log-areas.dox
+++ b/include/sal/log-areas.dox
@@ -82,6 +82,7 @@ certain functionality.
 @li @c connectivity.kab
 @li @c connectivity.macab
 @li @c connectivity.manager
+ at li @c connectivity.mozab
 @li @c connectivity.mysqlc
 @li @c connectivity.odbc
 @li @c connectivity.parse
diff --git a/postprocess/Rdb_services.mk b/postprocess/Rdb_services.mk
index 53a6f4cc4b2c..3876df9ec682 100644
--- a/postprocess/Rdb_services.mk
+++ b/postprocess/Rdb_services.mk
@@ -273,6 +273,12 @@ $(eval $(call gb_Rdb_add_components,services,\
 	) \
 ))
 
+ifneq (,$(filter DESKTOP,$(BUILD_TYPE)))
+$(eval $(call gb_Rdb_add_components,services,\
+	connectivity/source/drivers/mozab/bootstrap/mozbootstrap \
+))
+endif # DESKTOP
+
 endif # DBCONNECTIVITY
 
 ifeq (DESKTOP,$(filter DESKTOP,$(BUILD_TYPE)))
diff --git a/solenv/clang-format/excludelist b/solenv/clang-format/excludelist
index edd2eb530360..25d5fe43d99f 100644
--- a/solenv/clang-format/excludelist
+++ b/solenv/clang-format/excludelist
@@ -1966,6 +1966,13 @@ connectivity/source/drivers/macab/macabcondition.hxx
 connectivity/source/drivers/macab/macaborder.cxx
 connectivity/source/drivers/macab/macaborder.hxx
 connectivity/source/drivers/macab/macabutilities.hxx
+connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.cxx
+connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.hxx
+connectivity/source/drivers/mozab/bootstrap/MNSFolders.cxx
+connectivity/source/drivers/mozab/bootstrap/MNSINIParser.cxx
+connectivity/source/drivers/mozab/bootstrap/MNSINIParser.hxx
+connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.cxx
+connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.hxx
 connectivity/source/drivers/odbc/OConnection.cxx
 connectivity/source/drivers/odbc/ODatabaseMetaData.cxx
 connectivity/source/drivers/odbc/ODatabaseMetaDataResultSet.cxx


More information about the Libreoffice-commits mailing list