bool Plugin::loadPlugin(const std::string name, const std::string file) { LIBRARY_HANDLE lhandle = NULL; void (*fhandle)(mineserver_pointer_struct*) = NULL; if (!file.empty()) { LOG(INFO, "Plugin", "Loading plugin `" + name + "' (`" + file + "')..."); struct stat st; int statr = stat(file.c_str(), &st); if ((statr == 0) && !(st.st_mode & S_IFDIR)) { lhandle = LIBRARY_LOAD(file.c_str()); } else { LOG(INFO, "Plugin", "Could not find `" + file + "', trying `" + file + LIBRARY_EXTENSION + "'."); statr = stat((file + LIBRARY_EXTENSION).c_str(), &st); if ((statr == 0) && !(st.st_mode & S_IFDIR)) { lhandle = LIBRARY_LOAD((file + LIBRARY_EXTENSION).c_str()); } else { LOG(INFO, "Plugin", "Could not find `" + file + LIBRARY_EXTENSION + "'!"); return false; } } } else { LOG(INFO, "Plugin", "Loading plugin `" + name + "' (built in)..."); lhandle = LIBRARY_SELF(); } if (lhandle == NULL) { LOG(INFO, "Plugin", "Could not load plugin `" + name + "'!"); LOG(INFO, "Plugin", LIBRARY_ERROR()); return false; } m_libraryHandles[name] = lhandle; fhandle = (void (*)(mineserver_pointer_struct*)) LIBRARY_SYMBOL(lhandle, (name + "_init").c_str()); if (fhandle == NULL) { LOG(INFO, "Plugin", "Could not get init function handle!"); unloadPlugin(name); return false; } fhandle(&plugin_api_pointers); return true; }
bool Plugin::loadExternal(const std::string name, const std::string file) { LIBRARY_HANDLE lhandle = NULL; void (*fhandle)(Mineserver*) = NULL; Mineserver::get()->screen()->log("Loading plugin "+name+" ("+file+")..."); struct stat st; if(stat(file.c_str(), &st) != 0) { Mineserver::get()->screen()->log("Could not find "+file+"!"); return false; } lhandle = LIBRARY_LOAD(file.c_str()); if (lhandle == NULL) { Mineserver::get()->screen()->log("Could not load "+file+"!"); Mineserver::get()->screen()->log(LIBRARY_ERROR()); return false; } m_libraryHandles[name] = lhandle; fhandle = (void (*)(Mineserver*)) LIBRARY_SYMBOL(lhandle, (name+"_init").c_str()); if (fhandle == NULL) { Mineserver::get()->screen()->log("Could not get init function handle!"); unloadExternal(name); return false; } fhandle(Mineserver::get()); return true; }
bool Plugin::loadPlugin(const std::string& name, const std::string& path, std::string alias) { LIBRARY_HANDLE lhandle = NULL; pfms fhandle = NULL; if (name.empty() || (name.find('/') != std::string::npos) || (name.find('\\') != std::string::npos)) { LOG(INFO, "Plugin", "Invalid name: " + name); return false; } if (alias.empty()) { alias = name; } if (!path.empty()) { std::string file; file = path + '/' + name + LIBRARY_EXTENSION; struct stat st; int statr = stat(file.c_str(), &st); if ((statr == 0) && !(st.st_mode & S_IFDIR)) { LOG(INFO, "Plugin", "Loading: " + file); lhandle = LIBRARY_LOAD(file.c_str()); } else { LOG(INFO, "Plugin", "Could not find: " + file); return false; } } else { LOG(INFO, "Plugin", "Loading built-in: " + name); lhandle = LIBRARY_SELF(); } if (lhandle == NULL) { LOG(INFO, "Plugin", "Could not load: " + name); LOG(INFO, "Plugin", LIBRARY_ERROR()); return false; } m_libraryHandles[alias] = lhandle; *reinterpret_cast<void**>(&fhandle) = (void*)LIBRARY_SYMBOL(lhandle, (name + "_init").c_str()); if (fhandle == NULL) { LOG(INFO, "Plugin", "Could not get init function handle!"); unloadPlugin(alias); return false; } fhandle(&plugin_api_pointers); return true; }