Added
Link Here
|
1 |
/************************************************************************* |
2 |
* |
3 |
* OpenOffice.org - a multi-platform office productivity suite |
4 |
* |
5 |
* $RCSfile: speed-splash-ipc-name.diff,v $ |
6 |
* |
7 |
* $Revision: 1.5 $ |
8 |
* |
9 |
* last change: $Author: noelpwer $ $Date: 2006/01/19 09:36:18 $ |
10 |
* |
11 |
* The Contents of this file are made available subject to |
12 |
* the terms of GNU Lesser General Public License Version 2.1. |
13 |
* |
14 |
* |
15 |
* GNU Lesser General Public License Version 2.1 |
16 |
* ============================================= |
17 |
* Copyright 2005 by Sun Microsystems, Inc. |
18 |
* 901 San Antonio Road, Palo Alto, CA 94303, USA |
19 |
* |
20 |
* This library is free software; you can redistribute it and/or |
21 |
* modify it under the terms of the GNU Lesser General Public |
22 |
* License version 2.1, as published by the Free Software Foundation. |
23 |
* |
24 |
* This library is distributed in the hope that it will be useful, |
25 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
26 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
27 |
* Lesser General Public License for more details. |
28 |
* |
29 |
* You should have received a copy of the GNU Lesser General Public |
30 |
* License along with this library; if not, write to the Free Software |
31 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
32 |
* MA 02111-1307 USA |
33 |
* |
34 |
************************************************************************/ |
35 |
|
36 |
#ifndef _OFFICEPIPEHELPER_HXX_ |
37 |
#define _OFFICEPIPEHELPER_HXX_ |
38 |
#include <rtl/instance.hxx> |
39 |
#include <rtl/ustrbuf.hxx> |
40 |
#include <rtl/digest.h> |
41 |
#include <rtl/random.h> |
42 |
#include <rtl/bootstrap.hxx> |
43 |
#include <osl/file.hxx> |
44 |
#include <osl/pipe.hxx> |
45 |
#include <osl/security.hxx> |
46 |
#include <osl/thread.hxx> |
47 |
#include <osl/mutex.hxx> |
48 |
#include <vos/process.hxx> |
49 |
#include <com/sun/star/uno/RuntimeException.hpp> |
50 |
#include <string.h> |
51 |
namespace desktop |
52 |
{ |
53 |
|
54 |
class OfficePipeNameData |
55 |
{ |
56 |
friend class OfficePipeHelper; |
57 |
::rtl::OUString sPipePostName; |
58 |
::rtl::OUString sPipePrefix; |
59 |
public: |
60 |
const ::rtl::OUString& PipeNamePrefix() const { return sPipePrefix; } |
61 |
const ::rtl::OUString& PipeNamePostfix() const { return sPipePostName; } |
62 |
const ::rtl::OUString PipeName() const { return sPipePrefix + sPipePostName; } |
63 |
}; |
64 |
|
65 |
struct OfficePipeHelper : public rtl::StaticWithInit<const OfficePipeNameData, OfficePipeHelper> { |
66 |
const OfficePipeNameData operator () (); |
67 |
}; |
68 |
|
69 |
const OfficePipeNameData OfficePipeHelper::operator () () |
70 |
{ |
71 |
OfficePipeNameData aData; |
72 |
aData.sPipePrefix = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SingleOfficeIPC_") ); |
73 |
rtl::OUString userPath(RTL_CONSTASCII_USTRINGPARAM("${$SYSBINDIR/" SAL_CONFIGFILE("bootstrap") |
74 |
":UserInstallation}") ); |
75 |
::rtl::Bootstrap::expandMacros( userPath ); |
76 |
OSL_ASSERT( userPath.getLength() > 0 ); |
77 |
|
78 |
// normalize path: |
79 |
::osl::FileStatus status( FileStatusMask_FileURL ); |
80 |
::osl::DirectoryItem dirItem; |
81 |
if (::osl::DirectoryItem::get( userPath, dirItem ) |
82 |
!= ::osl::DirectoryItem::E_None || |
83 |
dirItem.getFileStatus( status ) |
84 |
!= ::osl::DirectoryItem::E_None || |
85 |
!status.isValid( FileStatusMask_FileURL ) || |
86 |
::osl::FileBase::getAbsoluteFileURL( |
87 |
rtl::OUString(), status.getFileURL(), userPath ) |
88 |
!= ::osl::FileBase::E_None) |
89 |
{ |
90 |
throw com::sun::star::uno::RuntimeException( |
91 |
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("No valid file URL in " SAL_CONFIGFILE("bootstrap") ": ") ) + |
92 |
userPath, com::sun::star::uno::Reference<com::sun::star::uno::XInterface>() ); |
93 |
} |
94 |
::rtl::OUStringBuffer buf; |
95 |
#ifdef UNX |
96 |
::vos::OStartupInfo aInfo; |
97 |
rtl::OUString aPath; |
98 |
aInfo.getExecutableFile( aPath ); |
99 |
sal_Int32 lastIndex = aPath.lastIndexOf('/'); |
100 |
if ( lastIndex > 0 ) |
101 |
aPath = aPath.copy( 0, lastIndex+1 ); |
102 |
|
103 |
osl::File::getSystemPathFromFileURL( aPath, userPath); |
104 |
|
105 |
/* Quick and simple to replicate hash */ |
106 |
sal_uInt32 nHash = 0; |
107 |
if (userPath.getLength() > 0) |
108 |
{ |
109 |
rtl::OString aUTF8 = rtl::OUStringToOString( userPath, |
110 |
RTL_TEXTENCODING_UTF8 ); |
111 |
const sal_Char *pStr = aUTF8; |
112 |
nHash = *pStr; |
113 |
for (sal_Int32 i = 1; i < aUTF8.getLength(); i++) |
114 |
nHash = (nHash << 5) - nHash + pStr[i]; |
115 |
} |
116 |
sal_Char szBuffer[128]; |
117 |
sprintf( szBuffer, "%d-%x", SUPD, nHash ); |
118 |
buf.append( rtl::OUString( szBuffer, strlen(szBuffer), osl_getThreadTextEncoding() ) ); |
119 |
#else |
120 |
|
121 |
rtlDigest digest = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); |
122 |
if (digest <= 0) { |
123 |
throw RuntimeException( |
124 |
OUSTR("cannot get digest rtl_Digest_AlgorithmMD5!"), 0 ); |
125 |
} |
126 |
|
127 |
sal_uInt8 const * data = |
128 |
reinterpret_cast<sal_uInt8 const *>(userPath.getStr()); |
129 |
sal_Size size = (userPath.getLength() * sizeof (sal_Unicode)); |
130 |
sal_uInt32 md5_key_len = rtl_digest_queryLength( digest ); |
131 |
::boost::scoped_array<sal_uInt8> md5_buf( new sal_uInt8 [ md5_key_len ] ); |
132 |
|
133 |
rtl_digest_init( digest, data, static_cast<sal_uInt32>(size) ); |
134 |
rtl_digest_update( digest, data, static_cast<sal_uInt32>(size) ); |
135 |
rtl_digest_get( digest, md5_buf.get(), md5_key_len ); |
136 |
rtl_digest_destroy( digest ); |
137 |
|
138 |
// create hex-value string from the MD5 value to keep |
139 |
// the string size minimal |
140 |
for ( sal_uInt32 i = 0; i < md5_key_len; ++i ) { |
141 |
buf.append( static_cast<sal_Int32>(md5_buf[ i ]), 0x10 ); |
142 |
} |
143 |
#endif |
144 |
aData.sPipePostName = buf.makeStringAndClear(); |
145 |
return aData; |
146 |
} |
147 |
|
148 |
|
149 |
} // namespace desktop |
150 |
|
151 |
#endif // _OFFICEPIPEHELPER_HXX |