mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-15 00:44:19 +09:00
Merge pull request #11768 from akallabeth/proxy-module-shared
Proxy module static and shared linking support
This commit is contained in:
@@ -40,6 +40,7 @@ include(CXXCompilerFlags)
|
||||
set(SRCS bitmap-filter.cpp)
|
||||
addtargetwithresourcefile(${PROJECT_NAME} FALSE "${PROJECT_VERSION}" SRCS FALSE)
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:BUILD_SHARED_LIBS>)
|
||||
target_link_libraries(${PROJECT_NAME} winpr freerdp)
|
||||
|
||||
installwithrpath(TARGETS ${PROJECT_NAME} DESTINATION ${FREERDP_PROXY_PLUGINDIR})
|
||||
|
||||
@@ -445,16 +445,7 @@ static BOOL filter_server_session_end(proxyPlugin* plugin, proxyData* pdata, voi
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
FREERDP_API BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata)
|
||||
static BOOL int_proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata)
|
||||
{
|
||||
proxyPlugin plugin = {};
|
||||
|
||||
@@ -477,3 +468,26 @@ BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userda
|
||||
|
||||
return plugins_manager->RegisterPlugin(plugins_manager, &plugin);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
#if defined(BUILD_SHARED_LIBS)
|
||||
FREERDP_API BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata);
|
||||
|
||||
BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata)
|
||||
{
|
||||
return int_proxy_module_entry_point(plugins_manager, userdata);
|
||||
}
|
||||
#else
|
||||
FREERDP_API BOOL demo_proxy_module_entry_point(proxyPluginsManager* plugins_manager,
|
||||
void* userdata);
|
||||
BOOL bitmap_filter_proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata)
|
||||
{
|
||||
return int_proxy_module_entry_point(plugins_manager, userdata);
|
||||
}
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -40,6 +40,7 @@ include(CXXCompilerFlags)
|
||||
set(SRCS demo.cpp)
|
||||
addtargetwithresourcefile(${PROJECT_NAME} FALSE "${PROJECT_VERSION}" SRCS FALSE)
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:BUILD_SHARED_LIBS>)
|
||||
target_link_libraries(${PROJECT_NAME} winpr)
|
||||
|
||||
installwithrpath(TARGETS ${PROJECT_NAME} DESTINATION ${FREERDP_PROXY_PLUGINDIR})
|
||||
|
||||
@@ -408,16 +408,7 @@ static BOOL demo_dyn_channel_intercept([[maybe_unused]] proxyPlugin* plugin,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
FREERDP_API BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata)
|
||||
static BOOL int_proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata)
|
||||
{
|
||||
struct demo_custom_data* custom = nullptr;
|
||||
proxyPlugin plugin = {};
|
||||
@@ -467,3 +458,26 @@ BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userda
|
||||
|
||||
return plugins_manager->RegisterPlugin(plugins_manager, &plugin);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
#if defined(BUILD_SHARED_LIBS)
|
||||
FREERDP_API BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata);
|
||||
|
||||
BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata)
|
||||
{
|
||||
return int_proxy_module_entry_point(plugins_manager, userdata);
|
||||
}
|
||||
#else
|
||||
FREERDP_API BOOL demo_proxy_module_entry_point(proxyPluginsManager* plugins_manager,
|
||||
void* userdata);
|
||||
BOOL demo_proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata)
|
||||
{
|
||||
return int_proxy_module_entry_point(plugins_manager, userdata);
|
||||
}
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -39,6 +39,7 @@ include(ProjectCXXStandard)
|
||||
set(SRCS dyn-channel-dump.cpp)
|
||||
addtargetwithresourcefile(${PROJECT_NAME} FALSE "${PROJECT_VERSION}" SRCS FALSE)
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:BUILD_SHARED_LIBS>)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE winpr freerdp freerdp-client freerdp-server freerdp-server-proxy)
|
||||
|
||||
installwithrpath(TARGETS ${PROJECT_NAME} DESTINATION ${FREERDP_PROXY_PLUGINDIR})
|
||||
|
||||
@@ -423,10 +423,7 @@ static BOOL dump_unload(proxyPlugin* plugin)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
extern "C" FREERDP_API BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager,
|
||||
void* userdata);
|
||||
|
||||
BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata)
|
||||
static BOOL int_proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata)
|
||||
{
|
||||
proxyPlugin plugin = {};
|
||||
|
||||
@@ -448,3 +445,26 @@ BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userda
|
||||
|
||||
return plugins_manager->RegisterPlugin(plugins_manager, &plugin);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
#if defined(BUILD_SHARED_LIBS)
|
||||
FREERDP_API BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata);
|
||||
|
||||
BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata)
|
||||
{
|
||||
return int_proxy_module_entry_point(plugins_manager, userdata);
|
||||
}
|
||||
#else
|
||||
FREERDP_API BOOL demo_proxy_module_entry_point(proxyPluginsManager* plugins_manager,
|
||||
void* userdata);
|
||||
BOOL dyn_channel_dump_proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata)
|
||||
{
|
||||
return int_proxy_module_entry_point(plugins_manager, userdata);
|
||||
}
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -479,10 +479,53 @@ void pf_modules_list_loaded_plugins(proxyModule* module)
|
||||
ArrayList_ForEach(module->plugins, pf_modules_print_ArrayList_ForEachFkt);
|
||||
}
|
||||
|
||||
static BOOL pf_modules_load_module(const char* module_path, proxyModule* module, void* userdata)
|
||||
static BOOL pf_modules_load_static_module(const char* module_name, proxyModule* module,
|
||||
void* userdata)
|
||||
{
|
||||
WINPR_ASSERT(module);
|
||||
|
||||
HANDLE handle = LoadLibraryX(NULL);
|
||||
|
||||
if (handle == NULL)
|
||||
{
|
||||
WLog_ERR(TAG, "failed loading static library: %s", module_name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
char name[256] = { 0 };
|
||||
(void)_snprintf(name, sizeof(name), "%s_%s", module_name, MODULE_ENTRY_POINT);
|
||||
for (size_t x = 0; x < strnlen(name, sizeof(name)); x++)
|
||||
{
|
||||
if (name[x] == '-')
|
||||
name[x] = '_';
|
||||
}
|
||||
|
||||
proxyModuleEntryPoint pEntryPoint = GetProcAddressAs(handle, name, proxyModuleEntryPoint);
|
||||
if (!pEntryPoint)
|
||||
{
|
||||
WLog_ERR(TAG, "GetProcAddress failed for static %s (module %s)", name, module_name);
|
||||
goto error;
|
||||
}
|
||||
if (!ArrayList_Append(module->handles, handle))
|
||||
{
|
||||
WLog_ERR(TAG, "ArrayList_Append failed!");
|
||||
goto error;
|
||||
}
|
||||
return pf_modules_add(module, pEntryPoint, userdata);
|
||||
|
||||
error:
|
||||
FreeLibrary(handle);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static BOOL pf_modules_load_module(const char* module_path, const char* module_name,
|
||||
proxyModule* module, void* userdata)
|
||||
{
|
||||
WINPR_ASSERT(module);
|
||||
|
||||
if (pf_modules_load_static_module(module_name, module, userdata))
|
||||
return TRUE;
|
||||
|
||||
HANDLE handle = LoadLibraryX(module_path);
|
||||
|
||||
if (handle == NULL)
|
||||
@@ -585,7 +628,6 @@ proxyModule* pf_modules_new(const char* root_dir, const char** modules, size_t c
|
||||
if (!winpr_PathMakePath(path, NULL))
|
||||
{
|
||||
WLog_ERR(TAG, "error occurred while creating modules directory: %s", root_dir);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -599,7 +641,7 @@ proxyModule* pf_modules_new(const char* root_dir, const char** modules, size_t c
|
||||
(void)_snprintf(name, sizeof(name), "proxy-%s-plugin%s", modules[i],
|
||||
FREERDP_SHARED_LIBRARY_SUFFIX);
|
||||
fullpath = GetCombinedPath(path, name);
|
||||
pf_modules_load_module(fullpath, module, NULL);
|
||||
pf_modules_load_module(fullpath, modules[i], module, NULL);
|
||||
free(fullpath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,17 +142,15 @@ HMODULE LoadLibraryA(LPCSTR lpLibFileName)
|
||||
|
||||
HMODULE LoadLibraryW(LPCWSTR lpLibFileName)
|
||||
{
|
||||
if (!lpLibFileName)
|
||||
return NULL;
|
||||
#if defined(_UWP)
|
||||
return LoadPackagedLibrary(lpLibFileName, 0);
|
||||
#else
|
||||
HMODULE module = NULL;
|
||||
char* name = ConvertWCharToUtf8Alloc(lpLibFileName, NULL);
|
||||
if (!name)
|
||||
return NULL;
|
||||
char* name = NULL;
|
||||
|
||||
module = LoadLibraryA(name);
|
||||
if (lpLibFileName)
|
||||
name = ConvertWCharToUtf8Alloc(lpLibFileName, NULL);
|
||||
|
||||
HMODULE module = LoadLibraryA(name);
|
||||
free(name);
|
||||
return module;
|
||||
#endif
|
||||
@@ -398,15 +396,14 @@ DWORD GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
|
||||
|
||||
HMODULE LoadLibraryX(LPCSTR lpLibFileName)
|
||||
{
|
||||
if (!lpLibFileName)
|
||||
return NULL;
|
||||
|
||||
#if defined(_WIN32)
|
||||
HMODULE hm = NULL;
|
||||
WCHAR* wstr = ConvertUtf8ToWCharAlloc(lpLibFileName, NULL);
|
||||
WCHAR* wstr = NULL;
|
||||
|
||||
if (wstr)
|
||||
hm = LoadLibraryW(wstr);
|
||||
if (lpLibFileName)
|
||||
wstr = ConvertUtf8ToWCharAlloc(lpLibFileName, NULL);
|
||||
|
||||
hm = LoadLibraryW(wstr);
|
||||
free(wstr);
|
||||
return hm;
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user