Commit ad85a23f authored by Simon Morlat's avatar Simon Morlat

fix compilation problem

parent e5235883
......@@ -217,6 +217,8 @@ MS2_PUBLIC void ms_factory_init_plugins(MSFactory *obj);
MS2_PUBLIC void ms_factory_set_plugins_dir(MSFactory *obj, const char *path);
MS2_PUBLIC int ms_factory_load_plugins(MSFactory *factory, const char *dir);
MS2_PUBLIC void ms_factory_uninit_plugins(MSFactory *obj);
MS2_PUBLIC void ms_factory_init_voip(MSFactory *obj);
......
......@@ -276,191 +276,8 @@ MSList *ms_list_copy(const MSList *list){
return copy;
}
#ifndef PLUGINS_EXT
#define PLUGINS_EXT ".so"
#endif
typedef void (*init_func_t)(void);
int ms_load_plugins(const char *dir){
int num=0;
#if defined(WIN32) && !defined(_WIN32_WCE)
WIN32_FIND_DATA FileData;
HANDLE hSearch;
char szDirPath[1024];
#if defined(WINAPI_FAMILY_PHONE_APP) && defined(UNICODE)
wchar_t wszDirPath[1024];
#endif
char szPluginFile[1024];
BOOL fFinished = FALSE;
const char *tmp=getenv("DEBUG");
BOOL debug=(tmp!=NULL && atoi(tmp)==1);
snprintf(szDirPath, sizeof(szDirPath), "%s", dir);
// Start searching for .dll files in the current directory.
#ifdef WINAPI_FAMILY_PHONE_APP
snprintf(szDirPath, sizeof(szDirPath), "%s\\libms*.dll", dir);
#ifdef UNICODE
mbstowcs(wszDirPath, szDirPath, sizeof(wszDirPath));
hSearch = FindFirstFileExW(wszDirPath, FindExInfoStandard, &FileData, FindExSearchNameMatch, NULL, 0);
#else
hSearch = FindFirstFileExA(szDirPath, FindExInfoStandard, &FileData, FindExSearchNameMatch, NULL, 0);
#endif
#else
snprintf(szDirPath, sizeof(szDirPath), "%s\\*.dll", dir);
hSearch = FindFirstFile(szDirPath, &FileData);
#endif
if (hSearch == INVALID_HANDLE_VALUE)
{
ms_message("no plugin (*.dll) found in %s.", szDirPath);
return 0;
}
snprintf(szDirPath, sizeof(szDirPath), "%s", dir);
while (!fFinished)
{
/* load library */
HINSTANCE os_handle;
#ifdef WINAPI_FAMILY_PHONE_APP
wchar_t wszPluginFile[2048];
#ifdef UNICODE
char filename[512];
wcstombs(filename, FileData.cFileName, sizeof(filename));
snprintf(szPluginFile, sizeof(szPluginFile), "%s\\%s", szDirPath, filename);
#else
snprintf(szPluginFile, sizeof(szPluginFile), "%s\\%s", szDirPath, FileData.cFileName);
#endif
mbstowcs(wszPluginFile, szPluginFile, sizeof(wszPluginFile));
os_handle = LoadPackagedLibrary(wszPluginFile, 0);
#else
UINT em=0;
if (!debug) em = SetErrorMode (SEM_FAILCRITICALERRORS);
snprintf(szPluginFile, sizeof(szPluginFile), "%s\\%s", szDirPath, FileData.cFileName);
os_handle = LoadLibraryEx (szPluginFile, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
if (os_handle==NULL)
{
ms_message("Fail to load plugin %s with altered search path: error %i",szPluginFile,(int)GetLastError());
os_handle = LoadLibraryEx (szPluginFile, NULL, 0);
}
if (!debug) SetErrorMode (em);
#endif
if (os_handle==NULL)
ms_error("Fail to load plugin %s: error %i", szPluginFile, (int)GetLastError());
else{
init_func_t initroutine;
char szPluginName[256];
char szMethodName[256];
char *minus;
#if defined(WINAPI_FAMILY_PHONE_APP) && defined(UNICODE)
snprintf(szPluginName, sizeof(szPluginName), "%s", filename);
#else
snprintf(szPluginName, sizeof(szPluginName), "%s", FileData.cFileName);
#endif
/*on mingw, dll names might be libsomething-3.dll. We must skip the -X.dll stuff*/
minus=strchr(szPluginName,'-');
if (minus) *minus='\0';
else szPluginName[strlen(szPluginName)-4]='\0'; /*remove .dll*/
snprintf(szMethodName, sizeof(szMethodName), "%s_init", szPluginName);
initroutine = (init_func_t) GetProcAddress (os_handle, szMethodName);
if (initroutine!=NULL){
initroutine();
ms_message("Plugin loaded (%s)", szPluginFile);
// Add this new loaded plugin to the list (useful for FreeLibrary at the end)
ms_plugins_loaded_list=ms_list_append(ms_plugins_loaded_list,os_handle);
num++;
}else{
ms_warning("Could not locate init routine of plugin %s. Should be %s",
szPluginFile, szMethodName);
}
}
if (!FindNextFile(hSearch, &FileData)) {
if (GetLastError() == ERROR_NO_MORE_FILES){
fFinished = TRUE;
}
else
{
ms_error("couldn't find next plugin dll.");
fFinished = TRUE;
}
}
}
/* Close the search handle. */
FindClose(hSearch);
#elif HAVE_DLOPEN
char plugin_name[64];
DIR *ds;
MSList *loaded_plugins = NULL;
struct dirent *de;
char *ext;
char *fullpath;
ds=opendir(dir);
if (ds==NULL){
ms_message("Cannot open directory %s: %s",dir,strerror(errno));
return -1;
}
while( (de=readdir(ds))!=NULL){
if (
#ifndef __QNX__
(de->d_type==DT_REG || de->d_type==DT_UNKNOWN || de->d_type==DT_LNK) &&
#endif
(ext=strstr(de->d_name,PLUGINS_EXT))!=NULL) {
void *handle;
snprintf(plugin_name, MIN(sizeof(plugin_name), ext - de->d_name + 1), "%s", de->d_name);
if (ms_list_find_custom(loaded_plugins, (MSCompareFunc)strcmp, plugin_name) != NULL) continue;
loaded_plugins = ms_list_append(loaded_plugins, ms_strdup(plugin_name));
fullpath=ms_strdup_printf("%s/%s",dir,de->d_name);
ms_message("Loading plugin %s...",fullpath);
if ( (handle=dlopen(fullpath,RTLD_NOW))==NULL){
ms_warning("Fail to load plugin %s : %s",fullpath,dlerror());
}else {
char *initroutine_name=ms_malloc0(strlen(de->d_name)+10);
char *p;
void *initroutine=NULL;
strcpy(initroutine_name,de->d_name);
p=strstr(initroutine_name,PLUGINS_EXT);
if (p!=NULL){
strcpy(p,"_init");
initroutine=dlsym(handle,initroutine_name);
}
#ifdef __APPLE__
if (initroutine==NULL){
/* on macosx: library name are libxxxx.1.2.3.dylib */
/* -> MUST remove the .1.2.3 */
p=strstr(initroutine_name,".");
if (p!=NULL)
{
strcpy(p,"_init");
initroutine=dlsym(handle,initroutine_name);
}
}
#endif
if (initroutine!=NULL){
init_func_t func=(init_func_t)initroutine;
func();
ms_message("Plugin loaded (%s)", fullpath);
num++;
}else{
ms_warning("Could not locate init routine of plugin %s",de->d_name);
}
ms_free(initroutine_name);
}
ms_free(fullpath);
}
}
ms_list_for_each(loaded_plugins, ms_free);
ms_list_free(loaded_plugins);
closedir(ds);
#else
ms_warning("no loadable plugin support: plugins cannot be loaded.");
num=-1;
#endif
return num;
return ms_factory_load_plugins(ms_factory_get_fallback(),dir);
}
static int ms_plugins_ref=0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment