From ec516765cfd4a4384c4cdaa6bbcd28e6aa578b27 Mon Sep 17 00:00:00 2001 From: Alexey Uzhva Date: Wed, 27 Aug 2008 12:38:22 +0000 Subject: no more libdl dependency. modulenames now unicode. git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@2314 17fca916-40b9-46aa-a4ea-0a15b648b75c --- src/kvilib/system/kvi_library.h | 115 --------------- src/kvirc/kernel/kvi_app_setup.cpp | 22 +-- src/kvirc/kvs/kvi_kvs_kernel.cpp | 6 +- .../kvs/kvi_kvs_treenode_modulecallbackcommand.cpp | 5 +- .../kvs/kvi_kvs_treenode_modulefunctioncall.cpp | 5 +- .../kvs/kvi_kvs_treenode_modulesimplecommand.cpp | 5 +- src/kvirc/module/kvi_module.cpp | 155 +-------------------- src/kvirc/module/kvi_module.h | 16 +-- src/kvirc/module/kvi_modulemanager.cpp | 34 ++--- src/kvirc/module/kvi_modulemanager.h | 4 +- src/kvirc/sparser/kvi_sp_ctcp.cpp | 2 +- src/modules/system/libkvisystem.cpp | 8 +- src/modules/system/plugin.cpp | 113 +++++++-------- src/modules/system/plugin.h | 8 +- 14 files changed, 108 insertions(+), 390 deletions(-) delete mode 100644 src/kvilib/system/kvi_library.h (limited to 'src') diff --git a/src/kvilib/system/kvi_library.h b/src/kvilib/system/kvi_library.h deleted file mode 100644 index 85d544fa6..000000000 --- a/src/kvilib/system/kvi_library.h +++ /dev/null @@ -1,115 +0,0 @@ -#ifndef _KVI_LIBRARY_H_ -#define _KVI_LIBRARY_H_ - -//===================================================================================== -// -// File : kvi_library.h -// Creation date : Tue Sep 25 16:20:40 2001 GMT by Szymon Stefanek -// -// This file is part of the KVirc irc client distribution -// Copyright (C) 2001 Szymon Stefanek (pragma at kvirc dot net) -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -//===================================================================================== - - -//===================================================================================== -// System dynamic linker interface abstraction -//===================================================================================== - - -#include "kvi_settings.h" - - -#if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) - - //#include - #include // this will pull in windows.h - - typedef HMODULE kvi_library_t; - - inline kvi_library_t kvi_library_open(const char * path) - { -#ifndef DEBUG - // this is to avoid the ugly message boxes when the dll has - // ... but do it only in release mode - UINT nOldErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS); -#endif - kvi_library_t ret = LoadLibrary(path); -#ifndef DEBUG - SetErrorMode(nOldErrorMode); -#endif - return ret; - }; - - inline void kvi_library_close(kvi_library_t lib) - { - FreeLibrary(lib); - }; - - inline void * kvi_library_symbol(kvi_library_t lib,const char * symName) - { - return (void *) GetProcAddress(lib,symName); - }; - - inline const char * kvi_library_error() - { - return "Windoze-like error"; - }; - -#else - - #include - - // sparc-unknown-openbsd3.0 (At least) has only RTLD_LAZY - #ifndef RTLD_NOW - #define RTLD_NOW RTLD_LAZY - #endif - #ifndef RTLD_GLOBAL - #define RTLD_GLOBAL 0 - #endif - - typedef void * kvi_library_t; - - inline kvi_library_t kvi_library_open(const char * path) - { - return dlopen(path,RTLD_GLOBAL | RTLD_NOW); - }; - - inline void kvi_library_close(kvi_library_t lib) - { - dlclose(lib); - }; - - - inline void * kvi_library_symbol(kvi_library_t lib,const char * symName) - { - return dlsym(lib,symName); - }; - - inline const char * kvi_library_error() - { - return dlerror(); - }; - - -#endif //!COMPILE_ON_WINDOWS - - -#define kvi_library_load kvi_library_open -#define kvi_library_unload kvi_library_close - -#endif //_KVI_LIBRARY_H_ diff --git a/src/kvirc/kernel/kvi_app_setup.cpp b/src/kvirc/kernel/kvi_app_setup.cpp index d8d2e9de6..f36f86356 100644 --- a/src/kvirc/kernel/kvi_app_setup.cpp +++ b/src/kvirc/kernel/kvi_app_setup.cpp @@ -35,7 +35,6 @@ #include "kvi_fileutils.h" #include "kvi_locale.h" #include "kvi_msgbox.h" -#include "kvi_library.h" #include "kvi_sourcesdate.h" #include "kvi_iconmanager.h" #include "kvi_config.h" @@ -58,7 +57,7 @@ #include #include #include - +#include // // Things launched at startup: @@ -729,7 +728,7 @@ void KviApp::loadDirectories() if(!checkUriAssociations("ircs6")) setupUriAssociations("ircs6"); } -static kvi_library_t g_hSetupLibrary = 0; +static QLibrary* g_pSetupLibrary = 0; void KviApp::setupBegin() @@ -745,12 +744,12 @@ void KviApp::setupBegin() #else szSetupLib.append("libkvisetup.so"); #endif - g_hSetupLibrary = kvi_library_open(szSetupLib.toLocal8Bit().data()); - if(!g_hSetupLibrary) + g_pSetupLibrary = new QLibrary(szSetupLib); + if(!g_pSetupLibrary->load()) { KviMessageBox::warning(__tr2qs("Ops...it looks like I can't load modules on this sytem.\n" \ "I have been looking for the %s library but I haven't been able to load it\n" \ - "due to the following error: \"%s\"\nAborting."),szSetupLib.toUtf8().data(),kvi_library_error()); + "due to the following error: \"%Q\"\nAborting."),szSetupLib.toUtf8().data(),&(g_pSetupLibrary->errorString())); #if defined(COMPILE_ON_WINDOWS) ExitProcess(-1); #elif defined(COMPILE_ON_MINGW) @@ -760,7 +759,7 @@ void KviApp::setupBegin() #endif } - bool (*sfunc)() = (bool(*)())kvi_library_symbol(g_hSetupLibrary,"setup_begin"); + bool (*sfunc)() = (bool(*)())g_pSetupLibrary->resolve("setup_begin"); if(!sfunc) { KviMessageBox::warning(__tr2qs("Ops...it looks like you have a broken distribution.\n" \ @@ -797,13 +796,13 @@ void KviApp::setupBegin() void KviApp::setupFinish() { - if(!g_hSetupLibrary) + if(!g_pSetupLibrary) { debug("Oops... lost the setup library ?"); return; } - void (*sfunc)() = (void(*)())kvi_library_symbol(g_hSetupLibrary,"setup_finish"); + void (*sfunc)() = (void(*)())g_pSetupLibrary->resolve("setup_finish"); if(!sfunc) { KviMessageBox::warning(__tr2qs("Ops...it looks like you have a broken distribution.\n" \ @@ -813,8 +812,9 @@ void KviApp::setupFinish() sfunc(); - kvi_library_close(g_hSetupLibrary); - g_hSetupLibrary = 0; + g_pSetupLibrary->unload(); + delete g_pSetupLibrary; + g_pSetupLibrary = 0; } diff --git a/src/kvirc/kvs/kvi_kvs_kernel.cpp b/src/kvirc/kvs/kvi_kvs_kernel.cpp index c81354c1b..2fbe41d9e 100644 --- a/src/kvirc/kvs/kvi_kvs_kernel.cpp +++ b/src/kvirc/kvs/kvi_kvs_kernel.cpp @@ -59,7 +59,7 @@ KviKvsKernel::KviKvsKernel() m_pObjectController = new KviKvsObjectController(); m_pObjectController->init(); m_pAsyncOperationManager = new KviKvsAsyncOperationManager(); - + KviKvsParser::init(); KviKvsCoreSimpleCommands::init(); @@ -138,7 +138,7 @@ void KviKvsKernel::completeCommand(const QString &szCommandBegin,KviPointerList< void KviKvsKernel::completeModuleCommand(const QString &szModuleName,const QString &szCommandBegin,KviPointerList * pMatches) { - KviModule * pModule = g_pModuleManager->getModule(szModuleName.toLatin1()); + KviModule * pModule = g_pModuleManager->getModule(szModuleName); if(!pModule)return; KviPointerList lModuleMatches; @@ -200,7 +200,7 @@ void KviKvsKernel::completeFunction(const QString &szFunctionBegin,KviPointerLis void KviKvsKernel::completeModuleFunction(const QString &szModuleName,const QString &szCommandBegin,KviPointerList * pMatches) { - KviModule * pModule = g_pModuleManager->getModule(szModuleName.toLatin1()); + KviModule * pModule = g_pModuleManager->getModule(szModuleName); if(!pModule)return; KviPointerList lModuleMatches; diff --git a/src/kvirc/kvs/kvi_kvs_treenode_modulecallbackcommand.cpp b/src/kvirc/kvs/kvi_kvs_treenode_modulecallbackcommand.cpp index 402354f4c..cd8285d02 100644 --- a/src/kvirc/kvs/kvi_kvs_treenode_modulecallbackcommand.cpp +++ b/src/kvirc/kvs/kvi_kvs_treenode_modulecallbackcommand.cpp @@ -61,11 +61,10 @@ void KviKvsTreeNodeModuleCallbackCommand::dump(const char * prefix) bool KviKvsTreeNodeModuleCallbackCommand::execute(KviKvsRunTimeContext * c) { -//#warning "FIXME: module names should be UNICODE!" - KviModule * m = g_pModuleManager->getModule(m_szModuleName.toUtf8().data()); + KviModule * m = g_pModuleManager->getModule(m_szModuleName); if(!m) { - QString szErr = g_pModuleManager->lastError().ptr(); // <-- fixme! + QString szErr = g_pModuleManager->lastError(); c->error(this,__tr2qs("Module command call failed: can't load the module '%Q': %Q"),&m_szModuleName,&szErr); return false; } diff --git a/src/kvirc/kvs/kvi_kvs_treenode_modulefunctioncall.cpp b/src/kvirc/kvs/kvi_kvs_treenode_modulefunctioncall.cpp index 61750ab52..3c2d0a373 100644 --- a/src/kvirc/kvs/kvi_kvs_treenode_modulefunctioncall.cpp +++ b/src/kvirc/kvs/kvi_kvs_treenode_modulefunctioncall.cpp @@ -60,11 +60,10 @@ void KviKvsTreeNodeModuleFunctionCall::dump(const char * prefix) bool KviKvsTreeNodeModuleFunctionCall::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer) { -//#warning "FIXME: module names should be UNICODE!" - KviModule * m = g_pModuleManager->getModule(m_szModuleName.toUtf8().data()); + KviModule * m = g_pModuleManager->getModule(m_szModuleName); if(!m) { - QString szErr = g_pModuleManager->lastError().ptr(); // <-- fixme! + QString szErr = g_pModuleManager->lastError(); c->error(this,__tr2qs("Module function call failed: can't load the module '%Q': %Q"),&m_szModuleName,&szErr); return false; } diff --git a/src/kvirc/kvs/kvi_kvs_treenode_modulesimplecommand.cpp b/src/kvirc/kvs/kvi_kvs_treenode_modulesimplecommand.cpp index f1918c001..252cba2b0 100644 --- a/src/kvirc/kvs/kvi_kvs_treenode_modulesimplecommand.cpp +++ b/src/kvirc/kvs/kvi_kvs_treenode_modulesimplecommand.cpp @@ -60,11 +60,10 @@ void KviKvsTreeNodeModuleSimpleCommand::dump(const char * prefix) bool KviKvsTreeNodeModuleSimpleCommand::execute(KviKvsRunTimeContext * c) { - //#warning "FIXME: module names should be UNICODE!" - KviModule * m = g_pModuleManager->getModule(m_szModuleName.toUtf8().data()); + KviModule * m = g_pModuleManager->getModule(m_szModuleName); if(!m) { - QString szErr = g_pModuleManager->lastError().ptr(); // <-- fixme! + QString szErr = g_pModuleManager->lastError(); c->error(this,__tr2qs("Module command call failed: can't load the module '%Q': %Q"),&m_szModuleName,&szErr); return false; } diff --git a/src/kvirc/module/kvi_module.cpp b/src/kvirc/module/kvi_module.cpp index 35efc746b..26a1a8afb 100644 --- a/src/kvirc/module/kvi_module.cpp +++ b/src/kvirc/module/kvi_module.cpp @@ -128,26 +128,15 @@ extern KVIRC_API KviModuleExtensionManager * g_pModuleExtensionManager; // FIXME: #warning "Move all the modules to the new locking method ?" -KviModule::KviModule(kvi_library_t handle,KviModuleInfo * info,const QString &name,const QString &filename) +KviModule::KviModule(QLibrary* handle,KviModuleInfo * info,const QString &name,const QString &filename) : KviKvsModuleInterface() { - m_dlHandle = handle; + m_pLibrary = handle; m_pModuleInfo = info; m_szName = name; m_szFileName = filename; -// FIXME: this should become case insensitive and converted toUpper() - /* - m_pCommandDict = new KviPointerHashTable(17,false,true); - m_pCommandDict->setAutoDelete(true); - m_pFunctionDict = new KviPointerHashTable(17,false,true); - m_pFunctionDict->setAutoDelete(true); - */ m_uLock = 0; m_lastAccessTime = (long int)time(0); - /* - m_pGenericCommandParseProc = 0; - m_pGenericFunctionParseProc = 0; - */ } KviModule::~KviModule() @@ -156,13 +145,9 @@ KviModule::~KviModule() unregisterCryptEngines(); #endif unregisterAllExtensions(); - /* - unregisterAllEventHandlers(); - delete m_pCommandDict; - delete m_pFunctionDict; - if(m_pGenericCommandParseProc)delete m_pGenericCommandParseProc; - if(m_pGenericFunctionParseProc)delete m_pGenericFunctionParseProc; - */ + + if(m_pLibrary->isLoaded()) m_pLibrary->unload(); + delete m_pLibrary; } KviModuleExtensionDescriptor * KviModule::registerExtension(const KviStr &szType,const KviStr &szName,const QString &szVisibleName,KviModuleExtensionAllocRoutine r) @@ -185,71 +170,7 @@ void KviModule::unregisterAllExtensions() { g_pModuleExtensionManager->unregisterExtensionsByModule(this); } -/* -void KviModule::setGenericCommandParseProc(KviModuleCommandParseProc proc) -{ - if(m_pGenericCommandParseProc)delete m_pGenericCommandParseProc; - if(proc) - { - m_pGenericCommandParseProc = new KviModuleCommandParseProc(proc); - } else { - m_pGenericCommandParseProc = 0; - } -} - -void KviModule::setGenericFunctionParseProc(KviModuleFunctionParseProc proc) -{ - if(m_pGenericFunctionParseProc)delete m_pGenericFunctionParseProc; - if(proc) - { - m_pGenericFunctionParseProc = new KviModuleFunctionParseProc(proc); - } else { - m_pGenericFunctionParseProc = 0; - } -} - -void KviModule::completeCommand(const QString &cmd,KviPointerList * matches) -{ - KviPointerHashTableIterator it(*m_pCommandDict); - - while(it.current()) - { - if(KviQString::equalCIN(cmd,it.currentKey(),cmd.length())) - { - QString * s = new QString(); - KviQString::sprintf(*s,"%s.%s",name(),it.currentKey()); - matches->append(s); - } - ++it; - } -} - -void KviModule::completeFunction(const QString &cmd,KviPointerList * matches) -{ - KviPointerHashTableIterator it(*m_pFunctionDict); - - while(it.current()) - { - if(KviQString::equalCIN(cmd,it.currentKey(),cmd.length())) - { - QString * s = new QString(); - KviQString::sprintf(*s,"%s.%s",name(),it.currentKey()); - matches->append(s); - } - ++it; - } -} - -void KviModule::unregisterMetaObject(const char * metaObjName) -{ -#if QT_VERSION < 300 -// FIXME: #warning "We might need zeroing the d->slotAccess member of QMetaObject!" - if(!objectDict)return; - objectDict->remove(metaObjName); -#endif -} -*/ void KviModule::updateAccessTime() { m_lastAccessTime = (long int)time(0); @@ -259,72 +180,8 @@ unsigned int KviModule::secondsSinceLastAccess() { return (unsigned int)(((long int)time(0)) - m_lastAccessTime); } -/* -void KviModule::registerCommand(const char * cmd,KviModuleCommandParseProc proc) -{ - if(m_pCommandDict->find(cmd))m_pCommandDict->remove(cmd); - m_pCommandDict->insert(cmd,new KviModuleCommandParseProc(proc)); -} - -void KviModule::unregisterCommand(const char * cmd) -{ - m_pCommandDict->remove(cmd); -} - -void KviModule::unregisterAllCommands() -{ - delete m_pCommandDict; - m_pCommandDict = new KviPointerHashTable(17,false,true); - m_pCommandDict->setAutoDelete(true); -} - -void KviModule::registerEventHandler(int evIdx,KviModuleEventParseProc proc) -{ - KviKvsOldModuleEventHandler * h = new KviKvsOldModuleEventHandler(proc,this); - KviKvsEventManager::instance()->addAppHandler(evIdx,h); -} - -void KviModule::unregisterEventHandler(int evIdx) -{ - KviKvsEventManager::instance()->removeModuleAppHandler(evIdx,this); -} - -void KviModule::registerRawNumericEventHandler(int evIdx,KviModuleEventParseProc proc) -{ - KviKvsOldModuleEventHandler * h = new KviKvsOldModuleEventHandler(proc,this); - KviKvsEventManager::instance()->addRawHandler(evIdx,h); -} - -void KviModule::unregisterRawNumericEventHandler(int evIdx) -{ - KviKvsEventManager::instance()->removeModuleRawHandler(evIdx,this); -} -void KviModule::unregisterAllEventHandlers() -{ - KviKvsEventManager::instance()->removeAllModuleHandlers(this); -} - -void KviModule::registerFunction(const char * fnc,KviModuleFunctionParseProc proc) -{ - if(m_pFunctionDict->find(fnc))m_pFunctionDict->remove(fnc); - m_pFunctionDict->insert(fnc,new KviModuleFunctionParseProc(proc)); -} - -void KviModule::unregisterFunction(const char * fnc) -{ - m_pFunctionDict->remove(fnc); -} - -void KviModule::unregisterAllFunctions() -{ - delete m_pFunctionDict; - m_pFunctionDict = new KviPointerHashTable(17,false,true); - m_pFunctionDict->setAutoDelete(true); -} -*/ - #ifdef COMPILE_CRYPT_SUPPORT void KviModule::registerCryptEngine(KviCryptEngineDescription * d) @@ -347,7 +204,7 @@ void KviModule::unregisterCryptEngines() void * KviModule::getSymbol(const char * symname) { - return kvi_library_symbol(handle(),symname); + return m_pLibrary->resolve(symname); } diff --git a/src/kvirc/module/kvi_module.h b/src/kvirc/module/kvi_module.h index ce182f57a..b4611dfdf 100644 --- a/src/kvirc/module/kvi_module.h +++ b/src/kvirc/module/kvi_module.h @@ -29,7 +29,7 @@ #include "kvi_string.h" //#include "kvi_command.h" #include "kvi_parameterlist.h" -#include "kvi_library.h" +#include #include "kvi_pointerlist.h" #include "kvi_moduleextension.h" #include "kvi_kvs_moduleinterface.h" @@ -126,28 +126,20 @@ typedef struct _KviModuleInfo }; -// old type parsing procedures -/* -typedef bool (*KviModuleCommandParseProc)(KviModule *,KviCommand *); -typedef bool (*KviModuleFunctionParseProc)(KviModule *,KviCommand *,KviParameterList *,KviStr &); -typedef bool (*KviModuleEventParseProc)(KviModule *,KviWindow *,KviParameterList *); -*/ - - class KVIRC_API KviModule : public KviKvsModuleInterface { friend class KviPointerHashTable; friend class KviModuleManager; friend class KviUserParser; protected: - KviModule(kvi_library_t handle,KviModuleInfo * info,const QString &name,const QString &filename); + KviModule(QLibrary* handle,KviModuleInfo * info,const QString &name,const QString &filename); public: ~KviModule(); // must be public for KviPointerList private: QString m_szName; QString m_szFileName; KviModuleInfo * m_pModuleInfo; - kvi_library_t m_dlHandle; + QLibrary * m_pLibrary; unsigned int m_uLock; long int m_lastAccessTime; protected: @@ -158,7 +150,7 @@ public: const QString & name(){ return m_szName; }; // filename of this module (with NO path): formatted as "libkvi%s.so",name() const QString & filename(){ return m_szFileName; }; - kvi_library_t handle(){ return m_dlHandle; }; + QLibrary* handle(){ return m_pLibrary; }; KviModuleInfo * moduleInfo(){ return m_pModuleInfo; }; // diff --git a/src/kvirc/module/kvi_modulemanager.cpp b/src/kvirc/module/kvi_modulemanager.cpp index d95df1726..01dcbc557 100644 --- a/src/kvirc/module/kvi_modulemanager.cpp +++ b/src/kvirc/module/kvi_modulemanager.cpp @@ -34,8 +34,6 @@ #include "kvi_locale.h" #include "kvi_out.h" -#include "kvi_library.h" - #include KviModuleManager * g_pModuleManager = 0; @@ -184,24 +182,26 @@ bool KviModuleManager::loadModule(const QString &modName) g_pApp->getGlobalKvircDirectory(tmp,KviApp::Plugins,szName); } - kvi_library_t handle = kvi_library_open(tmp.toLocal8Bit().data()); - if(!handle) + QLibrary* pLibrary = new QLibrary(tmp); + if(!pLibrary->load()) { - m_szLastError = kvi_library_error(); - //debug("ERROR IN LOADING MODULE %s (%s): %s",modName,szName.ptr(),kvi_library_error()); + m_szLastError = pLibrary->errorString(); + delete pLibrary; return false; } - KviModuleInfo * info = (KviModuleInfo *)kvi_library_symbol(handle,KVIRC_MODULE_STRUCTURE_SYMBOL); + KviModuleInfo * info = (KviModuleInfo *)pLibrary->resolve(KVIRC_MODULE_STRUCTURE_SYMBOL); if(!info) { m_szLastError = __tr2qs("No " KVIRC_MODULE_STRUCTURE_SYMBOL " symbol exported: not a kvirc module ?"); - kvi_library_close(handle); + pLibrary->unload(); + delete pLibrary; return false; } if(!info->szKVIrcVersion) { m_szLastError = __tr2qs("This module has no version informations: refusing to load it"); - kvi_library_close(handle); + pLibrary->unload(); + delete pLibrary; return false; } if(!KVI_OPTION_BOOL(KviOption_boolIgnoreModuleVersions)) @@ -212,11 +212,12 @@ bool KviModuleManager::loadModule(const QString &modName) m_szLastError += " ("; m_szLastError += info->szKVIrcVersion; m_szLastError += ")"; - kvi_library_close(handle); + pLibrary->unload(); + delete pLibrary; return false; } } - KviModule * module = new KviModule(handle,info,modName,szName.toUtf8().data()); + KviModule * module = new KviModule(pLibrary,info,modName,szName.toUtf8().data()); // the module is probably up.. the only thing can fail is the init_routine now // load the message catalogue if any @@ -238,7 +239,6 @@ bool KviModuleManager::loadModule(const QString &modName) { m_szLastError = __tr2qs("Failed to execute the init routine"); //debug("ERROR IN LOADING MODULE %s (%s): failed to execute the init routine",modName,szName.ptr()); - kvi_library_close(handle); delete module; // kill the message catalogue too then KviLocale::unloadCatalogue(modName); @@ -270,14 +270,6 @@ bool KviModuleManager::loadModule(const QString &modName) return true; } -/* -void KviModuleManager::registerDefaultCommands(KviModule * module) -{ - // Register the default commands - module->registerCommand("load",default_module_cmd_load); - module->registerCommand("unload",default_module_cmd_unload); -} -*/ bool KviModuleManager::unloadModule(const QString &modName) { return unloadModule(findModule(modName)); @@ -293,7 +285,7 @@ bool KviModuleManager::unloadModule(KviModule * module) (module->moduleInfo()->cleanup_routine)(module); } QString szModName = module->name(); - kvi_library_close(module->handle()); + module->handle()->unload(); //debug("Closing module %s, dlclose returns %d",szModName.ptr(),dlclose(module->handle())); m_pModuleDict->remove(szModName); diff --git a/src/kvirc/module/kvi_modulemanager.h b/src/kvirc/module/kvi_modulemanager.h index 1476c4bf9..4aff9fdf1 100644 --- a/src/kvirc/module/kvi_modulemanager.h +++ b/src/kvirc/module/kvi_modulemanager.h @@ -42,9 +42,9 @@ public: private: KviPointerHashTable * m_pModuleDict; QTimer * m_pCleanupTimer; - KviStr m_szLastError; + QString m_szLastError; public: - KviStr & lastError(){ return m_szLastError; }; + QString & lastError(){ return m_szLastError; }; KviModule * findModule(const QString &modName); KviModule * getModule(const QString &modName); bool loadModule(const QString &modName); diff --git a/src/kvirc/sparser/kvi_sp_ctcp.cpp b/src/kvirc/sparser/kvi_sp_ctcp.cpp index e87b0a694..c12e2e46f 100644 --- a/src/kvirc/sparser/kvi_sp_ctcp.cpp +++ b/src/kvirc/sparser/kvi_sp_ctcp.cpp @@ -1768,7 +1768,7 @@ void KviServerParser::parseCtcpRequestDcc(KviCtcpMessage *msg) if(!m) { msg->msg->console()->output(KVI_OUT_DCCERROR, - __tr2qs("Unable to process the above request: Cannot load DCC module (%s)"),g_pModuleManager->lastError().ptr()); + __tr2qs("Unable to process the above request: Cannot load DCC module (%Q)"),&(g_pModuleManager->lastError())); } else { dccModuleCtcpDccParseRoutine proc = (dccModuleCtcpDccParseRoutine)m->getSymbol("dccModuleCtcpDccParseRoutine"); if(!proc) diff --git a/src/modules/system/libkvisystem.cpp b/src/modules/system/libkvisystem.cpp index 21167fb00..022900f86 100644 --- a/src/modules/system/libkvisystem.cpp +++ b/src/modules/system/libkvisystem.cpp @@ -369,7 +369,7 @@ static bool system_kvs_fnc_checkModule(KviKvsModuleFunctionCall *c) KVSM_PARAMETER("module_name",KVS_PT_STRING,0,szModuleName) KVSM_PARAMETERS_END(c) - c->returnValue()->setBoolean(g_pModuleManager->loadModule(szModuleName.toUtf8().data())); + c->returnValue()->setBoolean(g_pModuleManager->loadModule(szModuleName)); return true; } @@ -450,7 +450,7 @@ static bool system_kvs_fnc_dcop(KviKvsModuleFunctionCall *c) KviQCString szApp,szObj,szFun; QStringList parms; - + KVSM_PARAMETERS_BEGIN(c) KVSM_PARAMETER("application",KVS_PT_NONEMPTYCSTRING,0,szApp) KVSM_PARAMETER("objectid",KVS_PT_NONEMPTYCSTRING,0,szObj) @@ -475,7 +475,7 @@ static bool system_kvs_fnc_dcop(KviKvsModuleFunctionCall *c) for ( QStringList::Iterator it = parms.begin(); it != parms.end(); ++it ) { KviStr tmp = *it; - + if(tmp.isEmpty()) { c->warning(__tr2qs("Invalid DCOP parameter syntax")); @@ -705,7 +705,7 @@ static bool system_module_init(KviModule * m) KVSM_REGISTER_SIMPLE_COMMAND(m,"setSelection",system_kvs_cmd_setSelection); g_pPluginManager = new(KviPluginManager); - + return true; } diff --git a/src/modules/system/plugin.cpp b/src/modules/system/plugin.cpp index b937957da..8208dfc52 100644 --- a/src/modules/system/plugin.cpp +++ b/src/modules/system/plugin.cpp @@ -26,7 +26,6 @@ #include "kvi_module.h" #include "kvi_string.h" -#include "kvi_library.h" #include "kvi_thread.h" #include "kvi_locale.h" #include "kvi_app.h" @@ -59,7 +58,7 @@ return 0;[br] }[br] [/example] - + [br][b]_load function[/b] [i](optional)[/i][br] After the plugin has be loaded, KVIrc will call the _load-function. Here you can prepare your plugin stuff. [example] @@ -67,20 +66,20 @@ {[br] return 0;[br] }[br] - [/example] - + [/example] + [br][b]_unload function[/b] [i]((optional)[/i][br] - This function will be called before the plugins is unloaded. In this function you can clean up memory or other things. + This function will be called before the plugins is unloaded. In this function you can clean up memory or other things. After this call there is no guarantee that the plugin will be kept in memory.[br] [example] int _unload()[br] {[br] return 0;[br] }[br] - [/example] + [/example] [br][b]_canunload function[/b] [i](optional)[/i][br] - The _canunload-function will be called by KVIrc to check if it may unload the plugin. + The _canunload-function will be called by KVIrc to check if it may unload the plugin. If return value is true KVIrc will unload the plugin, false means he will try unloading it at the next check.[br] Important: KVIrc will ignore this if unload of plugins will be forced! So you have to be sure that the _unload function of your plugins cleans up![br] [example] @@ -89,11 +88,11 @@ return 0; [br] }[br] [/example] - + [br][b]user function[/b][br] This is the general structure of a user function call.[br] The important thing here is the handling of return values. To return a value to KVIrc you have to allocate memory and write the pointer to it into pBuffer. Have a look at the example for more details.[br] - [example] + [example] int about(int argc, char * argv[], char ** pBuffer)[br] {[br] *pBuffer = (char*)malloc(1024);[br] @@ -103,29 +102,32 @@ [/example] */ -KviPlugin::KviPlugin(kvi_library_t pLib, const QString& name) +KviPlugin::KviPlugin(QLibrary * pLibrary, const QString& name) { - m_Plugin = pLib; + m_pLibrary = pLibrary; m_szName = name; } KviPlugin::~KviPlugin() { + if(m_pLibrary->isLoaded()) m_pLibrary->unload(); + delete m_pLibrary; } KviPlugin* KviPlugin::load(const QString& szFileName) { - kvi_library_t pLibrary = kvi_library_open(szFileName.toLocal8Bit()); - if (!pLibrary) + QLibrary* pLibrary = new QLibrary(szFileName); + if (!pLibrary->load()) { + delete pLibrary; return 0; - } + } KviPlugin* pPlugin = new KviPlugin(pLibrary,KviFileUtils::extractFileName(szFileName)); - + plugin_load function_load; - - function_load = (plugin_unload)kvi_library_symbol(pLibrary,"_load"); + + function_load = (plugin_unload)pLibrary->resolve("_load"); if (function_load) { //TODO: THREAD @@ -137,8 +139,8 @@ KviPlugin* KviPlugin::load(const QString& szFileName) bool KviPlugin::pfree(char * pBuffer) { plugin_free function_free; - - function_free = (plugin_free)kvi_library_symbol(m_Plugin,"_free"); + + function_free = (plugin_free)m_pLibrary->resolve("_free"); if (function_free) { //TODO: THREAD @@ -151,19 +153,15 @@ bool KviPlugin::pfree(char * pBuffer) bool KviPlugin::unload() { plugin_unload function_unload; - - function_unload = (plugin_unload)kvi_library_symbol(m_Plugin,"_unload"); + + function_unload = (plugin_unload)m_pLibrary->resolve("_unload"); if (function_unload) { //TODO: THREAD function_unload(); } - - if(m_Plugin) - { - kvi_library_close(m_Plugin); - } - + + m_pLibrary->unload(); return true; } @@ -171,14 +169,11 @@ bool KviPlugin::canunload() { plugin_canunload function_canunload; - function_canunload = (plugin_canunload)kvi_library_symbol(m_Plugin,"_canunload"); + function_canunload = (plugin_canunload)m_pLibrary->resolve("_canunload"); if (function_canunload) { //TODO: THREAD - if(!function_canunload()) - { - return false; - } + return function_canunload(); } return true; } @@ -187,7 +182,7 @@ int KviPlugin::call(const QString& pszFunctionName, int argc, char * argv[], cha { int r; plugin_function function_call; - function_call = (plugin_function)kvi_library_symbol(m_Plugin,pszFunctionName.toLocal8Bit()); + function_call = (plugin_function)m_pLibrary->resolve(pszFunctionName); if (!function_call) { return -1; @@ -213,7 +208,7 @@ KviPluginManager::KviPluginManager() { m_pPluginDict = new KviPointerHashTable(5,false); m_pPluginDict->setAutoDelete(false); - + m_bCanUnload = true; } @@ -227,43 +222,43 @@ bool KviPluginManager::pluginCall(KviKvsModuleFunctionCall *c) // /echo $system.call("traffic.dll",about) QString szPluginPath; //contains full path and plugin name like "c:/plugin.dll" QString szFunctionName; - + KVSM_PARAMETERS_BEGIN(c) KVSM_PARAMETER("plugin_path",KVS_PT_NONEMPTYSTRING,0,szPluginPath) KVSM_PARAMETER("function",KVS_PT_NONEMPTYSTRING,0,szFunctionName) KVSM_PARAMETERS_END(c) - + //Check if there is such a plugin if(!findPlugin(szPluginPath)) { c->error(__tr2qs("Plugin not found. Please check the plugin-name and path.")); return true; } - + //Load plugin or check it in cache if(!loadPlugin(szPluginPath)) { c->error(__tr2qs("Error while loading plugin.")); return true; } - + //Parsing more Parameters int iArgc = 0; char ** ppArgv; char * pArgvBuffer; - - //Preparing argv buffer + + //Preparing argv buffer if(c->parameterCount() > 2) { iArgc = c->parameterCount() - 2; } - + if (iArgc > 0) - { + { int i = 2; QString tmp; int iSize = 0; - + //Calculate buffer size while (i < (iArgc + 2) ) { @@ -271,11 +266,11 @@ bool KviPluginManager::pluginCall(KviKvsModuleFunctionCall *c) iSize += tmp.length()+1; //+1 for the \0 characters i++; } - + //Allocate buffer ppArgv = (char**)malloc(iArgc*sizeof(char*)); pArgvBuffer = (char*)malloc(iSize); - + i = 2; char * x = 0; x = pArgvBuffer; @@ -289,7 +284,7 @@ bool KviPluginManager::pluginCall(KviKvsModuleFunctionCall *c) *x = 0; x++; i++; - } + } } else { //Avoid using unfilled variables @@ -297,14 +292,14 @@ bool KviPluginManager::pluginCall(KviKvsModuleFunctionCall *c) pArgvBuffer = 0; iArgc = 0; } - + //Preparing return buffer char * returnBuffer; KviPlugin * plugin; - + plugin = getPlugin(szPluginPath); int r = plugin->call(szFunctionName,iArgc,ppArgv,&returnBuffer); - + if(r == -1) { c->error(__tr2qs("This plugin does not export the desired function.")); @@ -315,7 +310,7 @@ bool KviPluginManager::pluginCall(KviKvsModuleFunctionCall *c) c->returnValue()->setString(QString::fromLocal8Bit(returnBuffer)); } - + //Clean up if(pArgvBuffer) free(pArgvBuffer); if(ppArgv) free(ppArgv); @@ -332,14 +327,14 @@ bool KviPluginManager::pluginCall(KviKvsModuleFunctionCall *c) bool KviPluginManager::checkUnload() { - /* + /* Always called when system module should be unloaded - Checking here if all small "modules" can be unloaded + Checking here if all small "modules" can be unloaded */ KviPointerHashTableIterator it(*m_pPluginDict); - + m_bCanUnload = true; - + while(it.current()) { if(it.current()->canunload()) @@ -351,14 +346,14 @@ bool KviPluginManager::checkUnload() } it.moveNext(); } - + return m_bCanUnload; } void KviPluginManager::unloadAll() { KviPointerHashTableIterator it(*m_pPluginDict); - + while(it.current()) { it.current()->unload(); @@ -373,17 +368,17 @@ bool KviPluginManager::findPlugin(QString& szPath) // szFileName.detach(); if(KviFileUtils::isAbsolutePath(szPath) && KviFileUtils::fileExists(szPath)) { - // Ok, + // Ok, return true; } else { //Plugin not found in direct way. Looking in kvirc local dir g_pApp->getGlobalKvircDirectory(szPath,KviApp::EasyPlugins,szFileName); - + if(!KviFileUtils::fileExists(szPath)) { //Plugin not found in kvirc local dir. Looking in kvirc global dir g_pApp->getLocalKvircDirectory(szPath,KviApp::EasyPlugins,szFileName); - + if(!KviFileUtils::fileExists(szPath)) { return false; diff --git a/src/modules/system/plugin.h b/src/modules/system/plugin.h index 03e3c9a9a..3b51cbcaa 100644 --- a/src/modules/system/plugin.h +++ b/src/modules/system/plugin.h @@ -26,7 +26,7 @@ #include "kvi_module.h" #include "kvi_pointerhashtable.h" - +#include typedef int (*plugin_function)(int argc, char* argv[], char ** buffer); typedef int (*plugin_unload)(); typedef int (*plugin_canunload)(); @@ -37,14 +37,14 @@ class KviPlugin { protected: // You have to create plugin instance by calling KviPlugin::load() - KviPlugin(kvi_library_t pLib, const QString& name); + KviPlugin(QLibrary * pLibrary,const QString& name); public: ~KviPlugin(); private: // shared // internal - kvi_library_t m_Plugin; - QString m_szName; + QLibrary *m_pLibrary; + QString m_szName; public: static KviPlugin* load(const QString& szFileName); bool pfree(char * pBuffer); -- cgit v1.3.1-10-gc9f91