summaryrefslogtreecommitdiff
path: root/plugins/Dbx_mdb/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-03-10 19:03:29 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-03-10 19:03:29 +0000
commit6d8085a6bc3847734cfdfd497055bc0f9ec8f9c5 (patch)
treef6e79bbceca7c3bd5e0876618be3799d38aaedef /plugins/Dbx_mdb/src
parent2927b24587cf46907242792bf6190b3c607cbea5 (diff)
fix for the events' sorting order
git-svn-id: http://svn.miranda-ng.org/main/trunk@12377 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dbx_mdb/src')
-rw-r--r--plugins/Dbx_mdb/src/commonheaders.h1
-rw-r--r--plugins/Dbx_mdb/src/dbevents.cpp54
-rw-r--r--plugins/Dbx_mdb/src/dbintf.h2
-rw-r--r--plugins/Dbx_mdb/src/lmdb/mdb.c2
4 files changed, 40 insertions, 19 deletions
diff --git a/plugins/Dbx_mdb/src/commonheaders.h b/plugins/Dbx_mdb/src/commonheaders.h
index e68a261e56..50959d158f 100644
--- a/plugins/Dbx_mdb/src/commonheaders.h
+++ b/plugins/Dbx_mdb/src/commonheaders.h
@@ -42,6 +42,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <m_crypto.h>
#include <m_metacontacts.h>
#include <m_protocols.h>
+#include <m_netlib.h>
extern "C"
{
diff --git a/plugins/Dbx_mdb/src/dbevents.cpp b/plugins/Dbx_mdb/src/dbevents.cpp
index ea9b27b390..cb6cc7ab3d 100644
--- a/plugins/Dbx_mdb/src/dbevents.cpp
+++ b/plugins/Dbx_mdb/src/dbevents.cpp
@@ -88,7 +88,7 @@ STDMETHODIMP_(MEVENT) CDbxMdb::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
memcpy(pDest + sizeof(DBEvent), pBlob, dbe.cbBlob);
// add a sorting key
- DBEventSortingKey key2 = { contactID, dbe.timestamp, dwEventId };
+ DBEventSortingKey key2 = { dwEventId, dbe.timestamp, contactID };
key.mv_size = sizeof(key2); key.mv_data = &key2;
data.mv_size = 1; data.mv_data = "";
MDB_CHECK(mdb_put(txn, m_dbEventsSort, &key, &data, 0), 0);
@@ -137,7 +137,7 @@ STDMETHODIMP_(BOOL) CDbxMdb::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent)
DBEvent *dbe = (DBEvent*)data.mv_data;
DWORD dwSavedContact = dbe->contactID;
- DBEventSortingKey key2 = { contactID, dbe->timestamp, hDbEvent };
+ DBEventSortingKey key2 = { hDbEvent, dbe->timestamp, contactID };
mdb_del(txn, m_dbEvents, &key, &data);
// remove a sorting key
@@ -265,7 +265,7 @@ STDMETHODIMP_(BOOL) CDbxMdb::MarkEventRead(MCONTACT contactID, MEVENT hDbEvent)
if (dbe->markedRead())
return dbe->flags;
- DBEventSortingKey key2 = { contactID, dbe->timestamp, hDbEvent };
+ DBEventSortingKey key2 = { hDbEvent, dbe->timestamp, contactID };
dbe->flags |= DBEF_READ;
mdb_put(txn, m_dbEvents, &key, &data, 0);
@@ -297,7 +297,7 @@ STDMETHODIMP_(MCONTACT) CDbxMdb::GetEventContact(MEVENT hDbEvent)
STDMETHODIMP_(MEVENT) CDbxMdb::FindFirstEvent(MCONTACT contactID)
{
- DBEventSortingKey keyVal = { contactID, 0, 0 };
+ DBEventSortingKey keyVal = { 0, 0, contactID };
MDB_val key = { sizeof(keyVal), &keyVal }, data;
mir_cslock lck(m_csDbAccess);
@@ -305,11 +305,14 @@ STDMETHODIMP_(MEVENT) CDbxMdb::FindFirstEvent(MCONTACT contactID)
cursor_ptr cursor(txn, m_dbEventsSort);
mdb_cursor_get(cursor, &key, &data, MDB_SET_KEY);
- if (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) != MDB_SUCCESS)
+ if (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) != MDB_SUCCESS) {
+ // Netlib_Logf(NULL, "FindFirstEvent(%d): error", contactID);
return 0;
+ }
DBEventSortingKey *pKey = (DBEventSortingKey*)key.mv_data;
- return (pKey->dwContactId == contactID) ? pKey->dwEventId : 0;
+ // Netlib_Logf(NULL, "FindFirstEvent(%d): %d %d %d", contactID, pKey->dwContactId, pKey->ts, pKey->dwEventId);
+ return (pKey->dwContactId == contactID) ? pKey->dwEventId : 0;
}
STDMETHODIMP_(MEVENT) CDbxMdb::FindFirstUnreadEvent(MCONTACT contactID)
@@ -320,18 +323,21 @@ STDMETHODIMP_(MEVENT) CDbxMdb::FindFirstUnreadEvent(MCONTACT contactID)
STDMETHODIMP_(MEVENT) CDbxMdb::FindLastEvent(MCONTACT contactID)
{
- DBEventSortingKey keyVal = { contactID, -1, -1 };
+ DBEventSortingKey keyVal = { 0xFFFFFFFF, 0xFFFFFFFF, contactID };
MDB_val key = { sizeof(keyVal), &keyVal }, data;
mir_cslock lck(m_csDbAccess);
txn_ptr txn(m_pMdbEnv, true);
-
+
cursor_ptr cursor(txn, m_dbEventsSort);
mdb_cursor_get(cursor, &key, &data, MDB_SET_KEY);
- if (mdb_cursor_get(cursor, &key, &data, MDB_PREV) != MDB_SUCCESS)
+ if (mdb_cursor_get(cursor, &key, &data, MDB_PREV) != MDB_SUCCESS) {
+ // Netlib_Logf(NULL, "FindLastEvent(%d): error", contactID);
return 0;
+ }
DBEventSortingKey *pKey = (DBEventSortingKey*)key.mv_data;
+ // Netlib_Logf(NULL, "FindLastEvent(%d): %d %d %d", contactID, pKey->dwContactId, pKey->ts, pKey->dwEventId);
return (pKey->dwContactId == contactID) ? pKey->dwEventId : 0;
}
@@ -342,20 +348,27 @@ STDMETHODIMP_(MEVENT) CDbxMdb::FindNextEvent(MCONTACT contactID, MEVENT hDbEvent
mir_cslock lck(m_csDbAccess);
txn_ptr txn(m_pMdbEnv, true);
- if (mdb_get(txn, m_dbEvents, &key, &data) != MDB_SUCCESS)
+ if (mdb_get(txn, m_dbEvents, &key, &data) != MDB_SUCCESS) {
+ // Netlib_Logf(NULL, "FindNextEvent(%d, %d): no event", contactID, hDbEvent);
return 0;
+ }
DBEvent *dbe = (DBEvent*)data.mv_data;
- DBEventSortingKey keyVal = { contactID, dbe->timestamp, hDbEvent };
+ DBEventSortingKey keyVal = { hDbEvent, dbe->timestamp, contactID };
key.mv_size = sizeof(keyVal); key.mv_data = &keyVal;
cursor_ptr cursor(txn, m_dbEventsSort);
- if (mdb_cursor_get(cursor, &key, &data, MDB_SET_KEY) != MDB_SUCCESS)
+ if (mdb_cursor_get(cursor, &key, &data, MDB_SET_KEY) != MDB_SUCCESS) {
+ // Netlib_Logf(NULL, "FindNextEvent(%d, %d): set error", contactID, hDbEvent);
return 0;
- if (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) != MDB_SUCCESS)
+ }
+ if (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) != MDB_SUCCESS) {
+ // Netlib_Logf(NULL, "FindNextEvent(%d, %d): next error", contactID, hDbEvent);
return 0;
+ }
DBEventSortingKey *pKey = (DBEventSortingKey*)key.mv_data;
+ // Netlib_Logf(NULL, "FindNextEvent(%d, %d): %d %d %d", contactID, hDbEvent, pKey->dwContactId, pKey->ts, pKey->dwEventId);
return (pKey->dwContactId == contactID) ? pKey->dwEventId : 0;
}
@@ -366,20 +379,27 @@ STDMETHODIMP_(MEVENT) CDbxMdb::FindPrevEvent(MCONTACT contactID, MEVENT hDbEvent
mir_cslock lck(m_csDbAccess);
txn_ptr txn(m_pMdbEnv, true);
- if (mdb_get(txn, m_dbEvents, &key, &data) != MDB_SUCCESS)
+ if (mdb_get(txn, m_dbEvents, &key, &data) != MDB_SUCCESS) {
+ // Netlib_Logf(NULL, "FindPrevEvent(%d, %d): no event", contactID, hDbEvent);
return 0;
+ }
DBEvent *dbe = (DBEvent*)data.mv_data;
- DBEventSortingKey keyVal = { contactID, dbe->timestamp, hDbEvent };
+ DBEventSortingKey keyVal = { hDbEvent, dbe->timestamp, contactID };
key.mv_size = sizeof(keyVal); key.mv_data = &keyVal;
cursor_ptr cursor(txn, m_dbEventsSort);
- if (mdb_cursor_get(cursor, &key, &data, MDB_SET_KEY) != MDB_SUCCESS)
+ if (mdb_cursor_get(cursor, &key, &data, MDB_SET_KEY) != MDB_SUCCESS) {
+ // Netlib_Logf(NULL, "FindPrevEvent(%d, %d): set error", contactID, hDbEvent);
return 0;
- if (mdb_cursor_get(cursor, &key, &data, MDB_PREV) != MDB_SUCCESS)
+ }
+ if (mdb_cursor_get(cursor, &key, &data, MDB_PREV) != MDB_SUCCESS) {
+ // Netlib_Logf(NULL, "FindPrevEvent(%d, %d): prev error", contactID, hDbEvent);
return 0;
+ }
DBEventSortingKey *pKey = (DBEventSortingKey*)key.mv_data;
+ // Netlib_Logf(NULL, "FindPrevEvent(%d, %d): %d %d %d", contactID, hDbEvent, pKey->dwContactId, pKey->ts, pKey->dwEventId);
return (pKey->dwContactId == contactID) ? pKey->dwEventId : 0;
}
diff --git a/plugins/Dbx_mdb/src/dbintf.h b/plugins/Dbx_mdb/src/dbintf.h
index 5590b44c09..f36e64383b 100644
--- a/plugins/Dbx_mdb/src/dbintf.h
+++ b/plugins/Dbx_mdb/src/dbintf.h
@@ -107,7 +107,7 @@ struct DBEvent
struct DBEventSortingKey
{
- DWORD dwContactId, ts, dwEventId;
+ DWORD dwEventId, ts, dwContactId;
};
struct DBCachedContact : public DBCachedContactBase
diff --git a/plugins/Dbx_mdb/src/lmdb/mdb.c b/plugins/Dbx_mdb/src/lmdb/mdb.c
index 2ab6bda0c5..65ac5b7d74 100644
--- a/plugins/Dbx_mdb/src/lmdb/mdb.c
+++ b/plugins/Dbx_mdb/src/lmdb/mdb.c
@@ -4962,7 +4962,7 @@ mdb_node_search(MDB_cursor *mc, MDB_val *key, int *exactp)
if (cmp == mdb_cmp_cint && IS_BRANCH(mp)) {
if (NODEPTR(mp, 1)->mn_ksize == sizeof(size_t))
cmp = mdb_cmp_long;
- else
+ else if(NODEPTR(mp, 1)->mn_ksize == sizeof(int))
cmp = mdb_cmp_int;
}