From 92fec1aa22df4c4f1213d33663637c00b753f451 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 22 Aug 2017 15:23:04 +0300 Subject: code cleaning --- plugins/Db3x_mmap/src/database.cpp | 4 +- plugins/Db3x_mmap/src/dbcache.cpp | 26 ++--- plugins/Db3x_mmap/src/dbcontacts.cpp | 65 +++++------ plugins/Db3x_mmap/src/dbcrypt.cpp | 64 +++++------ plugins/Db3x_mmap/src/dbevents.cpp | 150 ++++++++++++------------- plugins/Db3x_mmap/src/dbheaders.cpp | 12 +- plugins/Db3x_mmap/src/dbintf.cpp | 14 +-- plugins/Db3x_mmap/src/dbintf.h | 8 +- plugins/Db3x_mmap/src/dbmodulechain.cpp | 14 +-- plugins/Db3x_mmap/src/dbsettings.cpp | 68 +++++------ plugins/Db3x_mmap/src/dbtool/disk.cpp | 8 +- plugins/Db3x_mmap/src/dbtool/eventchain.cpp | 14 +-- plugins/Db3x_mmap/src/dbtool/initialchecks.cpp | 2 +- plugins/Db3x_mmap/src/dbtool/modulechain.cpp | 6 +- plugins/Db3x_mmap/src/init.cpp | 8 +- plugins/Db3x_mmap/src/ui.cpp | 6 +- 16 files changed, 235 insertions(+), 234 deletions(-) (limited to 'plugins') diff --git a/plugins/Db3x_mmap/src/database.cpp b/plugins/Db3x_mmap/src/database.cpp index 82a10d8005..d78dce8e58 100644 --- a/plugins/Db3x_mmap/src/database.cpp +++ b/plugins/Db3x_mmap/src/database.cpp @@ -76,7 +76,7 @@ DWORD CDb3Mmap::ReallocSpace(DWORD ofs, int oldSize, int newSize) ///////////////////////////////////////////////////////////////////////////////////////// static DWORD DatabaseCorrupted = 0; -static wchar_t *msg = NULL; +static wchar_t *msg = nullptr; static DWORD dwErr = 0; static wchar_t tszPanic[] = LPGENW("Miranda has detected corruption in your database. This corruption may be fixed by DbChecker plugin. Please download it from https://miranda-ng.org/p/DbChecker/. Miranda will now shut down."); @@ -115,7 +115,7 @@ void CDb3Mmap::DatabaseCorruption(wchar_t *text) lck.unlock(); if (kill) { - _beginthread(dbpanic, 0, NULL); + _beginthread(dbpanic, 0, nullptr); Sleep(INFINITE); } } diff --git a/plugins/Db3x_mmap/src/dbcache.cpp b/plugins/Db3x_mmap/src/dbcache.cpp index 277ac5298b..ede7a56f26 100644 --- a/plugins/Db3x_mmap/src/dbcache.cpp +++ b/plugins/Db3x_mmap/src/dbcache.cpp @@ -33,7 +33,7 @@ void CDb3Mmap::Map() else dwProtectMode = PAGE_READWRITE, dwAccess = FILE_MAP_ALL_ACCESS; - m_hMap = CreateFileMapping(m_hDbFile, NULL, dwProtectMode, 0, m_dwFileSize, NULL); + m_hMap = CreateFileMapping(m_hDbFile, nullptr, dwProtectMode, 0, m_dwFileSize, nullptr); if (m_hMap) { m_pDbCache = (PBYTE)MapViewOfFile(m_hMap, dwAccess, 0, 0, 0); if (!m_pDbCache) @@ -44,7 +44,7 @@ void CDb3Mmap::Map() void CDb3Mmap::ReMap(DWORD needed) { - KillTimer(NULL, m_flushBuffersTimerId); + KillTimer(nullptr, m_flushBuffersTimerId); log3("remapping %d + %d (file end: %d)", m_dwFileSize, needed, m_dbHeader.ofsFileEnd); @@ -61,7 +61,7 @@ void CDb3Mmap::ReMap(DWORD needed) } UnmapViewOfFile(m_pDbCache); - m_pDbCache = NULL; + m_pDbCache = nullptr; CloseHandle(m_hMap); Map(); @@ -92,12 +92,12 @@ PBYTE CDb3Mmap::DBRead(DWORD ofs, int *bytesAvail) // buggy read if (ofs >= m_dwFileSize) { //log2("read from outside %d@%08x",bytesRequired,ofs); - if (bytesAvail != NULL) + if (bytesAvail != nullptr) *bytesAvail = m_ChunkSize; return m_pNull; } //log3((ofs+bytesRequired > m_dwFileSize)?"read %d@%08x, only %d avaliable":"read %d@%08x",bytesRequired,ofs,m_dwFileSize-ofs); - if (bytesAvail != NULL) + if (bytesAvail != nullptr) *bytesAvail = m_dwFileSize - ofs; return m_pDbCache + ofs; } @@ -131,13 +131,13 @@ static VOID CALLBACK DoBufferFlushTimerProc(HWND, UINT, UINT_PTR idEvent, DWORD) if (!db->m_pDbCache) return; - KillTimer(NULL, db->m_flushBuffersTimerId); + KillTimer(nullptr, db->m_flushBuffersTimerId); log0("tflush1"); if (FlushViewOfFile(db->m_pDbCache, 0) == 0) { if (db->m_flushFailTick == 0) db->m_flushFailTick = GetTickCount(); else if (GetTickCount() - db->m_flushFailTick > 5000) - db->DatabaseCorruption(NULL); + db->DatabaseCorruption(nullptr); } else db->m_flushFailTick = 0; log0("tflush2"); @@ -153,20 +153,20 @@ void CDb3Mmap::DBFlush(int setting) if (m_flushFailTick == 0) m_flushFailTick = GetTickCount(); else if (GetTickCount() - m_flushFailTick > 5000) - DatabaseCorruption(NULL); + DatabaseCorruption(nullptr); } else m_flushFailTick = 0; } log0("nflush2"); return; } - KillTimer(NULL, m_flushBuffersTimerId); - m_flushBuffersTimerId = SetTimer(NULL, m_flushBuffersTimerId, 50, DoBufferFlushTimerProc); + KillTimer(nullptr, m_flushBuffersTimerId); + m_flushBuffersTimerId = SetTimer(nullptr, m_flushBuffersTimerId, 50, DoBufferFlushTimerProc); } int CDb3Mmap::InitMap(void) { - m_dwFileSize = GetFileSize(m_hDbFile, NULL); + m_dwFileSize = GetFileSize(m_hDbFile, nullptr); // Align to chunk if (!m_bReadOnly) { @@ -186,8 +186,8 @@ DWORD CDb3Mmap::GetSettingsGroupOfsByModuleNameOfs(DBContact *dbc, DWORD ofsModu { DWORD ofsThis = dbc->ofsFirstSettings; while (ofsThis) { - DBContactSettings *dbcs = (DBContactSettings*)DBRead(ofsThis, NULL); - if (dbcs->signature != DBCONTACTSETTINGS_SIGNATURE) DatabaseCorruption(NULL); + DBContactSettings *dbcs = (DBContactSettings*)DBRead(ofsThis, nullptr); + if (dbcs->signature != DBCONTACTSETTINGS_SIGNATURE) DatabaseCorruption(nullptr); if (dbcs->ofsModuleName == ofsModuleName) return ofsThis; diff --git a/plugins/Db3x_mmap/src/dbcontacts.cpp b/plugins/Db3x_mmap/src/dbcontacts.cpp index 86a7ebe403..55e4aa8c23 100644 --- a/plugins/Db3x_mmap/src/dbcontacts.cpp +++ b/plugins/Db3x_mmap/src/dbcontacts.cpp @@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. int CDb3Mmap::CheckProto(DBCachedContact *cc, const char *proto) { - if (cc->szProto == NULL) { + if (cc->szProto == nullptr) { char protobuf[MAX_PATH] = { 0 }; DBVARIANT dbv; dbv.type = DBVT_ASCIIZ; @@ -34,7 +34,7 @@ int CDb3Mmap::CheckProto(DBCachedContact *cc, const char *proto) if (GetContactSettingStatic(cc->contactID, "Protocol", "p", &dbv) != 0 || (dbv.type != DBVT_ASCIIZ)) return 0; - cc->szProto = m_cache->GetCachedSetting(NULL, protobuf, 0, (int)mir_strlen(protobuf)); + cc->szProto = m_cache->GetCachedSetting(nullptr, protobuf, 0, (int)mir_strlen(protobuf)); } return !mir_strcmp(cc->szProto, proto); @@ -55,8 +55,8 @@ STDMETHODIMP_(MCONTACT) CDb3Mmap::FindFirstContact(const char *szProto) { mir_cslock lck(m_csDbAccess); DBCachedContact *cc = m_cache->GetFirstContact(); - if (cc == NULL) - return NULL; + if (cc == nullptr) + return 0; if (!szProto || CheckProto(cc, szProto)) return cc->contactID; @@ -69,7 +69,7 @@ STDMETHODIMP_(MCONTACT) CDb3Mmap::FindNextContact(MCONTACT contactID, const char mir_cslock lck(m_csDbAccess); while (contactID) { DBCachedContact *cc = m_cache->GetNextContact(contactID); - if (cc == NULL) + if (cc == nullptr) break; if (!szProto || CheckProto(cc, szProto)) @@ -78,7 +78,7 @@ STDMETHODIMP_(MCONTACT) CDb3Mmap::FindNextContact(MCONTACT contactID, const char contactID = cc->contactID; } - return NULL; + return 0; } STDMETHODIMP_(LONG) CDb3Mmap::DeleteContact(MCONTACT contactID) @@ -89,7 +89,7 @@ STDMETHODIMP_(LONG) CDb3Mmap::DeleteContact(MCONTACT contactID) mir_cslockfull lck(m_csDbAccess); DWORD ofsContact = GetContactOffset(contactID); - DBContact *dbc = (DBContact*)DBRead(ofsContact, NULL); + DBContact *dbc = (DBContact*)DBRead(ofsContact, nullptr); if (dbc->signature != DBCONTACT_SIGNATURE) return 1; @@ -111,7 +111,7 @@ STDMETHODIMP_(LONG) CDb3Mmap::DeleteContact(MCONTACT contactID) DWORD ofsThis = dbc->ofsFirstSettings; DWORD ofsFirstEvent = dbc->ofsFirstEvent; while (ofsThis) { - DBContactSettings *dbcs = (DBContactSettings*)DBRead(ofsThis, NULL); + DBContactSettings *dbcs = (DBContactSettings*)DBRead(ofsThis, nullptr); DWORD ofsNext = dbcs->ofsNext; DeleteSpace(ofsThis, offsetof(DBContactSettings, blob) + dbcs->cbBlob); ofsThis = ofsNext; @@ -120,7 +120,7 @@ STDMETHODIMP_(LONG) CDb3Mmap::DeleteContact(MCONTACT contactID) // delete event chain ofsThis = ofsFirstEvent; while (ofsThis) { - DBEvent *dbe = (DBEvent*)DBRead(ofsThis, NULL); + DBEvent *dbe = (DBEvent*)DBRead(ofsThis, nullptr); DWORD ofsNext = dbe->ofsNext; DeleteSpace(ofsThis, offsetof(DBEvent, blob) + dbe->cbBlob); ofsThis = ofsNext; @@ -134,11 +134,12 @@ STDMETHODIMP_(LONG) CDb3Mmap::DeleteContact(MCONTACT contactID) else { DWORD ofsNext = dbc->ofsNext; ofsThis = m_dbHeader.ofsFirstContact; - DBContact *dbcPrev = (DBContact*)DBRead(ofsThis, NULL); + DBContact *dbcPrev = (DBContact*)DBRead(ofsThis, nullptr); while (dbcPrev->ofsNext != ofsContact) { - if (dbcPrev->ofsNext == 0) DatabaseCorruption(NULL); + if (dbcPrev->ofsNext == 0) + DatabaseCorruption(nullptr); ofsThis = dbcPrev->ofsNext; - dbcPrev = (DBContact*)DBRead(ofsThis, NULL); + dbcPrev = (DBContact*)DBRead(ofsThis, nullptr); } dbcPrev->ofsNext = ofsNext; DBWrite(ofsThis, dbcPrev, sizeof(DBContact)); @@ -155,7 +156,7 @@ STDMETHODIMP_(LONG) CDb3Mmap::DeleteContact(MCONTACT contactID) // free cache item m_cache->FreeCachedContact(contactID); if (contactID == m_hLastCachedContact) - m_hLastCachedContact = NULL; + m_hLastCachedContact = 0; return 0; } @@ -189,11 +190,11 @@ STDMETHODIMP_(MCONTACT) CDb3Mmap::AddContact() STDMETHODIMP_(BOOL) CDb3Mmap::IsDbContact(MCONTACT contactID) { DBCachedContact *cc = m_cache->GetCachedContact(contactID); - if (cc == NULL) + if (cc == nullptr) return FALSE; mir_cslock lck(m_csDbAccess); - DBContact *dbc = (DBContact*)DBRead(cc->dwOfsContact, NULL); + DBContact *dbc = (DBContact*)DBRead(cc->dwOfsContact, nullptr); if (dbc->signature == DBCONTACT_SIGNATURE) { m_cache->AddContactToCache(contactID); return TRUE; @@ -224,8 +225,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->dwOfsContact, NULL); - DBContact *dbSub = (DBContact*)DBRead(ccSub->dwOfsContact, NULL); + DBContact *dbMeta = (DBContact*)DBRead(ccMeta->dwOfsContact, nullptr); + DBContact *dbSub = (DBContact*)DBRead(ccSub->dwOfsContact, nullptr); if (dbMeta->signature != DBCONTACT_SIGNATURE || dbSub->signature != DBCONTACT_SIGNATURE) return 1; @@ -247,7 +248,7 @@ BOOL CDb3Mmap::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) // 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, NULL); + DBEvent *pev = (DBEvent*)DBRead(ofsMeta, nullptr); if (pev->signature != DBEVENT_SIGNATURE) { // broken chain, don't touch it ret = 2; __leave; @@ -258,7 +259,7 @@ BOOL CDb3Mmap::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) } for (DWORD ofsSub = dbSub->ofsFirstEvent; ofsSub != 0;) { - DBEvent *pev = (DBEvent*)DBRead(ofsSub, NULL); + DBEvent *pev = (DBEvent*)DBRead(ofsSub, nullptr); if (pev->signature != DBEVENT_SIGNATURE) { // broken chain, don't touch it ret = 2; __leave; @@ -308,8 +309,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->dwOfsContact, NULL); - DBContact dbSub = *(DBContact*)DBRead(ccSub->dwOfsContact, NULL); + DBContact dbMeta = *(DBContact*)DBRead(ccMeta->dwOfsContact, nullptr); + DBContact dbSub = *(DBContact*)DBRead(ccSub->dwOfsContact, nullptr); if (dbMeta.signature != DBCONTACT_SIGNATURE || dbSub.signature != DBCONTACT_SIGNATURE) return 1; @@ -322,11 +323,11 @@ BOOL CDb3Mmap::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) __leave; DWORD dwOffset = dbMeta.ofsFirstEvent; - DBEvent *evMeta = NULL, *evSub = NULL; + DBEvent *evMeta = nullptr, *evSub = nullptr; dbMeta.eventCount = 0; dbMeta.ofsFirstEvent = dbMeta.ofsLastEvent = dbMeta.ofsFirstUnread = dbMeta.tsFirstUnread = 0; while (dwOffset != 0) { - DBEvent *evCurr = (DBEvent*)DBRead(dwOffset, NULL); + DBEvent *evCurr = (DBEvent*)DBRead(dwOffset, nullptr); if (evCurr->signature != DBEVENT_SIGNATURE) break; @@ -335,7 +336,7 @@ BOOL CDb3Mmap::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) // extract it to sub's chain if (evCurr->contactID == ccSub->contactID) { dbSub.eventCount++; - if (evSub != NULL) { + if (evSub != nullptr) { evSub->ofsNext = dwOffset; evCurr->ofsPrev = DWORD(PBYTE(evSub) - m_pDbCache); } @@ -352,7 +353,7 @@ BOOL CDb3Mmap::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) } else { dbMeta.eventCount++; - if (evMeta != NULL) { + if (evMeta != nullptr) { evMeta->ofsNext = dwOffset; evCurr->ofsPrev = DWORD(PBYTE(evMeta) - m_pDbCache); } @@ -401,7 +402,7 @@ void CDb3Mmap::FillContacts() OBJLIST arMetas(10, NumericKeySortT); for (DWORD dwOffset = m_dbHeader.ofsFirstContact; dwOffset != 0;) { - DBContact *p = (DBContact*)DBRead(dwOffset, NULL); + DBContact *p = (DBContact*)DBRead(dwOffset, nullptr); if (p->signature != DBCONTACT_SIGNATURE) break; @@ -424,11 +425,11 @@ void CDb3Mmap::FillContacts() for (int i = 0; i < cc->nSubs; i++) { char setting[100]; mir_snprintf(setting, "Handle%d", i); - cc->pSubs[i] = (0 != GetContactSetting(dwContactID, META_PROTO, setting, &dbv)) ? NULL : dbv.dVal; + cc->pSubs[i] = (0 != GetContactSetting(dwContactID, META_PROTO, setting, &dbv)) ? 0 : dbv.dVal; } } cc->nDefault = (0 != GetContactSetting(dwContactID, META_PROTO, "Default", &dbv)) ? -1 : dbv.dVal; - cc->parentID = (0 != GetContactSetting(dwContactID, META_PROTO, "ParentMeta", &dbv)) ? NULL : dbv.dVal; + cc->parentID = (0 != GetContactSetting(dwContactID, META_PROTO, "ParentMeta", &dbv)) ? 0 : dbv.dVal; // whether we need conversion or not if (!GetContactSetting(dwContactID, META_PROTO, "MetaID", &dbv)) @@ -447,7 +448,7 @@ void CDb3Mmap::FillContacts() continue; COldMeta *p = arMetas.find((COldMeta*)&dbv.dVal); - if (p == NULL) + if (p == nullptr) continue; if (GetContactSetting(hh, META_PROTO, "ContactNumber", &dbv)) @@ -485,7 +486,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->dwOfsContact, NULL)); + WipeContactHistory((DBContact*)DBRead(ccMeta->dwOfsContact, nullptr)); } for (int k = 0; k < ccMeta->nSubs; k++) { @@ -501,11 +502,11 @@ void CDb3Mmap::FillContacts() DWORD CDb3Mmap::GetContactOffset(MCONTACT contactID, DBCachedContact **pcc) { if (contactID == 0) { - if (pcc) *pcc = NULL; + if (pcc) *pcc = nullptr; return m_dbHeader.ofsUser; } DBCachedContact *cc = m_cache->GetCachedContact(contactID); if (pcc) *pcc = cc; - return (cc == NULL) ? 0 : cc->dwOfsContact; + return (cc == nullptr) ? 0 : cc->dwOfsContact; } diff --git a/plugins/Db3x_mmap/src/dbcrypt.cpp b/plugins/Db3x_mmap/src/dbcrypt.cpp index fad02d9a0a..66559fff3a 100644 --- a/plugins/Db3x_mmap/src/dbcrypt.cpp +++ b/plugins/Db3x_mmap/src/dbcrypt.cpp @@ -89,14 +89,14 @@ void sttContactEnum(MCONTACT contactID, const char *szModule, CDb3Mmap *db) { OBJLIST arSettings(1); SettingUgraderParam param = { db, szModule, contactID, &arSettings }; - db->EnumContactSettings(NULL, sttSettingUgrader, szModule, ¶m); + db->EnumContactSettings(0, sttSettingUgrader, szModule, ¶m); for (int i = 0; i < arSettings.getCount(); i++) { VarDescr &p = arSettings[i]; size_t len; BYTE *pResult = db->m_crypto->encodeString(p.szValue, &len); - if (pResult != NULL) { + if (pResult != nullptr) { DBCONTACTWRITESETTING dbcws = { szModule, p.szVar }; dbcws.value.type = DBVT_ENCRYPTED; dbcws.value.pbVal = pResult; @@ -111,7 +111,7 @@ void sttContactEnum(MCONTACT contactID, const char *szModule, CDb3Mmap *db) int sttModuleEnum(const char *szModule, DWORD, LPARAM lParam) { CDb3Mmap *db = (CDb3Mmap*)lParam; - sttContactEnum(NULL, szModule, db); + sttContactEnum(0, szModule, db); for (MCONTACT contactID = db->FindFirstContact(); contactID; contactID = db->FindNextContact(contactID)) sttContactEnum(contactID, szModule, db); @@ -131,7 +131,7 @@ int CDb3Mmap::InitCrypt() DBVARIANT dbv = { 0 }; dbv.type = DBVT_BLOB; - if (GetContactSetting(NULL, "CryptoEngine", "Provider", &dbv)) { + if (GetContactSetting(0, "CryptoEngine", "Provider", &dbv)) { LBL_CreateProvider: CRYPTO_PROVIDER **ppProvs; int iNumProvs; @@ -151,7 +151,7 @@ int CDb3Mmap::InitCrypt() dbcws.value.type = DBVT_BLOB; dbcws.value.pbVal = (PBYTE)pProvider->pszName; dbcws.value.cpbVal = (WORD)mir_strlen(pProvider->pszName) + 1; - WriteContactSetting(NULL, &dbcws); + WriteContactSetting(0, &dbcws); } else { if (dbv.type != DBVT_BLOB) { // old version, clean it up @@ -161,15 +161,15 @@ int CDb3Mmap::InitCrypt() pProvider = Crypto_GetProvider(LPCSTR(dbv.pbVal)); FreeVariant(&dbv); - if (pProvider == NULL) + if (pProvider == nullptr) goto LBL_CreateProvider; } - if ((m_crypto = pProvider->pFactory()) == NULL) + if ((m_crypto = pProvider->pFactory()) == nullptr) return 3; dbv.type = DBVT_BLOB; - if (GetContactSetting(NULL, "CryptoEngine", "StoredKey", &dbv)) { + if (GetContactSetting(0, "CryptoEngine", "StoredKey", &dbv)) { bMissingKey = true; LBL_SetNewKey: @@ -203,7 +203,7 @@ int CDb3Mmap::InitCrypt() EnumModuleNames(sttModuleEnum, this); dbv.type = DBVT_BYTE; - if (!GetContactSetting(NULL, "CryptoEngine", "DatabaseEncryption", &dbv)) + if (!GetContactSetting(0, "CryptoEngine", "DatabaseEncryption", &dbv)) m_bEncrypted = dbv.bVal != 0; InitDialogs(); @@ -220,16 +220,16 @@ void CDb3Mmap::StoreKey() dbcws.value.type = DBVT_BLOB; dbcws.value.cpbVal = (WORD)iKeyLength; dbcws.value.pbVal = pKey; - WriteContactSetting(NULL, &dbcws); + WriteContactSetting(0, &dbcws); SecureZeroMemory(pKey, iKeyLength); } void CDb3Mmap::SetPassword(LPCTSTR ptszPassword) { - if (ptszPassword == NULL || *ptszPassword == 0) { + if (ptszPassword == nullptr || *ptszPassword == 0) { m_bUsesPassword = false; - m_crypto->setPassword(NULL); + m_crypto->setPassword(nullptr); } else { m_bUsesPassword = true; @@ -242,14 +242,14 @@ void CDb3Mmap::SetPassword(LPCTSTR ptszPassword) void CDb3Mmap::ToggleEncryption() { - HANDLE hSave1 = hSettingChangeEvent; hSettingChangeEvent = NULL; - HANDLE hSave2 = hEventAddedEvent; hEventAddedEvent = NULL; - HANDLE hSave3 = hEventDeletedEvent; hEventDeletedEvent = NULL; - HANDLE hSave4 = hEventFilterAddedEvent; hEventFilterAddedEvent = NULL; + HANDLE hSave1 = hSettingChangeEvent; hSettingChangeEvent = nullptr; + HANDLE hSave2 = hEventAddedEvent; hEventAddedEvent = nullptr; + HANDLE hSave3 = hEventDeletedEvent; hEventDeletedEvent = nullptr; + HANDLE hSave4 = hEventFilterAddedEvent; hEventFilterAddedEvent = nullptr; mir_cslock lck(m_csDbAccess); - ToggleSettingsEncryption(NULL); - ToggleEventsEncryption(NULL); + ToggleSettingsEncryption(0); + ToggleEventsEncryption(0); for (MCONTACT contactID = FindFirstContact(); contactID; contactID = FindNextContact(contactID)) { ToggleSettingsEncryption(contactID); @@ -261,7 +261,7 @@ void CDb3Mmap::ToggleEncryption() DBCONTACTWRITESETTING dbcws = { "CryptoEngine", "DatabaseEncryption" }; dbcws.value.type = DBVT_BYTE; dbcws.value.bVal = m_bEncrypted; - WriteContactSetting(NULL, &dbcws); + WriteContactSetting(0, &dbcws); hSettingChangeEvent = hSave1; hEventAddedEvent = hSave2; @@ -275,15 +275,15 @@ void CDb3Mmap::ToggleSettingsEncryption(MCONTACT contactID) if (ofsContact == 0) return; - DBContact *contact = (DBContact*)DBRead(ofsContact, NULL); + DBContact *contact = (DBContact*)DBRead(ofsContact, nullptr); if (contact->ofsFirstSettings == 0) return; // fast cycle through all settings - DBContactSettings *setting = (DBContactSettings*)DBRead(contact->ofsFirstSettings, NULL); + DBContactSettings *setting = (DBContactSettings*)DBRead(contact->ofsFirstSettings, nullptr); DWORD offset = contact->ofsFirstSettings; char *szModule = GetModuleNameByOfs(setting->ofsModuleName); - if (szModule == NULL) + if (szModule == nullptr) return; while (true) { @@ -345,7 +345,7 @@ void CDb3Mmap::ToggleSettingsEncryption(MCONTACT contactID) if (!m_bEncrypted) { size_t encodedLen; BYTE *pResult = m_crypto->encodeString(p.szValue, &encodedLen); - if (pResult != NULL) { + if (pResult != nullptr) { DBCONTACTWRITESETTING dbcws = { szModule, p.szVar }; dbcws.value.type = DBVT_ENCRYPTED; dbcws.value.pbVal = pResult; @@ -358,7 +358,7 @@ void CDb3Mmap::ToggleSettingsEncryption(MCONTACT contactID) else { size_t realLen; ptrA decoded(m_crypto->decodeString((PBYTE)(char*)p.szValue, p.iLen, &realLen)); - if (decoded != NULL) { + if (decoded != nullptr) { DBCONTACTWRITESETTING dbcws = { szModule, p.szVar }; dbcws.value.type = DBVT_UNENCRYPTED; dbcws.value.pszVal = decoded; @@ -371,8 +371,8 @@ void CDb3Mmap::ToggleSettingsEncryption(MCONTACT contactID) if (!ofsNext) break; - setting = (DBContactSettings*)DBRead(offset = ofsNext, NULL); - if ((szModule = GetModuleNameByOfs(setting->ofsModuleName)) == NULL) + setting = (DBContactSettings*)DBRead(offset = ofsNext, nullptr); + if ((szModule = GetModuleNameByOfs(setting->ofsModuleName)) == nullptr) break; } } @@ -383,13 +383,13 @@ void CDb3Mmap::ToggleEventsEncryption(MCONTACT contactID) if (ofsContact == 0) return; - DBContact contact = *(DBContact*)DBRead(ofsContact, NULL); + DBContact contact = *(DBContact*)DBRead(ofsContact, nullptr); if (contact.ofsFirstEvent == 0 || contact.signature != DBCONTACT_SIGNATURE) return; // fast cycle through all events for (DWORD offset = contact.ofsFirstEvent; offset != 0;) { - DBEvent evt = *(DBEvent*)DBRead(offset, NULL); + DBEvent evt = *(DBEvent*)DBRead(offset, nullptr); if (evt.signature != DBEVENT_SIGNATURE) return; @@ -398,18 +398,18 @@ void CDb3Mmap::ToggleEventsEncryption(MCONTACT contactID) mir_ptr pBlob; BYTE *pSource = DBRead(offset + offsetof(DBEvent, blob), 0); if (!m_bEncrypted) { // we need more space - if ((pBlob = m_crypto->encodeBuffer(pSource, evt.cbBlob, &len)) == NULL) + if ((pBlob = m_crypto->encodeBuffer(pSource, evt.cbBlob, &len)) == nullptr) return; ofsDest = ReallocSpace(offset, offsetof(DBEvent, blob) + evt.cbBlob, offsetof(DBEvent, blob) + (DWORD)len); if (evt.ofsNext) { - DBEvent *e = (DBEvent*)DBRead(evt.ofsNext, NULL); + DBEvent *e = (DBEvent*)DBRead(evt.ofsNext, nullptr); e->ofsPrev = ofsDest; DBWrite(evt.ofsNext, e, sizeof(DBEvent)); } if (evt.ofsPrev) { - DBEvent *e = (DBEvent*)DBRead(evt.ofsPrev, NULL); + DBEvent *e = (DBEvent*)DBRead(evt.ofsPrev, nullptr); e->ofsNext = ofsDest; DBWrite(evt.ofsPrev, e, sizeof(DBEvent)); } @@ -423,7 +423,7 @@ void CDb3Mmap::ToggleEventsEncryption(MCONTACT contactID) evt.flags |= DBEF_ENCRYPTED; } else { - if ((pBlob = (BYTE*)m_crypto->decodeBuffer(pSource, evt.cbBlob, &len)) == NULL) + if ((pBlob = (BYTE*)m_crypto->decodeBuffer(pSource, evt.cbBlob, &len)) == nullptr) return; ofsDest = offset; // reuse the old space diff --git a/plugins/Db3x_mmap/src/dbevents.cpp b/plugins/Db3x_mmap/src/dbevents.cpp index 9fff41614d..767b22aa74 100644 --- a/plugins/Db3x_mmap/src/dbevents.cpp +++ b/plugins/Db3x_mmap/src/dbevents.cpp @@ -26,13 +26,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. STDMETHODIMP_(LONG) CDb3Mmap::GetEventCount(MCONTACT contactID) { mir_cslock lck(m_csDbAccess); - DBContact *dbc = (DBContact*)DBRead(GetContactOffset(contactID), NULL); + DBContact *dbc = (DBContact*)DBRead(GetContactOffset(contactID), nullptr); return (dbc->signature != DBCONTACT_SIGNATURE) ? -1 : dbc->eventCount; } STDMETHODIMP_(MEVENT) CDb3Mmap::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) { - if (dbei == NULL) return 0; + if (dbei == nullptr) return 0; if (dbei->timestamp == 0) return 0; DBEvent dbe; @@ -40,11 +40,11 @@ STDMETHODIMP_(MEVENT) CDb3Mmap::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) dbe.contactID = contactID; // store native or subcontact's id MCONTACT contactNotifyID = contactID; - DBCachedContact *ccSub = NULL; + DBCachedContact *ccSub = nullptr; if (contactID != 0) { DBCachedContact *cc = m_cache->GetCachedContact(contactID); - if (cc == NULL) - return NULL; + if (cc == nullptr) + return 0; if (cc->IsSub()) { ccSub = cc; @@ -58,7 +58,7 @@ STDMETHODIMP_(MEVENT) CDb3Mmap::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) } if (NotifyEventHooks(hEventFilterAddedEvent, contactNotifyID, (LPARAM)dbei)) - return NULL; + return 0; dbe.timestamp = dbei->timestamp; dbe.flags = dbei->flags; @@ -70,7 +70,7 @@ STDMETHODIMP_(MEVENT) CDb3Mmap::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) if (m_bEncrypted) { size_t len; BYTE *pResult = m_crypto->encodeBuffer(pBlob, dbe.cbBlob, &len); - if (pResult != NULL) { + if (pResult != nullptr) { pCryptBlob = pBlob = pResult; dbe.cbBlob = (DWORD)len; dbe.flags |= DBEF_ENCRYPTED; @@ -80,9 +80,9 @@ STDMETHODIMP_(MEVENT) CDb3Mmap::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) mir_cslockfull lck(m_csDbAccess); DWORD ofsContact = GetContactOffset(contactID); - DBContact dbc = *(DBContact*)DBRead(ofsContact, NULL); + DBContact dbc = *(DBContact*)DBRead(ofsContact, nullptr); if (dbc.signature != DBCONTACT_SIGNATURE) - return NULL; + return 0; DWORD ofsNew = CreateNewSpace(offsetof(DBEvent, blob) + dbe.cbBlob); @@ -93,20 +93,20 @@ STDMETHODIMP_(MEVENT) CDb3Mmap::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) dbc.ofsFirstEvent = dbc.ofsLastEvent = ofsNew; } else { - DBEvent *dbeTest = (DBEvent*)DBRead(dbc.ofsFirstEvent, NULL); + DBEvent *dbeTest = (DBEvent*)DBRead(dbc.ofsFirstEvent, nullptr); // Should new event be placed before first event in chain? if (dbe.timestamp < dbeTest->timestamp) { dbe.ofsPrev = 0; dbe.ofsNext = dbc.ofsFirstEvent; dbc.ofsFirstEvent = ofsNew; - dbeTest = (DBEvent*)DBRead(dbe.ofsNext, NULL); + dbeTest = (DBEvent*)DBRead(dbe.ofsNext, nullptr); dbeTest->ofsPrev = ofsNew; DBWrite(dbe.ofsNext, dbeTest, sizeof(DBEvent)); } else { // Loop through the chain, starting at the end DWORD ofsThis = dbc.ofsLastEvent; - dbeTest = (DBEvent*)DBRead(ofsThis, NULL); + dbeTest = (DBEvent*)DBRead(ofsThis, nullptr); for (;;) { // If the new event's timesstamp is equal to or greater than the // current dbevent, it will be inserted after. If not, continue @@ -119,14 +119,14 @@ STDMETHODIMP_(MEVENT) CDb3Mmap::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) if (dbe.ofsNext == 0) dbc.ofsLastEvent = ofsNew; else { - dbeTest = (DBEvent*)DBRead(dbe.ofsNext, NULL); + dbeTest = (DBEvent*)DBRead(dbe.ofsNext, nullptr); dbeTest->ofsPrev = ofsNew; DBWrite(dbe.ofsNext, dbeTest, sizeof(DBEvent)); } break; } ofsThis = dbeTest->ofsPrev; - dbeTest = (DBEvent*)DBRead(ofsThis, NULL); + dbeTest = (DBEvent*)DBRead(ofsThis, nullptr); } } } @@ -142,8 +142,8 @@ STDMETHODIMP_(MEVENT) CDb3Mmap::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) } else neednotify = m_safetyMode; - if (ccSub != NULL) { - DBContact *pSub = (DBContact*)DBRead(ccSub->dwOfsContact, NULL); + if (ccSub != nullptr) { + DBContact *pSub = (DBContact*)DBRead(ccSub->dwOfsContact, nullptr); pSub->eventCount++; } @@ -166,18 +166,18 @@ STDMETHODIMP_(BOOL) CDb3Mmap::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent) { DBCachedContact *cc; if (contactID) { - if ((cc = m_cache->GetCachedContact(contactID)) == NULL) + if ((cc = m_cache->GetCachedContact(contactID)) == nullptr) return 2; if (cc->IsSub()) - if ((cc = m_cache->GetCachedContact(cc->parentID)) == NULL) + if ((cc = m_cache->GetCachedContact(cc->parentID)) == nullptr) return 3; } - else cc = NULL; + else cc = nullptr; mir_cslockfull lck(m_csDbAccess); DWORD ofsContact = (cc) ? cc->dwOfsContact : m_dbHeader.ofsUser; - DBContact dbc = *(DBContact*)DBRead(ofsContact, NULL); - DBEvent dbe = *(DBEvent*)DBRead((DWORD)hDbEvent, NULL); + DBContact dbc = *(DBContact*)DBRead(ofsContact, nullptr); + DBEvent dbe = *(DBEvent*)DBRead((DWORD)hDbEvent, nullptr); if (dbc.signature != DBCONTACT_SIGNATURE || dbe.signature != DBEVENT_SIGNATURE) return 1; @@ -189,8 +189,8 @@ STDMETHODIMP_(BOOL) CDb3Mmap::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent) // get back in lck.lock(); - dbc = *(DBContact*)DBRead(ofsContact, NULL); - dbe = *(DBEvent*)DBRead((DWORD)hDbEvent, NULL); + dbc = *(DBContact*)DBRead(ofsContact, nullptr); + dbe = *(DBEvent*)DBRead((DWORD)hDbEvent, nullptr); // check if this was the first unread, if so, recalc the first unread if (dbc.ofsFirstUnread == (DWORD)hDbEvent) { @@ -201,7 +201,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent) break; } DWORD ofsThis = dbeNext->ofsNext; - dbeNext = (DBEvent*)DBRead(ofsThis, NULL); + dbeNext = (DBEvent*)DBRead(ofsThis, nullptr); if (!dbeNext->markedRead()) { dbc.ofsFirstUnread = ofsThis; dbc.tsFirstUnread = dbeNext->timestamp; @@ -215,7 +215,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent) if (dbe.ofsNext == 0) dbc.ofsFirstEvent = dbc.ofsLastEvent = 0; else { - DBEvent *dbeNext = (DBEvent*)DBRead(dbe.ofsNext, NULL); + DBEvent *dbeNext = (DBEvent*)DBRead(dbe.ofsNext, nullptr); dbeNext->ofsPrev = 0; DBWrite(dbe.ofsNext, dbeNext, sizeof(DBEvent)); dbc.ofsFirstEvent = dbe.ofsNext; @@ -223,17 +223,17 @@ STDMETHODIMP_(BOOL) CDb3Mmap::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent) } else { if (dbe.ofsNext == 0) { - DBEvent *dbePrev = (DBEvent*)DBRead(dbe.ofsPrev, NULL); + DBEvent *dbePrev = (DBEvent*)DBRead(dbe.ofsPrev, nullptr); dbePrev->ofsNext = 0; DBWrite(dbe.ofsPrev, dbePrev, sizeof(DBEvent)); dbc.ofsLastEvent = dbe.ofsPrev; } else { - DBEvent *dbePrev = (DBEvent*)DBRead(dbe.ofsPrev, NULL); + DBEvent *dbePrev = (DBEvent*)DBRead(dbe.ofsPrev, nullptr); dbePrev->ofsNext = dbe.ofsNext; DBWrite(dbe.ofsPrev, dbePrev, sizeof(DBEvent)); - DBEvent *dbeNext = (DBEvent*)DBRead(dbe.ofsNext, NULL); + DBEvent *dbeNext = (DBEvent*)DBRead(dbe.ofsNext, nullptr); dbeNext->ofsPrev = dbe.ofsPrev; DBWrite(dbe.ofsNext, dbeNext, sizeof(DBEvent)); } @@ -248,7 +248,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent) // also update a sub if (cc && dbe.contactID != cc->contactID) { - DBContact *pSub = (DBContact*)DBRead(GetContactOffset(dbe.contactID), NULL); + DBContact *pSub = (DBContact*)DBRead(GetContactOffset(dbe.contactID), nullptr); if (pSub->eventCount > 0) pSub->eventCount--; } @@ -266,8 +266,8 @@ STDMETHODIMP_(LONG) CDb3Mmap::GetBlobSize(MEVENT hDbEvent) STDMETHODIMP_(BOOL) CDb3Mmap::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei) { - if (dbei == NULL) return 1; - if (dbei->cbBlob > 0 && dbei->pBlob == NULL) { + if (dbei == nullptr) return 1; + if (dbei->cbBlob > 0 && dbei->pBlob == nullptr) { dbei->cbBlob = 0; return 1; } @@ -286,14 +286,14 @@ STDMETHODIMP_(BOOL) CDb3Mmap::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei) if (bytesToCopy && dbei->pBlob) { BYTE *pSrc; if (m_dbHeader.version >= DB_095_1_VERSION) - pSrc = DBRead(DWORD(hDbEvent) + offsetof(DBEvent, blob), NULL); + pSrc = DBRead(DWORD(hDbEvent) + offsetof(DBEvent, blob), nullptr); else - pSrc = DBRead(DWORD(hDbEvent) + offsetof(DBEvent_094, blob), NULL); + pSrc = DBRead(DWORD(hDbEvent) + offsetof(DBEvent_094, blob), nullptr); if (dbe->flags & DBEF_ENCRYPTED) { dbei->flags &= ~DBEF_ENCRYPTED; size_t len; BYTE* pBlob = (BYTE*)m_crypto->decodeBuffer(pSrc, dbe->cbBlob, &len); - if (pBlob == NULL) + if (pBlob == nullptr) return 1; memcpy(dbei->pBlob, pBlob, bytesToCopy); @@ -310,18 +310,18 @@ STDMETHODIMP_(BOOL) CDb3Mmap::MarkEventRead(MCONTACT contactID, MEVENT hDbEvent) { DBCachedContact *cc; if (contactID) { - if ((cc = m_cache->GetCachedContact(contactID)) == NULL) + if ((cc = m_cache->GetCachedContact(contactID)) == nullptr) return -1; if (cc->IsSub()) - if ((cc = m_cache->GetCachedContact(cc->parentID)) == NULL) + if ((cc = m_cache->GetCachedContact(cc->parentID)) == nullptr) return -1; } - else cc = NULL; + else cc = nullptr; mir_cslockfull lck(m_csDbAccess); DWORD ofsContact = (cc) ? cc->dwOfsContact : m_dbHeader.ofsUser; - DBContact dbc = *(DBContact*)DBRead(ofsContact, NULL); - DBEvent *dbe = (DBEvent*)DBRead((DWORD)hDbEvent, NULL); + DBContact dbc = *(DBContact*)DBRead(ofsContact, nullptr); + DBEvent *dbe = (DBEvent*)DBRead((DWORD)hDbEvent, nullptr); if (dbe->signature != DBEVENT_SIGNATURE || dbc.signature != DBCONTACT_SIGNATURE) return -1; @@ -340,7 +340,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::MarkEventRead(MCONTACT contactID, MEVENT hDbEvent) break; } DWORD ofsThis = dbe->ofsNext; - dbe = (DBEvent*)DBRead(ofsThis, NULL); + dbe = (DBEvent*)DBRead(ofsThis, nullptr); if (!dbe->markedRead()) { dbc.ofsFirstUnread = ofsThis; dbc.tsFirstUnread = dbe->timestamp; @@ -369,27 +369,27 @@ STDMETHODIMP_(MEVENT) CDb3Mmap::FindFirstEvent(MCONTACT contactID) DWORD ofsContact = GetContactOffset(contactID, &cc); mir_cslock lck(m_csDbAccess); - DBContact *dbc = (DBContact*)DBRead(ofsContact, NULL); + DBContact *dbc = (DBContact*)DBRead(ofsContact, nullptr); if (dbc->signature != DBCONTACT_SIGNATURE) - return NULL; + return 0; if (!cc || !cc->IsSub()) return MEVENT(dbc->ofsFirstEvent); - if ((cc = m_cache->GetCachedContact(cc->parentID)) == NULL) - return NULL; - dbc = (DBContact*)DBRead(cc->dwOfsContact, NULL); + if ((cc = m_cache->GetCachedContact(cc->parentID)) == nullptr) + return 0; + dbc = (DBContact*)DBRead(cc->dwOfsContact, nullptr); if (dbc->signature != DBCONTACT_SIGNATURE) - return NULL; + return 0; for (DWORD dwOffset = dbc->ofsFirstEvent; dwOffset != 0;) { DBEvent *dbe = AdaptEvent(dwOffset, contactID); if (dbe->signature != DBEVENT_SIGNATURE) - return NULL; + return 0; if (dbe->contactID == contactID) return MEVENT(dwOffset); dwOffset = dbe->ofsNext; } - return NULL; + return 0; } STDMETHODIMP_(MEVENT) CDb3Mmap::FindFirstUnreadEvent(MCONTACT contactID) @@ -398,27 +398,27 @@ STDMETHODIMP_(MEVENT) CDb3Mmap::FindFirstUnreadEvent(MCONTACT contactID) DWORD ofsContact = GetContactOffset(contactID, &cc); mir_cslock lck(m_csDbAccess); - DBContact *dbc = (DBContact*)DBRead(ofsContact, NULL); + DBContact *dbc = (DBContact*)DBRead(ofsContact, nullptr); if (dbc->signature != DBCONTACT_SIGNATURE) - return NULL; + return 0; if (!cc || !cc->IsSub()) return MEVENT(dbc->ofsFirstUnread); - if ((cc = m_cache->GetCachedContact(cc->parentID)) == NULL) - return NULL; - dbc = (DBContact*)DBRead(cc->dwOfsContact, NULL); + if ((cc = m_cache->GetCachedContact(cc->parentID)) == nullptr) + return 0; + dbc = (DBContact*)DBRead(cc->dwOfsContact, nullptr); if (dbc->signature != DBCONTACT_SIGNATURE) - return NULL; + return 0; for (DWORD dwOffset = dbc->ofsFirstUnread; dwOffset != 0;) { DBEvent *dbe = AdaptEvent(dwOffset, contactID); if (dbe->signature != DBEVENT_SIGNATURE) - return NULL; + return 0; if (dbe->contactID == contactID && !dbe->markedRead()) return MEVENT(dwOffset); dwOffset = dbe->ofsNext; } - return NULL; + return 0; } STDMETHODIMP_(MEVENT) CDb3Mmap::FindLastEvent(MCONTACT contactID) @@ -427,79 +427,79 @@ STDMETHODIMP_(MEVENT) CDb3Mmap::FindLastEvent(MCONTACT contactID) DWORD ofsContact = GetContactOffset(contactID, &cc); mir_cslock lck(m_csDbAccess); - DBContact *dbc = (DBContact*)DBRead(ofsContact, NULL); + DBContact *dbc = (DBContact*)DBRead(ofsContact, nullptr); if (dbc->signature != DBCONTACT_SIGNATURE) - return NULL; + return 0; if (!cc || !cc->IsSub()) return MEVENT(dbc->ofsLastEvent); - if ((cc = m_cache->GetCachedContact(cc->parentID)) == NULL) - return NULL; - dbc = (DBContact*)DBRead(cc->dwOfsContact, NULL); + if ((cc = m_cache->GetCachedContact(cc->parentID)) == nullptr) + return 0; + dbc = (DBContact*)DBRead(cc->dwOfsContact, nullptr); if (dbc->signature != DBCONTACT_SIGNATURE) - return NULL; + return 0; for (DWORD dwOffset = dbc->ofsLastEvent; dwOffset != 0;) { DBEvent *dbe = AdaptEvent(dwOffset, contactID); if (dbe->signature != DBEVENT_SIGNATURE) - return NULL; + return 0; if (dbe->contactID == contactID) return MEVENT(dwOffset); dwOffset = dbe->ofsPrev; } - return NULL; + return 0; } STDMETHODIMP_(MEVENT) CDb3Mmap::FindNextEvent(MCONTACT contactID, MEVENT hDbEvent) { - DBCachedContact *cc = (contactID) ? m_cache->GetCachedContact(contactID) : NULL; + DBCachedContact *cc = (contactID) ? m_cache->GetCachedContact(contactID) : nullptr; mir_cslock lck(m_csDbAccess); DBEvent *dbe = AdaptEvent((DWORD)hDbEvent, contactID); if (dbe->signature != DBEVENT_SIGNATURE) - return NULL; + return 0; if (!cc || !cc->IsSub()) return MEVENT(dbe->ofsNext); for (DWORD dwOffset = dbe->ofsNext; dwOffset != 0;) { dbe = AdaptEvent(dwOffset, contactID); if (dbe->signature != DBEVENT_SIGNATURE) - return NULL; + return 0; if (dbe->contactID == contactID) return MEVENT(dwOffset); dwOffset = dbe->ofsNext; } - return NULL; + return 0; } STDMETHODIMP_(MEVENT) CDb3Mmap::FindPrevEvent(MCONTACT contactID, MEVENT hDbEvent) { - DBCachedContact *cc = (contactID) ? m_cache->GetCachedContact(contactID) : NULL; + DBCachedContact *cc = (contactID) ? m_cache->GetCachedContact(contactID) : nullptr; mir_cslock lck(m_csDbAccess); DBEvent *dbe = AdaptEvent((DWORD)hDbEvent, contactID); if (dbe->signature != DBEVENT_SIGNATURE) - return NULL; + return 0; if (!cc || !cc->IsSub()) return MEVENT(dbe->ofsPrev); for (DWORD dwOffset = dbe->ofsPrev; dwOffset != 0;) { dbe = AdaptEvent(dwOffset, contactID); if (dbe->signature != DBEVENT_SIGNATURE) - return NULL; + return 0; if (dbe->contactID == contactID) return MEVENT(dwOffset); dwOffset = dbe->ofsPrev; } - return NULL; + return 0; } DBEvent* CDb3Mmap::AdaptEvent(DWORD ofs, DWORD dwContactID) { if (m_dbHeader.version >= DB_095_1_VERSION) - return (DBEvent*)DBRead(ofs, NULL); + return (DBEvent*)DBRead(ofs, nullptr); - DBEvent_094 *pOldEvent = (DBEvent_094*)DBRead(ofs, NULL); + DBEvent_094 *pOldEvent = (DBEvent_094*)DBRead(ofs, nullptr); m_tmpEvent.signature = pOldEvent->signature; m_tmpEvent.contactID = dwContactID; memcpy(&m_tmpEvent.ofsPrev, &pOldEvent->ofsPrev, sizeof(DBEvent_094) - sizeof(DWORD)); @@ -513,7 +513,7 @@ int CDb3Mmap::WipeContactHistory(DBContact *dbc) { // drop subContact's history if any for (DWORD dwOffset = dbc->ofsFirstEvent; dwOffset != 0;) { - DBEvent *pev = (DBEvent*)DBRead(dwOffset, NULL); + DBEvent *pev = (DBEvent*)DBRead(dwOffset, nullptr); if (pev->signature != DBEVENT_SIGNATURE) // broken chain, don't touch it return 2; diff --git a/plugins/Db3x_mmap/src/dbheaders.cpp b/plugins/Db3x_mmap/src/dbheaders.cpp index ac7c34e923..76dc1fb6bd 100644 --- a/plugins/Db3x_mmap/src/dbheaders.cpp +++ b/plugins/Db3x_mmap/src/dbheaders.cpp @@ -40,15 +40,15 @@ int CDb3Mmap::CreateDbHeaders(const DBSignature& _sign) // create user m_dbHeader.ofsUser = m_dbHeader.ofsFileEnd; m_dbHeader.ofsFileEnd += sizeof(DBContact); - SetFilePointer(m_hDbFile, 0, NULL, FILE_BEGIN); + SetFilePointer(m_hDbFile, 0, nullptr, FILE_BEGIN); DWORD bytesWritten; - WriteFile(m_hDbFile, &m_dbHeader, sizeof(m_dbHeader), &bytesWritten, NULL); + WriteFile(m_hDbFile, &m_dbHeader, sizeof(m_dbHeader), &bytesWritten, nullptr); DBContact user = { 0 }; user.signature = DBCONTACT_SIGNATURE; - SetFilePointer(m_hDbFile, m_dbHeader.ofsUser, NULL, FILE_BEGIN); - WriteFile(m_hDbFile, &user, sizeof(DBContact), &bytesWritten, NULL); + SetFilePointer(m_hDbFile, m_dbHeader.ofsUser, nullptr, FILE_BEGIN); + WriteFile(m_hDbFile, &user, sizeof(DBContact), &bytesWritten, nullptr); FlushFileBuffers(m_hDbFile); return 0; } @@ -69,9 +69,9 @@ int CDb3Mmap::CheckDbHeaders(bool bInteractive) if (!memcmp(&m_dbHeader.signature, &dbSignatureSD, sizeof(m_dbHeader.signature))) { if (bInteractive) - if (IDYES == MessageBox(NULL, TranslateW(tszOldHeaders), TranslateT("Obsolete database format"), MB_YESNO | MB_ICONWARNING)) { + if (IDYES == MessageBox(nullptr, TranslateW(tszOldHeaders), TranslateT("Obsolete database format"), MB_YESNO | MB_ICONWARNING)) { wchar_t tszCurPath[MAX_PATH]; - GetModuleFileName(NULL, tszCurPath, _countof(tszCurPath)); + GetModuleFileName(nullptr, tszCurPath, _countof(tszCurPath)); wchar_t *p = wcsrchr(tszCurPath, '\\'); if (p) *p = 0; diff --git a/plugins/Db3x_mmap/src/dbintf.cpp b/plugins/Db3x_mmap/src/dbintf.cpp index 2bf91ac90b..109dfb99da 100644 --- a/plugins/Db3x_mmap/src/dbintf.cpp +++ b/plugins/Db3x_mmap/src/dbintf.cpp @@ -71,7 +71,7 @@ CDb3Mmap::~CDb3Mmap() HeapDestroy(m_hModHeap); // destroy map - KillTimer(NULL, m_flushBuffersTimerId); + KillTimer(nullptr, m_flushBuffersTimerId); if (m_pDbCache) { FlushViewOfFile(m_pDbCache, 0); UnmapViewOfFile(m_pDbCache); @@ -89,8 +89,8 @@ CDb3Mmap::~CDb3Mmap() // update profile last modified time if (!m_bReadOnly) { DWORD bytesWritten; - SetFilePointer(m_hDbFile, 0, NULL, FILE_BEGIN); - WriteFile(m_hDbFile, &dbSignatureU, 1, &bytesWritten, NULL); + SetFilePointer(m_hDbFile, 0, nullptr, FILE_BEGIN); + WriteFile(m_hDbFile, &dbSignatureU, 1, &bytesWritten, nullptr); } if (m_hDbFile != INVALID_HANDLE_VALUE) @@ -119,14 +119,14 @@ int CDb3Mmap::Load(bool bSkipInit) if (m_bShared) dwMode |= FILE_SHARE_WRITE; if (m_bReadOnly) - m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ, dwMode, NULL, OPEN_EXISTING, 0, NULL); + m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ, dwMode, nullptr, OPEN_EXISTING, 0, nullptr); else - m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ | GENERIC_WRITE, dwMode, NULL, OPEN_ALWAYS, 0, NULL); + m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ | GENERIC_WRITE, dwMode, nullptr, OPEN_ALWAYS, 0, nullptr); if (m_hDbFile == INVALID_HANDLE_VALUE) return EGROKPRF_CANTREAD; - if (!ReadFile(m_hDbFile, &m_dbHeader, sizeof(m_dbHeader), &dummy, NULL)) { + if (!ReadFile(m_hDbFile, &m_dbHeader, sizeof(m_dbHeader), &dummy, nullptr)) { CloseHandle(m_hDbFile); return EGROKPRF_CANTREAD; } @@ -160,7 +160,7 @@ int CDb3Mmap::Load(bool bSkipInit) int CDb3Mmap::Create() { - m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL); + m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, nullptr, CREATE_ALWAYS, 0, nullptr); return (m_hDbFile == INVALID_HANDLE_VALUE); } diff --git a/plugins/Db3x_mmap/src/dbintf.h b/plugins/Db3x_mmap/src/dbintf.h index bc40dd4ac8..d5ada71747 100644 --- a/plugins/Db3x_mmap/src/dbintf.h +++ b/plugins/Db3x_mmap/src/dbintf.h @@ -38,7 +38,7 @@ DBHeader | | \-->module name (DBModuleName) | \-->first/last/firstunread event |-->user contact (DBContact) -| |-->next contact = NULL +| |-->next contact = nullptr | |-->first settings as above | \-->first/last/firstunread event as above \-->first module name (DBModuleName) @@ -212,8 +212,8 @@ public: STDMETHODIMP_(void) SetCacheSafetyMode(BOOL); STDMETHODIMP_(LONG) GetContactCount(void); - STDMETHODIMP_(MCONTACT) FindFirstContact(const char *szProto = NULL); - STDMETHODIMP_(MCONTACT) FindNextContact(MCONTACT contactID, const char *szProto = NULL); + STDMETHODIMP_(MCONTACT) FindFirstContact(const char *szProto = nullptr); + STDMETHODIMP_(MCONTACT) FindNextContact(MCONTACT contactID, const char *szProto = nullptr); STDMETHODIMP_(LONG) DeleteContact(MCONTACT contactID); STDMETHODIMP_(MCONTACT) AddContact(void); STDMETHODIMP_(BOOL) IsDbContact(MCONTACT contactID); @@ -319,7 +319,7 @@ protected: // contacts int WipeContactHistory(DBContact *dbc); - DWORD GetContactOffset(MCONTACT contactID, DBCachedContact **cc = NULL); + DWORD GetContactOffset(MCONTACT contactID, DBCachedContact **cc = nullptr); //////////////////////////////////////////////////////////////////////////// // events diff --git a/plugins/Db3x_mmap/src/dbmodulechain.cpp b/plugins/Db3x_mmap/src/dbmodulechain.cpp index 983b5a27f7..47d1cf40d3 100644 --- a/plugins/Db3x_mmap/src/dbmodulechain.cpp +++ b/plugins/Db3x_mmap/src/dbmodulechain.cpp @@ -41,21 +41,21 @@ void CDb3Mmap::AddToList(char *name, DWORD ofs) int CDb3Mmap::InitModuleNames(void) { DWORD ofsThis = m_dbHeader.ofsModuleNames; - DBModuleName *dbmn = (struct DBModuleName*)DBRead(ofsThis, NULL); + DBModuleName *dbmn = (struct DBModuleName*)DBRead(ofsThis, nullptr); while (ofsThis) { if (dbmn->signature != DBMODULENAME_SIGNATURE) - DatabaseCorruption(NULL); + DatabaseCorruption(nullptr); int nameLen = dbmn->cbName; char *mod = (char*)HeapAlloc(m_hModHeap, 0, nameLen + 1); - memcpy(mod, DBRead(ofsThis + offsetof(struct DBModuleName, name), NULL), nameLen); + memcpy(mod, DBRead(ofsThis + offsetof(struct DBModuleName, name), nullptr), nameLen); mod[nameLen] = 0; AddToList(mod, ofsThis); ofsThis = dbmn->ofsNext; - dbmn = (struct DBModuleName*)DBRead(ofsThis, NULL); + dbmn = (struct DBModuleName*)DBRead(ofsThis, nullptr); } return 0; } @@ -115,7 +115,7 @@ char* CDb3Mmap::GetModuleNameByOfs(DWORD ofs) if (m_lastmn && m_lastmn->ofs == ofs) return m_lastmn->name; - ModuleName mn = { NULL, ofs }; + ModuleName mn = { nullptr, ofs }; int index = m_lOfs.getIndex(&mn); if (index != -1) { ModuleName *pmn = m_lOfs[index]; @@ -123,8 +123,8 @@ char* CDb3Mmap::GetModuleNameByOfs(DWORD ofs) return pmn->name; } - DatabaseCorruption(NULL); - return NULL; + DatabaseCorruption(nullptr); + return nullptr; } STDMETHODIMP_(BOOL) CDb3Mmap::EnumModuleNames(DBMODULEENUMPROC pFunc, const void *pParam) diff --git a/plugins/Db3x_mmap/src/dbsettings.cpp b/plugins/Db3x_mmap/src/dbsettings.cpp index 9a559d2307..8f41895915 100644 --- a/plugins/Db3x_mmap/src/dbsettings.cpp +++ b/plugins/Db3x_mmap/src/dbsettings.cpp @@ -60,7 +60,7 @@ static bool ValidLookupName(LPCSTR szModule, LPCSTR szSetting) int CDb3Mmap::GetContactSettingWorker(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv, int isStatic) { - if (szSetting == NULL || szModule == NULL) + if (szSetting == nullptr || szModule == nullptr) return 1; // the db format can't tolerate more than 255 bytes of space (incl. null) for settings+module name @@ -86,14 +86,14 @@ LBL_Seek: log3("get [%08p] %s (%p)", hContact, szCachedSettingName, szCachedSettingName); DBVARIANT *pCachedValue = m_cache->GetCachedValuePtr(contactID, szCachedSettingName, 0); - if (pCachedValue != NULL) { + if (pCachedValue != nullptr) { if (pCachedValue->type == DBVT_ASCIIZ || pCachedValue->type == DBVT_UTF8) { int cbOrigLen = dbv->cchVal; char *cbOrigPtr = dbv->pszVal; memcpy(dbv, pCachedValue, sizeof(DBVARIANT)); if (isStatic) { int cbLen = 0; - if (pCachedValue->pszVal != NULL) + if (pCachedValue->pszVal != nullptr) cbLen = (int)mir_strlen(pCachedValue->pszVal); cbOrigLen--; @@ -124,7 +124,7 @@ LBL_Seek: DWORD ofsModuleName = GetModuleNameOfs(szModule); - DBContact dbc = *(DBContact*)DBRead(ofsContact, NULL); + DBContact dbc = *(DBContact*)DBRead(ofsContact, nullptr); if (dbc.signature != DBCONTACT_SIGNATURE) return 1; @@ -187,14 +187,14 @@ LBL_Seek: break; case DBVT_ENCRYPTED: - if (m_crypto == NULL) + if (m_crypto == nullptr) return 1; else { varLen = *(PWORD)(pBlob + 1); NeedBytes(int(3 + varLen)); size_t realLen; ptrA decoded(m_crypto->decodeString(pBlob + 3, varLen, &realLen)); - if (decoded == NULL) + if (decoded == nullptr) return 1; varLen = (WORD)realLen; @@ -219,7 +219,7 @@ LBL_Seek: /**** add to cache **********************/ if (iType != DBVT_BLOB && iType != DBVT_ENCRYPTED) { pCachedValue = m_cache->GetCachedValuePtr(contactID, szCachedSettingName, 1); - if (pCachedValue != NULL) { + if (pCachedValue != nullptr) { m_cache->SetCachedVariant(dbv, pCachedValue); log3("set cached [%08p] %s (%p)", hContact, szCachedSettingName, pCachedValue); } @@ -256,11 +256,11 @@ STDMETHODIMP_(BOOL) CDb3Mmap::GetContactSetting(MCONTACT contactID, LPCSTR szMod return 1; if (dbv->type == DBVT_UTF8) { - WCHAR *tmp = NULL; + WCHAR *tmp = nullptr; char *p = NEWSTR_ALLOCA(dbv->pszVal); - if (mir_utf8decode(p, &tmp) != NULL) { + if (mir_utf8decode(p, &tmp) != nullptr) { BOOL bUsed = FALSE; - int result = WideCharToMultiByte(m_codePage, WC_NO_BEST_FIT_CHARS, tmp, -1, NULL, 0, NULL, &bUsed); + int result = WideCharToMultiByte(m_codePage, WC_NO_BEST_FIT_CHARS, tmp, -1, nullptr, 0, nullptr, &bUsed); mir_free(dbv->pszVal); @@ -271,7 +271,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::GetContactSetting(MCONTACT contactID, LPCSTR szMod else { dbv->type = DBVT_ASCIIZ; dbv->pszVal = (char *)mir_alloc(result); - WideCharToMultiByte(m_codePage, WC_NO_BEST_FIT_CHARS, tmp, -1, dbv->pszVal, result, NULL, NULL); + WideCharToMultiByte(m_codePage, WC_NO_BEST_FIT_CHARS, tmp, -1, dbv->pszVal, result, nullptr, nullptr); mir_free(tmp); } } @@ -299,9 +299,9 @@ STDMETHODIMP_(BOOL) CDb3Mmap::GetContactSettingStr(MCONTACT contactID, LPCSTR sz if (iSaveType == DBVT_WCHAR) { if (dbv->type != DBVT_UTF8) { - int len = MultiByteToWideChar(CP_ACP, 0, dbv->pszVal, -1, NULL, 0); + int len = MultiByteToWideChar(CP_ACP, 0, dbv->pszVal, -1, nullptr, 0); wchar_t* wszResult = (wchar_t*)mir_alloc((len + 1)*sizeof(wchar_t)); - if (wszResult == NULL) + if (wszResult == nullptr) return 1; MultiByteToWideChar(CP_ACP, 0, dbv->pszVal, -1, wszResult, len); @@ -318,14 +318,14 @@ STDMETHODIMP_(BOOL) CDb3Mmap::GetContactSettingStr(MCONTACT contactID, LPCSTR sz } else if (iSaveType == DBVT_UTF8) { char* tmpBuf = mir_utf8encode(dbv->pszVal); - if (tmpBuf == NULL) + if (tmpBuf == nullptr) return 1; mir_free(dbv->pszVal); dbv->pszVal = tmpBuf; } else if (iSaveType == DBVT_ASCIIZ) - mir_utf8decode(dbv->pszVal, NULL); + mir_utf8decode(dbv->pszVal, nullptr); dbv->type = iSaveType; return 0; @@ -356,7 +356,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::GetContactSettingStatic(MCONTACT contactID, LPCSTR dbv->pwszVal[cbLen] = 0; } else if (dbv->type == DBVT_UTF8) { - mir_utf8decode(dbv->pszVal, NULL); + mir_utf8decode(dbv->pszVal, nullptr); dbv->type = DBVT_ASCIIZ; } @@ -385,7 +385,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::FreeVariant(DBVARIANT *dbv) STDMETHODIMP_(BOOL) CDb3Mmap::SetSettingResident(BOOL bIsResident, const char *pszSettingName) { - char *szSetting = m_cache->GetCachedSetting(NULL, pszSettingName, 0, (int)mir_strlen(pszSettingName)); + char *szSetting = m_cache->GetCachedSetting(nullptr, pszSettingName, 0, (int)mir_strlen(pszSettingName)); szSetting[-1] = (char)bIsResident; mir_cslock lck(m_csDbAccess); @@ -402,7 +402,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::SetSettingResident(BOOL bIsResident, const char *p STDMETHODIMP_(BOOL) CDb3Mmap::WriteContactSetting(MCONTACT contactID, DBCONTACTWRITESETTING *dbcws) { - if (dbcws == NULL || dbcws->szSetting == NULL || dbcws->szModule == NULL || m_bReadOnly) + if (dbcws == nullptr || dbcws->szSetting == nullptr || dbcws->szModule == nullptr || m_bReadOnly) return 1; // the db format can't tolerate more than 255 bytes of space (incl. null) for settings+module name @@ -424,9 +424,9 @@ STDMETHODIMP_(BOOL) CDb3Mmap::WriteContactSetting(MCONTACT contactID, DBCONTACTW // used for notifications DBCONTACTWRITESETTING dbcwNotif = *dbcws; if (dbcwNotif.value.type == DBVT_WCHAR) { - if (dbcwNotif.value.pszVal != NULL) { + if (dbcwNotif.value.pszVal != nullptr) { char* val = mir_utf8encodeW(dbcwNotif.value.pwszVal); - if (val == NULL) + if (val == nullptr) return 1; dbcwNotif.value.pszVal = (char*)alloca(mir_strlen(val) + 1); @@ -437,14 +437,14 @@ STDMETHODIMP_(BOOL) CDb3Mmap::WriteContactSetting(MCONTACT contactID, DBCONTACTW else return 1; } - if (dbcwNotif.szModule == NULL || dbcwNotif.szSetting == NULL) + if (dbcwNotif.szModule == nullptr || dbcwNotif.szSetting == nullptr) return 1; DBCONTACTWRITESETTING dbcwWork = dbcwNotif; char *szCachedSettingName = m_cache->GetCachedSetting(dbcwWork.szModule, dbcwWork.szSetting, moduleNameLen, settingNameLen); bool bIsResident = szCachedSettingName[-1] != 0; - mir_ptr pEncoded(NULL); + mir_ptr pEncoded(nullptr); bool bIsEncrypted = false; switch (dbcwWork.value.type) { case DBVT_BYTE: case DBVT_WORD: case DBVT_DWORD: @@ -453,13 +453,13 @@ STDMETHODIMP_(BOOL) CDb3Mmap::WriteContactSetting(MCONTACT contactID, DBCONTACTW case DBVT_ASCIIZ: case DBVT_UTF8: bIsEncrypted = !bIsResident && (m_bEncrypted || IsSettingEncrypted(dbcws->szModule, dbcws->szSetting)); LBL_WriteString: - if (dbcwWork.value.pszVal == NULL) + if (dbcwWork.value.pszVal == nullptr) return 1; dbcwWork.value.cchVal = (WORD)mir_strlen(dbcwWork.value.pszVal); if (bIsEncrypted) { size_t len; BYTE *pResult = m_crypto->encodeString(dbcwWork.value.pszVal, &len); - if (pResult != NULL) { + if (pResult != nullptr) { pEncoded = dbcwWork.value.pbVal = pResult; dbcwWork.value.cpbVal = (WORD)len; dbcwWork.value.type = DBVT_ENCRYPTED; @@ -472,7 +472,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::WriteContactSetting(MCONTACT contactID, DBCONTACTW goto LBL_WriteString; case DBVT_BLOB: case DBVT_ENCRYPTED: - if (dbcwWork.value.pbVal == NULL) + if (dbcwWork.value.pbVal == nullptr) return 1; break; default: @@ -492,7 +492,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::WriteContactSetting(MCONTACT contactID, DBCONTACTW // we don't cache blobs and passwords if (dbcwWork.value.type != DBVT_BLOB && dbcwWork.value.type != DBVT_ENCRYPTED && !bIsEncrypted) { DBVARIANT *pCachedValue = m_cache->GetCachedValuePtr(contactID, szCachedSettingName, 1); - if (pCachedValue != NULL) { + if (pCachedValue != nullptr) { bool bIsIdentical = false; if (pCachedValue->type == dbcwWork.value.type) { switch (dbcwWork.value.type) { @@ -519,7 +519,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::WriteContactSetting(MCONTACT contactID, DBCONTACTW log1(" write database as %s", printVariant(&dbcwWork.value)); DWORD ofsModuleName = GetModuleNameOfs(dbcwWork.szModule); - DBContact dbc = *(DBContact*)DBRead(ofsContact, NULL); + DBContact dbc = *(DBContact*)DBRead(ofsContact, nullptr); if (dbc.signature != DBCONTACT_SIGNATURE) return 1; @@ -652,11 +652,11 @@ STDMETHODIMP_(BOOL) CDb3Mmap::WriteContactSetting(MCONTACT contactID, DBCONTACTW ofsDbcsPrev = dbc.ofsFirstSettings; if (ofsDbcsPrev == ofsSettingsGroup) ofsDbcsPrev = 0; else { - dbcsPrev = (DBContactSettings*)DBRead(ofsDbcsPrev, NULL); + dbcsPrev = (DBContactSettings*)DBRead(ofsDbcsPrev, nullptr); while (dbcsPrev->ofsNext != ofsSettingsGroup) { - if (dbcsPrev->ofsNext == 0) DatabaseCorruption(NULL); + if (dbcsPrev->ofsNext == 0) DatabaseCorruption(nullptr); ofsDbcsPrev = dbcsPrev->ofsNext; - dbcsPrev = (DBContactSettings*)DBRead(ofsDbcsPrev, NULL); + dbcsPrev = (DBContactSettings*)DBRead(ofsDbcsPrev, nullptr); } } @@ -671,7 +671,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::WriteContactSetting(MCONTACT contactID, DBCONTACTW DBWrite(ofsContact, &dbc, sizeof(DBContact)); } else { - dbcsPrev = (DBContactSettings*)DBRead(ofsDbcsPrev, NULL); + dbcsPrev = (DBContactSettings*)DBRead(ofsDbcsPrev, nullptr); dbcsPrev->ofsNext = ofsNew; DBWrite(ofsDbcsPrev, dbcsPrev, offsetof(DBContactSettings, blob)); } @@ -750,7 +750,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::DeleteContactSetting(MCONTACT contactID, LPCSTR sz if (szCachedSettingName[-1] == 0) { // it's not a resident variable DWORD ofsModuleName = GetModuleNameOfs(szModule); DWORD ofsContact = GetContactOffset(contactID); - DBContact *dbc = (DBContact*)DBRead(ofsContact, NULL); + DBContact *dbc = (DBContact*)DBRead(ofsContact, nullptr); if (dbc->signature != DBCONTACT_SIGNATURE) return 1; @@ -798,7 +798,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::DeleteContactSetting(MCONTACT contactID, LPCSTR sz } else { // resident variable // if a value doesn't exist, simply return error - if (m_cache->GetCachedValuePtr(saveContact, szCachedSettingName, -1) == NULL) + if (m_cache->GetCachedValuePtr(saveContact, szCachedSettingName, -1) == nullptr) return 1; } } @@ -823,7 +823,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::EnumContactSettings(MCONTACT contactID, DBSETTINGE if (ofsContact == 0) return -1; - DBContact *dbc = (DBContact*)DBRead(ofsContact, NULL); + DBContact *dbc = (DBContact*)DBRead(ofsContact, nullptr); if (dbc->signature != DBCONTACT_SIGNATURE) return -1; diff --git a/plugins/Db3x_mmap/src/dbtool/disk.cpp b/plugins/Db3x_mmap/src/dbtool/disk.cpp index fabff439a2..da18f9a1d6 100644 --- a/plugins/Db3x_mmap/src/dbtool/disk.cpp +++ b/plugins/Db3x_mmap/src/dbtool/disk.cpp @@ -78,8 +78,8 @@ DWORD CDb3Mmap::WriteSegment(DWORD ofs, PVOID buf, int cbBytes) ofs = m_dbHeader.ofsFileEnd; m_dbHeader.ofsFileEnd += cbBytes; } - SetFilePointer(cb->hOutFile, ofs, NULL, FILE_BEGIN); - WriteFile(cb->hOutFile, buf, cbBytes, &bytesWritten, NULL); + SetFilePointer(cb->hOutFile, ofs, nullptr, FILE_BEGIN); + WriteFile(cb->hOutFile, buf, cbBytes, &bytesWritten, nullptr); if ((int)bytesWritten < cbBytes) { cb->pfnAddLogMessage(STATUS_FATAL, TranslateT("Can't write to output file - disk full? (%u)"), GetLastError()); return WS_ERROR; @@ -94,8 +94,8 @@ int CDb3Mmap::ReadWrittenSegment(DWORD ofs, PVOID buf, int cbBytes) if (ofs + cbBytes > m_dbHeader.ofsFileEnd) return ERROR_SEEK; - SetFilePointer(cb->hOutFile, ofs, NULL, FILE_BEGIN); - ReadFile(cb->hOutFile, buf, cbBytes, &bytesRead, NULL); + SetFilePointer(cb->hOutFile, ofs, nullptr, FILE_BEGIN); + ReadFile(cb->hOutFile, buf, cbBytes, &bytesRead, nullptr); if ((int)bytesRead < cbBytes) return ERROR_READ_FAULT; diff --git a/plugins/Db3x_mmap/src/dbtool/eventchain.cpp b/plugins/Db3x_mmap/src/dbtool/eventchain.cpp index e03bee1b0d..0225aa685a 100644 --- a/plugins/Db3x_mmap/src/dbtool/eventchain.cpp +++ b/plugins/Db3x_mmap/src/dbtool/eventchain.cpp @@ -33,8 +33,8 @@ static DWORD eventCount; static DWORD lastTimestamp; static DWORD ofsFirstUnread, tsFirstUnread; static DWORD memsize = 0; -static DBEvent* memblock = NULL; -static DBEvent* dbePrevEvent = NULL; +static DBEvent* memblock = nullptr; +static DBEvent* dbePrevEvent = nullptr; void CDb3Mmap::ConvertOldEvent(DBEvent*& dbei) { @@ -56,7 +56,7 @@ void CDb3Mmap::ConvertOldEvent(DBEvent*& dbei) if (msglenW > 0 && msglenW <= msglen) { char* utf8str = Utf8EncodeW((WCHAR*)&dbei->blob[msglen]); - if (utf8str == NULL) + if (utf8str == nullptr) return; dbei->cbBlob = (DWORD)mir_strlen(utf8str) + 1; @@ -98,7 +98,7 @@ void CDb3Mmap::FinishUp(DWORD ofsLast, DBContact *dbc) if (memsize && memblock) { free(memblock); memsize = 0; - memblock = NULL; + memblock = nullptr; } } @@ -123,7 +123,7 @@ DWORD CDb3Mmap::WriteEvent(DBEvent *dbe) DWORD ofs = WriteSegment(WSOFS_END, dbe, offsetof(DBEvent, blob) + dbe->cbBlob); if (ofs == WS_ERROR) { free(memblock); - memblock = NULL; + memblock = nullptr; memsize = 0; return 0; } @@ -135,7 +135,7 @@ int CDb3Mmap::WorkEventChain(DWORD ofsContact, DBContact *dbc, int firstTime) int isUnread = 0; if (firstTime) { - dbePrevEvent = NULL; + dbePrevEvent = nullptr; ofsPrevEvent = 0; ofsDestPrevEvent = 0; ofsThisEvent = dbc->ofsFirstEvent; @@ -219,7 +219,7 @@ int CDb3Mmap::WorkEventChain(DWORD ofsContact, DBContact *dbc, int firstTime) return ERROR_SUCCESS; } - DBEvent *dbePrev = NULL; + DBEvent *dbePrev = nullptr; if (dbePrevEvent && dbeOld.timestamp == lastTimestamp) { int len = offsetof(DBEvent, blob) + dbePrevEvent->cbBlob; dbePrev = (DBEvent*)malloc(len); diff --git a/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp b/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp index 07505eb2ab..45c8120442 100644 --- a/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp +++ b/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp @@ -47,7 +47,7 @@ int CDb3Mmap::WorkInitialCheckHeaders() int CDb3Mmap::WorkInitialChecks(int) { - sourceFileSize = GetFileSize(m_hDbFile, NULL); + sourceFileSize = GetFileSize(m_hDbFile, nullptr); if (sourceFileSize == 0) { cb->pfnAddLogMessage(STATUS_WARNING, TranslateT("Database is newly created and has no data to process")); cb->pfnAddLogMessage(STATUS_SUCCESS, TranslateT("Processing completed successfully")); diff --git a/plugins/Db3x_mmap/src/dbtool/modulechain.cpp b/plugins/Db3x_mmap/src/dbtool/modulechain.cpp index 16ff76df78..60ae30af7c 100644 --- a/plugins/Db3x_mmap/src/dbtool/modulechain.cpp +++ b/plugins/Db3x_mmap/src/dbtool/modulechain.cpp @@ -23,7 +23,7 @@ struct ModChainEntry { DWORD ofsOld, ofsNew; int size; char name[257]; -} static *modChain = NULL; +} static *modChain = nullptr; static int modChainCount; static DWORD ofsCurrent; static int phase, iCurrentModName; @@ -132,9 +132,9 @@ DWORD CDb3Mmap::ConvertModuleNameOfs(DWORD ofsOld) void CDb3Mmap::FreeModuleChain() { - if (modChain != NULL) { + if (modChain != nullptr) { free(modChain); - modChain = NULL; + modChain = nullptr; last_mod = 0; } } diff --git a/plugins/Db3x_mmap/src/init.cpp b/plugins/Db3x_mmap/src/init.cpp index 3e7ce1b49a..316ebe4d8a 100644 --- a/plugins/Db3x_mmap/src/init.cpp +++ b/plugins/Db3x_mmap/src/init.cpp @@ -40,7 +40,7 @@ static PLUGININFOEX pluginInfo = { 0xf7a6b27c, 0x9d9c, 0x4a42, { 0xbe, 0x86, 0xa4, 0x48, 0xae, 0x10, 0x91, 0x61 } } }; -HINSTANCE g_hInst = NULL; +HINSTANCE g_hInst = nullptr; LIST g_Dbs(1, HandleKeySortT); @@ -74,7 +74,7 @@ static MIDatabase* LoadDatabase(const wchar_t *profile, BOOL bReadOnly) std::auto_ptr db(new CDb3Mmap(profile, (bReadOnly) ? DBMODE_READONLY : 0)); if (db->Load(false) != ERROR_SUCCESS) - return NULL; + return nullptr; g_Dbs.insert(db.get()); return db.release(); @@ -92,11 +92,11 @@ MIDatabaseChecker* CheckDb(const wchar_t *profile, int *error) std::auto_ptr db(new CDb3Mmap(profile, DBMODE_READONLY)); if (db->Load(true) != ERROR_SUCCESS) { *error = ERROR_ACCESS_DENIED; - return NULL; + return nullptr; } if (db->PrepareCheck(error)) - return NULL; + return nullptr; return db.release(); } diff --git a/plugins/Db3x_mmap/src/ui.cpp b/plugins/Db3x_mmap/src/ui.cpp index a704df0bf7..8254a99df4 100644 --- a/plugins/Db3x_mmap/src/ui.cpp +++ b/plugins/Db3x_mmap/src/ui.cpp @@ -81,7 +81,7 @@ static INT_PTR CALLBACK sttEnterPassword(HWND hwndDlg, UINT uMsg, WPARAM wParam, else SetDlgItemText(hwndDlg, IDC_HEADERBAR, TranslateT("Please type in your password")); oldLangID = 0; - SetTimer(hwndDlg, 1, 200, NULL); + SetTimer(hwndDlg, 1, 200, nullptr); LanguageChanged(hwndDlg); return TRUE; @@ -184,7 +184,7 @@ static INT_PTR CALLBACK sttChangePassword(HWND hwndDlg, UINT uMsg, WPARAM wParam SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); oldLangID = 0; - SetTimer(hwndDlg, 1, 200, NULL); + SetTimer(hwndDlg, 1, 200, nullptr); LanguageChanged(hwndDlg); return TRUE; @@ -211,7 +211,7 @@ static INT_PTR CALLBACK sttChangePassword(HWND hwndDlg, UINT uMsg, WPARAM wParam } else { param->db->WriteSignature(dbSignatureU); - param->db->SetPassword(NULL); + param->db->SetPassword(nullptr); param->db->StoreKey(); EndDialog(hwndDlg, IDREMOVE); } -- cgit v1.2.3