diff options
Diffstat (limited to 'extensions/source/mozbootstrap')
-rw-r--r-- | extensions/source/mozbootstrap/MMozillaBootstrap.cxx | 233 | ||||
-rw-r--r-- | extensions/source/mozbootstrap/MMozillaBootstrap.hxx | 97 | ||||
-rw-r--r-- | extensions/source/mozbootstrap/MNSFolders.cxx | 147 | ||||
-rw-r--r-- | extensions/source/mozbootstrap/MNSFolders.hxx | 39 | ||||
-rw-r--r-- | extensions/source/mozbootstrap/MNSINIParser.cxx | 133 | ||||
-rw-r--r-- | extensions/source/mozbootstrap/MNSINIParser.hxx | 79 | ||||
-rw-r--r-- | extensions/source/mozbootstrap/MNSProfileDiscover.cxx | 221 | ||||
-rw-r--r-- | extensions/source/mozbootstrap/MNSProfileDiscover.hxx | 98 | ||||
-rw-r--r-- | extensions/source/mozbootstrap/makefile.mk | 76 | ||||
-rw-r--r-- | extensions/source/mozbootstrap/mozbootstrap.component | 27 |
10 files changed, 1150 insertions, 0 deletions
diff --git a/extensions/source/mozbootstrap/MMozillaBootstrap.cxx b/extensions/source/mozbootstrap/MMozillaBootstrap.cxx new file mode 100644 index 000000000000..410c55df9a12 --- /dev/null +++ b/extensions/source/mozbootstrap/MMozillaBootstrap.cxx @@ -0,0 +1,233 @@ +/************************************************************** + * + * 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 + * + * 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. + * + *************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_extensions.hxx" + +#include "MMozillaBootstrap.hxx" + +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::mozilla; +using namespace connectivity::mozab; +#include <MNSFolders.hxx> +#include "MNSProfileDiscover.hxx" + +static MozillaBootstrap *pMozillaBootstrap=NULL; +static Reference<XMozillaBootstrap> xMozillaBootstrap; +extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL OMozillaBootstrap_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) +{ + if (!pMozillaBootstrap) + { + pMozillaBootstrap=new connectivity::mozab::MozillaBootstrap( _rxFactory ); + pMozillaBootstrap->Init(); + xMozillaBootstrap = pMozillaBootstrap; + } + return pMozillaBootstrap; +} + +// -------------------------------------------------------------------------------- + + +// -------------------------------------------------------------------------------- +MozillaBootstrap::MozillaBootstrap( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) + : OMozillaBootstrap_BASE(m_aMutex), m_xMSFactory( _rxFactory ) +{ +} +// ----------------------------------------------------------------------------- +MozillaBootstrap::~MozillaBootstrap() +{ +} +// ----------------------------------------------------------------------------- +void MozillaBootstrap::Init() +{ + sal_Bool aProfileExists=sal_False; + + (void)aProfileExists; /* avoid warning about unused parameter */ + + m_ProfileAccess = new ProfileAccess(); + bootupProfile(::com::sun::star::mozilla::MozillaProductType_Mozilla,rtl::OUString()); +} + +// -------------------------------------------------------------------------------- +void MozillaBootstrap::disposing() +{ + ::osl::MutexGuard aGuard(m_aMutex); + OMozillaBootstrap_BASE::disposing(); +} + +// static ServiceInfo +//------------------------------------------------------------------------------ +rtl::OUString MozillaBootstrap::getImplementationName_Static( ) throw(RuntimeException) +{ + return rtl::OUString::createFromAscii(MOZAB_MozillaBootstrap_IMPL_NAME); +} +//------------------------------------------------------------------------------ +Sequence< ::rtl::OUString > MozillaBootstrap::getSupportedServiceNames_Static( ) throw (RuntimeException) +{ + // which service is supported + // for more information @see com.sun.star.mozilla.MozillaBootstrap + Sequence< ::rtl::OUString > aSNS( 1 ); + aSNS[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.mozilla.MozillaBootstrap")); + return aSNS; +} + +//------------------------------------------------------------------ +::rtl::OUString SAL_CALL MozillaBootstrap::getImplementationName( ) throw(RuntimeException) +{ + return getImplementationName_Static(); +} + +//------------------------------------------------------------------ +sal_Bool SAL_CALL MozillaBootstrap::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException) +{ + Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); + const ::rtl::OUString* pSupported = aSupported.getConstArray(); + const ::rtl::OUString* pEnd = pSupported + aSupported.getLength(); + for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported) + ; + + return pSupported != pEnd; +} + +//------------------------------------------------------------------ +Sequence< ::rtl::OUString > SAL_CALL MozillaBootstrap::getSupportedServiceNames( ) throw(RuntimeException) +{ + return getSupportedServiceNames_Static(); +} + + +// XProfileDiscover +::sal_Int32 SAL_CALL MozillaBootstrap::getProfileCount( ::com::sun::star::mozilla::MozillaProductType product) throw (::com::sun::star::uno::RuntimeException) +{ + return m_ProfileAccess->getProfileCount(product); +} +::sal_Int32 SAL_CALL MozillaBootstrap::getProfileList( ::com::sun::star::mozilla::MozillaProductType product, ::com::sun::star::uno::Sequence< ::rtl::OUString >& list ) throw (::com::sun::star::uno::RuntimeException) +{ + return m_ProfileAccess->getProfileList(product,list); +} +::rtl::OUString SAL_CALL MozillaBootstrap::getDefaultProfile( ::com::sun::star::mozilla::MozillaProductType product ) throw (::com::sun::star::uno::RuntimeException) +{ + return m_ProfileAccess->getDefaultProfile(product); +} +::rtl::OUString SAL_CALL MozillaBootstrap::getProfilePath( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException) +{ + return m_ProfileAccess->getProfilePath(product,profileName); +} +::sal_Bool SAL_CALL MozillaBootstrap::isProfileLocked( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException) +{ + return m_ProfileAccess->isProfileLocked(product,profileName); +} +::sal_Bool SAL_CALL MozillaBootstrap::getProfileExists( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException) +{ + return m_ProfileAccess->getProfileExists(product,profileName); +} + +// XProfileManager +::sal_Int32 SAL_CALL MozillaBootstrap::bootupProfile( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException) +{ + (void)product; /* avoid warning about unused parameter */ + (void)profileName; /* avoid warning about unused parameter */ + return -1; +} +::sal_Int32 SAL_CALL MozillaBootstrap::shutdownProfile( ) throw (::com::sun::star::uno::RuntimeException) +{ + return -1; +} +::com::sun::star::mozilla::MozillaProductType SAL_CALL MozillaBootstrap::getCurrentProduct( ) throw (::com::sun::star::uno::RuntimeException) +{ + return ::com::sun::star::mozilla::MozillaProductType_Default; +} +::rtl::OUString SAL_CALL MozillaBootstrap::getCurrentProfile( ) throw (::com::sun::star::uno::RuntimeException) +{ + return ::rtl::OUString(); +} +::sal_Bool SAL_CALL MozillaBootstrap::isCurrentProfileLocked( ) throw (::com::sun::star::uno::RuntimeException) +{ + return true; +} +::rtl::OUString SAL_CALL MozillaBootstrap::setCurrentProfile( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException) +{ + (void)product; /* avoid warning about unused parameter */ + (void)profileName; /* avoid warning about unused parameter */ + return ::rtl::OUString(); +} + +// XProxyRunner +::sal_Int32 SAL_CALL MozillaBootstrap::Run( const ::com::sun::star::uno::Reference< ::com::sun::star::mozilla::XCodeProxy >& aCode ) throw (::com::sun::star::uno::RuntimeException) +{ + (void)aCode; /* avoid warning about unused parameter */ + return -1; +} + + +#include <cppuhelper/factory.hxx> +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::lang::XSingleServiceFactory; +using ::com::sun::star::lang::XMultiServiceFactory; + +extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL +component_getImplementationEnvironment( + const sal_Char **ppEnvTypeName, + uno_Environment ** /*ppEnv*/ + ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +static Reference< XInterface > SAL_CALL createInstance( const Reference< XMultiServiceFactory >& rServiceManager ) +{ + MozillaBootstrap * pBootstrap = reinterpret_cast<MozillaBootstrap*>(OMozillaBootstrap_CreateInstance(rServiceManager)); + return *pBootstrap; +} + +extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory( + const sal_Char* pImplementationName, + void* pServiceManager, + void* /*pRegistryKey*/) +{ + void* pRet = 0; + + if (pServiceManager) + { + ::rtl::OUString aImplName( ::rtl::OUString::createFromAscii( pImplementationName ) ); + Reference< XSingleServiceFactory > xFactory; + if (aImplName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.mozilla.MozillaBootstrap")) )) + { + Sequence< ::rtl::OUString > aSNS( 1 ); + aSNS[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.mozilla.MozillaBootstrap")); + + xFactory = ::cppu::createSingleFactory( + reinterpret_cast< XMultiServiceFactory* > ( pServiceManager), + aImplName, createInstance, aSNS ); + } + if ( xFactory.is() ) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + + return pRet; +}; + diff --git a/extensions/source/mozbootstrap/MMozillaBootstrap.hxx b/extensions/source/mozbootstrap/MMozillaBootstrap.hxx new file mode 100644 index 000000000000..afc2ccdbf7c0 --- /dev/null +++ b/extensions/source/mozbootstrap/MMozillaBootstrap.hxx @@ -0,0 +1,97 @@ +/************************************************************** + * + * 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 + * + * 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. + * + *************************************************************/ + + +#ifndef _SMOZILLABOOTSTRAP_HXX +#define _SMOZILLABOOTSTRAP_HXX + +#include <com/sun/star/mozilla/XMozillaBootstrap.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <cppuhelper/compbase2.hxx> +#include <osl/module.h> + + +#define MOZAB_MozillaBootstrap_IMPL_NAME "com.sun.star.comp.mozilla.MozillaBootstrap" + +namespace connectivity +{ + namespace mozab + { + typedef ::cppu::WeakComponentImplHelper2< ::com::sun::star::mozilla::XMozillaBootstrap, + ::com::sun::star::lang::XServiceInfo > OMozillaBootstrap_BASE; + class ProfileAccess; + class ProfileManager; + class MozillaBootstrap : public OMozillaBootstrap_BASE + { + protected: + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xMSFactory; + + ::osl::Mutex m_aMutex; // mutex is need to control member access + virtual ~MozillaBootstrap(); + protected: + ProfileAccess * m_ProfileAccess; + ProfileManager * m_ProfileManager; + public: + + void Init(); + MozillaBootstrap(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory); + + // OComponentHelper + virtual void SAL_CALL disposing(void); + // XInterface + static ::rtl::OUString getImplementationName_Static( ) throw(::com::sun::star::uno::RuntimeException); + static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static( ) throw (::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException); + + // XMozillaBootstrap + + // XProfileDiscover + virtual ::sal_Int32 SAL_CALL getProfileCount( ::com::sun::star::mozilla::MozillaProductType product) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getProfileList( ::com::sun::star::mozilla::MozillaProductType product, ::com::sun::star::uno::Sequence< ::rtl::OUString >& list ) throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getDefaultProfile( ::com::sun::star::mozilla::MozillaProductType product ) throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getProfilePath( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL isProfileLocked( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getProfileExists( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException); + + // XProfileManager + virtual ::sal_Int32 SAL_CALL bootupProfile( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL shutdownProfile( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::mozilla::MozillaProductType SAL_CALL getCurrentProduct( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getCurrentProfile( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL isCurrentProfileLocked( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL setCurrentProfile( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException); + + // XProxyRunner + virtual ::sal_Int32 SAL_CALL Run( const ::com::sun::star::uno::Reference< ::com::sun::star::mozilla::XCodeProxy >& aCode ) throw (::com::sun::star::uno::RuntimeException); + + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > + & getMSFactory(void) const { return m_xMSFactory; } + + }; + } + +} + +#endif // _SMozillaBootstrap_HXX diff --git a/extensions/source/mozbootstrap/MNSFolders.cxx b/extensions/source/mozbootstrap/MNSFolders.cxx new file mode 100644 index 000000000000..c16d36c8f746 --- /dev/null +++ b/extensions/source/mozbootstrap/MNSFolders.cxx @@ -0,0 +1,147 @@ +/************************************************************** + * + * 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 + * + * 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. + * + *************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_extensions.hxx" +#include <MNSFolders.hxx> + +#ifdef UNIX +#include <sys/types.h> +#include <strings.h> +#include <string.h> +#endif // End UNIX + +#ifdef WNT +#include "pre_include_windows.h" +#include <windows.h> +#include <stdlib.h> +#include <shlobj.h> +#include <objidl.h> +#include "post_include_windows.h" +#endif // End WNT +#include <osl/security.hxx> +#include <osl/file.hxx> +#include <osl/thread.h> + +using namespace ::com::sun::star::mozilla; + +namespace +{ + // ------------------------------------------------------------------- + static ::rtl::OUString lcl_getUserDataDirectory() + { + ::osl::Security aSecurity; + ::rtl::OUString aConfigPath; + + aSecurity.getConfigDir( aConfigPath ); + return aConfigPath + ::rtl::OUString::createFromAscii( "/" ); + } + + // ------------------------------------------------------------------- + static const char* DefaultProductDir[3][3] = + { + #if defined(XP_WIN) + { "Mozilla/SeaMonkey/", NULL, NULL }, + { "Mozilla/Firefox/", NULL, NULL }, + { "Thunderbird/", "Mozilla/Thunderbird/", NULL } + #elif(MACOSX) + { "../Mozilla/SeaMonkey/", NULL, NULL }, + { "Firefox/", NULL, NULL }, + { "../Thunderbird/", NULL, NULL } + #else + { ".mozilla/seamonkey/", NULL, NULL }, + { ".mozilla/firefox/", NULL, NULL }, + { ".thunderbird/", ".mozilla-thunderbird/", ".mozilla/thunderbird/" } + #endif + }; + + static const char* ProductRootEnvironmentVariable[3] = + { + "MOZILLA_PROFILE_ROOT", + "MOZILLA_FIREFOX_PROFILE_ROOT", + "MOZILLA_THUNDERBIRD_PROFILE_ROOT", + }; + + // ------------------------------------------------------------------- + static ::rtl::OUString lcl_guessProfileRoot( MozillaProductType _product ) + { + size_t productIndex = _product - 1; + + static ::rtl::OUString s_productDirectories[3]; + + if ( !s_productDirectories[ productIndex ].getLength() ) + { + ::rtl::OUString sProductPath; + + // check whether we have an anevironment variable which helps us + const char* pProfileByEnv = getenv( ProductRootEnvironmentVariable[ productIndex ] ); + if ( pProfileByEnv ) + { + sProductPath = ::rtl::OUString( pProfileByEnv, rtl_str_getLength( pProfileByEnv ), osl_getThreadTextEncoding() ); + // asume that this is fine, no further checks + } + else + { + ::rtl::OUString sProductDirCandidate; + const char* pProfileRegistry = "profiles.ini"; + + // check all possible candidates + for ( size_t i=0; i<3; ++i ) + { + if ( NULL == DefaultProductDir[ productIndex ][ i ] ) + break; + + sProductDirCandidate = lcl_getUserDataDirectory() + + ::rtl::OUString::createFromAscii( DefaultProductDir[ productIndex ][ i ] ); + + // check existence + ::osl::DirectoryItem aRegistryItem; + ::osl::FileBase::RC result = ::osl::DirectoryItem::get( sProductDirCandidate + ::rtl::OUString::createFromAscii( pProfileRegistry ), aRegistryItem ); + if ( result == ::osl::FileBase::E_None ) + { + ::osl::FileStatus aStatus( FileStatusMask_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 ]; + } +} + +// ----------------------------------------------------------------------- +::rtl::OUString getRegistryDir(MozillaProductType product) +{ + if (product == MozillaProductType_Default) + return ::rtl::OUString(); + + return lcl_guessProfileRoot( product ); +} diff --git a/extensions/source/mozbootstrap/MNSFolders.hxx b/extensions/source/mozbootstrap/MNSFolders.hxx new file mode 100644 index 000000000000..64582d868856 --- /dev/null +++ b/extensions/source/mozbootstrap/MNSFolders.hxx @@ -0,0 +1,39 @@ +/************************************************************** + * + * 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 + * + * 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. + * + *************************************************************/ + + + +#ifndef _MNSFOLDERS_HXX_ +#define _MNSFOLDERS_HXX_ + +#include <sal/types.h> +#include <osl/diagnose.h> +#include <osl/conditn.hxx> +#ifndef _COM_SUN_STAR_MOZILLA_MOZILLPRODUCTTYPE_HPP_ +#include <com/sun/star/mozilla/MozillaProductType.hpp> +#endif + +#include <rtl/ustring.hxx> + +::rtl::OUString getRegistryDir(::com::sun::star::mozilla::MozillaProductType product); + +#endif + diff --git a/extensions/source/mozbootstrap/MNSINIParser.cxx b/extensions/source/mozbootstrap/MNSINIParser.cxx new file mode 100644 index 000000000000..b1671c2a7a66 --- /dev/null +++ b/extensions/source/mozbootstrap/MNSINIParser.cxx @@ -0,0 +1,133 @@ +/************************************************************** + * + * 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 + * + * 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. + * + *************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_extensions.hxx" +#include <MNSINIParser.hxx> +#include <rtl/byteseq.hxx> + +IniParser::IniParser(OUString const & rIniName) throw(com::sun::star::io::IOException ) +{ + OUString iniUrl; + if (osl_File_E_None != osl_getFileURLFromSystemPath(rIniName.pData, &iniUrl.pData)) + return; + + +#if OSL_DEBUG_LEVEL > 0 + OString sFile = OUStringToOString(iniUrl, RTL_TEXTENCODING_ASCII_US); + OSL_TRACE(__FILE__" -- parser() - %s\n", sFile.getStr()); +#endif + oslFileHandle handle=NULL; + oslFileError fileError = osl_File_E_INVAL; + try{ + if (iniUrl.getLength()) + fileError = osl_openFile(iniUrl.pData, &handle, osl_File_OpenFlag_Read); + } + catch(::com::sun::star::io::IOException e) + { +#if OSL_DEBUG_LEVEL > 0 + OString file_tmp = OUStringToOString(iniUrl, RTL_TEXTENCODING_ASCII_US); + OSL_TRACE( __FILE__" -- couldn't open file: %s", file_tmp.getStr() ); +#endif + } + + if (osl_File_E_None == fileError) + { + rtl::ByteSequence seq; + sal_uInt64 nSize = 0; + + osl_getFileSize(handle, &nSize); + OUString sectionName = OUString::createFromAscii("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 , (sal_Sequence **) &seq)) + break; + OString line( (const sal_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->lList.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.getLength()) + sectionName = OUString::createFromAscii("no name section"); + + ini_Section *aSection = &mAllSection[sectionName]; + aSection->sName = sectionName; + } + } + } + osl_closeFile(handle); + } +#if OSL_DEBUG_LEVEL > 0 + else + { + OString file_tmp = OUStringToOString(iniUrl, RTL_TEXTENCODING_ASCII_US); + OSL_TRACE( __FILE__" -- couldn't open file: %s", file_tmp.getStr() ); + } +#endif +} +#if OSL_DEBUG_LEVEL > 0 +void IniParser::Dump() +{ + IniSectionMap::iterator iBegin = mAllSection.begin(); + IniSectionMap::iterator iEnd = mAllSection.end(); + for(;iBegin != iEnd;iBegin++) + { + ini_Section *aSection = &(*iBegin).second; + OString sec_name_tmp = OUStringToOString(aSection->sName, RTL_TEXTENCODING_ASCII_US); + for(NameValueList::iterator itor=aSection->lList.begin(); + itor != aSection->lList.end(); + itor++) + { + struct ini_NameValue * aValue = &(*itor); + OString name_tmp = OUStringToOString(aValue->sName, RTL_TEXTENCODING_ASCII_US); + OString value_tmp = OUStringToOString(aValue->sValue, RTL_TEXTENCODING_UTF8); + OSL_TRACE( + " section=%s name=%s value=%s\n", + sec_name_tmp.getStr(), + name_tmp.getStr(), + value_tmp.getStr() ); + + } + } + +} +#endif + diff --git a/extensions/source/mozbootstrap/MNSINIParser.hxx b/extensions/source/mozbootstrap/MNSINIParser.hxx new file mode 100644 index 000000000000..f2aaaf4805b9 --- /dev/null +++ b/extensions/source/mozbootstrap/MNSINIParser.hxx @@ -0,0 +1,79 @@ +/************************************************************** + * + * 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 + * + * 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. + * + *************************************************************/ + + +#ifndef __MNSINIPARSER_HXX__ +#define __MNSINIPARSER_HXX__ + +#include <rtl/ustring.hxx> +#include <com/sun/star/io/IOException.hpp> +#include <osl/process.h> +using namespace rtl; + +#include <map> +#include <list> + +#if OSL_DEBUG_LEVEL > 0 +#include <stdio.h> +#endif + +struct ini_NameValue +{ + rtl::OUString sName; + rtl::OUString sValue; + + inline ini_NameValue() SAL_THROW( () ) + {} + inline ini_NameValue( + OUString const & name, OUString const & value ) SAL_THROW( () ) + : sName( name ), + sValue( value ) + {} +}; + +typedef std::list< + ini_NameValue +> NameValueList; + +struct ini_Section +{ + rtl::OUString sName; + NameValueList lList; +}; +typedef std::map<rtl::OUString, + ini_Section + >IniSectionMap; + + +class IniParser +{ + IniSectionMap mAllSection; +public: + IniSectionMap * getAllSection(){return &mAllSection;}; + IniParser(OUString const & rIniName) throw(com::sun::star::io::IOException ); +#if OSL_DEBUG_LEVEL > 0 + void Dump(); +#endif + +}; + +#endif + diff --git a/extensions/source/mozbootstrap/MNSProfileDiscover.cxx b/extensions/source/mozbootstrap/MNSProfileDiscover.cxx new file mode 100644 index 000000000000..ee7d43f47d6b --- /dev/null +++ b/extensions/source/mozbootstrap/MNSProfileDiscover.cxx @@ -0,0 +1,221 @@ +/************************************************************** + * + * 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 + * + * 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. + * + *************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_extensions.hxx" +#include "MNSProfileDiscover.hxx" + +// Registry Keys + +static ::rtl::OUString szProfileSubtreeString=::rtl::OUString::createFromAscii("Profiles"); +static ::rtl::OUString szCurrentProfileString= ::rtl::OUString::createFromAscii("CurrentProfile"); +static ::rtl::OUString szDirectoryString =::rtl::OUString::createFromAscii("directory"); + +#ifndef MAXPATHLEN +#define MAXPATHLEN 1024 +#endif +#include <MNSFolders.hxx> +#include <MNSINIParser.hxx> + +namespace connectivity +{ + namespace mozab + { + ProfileStruct::ProfileStruct(MozillaProductType aProduct,::rtl::OUString aProfileName, + const ::rtl::OUString& aProfilePath) + { + product=aProduct; + profileName = aProfileName; + profilePath = aProfilePath; + } + ::rtl::OUString ProfileStruct::getProfilePath() + { + return profilePath; + } + + ProfileAccess::~ProfileAccess() + { + } + ProfileAccess::ProfileAccess() + { + LoadProductsInfo(); + } + + sal_Int32 ProfileAccess::LoadProductsInfo() + { + //load SeaMonkey 2 profiles to m_ProductProfileList + sal_Int32 count = LoadXPToolkitProfiles(MozillaProductType_Mozilla); + + //load thunderbird profiles to m_ProductProfileList + count += LoadXPToolkitProfiles(MozillaProductType_Thunderbird); + + //load firefox profiles to m_ProductProfileList + //firefox profile does not containt address book, but maybe others need them + count += LoadXPToolkitProfiles(MozillaProductType_Firefox); + return count; + } + //Thunderbird and firefox profiles are saved in profiles.ini + sal_Int32 ProfileAccess::LoadXPToolkitProfiles(MozillaProductType product) + { + sal_Int32 index=product; + ProductStruct &m_Product = m_ProductProfileList[index]; + + ::rtl::OUString regDir = getRegistryDir(product); + ::rtl::OUString profilesIni( regDir ); + profilesIni += ::rtl::OUString::createFromAscii( "profiles.ini" ); + IniParser parser( profilesIni ); + IniSectionMap &mAllSection = *(parser.getAllSection()); + + IniSectionMap::iterator iBegin = mAllSection.begin(); + IniSectionMap::iterator iEnd = mAllSection.end(); + for(;iBegin != iEnd;iBegin++) + { + ini_Section *aSection = &(*iBegin).second; + ::rtl::OUString profileName; + ::rtl::OUString profilePath; + ::rtl::OUString sIsRelative; + ::rtl::OUString sIsDefault; + + for(NameValueList::iterator itor=aSection->lList.begin(); + itor != aSection->lList.end(); + itor++) + { + struct ini_NameValue * aValue = &(*itor); + if (aValue->sName.equals(::rtl::OUString::createFromAscii("Name"))) + { + profileName = aValue->sValue; + } + else if (aValue->sName.equals(::rtl::OUString::createFromAscii("IsRelative"))) + { + sIsRelative = aValue->sValue; + } + else if (aValue->sName.equals(::rtl::OUString::createFromAscii("Path"))) + { + profilePath = aValue->sValue; + } + else if (aValue->sName.equals(::rtl::OUString::createFromAscii("Default"))) + { + sIsDefault = aValue->sValue; + } + } + if (profileName.getLength() != 0 || profilePath.getLength() != 0) + { + sal_Int32 isRelative = 0; + if (sIsRelative.getLength() != 0) + { + isRelative = sIsRelative.toInt32(); + } + + ProfileStruct* profileItem = new ProfileStruct(product,profileName, + regDir + profilePath); + m_Product.mProfileList[profileName] = profileItem; + + sal_Int32 isDefault = 0; + if (sIsDefault.getLength() != 0) + { + isDefault = sIsDefault.toInt32(); + } + if (isDefault) + m_Product.mCurrentProfileName = profileName; + + } + + } + return static_cast< ::sal_Int32 >(m_Product.mProfileList.size()); + } + + ::rtl::OUString ProfileAccess::getProfilePath( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException) + { + sal_Int32 index=product; + ProductStruct &m_Product = m_ProductProfileList[index]; + if (!m_Product.mProfileList.size() || m_Product.mProfileList.find(profileName) == m_Product.mProfileList.end()) + { + //Profile not found + return ::rtl::OUString(); + } + else + return m_Product.mProfileList[profileName]->getProfilePath(); + } + + ::sal_Int32 ProfileAccess::getProfileCount( ::com::sun::star::mozilla::MozillaProductType product) throw (::com::sun::star::uno::RuntimeException) + { + sal_Int32 index=product; + ProductStruct &m_Product = m_ProductProfileList[index]; + return static_cast< ::sal_Int32 >(m_Product.mProfileList.size()); + } + ::sal_Int32 ProfileAccess::getProfileList( ::com::sun::star::mozilla::MozillaProductType product, ::com::sun::star::uno::Sequence< ::rtl::OUString >& list ) throw (::com::sun::star::uno::RuntimeException) + { + sal_Int32 index=product; + ProductStruct &m_Product = m_ProductProfileList[index]; + list.realloc(static_cast<sal_Int32>(m_Product.mProfileList.size())); + sal_Int32 i=0; + for(ProfileList::iterator itor=m_Product.mProfileList.begin(); + itor != m_Product.mProfileList.end(); + itor++) + { + ProfileStruct * aProfile = (*itor).second; + list[i] = aProfile->getProfileName(); + i++; + } + + return static_cast< ::sal_Int32 >(m_Product.mProfileList.size()); + } + + ::rtl::OUString ProfileAccess::getDefaultProfile( ::com::sun::star::mozilla::MozillaProductType product ) throw (::com::sun::star::uno::RuntimeException) + { + sal_Int32 index=product; + ProductStruct &m_Product = m_ProductProfileList[index]; + if (m_Product.mCurrentProfileName.getLength() != 0) + { + //default profile setted in mozilla registry + return m_Product.mCurrentProfileName; + } + if (m_Product.mProfileList.size() == 0) + { + //there are not any profiles + return ::rtl::OUString(); + } + ProfileStruct * aProfile = (*m_Product.mProfileList.begin()).second; + return aProfile->getProfileName(); + } + + ::sal_Bool ProfileAccess::isProfileLocked( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException) + { + (void)product; /* avoid warning about unused parameter */ + (void)profileName; /* avoid warning about unused parameter */ + return sal_True; + } + + ::sal_Bool ProfileAccess::getProfileExists( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException) + { + sal_Int32 index=product; + ProductStruct &m_Product = m_ProductProfileList[index]; + if (!m_Product.mProfileList.size() || m_Product.mProfileList.find(profileName) == m_Product.mProfileList.end()) + { + return sal_False; + } + else + return sal_True; + } + } +} + + diff --git a/extensions/source/mozbootstrap/MNSProfileDiscover.hxx b/extensions/source/mozbootstrap/MNSProfileDiscover.hxx new file mode 100644 index 000000000000..916b8e437651 --- /dev/null +++ b/extensions/source/mozbootstrap/MNSProfileDiscover.hxx @@ -0,0 +1,98 @@ +/************************************************************** + * + * 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 + * + * 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. + * + *************************************************************/ + +#ifndef __MNSProfileDiscover_h___ +#define __MNSProfileDiscover_h___ + +#include <sal/types.h> +#include <osl/diagnose.h> +#include <osl/conditn.hxx> +#ifndef _COM_SUN_STAR_MOZILLA_MOZILLPRODUCTTYPE_HPP_ +#include <com/sun/star/mozilla/MozillaProductType.hpp> +#endif +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include <rtl/ustring.hxx> + +#include <vector> +#include <map> + +using namespace com::sun::star::mozilla; +namespace connectivity +{ + namespace mozab + { + class ProfileStruct; + } +} +typedef ::std::map < ::rtl::OUString, ::connectivity::mozab::ProfileStruct* > ProfileList; +namespace connectivity +{ + namespace mozab + { + class ProfileStruct + { + public: + ProfileStruct(MozillaProductType aProduct,::rtl::OUString aProfileName, + const ::rtl::OUString &aProfilePath ); + MozillaProductType getProductType() { return product;} + ::rtl::OUString getProfileName(){ return profileName;} + ::rtl::OUString getProfilePath() ; + protected: + MozillaProductType product; + ::rtl::OUString profileName; + ::rtl::OUString profilePath; + }; + + class ProductStruct + { + public: + void setCurrentProfile(::rtl::OUString aProfileName){mCurrentProfileName = aProfileName;} + + ::rtl::OUString mCurrentProfileName; + + ProfileList mProfileList; + }; + + //Used to query profiles information + class ProfileAccess + { + public: + + virtual ~ProfileAccess(); + ProfileAccess(); + ::rtl::OUString getProfilePath( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException); + ::sal_Int32 getProfileCount( ::com::sun::star::mozilla::MozillaProductType product ) throw (::com::sun::star::uno::RuntimeException); + ::sal_Int32 getProfileList( ::com::sun::star::mozilla::MozillaProductType product, ::com::sun::star::uno::Sequence< ::rtl::OUString >& list ) throw (::com::sun::star::uno::RuntimeException); + ::rtl::OUString getDefaultProfile( ::com::sun::star::mozilla::MozillaProductType product ) throw (::com::sun::star::uno::RuntimeException); + ::sal_Bool SAL_CALL isProfileLocked( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException); + ::sal_Bool SAL_CALL getProfileExists( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException); + protected: + ProductStruct m_ProductProfileList[4]; + sal_Int32 LoadProductsInfo(); + sal_Int32 LoadXPToolkitProfiles(MozillaProductType product); + }; + + } +} + +#endif // __MNSProfileDiscover_h___ + diff --git a/extensions/source/mozbootstrap/makefile.mk b/extensions/source/mozbootstrap/makefile.mk new file mode 100644 index 000000000000..a6ec4bb4a54e --- /dev/null +++ b/extensions/source/mozbootstrap/makefile.mk @@ -0,0 +1,76 @@ +#************************************************************** +# +# 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 +# +# 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. +# +#************************************************************** + +CALL_CDECL=TRUE + +PRJ=..$/.. +PRJNAME=extensions +TARGET=mozbootstrap + +.IF "$(OS)" == "OS2" || "$(OS)" == "WNT" +all: + @echo " Not building under Windows / OS/2" +.ENDIF + +# --- Settings ---------------------------------- + +LIBTARGET=NO +ENABLE_EXCEPTIONS=TRUE +VISIBILITY_HIDDEN=TRUE + +.INCLUDE : settings.mk + +# no "lib" prefix +DLLPRE = + +# --- Files ------------------------------------- + +SLOFILES += \ + $(SLO)$/MNSINIParser.obj \ + $(SLO)$/MNSProfileDiscover.obj \ + $(SLO)$/MMozillaBootstrap.obj \ + $(SLO)$/MNSFolders.obj + +# CDEFS+=-DMINIMAL_PROFILEDISCOVER + +SHL1TARGET=$(TARGET).uno +SHL1VERSIONMAP=$(SOLARENV)/src/component.map +SHL1OBJS=$(SLOFILES) +SHL1DEF=$(MISC)$/$(SHL1TARGET).def +DEF1NAME=$(SHL1TARGET) + +SHL1STDLIBS=\ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(SALLIB) \ + $(COMPHELPERLIB) + +ALLTAR : $(MISC)/mozbootstrap.component + +$(MISC)/mozbootstrap.component .ERRREMOVE : \ + $(SOLARENV)/bin/createcomponent.xslt mozbootstrap.component + $(XSLTPROC) --nonet --stringparam uri \ + '$(COMPONENTPREFIX_BASIS_NATIVE)$(SHL1TARGETN:f)' -o $@ \ + $(SOLARENV)/bin/createcomponent.xslt mozbootstrap.component + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk diff --git a/extensions/source/mozbootstrap/mozbootstrap.component b/extensions/source/mozbootstrap/mozbootstrap.component new file mode 100644 index 000000000000..618a4b4f3d4a --- /dev/null +++ b/extensions/source/mozbootstrap/mozbootstrap.component @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!--*********************************************************** + * + * 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 + * + * 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. + * + ***********************************************************--> +<component loader="com.sun.star.loader.SharedLibrary" + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="com.sun.star.comp.mozilla.MozillaBootstrap"> + <service name="com.sun.star.mozilla.MozillaBootstrap"/> + </implementation> +</component> |