diff options
author | George Hazan <george.hazan@gmail.com> | 2014-03-12 15:18:23 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-03-12 15:18:23 +0000 |
commit | 84c4cf586edb825d669c21528d6821918ddd7f0c (patch) | |
tree | 516185cf651b8f20de5fb6d6ebc1125c14b36159 /plugins/Db3x_mmap | |
parent | fab0ad41fc5a614a3d9710e9dfc9ed7850fa34c3 (diff) |
transparent access for subs' events
git-svn-id: http://svn.miranda-ng.org/main/trunk@8582 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Db3x_mmap')
-rw-r--r-- | plugins/Db3x_mmap/src/commonheaders.h | 2 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/dbcontacts.cpp | 2 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/dbevents.cpp | 113 |
3 files changed, 103 insertions, 14 deletions
diff --git a/plugins/Db3x_mmap/src/commonheaders.h b/plugins/Db3x_mmap/src/commonheaders.h index 4ddc34de68..b6274b4868 100644 --- a/plugins/Db3x_mmap/src/commonheaders.h +++ b/plugins/Db3x_mmap/src/commonheaders.h @@ -47,6 +47,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "resource.h"
#include "version.h"
+#define NOT_UNREAD (DBEF_READ | DBEF_SENT)
+
extern HINSTANCE g_hInst;
extern LIST<CDb3Mmap> g_Dbs;
extern DBSignature dbSignatureU, dbSignatureE, dbSignatureIM, dbSignatureSA;
diff --git a/plugins/Db3x_mmap/src/dbcontacts.cpp b/plugins/Db3x_mmap/src/dbcontacts.cpp index 7365fb5bd9..bdc60424f6 100644 --- a/plugins/Db3x_mmap/src/dbcontacts.cpp +++ b/plugins/Db3x_mmap/src/dbcontacts.cpp @@ -23,8 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "commonheaders.h"
-#define NOT_UNREAD (DBEF_READ | DBEF_SENT)
-
int CDb3Mmap::CheckProto(DBCachedContact *cc, const char *proto)
{
if (cc->szProto == NULL) {
diff --git a/plugins/Db3x_mmap/src/dbevents.cpp b/plugins/Db3x_mmap/src/dbevents.cpp index 5f02dd2586..9ed871c5f1 100644 --- a/plugins/Db3x_mmap/src/dbevents.cpp +++ b/plugins/Db3x_mmap/src/dbevents.cpp @@ -327,41 +327,130 @@ STDMETHODIMP_(MCONTACT) CDb3Mmap::GetEventContact(HANDLE hDbEvent) STDMETHODIMP_(HANDLE) CDb3Mmap::FindFirstEvent(MCONTACT contactID)
{
+ DBCachedContact *cc = (contactID) ? m_cache->GetCachedContact(contactID) : NULL;
+
mir_cslock lck(m_csDbAccess);
- DWORD ofsContact = GetContactOffset(contactID);
- DBContact *dbc = (DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
- return (dbc->signature != DBCONTACT_SIGNATURE) ? 0 : (HANDLE)dbc->ofsFirstEvent;
+ DBContact *dbc = (DBContact*)DBRead((cc) ? cc->dwDriverData : m_dbHeader.ofsUser, sizeof(DBContact), NULL);
+ if (dbc->signature != DBCONTACT_SIGNATURE)
+ return NULL;
+ if (!cc || !cc->IsSub())
+ return HANDLE(dbc->ofsFirstEvent);
+
+ if ((cc = m_cache->GetCachedContact(cc->parentID)) == NULL)
+ return NULL;
+ dbc = (DBContact*)DBRead(cc->dwDriverData, sizeof(DBContact), NULL);
+ if (dbc->signature != DBCONTACT_SIGNATURE)
+ return NULL;
+
+ for (DWORD dwOffset = dbc->ofsFirstEvent; dwOffset != 0;) {
+ DBEvent *dbe = (DBEvent*)DBRead(dwOffset, sizeof(DBEvent), NULL);
+ if (dbe->signature != DBEVENT_SIGNATURE)
+ return NULL;
+ if (dbe->contactID == contactID)
+ return HANDLE(dwOffset);
+ dwOffset = dbe->ofsNext;
+ }
+ return NULL;
}
STDMETHODIMP_(HANDLE) CDb3Mmap::FindFirstUnreadEvent(MCONTACT contactID)
{
+ DBCachedContact *cc = (contactID) ? m_cache->GetCachedContact(contactID) : NULL;
+
mir_cslock lck(m_csDbAccess);
- DWORD ofsContact = GetContactOffset(contactID);
- DBContact *dbc = (DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
- return (dbc->signature != DBCONTACT_SIGNATURE) ? 0 : (HANDLE)dbc->ofsFirstUnread;
+ DBContact *dbc = (DBContact*)DBRead((cc) ? cc->dwDriverData : m_dbHeader.ofsUser, sizeof(DBContact), NULL);
+ if (dbc->signature != DBCONTACT_SIGNATURE)
+ return NULL;
+ if (!cc || !cc->IsSub())
+ return HANDLE(dbc->ofsFirstUnread);
+
+ if ((cc = m_cache->GetCachedContact(cc->parentID)) == NULL)
+ return NULL;
+ dbc = (DBContact*)DBRead(cc->dwDriverData, sizeof(DBContact), NULL);
+ if (dbc->signature != DBCONTACT_SIGNATURE)
+ return NULL;
+
+ for (DWORD dwOffset = dbc->ofsFirstUnread; dwOffset != 0;) {
+ DBEvent *dbe = (DBEvent*)DBRead(dwOffset, sizeof(DBEvent), NULL);
+ if (dbe->signature != DBEVENT_SIGNATURE)
+ return NULL;
+ if (dbe->contactID == contactID && !(dbe->flags & NOT_UNREAD))
+ return HANDLE(dwOffset);
+ dwOffset = dbe->ofsNext;
+ }
+ return NULL;
}
STDMETHODIMP_(HANDLE) CDb3Mmap::FindLastEvent(MCONTACT contactID)
{
+ DBCachedContact *cc = (contactID) ? m_cache->GetCachedContact(contactID) : NULL;
+
mir_cslock lck(m_csDbAccess);
- DWORD ofsContact = GetContactOffset(contactID);
- DBContact *dbc = (DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
- return (dbc->signature != DBCONTACT_SIGNATURE) ? 0 : (HANDLE)dbc->ofsLastEvent;
+ DBContact *dbc = (DBContact*)DBRead((cc) ? cc->dwDriverData : m_dbHeader.ofsUser, sizeof(DBContact), NULL);
+ if (dbc->signature != DBCONTACT_SIGNATURE)
+ return NULL;
+ if (!cc || !cc->IsSub())
+ return HANDLE(dbc->ofsLastEvent);
+
+ if ((cc = m_cache->GetCachedContact(cc->parentID)) == NULL)
+ return NULL;
+ dbc = (DBContact*)DBRead(cc->dwDriverData, sizeof(DBContact), NULL);
+ if (dbc->signature != DBCONTACT_SIGNATURE)
+ return NULL;
+
+ for (DWORD dwOffset = dbc->ofsLastEvent; dwOffset != 0;) {
+ DBEvent *dbe = (DBEvent*)DBRead(dwOffset, sizeof(DBEvent), NULL);
+ if (dbe->signature != DBEVENT_SIGNATURE)
+ return NULL;
+ if (dbe->contactID == contactID)
+ return HANDLE(dwOffset);
+ dwOffset = dbe->ofsPrev;
+ }
+ return NULL;
}
STDMETHODIMP_(HANDLE) CDb3Mmap::FindNextEvent(MCONTACT contactID, HANDLE hDbEvent)
{
+ DBCachedContact *cc = (contactID) ? m_cache->GetCachedContact(contactID) : NULL;
+
mir_cslock lck(m_csDbAccess);
DBEvent *dbe = (DBEvent*)DBRead((DWORD)hDbEvent, sizeof(DBEvent), NULL);
- return (dbe->signature != DBEVENT_SIGNATURE) ? 0 : (HANDLE)dbe->ofsNext;
+ if (dbe->signature != DBEVENT_SIGNATURE)
+ return NULL;
+ if (!cc || !cc->IsSub())
+ return HANDLE(dbe->ofsNext);
+
+ for (DWORD dwOffset = dbe->ofsNext; dwOffset != 0;) {
+ dbe = (DBEvent*)DBRead(dwOffset, sizeof(DBEvent), NULL);
+ if (dbe->signature != DBEVENT_SIGNATURE)
+ return NULL;
+ if (dbe->contactID == contactID)
+ return HANDLE(dwOffset);
+ dwOffset = dbe->ofsNext;
+ }
+ return NULL;
}
STDMETHODIMP_(HANDLE) CDb3Mmap::FindPrevEvent(MCONTACT contactID, HANDLE hDbEvent)
{
+ DBCachedContact *cc = (contactID) ? m_cache->GetCachedContact(contactID) : NULL;
+
mir_cslock lck(m_csDbAccess);
DBEvent *dbe = (DBEvent*)DBRead((DWORD)hDbEvent, sizeof(DBEvent), NULL);
- if (dbe->signature != DBEVENT_SIGNATURE) return 0;
- return (dbe->flags & DBEF_FIRST) ? 0 : (HANDLE)dbe->ofsPrev;
+ if (dbe->signature != DBEVENT_SIGNATURE)
+ return NULL;
+ if (!cc || !cc->IsSub())
+ return HANDLE(dbe->ofsPrev);
+
+ for (DWORD dwOffset = dbe->ofsPrev; dwOffset != 0;) {
+ dbe = (DBEvent*)DBRead(dwOffset, sizeof(DBEvent), NULL);
+ if (dbe->signature != DBEVENT_SIGNATURE)
+ return NULL;
+ if (dbe->contactID == contactID)
+ return HANDLE(dwOffset);
+ dwOffset = dbe->ofsPrev;
+ }
+ return NULL;
}
/////////////////////////////////////////////////////////////////////////////////////////
|