From bfe1bd0fc087be44c70904aee0fe4276643d206d Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 20 Jul 2012 15:56:25 +0000 Subject: - db3x_mmap is completely moved to a class; - the old nightmare in the core "How to detect a db plugin and load it" is eliminated forever; - databases are the usual plugins now (loadable via Load) - dynamic DATABASELINK registration git-svn-id: http://svn.miranda-ng.org/main/trunk@1082 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/modules/plugins/dll_sniffer.cpp | 2 +- src/modules/plugins/newplugins.cpp | 70 ++++++++----------------------------- src/modules/plugins/plugins.h | 7 +--- 3 files changed, 17 insertions(+), 62 deletions(-) (limited to 'src/modules/plugins') diff --git a/src/modules/plugins/dll_sniffer.cpp b/src/modules/plugins/dll_sniffer.cpp index 469cebf931..531c9e6919 100644 --- a/src/modules/plugins/dll_sniffer.cpp +++ b/src/modules/plugins/dll_sniffer.cpp @@ -42,7 +42,7 @@ MUUID* GetPluginInterfaces(const TCHAR* ptszFileName, bool& bIsPlugin) MUUID* pResult = NULL; BYTE* ptr = NULL; - HANDLE hMap = CreateFileMapping( hFile, NULL, PAGE_WRITECOPY, 0, 0, NULL ); + HANDLE hMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL ); __try { diff --git a/src/modules/plugins/newplugins.cpp b/src/modules/plugins/newplugins.cpp index 083338614d..ce412e8d34 100644 --- a/src/modules/plugins/newplugins.cpp +++ b/src/modules/plugins/newplugins.cpp @@ -76,7 +76,7 @@ static int serviceModeIdx = -1, sttFakeID = -100; static HANDLE hPluginListHeap = NULL; static int askAboutIgnoredPlugins; -static pluginEntry *pluginListSM, *pluginListDb, *pluginListUI, *pluginList_freeimg, *pluginList_crshdmp; +static pluginEntry *pluginListSM, *pluginListUI, *pluginList_freeimg, *pluginList_crshdmp; int InitIni(void); void UninitIni(void); @@ -197,11 +197,6 @@ static int isPluginBanned(MUUID u1, DWORD dwVersion) return 0; } -// returns true if the API exports were good, otherwise, passed in data is returned -#define CHECKAPI_NONE 0 -#define CHECKAPI_DB 1 -#define CHECKAPI_CLIST 2 - /* * historyeditor added by nightwish - plugin is problematic and can ruin database as it does not understand UTF-8 message * storage @@ -291,17 +286,6 @@ LBL_Ok: return 1; } - // check for DB? - if (checkTypeAPI == CHECKAPI_DB) { - bpi->DbInfo = (Database_Plugin_Info) GetProcAddress(h, "DatabasePluginInfo"); - if (bpi->DbInfo) { - // fetch internal database function pointers - bpi->dblink = bpi->DbInfo(NULL); - // validate returned link structure - if (bpi->dblink && bpi->dblink->cbSize == sizeof(DATABASELINK)) - goto LBL_Ok; - } } - // check clist ? if (checkTypeAPI == CHECKAPI_CLIST) { bpi->clistlink = (CList_Initialise) GetProcAddress(h, "CListInitialise"); @@ -316,10 +300,6 @@ LBL_Ok: // perform any API related tasks to freeing void Plugin_Uninit(pluginEntry* p) { - // if it was an installed database plugin, call its unload - if (p->pclass & PCLASS_DB) - p->bpi.dblink->Unload(p->pclass & PCLASS_OK); - // if the basic API check had passed, call Unload if Load(void) was ever called if (p->pclass & PCLASS_LOADED) p->bpi.Unload(); @@ -406,33 +386,6 @@ void enumPlugins(SCAN_PLUGINS_CALLBACK cb, WPARAM wParam, LPARAM lParam) } } -// this is called by the db module to return all DBs plugins, then when it finds the one it likes the others are unloaded -int enumDbPlugins(pfnDbEnumCallback pFunc, LPARAM lParam) -{ - pluginEntry *x = pluginListDb; - if (pFunc == NULL) - return 1; - - while (x != NULL) { - int rc = pFunc(x->pluginname, x->bpi.dblink, lParam); - if (rc == DBPE_DONE) { - // this db has been picked, get rid of all the others - pluginEntry *y = pluginListDb, *n; - while (y != NULL) { - n = y->nextclass; - if (x != y) - Plugin_Uninit(y); - y = n; - } // while - x->pclass |= PCLASS_LOADED | PCLASS_OK | PCLASS_LAST; - return 0; - } - else if (rc == DBPE_HALT) return 1; - x = x->nextclass; - } // while - return pluginListDb != NULL ? 1 : -1; -} - pluginEntry* OpenPlugin(TCHAR *tszFileName, TCHAR *dir, TCHAR *path) { pluginEntry* p = (pluginEntry*)HeapAlloc(hPluginListHeap, HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY, sizeof(pluginEntry)); @@ -455,18 +408,19 @@ pluginEntry* OpenPlugin(TCHAR *tszFileName, TCHAR *dir, TCHAR *path) // plugin declared that it's a database. load it asap! if ( hasMuuid(pIds, miid_database)) { BASIC_PLUGIN_INFO bpi; - if (checkAPI(tszFullPath, &bpi, mirandaVersion, CHECKAPI_DB)) { + if (checkAPI(tszFullPath, &bpi, mirandaVersion, CHECKAPI_NONE)) { // db plugin is valid p->pclass |= (PCLASS_DB | PCLASS_BASICAPI); // copy the dblink stuff p->bpi = bpi; - // keep a faster list. - if (pluginListDb != NULL) p->nextclass = pluginListDb; - pluginListDb = p; + + RegisterModule(p->bpi.hInst); + if (bpi.Load() != 0) + p->pclass |= PCLASS_FAILED; + else + p->pclass |= PCLASS_LOADED; } - else - // didn't have basic APIs or DB exports - failed. - p->pclass |= PCLASS_FAILED; + else p->pclass |= PCLASS_FAILED; } // plugin declared that it's a contact list. mark it for the future load else if ( hasMuuid(pIds, miid_clist)) { @@ -859,6 +813,12 @@ void UnloadNewPluginsModule(void) Plugin_Uninit(pluginList_crshdmp); // unload the DB + if (currDb != NULL) { + db_setCurrent(NULL); + currDblink->Unload(currDb); + currDb = NULL; + } + for (int k = pluginList.getCount()-1; k >= 0; k--) { pluginEntry* p = pluginList[k]; Plugin_Uninit(p); diff --git a/src/modules/plugins/plugins.h b/src/modules/plugins/plugins.h index 64118a45ed..e0466ccc35 100644 --- a/src/modules/plugins/plugins.h +++ b/src/modules/plugins/plugins.h @@ -1,8 +1,7 @@ // returns true if the API exports were good, otherwise, passed in data is returned #define CHECKAPI_NONE 0 -#define CHECKAPI_DB 1 -#define CHECKAPI_CLIST 2 +#define CHECKAPI_CLIST 1 // block these plugins #define DEFMOD_REMOVED_UIPLUGINOPTS 21 @@ -13,8 +12,6 @@ typedef int (__cdecl * Miranda_Plugin_Load) (void); typedef int (__cdecl * Miranda_Plugin_Unload) (void); // version control typedef PLUGININFOEX * (__cdecl * Miranda_Plugin_InfoEx) (DWORD mirandaVersion); -// prototype for databases -typedef DATABASELINK * (__cdecl * Database_Plugin_Info) (void * reserved); // prototype for clists typedef int (__cdecl * CList_Initialise) (void); @@ -25,11 +22,9 @@ struct BASIC_PLUGIN_INFO Miranda_Plugin_Load Load; Miranda_Plugin_Unload Unload; Miranda_Plugin_InfoEx InfoEx; - Database_Plugin_Info DbInfo; CList_Initialise clistlink; PLUGININFOEX * pluginInfo; // must be freed if hInst = = NULL then its a copy MUUID *Interfaces; // array of supported interfaces - DATABASELINK * dblink; // only valid during module being in memory }; #define PCLASS_FAILED 0x1 // not a valid plugin, or API is invalid, pluginname is valid -- cgit v1.2.3