summaryrefslogtreecommitdiff
path: root/cli_ure/source
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2014-12-02 18:12:54 +0100
committerStephan Bergmann <sbergman@redhat.com>2014-12-03 15:19:55 +0100
commit827430c8c0417396b3c1d2a049ccddb818c89646 (patch)
tree2b249c14dcbfb725469b4dd70c125d00486d2a84 /cli_ure/source
parent1924d05e706e6308b4de3b6103ebb73976866d66 (diff)
Fold URE: Windows
...assuming the delayLoadHook in cli_ure/source/native/native_bootstrap.cxx is no longer necessary and loading of cppuhelper from the program dir cannot fail regardless in whatever scenario the cli_cppuhelper library itself is loaded. Change-Id: I13f32b327bca4cce9780864f5e57cdad3860afe5
Diffstat (limited to 'cli_ure/source')
-rw-r--r--cli_ure/source/native/native_bootstrap.cxx261
-rw-r--r--cli_ure/source/native/path.cxx163
2 files changed, 0 insertions, 424 deletions
diff --git a/cli_ure/source/native/native_bootstrap.cxx b/cli_ure/source/native/native_bootstrap.cxx
index 1e2140278355..2ff980fa776f 100644
--- a/cli_ure/source/native/native_bootstrap.cxx
+++ b/cli_ure/source/native/native_bootstrap.cxx
@@ -25,7 +25,6 @@
#pragma warning(push, 1)
#endif
#include <windows.h>
-#include "uno/environment.hxx"
#ifdef _MSC_VER
#pragma warning(pop)
#endif
@@ -37,271 +36,11 @@
#include "rtl/bootstrap.hxx"
#include "com/sun/star/uno/XComponentContext.hpp"
#include "cppuhelper/bootstrap.hxx"
-#include <delayimp.h>
#include <stdio.h>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
-namespace cli_ure {
- WCHAR * resolveLink(WCHAR * path);
-}
-
-#define INSTALL_PATH L"Software\\LibreOffice\\UNO\\InstallPath"
-#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 occurred
- */
-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 );
- delete[] data;
- 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:/LibreOffice 3/program
- This path is either obtained from the environment variable UNO_PATH
- or the registry item
- "Software\\LibreOffice\\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)
- {
- oneDirUp(szInstallPath);
-
- //build the path to the ure-link file
- szUrePath = new WCHAR[MAX_PATH];
- szUrePath[0] = L'\0';
- lstrcat(szUrePath, szInstallPath);
- 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);
- }
- 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))
- {
- delete[] szLibName;
- return 0;
- }
- }
- HANDLE h = loadFromPath(szLibName);
- delete[] szLibName;
- return (FARPROC) h;
- }
- return 0;
-}
-}
-
-ExternC
-PfnDliHook __pfnDliFailureHook2 = delayLoadHook;
-
namespace uno
{
namespace util
diff --git a/cli_ure/source/native/path.cxx b/cli_ure/source/native/path.cxx
index 97c7f36c58b3..006c70fe36cd 100644
--- a/cli_ure/source/native/path.cxx
+++ b/cli_ure/source/native/path.cxx
@@ -21,8 +21,6 @@
#if defined WNT
-#include <cstddef>
-
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
@@ -43,167 +41,6 @@ SAL_DLLPUBLIC_EXPORT WCHAR * filename(WCHAR * path) {
}
}
-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