mirror of https://github.com/FreeRDP/FreeRDP
libfreerdp-utils: add load_plugin module.
This commit is contained in:
parent
da06a26f23
commit
3a9c774979
|
@ -56,6 +56,9 @@ test_big_endian(BIG_ENDIAN)
|
|||
# Path to put keymaps
|
||||
set(FREERDP_KEYMAP_PATH "${CMAKE_INSTALL_PREFIX}/freerdp/keymaps")
|
||||
|
||||
# Path to put plugins
|
||||
set(FREERDP_PLUGIN_PATH "${CMAKE_INSTALL_PREFIX}/lib/freerdp")
|
||||
|
||||
# Include directories
|
||||
include_directories(${CMAKE_SOURCE_DIR})
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include)
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Client
|
||||
* Plugin Loading Utils
|
||||
*
|
||||
* Copyright 2011 Vic Lee
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __LOAD_PLUGIN_UTILS_H
|
||||
#define __LOAD_PLUGIN_UTILS_H
|
||||
|
||||
void* freerdp_load_plugin(const char* name, const char* entry_name);
|
||||
|
||||
#endif /* __LOAD_PLUGIN_UTILS_H */
|
|
@ -20,12 +20,15 @@
|
|||
set(FREERDP_UTILS_SRCS
|
||||
blob.c
|
||||
hexdump.c
|
||||
load_plugin.c
|
||||
memory.c
|
||||
mutex.c
|
||||
semaphore.c
|
||||
stream.c
|
||||
unicode.c)
|
||||
|
||||
add_definitions(-DPLUGIN_PATH="${FREERDP_PLUGIN_PATH}")
|
||||
|
||||
add_library(freerdp-utils SHARED ${FREERDP_UTILS_SRCS})
|
||||
|
||||
set_target_properties(freerdp-utils PROPERTIES VERSION ${FREERDP_VERSION_FULL} SOVERSION ${FREERDP_VERSION})
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Client
|
||||
* Plugin Loading Utils
|
||||
*
|
||||
* Copyright 2011 Vic Lee
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <freerdp/utils/load_plugin.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <windows.h>
|
||||
#define DLOPEN(f) LoadLibrary(f)
|
||||
#define DLSYM(f, n) GetProcAddress(f, n)
|
||||
#define DLCLOSE(f) FreeLibrary(f)
|
||||
#define PATH_SEPARATOR '\\'
|
||||
#define PLUGIN_EXT "dll"
|
||||
|
||||
#else
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <unistd.h>
|
||||
#define DLOPEN(f) dlopen(f, RTLD_LOCAL | RTLD_LAZY)
|
||||
#define DLSYM(f, n) dlsym(f, n)
|
||||
#define DLCLOSE(f) dlclose(f)
|
||||
#define PATH_SEPARATOR '/'
|
||||
#define PLUGIN_EXT "so"
|
||||
|
||||
#endif
|
||||
|
||||
void* freerdp_load_plugin(const char* name, const char* entry_name)
|
||||
{
|
||||
char path[255];
|
||||
void* module;
|
||||
void* entry;
|
||||
|
||||
if (strchr(name, PATH_SEPARATOR) == NULL)
|
||||
{
|
||||
snprintf(path, sizeof(path), PLUGIN_PATH "%c%s." PLUGIN_EXT, PATH_SEPARATOR, name);
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(path, name, sizeof(path));
|
||||
}
|
||||
|
||||
module = DLOPEN(path);
|
||||
if (module == NULL)
|
||||
{
|
||||
printf("freerdp_load_plugin: failed to open %s.\n", path);
|
||||
return NULL;
|
||||
}
|
||||
entry = DLSYM(module, entry_name);
|
||||
if (entry == NULL)
|
||||
{
|
||||
printf("freerdp_load_plugin: failed to load %s.\n", path);
|
||||
return NULL;
|
||||
}
|
||||
return entry;
|
||||
}
|
Loading…
Reference in New Issue