diff options
Diffstat (limited to 'cli_ure/source/native')
-rw-r--r-- | cli_ure/source/native/assembly.cxx | 36 | ||||
-rw-r--r-- | cli_ure/source/native/cli_cppuhelper_config | 11 | ||||
-rw-r--r-- | cli_ure/source/native/makefile.mk | 184 | ||||
-rw-r--r-- | cli_ure/source/native/msvc.map | 6 | ||||
-rw-r--r-- | cli_ure/source/native/native_bootstrap.cxx | 433 | ||||
-rw-r--r-- | cli_ure/source/native/native_share.h | 120 | ||||
-rw-r--r-- | cli_ure/source/native/path.cxx | 218 |
7 files changed, 1008 insertions, 0 deletions
diff --git a/cli_ure/source/native/assembly.cxx b/cli_ure/source/native/assembly.cxx new file mode 100644 index 000000000000..c7a979b49f81 --- /dev/null +++ b/cli_ure/source/native/assembly.cxx @@ -0,0 +1,36 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cli_ure.hxx" +#using <mscorlib.dll> + +[assembly:System::Reflection::AssemblyProduct( "CLI-UNO Language Binding" )]; +[assembly:System::Reflection::AssemblyDescription( "CLI-UNO Helper Library" )]; +[assembly:System::Reflection::AssemblyDelaySign(true)]; +[assembly:System::Reflection::AssemblyCompany( "OpenOffice.org" )]; diff --git a/cli_ure/source/native/cli_cppuhelper_config b/cli_ure/source/native/cli_cppuhelper_config new file mode 100644 index 000000000000..627a3a564f27 --- /dev/null +++ b/cli_ure/source/native/cli_cppuhelper_config @@ -0,0 +1,11 @@ +<?xml version="1.0"?> +<configuration> + <runtime> + <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> + <dependentAssembly> + <assemblyIdentity name="cli_cppuhelper" publicKeyToken="ce2cb7e279207b9e"/> + <bindingRedirect oldVersion="CLI_CPPUHELPER_OLD_VERSION" newVersion="CLI_CPPUHELPER_NEW_VERSION" /> + </dependentAssembly> + </assemblyBinding> + </runtime> +</configuration>
\ No newline at end of file diff --git a/cli_ure/source/native/makefile.mk b/cli_ure/source/native/makefile.mk new file mode 100644 index 000000000000..2c8be1a9b5b9 --- /dev/null +++ b/cli_ure/source/native/makefile.mk @@ -0,0 +1,184 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# 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. +# +# 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). +# +# 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. +# +# ************************************************************************/ + + +PRJ = ..$/.. +PRJNAME = cli_ure + +TARGET = cli_cppuhelper +NO_BSYMBOLIC = TRUE +ENABLE_EXCEPTIONS = TRUE +LIBTARGET = NO +USE_DEFFILE = TRUE + +# disable caching to avoid stale objects +# on version changes +CCACHE_DISABLE=TRUE +.EXPORT : CCACHE_DISABLE + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/util$/makefile.pmk + +use_shl_versions= + +.IF "$(BUILD_FOR_CLI)" == "" +#do not even build the cxx files because they contain cli cpp +all: +.ELSE + +.INCLUDE : $(BIN)$/cliureversion.mk + +ASSEMBLY_KEY="$(BIN)$/cliuno.snk" + +ASSEMBLY_ATTRIBUTES = $(MISC)$/assembly_cppuhelper.cxx + +POLICY_ASSEMBLY_FILE=$(BIN)$/$(CLI_CPPUHELPER_POLICY_ASSEMBLY).dll + +ASSEMBLY_KEY_X=$(subst,\,\\ $(ASSEMBLY_KEY)) + + +LINKFLAGS += /delayload:cppuhelper3MSC.dll \ + /delayload:cppu3.dll \ + /delayload:sal3.dll + +UWINAPILIB= + +NO_OFFUH=TRUE +CPPUMAKERFLAGS = +UNOTYPES = \ + com.sun.star.lang.XSingleComponentFactory \ + com.sun.star.loader.CannotActivateFactoryException \ + com.sun.star.container.XHierarchicalNameAccess \ + com.sun.star.registry.CannotRegisterImplementationException \ + com.sun.star.registry.XRegistryKey \ + com.sun.star.registry.XSimpleRegistry + +#loader lock was solved as of VS 2005 (CCNUMVER = 0014..) +# When compiling for CLR, disable "warning C4339: use of undefined type detected +# in CLR meta-data - use of this type may lead to a runtime exception": +.IF "$(CCNUMVER)" >= "001399999999" +CFLAGSCXX += -clr:oldSyntax -AI $(BIN) -wd4339 +.ELSE +CFLAGSCXX += -clr -AI $(BIN) -wd4339 +#see Microsoft Knowledge Base Article - 814472 +LINKFLAGS += -NOENTRY -NODEFAULTLIB:nochkclr.obj -INCLUDE:__DllMainCRTStartup@12 +.ENDIF + +SLOFILES = \ + $(SLO)$/native_bootstrap.obj \ + $(SLO)$/path.obj \ + $(SLO)$/assembly_cppuhelper.obj + + +SHL1OBJS = $(SLOFILES) + +SHL1TARGET = $(TARGET) + +SHL1STDLIBS = \ + $(CPPUHELPERLIB) \ + $(CPPULIB) \ + $(SALLIB) \ + delayimp.lib \ + advapi32.lib \ + mscoree.lib \ + Advapi32.lib + +.IF "$(CCNUMVER)" >= "001399999999" +SHL1STDLIBS += \ + msvcmrt.lib +.ENDIF + +SHL1VERSIONMAP = msvc.map + +SHL1DEF = $(MISC)$/$(SHL1TARGET).def +DEF1NAME = $(SHL1TARGET) + + +.INCLUDE : $(PRJ)$/util$/target.pmk +.INCLUDE : target.mk + +SIGN= $(MISC)$/cppuhelper_is_signed_flag + +ALLTAR: \ + $(POLICY_ASSEMBLY_FILE) \ + $(SIGN) + + + +.IF "$(CCNUMVER)" >= "001399999999" +CFLAGSCXX += -clr:oldSyntax +.ENDIF + +$(ASSEMBLY_ATTRIBUTES) : assembly.cxx $(BIN)$/cliuno.snk $(BIN)$/cliureversion.mk + @echo $(ASSEMBLY_KEY_X) + $(GNUCOPY) -p assembly.cxx $@ + echo \ + '[assembly:System::Reflection::AssemblyVersion( "$(CLI_CPPUHELPER_NEW_VERSION)" )];' \ + >> $(OUT)$/misc$/assembly_cppuhelper.cxx + echo \ + '[assembly:System::Reflection::AssemblyKeyFile($(ASSEMBLY_KEY_X))];' \ + >> $(OUT)$/misc$/assembly_cppuhelper.cxx + + + +#make sure we build cli_cppuhelper after the version changed +$(SHL1OBJS) : $(BIN)$/cli_cppuhelper.config + + + +$(SIGN): $(SHL1TARGETN) + $(WRAPCMD) sn.exe -R $(BIN)$/$(TARGET).dll $(BIN)$/cliuno.snk && $(TOUCH) $@ + +#do not forget to deliver cli_cppuhelper.config. It is NOT embedded in the policy file. +.IF "$(CCNUMVER)" >= "001399999999" +#.NET 2 and higher +# If the x86 switch is ommitted then the system assumes the assembly to be MSIL. +# The policy file is still found when an application tries to load an older +# cli_cppuhelper.dll but the system cannot locate it. It possibly assumes that the +# assembly is also 'MSIL' like its policy file. +$(POLICY_ASSEMBLY_FILE) : $(BIN)$/cli_cppuhelper.config + $(WRAPCMD) AL.exe -out:$@ \ + -version:$(CLI_CPPUHELPER_POLICY_VERSION) \ + -keyfile:$(BIN)$/cliuno.snk \ + -link:$(BIN)$/cli_cppuhelper.config \ + -platform:x86 +.ELSE +#.NET 1.1: platform flag not needed +$(POLICY_ASSEMBLY_FILE) : $(BIN)$/cli_cppuhelper.config + $(WRAPCMD) AL.exe -out:$@ \ + -version:$(CLI_CPPUHELPER_POLICY_VERSION) \ + -keyfile:$(BIN)$/cliuno.snk \ + -link:$(BIN)$/cli_cppuhelper.config +.ENDIF + +#Create the config file that is used with the policy assembly +$(BIN)$/cli_cppuhelper.config: cli_cppuhelper_config $(BIN)$/cliureversion.mk + $(PERL) $(SOLARENV)$/bin$/clipatchconfig.pl \ + $< $@ + +.ENDIF # "$(BUILD_FOR_CLI)" != "" + diff --git a/cli_ure/source/native/msvc.map b/cli_ure/source/native/msvc.map new file mode 100644 index 000000000000..429f750cc2b0 --- /dev/null +++ b/cli_ure/source/native/msvc.map @@ -0,0 +1,6 @@ +UDK_3_0_0 { + global: + + local: + *; +}; diff --git a/cli_ure/source/native/native_bootstrap.cxx b/cli_ure/source/native/native_bootstrap.cxx new file mode 100644 index 000000000000..13be868dc9fd --- /dev/null +++ b/cli_ure/source/native/native_bootstrap.cxx @@ -0,0 +1,433 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// Use UNICODE Windows and C API. +#define _UNICODE +#define UNICODE + +#ifdef _MSC_VER +#pragma warning(push, 1) +#endif +#include <windows.h> +#include "uno/environment.hxx" +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +#include <tchar.h> + +#include "native_share.h" + +#include "rtl/bootstrap.hxx" +#include "com/sun/star/uno/XComponentContext.hpp" +#include "cppuhelper/bootstrap.hxx" +#include <delayimp.h> +#include <stdio.h> + +using namespace ::rtl; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +namespace cli_ure { + WCHAR * resolveLink(WCHAR * path); +} + +#define INSTALL_PATH L"Software\\OpenOffice.org\\UNO\\InstallPath" +#define BASIS_LINK L"\\basis-link" +#define URE_LINK L"\\ure-link" +#define URE_BIN L"\\bin" +#define UNO_PATH L"UNO_PATH" + +namespace +{ + + /* + * Gets the installation path from the Windows Registry for the specified + * registry key. + * + * @param hroot open handle to predefined root registry key + * @param subKeyName name of the subkey to open + * + * @return the installation path or NULL, if no installation was found or + * if an error occured + */ +WCHAR* getPathFromRegistryKey( HKEY hroot, LPCWSTR subKeyName ) +{ + HKEY hkey; + DWORD type; + TCHAR* data = NULL; + DWORD size; + + /* open the specified registry key */ + if ( RegOpenKeyEx( hroot, subKeyName, 0, KEY_READ, &hkey ) != ERROR_SUCCESS ) + { + return NULL; + } + + /* find the type and size of the default value */ + if ( RegQueryValueEx( hkey, NULL, NULL, &type, NULL, &size) != ERROR_SUCCESS ) + { + RegCloseKey( hkey ); + return NULL; + } + + /* get memory to hold the default value */ + data = new WCHAR[size]; + + /* read the default value */ + if ( RegQueryValueEx( hkey, NULL, NULL, &type, (LPBYTE) data, &size ) != ERROR_SUCCESS ) + { + RegCloseKey( hkey ); + return NULL; + } + + /* release registry key handle */ + RegCloseKey( hkey ); + + return data; +} + +/* If the path does not end with '\' the las segment will be removed. + path: C:\a\b + -> C:\a + @param io_path + in/out parameter. The string is not reallocated. Simply a '\0' + will be inserted to shorten the string. +*/ +void oneDirUp(LPTSTR io_path) +{ + WCHAR * pEnd = io_path + lstrlen(io_path) - 1; + while (pEnd > io_path //prevent crashing if provided string does not contain a backslash + && *pEnd != L'\\') + pEnd --; + *pEnd = L'\0'; +} + + +/* Returns the path to the program folder of the brand layer, + for example c:/openoffice.org 3/program + This path is either obtained from the environment variable UNO_PATH + or the registry item + "Software\\OpenOffice.org\\UNO\\InstallPath" + either in HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE + The return value must be freed with delete[] +*/ +WCHAR * getInstallPath() +{ + WCHAR * szInstallPath = NULL; + + DWORD cChars = GetEnvironmentVariable(UNO_PATH, NULL, 0); + if (cChars > 0) + { + szInstallPath = new WCHAR[cChars]; + cChars = GetEnvironmentVariable(UNO_PATH, szInstallPath, cChars); + //If PATH is not set then it is no error + if (cChars == 0) + { + delete[] szInstallPath; + return NULL; + } + } + + if (! szInstallPath) + { + szInstallPath = getPathFromRegistryKey( HKEY_CURRENT_USER, INSTALL_PATH ); + if ( szInstallPath == NULL ) + { + /* read the key's default value from HKEY_LOCAL_MACHINE */ + szInstallPath = getPathFromRegistryKey( HKEY_LOCAL_MACHINE, INSTALL_PATH ); + } + } + return szInstallPath; +} + +/* Returns the path to the URE/bin path, where cppuhelper lib resides. + The returned string must be freed with delete[] +*/ +WCHAR* getUnoPath() +{ + WCHAR * szLinkPath = NULL; + WCHAR * szUrePath = NULL; + WCHAR * szUreBin = NULL; //the return value + + WCHAR * szInstallPath = getInstallPath(); + if (szInstallPath) + { + //build the path tho the basis-link file + oneDirUp(szInstallPath); + int sizeLinkPath = lstrlen(szInstallPath) + lstrlen(INSTALL_PATH) + 1; + if (sizeLinkPath < MAX_PATH) + sizeLinkPath = MAX_PATH; + szLinkPath = new WCHAR[sizeLinkPath]; + szLinkPath[0] = L'\0'; + lstrcat(szLinkPath, szInstallPath); + lstrcat(szLinkPath, BASIS_LINK); + + //get the path to the actual Basis folder + if (cli_ure::resolveLink(szLinkPath)) + { + //build the path to the ure-link file + int sizeUrePath = lstrlen(szLinkPath) + lstrlen(URE_LINK) + 1; + if (sizeUrePath < MAX_PATH) + sizeUrePath = MAX_PATH; + szUrePath = new WCHAR[sizeUrePath]; + szUrePath[0] = L'\0'; + lstrcat(szUrePath, szLinkPath); + lstrcat(szUrePath, URE_LINK); + + //get the path to the actual Ure folder + if (cli_ure::resolveLink(szUrePath)) + { + //build the path to the URE/bin directory + szUreBin = new WCHAR[lstrlen(szUrePath) + lstrlen(URE_BIN) + 1]; + szUreBin[0] = L'\0'; + lstrcat(szUreBin, szUrePath); + lstrcat(szUreBin, URE_BIN); + } + } + } +#if OSL_DEBUG_LEVEL >=2 + if (szUreBin) + { + fwprintf(stdout,L"[cli_cppuhelper]: Path to URE libraries:\n %s \n", szUreBin); + } + else + { + fwprintf(stdout,L"[cli_cppuhelper]: Failed to determine location of URE.\n"); + } +#endif + delete[] szInstallPath; + delete[] szLinkPath; + delete[] szUrePath; + return szUreBin; +} + + +/*We extend the path to contain the Ure/bin folder, + so that components can use osl_loadModule with arguments, such as + "reg3.dll". That is, the arguments are only the library names. +*/ +void extendPath(LPCWSTR szUreBinPath) +{ + if (!szUreBinPath) + return; + + WCHAR * sEnvPath = NULL; + DWORD cChars = GetEnvironmentVariable(L"PATH", sEnvPath, 0); + if (cChars > 0) + { + sEnvPath = new WCHAR[cChars]; + cChars = GetEnvironmentVariable(L"PATH", sEnvPath, cChars); + //If PATH is not set then it is no error + if (cChars == 0 && GetLastError() != ERROR_ENVVAR_NOT_FOUND) + { + delete[] sEnvPath; + return; + } + } + //prepare the new PATH. Add the Ure/bin directory at the front. + //note also adding ';' + WCHAR * sNewPath = new WCHAR[lstrlen(sEnvPath) + lstrlen(szUreBinPath) + 2]; + sNewPath[0] = L'\0'; + lstrcat(sNewPath, szUreBinPath); + if (lstrlen(sEnvPath)) + { + lstrcat(sNewPath, L";"); + lstrcat(sNewPath, sEnvPath); + } + BOOL bSet = SetEnvironmentVariable(L"PATH", sNewPath); + + delete[] sEnvPath; + delete[] sNewPath; +} + + +HMODULE loadFromPath(LPCWSTR sLibName) +{ + if (sLibName == NULL) + return NULL; + + WCHAR * szUreBinPath = getUnoPath(); + if (!szUreBinPath) + return NULL; + + extendPath(szUreBinPath); + + WCHAR* szFullPath = new WCHAR[lstrlen(sLibName) + lstrlen(szUreBinPath) + 2]; + szFullPath[0] = L'\0'; + lstrcat(szFullPath, szUreBinPath); + lstrcat(szFullPath, L"\\"); + lstrcat(szFullPath, sLibName); + HMODULE handle = LoadLibraryEx(szFullPath, NULL, + LOAD_WITH_ALTERED_SEARCH_PATH); + + delete[] szFullPath; + delete[] szUreBinPath; + return handle; +} + +/*Hook for delayed loading of libraries which this library is linked with. + This is a failure hook. That is, it is only called when the loading of + a library failed. It will be called when loading of cppuhelper failed. + Because we extend the PATH to the URE/bin folder while this function is + executed (see extendPath), all other libraries are found. +*/ +extern "C" FARPROC WINAPI delayLoadHook( + unsigned dliNotify, + PDelayLoadInfo pdli + ) +{ + if (dliNotify == dliFailLoadLib) + { + LPWSTR szLibName = NULL; + //Convert the ansi file name to wchar_t* + int size = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, pdli->szDll, -1, NULL, 0); + if (size > 0) + { + szLibName = new WCHAR[size]; + if (! MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, pdli->szDll, -1, szLibName, size)) + { + return 0; + } + } + HANDLE h = loadFromPath(szLibName); + delete[] szLibName; + return (FARPROC) h; + } + return 0; +} +} + +ExternC +PfnDliHook __pfnDliFailureHook2 = delayLoadHook; + +namespace uno +{ +namespace util +{ + +/** Bootstrapping native UNO. + + Bootstrapping requires the existence of many libraries which are contained + in an URE installation. To find and load these libraries the Windows + registry keys HKEY_CURRENT_USER\Software\OpenOffice.org\Layer\URE\1 + and HKEY_LOCAL_MACHINE\Software\OpenOffice.org\Layer\URE\1 are examined. + These contain a named value UREINSTALLLOCATION which holds a path to the URE + installation folder. +*/ +public __sealed __gc class Bootstrap +{ + inline Bootstrap() {} + +public: + + /** Bootstraps the initial component context from a native UNO installation. + + @see cppuhelper/bootstrap.hxx:defaultBootstrap_InitialComponentContext() + */ + static ::unoidl::com::sun::star::uno::XComponentContext * + defaultBootstrap_InitialComponentContext(); + + /** Bootstraps the initial component context from a native UNO installation. + + @param ini_file + a file URL of an ini file, e.g. uno.ini/unorc. (The ini file must + reside next to the cppuhelper library) + @param bootstrap_parameters + bootstrap parameters (maybe null) + + @see cppuhelper/bootstrap.hxx:defaultBootstrap_InitialComponentContext() + */ + static ::unoidl::com::sun::star::uno::XComponentContext * + defaultBootstrap_InitialComponentContext( + ::System::String * ini_file, + ::System::Collections::IDictionaryEnumerator * + bootstrap_parameters ); + + /** Bootstraps the initial component context from a native UNO installation. + + @see cppuhelper/bootstrap.hxx:bootstrap() + */ + static ::unoidl::com::sun::star::uno::XComponentContext * + bootstrap(); +}; + +//______________________________________________________________________________ +::unoidl::com::sun::star::uno::XComponentContext * +Bootstrap::defaultBootstrap_InitialComponentContext( + ::System::String * ini_file, + ::System::Collections::IDictionaryEnumerator * bootstrap_parameters ) +{ + if (0 != bootstrap_parameters) + { + bootstrap_parameters->Reset(); + while (bootstrap_parameters->MoveNext()) + { + OUString key( + String_to_ustring( __try_cast< ::System::String * >( + bootstrap_parameters->get_Key() ) ) ); + OUString value( + String_to_ustring( __try_cast< ::System::String * >( + bootstrap_parameters->get_Value() ) ) ); + + ::rtl::Bootstrap::set( key, value ); + } + } + + // bootstrap native uno + Reference< XComponentContext > xContext; + if (0 == ini_file) + { + xContext = ::cppu::defaultBootstrap_InitialComponentContext(); + } + else + { + xContext = ::cppu::defaultBootstrap_InitialComponentContext( + String_to_ustring( __try_cast< ::System::String * >( ini_file ) ) ); + } + + return __try_cast< ::unoidl::com::sun::star::uno::XComponentContext * >( + to_cli( xContext ) ); +} + +//______________________________________________________________________________ +::unoidl::com::sun::star::uno::XComponentContext * +Bootstrap::defaultBootstrap_InitialComponentContext() +{ + return defaultBootstrap_InitialComponentContext( 0, 0 ); +} + +::unoidl::com::sun::star::uno::XComponentContext * Bootstrap::bootstrap() +{ + Reference<XComponentContext> xContext = ::cppu::bootstrap(); + return __try_cast< ::unoidl::com::sun::star::uno::XComponentContext * >( + to_cli( xContext ) ); + +} + +} +} diff --git a/cli_ure/source/native/native_share.h b/cli_ure/source/native/native_share.h new file mode 100644 index 000000000000..dff079b8d1db --- /dev/null +++ b/cli_ure/source/native/native_share.h @@ -0,0 +1,120 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#using <mscorlib.dll> +#using "cli_ure.dll" +#using "cli_uretypes.dll" + +#include "rtl/ustring.hxx" +#include "uno/mapping.hxx" + +#include <vcclr.h> + +#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) + + +namespace uno +{ +namespace util +{ + +//------------------------------------------------------------------------------ +inline ::System::String * ustring_to_String( ::rtl::OUString const & ustr ) +{ + return new ::System::String( ustr.getStr(), 0, ustr.getLength() ); +} +//------------------------------------------------------------------------------ +inline ::rtl::OUString String_to_ustring( ::System::String * str ) +{ + OSL_ASSERT( sizeof (wchar_t) == sizeof (sal_Unicode) ); + wchar_t const __pin * chars = PtrToStringChars( str ); + return ::rtl::OUString( chars, str->get_Length() ); +} + +template< typename T > +inline ::System::Object * to_cli( + ::com::sun::star::uno::Reference< T > const & x ) +{ + ::com::sun::star::uno::Mapping mapping( + OUSTR(CPPU_CURRENT_LANGUAGE_BINDING_NAME), OUSTR(UNO_LB_CLI) ); + OSL_ASSERT( mapping.is() ); + if (! mapping.is()) + { + throw ::com::sun::star::uno::RuntimeException( + OUSTR("cannot get mapping from C++ to CLI!"), + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XInterface >() ); + } + + intptr_t intptr = + reinterpret_cast< intptr_t >( + mapping.mapInterface( x.get(), ::getCppuType( &x ) ) ); + ::System::Runtime::InteropServices::GCHandle handle( + ::System::Runtime::InteropServices::GCHandle::op_Explicit( intptr ) ); + ::System::Object * ret = handle.get_Target(); + handle.Free(); + return ret; +} + +template< typename T > +inline void to_uno( + ::com::sun::star::uno::Reference< T > * pRet, ::System::Object * x ) +{ + ::com::sun::star::uno::Mapping mapping( + OUSTR(UNO_LB_CLI), OUSTR(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); + OSL_ASSERT( mapping.is() ); + if (! mapping.is()) + { + throw ::com::sun::star::uno::RuntimeException( + OUSTR("cannot get mapping from CLI to C++!"), + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XInterface >() ); + } + + ::System::Runtime::InteropServices::GCHandle handle( + ::System::Runtime::InteropServices::GCHandle::Alloc( x ) ); + T * ret = 0; + mapping.mapInterface( + reinterpret_cast< void ** >( &ret ), + reinterpret_cast< void * >( + ::System::Runtime::InteropServices::GCHandle::op_Explicit( handle ) +#if defined _WIN32 + .ToInt32() +#elif defined _WIN64 + .ToInt64() +#else +#error ERROR: either _WIN64 or _WIN32 must be defined + ERROR: either _WIN64 or _WIN32 must be defined +#endif + ), + ::getCppuType( pRet ) ); + handle.Free(); + pRet->set( ret, SAL_NO_ACQUIRE /* takeover ownership */ ); +} + +} +} diff --git a/cli_ure/source/native/path.cxx b/cli_ure/source/native/path.cxx new file mode 100644 index 000000000000..56b5caf3b299 --- /dev/null +++ b/cli_ure/source/native/path.cxx @@ -0,0 +1,218 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#include "sal/config.h" + +#if defined WNT + +#include <cstddef> + +#define WIN32_LEAN_AND_MEAN +#include <windows.h> + +#include "sal/types.h" +//#include "tools/pathutils.hxx" + +namespace cli_ure { + +WCHAR * filename(WCHAR * path) { + WCHAR * f = path; + for (WCHAR * p = path;;) { + switch (*p++) { + case L'\0': + return f; + case L'\\': + f = p; + break; + } + } +} + +WCHAR * buildPath( + WCHAR * path, WCHAR const * frontBegin, WCHAR const * frontEnd, + WCHAR const * backBegin, std::size_t backLength) +{ + // Remove leading ".." segments in the second path together with matching + // segments in the first path that are neither empty nor "." nor ".." nor + // end in ":" (which is not foolprove, as it can erroneously erase the start + // of a UNC path, but only if the input is bad data): + while (backLength >= 2 && backBegin[0] == L'.' && backBegin[1] == L'.' && + (backLength == 2 || backBegin[2] == L'\\')) + { + if (frontEnd - frontBegin < 2 || frontEnd[-1] != L'\\' || + frontEnd[-2] == L'\\' || frontEnd[-2] == L':' || + (frontEnd[-2] == L'.' && + (frontEnd - frontBegin < 3 || frontEnd[-3] == L'\\' || + (frontEnd[-3] == L'.' && + (frontEnd - frontBegin < 4 || frontEnd[-4] == L'\\'))))) + { + break; + } + WCHAR const * p = frontEnd - 1; + while (p != frontBegin && p[-1] != L'\\') { + --p; + } + if (p == frontBegin) { + break; + } + frontEnd = p; + if (backLength == 2) { + backBegin += 2; + backLength -= 2; + } else { + backBegin += 3; + backLength -= 3; + } + } + if (backLength < + static_cast< std::size_t >(MAX_PATH - (frontEnd - frontBegin))) + // hopefully std::size_t is large enough + { + WCHAR * p; + if (frontBegin == path) { + p = const_cast< WCHAR * >(frontEnd); + } else { + p = path; + while (frontBegin != frontEnd) { + *p++ = *frontBegin++; + } + } + for (; backLength > 0; --backLength) { + *p++ = *backBegin++; + } + *p = L'\0'; + return p; + } else { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + return NULL; + } +} + +WCHAR * resolveLink(WCHAR * path) { + HANDLE h = CreateFileW( + path, FILE_READ_DATA, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); + if (h == INVALID_HANDLE_VALUE) { + return NULL; + } + char p1[MAX_PATH]; + DWORD n; + BOOL ok = ReadFile(h, p1, MAX_PATH, &n, NULL); + CloseHandle(h); + if (!ok) { + return NULL; + } + WCHAR p2[MAX_PATH]; + std::size_t n2 = 0; + bool colon = false; + for (DWORD i = 0; i < n;) { + unsigned char c = static_cast< unsigned char >(p1[i++]); + switch (c) { + case '\0': + SetLastError(ERROR_BAD_PATHNAME); + return NULL; + case '\x0A': + case '\x0D': + if (n2 == MAX_PATH) { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + return NULL; + } + p2[n2] = L'\0'; + break; + case ':': + colon = true; + // fall through + default: + // Convert from UTF-8 to UTF-16: + if (c <= 0x7F) { + p2[n2++] = c; + } else if (c >= 0xC2 && c <= 0xDF && i < n && + static_cast< unsigned char >(p1[i]) >= 0x80 && + static_cast< unsigned char >(p1[i]) <= 0xBF) + { + p2[n2++] = ((c & 0x1F) << 6) | + (static_cast< unsigned char >(p1[i++]) & 0x3F); + } else if (n - i > 1 && + ((c == 0xE0 && + static_cast< unsigned char >(p1[i]) >= 0xA0 && + static_cast< unsigned char >(p1[i]) <= 0xBF) || + ((c >= 0xE1 && c <= 0xEC || c >= 0xEE && c <= 0xEF) && + static_cast< unsigned char >(p1[i]) >= 0x80 && + static_cast< unsigned char >(p1[i]) <= 0xBF) || + (c == 0xED && + static_cast< unsigned char >(p1[i]) >= 0x80 && + static_cast< unsigned char >(p1[i]) <= 0x9F)) && + static_cast< unsigned char >(p1[i + 1]) >= 0x80 && + static_cast< unsigned char >(p1[i + 1]) <= 0xBF) + { + p2[n2++] = ((c & 0x0F) << 12) | + ((static_cast< unsigned char >(p1[i]) & 0x3F) << 6) | + (static_cast< unsigned char >(p1[i + 1]) & 0x3F); + i += 2; + } else if (n - 2 > 1 && + ((c == 0xF0 && + static_cast< unsigned char >(p1[i]) >= 0x90 && + static_cast< unsigned char >(p1[i]) <= 0xBF) || + (c >= 0xF1 && c <= 0xF3 && + static_cast< unsigned char >(p1[i]) >= 0x80 && + static_cast< unsigned char >(p1[i]) <= 0xBF) || + (c == 0xF4 && + static_cast< unsigned char >(p1[i]) >= 0x80 && + static_cast< unsigned char >(p1[i]) <= 0x8F)) && + static_cast< unsigned char >(p1[i + 1]) >= 0x80 && + static_cast< unsigned char >(p1[i + 1]) <= 0xBF && + static_cast< unsigned char >(p1[i + 2]) >= 0x80 && + static_cast< unsigned char >(p1[i + 2]) <= 0xBF) + { + sal_Int32 u = ((c & 0x07) << 18) | + ((static_cast< unsigned char >(p1[i]) & 0x3F) << 12) | + ((static_cast< unsigned char >(p1[i + 1]) & 0x3F) << 6) | + (static_cast< unsigned char >(p1[i + 2]) & 0x3F); + i += 3; + p2[n2++] = static_cast< WCHAR >(((u - 0x10000) >> 10) | 0xD800); + p2[n2++] = static_cast< WCHAR >( + ((u - 0x10000) & 0x3FF) | 0xDC00); + } else { + SetLastError(ERROR_BAD_PATHNAME); + return NULL; + } + break; + } + } + WCHAR * end; + if (colon || p2[0] == L'\\') { + // Interpret p2 as an absolute path: + end = path; + } else { + // Interpret p2 as a relative path: + end = filename(path); + } + return buildPath(path, path, end, p2, n2); +} + +} + +#endif |