2 * FreeRDP: A Remote Desktop Protocol Client
5 * Copyright 2011 Vic Lee
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
23 #include <freerdp/utils/file.h>
24 #include <freerdp/utils/print.h>
25 #include <freerdp/utils/memory.h>
26 #include <freerdp/utils/load_plugin.h>
31 #define DLOPEN(f) LoadLibraryA(f)
32 #define DLSYM(f, n) GetProcAddress(f, n)
33 #define DLCLOSE(f) FreeLibrary(f)
40 #define DLOPEN(f) dlopen(f, RTLD_LOCAL | RTLD_LAZY)
41 #define DLSYM(f, n) dlsym(f, n)
42 #define DLCLOSE(f) dlclose(f)
43 #define DLERROR() dlerror()
47 void* freerdp_open_library(const char* file)
51 library = DLOPEN(file);
55 printf("freerdp_load_library: failed to open %s: %s\n", file, DLERROR());
62 void* freerdp_get_library_symbol(void* library, const char* name)
66 symbol = DLSYM(library, name);
70 printf("freerdp_get_library_symbol: failed to load %s: %s\n", name, DLERROR());
77 boolean freerdp_close_library(void* library)
81 status = DLCLOSE(library);
89 printf("freerdp_free_library: failed to close: %s\n", DLERROR());
96 void* freerdp_load_library_symbol(const char* file, const char* name)
101 library = DLOPEN(file);
105 printf("freerdp_load_library_symbol: failed to open %s: %s\n", file, DLERROR());
109 symbol = DLSYM(library, name);
113 printf("freerdp_load_library_symbol: failed to load %s: %s\n", file, DLERROR());
120 void* freerdp_load_plugin(const char* name, const char* entry_name)
126 suffixed_name = freerdp_append_shared_library_suffix((char*) name);
128 if (!freerdp_path_contains_separator(suffixed_name))
130 /* no explicit path given, use default path */
131 path = freerdp_construct_path(PLUGIN_PATH, suffixed_name);
135 /* explicit path given, use it instead of default path */
136 path = xstrdup(suffixed_name);
139 entry = freerdp_load_library_symbol(path, entry_name);
141 xfree(suffixed_name);
146 printf("freerdp_load_plugin: failed to load %s/%s\n", name, entry_name);
153 void* freerdp_load_channel_plugin(rdpSettings* settings, const char* name, const char* entry_name)
159 suffixed_name = freerdp_append_shared_library_suffix((char*) name);
161 if (!freerdp_path_contains_separator(suffixed_name))
163 /* no explicit path given, use default path */
165 if (!settings->development_mode)
167 path = freerdp_construct_path(PLUGIN_PATH, suffixed_name);
174 char* channel_subpath;
176 dot = strrchr(suffixed_name, '.');
177 plugin_name = xmalloc((dot - suffixed_name) + 1);
178 strncpy(plugin_name, suffixed_name, (dot - suffixed_name));
179 plugin_name[(dot - suffixed_name)] = '\0';
181 channels_path = freerdp_construct_path(settings->development_path, "channels");
182 channel_subpath = freerdp_construct_path(channels_path, plugin_name);
184 path = freerdp_construct_path(channel_subpath, suffixed_name);
187 xfree(channels_path);
188 xfree(channel_subpath);
193 /* explicit path given, use it instead of default path */
194 path = xstrdup(suffixed_name);
197 entry = freerdp_load_library_symbol(path, entry_name);
199 xfree(suffixed_name);
204 printf("freerdp_load_channel_plugin: failed to load %s/%s\n", name, entry_name);