summaryrefslogtreecommitdiff
path: root/src/modules/database
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-07-20 15:56:25 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-07-20 15:56:25 +0000
commitbfe1bd0fc087be44c70904aee0fe4276643d206d (patch)
treed5376d7cab1f6e5084a1449dc341c325b6cee45c /src/modules/database
parent8593e7594773c30b35488bb6a45fcc782ed5df0c (diff)
- 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
Diffstat (limited to 'src/modules/database')
-rw-r--r--src/modules/database/database.cpp76
-rw-r--r--src/modules/database/dbintf.cpp34
-rw-r--r--src/modules/database/profilemanager.cpp65
-rw-r--r--src/modules/database/profilemanager.h11
4 files changed, 90 insertions, 96 deletions
diff --git a/src/modules/database/database.cpp b/src/modules/database/database.cpp
index 8686d50bc6..13ce6bbfa9 100644
--- a/src/modules/database/database.cpp
+++ b/src/modules/database/database.cpp
@@ -23,8 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "..\..\core\commonheaders.h"
#include "profilemanager.h"
-MIR_CORE_DLL(void) db_setCurrent(MIDatabase* _db);
-
// contains the location of mirandaboot.ini
extern TCHAR mirandabootini[MAX_PATH];
bool dbCreated;
@@ -413,59 +411,59 @@ int makeDatabase(TCHAR *profile, DATABASELINK * link, HWND hwndDlg)
}
// enumerate all plugins that had valid DatabasePluginInfo()
-static int FindDbPluginForProfile(const TCHAR*, DATABASELINK *dblink, LPARAM lParam)
+int tryOpenDatabase(const TCHAR* tszProfile)
{
- TCHAR* tszProfile = (TCHAR*)lParam;
- int res = DBPE_CONT;
- if (dblink && dblink->cbSize == sizeof(DATABASELINK)) {
+ for (int i=0; i < arDbPlugins.getCount(); i++) {
+ DATABASELINK* p = arDbPlugins[i];
+
// liked the profile?
int err = 0;
- if (dblink->grokHeader(tszProfile, &err) == 0) {
+ if ( p->grokHeader(tszProfile, &err) == 0) {
// added APIs?
- MIDatabase* pDb = dblink->Load(tszProfile);
+ MIDatabase* pDb = p->Load(tszProfile);
if (pDb) {
fillProfileName(tszProfile);
+ currDblink = p;
db_setCurrent(currDb = pDb);
- res = DBPE_DONE;
+ return 0;
}
- else res = DBPE_HALT;
+ return 1;
}
else {
- res = DBPE_HALT;
switch (err) {
case EGROKPRF_CANTREAD:
case EGROKPRF_UNKHEADER:
// just not supported.
- res = DBPE_CONT;
+ continue;
case EGROKPRF_VERNEWER:
case EGROKPRF_DAMAGED:
- break;
+ return 1;
}
} //if
}
- return res;
+ return 1;
}
// enumerate all plugins that had valid DatabasePluginInfo()
-static int FindDbPluginAutoCreate(const TCHAR* ptszProfile, DATABASELINK * dblink, LPARAM lParam)
+static int tryCreateDatabase(const TCHAR* ptszProfile)
{
- int res = DBPE_CONT;
- if (dblink && dblink->cbSize == sizeof(DATABASELINK)) {
- TCHAR* tszProfile = NEWTSTR_ALLOCA(ptszProfile);
- CreatePathToFileT(tszProfile);
+ TCHAR* tszProfile = NEWTSTR_ALLOCA(ptszProfile);
+ CreatePathToFileT(tszProfile);
+
+ for (int i=0; i < arDbPlugins.getCount(); i++) {
+ DATABASELINK* p = arDbPlugins[i];
int err;
- if (dblink->makeDatabase(tszProfile, &err) == 0) {
- dbCreated = true;
- if ( !dblink->Load(tszProfile)) {
+ if (p->makeDatabase(tszProfile, &err) == 0) {
+ if ( !p->Load(tszProfile)) {
fillProfileName(tszProfile);
- res = DBPE_DONE;
+ return 0;
}
- else res = DBPE_HALT;
+ return 1;
}
}
- return res;
+ return 1;
}
typedef struct {
@@ -514,28 +512,24 @@ int LoadDatabaseModule(void)
if ( !getProfile(szProfile, SIZEOF(szProfile)))
return 1;
- pfnDbEnumCallback pFunc;
- if (_taccess(szProfile, 0) && shouldAutoCreate(szProfile))
- pFunc = FindDbPluginAutoCreate;
- else
- pFunc = FindDbPluginForProfile;
+ if ( arDbPlugins.getCount() == 0) {
+ TCHAR buf[256];
+ TCHAR* p = _tcsrchr(szProfile, '\\');
+ mir_sntprintf(buf, SIZEOF(buf), TranslateT("Miranda is unable to open '%s' because you do not have any profile plugins installed.\nYou need to install dbx_3x.dll or equivalent."), p ? ++p : szProfile);
+ MessageBox(0, buf, TranslateT("No profile support installed!"), MB_OK | MB_ICONERROR);
+ }
// find a driver to support the given profile
bool retry;
int rc;
do {
retry = false;
- rc = enumDbPlugins(pFunc, (LPARAM)szProfile);
- switch (rc) {
- case -1: {
- // no plugins at all
- TCHAR buf[256];
- TCHAR* p = _tcsrchr(szProfile, '\\');
- mir_sntprintf(buf, SIZEOF(buf), TranslateT("Miranda is unable to open '%s' because you do not have any profile plugins installed.\nYou need to install dbx_3x.dll or equivalent."), p ? ++p : szProfile);
- MessageBox(0, buf, TranslateT("No profile support installed!"), MB_OK | MB_ICONERROR);
- break;
- }
- case 1:
+ if ( _taccess(szProfile, 0) && shouldAutoCreate(szProfile))
+ rc = tryCreateDatabase(szProfile);
+ else
+ rc = tryOpenDatabase(szProfile);
+
+ if (rc != 0) {
// if there were drivers but they all failed cos the file is locked, try and find the miranda which locked it
if (fileExist(szProfile)) {
// file isn't locked, just no driver could open it.
diff --git a/src/modules/database/dbintf.cpp b/src/modules/database/dbintf.cpp
index c3bf4f3b5c..2f7cf4ea72 100644
--- a/src/modules/database/dbintf.cpp
+++ b/src/modules/database/dbintf.cpp
@@ -23,7 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "..\..\core\commonheaders.h"
-MIDatabase* currDb = NULL;
+MIDatabase *currDb = NULL;
+DATABASELINK *currDblink = NULL;
MIR_CORE_DLL(void) db_setCurrent(MIDatabase*);
@@ -159,6 +160,34 @@ static INT_PTR srvEnumResidentSettings(WPARAM wParam,LPARAM lParam)
{ return (currDb) ? (INT_PTR)currDb->EnumResidentSettings((DBMODULEENUMPROC)wParam, (void*)lParam) : 0;
}
+///////////////////////////////////////////////////////////////////////////////
+// Database list
+
+LIST<DATABASELINK> arDbPlugins(5);
+
+static INT_PTR srvRegisterPlugin(WPARAM wParam,LPARAM lParam)
+{
+ DATABASELINK* pPlug = (DATABASELINK*)lParam;
+ if (pPlug == NULL)
+ return 1;
+
+ arDbPlugins.insert(pPlug);
+ return 0;
+}
+
+static INT_PTR srvFindPlugin(WPARAM wParam,LPARAM lParam)
+{
+ for (int i=0; i < arDbPlugins.getCount(); i++) {
+ int error;
+ if (arDbPlugins[i]->grokHeader((TCHAR*)lParam, &error) == ERROR_SUCCESS)
+ return (INT_PTR)arDbPlugins[i];
+ }
+
+ return NULL;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
int LoadDbintfModule()
{
CreateServiceFunction(MS_DB_SETSAFETYMODE, srvSetSafetyMode);
@@ -194,5 +223,8 @@ int LoadDbintfModule()
CreateServiceFunction(MS_DB_CONTACT_ENUMSETTINGS, srvEnumContactSettings);
CreateServiceFunction(MS_DB_SETSETTINGRESIDENT, srvSetSettingResident);
CreateServiceFunction("DB/ResidentSettings/Enum", srvEnumResidentSettings);
+
+ CreateServiceFunction(MS_DB_REGISTER_PLUGIN, srvRegisterPlugin);
+ CreateServiceFunction(MS_DB_FIND_PLUGIN, srvFindPlugin);
return 0;
}
diff --git a/src/modules/database/profilemanager.cpp b/src/modules/database/profilemanager.cpp
index 4e8ebc381f..6ca3206574 100644
--- a/src/modules/database/profilemanager.cpp
+++ b/src/modules/database/profilemanager.cpp
@@ -115,20 +115,6 @@ static LRESULT CALLBACK ProfileNameValidate(HWND edit, UINT msg, WPARAM wParam,
return CallWindowProc((WNDPROC)GetWindowLongPtr(edit, GWLP_USERDATA), edit, msg, wParam, lParam);
}
-static int FindDbProviders(const TCHAR* tszProfileName, DATABASELINK *dblink, LPARAM lParam)
-{
- HWND hwndDlg = (HWND)lParam;
- HWND hwndCombo = GetDlgItem(hwndDlg, IDC_PROFILEDRIVERS);
- TCHAR szName[64];
-
- if (dblink->getFriendlyName(szName, SIZEOF(szName), 1) == 0) {
- // add to combo box
- LRESULT index = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)szName);
- SendMessage(hwndCombo, CB_SETITEMDATA, index, (LPARAM)dblink);
- }
- return DBPE_CONT;
-}
-
static INT_PTR CALLBACK DlgProfileNew(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
struct DlgProfData * dat = (struct DlgProfData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
@@ -138,18 +124,26 @@ static INT_PTR CALLBACK DlgProfileNew(HWND hwndDlg, UINT msg, WPARAM wParam, LPA
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
dat = (struct DlgProfData *)lParam;
{
- // fill in the db plugins present
- if (enumDbPlugins(FindDbProviders, (LPARAM)hwndDlg) == -1) {
- // what, no plugins?!
- EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILEDRIVERS), FALSE);
+ HWND hwndCombo = GetDlgItem(hwndDlg, IDC_PROFILEDRIVERS);
+
+ // what, no plugins?!
+ if (arDbPlugins.getCount() == 0) {
+ EnableWindow(hwndCombo, FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILENAME), FALSE);
ShowWindow(GetDlgItem(hwndDlg, IDC_NODBDRIVERS), TRUE);
}
+ else {
+ for (int i=0; i < arDbPlugins.getCount(); i++) {
+ DATABASELINK* p = arDbPlugins[i];
+ LRESULT index = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)TranslateTS(p->szFullName));
+ SendMessage(hwndCombo, CB_SETITEMDATA, index, (LPARAM)p);
+ }
+ }
+
// default item
- SendDlgItemMessage(hwndDlg, IDC_PROFILEDRIVERS, CB_SETCURSEL, 0, 0);
- }
- // subclass the profile name box
- {
+ SendMessage(hwndCombo, CB_SETCURSEL, 0, 0);
+
+ // subclass the profile name box
HWND hwndProfile = GetDlgItem(hwndDlg, IDC_PROFILENAME);
WNDPROC proc = (WNDPROC)GetWindowLongPtr(hwndProfile, GWLP_WNDPROC);
SetWindowLongPtr(hwndProfile, GWLP_USERDATA, (LONG_PTR)proc);
@@ -157,8 +151,7 @@ static INT_PTR CALLBACK DlgProfileNew(HWND hwndDlg, UINT msg, WPARAM wParam, LPA
}
// decide if there is a default profile name given in the INI and if it should be used
- if (dat->pd->noProfiles || (shouldAutoCreate(dat->pd->szProfile) && _taccess(dat->pd->szProfile, 0)))
- {
+ if (dat->pd->noProfiles || (shouldAutoCreate(dat->pd->szProfile) && _taccess(dat->pd->szProfile, 0))) {
TCHAR* profile = _tcsrchr(dat->pd->szProfile, '\\');
if (profile) ++profile;
else profile = dat->pd->szProfile;
@@ -216,21 +209,6 @@ static INT_PTR CALLBACK DlgProfileNew(HWND hwndDlg, UINT msg, WPARAM wParam, LPA
return FALSE;
}
-static int DetectDbProvider(const TCHAR*, DATABASELINK * dblink, LPARAM lParam)
-{
- int error;
- int ret = dblink->grokHeader((TCHAR*)lParam, &error);
- if (ret == 0) {
-
- TCHAR tmp[ MAX_PATH ];
- dblink->getFriendlyName(tmp, SIZEOF(tmp), 1);
- _tcsncpy((TCHAR*)lParam, tmp, MAX_PATH);
- return DBPE_HALT;
- }
-
- return DBPE_CONT;
-}
-
BOOL EnumProfilesForList(TCHAR *fullpath, TCHAR *profile, LPARAM lParam)
{
ProfileEnumData *ped = (ProfileEnumData*)lParam;
@@ -260,7 +238,6 @@ BOOL EnumProfilesForList(TCHAR *fullpath, TCHAR *profile, LPARAM lParam)
_tcscpy(sizeBuf+5, _T(" KB"));
}
bFileExists = TRUE;
-
bFileLocked = !fileExist(fullpath);
}
@@ -283,7 +260,8 @@ BOOL EnumProfilesForList(TCHAR *fullpath, TCHAR *profile, LPARAM lParam)
item2.mask = LVIF_TEXT;
item2.iItem = iItem;
- if ( enumDbPlugins(DetectDbProvider, (LPARAM)szPath) == 1) {
+ DATABASELINK* dblink = FindDatabasePlugin(szPath);
+ if (dblink != NULL) {
if (bFileLocked) {
// file locked
item2.pszText = TranslateT("<In Use>");
@@ -291,10 +269,11 @@ BOOL EnumProfilesForList(TCHAR *fullpath, TCHAR *profile, LPARAM lParam)
SendMessage(hwndList, LVM_SETITEMTEXT, iItem, (LPARAM)&item2);
}
else {
- item.pszText = szPath;
+ item.pszText = TranslateTS(dblink->szFullName);
item.iSubItem = 1;
SendMessage(hwndList, LVM_SETITEMTEXT, iItem, (LPARAM)&item);
- } }
+ }
+ }
item2.iSubItem = 3;
item2.pszText = trtrim(_tctime(&statbuf.st_ctime));
diff --git a/src/modules/database/profilemanager.h b/src/modules/database/profilemanager.h
index 64e4960fdc..e3ed554e56 100644
--- a/src/modules/database/profilemanager.h
+++ b/src/modules/database/profilemanager.h
@@ -42,14 +42,3 @@ bool shouldAutoCreate(TCHAR *szProfile);
extern TCHAR g_profileDir[MAX_PATH];
extern TCHAR g_profileName[MAX_PATH];
-
-///////////////////////////////////////////////////////////////////////////////
-// former m_plugins.h
-
-#define DBPE_DONE 1
-#define DBPE_CONT 0
-#define DBPE_HALT (-1)
-
-typedef int (*pfnDbEnumCallback) (const TCHAR *pluginname, DATABASELINK* link, LPARAM lParam);
-
-int enumDbPlugins(pfnDbEnumCallback pFunc, LPARAM lParam);