2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-07-17 12:30:48 +01:00
|
|
|
/*
|
|
|
|
* 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 .
|
|
|
|
*/
|
2006-11-08 10:54:56 +00:00
|
|
|
|
|
|
|
#include "scriptcont.hxx"
|
New identifier for save/open macro with user defined types
no version bump but B_USERTYPE defined
fix test from commit de26ef85 that should be nMaxRecords
tested full round trip on password protected document (ie. use binary storage)
master --(0)--> master --(1)--> libreoffice 4.4 --(2)--> master --(3)--> master
(0) in master, User type supported, big module supported
(1) in libreoffice 4.4, user type not supported, big module supported, no loss of code
(2) in master, user type not supported, big module not found, no loss of code
it is OK as libreoffice 4.4 saves to LegacyVersion
(3) in master, User type supported, big module supported (all is restored)
it is OK as module was saved with CURRENT_VERSION (see sbxmod.cxx)
Change-Id: I237cf7de70adf1a755be1bc30987b21c43b6ab35
Reviewed-on: https://gerrit.libreoffice.org/17871
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
2015-08-19 17:58:12 +02:00
|
|
|
#include <filefmt.hxx>
|
2006-11-08 10:54:56 +00:00
|
|
|
#include <com/sun/star/container/XNameContainer.hpp>
|
2017-02-06 17:08:38 +01:00
|
|
|
#include <com/sun/star/packages/WrongPasswordException.hpp>
|
2012-10-03 13:30:43 +02:00
|
|
|
#include <com/sun/star/xml/sax/Parser.hpp>
|
2006-11-08 10:54:56 +00:00
|
|
|
#include <com/sun/star/xml/sax/InputSource.hpp>
|
2012-10-10 10:13:18 +02:00
|
|
|
#include <com/sun/star/xml/sax/Writer.hpp>
|
2006-11-08 10:54:56 +00:00
|
|
|
#include <com/sun/star/io/XOutputStream.hpp>
|
|
|
|
#include <com/sun/star/io/XInputStream.hpp>
|
|
|
|
#include <com/sun/star/io/XActiveDataSource.hpp>
|
2012-11-02 17:46:30 +02:00
|
|
|
#include <com/sun/star/ucb/XSimpleFileAccess3.hpp>
|
2006-11-08 10:54:56 +00:00
|
|
|
#include <com/sun/star/embed/ElementModes.hpp>
|
|
|
|
#include <com/sun/star/embed/XEncryptionProtectedSource.hpp>
|
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
|
|
|
#include <com/sun/star/embed/XTransactedObject.hpp>
|
|
|
|
#include <com/sun/star/task/ErrorCodeIOException.hpp>
|
2010-06-15 20:02:53 +02:00
|
|
|
#include <com/sun/star/script/ModuleType.hpp>
|
2006-11-08 10:54:56 +00:00
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
#include <comphelper/storagehelper.hxx>
|
|
|
|
#include <unotools/streamwrap.hxx>
|
|
|
|
#include <unotools/ucbstreamhelper.hxx>
|
|
|
|
#include <osl/mutex.hxx>
|
2013-09-02 09:03:31 +01:00
|
|
|
#include <osl/thread.h>
|
2006-11-08 10:54:56 +00:00
|
|
|
#include <rtl/digest.h>
|
2008-06-06 12:30:11 +00:00
|
|
|
#include <rtl/strbuf.hxx>
|
2006-11-08 10:54:56 +00:00
|
|
|
|
|
|
|
// For password functionality
|
|
|
|
#include <tools/urlobj.hxx>
|
|
|
|
|
|
|
|
|
2009-10-06 07:38:24 +02:00
|
|
|
#include <unotools/pathoptions.hxx>
|
2006-11-08 10:54:56 +00:00
|
|
|
#include <svtools/sfxecode.hxx>
|
|
|
|
#include <svtools/ehdl.hxx>
|
2007-06-27 13:34:11 +00:00
|
|
|
#include <basic/basmgr.hxx>
|
|
|
|
#include <basic/sbmod.hxx>
|
2010-06-15 20:02:53 +02:00
|
|
|
#include <basic/basicmanagerrepository.hxx>
|
2013-11-11 21:25:36 -06:00
|
|
|
#include <basic/modsizeexceeded.hxx>
|
2006-11-08 10:54:56 +00:00
|
|
|
#include <xmlscript/xmlmod_imexp.hxx>
|
|
|
|
#include <cppuhelper/factory.hxx>
|
2007-01-29 14:06:56 +00:00
|
|
|
#include <com/sun/star/util/VetoException.hpp>
|
2015-09-17 17:10:47 +01:00
|
|
|
#include <memory>
|
2014-05-31 00:09:32 +09:00
|
|
|
|
2006-11-08 10:54:56 +00:00
|
|
|
namespace basic
|
|
|
|
{
|
|
|
|
|
2007-03-15 14:39:48 +00:00
|
|
|
using namespace com::sun::star::document;
|
2006-11-08 10:54:56 +00:00
|
|
|
using namespace com::sun::star::container;
|
|
|
|
using namespace com::sun::star::io;
|
|
|
|
using namespace com::sun::star::uno;
|
|
|
|
using namespace com::sun::star::ucb;
|
|
|
|
using namespace com::sun::star::lang;
|
|
|
|
using namespace com::sun::star::script;
|
|
|
|
using namespace com::sun::star::xml::sax;
|
|
|
|
using namespace com::sun::star;
|
|
|
|
using namespace cppu;
|
|
|
|
using namespace osl;
|
|
|
|
|
2014-02-25 17:41:32 +01:00
|
|
|
|
2006-11-08 10:54:56 +00:00
|
|
|
// Implementation class SfxScriptLibraryContainer
|
|
|
|
|
2007-03-15 14:39:48 +00:00
|
|
|
const sal_Char* SAL_CALL SfxScriptLibraryContainer::getInfoFileName() const { return "script"; }
|
|
|
|
const sal_Char* SAL_CALL SfxScriptLibraryContainer::getOldInfoFileName() const { return "script"; }
|
|
|
|
const sal_Char* SAL_CALL SfxScriptLibraryContainer::getLibElementFileExtension() const { return "xba"; }
|
|
|
|
const sal_Char* SAL_CALL SfxScriptLibraryContainer::getLibrariesDir() const { return "Basic"; }
|
2006-11-08 10:54:56 +00:00
|
|
|
|
|
|
|
// OldBasicPassword interface
|
2012-11-03 09:07:25 -05:00
|
|
|
void SfxScriptLibraryContainer::setLibraryPassword( const OUString& rLibraryName, const OUString& rPassword )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
SfxLibrary* pImplLib = getImplLib( rLibraryName );
|
2012-10-23 15:35:12 +02:00
|
|
|
if( !rPassword.isEmpty() )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
2012-08-19 17:49:02 +09:00
|
|
|
pImplLib->mbDoc50Password = true;
|
2014-04-04 16:52:44 +02:00
|
|
|
pImplLib->mbPasswordProtected = true;
|
2006-11-08 10:54:56 +00:00
|
|
|
pImplLib->maPassword = rPassword;
|
2016-03-05 00:42:05 +01:00
|
|
|
SfxScriptLibrary *const pSL(dynamic_cast<SfxScriptLibrary *>(pImplLib));
|
|
|
|
if (pSL && pSL->mbLoaded)
|
|
|
|
{
|
|
|
|
pSL->mbLoadedSource = true; // must store source code now!
|
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-24 11:22:56 +09:00
|
|
|
catch(const NoSuchElementException& ) {}
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ctor for service
|
2015-04-14 12:44:47 +02:00
|
|
|
SfxScriptLibraryContainer::SfxScriptLibraryContainer()
|
2012-06-02 17:46:27 -05:00
|
|
|
:maScriptLanguage( "StarBasic" )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
|
|
|
// all initialisation has to be done
|
|
|
|
// by calling XInitialization::initialize
|
|
|
|
}
|
|
|
|
|
2007-03-15 14:39:48 +00:00
|
|
|
SfxScriptLibraryContainer::SfxScriptLibraryContainer( const uno::Reference< embed::XStorage >& xStorage )
|
2012-06-02 17:46:27 -05:00
|
|
|
:maScriptLanguage( "StarBasic" )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
2007-03-15 14:39:48 +00:00
|
|
|
init( OUString(), xStorage );
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Methods to get library instances of the correct type
|
2007-01-02 14:41:30 +00:00
|
|
|
SfxLibrary* SfxScriptLibraryContainer::implCreateLibrary( const OUString& aName )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
2007-01-02 14:41:30 +00:00
|
|
|
(void)aName; // Only needed for SfxDialogLibrary
|
2015-12-23 09:46:48 +02:00
|
|
|
SfxLibrary* pRet = new SfxScriptLibrary( maModifiable, mxSFI );
|
2006-11-08 10:54:56 +00:00
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2012-11-03 09:07:25 -05:00
|
|
|
SfxLibrary* SfxScriptLibraryContainer::implCreateLibraryLink( const OUString& aName,
|
|
|
|
const OUString& aLibInfoFileURL,
|
|
|
|
const OUString& StorageURL,
|
2014-04-04 16:52:44 +02:00
|
|
|
bool ReadOnly )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
2007-01-02 14:41:30 +00:00
|
|
|
(void)aName; // Only needed for SfxDialogLibrary
|
2015-12-23 09:46:48 +02:00
|
|
|
SfxLibrary* pRet = new SfxScriptLibrary( maModifiable, mxSFI,
|
2012-11-03 09:07:25 -05:00
|
|
|
aLibInfoFileURL, StorageURL, ReadOnly );
|
2006-11-08 10:54:56 +00:00
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2015-04-14 12:44:47 +02:00
|
|
|
Any SAL_CALL SfxScriptLibraryContainer::createEmptyLibraryElement()
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
|
|
|
OUString aMod;
|
|
|
|
Any aRetAny;
|
|
|
|
aRetAny <<= aMod;
|
|
|
|
return aRetAny;
|
|
|
|
}
|
|
|
|
|
2015-03-04 09:28:31 +00:00
|
|
|
bool SAL_CALL SfxScriptLibraryContainer::isLibraryElementValid(const Any& rElement) const
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
2015-03-04 09:28:31 +00:00
|
|
|
return SfxScriptLibrary::containsValidModule(rElement);
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
|
2012-11-03 09:07:25 -05:00
|
|
|
void SAL_CALL SfxScriptLibraryContainer::writeLibraryElement( const Reference < XNameContainer >& xLib,
|
|
|
|
const OUString& aElementName,
|
|
|
|
const Reference< XOutputStream >& xOutput)
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
|
|
|
// Create sax writer
|
2013-05-13 16:51:26 +02:00
|
|
|
Reference< XWriter > xWriter = xml::sax::Writer::create(mxContext);
|
2006-11-08 10:54:56 +00:00
|
|
|
|
|
|
|
Reference< XTruncate > xTruncate( xOutput, UNO_QUERY );
|
|
|
|
OSL_ENSURE( xTruncate.is(), "Currently only the streams that can be truncated are expected!" );
|
|
|
|
if ( xTruncate.is() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2006-11-08 10:54:56 +00:00
|
|
|
xTruncate->truncate();
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2012-10-10 10:13:18 +02:00
|
|
|
xWriter->setOutputStream( xOutput );
|
2006-11-08 10:54:56 +00:00
|
|
|
|
|
|
|
xmlscript::ModuleDescriptor aMod;
|
|
|
|
aMod.aName = aElementName;
|
|
|
|
aMod.aLanguage = maScriptLanguage;
|
2010-06-15 20:02:53 +02:00
|
|
|
Any aElement = xLib->getByName( aElementName );
|
2006-11-08 10:54:56 +00:00
|
|
|
aElement >>= aMod.aCode;
|
2010-06-15 20:02:53 +02:00
|
|
|
|
2010-07-27 17:12:01 +02:00
|
|
|
Reference< script::vba::XVBAModuleInfo > xModInfo( xLib, UNO_QUERY );
|
2010-06-15 20:02:53 +02:00
|
|
|
if( xModInfo.is() && xModInfo->hasModuleInfo( aElementName ) )
|
|
|
|
{
|
|
|
|
script::ModuleInfo aModInfo = xModInfo->getModuleInfo( aElementName );
|
|
|
|
switch( aModInfo.ModuleType )
|
|
|
|
{
|
|
|
|
case ModuleType::NORMAL:
|
2012-11-06 23:34:23 -06:00
|
|
|
aMod.aModuleType = "normal";
|
2010-06-15 20:02:53 +02:00
|
|
|
break;
|
|
|
|
case ModuleType::CLASS:
|
2012-11-06 23:34:23 -06:00
|
|
|
aMod.aModuleType ="class";
|
2010-06-15 20:02:53 +02:00
|
|
|
break;
|
|
|
|
case ModuleType::FORM:
|
2012-11-06 23:34:23 -06:00
|
|
|
aMod.aModuleType = "form";
|
2010-06-15 20:02:53 +02:00
|
|
|
break;
|
|
|
|
case ModuleType::DOCUMENT:
|
2012-11-06 23:34:23 -06:00
|
|
|
aMod.aModuleType = "document";
|
2010-06-15 20:02:53 +02:00
|
|
|
break;
|
|
|
|
case ModuleType::UNKNOWN:
|
|
|
|
// nothing
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-10 10:13:18 +02:00
|
|
|
xmlscript::exportScriptModule( xWriter, aMod );
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Any SAL_CALL SfxScriptLibraryContainer::importLibraryElement
|
2010-06-15 20:02:53 +02:00
|
|
|
( const Reference < XNameContainer >& xLib,
|
|
|
|
const OUString& aElementName, const OUString& aFile,
|
|
|
|
const uno::Reference< io::XInputStream >& xInStream )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
|
|
|
Any aRetAny;
|
|
|
|
|
2013-05-13 16:51:26 +02:00
|
|
|
Reference< XParser > xParser = xml::sax::Parser::create( mxContext );
|
2006-11-08 10:54:56 +00:00
|
|
|
|
|
|
|
// Read from storage?
|
2014-04-04 16:52:44 +02:00
|
|
|
bool bStorage = xInStream.is();
|
2006-11-08 10:54:56 +00:00
|
|
|
Reference< XInputStream > xInput;
|
|
|
|
|
|
|
|
if( bStorage )
|
|
|
|
{
|
|
|
|
xInput = xInStream;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
xInput = mxSFI->openFileRead( aFile );
|
|
|
|
}
|
2011-08-24 11:22:56 +09:00
|
|
|
catch(const Exception& )
|
2006-11-08 10:54:56 +00:00
|
|
|
//catch( Exception& e )
|
|
|
|
{
|
|
|
|
// TODO:
|
|
|
|
//throw WrappedTargetException( e );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !xInput.is() )
|
|
|
|
return aRetAny;
|
|
|
|
|
|
|
|
InputSource source;
|
|
|
|
source.aInputStream = xInput;
|
|
|
|
source.sSystemId = aFile;
|
|
|
|
|
|
|
|
// start parsing
|
|
|
|
xmlscript::ModuleDescriptor aMod;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
xParser->setDocumentHandler( ::xmlscript::importScriptModule( aMod ) );
|
|
|
|
xParser->parseStream( source );
|
|
|
|
}
|
2011-08-24 11:22:56 +09:00
|
|
|
catch(const Exception& )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
|
|
|
SfxErrorContext aEc( ERRCTX_SFX_LOADBASIC, aFile );
|
2014-03-17 17:18:08 +01:00
|
|
|
ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aRetAny <<= aMod.aCode;
|
|
|
|
|
|
|
|
// TODO: Check language
|
|
|
|
// aMod.aLanguage
|
|
|
|
// aMod.aName ignored
|
2011-12-10 13:35:14 -02:00
|
|
|
if( !aMod.aModuleType.isEmpty() )
|
2010-06-15 20:02:53 +02:00
|
|
|
{
|
2010-09-17 15:28:21 +02:00
|
|
|
/* If in VBA compatibility mode, force creation of the VBA Globals
|
|
|
|
object. Each application will create an instance of its own
|
|
|
|
implementation and store it in its Basic manager. Implementations
|
|
|
|
will do all necessary additional initialization, such as
|
|
|
|
registering the global "This***Doc" UNO constant, starting the
|
|
|
|
document events processor etc.
|
|
|
|
*/
|
|
|
|
if( getVBACompatibilityMode() ) try
|
|
|
|
{
|
|
|
|
Reference< frame::XModel > xModel( mxOwnerDocument ); // weak-ref -> ref
|
|
|
|
Reference< XMultiServiceFactory > xFactory( xModel, UNO_QUERY_THROW );
|
2013-06-29 21:24:12 +02:00
|
|
|
xFactory->createInstance("ooo.vba.VBAGlobals");
|
2010-09-17 15:28:21 +02:00
|
|
|
}
|
2011-08-24 11:22:56 +09:00
|
|
|
catch(const Exception& )
|
2010-06-15 20:02:53 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
script::ModuleInfo aModInfo;
|
|
|
|
aModInfo.ModuleType = ModuleType::UNKNOWN;
|
2012-04-06 19:49:53 +02:00
|
|
|
if( aMod.aModuleType == "normal" )
|
2010-06-15 20:02:53 +02:00
|
|
|
{
|
|
|
|
aModInfo.ModuleType = ModuleType::NORMAL;
|
|
|
|
}
|
2012-04-06 19:49:53 +02:00
|
|
|
else if( aMod.aModuleType == "class" )
|
2010-06-15 20:02:53 +02:00
|
|
|
{
|
|
|
|
aModInfo.ModuleType = ModuleType::CLASS;
|
|
|
|
}
|
2012-04-06 19:49:53 +02:00
|
|
|
else if( aMod.aModuleType == "form" )
|
2010-06-15 20:02:53 +02:00
|
|
|
{
|
|
|
|
aModInfo.ModuleType = ModuleType::FORM;
|
|
|
|
aModInfo.ModuleObject = mxOwnerDocument;
|
|
|
|
}
|
2012-04-06 19:49:53 +02:00
|
|
|
else if( aMod.aModuleType == "document" )
|
2010-06-15 20:02:53 +02:00
|
|
|
{
|
|
|
|
aModInfo.ModuleType = ModuleType::DOCUMENT;
|
2010-09-20 15:03:23 +02:00
|
|
|
|
|
|
|
// #163691# use the same codename access instance for all document modules
|
|
|
|
if( !mxCodeNameAccess.is() ) try
|
2010-06-15 20:02:53 +02:00
|
|
|
{
|
2010-09-20 15:03:23 +02:00
|
|
|
Reference<frame::XModel > xModel( mxOwnerDocument );
|
|
|
|
Reference< XMultiServiceFactory> xSF( xModel, UNO_QUERY_THROW );
|
2013-06-29 21:24:12 +02:00
|
|
|
mxCodeNameAccess.set( xSF->createInstance("ooo.vba.VBAObjectModuleObjectProvider"), UNO_QUERY );
|
2010-06-15 20:02:53 +02:00
|
|
|
}
|
2011-08-24 11:22:56 +09:00
|
|
|
catch(const Exception& ) {}
|
2010-09-20 15:03:23 +02:00
|
|
|
|
|
|
|
if( mxCodeNameAccess.is() )
|
2010-06-15 20:02:53 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2010-09-20 15:03:23 +02:00
|
|
|
aModInfo.ModuleObject.set( mxCodeNameAccess->getByName( aElementName), uno::UNO_QUERY );
|
2010-06-15 20:02:53 +02:00
|
|
|
}
|
2011-08-24 11:22:56 +09:00
|
|
|
catch(const uno::Exception&)
|
2010-06-15 20:02:53 +02:00
|
|
|
{
|
2016-12-13 08:07:40 +02:00
|
|
|
SAL_WARN("basic", "Failed to get document object for " << aElementName );
|
2010-06-15 20:02:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-27 17:12:01 +02:00
|
|
|
Reference< script::vba::XVBAModuleInfo > xVBAModuleInfo( xLib, UNO_QUERY );
|
2010-06-15 20:02:53 +02:00
|
|
|
if( xVBAModuleInfo.is() )
|
|
|
|
{
|
|
|
|
if( xVBAModuleInfo->hasModuleInfo( aElementName ) )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2010-06-15 20:02:53 +02:00
|
|
|
xVBAModuleInfo->removeModuleInfo( aElementName );
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2010-06-15 20:02:53 +02:00
|
|
|
xVBAModuleInfo->insertModuleInfo( aElementName, aModInfo );
|
|
|
|
}
|
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
|
|
|
|
return aRetAny;
|
|
|
|
}
|
|
|
|
|
2015-04-14 12:44:47 +02:00
|
|
|
SfxLibraryContainer* SfxScriptLibraryContainer::createInstanceImpl()
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
|
|
|
return new SfxScriptLibraryContainer();
|
|
|
|
}
|
|
|
|
|
2012-12-30 13:07:28 -02:00
|
|
|
void SAL_CALL SfxScriptLibraryContainer::importFromOldStorage( const OUString& aFile )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
|
|
|
// TODO: move loading from old storage to binary filters?
|
2016-02-21 17:51:28 +01:00
|
|
|
auto xStorage = tools::make_ref<SotStorage>( false, aFile );
|
|
|
|
if( xStorage->GetError() == ERRCODE_NONE )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
2016-02-21 17:51:28 +01:00
|
|
|
BasicManager* pBasicManager = new BasicManager( *(xStorage.get()), aFile );
|
2006-11-08 10:54:56 +00:00
|
|
|
|
|
|
|
// Set info
|
2015-11-10 10:10:36 +01:00
|
|
|
LibraryContainerInfo aInfo( this, nullptr, static_cast< OldBasicPassword* >( this ) );
|
2007-03-15 14:39:48 +00:00
|
|
|
pBasicManager->SetLibraryContainerInfo( aInfo );
|
2006-11-08 10:54:56 +00:00
|
|
|
|
|
|
|
// Now the libraries should be copied to this SfxScriptLibraryContainer
|
|
|
|
BasicManager::LegacyDeleteBasicManager( pBasicManager );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Storing with password encryption
|
|
|
|
|
|
|
|
// Methods XLibraryContainerPassword
|
|
|
|
sal_Bool SAL_CALL SfxScriptLibraryContainer::isLibraryPasswordProtected( const OUString& Name )
|
|
|
|
{
|
2007-03-15 14:39:48 +00:00
|
|
|
LibraryContainerMethodGuard aGuard( *this );
|
2006-11-08 10:54:56 +00:00
|
|
|
SfxLibrary* pImplLib = getImplLib( Name );
|
2014-04-04 16:52:44 +02:00
|
|
|
bool bRet = pImplLib->mbPasswordProtected;
|
2006-11-08 10:54:56 +00:00
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL SfxScriptLibraryContainer::isLibraryPasswordVerified( const OUString& Name )
|
|
|
|
{
|
2007-03-15 14:39:48 +00:00
|
|
|
LibraryContainerMethodGuard aGuard( *this );
|
2006-11-08 10:54:56 +00:00
|
|
|
SfxLibrary* pImplLib = getImplLib( Name );
|
|
|
|
if( !pImplLib->mbPasswordProtected )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2006-11-08 10:54:56 +00:00
|
|
|
throw IllegalArgumentException();
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2014-04-04 16:52:44 +02:00
|
|
|
bool bRet = pImplLib->mbPasswordVerified;
|
2006-11-08 10:54:56 +00:00
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL SfxScriptLibraryContainer::verifyLibraryPassword
|
|
|
|
( const OUString& Name, const OUString& Password )
|
|
|
|
{
|
2007-03-15 14:39:48 +00:00
|
|
|
LibraryContainerMethodGuard aGuard( *this );
|
2006-11-08 10:54:56 +00:00
|
|
|
SfxLibrary* pImplLib = getImplLib( Name );
|
|
|
|
if( !pImplLib->mbPasswordProtected || pImplLib->mbPasswordVerified )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2006-11-08 10:54:56 +00:00
|
|
|
throw IllegalArgumentException();
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
// Test password
|
2014-04-04 16:52:44 +02:00
|
|
|
bool bSuccess = false;
|
2006-11-08 10:54:56 +00:00
|
|
|
if( pImplLib->mbDoc50Password )
|
|
|
|
{
|
|
|
|
bSuccess = ( Password == pImplLib->maPassword );
|
|
|
|
if( bSuccess )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2014-04-04 16:52:44 +02:00
|
|
|
pImplLib->mbPasswordVerified = true;
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pImplLib->maPassword = Password;
|
2014-04-04 16:52:44 +02:00
|
|
|
bSuccess = implLoadPasswordLibrary( pImplLib, Name, true );
|
2006-11-08 10:54:56 +00:00
|
|
|
if( bSuccess )
|
|
|
|
{
|
2014-02-06 23:21:40 +01:00
|
|
|
// The library gets modified by verifying the password, because other-
|
2006-11-08 10:54:56 +00:00
|
|
|
// wise for saving the storage would be copied and that doesn't work
|
|
|
|
// with mtg's storages when the password is verified
|
2014-04-04 16:52:44 +02:00
|
|
|
pImplLib->implSetModified( true );
|
|
|
|
pImplLib->mbPasswordVerified = true;
|
2006-11-08 10:54:56 +00:00
|
|
|
|
|
|
|
// Reload library to get source
|
|
|
|
if( pImplLib->mbLoaded )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2006-11-08 10:54:56 +00:00
|
|
|
implLoadPasswordLibrary( pImplLib, Name );
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL SfxScriptLibraryContainer::changeLibraryPassword( const OUString& Name,
|
2012-11-03 09:07:25 -05:00
|
|
|
const OUString& OldPassword,
|
|
|
|
const OUString& NewPassword )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
2007-03-15 14:39:48 +00:00
|
|
|
LibraryContainerMethodGuard aGuard( *this );
|
2006-11-08 10:54:56 +00:00
|
|
|
SfxLibrary* pImplLib = getImplLib( Name );
|
|
|
|
if( OldPassword == NewPassword )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2006-11-08 10:54:56 +00:00
|
|
|
return;
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2014-04-04 16:52:44 +02:00
|
|
|
bool bOldPassword = !OldPassword.isEmpty();
|
|
|
|
bool bNewPassword = !NewPassword.isEmpty();
|
|
|
|
bool bStorage = mxStorage.is() && !pImplLib->mbLink;
|
2006-11-08 10:54:56 +00:00
|
|
|
|
|
|
|
if( pImplLib->mbReadOnly || (bOldPassword && !pImplLib->mbPasswordProtected) )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2006-11-08 10:54:56 +00:00
|
|
|
throw IllegalArgumentException();
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
// Library must be loaded
|
|
|
|
loadLibrary( Name );
|
|
|
|
|
2013-10-07 17:02:13 +09:00
|
|
|
bool bKillCryptedFiles = false;
|
|
|
|
bool bKillUncryptedFiles = false;
|
2006-11-08 10:54:56 +00:00
|
|
|
|
|
|
|
// Remove or change password?
|
|
|
|
if( bOldPassword )
|
|
|
|
{
|
|
|
|
if( isLibraryPasswordVerified( Name ) )
|
|
|
|
{
|
|
|
|
if( pImplLib->maPassword != OldPassword )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2006-11-08 10:54:56 +00:00
|
|
|
throw IllegalArgumentException();
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !verifyLibraryPassword( Name, OldPassword ) )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2006-11-08 10:54:56 +00:00
|
|
|
throw IllegalArgumentException();
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
// Reload library to get source
|
|
|
|
// Should be done in verifyLibraryPassword loadLibrary( Name );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !bNewPassword )
|
|
|
|
{
|
2014-04-04 16:52:44 +02:00
|
|
|
pImplLib->mbPasswordProtected = false;
|
|
|
|
pImplLib->mbPasswordVerified = false;
|
2014-12-18 13:20:44 +01:00
|
|
|
pImplLib->maPassword.clear();
|
2006-11-08 10:54:56 +00:00
|
|
|
|
2014-04-04 16:52:44 +02:00
|
|
|
maModifiable.setModified( true );
|
|
|
|
pImplLib->implSetModified( true );
|
2006-11-08 10:54:56 +00:00
|
|
|
|
|
|
|
if( !bStorage && !pImplLib->mbDoc50Password )
|
|
|
|
{
|
|
|
|
// Store application basic uncrypted
|
|
|
|
uno::Reference< embed::XStorage > xStorage;
|
2012-08-19 17:49:02 +09:00
|
|
|
storeLibraries_Impl( xStorage, false );
|
2013-10-07 17:02:13 +09:00
|
|
|
bKillCryptedFiles = true;
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set new password?
|
|
|
|
if( bNewPassword )
|
|
|
|
{
|
2014-04-04 16:52:44 +02:00
|
|
|
pImplLib->mbPasswordProtected = true;
|
|
|
|
pImplLib->mbPasswordVerified = true;
|
2006-11-08 10:54:56 +00:00
|
|
|
pImplLib->maPassword = NewPassword;
|
2016-03-05 00:42:05 +01:00
|
|
|
SfxScriptLibrary *const pSL(dynamic_cast<SfxScriptLibrary *>(pImplLib));
|
|
|
|
if (pSL && pSL->mbLoaded)
|
|
|
|
{
|
|
|
|
pSL->mbLoadedSource = true; // must store source code now!
|
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
|
2014-04-04 16:52:44 +02:00
|
|
|
maModifiable.setModified( true );
|
|
|
|
pImplLib->implSetModified( true );
|
2006-11-08 10:54:56 +00:00
|
|
|
|
|
|
|
if( !bStorage && !pImplLib->mbDoc50Password )
|
|
|
|
{
|
2014-02-06 21:51:36 +01:00
|
|
|
// Store application basic crypted
|
2006-11-08 10:54:56 +00:00
|
|
|
uno::Reference< embed::XStorage > xStorage;
|
2012-08-19 17:49:02 +09:00
|
|
|
storeLibraries_Impl( xStorage, false );
|
2013-10-07 17:02:13 +09:00
|
|
|
bKillUncryptedFiles = true;
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( bKillCryptedFiles || bKillUncryptedFiles )
|
|
|
|
{
|
|
|
|
Sequence< OUString > aElementNames = pImplLib->getElementNames();
|
|
|
|
sal_Int32 nNameCount = aElementNames.getLength();
|
|
|
|
const OUString* pNames = aElementNames.getConstArray();
|
|
|
|
OUString aLibDirPath = createAppLibraryFolder( pImplLib, Name );
|
|
|
|
try
|
|
|
|
{
|
|
|
|
for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
|
|
|
|
{
|
|
|
|
OUString aElementName = pNames[ i ];
|
|
|
|
|
|
|
|
INetURLObject aElementInetObj( aLibDirPath );
|
2014-01-28 20:03:03 +01:00
|
|
|
aElementInetObj.insertName( aElementName, false,
|
2016-03-16 13:17:24 +02:00
|
|
|
INetURLObject::LAST_SEGMENT,
|
2016-12-05 07:59:20 +02:00
|
|
|
INetURLObject::EncodeMechanism::All );
|
2006-11-08 10:54:56 +00:00
|
|
|
if( bKillUncryptedFiles )
|
2012-11-06 23:34:23 -06:00
|
|
|
{
|
2006-11-08 10:54:56 +00:00
|
|
|
aElementInetObj.setExtension( maLibElementFileExtension );
|
2012-11-06 23:34:23 -06:00
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
else
|
2012-11-06 23:34:23 -06:00
|
|
|
{
|
2015-11-06 09:34:39 +01:00
|
|
|
aElementInetObj.setExtension( "pba" );
|
2012-11-06 23:34:23 -06:00
|
|
|
}
|
2016-12-05 08:47:18 +02:00
|
|
|
OUString aElementPath( aElementInetObj.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
|
2006-11-08 10:54:56 +00:00
|
|
|
|
|
|
|
if( mxSFI->exists( aElementPath ) )
|
2012-11-06 23:34:23 -06:00
|
|
|
{
|
2006-11-08 10:54:56 +00:00
|
|
|
mxSFI->kill( aElementPath );
|
2012-11-06 23:34:23 -06:00
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-24 11:22:56 +09:00
|
|
|
catch(const Exception& ) {}
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-11 10:20:19 +02:00
|
|
|
void setStreamKey( const uno::Reference< io::XStream >& xStream, const OUString& aPass )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
|
|
|
uno::Reference< embed::XEncryptionProtectedSource > xEncrStream( xStream, uno::UNO_QUERY );
|
|
|
|
if ( xEncrStream.is() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2006-11-08 10:54:56 +00:00
|
|
|
xEncrStream->setEncryptionPassword( aPass );
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Impl methods
|
2014-04-04 16:52:44 +02:00
|
|
|
bool SfxScriptLibraryContainer::implStorePasswordLibrary( SfxLibrary* pLib,
|
|
|
|
const OUString& aName,
|
|
|
|
const uno::Reference< embed::XStorage >& xStorage,
|
2015-07-20 09:21:24 +02:00
|
|
|
const css::uno::Reference< css::task::XInteractionHandler >& xHandler )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
|
|
|
OUString aDummyLocation;
|
2012-11-02 17:46:30 +02:00
|
|
|
Reference< XSimpleFileAccess3 > xDummySFA;
|
2007-01-29 14:06:56 +00:00
|
|
|
return implStorePasswordLibrary( pLib, aName, xStorage, aDummyLocation, xDummySFA, xHandler );
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
|
2014-04-04 16:52:44 +02:00
|
|
|
bool SfxScriptLibraryContainer::implStorePasswordLibrary( SfxLibrary* pLib, const OUString& aName,
|
2015-07-20 09:21:24 +02:00
|
|
|
const css::uno::Reference< css::embed::XStorage >& xStorage,
|
2014-04-04 16:52:44 +02:00
|
|
|
const OUString& aTargetURL,
|
2015-03-09 10:11:00 +00:00
|
|
|
const Reference< XSimpleFileAccess3 >& rToUseSFI,
|
2015-07-20 09:21:24 +02:00
|
|
|
const css::uno::Reference< css::task::XInteractionHandler >& xHandler )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
2011-12-10 13:35:14 -02:00
|
|
|
bool bExport = !aTargetURL.isEmpty();
|
2007-03-15 14:39:48 +00:00
|
|
|
|
|
|
|
BasicManager* pBasicMgr = getBasicManager();
|
|
|
|
OSL_ENSURE( pBasicMgr, "SfxScriptLibraryContainer::implStorePasswordLibrary: cannot do this without a BasicManager!" );
|
|
|
|
if ( !pBasicMgr )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2014-04-04 16:52:44 +02:00
|
|
|
return false;
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2007-01-29 14:06:56 +00:00
|
|
|
// Only need to handle the export case here,
|
|
|
|
// save/saveas etc are handled in sfxbasemodel::storeSelf &
|
|
|
|
// sfxbasemodel::impl_store
|
2016-02-06 16:06:48 +02:00
|
|
|
std::vector<OUString> aNames;
|
2007-03-15 14:39:48 +00:00
|
|
|
if ( bExport && pBasicMgr->LegacyPsswdBinaryLimitExceeded(aNames) )
|
2007-01-29 14:06:56 +00:00
|
|
|
{
|
|
|
|
if ( xHandler.is() )
|
|
|
|
{
|
|
|
|
ModuleSizeExceeded* pReq = new ModuleSizeExceeded( aNames );
|
|
|
|
uno::Reference< task::XInteractionRequest > xReq( pReq );
|
|
|
|
xHandler->handle( xReq );
|
|
|
|
if ( pReq->isAbort() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2007-01-29 14:06:56 +00:00
|
|
|
throw util::VetoException();
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2007-01-29 14:06:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-08 10:54:56 +00:00
|
|
|
StarBASIC* pBasicLib = pBasicMgr->GetLib( aName );
|
|
|
|
if( !pBasicLib )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2014-04-04 16:52:44 +02:00
|
|
|
return false;
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
Sequence< OUString > aElementNames = pLib->getElementNames();
|
|
|
|
sal_Int32 nNameCount = aElementNames.getLength();
|
|
|
|
const OUString* pNames = aElementNames.getConstArray();
|
|
|
|
|
2014-04-04 16:52:44 +02:00
|
|
|
bool bLink = pLib->mbLink;
|
|
|
|
bool bStorage = xStorage.is() && !bLink;
|
2006-11-08 10:54:56 +00:00
|
|
|
if( bStorage )
|
|
|
|
{
|
|
|
|
for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
|
|
|
|
{
|
|
|
|
OUString aElementName = pNames[ i ];
|
|
|
|
|
|
|
|
// Write binary image stream
|
|
|
|
SbModule* pMod = pBasicLib->FindModule( aElementName );
|
|
|
|
if( pMod )
|
|
|
|
{
|
2016-07-15 00:09:57 +05:30
|
|
|
OUString aCodeStreamName = aElementName + ".bin";
|
2012-11-03 09:07:25 -05:00
|
|
|
try
|
|
|
|
{
|
2006-11-08 10:54:56 +00:00
|
|
|
uno::Reference< io::XStream > xCodeStream = xStorage->openStreamElement(
|
2012-11-03 09:07:25 -05:00
|
|
|
aCodeStreamName,
|
|
|
|
embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
|
2006-11-08 10:54:56 +00:00
|
|
|
|
|
|
|
if ( !xCodeStream.is() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2017-01-17 22:16:28 +05:30
|
|
|
throw uno::RuntimeException("null returned from openStreamElement");
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
SvMemoryStream aMemStream;
|
2017-04-04 14:13:00 +02:00
|
|
|
/*sal_Bool bStore = */pMod->StoreBinaryData( aMemStream );
|
2006-11-08 10:54:56 +00:00
|
|
|
|
2016-09-14 17:01:50 +02:00
|
|
|
sal_Int32 const nSize = aMemStream.Tell();
|
|
|
|
if (nSize < 0) { abort(); }
|
2006-11-08 10:54:56 +00:00
|
|
|
Sequence< sal_Int8 > aBinSeq( nSize );
|
|
|
|
sal_Int8* pData = aBinSeq.getArray();
|
2012-09-29 14:47:11 +02:00
|
|
|
memcpy( pData, aMemStream.GetData(), nSize );
|
2006-11-08 10:54:56 +00:00
|
|
|
|
|
|
|
Reference< XOutputStream > xOut = xCodeStream->getOutputStream();
|
|
|
|
if ( !xOut.is() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2006-11-08 10:54:56 +00:00
|
|
|
throw io::IOException(); // access denied because the stream is readonly
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
|
|
|
xOut->writeBytes( aBinSeq );
|
2006-11-08 10:54:56 +00:00
|
|
|
xOut->closeOutput();
|
|
|
|
}
|
2011-08-24 11:22:56 +09:00
|
|
|
catch(const uno::Exception& )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
|
|
|
// TODO: handle error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( pLib->mbPasswordVerified || pLib->mbDoc50Password )
|
|
|
|
{
|
2010-06-15 20:02:53 +02:00
|
|
|
if( !isLibraryElementValid( pLib->getByName( aElementName ) ) )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
2012-11-03 09:07:25 -05:00
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2012-12-30 13:47:18 -02:00
|
|
|
OString aMessage = "invalid library element '" +
|
|
|
|
OUStringToOString( aElementName, osl_getThreadTextEncoding() ) +
|
|
|
|
"'.";
|
2013-01-03 19:04:15 +01:00
|
|
|
OSL_FAIL( aMessage.getStr());
|
2012-11-03 09:07:25 -05:00
|
|
|
#endif
|
2008-06-06 12:30:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
|
2016-07-15 00:09:57 +05:30
|
|
|
OUString aSourceStreamName = aElementName + ".xml";
|
2012-11-03 09:07:25 -05:00
|
|
|
try
|
|
|
|
{
|
2008-06-06 12:30:11 +00:00
|
|
|
uno::Reference< io::XStream > xSourceStream = xStorage->openStreamElement(
|
2012-11-03 09:07:25 -05:00
|
|
|
aSourceStreamName,
|
|
|
|
embed::ElementModes::READWRITE );
|
2017-02-14 16:11:21 +01:00
|
|
|
uno::Reference< beans::XPropertySet > xProps( xSourceStream, uno::UNO_QUERY_THROW );
|
2012-06-02 17:46:27 -05:00
|
|
|
OUString aMime( "text/xml" );
|
2017-02-03 08:54:47 +02:00
|
|
|
xProps->setPropertyValue("MediaType", uno::Any( aMime ) );
|
2006-11-08 10:54:56 +00:00
|
|
|
|
2008-06-06 12:30:11 +00:00
|
|
|
// Set encryption key
|
|
|
|
setStreamKey( xSourceStream, pLib->maPassword );
|
|
|
|
|
|
|
|
Reference< XOutputStream > xOutput = xSourceStream->getOutputStream();
|
2010-06-15 20:02:53 +02:00
|
|
|
Reference< XNameContainer > xLib( pLib );
|
|
|
|
writeLibraryElement( xLib, aElementName, xOutput );
|
2008-06-06 12:30:11 +00:00
|
|
|
}
|
2011-08-24 11:22:56 +09:00
|
|
|
catch(const uno::Exception& )
|
2008-06-06 12:30:11 +00:00
|
|
|
{
|
2017-04-20 11:08:35 +02:00
|
|
|
OSL_FAIL( "Problem on storing of password library!" );
|
2008-06-06 12:30:11 +00:00
|
|
|
// TODO: error handling
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else // !mbPasswordVerified
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
// What to do if not verified?! In any case it's already loaded here
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// Application libraries have only to be saved if the password
|
|
|
|
// is verified because otherwise they can't be modified
|
|
|
|
else if( pLib->mbPasswordVerified || bExport )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2012-11-02 17:46:30 +02:00
|
|
|
Reference< XSimpleFileAccess3 > xSFI = mxSFI;
|
2015-03-09 10:11:00 +00:00
|
|
|
if( rToUseSFI.is() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2015-03-09 10:11:00 +00:00
|
|
|
xSFI = rToUseSFI;
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
OUString aLibDirPath;
|
|
|
|
if( bExport )
|
|
|
|
{
|
|
|
|
INetURLObject aInetObj( aTargetURL );
|
2016-03-16 13:17:24 +02:00
|
|
|
aInetObj.insertName( aName, true, INetURLObject::LAST_SEGMENT,
|
2016-12-05 07:59:20 +02:00
|
|
|
INetURLObject::EncodeMechanism::All );
|
2016-12-05 08:47:18 +02:00
|
|
|
aLibDirPath = aInetObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
|
2006-11-08 10:54:56 +00:00
|
|
|
|
|
|
|
if( !xSFI->isFolder( aLibDirPath ) )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2006-11-08 10:54:56 +00:00
|
|
|
xSFI->createFolder( aLibDirPath );
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aLibDirPath = createAppLibraryFolder( pLib, aName );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
|
|
|
|
{
|
|
|
|
OUString aElementName = pNames[ i ];
|
|
|
|
|
|
|
|
INetURLObject aElementInetObj( aLibDirPath );
|
2014-01-28 20:03:03 +01:00
|
|
|
aElementInetObj.insertName( aElementName, false,
|
2016-03-16 13:17:24 +02:00
|
|
|
INetURLObject::LAST_SEGMENT,
|
2016-12-05 07:59:20 +02:00
|
|
|
INetURLObject::EncodeMechanism::All );
|
2015-11-06 09:34:39 +01:00
|
|
|
aElementInetObj.setExtension( "pba" );
|
2016-12-05 08:47:18 +02:00
|
|
|
OUString aElementPath = aElementInetObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
|
2006-11-08 10:54:56 +00:00
|
|
|
|
2010-06-15 20:02:53 +02:00
|
|
|
if( !isLibraryElementValid( pLib->getByName( aElementName ) ) )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
2012-11-03 09:07:25 -05:00
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2012-12-30 13:47:18 -02:00
|
|
|
OString aMessage = "invalid library element '" +
|
|
|
|
OUStringToOString( aElementName, osl_getThreadTextEncoding() ) +
|
|
|
|
"'.";
|
2013-01-03 19:04:15 +01:00
|
|
|
OSL_FAIL( aMessage.getStr());
|
2012-11-03 09:07:25 -05:00
|
|
|
#endif
|
2008-06-06 12:30:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
|
2008-06-06 12:30:11 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
uno::Reference< embed::XStorage > xElementRootStorage =
|
2012-11-03 09:07:25 -05:00
|
|
|
::comphelper::OStorageHelper::GetStorageFromURL(
|
|
|
|
aElementPath,
|
|
|
|
embed::ElementModes::READWRITE );
|
2008-06-06 12:30:11 +00:00
|
|
|
if ( !xElementRootStorage.is() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2017-01-17 22:16:28 +05:30
|
|
|
throw uno::RuntimeException("null returned from GetStorageFromURL");
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2008-06-06 12:30:11 +00:00
|
|
|
// Write binary image stream
|
|
|
|
SbModule* pMod = pBasicLib->FindModule( aElementName );
|
|
|
|
if( pMod )
|
|
|
|
{
|
2012-06-02 17:46:27 -05:00
|
|
|
OUString aCodeStreamName( "code.bin" );
|
2006-11-08 10:54:56 +00:00
|
|
|
|
2008-06-06 12:30:11 +00:00
|
|
|
uno::Reference< io::XStream > xCodeStream = xElementRootStorage->openStreamElement(
|
|
|
|
aCodeStreamName,
|
|
|
|
embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE );
|
2006-11-08 10:54:56 +00:00
|
|
|
|
2008-06-06 12:30:11 +00:00
|
|
|
SvMemoryStream aMemStream;
|
2017-04-04 14:13:00 +02:00
|
|
|
/*sal_Bool bStore = */pMod->StoreBinaryData( aMemStream );
|
2006-11-08 10:54:56 +00:00
|
|
|
|
2016-09-14 17:01:50 +02:00
|
|
|
sal_Int32 const nSize = aMemStream.Tell();
|
|
|
|
if (nSize < 0) { abort(); }
|
2008-06-06 12:30:11 +00:00
|
|
|
Sequence< sal_Int8 > aBinSeq( nSize );
|
|
|
|
sal_Int8* pData = aBinSeq.getArray();
|
2012-09-29 14:47:11 +02:00
|
|
|
memcpy( pData, aMemStream.GetData(), nSize );
|
2006-11-08 10:54:56 +00:00
|
|
|
|
2008-06-06 12:30:11 +00:00
|
|
|
Reference< XOutputStream > xOut = xCodeStream->getOutputStream();
|
|
|
|
if ( xOut.is() )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
2008-06-06 12:30:11 +00:00
|
|
|
xOut->writeBytes( aBinSeq );
|
|
|
|
xOut->closeOutput();
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
2008-06-06 12:30:11 +00:00
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
|
2008-06-06 12:30:11 +00:00
|
|
|
// Write encrypted source stream
|
2012-06-02 17:46:27 -05:00
|
|
|
OUString aSourceStreamName( "source.xml" );
|
2006-11-08 10:54:56 +00:00
|
|
|
|
2008-06-06 12:30:11 +00:00
|
|
|
uno::Reference< io::XStream > xSourceStream;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
xSourceStream = xElementRootStorage->openStreamElement(
|
|
|
|
aSourceStreamName,
|
|
|
|
embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE );
|
|
|
|
|
|
|
|
// #87671 Allow encryption
|
2017-02-14 16:11:21 +01:00
|
|
|
uno::Reference< embed::XEncryptionProtectedSource > xEncr( xSourceStream, uno::UNO_QUERY_THROW );
|
2008-06-06 12:30:11 +00:00
|
|
|
xEncr->setEncryptionPassword( pLib->maPassword );
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
2015-07-20 09:21:24 +02:00
|
|
|
catch(const css::packages::WrongPasswordException& )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
2008-06-06 12:30:11 +00:00
|
|
|
xSourceStream = xElementRootStorage->openEncryptedStreamElement(
|
2012-11-03 09:07:25 -05:00
|
|
|
aSourceStreamName,
|
|
|
|
embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE,
|
|
|
|
pLib->maPassword );
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
|
2017-02-14 16:11:21 +01:00
|
|
|
uno::Reference< beans::XPropertySet > xProps( xSourceStream, uno::UNO_QUERY_THROW );
|
2012-06-02 17:46:27 -05:00
|
|
|
OUString aMime( "text/xml" );
|
2017-02-03 08:54:47 +02:00
|
|
|
xProps->setPropertyValue("MediaType", uno::Any( aMime ) );
|
2008-06-06 12:30:11 +00:00
|
|
|
|
|
|
|
Reference< XOutputStream > xOut = xSourceStream->getOutputStream();
|
2010-06-15 20:02:53 +02:00
|
|
|
Reference< XNameContainer > xLib( pLib );
|
|
|
|
writeLibraryElement( xLib, aElementName, xOut );
|
2008-06-06 12:30:11 +00:00
|
|
|
// i50568: sax writer already closes stream
|
|
|
|
// xOut->closeOutput();
|
|
|
|
|
2017-02-14 16:11:21 +01:00
|
|
|
uno::Reference< embed::XTransactedObject > xTransact( xElementRootStorage, uno::UNO_QUERY_THROW );
|
2008-06-06 12:30:11 +00:00
|
|
|
xTransact->commit();
|
|
|
|
}
|
2011-08-24 11:22:56 +09:00
|
|
|
catch(const uno::Exception& )
|
2008-06-06 12:30:11 +00:00
|
|
|
{
|
|
|
|
// TODO: handle error
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2011-08-24 11:22:56 +09:00
|
|
|
catch(const Exception& )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2014-04-04 16:52:44 +02:00
|
|
|
return true;
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
|
2014-04-04 16:52:44 +02:00
|
|
|
bool SfxScriptLibraryContainer::implLoadPasswordLibrary
|
|
|
|
( SfxLibrary* pLib, const OUString& Name, bool bVerifyPasswordOnly )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
2014-04-04 16:52:44 +02:00
|
|
|
bool bRet = true;
|
2006-11-08 10:54:56 +00:00
|
|
|
|
2014-04-04 16:52:44 +02:00
|
|
|
bool bLink = pLib->mbLink;
|
|
|
|
bool bStorage = mxStorage.is() && !bLink;
|
2006-11-08 10:54:56 +00:00
|
|
|
|
|
|
|
// Already loaded? Then only verifiedPassword can change something
|
|
|
|
SfxScriptLibrary* pScriptLib = static_cast< SfxScriptLibrary* >( pLib );
|
|
|
|
if( pScriptLib->mbLoaded )
|
|
|
|
{
|
|
|
|
if( pScriptLib->mbLoadedBinary && !bVerifyPasswordOnly &&
|
|
|
|
(pScriptLib->mbLoadedSource || !pLib->mbPasswordVerified) )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2014-04-04 16:52:44 +02:00
|
|
|
return false;
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
|
2015-11-10 10:10:36 +01:00
|
|
|
StarBASIC* pBasicLib = nullptr;
|
2014-04-04 16:52:44 +02:00
|
|
|
bool bLoadBinary = false;
|
2006-11-08 10:54:56 +00:00
|
|
|
if( !pScriptLib->mbLoadedBinary && !bVerifyPasswordOnly && !pLib->mbPasswordVerified )
|
|
|
|
{
|
|
|
|
BasicManager* pBasicMgr = getBasicManager();
|
2007-03-15 14:39:48 +00:00
|
|
|
OSL_ENSURE( pBasicMgr, "SfxScriptLibraryContainer::implLoadPasswordLibrary: cannot do this without a BasicManager!" );
|
2014-04-04 16:52:44 +02:00
|
|
|
bool bLoaded = pScriptLib->mbLoaded;
|
|
|
|
pScriptLib->mbLoaded = true; // Necessary to get lib
|
2015-11-10 10:10:36 +01:00
|
|
|
pBasicLib = pBasicMgr ? pBasicMgr->GetLib( Name ) : nullptr;
|
2006-11-08 10:54:56 +00:00
|
|
|
pScriptLib->mbLoaded = bLoaded; // Restore flag
|
|
|
|
if( !pBasicLib )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2014-04-04 16:52:44 +02:00
|
|
|
return false;
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2014-04-04 16:52:44 +02:00
|
|
|
bLoadBinary = true;
|
2012-08-21 22:54:26 +09:00
|
|
|
pScriptLib->mbLoadedBinary = true;
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 17:02:13 +09:00
|
|
|
bool bLoadSource = false;
|
2006-11-08 10:54:56 +00:00
|
|
|
if( !pScriptLib->mbLoadedSource && pLib->mbPasswordVerified && !bVerifyPasswordOnly )
|
|
|
|
{
|
2013-10-07 17:02:13 +09:00
|
|
|
bLoadSource = true;
|
2012-08-21 22:54:26 +09:00
|
|
|
pScriptLib->mbLoadedSource = true;
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Sequence< OUString > aElementNames = pLib->getElementNames();
|
|
|
|
sal_Int32 nNameCount = aElementNames.getLength();
|
|
|
|
const OUString* pNames = aElementNames.getConstArray();
|
|
|
|
|
|
|
|
if( bStorage )
|
|
|
|
{
|
|
|
|
uno::Reference< embed::XStorage > xLibrariesStor;
|
|
|
|
uno::Reference< embed::XStorage > xLibraryStor;
|
|
|
|
if( bStorage )
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
xLibrariesStor = mxStorage->openStorageElement( maLibrariesDir, embed::ElementModes::READ );
|
|
|
|
if ( !xLibrariesStor.is() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2017-01-17 22:16:28 +05:30
|
|
|
throw uno::RuntimeException("null returned from openStorageElement");
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
xLibraryStor = xLibrariesStor->openStorageElement( Name, embed::ElementModes::READ );
|
|
|
|
if ( !xLibraryStor.is() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2017-01-17 22:16:28 +05:30
|
|
|
throw uno::RuntimeException("null returned from openStorageElement");
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
2011-08-24 11:22:56 +09:00
|
|
|
catch(const uno::Exception& )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
2017-04-20 11:08:35 +02:00
|
|
|
OSL_FAIL( "### couldn't open sub storage for library" );
|
2014-04-04 16:52:44 +02:00
|
|
|
return false;
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
|
|
|
|
{
|
|
|
|
OUString aElementName = pNames[ i ];
|
|
|
|
|
|
|
|
// Load binary
|
|
|
|
if( bLoadBinary )
|
|
|
|
{
|
|
|
|
SbModule* pMod = pBasicLib->FindModule( aElementName );
|
|
|
|
if( !pMod )
|
|
|
|
{
|
2013-09-02 09:03:31 +01:00
|
|
|
pMod = pBasicLib->MakeModule( aElementName, OUString() );
|
2014-03-26 11:18:51 +02:00
|
|
|
pBasicLib->SetModified( false );
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
|
2016-07-15 00:09:57 +05:30
|
|
|
OUString aCodeStreamName= aElementName + ".bin";
|
2012-11-03 09:07:25 -05:00
|
|
|
try
|
|
|
|
{
|
2006-11-08 10:54:56 +00:00
|
|
|
uno::Reference< io::XStream > xCodeStream = xLibraryStor->openStreamElement(
|
|
|
|
aCodeStreamName,
|
|
|
|
embed::ElementModes::READ );
|
|
|
|
if ( !xCodeStream.is() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2017-01-17 22:16:28 +05:30
|
|
|
throw uno::RuntimeException("null returned from openStreamElement");
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2015-09-17 17:10:47 +01:00
|
|
|
std::unique_ptr<SvStream> pStream(::utl::UcbStreamHelper::CreateStream( xCodeStream ));
|
2006-11-08 10:54:56 +00:00
|
|
|
if ( !pStream || pStream->GetError() )
|
|
|
|
{
|
|
|
|
sal_Int32 nError = pStream ? pStream->GetError() : ERRCODE_IO_GENERAL;
|
2013-10-09 19:23:35 +02:00
|
|
|
throw task::ErrorCodeIOException(
|
|
|
|
("utl::UcbStreamHelper::CreateStream failed for \""
|
|
|
|
+ aCodeStreamName + "\": 0x"
|
|
|
|
+ OUString::number(nError, 16)),
|
|
|
|
uno::Reference< uno::XInterface >(), nError);
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
|
2011-01-10 14:40:57 +01:00
|
|
|
/*sal_Bool bRet = */pMod->LoadBinaryData( *pStream );
|
2006-11-08 10:54:56 +00:00
|
|
|
// TODO: Check return value
|
|
|
|
}
|
2011-08-24 11:22:56 +09:00
|
|
|
catch(const uno::Exception& )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
|
|
|
// TODO: error handling
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load source
|
|
|
|
if( bLoadSource || bVerifyPasswordOnly )
|
|
|
|
{
|
|
|
|
// Access encrypted source stream
|
2016-07-15 00:09:57 +05:30
|
|
|
OUString aSourceStreamName = aElementName + ".xml";
|
2012-11-03 09:07:25 -05:00
|
|
|
try
|
|
|
|
{
|
2006-11-08 10:54:56 +00:00
|
|
|
uno::Reference< io::XStream > xSourceStream = xLibraryStor->openEncryptedStreamElement(
|
|
|
|
aSourceStreamName,
|
|
|
|
embed::ElementModes::READ,
|
|
|
|
pLib->maPassword );
|
|
|
|
if ( !xSourceStream.is() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2017-01-17 22:16:28 +05:30
|
|
|
throw uno::RuntimeException("null returned from openEncryptedStreamElement");
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
// if this point is reached then the password is correct
|
|
|
|
if ( !bVerifyPasswordOnly )
|
|
|
|
{
|
|
|
|
uno::Reference< io::XInputStream > xInStream = xSourceStream->getInputStream();
|
|
|
|
if ( !xInStream.is() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2006-11-08 10:54:56 +00:00
|
|
|
throw io::IOException(); // read access denied, seems to be impossible
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2010-06-15 20:02:53 +02:00
|
|
|
Reference< XNameContainer > xLib( pLib );
|
|
|
|
Any aAny = importLibraryElement( xLib,
|
2012-11-03 09:07:25 -05:00
|
|
|
aElementName, aSourceStreamName,
|
|
|
|
xInStream );
|
2006-11-08 10:54:56 +00:00
|
|
|
if( pLib->hasByName( aElementName ) )
|
|
|
|
{
|
|
|
|
if( aAny.hasValue() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2015-07-13 16:17:00 +02:00
|
|
|
pLib->maNameContainer->replaceByName( aElementName, aAny );
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-13 16:17:00 +02:00
|
|
|
pLib->maNameContainer->insertByName( aElementName, aAny );
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-24 11:22:56 +09:00
|
|
|
catch(const uno::Exception& )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
2014-04-04 16:52:44 +02:00
|
|
|
bRet = false;
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
OUString aLibDirPath = createAppLibraryFolder( pLib, Name );
|
|
|
|
|
|
|
|
for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
|
|
|
|
{
|
|
|
|
OUString aElementName = pNames[ i ];
|
|
|
|
|
|
|
|
INetURLObject aElementInetObj( aLibDirPath );
|
2014-01-28 20:03:03 +01:00
|
|
|
aElementInetObj.insertName( aElementName, false,
|
2016-12-05 07:59:20 +02:00
|
|
|
INetURLObject::LAST_SEGMENT, INetURLObject::EncodeMechanism::All );
|
2015-11-06 09:34:39 +01:00
|
|
|
aElementInetObj.setExtension( "pba" );
|
2016-12-05 08:47:18 +02:00
|
|
|
OUString aElementPath = aElementInetObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
|
2006-11-08 10:54:56 +00:00
|
|
|
|
|
|
|
uno::Reference< embed::XStorage > xElementRootStorage;
|
2012-11-03 09:07:25 -05:00
|
|
|
try
|
|
|
|
{
|
2006-11-08 10:54:56 +00:00
|
|
|
xElementRootStorage = ::comphelper::OStorageHelper::GetStorageFromURL(
|
2012-11-03 09:07:25 -05:00
|
|
|
aElementPath,
|
|
|
|
embed::ElementModes::READ );
|
2011-08-24 11:22:56 +09:00
|
|
|
} catch(const uno::Exception& )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
|
|
|
// TODO: error handling
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( xElementRootStorage.is() )
|
|
|
|
{
|
|
|
|
// Load binary
|
|
|
|
if( bLoadBinary )
|
|
|
|
{
|
|
|
|
SbModule* pMod = pBasicLib->FindModule( aElementName );
|
|
|
|
if( !pMod )
|
|
|
|
{
|
2013-09-02 09:03:31 +01:00
|
|
|
pMod = pBasicLib->MakeModule( aElementName, OUString() );
|
2014-03-26 11:18:51 +02:00
|
|
|
pBasicLib->SetModified( false );
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
|
2012-11-03 09:07:25 -05:00
|
|
|
try
|
|
|
|
{
|
2012-06-02 17:46:27 -05:00
|
|
|
OUString aCodeStreamName( "code.bin" );
|
2006-11-08 10:54:56 +00:00
|
|
|
uno::Reference< io::XStream > xCodeStream = xElementRootStorage->openStreamElement(
|
|
|
|
aCodeStreamName,
|
|
|
|
embed::ElementModes::READ );
|
|
|
|
|
2015-09-17 17:10:47 +01:00
|
|
|
std::unique_ptr<SvStream> pStream(::utl::UcbStreamHelper::CreateStream( xCodeStream ));
|
2006-11-08 10:54:56 +00:00
|
|
|
if ( !pStream || pStream->GetError() )
|
|
|
|
{
|
|
|
|
sal_Int32 nError = pStream ? pStream->GetError() : ERRCODE_IO_GENERAL;
|
2013-10-09 19:23:35 +02:00
|
|
|
throw task::ErrorCodeIOException(
|
|
|
|
("utl::UcbStreamHelper::CreateStream failed"
|
|
|
|
" for code.bin: 0x"
|
|
|
|
+ OUString::number(nError, 16)),
|
|
|
|
uno::Reference< uno::XInterface >(),
|
|
|
|
nError);
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
|
2011-01-10 14:40:57 +01:00
|
|
|
/*sal_Bool bRet = */pMod->LoadBinaryData( *pStream );
|
2006-11-08 10:54:56 +00:00
|
|
|
// TODO: Check return value
|
|
|
|
}
|
2011-08-24 11:22:56 +09:00
|
|
|
catch(const uno::Exception& )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
|
|
|
// TODO: error handling
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load source
|
|
|
|
if( bLoadSource || bVerifyPasswordOnly )
|
|
|
|
{
|
|
|
|
// Access encrypted source stream
|
2012-06-02 17:46:27 -05:00
|
|
|
OUString aSourceStreamName( "source.xml" );
|
2012-11-03 09:07:25 -05:00
|
|
|
try
|
|
|
|
{
|
2006-11-08 10:54:56 +00:00
|
|
|
uno::Reference< io::XStream > xSourceStream = xElementRootStorage->openEncryptedStreamElement(
|
|
|
|
aSourceStreamName,
|
|
|
|
embed::ElementModes::READ,
|
|
|
|
pLib->maPassword );
|
|
|
|
if ( !xSourceStream.is() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2017-01-17 22:16:28 +05:30
|
|
|
throw uno::RuntimeException("null returned from openEncryptedStreamElement");
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
if ( !bVerifyPasswordOnly )
|
|
|
|
{
|
|
|
|
uno::Reference< io::XInputStream > xInStream = xSourceStream->getInputStream();
|
|
|
|
if ( !xInStream.is() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2006-11-08 10:54:56 +00:00
|
|
|
throw io::IOException(); // read access denied, seems to be impossible
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2010-06-15 20:02:53 +02:00
|
|
|
Reference< XNameContainer > xLib( pLib );
|
|
|
|
Any aAny = importLibraryElement( xLib,
|
2012-11-03 09:07:25 -05:00
|
|
|
aElementName,
|
|
|
|
aSourceStreamName,
|
|
|
|
xInStream );
|
2006-11-08 10:54:56 +00:00
|
|
|
if( pLib->hasByName( aElementName ) )
|
|
|
|
{
|
|
|
|
if( aAny.hasValue() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2015-07-13 16:17:00 +02:00
|
|
|
pLib->maNameContainer->replaceByName( aElementName, aAny );
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-13 16:17:00 +02:00
|
|
|
pLib->maNameContainer->insertByName( aElementName, aAny );
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-24 11:22:56 +09:00
|
|
|
catch (const uno::Exception& )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
2014-04-04 16:52:44 +02:00
|
|
|
bRet = false;
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-24 11:22:56 +09:00
|
|
|
catch(const Exception& )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
//throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-06 17:54:17 +00:00
|
|
|
void SfxScriptLibraryContainer::onNewRootStorage()
|
2007-01-02 14:41:30 +00:00
|
|
|
{
|
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
|
2012-12-30 13:07:28 -02:00
|
|
|
sal_Bool SAL_CALL SfxScriptLibraryContainer:: HasExecutableCode( const OUString& Library )
|
2010-10-06 10:16:27 +01:00
|
|
|
{
|
|
|
|
BasicManager* pBasicMgr = getBasicManager();
|
2010-10-13 10:51:50 +01:00
|
|
|
OSL_ENSURE( pBasicMgr, "we need a basicmanager, really we do" );
|
2010-10-06 10:16:27 +01:00
|
|
|
if ( pBasicMgr )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2010-10-06 10:16:27 +01:00
|
|
|
return pBasicMgr->HasExeCode( Library ); // need to change this to take name
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2010-10-06 10:16:27 +01:00
|
|
|
// default to it has code if we can't decide
|
2016-04-20 17:14:08 +02:00
|
|
|
return true;
|
2010-10-06 10:16:27 +01:00
|
|
|
}
|
|
|
|
|
2014-02-25 17:41:32 +01:00
|
|
|
|
2006-11-08 10:54:56 +00:00
|
|
|
// Service
|
2012-11-03 09:07:25 -05:00
|
|
|
OUString SAL_CALL SfxScriptLibraryContainer::getImplementationName( )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
2015-02-26 15:34:57 +01:00
|
|
|
return OUString("com.sun.star.comp.sfx2.ScriptLibraryContainer" );
|
2007-03-15 14:39:48 +00:00
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
|
2012-11-03 09:07:25 -05:00
|
|
|
Sequence< OUString > SAL_CALL SfxScriptLibraryContainer::getSupportedServiceNames( )
|
2007-03-15 14:39:48 +00:00
|
|
|
{
|
2016-09-13 13:48:00 +02:00
|
|
|
return {"com.sun.star.script.DocumentScriptLibraryContainer",
|
|
|
|
"com.sun.star.script.ScriptLibraryContainer"}; // for compatibility
|
2006-11-08 10:54:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Implementation class SfxScriptLibrary
|
|
|
|
|
|
|
|
// Ctor
|
2007-03-15 14:39:48 +00:00
|
|
|
SfxScriptLibrary::SfxScriptLibrary( ModifiableHelper& _rModifiable,
|
2012-11-02 17:46:30 +02:00
|
|
|
const Reference< XSimpleFileAccess3 >& xSFI )
|
2015-12-23 09:46:48 +02:00
|
|
|
: SfxLibrary( _rModifiable, cppu::UnoType<OUString>::get(), xSFI )
|
2012-08-21 22:54:26 +09:00
|
|
|
, mbLoadedSource( false )
|
|
|
|
, mbLoadedBinary( false )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-03-15 14:39:48 +00:00
|
|
|
SfxScriptLibrary::SfxScriptLibrary( ModifiableHelper& _rModifiable,
|
2012-11-02 17:46:30 +02:00
|
|
|
const Reference< XSimpleFileAccess3 >& xSFI,
|
2006-11-08 10:54:56 +00:00
|
|
|
const OUString& aLibInfoFileURL,
|
|
|
|
const OUString& aStorageURL,
|
2014-04-04 16:52:44 +02:00
|
|
|
bool ReadOnly )
|
2015-12-23 09:46:48 +02:00
|
|
|
: SfxLibrary( _rModifiable, cppu::UnoType<OUString>::get(), xSFI,
|
2006-11-08 10:54:56 +00:00
|
|
|
aLibInfoFileURL, aStorageURL, ReadOnly)
|
2012-08-21 22:54:26 +09:00
|
|
|
, mbLoadedSource( false )
|
|
|
|
, mbLoadedBinary( false )
|
2006-11-08 10:54:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-05-21 22:26:05 +02:00
|
|
|
bool SfxScriptLibrary::isLoadedStorable()
|
|
|
|
{
|
|
|
|
// note: mbLoadedSource can only be true for password-protected lib!
|
|
|
|
return SfxLibrary::isLoadedStorable() && (!mbPasswordProtected || mbLoadedSource);
|
|
|
|
}
|
|
|
|
|
2007-01-02 14:41:30 +00:00
|
|
|
// Provide modify state including resources
|
2015-04-14 12:44:47 +02:00
|
|
|
bool SfxScriptLibrary::isModified()
|
2007-01-02 14:41:30 +00:00
|
|
|
{
|
|
|
|
return implIsModified(); // No resources
|
|
|
|
}
|
|
|
|
|
2015-04-14 12:44:47 +02:00
|
|
|
void SfxScriptLibrary::storeResources()
|
2007-01-02 14:41:30 +00:00
|
|
|
{
|
|
|
|
// No resources
|
|
|
|
}
|
|
|
|
|
2012-12-30 13:07:28 -02:00
|
|
|
void SfxScriptLibrary::storeResourcesToURL( const OUString& URL,
|
2007-01-02 14:41:30 +00:00
|
|
|
const Reference< task::XInteractionHandler >& Handler )
|
|
|
|
{
|
|
|
|
(void)URL;
|
|
|
|
(void)Handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SfxScriptLibrary::storeResourcesAsURL
|
2012-12-30 13:07:28 -02:00
|
|
|
( const OUString& URL, const OUString& NewName )
|
2007-01-02 14:41:30 +00:00
|
|
|
{
|
|
|
|
(void)URL;
|
|
|
|
(void)NewName;
|
|
|
|
}
|
|
|
|
|
2015-07-20 09:21:24 +02:00
|
|
|
void SfxScriptLibrary::storeResourcesToStorage( const css::uno::Reference
|
|
|
|
< css::embed::XStorage >& xStorage )
|
2007-01-02 14:41:30 +00:00
|
|
|
{
|
|
|
|
// No resources
|
|
|
|
(void)xStorage;
|
|
|
|
}
|
|
|
|
|
2015-03-04 09:28:31 +00:00
|
|
|
bool SfxScriptLibrary::containsValidModule(const Any& rElement)
|
2008-06-06 12:30:11 +00:00
|
|
|
{
|
|
|
|
OUString sModuleText;
|
2015-03-04 09:28:31 +00:00
|
|
|
rElement >>= sModuleText;
|
2011-12-10 13:35:14 -02:00
|
|
|
return ( !sModuleText.isEmpty() );
|
2008-06-06 12:30:11 +00:00
|
|
|
}
|
|
|
|
|
2015-03-04 09:28:31 +00:00
|
|
|
bool SAL_CALL SfxScriptLibrary::isLibraryElementValid(const css::uno::Any& rElement) const
|
2008-06-06 12:30:11 +00:00
|
|
|
{
|
2015-03-04 09:28:31 +00:00
|
|
|
return SfxScriptLibrary::containsValidModule(rElement);
|
2008-06-06 12:30:11 +00:00
|
|
|
}
|
|
|
|
|
2010-03-02 12:39:31 +00:00
|
|
|
IMPLEMENT_FORWARD_XINTERFACE2( SfxScriptLibrary, SfxLibrary, SfxScriptLibrary_BASE );
|
|
|
|
IMPLEMENT_FORWARD_XTYPEPROVIDER2( SfxScriptLibrary, SfxLibrary, SfxScriptLibrary_BASE );
|
|
|
|
|
2012-11-03 09:07:25 -05:00
|
|
|
script::ModuleInfo SAL_CALL SfxScriptLibrary::getModuleInfo( const OUString& ModuleName )
|
2010-03-02 12:39:31 +00:00
|
|
|
{
|
|
|
|
if ( !hasModuleInfo( ModuleName ) )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2010-03-02 12:39:31 +00:00
|
|
|
throw NoSuchElementException();
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2016-02-11 22:07:09 +00:00
|
|
|
return mModuleInfo[ ModuleName ];
|
2010-03-02 12:39:31 +00:00
|
|
|
}
|
|
|
|
|
2012-11-03 09:07:25 -05:00
|
|
|
sal_Bool SAL_CALL SfxScriptLibrary::hasModuleInfo( const OUString& ModuleName )
|
2010-03-02 12:39:31 +00:00
|
|
|
{
|
2014-04-04 16:52:44 +02:00
|
|
|
bool bRes = false;
|
2016-02-11 22:07:09 +00:00
|
|
|
ModuleInfoMap::iterator it = mModuleInfo.find( ModuleName );
|
2010-03-02 12:39:31 +00:00
|
|
|
|
2016-02-11 22:07:09 +00:00
|
|
|
if ( it != mModuleInfo.end() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2014-04-04 16:52:44 +02:00
|
|
|
bRes = true;
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2010-03-02 12:39:31 +00:00
|
|
|
return bRes;
|
|
|
|
}
|
|
|
|
|
2012-11-03 09:07:25 -05:00
|
|
|
void SAL_CALL SfxScriptLibrary::insertModuleInfo( const OUString& ModuleName, const script::ModuleInfo& ModuleInfo )
|
2010-03-02 12:39:31 +00:00
|
|
|
{
|
|
|
|
if ( hasModuleInfo( ModuleName ) )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2010-03-02 12:39:31 +00:00
|
|
|
throw ElementExistException();
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2016-02-11 22:07:09 +00:00
|
|
|
mModuleInfo[ ModuleName ] = ModuleInfo;
|
2010-03-02 12:39:31 +00:00
|
|
|
}
|
|
|
|
|
2012-11-03 09:07:25 -05:00
|
|
|
void SAL_CALL SfxScriptLibrary::removeModuleInfo( const OUString& ModuleName )
|
2010-03-02 12:39:31 +00:00
|
|
|
{
|
|
|
|
// #FIXME add NoSuchElementException to the spec
|
|
|
|
if ( !hasModuleInfo( ModuleName ) )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2010-03-02 12:39:31 +00:00
|
|
|
throw NoSuchElementException();
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2016-02-11 22:07:09 +00:00
|
|
|
mModuleInfo.erase( mModuleInfo.find( ModuleName ) );
|
2010-03-02 12:39:31 +00:00
|
|
|
}
|
|
|
|
|
2015-02-24 14:31:11 +11:00
|
|
|
} // namespace basic
|
2010-03-02 12:39:31 +00:00
|
|
|
|
2014-02-25 17:41:32 +01:00
|
|
|
|
2015-07-20 09:21:24 +02:00
|
|
|
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* SAL_CALL
|
|
|
|
com_sun_star_comp_sfx2_ScriptLibraryContainer_get_implementation(css::uno::XComponentContext*,
|
|
|
|
css::uno::Sequence<css::uno::Any> const &)
|
2015-02-24 14:31:11 +11:00
|
|
|
{
|
|
|
|
return cppu::acquire(new basic::SfxScriptLibraryContainer());
|
|
|
|
}
|
2006-11-08 10:54:56 +00:00
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|