diff options
author | George Hazan <george.hazan@gmail.com> | 2014-03-07 14:47:31 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-03-07 14:47:31 +0000 |
commit | 7cd8f6ec7632a697bc52ed2509981bfae3873be9 (patch) | |
tree | 7af76d88342c014f8a25e14c66e1e4879b23ba82 /plugins/Db3x_mmap | |
parent | 574ce873c3b0eb608186c03af324d841f32465a6 (diff) |
guarding merge/split functions
git-svn-id: http://svn.miranda-ng.org/main/trunk@8447 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 | 206 |
2 files changed, 115 insertions, 93 deletions
diff --git a/plugins/Db3x_mmap/src/commonheaders.h b/plugins/Db3x_mmap/src/commonheaders.h index 6fac634f56..4ddc34de68 100644 --- a/plugins/Db3x_mmap/src/commonheaders.h +++ b/plugins/Db3x_mmap/src/commonheaders.h @@ -24,6 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define _CRT_SECURE_NO_WARNINGS
#define _WIN32_WINNT 0x0501
+#pragma warning(disable:4509)
+
#include <windows.h>
#include <time.h>
#include <process.h>
diff --git a/plugins/Db3x_mmap/src/dbcontacts.cpp b/plugins/Db3x_mmap/src/dbcontacts.cpp index 3277114de6..1fba90777f 100644 --- a/plugins/Db3x_mmap/src/dbcontacts.cpp +++ b/plugins/Db3x_mmap/src/dbcontacts.cpp @@ -232,64 +232,76 @@ BOOL CDb3Mmap::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) if (dbSub->ofsFirstEvent == 0) // hurrah, nothing to do
return 0;
- if (dbMeta->ofsFirstEvent == 0) { // simply chain history to a meta
- dbMeta->eventCount = dbSub->eventCount;
- dbMeta->ofsFirstEvent = dbSub->ofsFirstEvent;
- dbMeta->ofsLastEvent = dbSub->ofsLastEvent;
- dbMeta->ofsFirstUnread = dbSub->ofsFirstUnread;
- dbMeta->tsFirstUnread = dbSub->tsFirstUnread;
- }
- else {
- // there're events in both meta's & sub's event chains
- // relink sub's event chain to meta without changing events themselves
- LIST<DBEvent> arEvents(20000, SortEvent);
- for (DWORD ofsMeta = dbMeta->ofsFirstEvent; ofsMeta != 0;) {
- DBEvent *pev = (DBEvent*)DBRead(ofsMeta, sizeof(DBEvent), NULL);
- if (pev->signature != DBEVENT_SIGNATURE) // broken chain, don't touch it
- return 2;
-
- arEvents.insert(pev);
- ofsMeta = pev->ofsNext;
+ LIST<DBEvent> arEvents(20000, SortEvent);
+ BOOL ret = 0;
+ __try {
+ if (dbMeta->ofsFirstEvent == 0) { // simply chain history to a meta
+ dbMeta->eventCount = dbSub->eventCount;
+ dbMeta->ofsFirstEvent = dbSub->ofsFirstEvent;
+ dbMeta->ofsLastEvent = dbSub->ofsLastEvent;
+ dbMeta->ofsFirstUnread = dbSub->ofsFirstUnread;
+ dbMeta->tsFirstUnread = dbSub->tsFirstUnread;
}
+ else {
+ // there're events in both meta's & sub's event chains
+ // relink sub's event chain to meta without changing events themselves
+ for (DWORD ofsMeta = dbMeta->ofsFirstEvent; ofsMeta != 0;) {
+ DBEvent *pev = (DBEvent*)DBRead(ofsMeta, sizeof(DBEvent), NULL);
+ if (pev->signature != DBEVENT_SIGNATURE) { // broken chain, don't touch it
+ ret = 2;
+ __leave;
+ }
- for (DWORD ofsSub = dbSub->ofsFirstEvent; ofsSub != 0;) {
- DBEvent *pev = (DBEvent*)DBRead(ofsSub, sizeof(DBEvent), NULL);
- if (pev->signature != DBEVENT_SIGNATURE) // broken chain, don't touch it
- return 2;
+ arEvents.insert(pev);
+ ofsMeta = pev->ofsNext;
+ }
- pev->contactID = ccSub->contactID;
- arEvents.insert(pev);
- ofsSub = pev->ofsNext;
- }
+ for (DWORD ofsSub = dbSub->ofsFirstEvent; ofsSub != 0;) {
+ DBEvent *pev = (DBEvent*)DBRead(ofsSub, sizeof(DBEvent), NULL);
+ if (pev->signature != DBEVENT_SIGNATURE) { // broken chain, don't touch it
+ ret = 2;
+ __leave;
+ }
+
+ pev->contactID = ccSub->contactID;
+ arEvents.insert(pev);
+ ofsSub = pev->ofsNext;
+ }
- // all events are in memory, valid & sorted in the right order.
- // ready? steady? go!
- dbMeta->eventCount = arEvents.getCount();
+ // all events are in memory, valid & sorted in the right order.
+ // ready? steady? go!
+ dbMeta->eventCount = arEvents.getCount();
- DBEvent *pFirst = arEvents[0];
- dbMeta->ofsFirstEvent = DWORD(PBYTE(pFirst) - m_pDbCache);
- pFirst->ofsPrev = 0;
- dbMeta->ofsFirstUnread = (pFirst->flags & NOT_UNREAD) ? 0 : dbMeta->ofsFirstEvent;
+ DBEvent *pFirst = arEvents[0];
+ dbMeta->ofsFirstEvent = DWORD(PBYTE(pFirst) - m_pDbCache);
+ pFirst->ofsPrev = 0;
+ dbMeta->ofsFirstUnread = (pFirst->flags & NOT_UNREAD) ? 0 : dbMeta->ofsFirstEvent;
- DBEvent *pLast = arEvents[arEvents.getCount()-1];
- dbMeta->ofsLastEvent = DWORD(PBYTE(pLast) - m_pDbCache);
- pLast->ofsNext = 0;
+ DBEvent *pLast = arEvents[arEvents.getCount() - 1];
+ dbMeta->ofsLastEvent = DWORD(PBYTE(pLast) - m_pDbCache);
+ pLast->ofsNext = 0;
- for (int i = 1; i < arEvents.getCount(); i++) {
- DBEvent *pPrev = arEvents[i-1], *pNext = arEvents[i];
- pPrev->ofsNext = DWORD(PBYTE(pNext) - m_pDbCache);
- pNext->ofsPrev = DWORD(PBYTE(pPrev) - m_pDbCache);
+ for (int i = 1; i < arEvents.getCount(); i++) {
+ DBEvent *pPrev = arEvents[i - 1], *pNext = arEvents[i];
+ pPrev->ofsNext = DWORD(PBYTE(pNext) - m_pDbCache);
+ pNext->ofsPrev = DWORD(PBYTE(pPrev) - m_pDbCache);
- if (dbMeta->ofsFirstUnread == 0 && !(pNext->flags & NOT_UNREAD))
- dbMeta->ofsFirstUnread = pPrev->ofsNext;
+ if (dbMeta->ofsFirstUnread == 0 && !(pNext->flags & NOT_UNREAD))
+ dbMeta->ofsFirstUnread = pPrev->ofsNext;
+ }
}
+
+ // remove any traces of history from sub
+ dbSub->eventCount = 0;
+ dbSub->ofsFirstEvent = dbSub->ofsLastEvent = dbSub->ofsFirstUnread = dbSub->tsFirstUnread = 0;
+ }
+ __except (EXCEPTION_EXECUTE_HANDLER)
+ {
+ ret = 3;
}
- // remove any traces of history from sub
- dbSub->eventCount = 0;
- dbSub->ofsFirstEvent = dbSub->ofsLastEvent = dbSub->ofsFirstUnread = dbSub->tsFirstUnread = 0;
FlushViewOfFile(m_pDbCache, 0);
- return 0;
+ return ret;
}
BOOL CDb3Mmap::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub)
@@ -314,61 +326,69 @@ BOOL CDb3Mmap::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) dwOffset = dwNext;
}
- DWORD dwOffset = dbMeta.ofsFirstEvent;
- DBEvent *evMeta = NULL, *evSub = NULL;
- dbSub.eventCount = 0; dbSub.ofsFirstEvent = dbSub.ofsLastEvent = dbSub.ofsFirstUnread = dbSub.tsFirstUnread = 0;
- dbMeta.eventCount = 0; dbMeta.ofsFirstEvent = dbMeta.ofsLastEvent = dbMeta.ofsFirstUnread = dbMeta.tsFirstUnread = 0;
-
- while (dwOffset != 0) {
- DBEvent *evCurr = (DBEvent*)DBRead(dwOffset, sizeof(DBEvent), NULL);
- if (evCurr->signature != DBEVENT_SIGNATURE)
- break;
-
- DWORD dwNext = evCurr->ofsNext; evCurr->ofsNext = 0;
-
- // extract it to sub's chain
- if (evCurr->contactID == ccSub->contactID) {
- dbSub.eventCount++;
- if (evSub != NULL) {
- evSub->ofsNext = dwOffset;
- evCurr->ofsPrev = DWORD(PBYTE(evSub) - m_pDbCache);
- }
- else {
- dbSub.ofsFirstEvent = dwOffset;
- evCurr->ofsPrev = 0;
- }
- if (dbSub.ofsFirstUnread == 0 && !(evCurr->flags & NOT_UNREAD)) {
- dbSub.ofsFirstUnread = dwOffset;
- dbSub.tsFirstUnread = evCurr->timestamp;
- }
- dbSub.ofsLastEvent = dwOffset;
- evSub = evCurr;
- }
- else {
- dbMeta.eventCount++;
- if (evMeta != NULL) {
- evMeta->ofsNext = dwOffset;
- evCurr->ofsPrev = DWORD(PBYTE(evMeta) - m_pDbCache);
+ BOOL ret = 0;
+ __try {
+ DWORD dwOffset = dbMeta.ofsFirstEvent;
+ DBEvent *evMeta = NULL, *evSub = NULL;
+ dbSub.eventCount = 0; dbSub.ofsFirstEvent = dbSub.ofsLastEvent = dbSub.ofsFirstUnread = dbSub.tsFirstUnread = 0;
+ dbMeta.eventCount = 0; dbMeta.ofsFirstEvent = dbMeta.ofsLastEvent = dbMeta.ofsFirstUnread = dbMeta.tsFirstUnread = 0;
+
+ while (dwOffset != 0) {
+ DBEvent *evCurr = (DBEvent*)DBRead(dwOffset, sizeof(DBEvent), NULL);
+ if (evCurr->signature != DBEVENT_SIGNATURE)
+ break;
+
+ DWORD dwNext = evCurr->ofsNext; evCurr->ofsNext = 0;
+
+ // extract it to sub's chain
+ if (evCurr->contactID == ccSub->contactID) {
+ dbSub.eventCount++;
+ if (evSub != NULL) {
+ evSub->ofsNext = dwOffset;
+ evCurr->ofsPrev = DWORD(PBYTE(evSub) - m_pDbCache);
+ }
+ else {
+ dbSub.ofsFirstEvent = dwOffset;
+ evCurr->ofsPrev = 0;
+ }
+ if (dbSub.ofsFirstUnread == 0 && !(evCurr->flags & NOT_UNREAD)) {
+ dbSub.ofsFirstUnread = dwOffset;
+ dbSub.tsFirstUnread = evCurr->timestamp;
+ }
+ dbSub.ofsLastEvent = dwOffset;
+ evSub = evCurr;
}
else {
- dbMeta.ofsFirstEvent = dwOffset;
- evCurr->ofsPrev = 0;
- }
- if (dbMeta.ofsFirstUnread == 0 && !(evCurr->flags & NOT_UNREAD)) {
- dbMeta.ofsFirstUnread = dwOffset;
- dbMeta.tsFirstUnread = evCurr->timestamp;
+ dbMeta.eventCount++;
+ if (evMeta != NULL) {
+ evMeta->ofsNext = dwOffset;
+ evCurr->ofsPrev = DWORD(PBYTE(evMeta) - m_pDbCache);
+ }
+ else {
+ dbMeta.ofsFirstEvent = dwOffset;
+ evCurr->ofsPrev = 0;
+ }
+ if (dbMeta.ofsFirstUnread == 0 && !(evCurr->flags & NOT_UNREAD)) {
+ dbMeta.ofsFirstUnread = dwOffset;
+ dbMeta.tsFirstUnread = evCurr->timestamp;
+ }
+ dbMeta.ofsLastEvent = dwOffset;
+ evMeta = evCurr;
}
- dbMeta.ofsLastEvent = dwOffset;
- evMeta = evCurr;
+
+ dwOffset = dwNext;
}
- dwOffset = dwNext;
+ DBWrite(ccSub->dwDriverData, &dbSub, sizeof(DBContact));
+ DBWrite(ccMeta->dwDriverData, &dbMeta, sizeof(DBContact));
+ }
+ __except (EXCEPTION_EXECUTE_HANDLER)
+ {
+ ret = 3;
}
- DBWrite(ccSub->dwDriverData, &dbSub, sizeof(DBContact));
- DBWrite(ccMeta->dwDriverData, &dbMeta, sizeof(DBContact));
FlushViewOfFile(m_pDbCache, 0);
- return 0;
+ return ret;
}
/////////////////////////////////////////////////////////////////////////////////////////
|