diff options
author | George Hazan <george.hazan@gmail.com> | 2015-04-05 11:22:18 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-04-05 11:22:18 +0000 |
commit | 555cb30158d41cb7f66eae95d5aaf400a413731a (patch) | |
tree | 51612042c6a1f0fa29991e9d9e1b51e737e9161e /plugins | |
parent | 340d879890f5099c21e36fc147d6432a1ac050bf (diff) |
fix for custom sorting procedures
git-svn-id: http://svn.miranda-ng.org/main/trunk@12605 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Dbx_kyoto/src/dbevents.cpp | 2 | ||||
-rw-r--r-- | plugins/Dbx_kyoto/src/dbintf.cpp | 35 | ||||
-rw-r--r-- | plugins/Dbx_kyoto/src/dbintf.h | 7 | ||||
-rw-r--r-- | plugins/Dbx_kyoto/src/dbsettings.cpp | 18 |
4 files changed, 22 insertions, 40 deletions
diff --git a/plugins/Dbx_kyoto/src/dbevents.cpp b/plugins/Dbx_kyoto/src/dbevents.cpp index cf47287eed..e1b3cf3206 100644 --- a/plugins/Dbx_kyoto/src/dbevents.cpp +++ b/plugins/Dbx_kyoto/src/dbevents.cpp @@ -314,7 +314,6 @@ STDMETHODIMP_(MEVENT) CDbxKyoto::FindNextEvent(MCONTACT contactID, MEVENT hDbEve DBEventSortingKey keyVal = { contactID, ts, hDbEvent+1 };
cursor_ptr cursor(m_dbEventsSort);
cursor->jump((LPCSTR)&keyVal, sizeof(keyVal));
- cursor->step();
size_t size;
DBEventSortingKey *pKey = (DBEventSortingKey*)cursor->get_key(&size);
@@ -344,7 +343,6 @@ STDMETHODIMP_(MEVENT) CDbxKyoto::FindPrevEvent(MCONTACT contactID, MEVENT hDbEve DBEventSortingKey keyVal = { contactID, ts, hDbEvent-1 };
cursor_ptr cursor(m_dbEventsSort);
cursor->jump_back((LPCSTR)&keyVal, sizeof(keyVal));
- cursor->step_back();
size_t size;
DBEventSortingKey *pKey = (DBEventSortingKey*)cursor->get_key(&size);
diff --git a/plugins/Dbx_kyoto/src/dbintf.cpp b/plugins/Dbx_kyoto/src/dbintf.cpp index e02fa083f6..bd43f0fa7d 100644 --- a/plugins/Dbx_kyoto/src/dbintf.cpp +++ b/plugins/Dbx_kyoto/src/dbintf.cpp @@ -25,18 +25,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define DBHEADER_SIGNATURE _T("KyotoCabinet")
+#define CMP_UINT32(A,B) if(A!=B) return (A<B)?-1:1;
+
struct SettingsComparator : public Comparator
{
SettingsComparator() {}
virtual int32_t compare(const char *akbuf, size_t, const char *bkbuf, size_t) { DBSettingSortingKey *k1 = (DBSettingSortingKey*)akbuf, *k2 = (DBSettingSortingKey*)bkbuf;
- if (k1->dwContactID < k2->dwContactID) return -1;
- if (k1->dwContactID > k2->dwContactID) return 1;
-
- if (k1->dwOfsModule < k2->dwOfsModule) return -1;
- if (k1->dwOfsModule > k2->dwOfsModule) return 1;
-
+ CMP_UINT32(k1->dwContactID, k2->dwContactID);
+ CMP_UINT32(k1->dwOfsModule, k2->dwOfsModule);
return strcmp(k1->szSettingName, k2->szSettingName);
} }
@@ -48,15 +46,9 @@ struct EventsComparator : public Comparator virtual int32_t compare(const char *akbuf, size_t, const char *bkbuf, size_t) { DBEventSortingKey *k1 = (DBEventSortingKey*)akbuf, *k2 = (DBEventSortingKey*)bkbuf;
- if (k1->dwContactId < k2->dwContactId) return -1;
- if (k1->dwContactId > k2->dwContactId) return 1;
-
- if (k1->ts < k2->ts) return -1;
- if (k1->ts > k2->ts) return 1;
-
- if (k1->dwEventId < k2->dwEventId) return -1;
- if (k1->dwEventId > k2->dwEventId) return 1;
-
+ CMP_UINT32(k1->dwContactId, k2->dwContactId);
+ CMP_UINT32(k1->ts, k2->ts);
+ CMP_UINT32(k1->dwEventId, k2->dwEventId);
return 0;
}
}
@@ -137,7 +129,7 @@ CDbxKyoto::~CDbxKyoto() int CDbxKyoto::Load(bool bSkipInit)
{
if (!bSkipInit) {
- int iFlags = TreeDB::OREADER | TreeDB::ONOREPAIR;
+ int iFlags = TreeDB::OREADER | TreeDB::ONOREPAIR | TreeDB::OCREATE;
if (!m_bReadOnly)
iFlags |= TreeDB::OWRITER;
@@ -206,19 +198,8 @@ int CDbxKyoto::Load(bool bSkipInit) int CDbxKyoto::Create(void)
{
- int iFlags = TreeDB::OREADER | TreeDB::OCREATE;
- if (!m_bReadOnly)
- iFlags |= TreeDB::OWRITER;
-
WritePrivateProfileString(_T("Database"), _T("Version"), _T("1"), m_tszProfileName);
WritePrivateProfileString(_T("Database"), _T("Signature"), DBHEADER_SIGNATURE, m_tszProfileName);
-
- std::string szFilename((char*)_T2A(m_tszProfileName));
- if (!m_dbContacts.open(szFilename + ".cnt", iFlags)) return EGROKPRF_DAMAGED;
- if (!m_dbModules.open(szFilename + ".mod", iFlags)) return EGROKPRF_DAMAGED;
- if (!m_dbEvents.open(szFilename + ".evt", iFlags)) return EGROKPRF_DAMAGED;
- if (!m_dbEventsSort.open(szFilename + ".evs", iFlags)) return EGROKPRF_DAMAGED;
- if (!m_dbSettings.open(szFilename + ".set", iFlags)) return EGROKPRF_DAMAGED;
return 0;
}
diff --git a/plugins/Dbx_kyoto/src/dbintf.h b/plugins/Dbx_kyoto/src/dbintf.h index 3d05288d26..9e75bd2804 100644 --- a/plugins/Dbx_kyoto/src/dbintf.h +++ b/plugins/Dbx_kyoto/src/dbintf.h @@ -99,14 +99,13 @@ struct DBEvent struct DBEventSortingKey
{
- DWORD dwContactId, ts, dwEventId;
+ uint32_t dwContactId, ts, dwEventId;
};
struct DBSettingSortingKey
{
- DWORD dwContactID;
- DWORD dwOfsModule;
- char szSettingName[100];
+ uint32_t dwContactID, dwOfsModule;
+ char szSettingName[100];
};
struct DBCachedContact : public DBCachedContactBase
diff --git a/plugins/Dbx_kyoto/src/dbsettings.cpp b/plugins/Dbx_kyoto/src/dbsettings.cpp index c1b4eea707..5edd642bf8 100644 --- a/plugins/Dbx_kyoto/src/dbsettings.cpp +++ b/plugins/Dbx_kyoto/src/dbsettings.cpp @@ -120,7 +120,7 @@ LBL_Seek: strncpy_s(keySearch.szSettingName, szSetting, _TRUNCATE);
char *rec = (char*)_alloca(65536);
- if (-1 == m_dbSettings.get((LPCSTR)&keySearch, 2 * sizeof(DWORD) + settingNameLen, rec, 65536)) {
+ if (-1 == m_dbSettings.get((LPCSTR)&keySearch, 2 * sizeof(DWORD) + settingNameLen+1, rec, 65536)) {
// try to get the missing mc setting from the active sub
if (cc && cc->IsMeta() && ValidLookupName(szModule, szSetting)) {
if (contactID = db_mc_getDefault(contactID)) {
@@ -503,7 +503,7 @@ STDMETHODIMP_(BOOL) CDbxKyoto::WriteContactSetting(MCONTACT contactID, DBCONTACT *(WORD*)pBlob = dbcwWork.value.cpbVal;
memcpy(pBlob+2, dbcwWork.value.pbVal, dbcwWork.value.cpbVal);
}
- m_dbSettings.set((LPCSTR)&keySearch, 2 * sizeof(DWORD) + settingNameLen, recData, recSize);
+ m_dbSettings.set((LPCSTR)&keySearch, 2 * sizeof(DWORD) + settingNameLen+1, recData, recSize);
lck.unlock();
// notify
@@ -541,7 +541,7 @@ STDMETHODIMP_(BOOL) CDbxKyoto::DeleteContactSetting(MCONTACT contactID, LPCSTR s keySearch.dwContactID = contactID;
keySearch.dwOfsModule = GetModuleNameOfs(szModule);
strncpy_s(keySearch.szSettingName, szSetting, _TRUNCATE);
- if (!m_dbSettings.remove((LPCSTR)&keySearch, 2 * sizeof(DWORD) + settingNameLen))
+ if (!m_dbSettings.remove((LPCSTR)&keySearch, 2 * sizeof(DWORD) + settingNameLen+1))
return 1;
}
@@ -576,13 +576,17 @@ STDMETHODIMP_(BOOL) CDbxKyoto::EnumContactSettings(MCONTACT contactID, DBCONTACT while (cursor->step()) {
size_t size, keySize;
const char *pRec, *key = cursor->get(&keySize, &pRec, &size);
+ if (key == NULL)
+ break;
+
DBSettingSortingKey *pKey = (DBSettingSortingKey*)key;
- if (pKey->dwContactID != contactID || pKey->dwOfsModule != keySearch.dwOfsModule)
+ if (pKey->dwContactID != contactID || pKey->dwOfsModule != keySearch.dwOfsModule) {
+ delete[] pKey;
break;
+ }
- char szSetting[256];
- strncpy_s(szSetting, pKey->szSettingName, keySize - sizeof(DWORD) * 2);
- result = (dbces->pfnEnumProc)(szSetting, dbces->lParam);
+ result = (dbces->pfnEnumProc)(pKey->szSettingName, dbces->lParam);
+ delete[] pKey;
}
return result;
|