From ffed014ccd5370a5073594d55dd0dc88080e0b3d Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 18 Jan 2015 18:55:32 +0000 Subject: contacts cache details to be completely hidden from the outside world git-svn-id: http://svn.miranda-ng.org/main/trunk@11873 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Db3x_mmap/src/dbcontacts.cpp | 27 ++++++++++++++++----------- plugins/Db3x_mmap/src/dbevents.cpp | 12 ++++++------ plugins/Db3x_mmap/src/dbintf.h | 8 ++++++++ plugins/Dbx_mdb/src/dbcontacts.cpp | 15 ++++++++++----- plugins/Dbx_mdb/src/dbevents.cpp | 6 +++--- plugins/Dbx_mdb/src/dbintf.h | 14 +++++++++++++- plugins/TabSRMM/src/contactcache.cpp | 2 +- plugins/TabSRMM/src/utils.cpp | 4 ++-- 8 files changed, 59 insertions(+), 29 deletions(-) (limited to 'plugins') diff --git a/plugins/Db3x_mmap/src/dbcontacts.cpp b/plugins/Db3x_mmap/src/dbcontacts.cpp index 9946fe2f9a..b1c842448a 100644 --- a/plugins/Db3x_mmap/src/dbcontacts.cpp +++ b/plugins/Db3x_mmap/src/dbcontacts.cpp @@ -46,6 +46,11 @@ STDMETHODIMP_(LONG) CDb3Mmap::GetContactCount(void) return m_dbHeader.contactCount; } +STDMETHODIMP_(LONG) CDb3Mmap::GetContactSize(void) +{ + return sizeof(DBCachedContact); +} + STDMETHODIMP_(MCONTACT) CDb3Mmap::FindFirstContact(const char *szProto) { mir_cslock lck(m_csDbAccess); @@ -175,7 +180,7 @@ STDMETHODIMP_(MCONTACT) CDb3Mmap::AddContact() } DBCachedContact *cc = m_cache->AddContactToCache(dbc.dwContactID); - cc->dwDriverData = ofsNew; + cc->dwOfsContact = ofsNew; NotifyEventHooks(hContactAddedEvent, dbc.dwContactID, 0); return dbc.dwContactID; @@ -188,7 +193,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::IsDbContact(MCONTACT contactID) return FALSE; mir_cslock lck(m_csDbAccess); - DBContact *dbc = (DBContact*)DBRead(cc->dwDriverData, NULL); + DBContact *dbc = (DBContact*)DBRead(cc->dwOfsContact, NULL); if (dbc->signature == DBCONTACT_SIGNATURE) { m_cache->AddContactToCache(contactID); return TRUE; @@ -219,8 +224,8 @@ static int SortEvent(const DBEvent *p1, const DBEvent *p2) BOOL CDb3Mmap::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) { mir_cslock lck(m_csDbAccess); - DBContact *dbMeta = (DBContact*)DBRead(ccMeta->dwDriverData, NULL); - DBContact *dbSub = (DBContact*)DBRead(ccSub->dwDriverData, NULL); + DBContact *dbMeta = (DBContact*)DBRead(ccMeta->dwOfsContact, NULL); + DBContact *dbSub = (DBContact*)DBRead(ccSub->dwOfsContact, NULL); if (dbMeta->signature != DBCONTACT_SIGNATURE || dbSub->signature != DBCONTACT_SIGNATURE) return 1; @@ -303,8 +308,8 @@ BOOL CDb3Mmap::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) BOOL CDb3Mmap::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) { mir_cslock lck(m_csDbAccess); - DBContact dbMeta = *(DBContact*)DBRead(ccMeta->dwDriverData, NULL); - DBContact dbSub = *(DBContact*)DBRead(ccSub->dwDriverData, NULL); + DBContact dbMeta = *(DBContact*)DBRead(ccMeta->dwOfsContact, NULL); + DBContact dbSub = *(DBContact*)DBRead(ccSub->dwOfsContact, NULL); if (dbMeta.signature != DBCONTACT_SIGNATURE || dbSub.signature != DBCONTACT_SIGNATURE) return 1; @@ -366,8 +371,8 @@ BOOL CDb3Mmap::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) dwOffset = dwNext; } - DBWrite(ccSub->dwDriverData, &dbSub, sizeof(DBContact)); - DBWrite(ccMeta->dwDriverData, &dbMeta, sizeof(DBContact)); + DBWrite(ccSub->dwOfsContact, &dbSub, sizeof(DBContact)); + DBWrite(ccMeta->dwOfsContact, &dbMeta, sizeof(DBContact)); } __except (EXCEPTION_EXECUTE_HANDLER) { @@ -409,7 +414,7 @@ void CDb3Mmap::FillContacts() else dwContactID = m_dwMaxContactId++; DBCachedContact *cc = m_cache->AddContactToCache(dwContactID); - cc->dwDriverData = dwOffset; + cc->dwOfsContact = dwOffset; CheckProto(cc, ""); DBVARIANT dbv; dbv.type = DBVT_DWORD; @@ -480,7 +485,7 @@ void CDb3Mmap::FillContacts() // we don't need it anymore if (!GetContactSetting(hContact, META_PROTO, "MetaID", &dbv)) { DeleteContactSetting(hContact, META_PROTO, "MetaID"); - WipeContactHistory((DBContact*)DBRead(ccMeta->dwDriverData, NULL)); + WipeContactHistory((DBContact*)DBRead(ccMeta->dwOfsContact, NULL)); } for (int k = 0; k < ccMeta->nSubs; k++) { @@ -502,5 +507,5 @@ DWORD CDb3Mmap::GetContactOffset(MCONTACT contactID, DBCachedContact **pcc) DBCachedContact *cc = m_cache->GetCachedContact(contactID); if (pcc) *pcc = cc; - return (cc == NULL) ? 0 : cc->dwDriverData; + return (cc == NULL) ? 0 : cc->dwOfsContact; } diff --git a/plugins/Db3x_mmap/src/dbevents.cpp b/plugins/Db3x_mmap/src/dbevents.cpp index ee5f449288..7a79bd4327 100644 --- a/plugins/Db3x_mmap/src/dbevents.cpp +++ b/plugins/Db3x_mmap/src/dbevents.cpp @@ -142,7 +142,7 @@ STDMETHODIMP_(MEVENT) CDb3Mmap::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) else neednotify = m_safetyMode; if (ccSub != NULL) { - DBContact *pSub = (DBContact*)DBRead(ccSub->dwDriverData, NULL); + DBContact *pSub = (DBContact*)DBRead(ccSub->dwOfsContact, NULL); pSub->eventCount++; } @@ -174,7 +174,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent) else cc = NULL; mir_cslockfull lck(m_csDbAccess); - DWORD ofsContact = (cc) ? cc->dwDriverData : m_dbHeader.ofsUser; + DWORD ofsContact = (cc) ? cc->dwOfsContact : m_dbHeader.ofsUser; DBContact dbc = *(DBContact*)DBRead(ofsContact, NULL); DBEvent dbe = *(DBEvent*)DBRead((DWORD)hDbEvent, NULL); if (dbc.signature != DBCONTACT_SIGNATURE || dbe.signature != DBEVENT_SIGNATURE) @@ -318,7 +318,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::MarkEventRead(MCONTACT contactID, MEVENT hDbEvent) else cc = NULL; mir_cslockfull lck(m_csDbAccess); - DWORD ofsContact = (cc) ? cc->dwDriverData : m_dbHeader.ofsUser; + DWORD ofsContact = (cc) ? cc->dwOfsContact : m_dbHeader.ofsUser; DBContact dbc = *(DBContact*)DBRead(ofsContact, NULL); DBEvent *dbe = (DBEvent*)DBRead((DWORD)hDbEvent, NULL); if (dbe->signature != DBEVENT_SIGNATURE || dbc.signature != DBCONTACT_SIGNATURE) @@ -376,7 +376,7 @@ STDMETHODIMP_(MEVENT) CDb3Mmap::FindFirstEvent(MCONTACT contactID) if ((cc = m_cache->GetCachedContact(cc->parentID)) == NULL) return NULL; - dbc = (DBContact*)DBRead(cc->dwDriverData, NULL); + dbc = (DBContact*)DBRead(cc->dwOfsContact, NULL); if (dbc->signature != DBCONTACT_SIGNATURE) return NULL; @@ -405,7 +405,7 @@ STDMETHODIMP_(MEVENT) CDb3Mmap::FindFirstUnreadEvent(MCONTACT contactID) if ((cc = m_cache->GetCachedContact(cc->parentID)) == NULL) return NULL; - dbc = (DBContact*)DBRead(cc->dwDriverData, NULL); + dbc = (DBContact*)DBRead(cc->dwOfsContact, NULL); if (dbc->signature != DBCONTACT_SIGNATURE) return NULL; @@ -434,7 +434,7 @@ STDMETHODIMP_(MEVENT) CDb3Mmap::FindLastEvent(MCONTACT contactID) if ((cc = m_cache->GetCachedContact(cc->parentID)) == NULL) return NULL; - dbc = (DBContact*)DBRead(cc->dwDriverData, NULL); + dbc = (DBContact*)DBRead(cc->dwOfsContact, NULL); if (dbc->signature != DBCONTACT_SIGNATURE) return NULL; diff --git a/plugins/Db3x_mmap/src/dbintf.h b/plugins/Db3x_mmap/src/dbintf.h index df3d1cd949..761c28ede9 100644 --- a/plugins/Db3x_mmap/src/dbintf.h +++ b/plugins/Db3x_mmap/src/dbintf.h @@ -21,6 +21,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#define OWN_CACHED_CONTACT + #include /* tree diagram @@ -174,6 +176,11 @@ struct DBEvent #include +struct DBCachedContact : public DBCachedContactBase +{ + DWORD dwOfsContact; +}; + struct CDb3Mmap : public MIDatabase, public MIDatabaseChecker, public MZeroedObject { CDb3Mmap(const TCHAR *tszFileName, int mode); @@ -209,6 +216,7 @@ public: STDMETHODIMP_(LONG) DeleteContact(MCONTACT contactID); STDMETHODIMP_(MCONTACT) AddContact(void); STDMETHODIMP_(BOOL) IsDbContact(MCONTACT contactID); + STDMETHODIMP_(LONG) GetContactSize(void); STDMETHODIMP_(LONG) GetEventCount(MCONTACT contactID); STDMETHODIMP_(MEVENT) AddEvent(MCONTACT contactID, DBEVENTINFO *dbe); diff --git a/plugins/Dbx_mdb/src/dbcontacts.cpp b/plugins/Dbx_mdb/src/dbcontacts.cpp index cf13a782b9..14267ab9ff 100644 --- a/plugins/Dbx_mdb/src/dbcontacts.cpp +++ b/plugins/Dbx_mdb/src/dbcontacts.cpp @@ -46,6 +46,11 @@ STDMETHODIMP_(LONG) CDbxMdb::GetContactCount(void) return m_contactCount; } +STDMETHODIMP_(LONG) CDbxMdb::GetContactSize(void) +{ + return sizeof(DBCachedContact); +} + STDMETHODIMP_(MCONTACT) CDbxMdb::FindFirstContact(const char *szProto) { mir_cslock lck(m_csDbAccess); @@ -102,9 +107,8 @@ STDMETHODIMP_(MCONTACT) CDbxMdb::AddContact() { DWORD dwContactId; - DBContact dbc; + DBContact dbc = { 0 }; dbc.signature = DBCONTACT_SIGNATURE; - dbc.eventCount = 0; { mir_cslock lck(m_csDbAccess); dwContactId = m_dwMaxContactId++; @@ -119,8 +123,7 @@ STDMETHODIMP_(MCONTACT) CDbxMdb::AddContact() break; } - DBCachedContact *cc = m_cache->AddContactToCache(dwContactId); - cc->dwDriverData = 0; + m_cache->AddContactToCache(dwContactId); } NotifyEventHooks(hContactAddedEvent, dwContactId, 0); @@ -185,7 +188,9 @@ void CDbxMdb::FillContacts() DatabaseCorruption(NULL); DBCachedContact *cc = m_cache->AddContactToCache(*(DWORD*)key.mv_data); - cc->dwDriverData = dbc->eventCount; + cc->dwEventCount = dbc->eventCount; + cc->dwFirstUnread = dbc->dwFirstUnread; + cc->tsFirstUnread = dbc->tsFirstUnread; arContacts.insert(cc); } } diff --git a/plugins/Dbx_mdb/src/dbevents.cpp b/plugins/Dbx_mdb/src/dbevents.cpp index 5db1d6714b..720956817d 100644 --- a/plugins/Dbx_mdb/src/dbevents.cpp +++ b/plugins/Dbx_mdb/src/dbevents.cpp @@ -35,7 +35,7 @@ STDMETHODIMP_(LONG) CDbxMdb::GetEventCount(MCONTACT contactID) return m_header.eventCount; DBCachedContact *cc = m_cache->GetCachedContact(contactID); - return (cc == NULL) ? 0 : cc->dwDriverData; + return (cc == NULL) ? 0 : cc->dwEventCount; } STDMETHODIMP_(MEVENT) CDbxMdb::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) @@ -106,7 +106,7 @@ STDMETHODIMP_(MEVENT) CDbxMdb::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) return 0; if (contactID != NULL) { - DBContact dbc = { DBCONTACT_SIGNATURE, ++cc->dwDriverData }; + DBContact dbc = { DBCONTACT_SIGNATURE, ++cc->dwEventCount }; MDB_val keyc = { sizeof(int), &contactID }, datac = { sizeof(DBContact), &dbc }; mdb_put(txn, m_dbContacts, &keyc, &datac, 0); @@ -115,7 +115,7 @@ STDMETHODIMP_(MEVENT) CDbxMdb::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) key2.dwContactId = ccSub->contactID; mdb_put(txn, m_dbEventsSort, &key, &data, 0); - dbc.eventCount = ++ccSub->dwDriverData; + dbc.eventCount = ++ccSub->dwEventCount; keyc.mv_data = &ccSub->contactID; mdb_put(txn, m_dbContacts, &keyc, &datac, 0); } diff --git a/plugins/Dbx_mdb/src/dbintf.h b/plugins/Dbx_mdb/src/dbintf.h index cf9600eadf..ea3d2feb0f 100644 --- a/plugins/Dbx_mdb/src/dbintf.h +++ b/plugins/Dbx_mdb/src/dbintf.h @@ -21,6 +21,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#define OWN_CACHED_CONTACT + #include /* tree diagram @@ -73,6 +75,8 @@ struct DBContact { DWORD signature; DWORD eventCount; // number of events in the chain for this contact + DWORD tsFirstUnread; + DWORD dwFirstUnread; }; #define DBMODULENAME_SIGNATURE 0x4DDECADEu @@ -102,6 +106,13 @@ struct DBEvent #include +struct DBCachedContact : public DBCachedContactBase +{ + DWORD dwEventCount; + DWORD tsFirstUnread; + DWORD dwFirstUnread; +}; + struct CDbxMdb : public MIDatabase, public MIDatabaseChecker, public MZeroedObject { CDbxMdb(const TCHAR *tszFileName, int mode); @@ -126,7 +137,7 @@ struct CDbxMdb : public MIDatabase, public MIDatabaseChecker, public MZeroedObje __forceinline bool usesPassword() const { return m_bUsesPassword; } public: - STDMETHODIMP_(void) SetCacheSafetyMode(BOOL); + STDMETHODIMP_(void) SetCacheSafetyMode(BOOL); STDMETHODIMP_(LONG) GetContactCount(void); STDMETHODIMP_(MCONTACT) FindFirstContact(const char *szProto = NULL); @@ -134,6 +145,7 @@ public: STDMETHODIMP_(LONG) DeleteContact(MCONTACT contactID); STDMETHODIMP_(MCONTACT) AddContact(void); STDMETHODIMP_(BOOL) IsDbContact(MCONTACT contactID); + STDMETHODIMP_(LONG) GetContactSize(void); STDMETHODIMP_(LONG) GetEventCount(MCONTACT contactID); STDMETHODIMP_(MEVENT) AddEvent(MCONTACT contactID, DBEVENTINFO *dbe); diff --git a/plugins/TabSRMM/src/contactcache.cpp b/plugins/TabSRMM/src/contactcache.cpp index 65e1fedcd4..f7240bbf3c 100644 --- a/plugins/TabSRMM/src/contactcache.cpp +++ b/plugins/TabSRMM/src/contactcache.cpp @@ -33,7 +33,7 @@ static OBJLIST arContacts(50, NumericKeySortT); -static DBCachedContact ccInvalid = { 0 }; +static DBCachedContact ccInvalid; CContactCache::CContactCache(const MCONTACT hContact) { diff --git a/plugins/TabSRMM/src/utils.cpp b/plugins/TabSRMM/src/utils.cpp index 62ab6d02e7..d0c06d7821 100644 --- a/plugins/TabSRMM/src/utils.cpp +++ b/plugins/TabSRMM/src/utils.cpp @@ -147,11 +147,11 @@ search_again: } } if (!clr_found) { - size_t c_closing = colorname.find_first_of(_T("]"), 0); + size_t c_closing = colorname.find_first_of(_T("]"), 0); if (c_closing == colorname.npos) c_closing = colorname.length(); const TCHAR *wszColname = colorname.c_str(); - if (endmark != message.npos && c_closing > 2 && c_closing <= 6 && iswalnum(colorname[0]) && iswalnum(colorname[c_closing -1])) { + if (endmark != message.npos && c_closing > 2 && c_closing <= 6 && iswalnum(colorname[0]) && iswalnum(colorname[c_closing - 1])) { RTF_ColorAdd(wszColname, c_closing); if (!was_added) { clr_was_added = was_added = true; -- cgit v1.2.3