2012-11-18 07:03:04 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Addin Loader
|
|
|
|
*
|
|
|
|
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed 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
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/path.h>
|
|
|
|
#include <winpr/library.h>
|
|
|
|
|
|
|
|
#include <freerdp/addin.h>
|
|
|
|
|
|
|
|
|
|
|
|
LPSTR freerdp_get_library_install_path()
|
|
|
|
{
|
|
|
|
LPSTR pszPath;
|
|
|
|
size_t cchPath;
|
|
|
|
size_t cchLibraryPath;
|
|
|
|
size_t cchInstallPrefix;
|
2012-12-20 16:09:33 +04:00
|
|
|
LPCSTR pszLibraryPath = FREERDP_LIBRARY_PATH;
|
|
|
|
LPCSTR pszInstallPrefix = FREERDP_INSTALL_PREFIX;
|
2012-11-18 07:03:04 +04:00
|
|
|
|
2012-12-20 16:09:33 +04:00
|
|
|
cchLibraryPath = strlen(pszLibraryPath);
|
|
|
|
cchInstallPrefix = strlen(pszInstallPrefix);
|
2012-11-18 07:03:04 +04:00
|
|
|
|
|
|
|
cchPath = cchInstallPrefix + cchLibraryPath + 2;
|
|
|
|
pszPath = (LPSTR) malloc(cchPath + 1);
|
|
|
|
|
2012-12-20 16:09:33 +04:00
|
|
|
CopyMemory(pszPath, pszInstallPrefix, cchInstallPrefix);
|
2012-11-18 07:03:04 +04:00
|
|
|
pszPath[cchInstallPrefix] = '\0';
|
|
|
|
|
2012-12-20 16:09:33 +04:00
|
|
|
NativePathCchAppendA(pszPath, cchPath + 1, pszLibraryPath);
|
2012-11-18 07:03:04 +04:00
|
|
|
|
|
|
|
return pszPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
LPSTR freerdp_get_dynamic_addin_install_path()
|
|
|
|
{
|
|
|
|
LPSTR pszPath;
|
|
|
|
size_t cchPath;
|
|
|
|
size_t cchAddinPath;
|
|
|
|
size_t cchInstallPrefix;
|
2012-12-20 16:09:33 +04:00
|
|
|
LPCSTR pszAddinPath = FREERDP_ADDIN_PATH;
|
|
|
|
LPCSTR pszInstallPrefix = FREERDP_INSTALL_PREFIX;
|
2012-11-18 07:03:04 +04:00
|
|
|
|
2012-12-20 16:09:33 +04:00
|
|
|
cchAddinPath = strlen(pszAddinPath);
|
|
|
|
cchInstallPrefix = strlen(pszInstallPrefix);
|
2012-11-18 07:03:04 +04:00
|
|
|
|
|
|
|
cchPath = cchInstallPrefix + cchAddinPath + 2;
|
|
|
|
pszPath = (LPSTR) malloc(cchPath + 1);
|
|
|
|
|
2012-12-20 16:09:33 +04:00
|
|
|
CopyMemory(pszPath, pszInstallPrefix, cchInstallPrefix);
|
2012-11-18 07:03:04 +04:00
|
|
|
pszPath[cchInstallPrefix] = '\0';
|
|
|
|
|
2012-12-20 16:09:33 +04:00
|
|
|
NativePathCchAppendA(pszPath, cchPath + 1, pszAddinPath);
|
2012-11-18 07:03:04 +04:00
|
|
|
|
|
|
|
return pszPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* freerdp_load_dynamic_addin(LPCSTR pszFileName, LPCSTR pszPath, LPCSTR pszEntryName)
|
|
|
|
{
|
|
|
|
void* entry;
|
|
|
|
BOOL bHasExt;
|
|
|
|
PCSTR pszExt;
|
|
|
|
size_t cchExt;
|
|
|
|
HINSTANCE library;
|
|
|
|
size_t cchFileName;
|
|
|
|
LPSTR pszFilePath;
|
|
|
|
size_t cchFilePath;
|
|
|
|
LPSTR pszAddinFile;
|
|
|
|
size_t cchAddinFile;
|
|
|
|
LPSTR pszAddinInstallPath;
|
|
|
|
size_t cchAddinInstallPath;
|
|
|
|
|
|
|
|
entry = NULL;
|
|
|
|
cchExt = 0;
|
|
|
|
bHasExt = TRUE;
|
|
|
|
cchFileName = strlen(pszFileName);
|
|
|
|
|
|
|
|
if (PathCchFindExtensionA(pszFileName, cchFileName + 1, &pszExt) != S_OK)
|
|
|
|
{
|
|
|
|
pszExt = PathGetSharedLibraryExtensionA(PATH_SHARED_LIB_EXT_WITH_DOT);
|
|
|
|
cchExt = strlen(pszExt);
|
|
|
|
bHasExt = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
pszAddinInstallPath = freerdp_get_dynamic_addin_install_path();
|
|
|
|
cchAddinInstallPath = strlen(pszAddinInstallPath);
|
|
|
|
|
|
|
|
cchFilePath = cchAddinInstallPath + cchFileName + 32;
|
|
|
|
pszFilePath = (LPSTR) malloc(cchFilePath + 1);
|
|
|
|
|
|
|
|
if (bHasExt)
|
|
|
|
{
|
|
|
|
pszAddinFile = _strdup(pszFileName);
|
|
|
|
cchAddinFile = strlen(pszAddinFile);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-09-17 13:44:15 +04:00
|
|
|
cchAddinFile = cchFileName + cchExt + 2 + sizeof(CMAKE_SHARED_LIBRARY_PREFIX);
|
2012-11-18 07:03:04 +04:00
|
|
|
pszAddinFile = (LPSTR) malloc(cchAddinFile + 1);
|
2014-09-17 13:44:15 +04:00
|
|
|
sprintf_s(pszAddinFile, cchAddinFile, CMAKE_SHARED_LIBRARY_PREFIX"%s%s", pszFileName, pszExt);
|
2012-11-18 07:03:04 +04:00
|
|
|
cchAddinFile = strlen(pszAddinFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
CopyMemory(pszFilePath, pszAddinInstallPath, cchAddinInstallPath);
|
|
|
|
pszFilePath[cchAddinInstallPath] = '\0';
|
|
|
|
|
|
|
|
NativePathCchAppendA((LPSTR) pszFilePath, cchFilePath + 1, pszAddinFile);
|
|
|
|
|
|
|
|
library = LoadLibraryA(pszFilePath);
|
|
|
|
|
2012-11-19 02:32:18 +04:00
|
|
|
free(pszAddinInstallPath);
|
|
|
|
free(pszAddinFile);
|
|
|
|
free(pszFilePath);
|
|
|
|
|
2012-11-18 07:03:04 +04:00
|
|
|
if (!library)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
entry = GetProcAddress(library, pszEntryName);
|
|
|
|
|
|
|
|
if (entry)
|
|
|
|
return entry;
|
|
|
|
|
2013-08-28 18:22:35 +04:00
|
|
|
FreeLibrary(library);
|
2012-11-18 07:03:04 +04:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* freerdp_load_dynamic_channel_addin_entry(LPCSTR pszName, LPSTR pszSubsystem, LPSTR pszType, DWORD dwFlags)
|
|
|
|
{
|
|
|
|
void* entry;
|
|
|
|
LPSTR pszFileName;
|
2014-09-17 13:44:15 +04:00
|
|
|
size_t cchFileName = sizeof(CMAKE_SHARED_LIBRARY_PREFIX) + 32;
|
2012-11-18 07:03:04 +04:00
|
|
|
LPCSTR pszExtension;
|
2014-09-17 13:44:15 +04:00
|
|
|
LPCSTR pszPrefix = CMAKE_SHARED_LIBRARY_PREFIX;
|
2012-11-18 07:03:04 +04:00
|
|
|
|
|
|
|
pszExtension = PathGetSharedLibraryExtensionA(0);
|
|
|
|
|
|
|
|
if (pszName && pszSubsystem && pszType)
|
|
|
|
{
|
2014-09-17 13:44:15 +04:00
|
|
|
cchFileName += strlen(pszName) + strlen(pszSubsystem) + strlen(pszType) + strlen(pszExtension);
|
2012-11-18 07:03:04 +04:00
|
|
|
pszFileName = (LPSTR) malloc(cchFileName);
|
2014-09-17 13:44:15 +04:00
|
|
|
sprintf_s(pszFileName, cchFileName, "%s%s-client-%s-%s.%s", pszPrefix, pszName, pszSubsystem, pszType, pszExtension);
|
2012-11-18 07:03:04 +04:00
|
|
|
cchFileName = strlen(pszFileName);
|
|
|
|
}
|
|
|
|
else if (pszName && pszSubsystem)
|
|
|
|
{
|
2014-09-17 13:44:15 +04:00
|
|
|
cchFileName += strlen(pszName) + strlen(pszSubsystem) + strlen(pszExtension);
|
2012-11-18 07:03:04 +04:00
|
|
|
pszFileName = (LPSTR) malloc(cchFileName);
|
2014-09-17 13:44:15 +04:00
|
|
|
sprintf_s(pszFileName, cchFileName, "%s%s-client-%s.%s", pszPrefix, pszName, pszSubsystem, pszExtension);
|
2012-11-18 07:03:04 +04:00
|
|
|
cchFileName = strlen(pszFileName);
|
|
|
|
}
|
|
|
|
else if (pszName)
|
|
|
|
{
|
2014-09-17 13:44:15 +04:00
|
|
|
cchFileName += strlen(pszName) + strlen(pszExtension);
|
2012-11-18 07:03:04 +04:00
|
|
|
pszFileName = (LPSTR) malloc(cchFileName);
|
2014-09-17 13:44:15 +04:00
|
|
|
sprintf_s(pszFileName, cchFileName, "%s%s-client.%s", pszPrefix, pszName, pszExtension);
|
2012-11-18 07:03:04 +04:00
|
|
|
cchFileName = strlen(pszFileName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pszSubsystem)
|
|
|
|
{
|
|
|
|
LPSTR pszEntryName;
|
|
|
|
size_t cchEntryName;
|
|
|
|
|
|
|
|
/* subsystem add-in */
|
|
|
|
|
|
|
|
cchEntryName = 64 + strlen(pszName);
|
|
|
|
pszEntryName = (LPSTR) malloc(cchEntryName + 1);
|
|
|
|
sprintf_s(pszEntryName, cchEntryName + 1, "freerdp_%s_client_subsystem_entry", pszName);
|
|
|
|
|
|
|
|
entry = freerdp_load_dynamic_addin(pszFileName, NULL, pszEntryName);
|
|
|
|
|
2012-11-19 22:26:56 +04:00
|
|
|
free(pszEntryName);
|
|
|
|
free(pszFileName);
|
|
|
|
|
2012-11-18 07:03:04 +04:00
|
|
|
if (entry)
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* channel add-in */
|
|
|
|
|
|
|
|
if (dwFlags & FREERDP_ADDIN_CHANNEL_STATIC)
|
|
|
|
entry = freerdp_load_dynamic_addin(pszFileName, NULL, "VirtualChannelEntry");
|
|
|
|
else if (dwFlags & FREERDP_ADDIN_CHANNEL_DYNAMIC)
|
|
|
|
entry = freerdp_load_dynamic_addin(pszFileName, NULL, "DVCPluginEntry");
|
|
|
|
else if (dwFlags & FREERDP_ADDIN_CHANNEL_DEVICE)
|
|
|
|
entry = freerdp_load_dynamic_addin(pszFileName, NULL, "DeviceServiceEntry");
|
|
|
|
else
|
|
|
|
entry = freerdp_load_dynamic_addin(pszFileName, NULL, pszType);
|
|
|
|
|
2012-11-19 22:26:56 +04:00
|
|
|
free(pszFileName);
|
|
|
|
|
2012-11-18 07:03:04 +04:00
|
|
|
if (entry)
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static FREERDP_LOAD_CHANNEL_ADDIN_ENTRY_FN freerdp_load_static_channel_addin_entry = NULL;
|
|
|
|
|
|
|
|
int freerdp_register_addin_provider(FREERDP_LOAD_CHANNEL_ADDIN_ENTRY_FN provider, DWORD dwFlags)
|
|
|
|
{
|
|
|
|
freerdp_load_static_channel_addin_entry = provider;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* freerdp_load_channel_addin_entry(LPCSTR pszName, LPSTR pszSubsystem, LPSTR pszType, DWORD dwFlags)
|
|
|
|
{
|
|
|
|
void* entry = NULL;
|
|
|
|
|
|
|
|
if (freerdp_load_static_channel_addin_entry)
|
|
|
|
entry = freerdp_load_static_channel_addin_entry(pszName, pszSubsystem, pszType, dwFlags);
|
|
|
|
|
|
|
|
if (!entry)
|
|
|
|
entry = freerdp_load_dynamic_channel_addin_entry(pszName, pszSubsystem, pszType, dwFlags);
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|