2004-04-13 11:07:02 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 03:08:17 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2004-04-13 11:07:02 +00:00
|
|
|
*
|
2008-04-11 03:08:17 +00:00
|
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
2004-04-13 11:07:02 +00:00
|
|
|
*
|
2008-04-11 03:08:17 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2004-04-13 11:07:02 +00:00
|
|
|
*
|
2008-04-11 03:08:17 +00:00
|
|
|
* $RCSfile: dp_misc.cxx,v $
|
2008-07-22 16:15:54 +00:00
|
|
|
* $Revision: 1.20 $
|
2004-04-13 11:07:02 +00:00
|
|
|
*
|
2008-04-11 03:08:17 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2004-04-13 11:07:02 +00:00
|
|
|
*
|
2008-04-11 03:08:17 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2004-04-13 11:07:02 +00:00
|
|
|
*
|
2008-04-11 03:08:17 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2004-04-13 11:07:02 +00:00
|
|
|
*
|
2008-04-11 03:08:17 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2004-04-13 11:07:02 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-17 08:41:35 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_desktop.hxx"
|
|
|
|
|
2004-04-13 11:07:02 +00:00
|
|
|
#include "dp_misc.h"
|
2004-06-11 11:09:03 +00:00
|
|
|
#include "dp_interact.h"
|
2004-04-13 11:07:02 +00:00
|
|
|
#include "rtl/uri.hxx"
|
|
|
|
#include "rtl/digest.h"
|
2004-06-11 11:09:03 +00:00
|
|
|
#include "rtl/random.h"
|
|
|
|
#include "rtl/bootstrap.hxx"
|
2006-09-13 10:51:22 +00:00
|
|
|
#include "unotools/bootstrap.hxx"
|
2004-04-13 11:07:02 +00:00
|
|
|
#include "osl/file.hxx"
|
|
|
|
#include "osl/pipe.hxx"
|
2004-06-11 11:09:03 +00:00
|
|
|
#include "osl/security.hxx"
|
|
|
|
#include "osl/thread.hxx"
|
|
|
|
#include "osl/mutex.hxx"
|
|
|
|
#include "com/sun/star/ucb/CommandAbortedException.hpp"
|
2004-07-23 13:32:58 +00:00
|
|
|
#include "com/sun/star/bridge/UnoUrlResolver.hpp"
|
2004-06-11 11:09:03 +00:00
|
|
|
#include "com/sun/star/bridge/XUnoUrlResolver.hpp"
|
2004-11-09 13:09:07 +00:00
|
|
|
#include "boost/scoped_array.hpp"
|
|
|
|
#include "boost/shared_ptr.hpp"
|
2004-04-13 11:07:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
using namespace ::com::sun::star::uno;
|
2004-11-09 13:09:07 +00:00
|
|
|
using ::rtl::OUString;
|
2004-04-13 11:07:02 +00:00
|
|
|
|
2007-11-01 13:27:39 +00:00
|
|
|
|
|
|
|
#define SOFFICE1 "soffice.exe"
|
|
|
|
#define SOFFICE2 "soffice.bin"
|
|
|
|
#define SBASE "sbase.exe"
|
|
|
|
#define SCALC "scalc.exe"
|
|
|
|
#define SDRAW "sdraw.exe"
|
|
|
|
#define SIMPRESS "simpress.exe"
|
|
|
|
#define SWRITER "swriter.exe"
|
|
|
|
|
2004-08-12 11:08:13 +00:00
|
|
|
namespace dp_misc {
|
2004-11-09 13:09:07 +00:00
|
|
|
namespace {
|
2004-04-13 11:07:02 +00:00
|
|
|
|
2004-12-07 09:52:56 +00:00
|
|
|
struct UnoRc : public rtl::StaticWithInit<
|
|
|
|
const boost::shared_ptr<rtl::Bootstrap>, UnoRc> {
|
|
|
|
const boost::shared_ptr<rtl::Bootstrap> operator () () {
|
2004-11-09 13:09:07 +00:00
|
|
|
OUString unorc( RTL_CONSTASCII_USTRINGPARAM(
|
2008-03-18 12:47:17 +00:00
|
|
|
"$OOO_BASE_DIR/program/" SAL_CONFIGFILE("uno")) );
|
2004-11-09 13:09:07 +00:00
|
|
|
::rtl::Bootstrap::expandMacros( unorc );
|
|
|
|
::boost::shared_ptr< ::rtl::Bootstrap > ret(
|
|
|
|
new ::rtl::Bootstrap( unorc ) );
|
|
|
|
OSL_ASSERT( ret->getHandle() != 0 );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-12-07 09:52:56 +00:00
|
|
|
struct OfficePipeId : public rtl::StaticWithInit<const OUString, OfficePipeId> {
|
|
|
|
const OUString operator () ();
|
2004-11-09 13:09:07 +00:00
|
|
|
};
|
|
|
|
|
2004-12-07 09:52:56 +00:00
|
|
|
const OUString OfficePipeId::operator () ()
|
2004-11-09 13:09:07 +00:00
|
|
|
{
|
2006-09-13 10:51:22 +00:00
|
|
|
OUString userPath;
|
|
|
|
::utl::Bootstrap::PathStatus aLocateResult =
|
|
|
|
::utl::Bootstrap::locateUserInstallation( userPath );
|
|
|
|
if (!(aLocateResult == ::utl::Bootstrap::PATH_EXISTS ||
|
|
|
|
aLocateResult == ::utl::Bootstrap::PATH_VALID))
|
2004-11-09 13:09:07 +00:00
|
|
|
{
|
2006-09-13 10:51:22 +00:00
|
|
|
throw Exception(OUSTR("Extension Manager: Could not obtain path for UserInstallation."), 0);
|
2004-11-09 13:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rtlDigest digest = rtl_digest_create( rtl_Digest_AlgorithmMD5 );
|
|
|
|
if (digest <= 0) {
|
|
|
|
throw RuntimeException(
|
|
|
|
OUSTR("cannot get digest rtl_Digest_AlgorithmMD5!"), 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_uInt8 const * data =
|
|
|
|
reinterpret_cast<sal_uInt8 const *>(userPath.getStr());
|
|
|
|
sal_Size size = (userPath.getLength() * sizeof (sal_Unicode));
|
|
|
|
sal_uInt32 md5_key_len = rtl_digest_queryLength( digest );
|
|
|
|
::boost::scoped_array<sal_uInt8> md5_buf( new sal_uInt8 [ md5_key_len ] );
|
|
|
|
|
|
|
|
rtl_digest_init( digest, data, static_cast<sal_uInt32>(size) );
|
|
|
|
rtl_digest_update( digest, data, static_cast<sal_uInt32>(size) );
|
|
|
|
rtl_digest_get( digest, md5_buf.get(), md5_key_len );
|
|
|
|
rtl_digest_destroy( digest );
|
|
|
|
|
|
|
|
// create hex-value string from the MD5 value to keep
|
|
|
|
// the string size minimal
|
|
|
|
::rtl::OUStringBuffer buf;
|
|
|
|
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("SingleOfficeIPC_") );
|
|
|
|
for ( sal_uInt32 i = 0; i < md5_key_len; ++i ) {
|
|
|
|
buf.append( static_cast<sal_Int32>(md5_buf[ i ]), 0x10 );
|
2004-06-11 11:09:03 +00:00
|
|
|
}
|
2004-11-09 13:09:07 +00:00
|
|
|
return buf.makeStringAndClear();
|
|
|
|
}
|
|
|
|
|
2007-11-01 13:27:39 +00:00
|
|
|
bool existsOfficePipe()
|
|
|
|
{
|
|
|
|
OUString const & pipeId = OfficePipeId::get();
|
|
|
|
if (pipeId.getLength() == 0)
|
|
|
|
return false;
|
|
|
|
::osl::Security sec;
|
|
|
|
::osl::Pipe pipe( pipeId, osl_Pipe_OPEN, sec );
|
|
|
|
return pipe.is();
|
|
|
|
}
|
|
|
|
|
2004-11-09 13:09:07 +00:00
|
|
|
} // anon namespace
|
|
|
|
|
|
|
|
//==============================================================================
|
2004-06-11 11:09:03 +00:00
|
|
|
|
2004-11-09 13:09:07 +00:00
|
|
|
namespace {
|
|
|
|
inline OUString encodeForRcFile( OUString const & str )
|
2004-06-11 11:09:03 +00:00
|
|
|
{
|
2004-11-09 13:09:07 +00:00
|
|
|
// escape $\{} (=> rtl bootstrap files)
|
2004-06-11 11:09:03 +00:00
|
|
|
::rtl::OUStringBuffer buf;
|
2004-11-09 13:09:07 +00:00
|
|
|
sal_Int32 pos = 0;
|
|
|
|
const sal_Int32 len = str.getLength();
|
|
|
|
for ( ; pos < len; ++pos ) {
|
|
|
|
sal_Unicode c = str[ pos ];
|
|
|
|
switch (c) {
|
|
|
|
case '$':
|
|
|
|
case '\\':
|
|
|
|
case '{':
|
|
|
|
case '}':
|
|
|
|
buf.append( static_cast<sal_Unicode>('\\') );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
buf.append( c );
|
2004-06-11 11:09:03 +00:00
|
|
|
}
|
|
|
|
return buf.makeStringAndClear();
|
|
|
|
}
|
2004-11-09 13:09:07 +00:00
|
|
|
}
|
2004-06-11 11:09:03 +00:00
|
|
|
|
|
|
|
//==============================================================================
|
2004-11-09 13:09:07 +00:00
|
|
|
OUString makeURL( OUString const & baseURL, OUString const & relPath_ )
|
2004-04-13 11:07:02 +00:00
|
|
|
{
|
2004-11-09 13:09:07 +00:00
|
|
|
::rtl::OUStringBuffer buf;
|
|
|
|
if (baseURL.getLength() > 1 && baseURL[ baseURL.getLength() - 1 ] == '/')
|
|
|
|
buf.append( baseURL.copy( 0, baseURL.getLength() - 1 ) );
|
|
|
|
else
|
|
|
|
buf.append( baseURL );
|
|
|
|
OUString relPath(relPath_);
|
|
|
|
if (relPath.getLength() > 0 && relPath[ 0 ] == '/')
|
|
|
|
relPath = relPath.copy( 1 );
|
|
|
|
if (relPath.getLength() > 0)
|
|
|
|
{
|
|
|
|
buf.append( static_cast<sal_Unicode>('/') );
|
|
|
|
if (baseURL.matchAsciiL(
|
|
|
|
RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.expand:") )) {
|
|
|
|
// encode for macro expansion: relPath is supposed to have no
|
|
|
|
// macros, so encode $, {} \ (bootstrap mimic)
|
|
|
|
relPath = encodeForRcFile(relPath);
|
|
|
|
|
|
|
|
// encode once more for vnd.sun.star.expand schema:
|
|
|
|
// vnd.sun.star.expand:$UNO_...
|
|
|
|
// will expand to file-url
|
|
|
|
relPath = ::rtl::Uri::encode( relPath, rtl_UriCharClassUric,
|
|
|
|
rtl_UriEncodeIgnoreEscapes,
|
|
|
|
RTL_TEXTENCODING_UTF8 );
|
2004-06-11 11:09:03 +00:00
|
|
|
}
|
2004-11-09 13:09:07 +00:00
|
|
|
buf.append( relPath );
|
|
|
|
}
|
|
|
|
return buf.makeStringAndClear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
OUString expandUnoRcTerm( OUString const & term_ )
|
|
|
|
{
|
|
|
|
OUString term(term_);
|
|
|
|
UnoRc::get()->expandMacrosFrom( term );
|
|
|
|
return term;
|
|
|
|
}
|
2004-06-11 11:09:03 +00:00
|
|
|
|
2004-11-09 13:09:07 +00:00
|
|
|
//==============================================================================
|
|
|
|
OUString expandUnoRcUrl( OUString const & url )
|
|
|
|
{
|
|
|
|
if (url.matchAsciiL( RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.expand:") )) {
|
2004-04-13 11:07:02 +00:00
|
|
|
// cut protocol:
|
2004-11-09 13:09:07 +00:00
|
|
|
OUString rcurl( url.copy( sizeof ("vnd.sun.star.expand:") - 1 ) );
|
2004-04-13 11:07:02 +00:00
|
|
|
// decode uric class chars:
|
2004-11-09 13:09:07 +00:00
|
|
|
rcurl = ::rtl::Uri::decode(
|
|
|
|
rcurl, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
|
2004-04-13 11:07:02 +00:00
|
|
|
// expand macro string:
|
2004-11-09 13:09:07 +00:00
|
|
|
UnoRc::get()->expandMacrosFrom( rcurl );
|
|
|
|
return rcurl;
|
|
|
|
}
|
|
|
|
else {
|
2004-04-13 11:07:02 +00:00
|
|
|
return url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
2004-06-11 11:09:03 +00:00
|
|
|
bool office_is_running()
|
2004-04-13 11:07:02 +00:00
|
|
|
{
|
2007-11-01 13:27:39 +00:00
|
|
|
//We need to check if we run within the office process. Then we must not use the pipe, because
|
|
|
|
//this could cause a deadlock. This is actually a workaround for i82778
|
|
|
|
OUString sFile;
|
|
|
|
oslProcessError err = osl_getExecutableFile(& sFile.pData);
|
|
|
|
bool ret = false;
|
|
|
|
if (osl_Process_E_None == err)
|
|
|
|
{
|
|
|
|
sFile = sFile.copy(sFile.lastIndexOf('/') + 1);
|
|
|
|
if (
|
|
|
|
#if defined UNIX
|
|
|
|
sFile.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(SOFFICE2)))
|
2008-07-22 16:15:54 +00:00
|
|
|
#elif defined WNT || defined OS2
|
2007-11-01 13:27:39 +00:00
|
|
|
//osl_getExecutableFile should deliver "soffice.bin" on windows
|
|
|
|
//even if swriter.exe, scalc.exe etc. was started. This is a bug
|
|
|
|
//in osl_getExecutableFile
|
|
|
|
sFile.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(SOFFICE1)))
|
|
|
|
|| sFile.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(SOFFICE2)))
|
|
|
|
|| sFile.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(SBASE)))
|
|
|
|
|| sFile.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(SCALC)))
|
|
|
|
|| sFile.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(SDRAW)))
|
|
|
|
|| sFile.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(SIMPRESS)))
|
|
|
|
|| sFile.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(SWRITER)))
|
|
|
|
#else
|
|
|
|
#error "Unsupported platform"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
)
|
|
|
|
ret = true;
|
|
|
|
else
|
|
|
|
ret = existsOfficePipe();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OSL_ENSURE(0, "NOT osl_Process_E_None ");
|
|
|
|
//if osl_getExecutable file than we take the risk of creating a pipe
|
|
|
|
ret = existsOfficePipe();
|
|
|
|
}
|
|
|
|
return ret;
|
2004-06-11 11:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
oslProcess raiseProcess(
|
|
|
|
OUString const & appURL, Sequence<OUString> const & args )
|
|
|
|
{
|
|
|
|
::osl::Security sec;
|
|
|
|
oslProcess hProcess = 0;
|
|
|
|
oslProcessError rc = osl_executeProcess(
|
2004-11-09 13:09:07 +00:00
|
|
|
appURL.pData,
|
|
|
|
reinterpret_cast<rtl_uString **>(
|
|
|
|
const_cast<OUString *>(args.getConstArray()) ),
|
|
|
|
args.getLength(),
|
2004-06-11 11:09:03 +00:00
|
|
|
osl_Process_DETACHED,
|
|
|
|
sec.getHandle(),
|
|
|
|
0, // => current working dir
|
|
|
|
0, 0, // => no env vars
|
|
|
|
&hProcess );
|
2004-04-13 11:07:02 +00:00
|
|
|
|
2004-08-12 11:08:13 +00:00
|
|
|
switch (rc) {
|
2004-06-11 11:09:03 +00:00
|
|
|
case osl_Process_E_None:
|
|
|
|
break;
|
|
|
|
case osl_Process_E_NotFound:
|
|
|
|
throw RuntimeException( OUSTR("image not found!"), 0 );
|
|
|
|
case osl_Process_E_TimedOut:
|
|
|
|
throw RuntimeException( OUSTR("timout occured!"), 0 );
|
|
|
|
case osl_Process_E_NoPermission:
|
|
|
|
throw RuntimeException( OUSTR("permission denied!"), 0 );
|
|
|
|
case osl_Process_E_Unknown:
|
|
|
|
throw RuntimeException( OUSTR("unknown error!"), 0 );
|
|
|
|
case osl_Process_E_InvalidError:
|
|
|
|
default:
|
|
|
|
throw RuntimeException( OUSTR("unmapped error!"), 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return hProcess;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
OUString generateRandomPipeId()
|
|
|
|
{
|
|
|
|
// compute some good pipe id:
|
|
|
|
static rtlRandomPool s_hPool = rtl_random_createPool();
|
|
|
|
if (s_hPool == 0)
|
|
|
|
throw RuntimeException( OUSTR("cannot create random pool!?"), 0 );
|
|
|
|
sal_uInt8 bytes[ 32 ];
|
|
|
|
if (rtl_random_getBytes(
|
2004-11-09 13:09:07 +00:00
|
|
|
s_hPool, bytes, ARLEN(bytes) ) != rtl_Random_E_None) {
|
2004-06-11 11:09:03 +00:00
|
|
|
throw RuntimeException( OUSTR("random pool error!?"), 0 );
|
2004-11-09 13:09:07 +00:00
|
|
|
}
|
2004-06-11 11:09:03 +00:00
|
|
|
::rtl::OUStringBuffer buf;
|
2004-11-09 13:09:07 +00:00
|
|
|
for ( sal_uInt32 i = 0; i < ARLEN(bytes); ++i ) {
|
2004-06-11 11:09:03 +00:00
|
|
|
buf.append( static_cast<sal_Int32>(bytes[ i ]), 0x10 );
|
2004-11-09 13:09:07 +00:00
|
|
|
}
|
2004-06-11 11:09:03 +00:00
|
|
|
return buf.makeStringAndClear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
Reference<XInterface> resolveUnoURL(
|
|
|
|
OUString const & connectString,
|
|
|
|
Reference<XComponentContext> const & xLocalContext,
|
|
|
|
AbortChannel * abortChannel )
|
|
|
|
{
|
|
|
|
Reference<bridge::XUnoUrlResolver> xUnoUrlResolver(
|
2004-07-23 13:32:58 +00:00
|
|
|
bridge::UnoUrlResolver::create( xLocalContext ) );
|
2004-06-11 11:09:03 +00:00
|
|
|
|
2004-11-09 13:09:07 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (abortChannel != 0 && abortChannel->isAborted()) {
|
2004-06-11 11:09:03 +00:00
|
|
|
throw ucb::CommandAbortedException(
|
|
|
|
OUSTR("abort!"), Reference<XInterface>() );
|
2004-11-09 13:09:07 +00:00
|
|
|
}
|
2004-08-12 11:08:13 +00:00
|
|
|
try {
|
2004-06-11 11:09:03 +00:00
|
|
|
return xUnoUrlResolver->resolve( connectString );
|
|
|
|
}
|
2004-08-12 11:08:13 +00:00
|
|
|
catch (connection::NoConnectException &) {
|
2004-06-11 11:09:03 +00:00
|
|
|
TimeValue tv = { 0 /* secs */, 500000000 /* nanosecs */ };
|
|
|
|
::osl::Thread::wait( tv );
|
|
|
|
}
|
2004-04-13 11:07:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-26 07:54:46 +00:00
|
|
|
OUString getExtensionDefaultUpdateURL()
|
|
|
|
{
|
|
|
|
::rtl::OUString sUrl(
|
|
|
|
RTL_CONSTASCII_USTRINGPARAM(
|
2008-03-18 12:47:17 +00:00
|
|
|
"${$BRAND_BASE_DIR/program/" SAL_CONFIGFILE("version")
|
2008-06-25 11:22:23 +00:00
|
|
|
":Version:ExtensionUpdateURL}"));
|
2007-07-26 07:54:46 +00:00
|
|
|
::rtl::Bootstrap::expandMacros(sUrl);
|
|
|
|
return sUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-13 11:07:02 +00:00
|
|
|
}
|