summaryrefslogtreecommitdiff
path: root/protocols/YAMN/src/account.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-12-12 21:11:44 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-12-12 21:11:44 +0300
commit46793bcdf9bdc0c48a509aa1a2d41dbc262500bf (patch)
treee0a2f1824c50a2ee0a0b9b4de82867db43e67f85 /protocols/YAMN/src/account.cpp
parentf72215dbc4afeaf81fad333eb6de01591637021b (diff)
YAMN: code cleaning
Diffstat (limited to 'protocols/YAMN/src/account.cpp')
-rw-r--r--protocols/YAMN/src/account.cpp604
1 files changed, 204 insertions, 400 deletions
diff --git a/protocols/YAMN/src/account.cpp b/protocols/YAMN/src/account.cpp
index 9749462f24..91b57ad544 100644
--- a/protocols/YAMN/src/account.cpp
+++ b/protocols/YAMN/src/account.cpp
@@ -8,9 +8,9 @@
#include "stdafx.h"
-// Account status CS
-// When we check some account, thread should change status of account to idle, connecting etc.
-// So if we want to read status, we have to successfully write and then read.
+ // Account status CS
+ // When we check some account, thread should change status of account to idle, connecting etc.
+ // So if we want to read status, we have to successfully write and then read.
static mir_cs csAccountStatusCS;
// File Writing CS
@@ -19,19 +19,19 @@ static mir_cs csFileWritingCS;
struct CExportedFunctions AccountExportedFcn[] =
{
- { YAMN_GETSTATUSID, (void *)GetStatusFcn },
- { YAMN_SETSTATUSID, (void *)SetStatusFcn },
+ {YAMN_GETSTATUSID, (void *)GetStatusFcn},
+ {YAMN_SETSTATUSID, (void *)SetStatusFcn},
};
struct CExportedServices AccountExportedSvc[] =
{
- { MS_YAMN_CREATEPLUGINACCOUNT, CreatePluginAccountSvc },
- { MS_YAMN_DELETEPLUGINACCOUNT, DeletePluginAccountSvc },
- { MS_YAMN_FINDACCOUNTBYNAME, FindAccountByNameSvc },
- { MS_YAMN_GETNEXTFREEACCOUNT, GetNextFreeAccountSvc },
- { MS_YAMN_DELETEACCOUNT, DeletePluginAccountSvc },
- { MS_YAMN_READACCOUNTS, AddAccountsFromFileSvc },
- { MS_YAMN_WRITEACCOUNTS, WriteAccountsToFileSvc },
+ {MS_YAMN_CREATEPLUGINACCOUNT, CreatePluginAccountSvc},
+ {MS_YAMN_DELETEPLUGINACCOUNT, DeletePluginAccountSvc},
+ {MS_YAMN_FINDACCOUNTBYNAME, FindAccountByNameSvc},
+ {MS_YAMN_GETNEXTFREEACCOUNT, GetNextFreeAccountSvc},
+ {MS_YAMN_DELETEACCOUNT, DeletePluginAccountSvc},
+ {MS_YAMN_READACCOUNTS, AddAccountsFromFileSvc},
+ {MS_YAMN_WRITEACCOUNTS, WriteAccountsToFileSvc},
};
//--------------------------------------------------------------------------------------------------
@@ -46,8 +46,7 @@ INT_PTR CreatePluginAccountSvc(WPARAM wParam, LPARAM lParam)
if (AccountVersion != YAMN_ACCOUNTVERSION)
return NULL;
- if (Plugin != nullptr)
- {
+ if (Plugin != nullptr) {
CAccount *NewAccount;
if (Plugin->Fcn->NewAccountFcnPtr != nullptr)
//Let plugin create its own structure, which can be derived from CAccount structure
@@ -59,7 +58,7 @@ INT_PTR CreatePluginAccountSvc(WPARAM wParam, LPARAM lParam)
//If not created successfully
if (NewAccount == nullptr)
return NULL;
-
+
NewAccount->Plugin = Plugin;
//Init every members of structure, used by YAMN
InitAccount(NewAccount);
@@ -73,20 +72,14 @@ INT_PTR DeletePluginAccountSvc(WPARAM wParam, LPARAM)
{
CAccount *OldAccount = (CAccount *)wParam;
- if (OldAccount->Plugin->Fcn != nullptr)
- {
- //Deinit every members and allocated fields of structure used by YAMN
+ if (OldAccount->Plugin->Fcn != nullptr) {
+ // Deinit every members and allocated fields of structure used by YAMN
DeInitAccount(OldAccount);
- if (OldAccount->Plugin->Fcn->DeleteAccountFcnPtr != nullptr)
- {
- //Let plugin delete its own CAccount derived structure
+ if (OldAccount->Plugin->Fcn->DeleteAccountFcnPtr != nullptr) {
+ // Let plugin delete its own CAccount derived structure
OldAccount->Plugin->Fcn->DeleteAccountFcnPtr(OldAccount);
}
- else
- {
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"DeletePluginAccountSvc:delete OldAccount\n");
-#endif
+ else {
delete OldAccount; //consider account as standard YAMN CAccount *and use its own destructor
}
return 1;
@@ -115,7 +108,7 @@ int InitAccount(CAccount *Which)
Which->Mails = nullptr;
Which->Interval = 0;
Which->Flags = 0;
- Which->StatusFlags = 0;
+ Which->StatusFlags = YAMN_ACC_ST1 + YAMN_ACC_ST7;
Which->Next = nullptr;
Which->Server = new struct CServer;
@@ -150,9 +143,6 @@ void DeInitAccount(CAccount *Which)
void StopSignalFcn(CAccount *Which)
//set event that we are going to delete account
{
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"\tStopSignalFcn:stop account: %x\n",Which);
-#endif
Which->AbleToWork = FALSE;
//do not use synchronizing objects anymore
//any access to these objects then ends with WAIT_FAILED
@@ -167,8 +157,7 @@ void CodeDecodeString(char *Dest, BOOL Encrypt)
if (Dest == nullptr)
return;
- for (; *Dest != (wchar_t)0; Dest++)
- {
+ for (; *Dest != (wchar_t)0; Dest++) {
if (Encrypt)
*Dest = *Dest + Code;
else
@@ -186,15 +175,13 @@ static uint32_t PostFileToMemory(HANDLE File, char **MemFile, char **End)
}
//allocate space in memory, where we copy the whole file
- if (nullptr == (*MemFile = new char[FileSize]))
- {
+ if (nullptr == (*MemFile = new char[FileSize])) {
CloseHandle(File);
return EACC_ALLOC;
}
//copy file to memory
- if (!ReadFile(File, (LPVOID)*MemFile, FileSize, &ReadBytes, nullptr))
- {
+ if (!ReadFile(File, (LPVOID)*MemFile, FileSize, &ReadBytes, nullptr)) {
CloseHandle(File);
delete[] * MemFile;
return EACC_SYSTEM;
@@ -214,30 +201,28 @@ uint32_t FileToMemory(wchar_t *FileName, char **MemFile, char **End)
}
#if defined(DEBUG_FILEREAD) || defined(DEBUG_FILEREADMESSAGES)
-uint32_t ReadStringFromMemory(char **Parser,wchar_t *End,char **StoreTo,wchar_t *DebugString)
+uint32_t ReadStringFromMemory(char **Parser, wchar_t *End, char **StoreTo, wchar_t *DebugString)
{
//This is the debug version of ReadStringFromMemory function. This version shows MessageBox where
//read string is displayed
- wchar_t *Dest,*Finder;
+ wchar_t *Dest, *Finder;
uint32_t Size;
wchar_t Debug[65536];
- Finder=*Parser;
- while((*Finder != (wchar_t)0) && (Finder<=End)) Finder++;
- mir_snwprintf(Debug, L"%s: %s,length is %d, remaining %d chars", DebugString, *Parser, Finder-*Parser, End-Finder);
- MessageBox(NULL,Debug,L"debug",MB_OK);
- if (Finder>=End)
+ Finder = *Parser;
+ while ((*Finder != (wchar_t)0) && (Finder <= End)) Finder++;
+ mir_snwprintf(Debug, L"%s: %s,length is %d, remaining %d chars", DebugString, *Parser, Finder - *Parser, End - Finder);
+ MessageBox(NULL, Debug, L"debug", MB_OK);
+ if (Finder >= End)
return EACC_FILECOMPATIBILITY;
- if (Size=Finder-*Parser)
- {
- if (NULL==(Dest=*StoreTo=new wchar_t[Size+1]))
+ if (Size = Finder - *Parser) {
+ if (NULL == (Dest = *StoreTo = new wchar_t[Size + 1]))
return EACC_ALLOC;
- for (;*Parser<=Finder;(*Parser)++,Dest++)
- *Dest=**Parser;
+ for (; *Parser <= Finder; (*Parser)++, Dest++)
+ *Dest = **Parser;
}
- else
- {
- *StoreTo=NULL;
+ else {
+ *StoreTo = NULL;
(*Parser)++;
}
return 0;
@@ -253,15 +238,13 @@ uint32_t ReadStringFromMemory(char **Parser, char *End, char **StoreTo)
while ((*Finder != (wchar_t)0) && (Finder <= End)) Finder++;
if (Finder >= End)
return EACC_FILECOMPATIBILITY;
- if (Size = Finder - *Parser)
- {
+ if (Size = Finder - *Parser) {
if (nullptr == (Dest = *StoreTo = new char[Size + 1]))
return EACC_ALLOC;
for (; *Parser <= Finder; (*Parser)++, Dest++)
*Dest = **Parser;
}
- else
- {
+ else {
*StoreTo = nullptr;
(*Parser)++;
}
@@ -269,30 +252,28 @@ uint32_t ReadStringFromMemory(char **Parser, char *End, char **StoreTo)
}
#if defined(DEBUG_FILEREAD) || defined(DEBUG_FILEREADMESSAGES)
-uint32_t ReadStringFromMemoryW(wchar_t **Parser,wchar_t *End,wchar_t **StoreTo,wchar_t *DebugString)
+uint32_t ReadStringFromMemoryW(wchar_t **Parser, wchar_t *End, wchar_t **StoreTo, wchar_t *DebugString)
{
//This is the debug version of ReadStringFromMemoryW function. This version shows MessageBox where
//read string is displayed
- wchar_t *Dest,*Finder;
+ wchar_t *Dest, *Finder;
uint32_t Size;
wchar_t Debug[65536];
- Finder=*Parser;
- while((*Finder != (wchar_t)0) && (Finder<=(wchar_t *)End)) Finder++;
- mir_snwprintf(Debug, L"%s: %s,length is %d, remaining %d chars", DebugString, *Parser, Finder-*Parser, (wchar_t *)End-Finder);
- MessageBoxW(NULL,Debug,L"debug",MB_OK);
- if (Finder>=(wchar_t *)End)
+ Finder = *Parser;
+ while ((*Finder != (wchar_t)0) && (Finder <= (wchar_t *)End)) Finder++;
+ mir_snwprintf(Debug, L"%s: %s,length is %d, remaining %d chars", DebugString, *Parser, Finder - *Parser, (wchar_t *)End - Finder);
+ MessageBoxW(NULL, Debug, L"debug", MB_OK);
+ if (Finder >= (wchar_t *)End)
return EACC_FILECOMPATIBILITY;
- if (Size=Finder-*Parser)
- {
- if (NULL==(Dest=*StoreTo=new wchar_t[Size+1]))
+ if (Size = Finder - *Parser) {
+ if (NULL == (Dest = *StoreTo = new wchar_t[Size + 1]))
return EACC_ALLOC;
- for (;*Parser<=Finder;(*Parser)++,Dest++)
- *Dest=**Parser;
+ for (; *Parser <= Finder; (*Parser)++, Dest++)
+ *Dest = **Parser;
}
- else
- {
- *StoreTo=NULL;
+ else {
+ *StoreTo = NULL;
(*Parser)++;
}
return 0;
@@ -308,15 +289,13 @@ uint32_t ReadStringFromMemoryW(wchar_t **Parser, wchar_t *End, wchar_t **StoreTo
while ((*Finder != (wchar_t)0) && (Finder <= (wchar_t *)End)) Finder++;
if (Finder >= (wchar_t *)End)
return EACC_FILECOMPATIBILITY;
- if (Size = Finder - *Parser)
- {
+ if (Size = Finder - *Parser) {
if (nullptr == (Dest = *StoreTo = new wchar_t[Size + 1]))
return EACC_ALLOC;
for (; *Parser <= Finder; (*Parser)++, Dest++)
*Dest = **Parser;
}
- else
- {
+ else {
*StoreTo = nullptr;
(*Parser)++;
}
@@ -326,55 +305,55 @@ uint32_t ReadStringFromMemoryW(wchar_t **Parser, wchar_t *End, wchar_t **StoreTo
static uint32_t ReadNotificationFromMemory(char **Parser, char *End, YAMN_NOTIFICATION *Which)
{
uint32_t Stat;
-#ifdef DEBUG_FILEREAD
+ #ifdef DEBUG_FILEREAD
wchar_t Debug[65536];
-#endif
+ #endif
Which->Flags = *(uint32_t *)(*Parser);
(*Parser) += sizeof(uint32_t);
if (*Parser >= End)
return EACC_FILECOMPATIBILITY;
-#ifdef DEBUG_FILEREAD
- mir_snwprintf(Debug, L"NFlags: %04x, remaining %d chars", Which->Flags, End-*Parser);
- MessageBox(NULL,Debug,L"debug",MB_OK);
-#endif
+ #ifdef DEBUG_FILEREAD
+ mir_snwprintf(Debug, L"NFlags: %04x, remaining %d chars", Which->Flags, End - *Parser);
+ MessageBox(NULL, Debug, L"debug", MB_OK);
+ #endif
Which->PopupB = *(COLORREF *)(*Parser);
(*Parser) += sizeof(COLORREF);
if (*Parser >= End)
return EACC_FILECOMPATIBILITY;
-#ifdef DEBUG_FILEREAD
- mir_snwprintf(Debug, L"PopupB: %04x, remaining %d chars", Which->PopupB, End-*Parser);
- MessageBox(NULL,Debug,L"debug",MB_OK);
-#endif
+ #ifdef DEBUG_FILEREAD
+ mir_snwprintf(Debug, L"PopupB: %04x, remaining %d chars", Which->PopupB, End - *Parser);
+ MessageBox(NULL, Debug, L"debug", MB_OK);
+ #endif
Which->PopupT = *(COLORREF *)(*Parser);
(*Parser) += sizeof(COLORREF);
if (*Parser >= End)
return EACC_FILECOMPATIBILITY;
-#ifdef DEBUG_FILEREAD
- mir_snwprintf(Debug, L"PopupT: %04x, remaining %d chars", Which->PopupT, End-*Parser);
- MessageBox(NULL,Debug,L"debug",MB_OK);
-#endif
+ #ifdef DEBUG_FILEREAD
+ mir_snwprintf(Debug, L"PopupT: %04x, remaining %d chars", Which->PopupT, End - *Parser);
+ MessageBox(NULL, Debug, L"debug", MB_OK);
+ #endif
Which->PopupTime = *(uint32_t *)(*Parser);
(*Parser) += sizeof(uint32_t);
if (*Parser >= End)
return EACC_FILECOMPATIBILITY;
-#ifdef DEBUG_FILEREAD
- mir_snwprintf(Debug, L"PopupTime: %04x, remaining %d chars", Which->PopupTime, End-*Parser);
- MessageBox(NULL,Debug,L"debug",MB_OK);
-#endif
-
-#ifdef DEBUG_FILEREAD
- if (Stat=ReadStringFromMemoryW((wchar_t **)Parser,(wchar_t*)End,&Which->App,L"App"))
-#else
- if (Stat = ReadStringFromMemoryW((wchar_t **)Parser, (wchar_t*)End, &Which->App))
-#endif
+ #ifdef DEBUG_FILEREAD
+ mir_snwprintf(Debug, L"PopupTime: %04x, remaining %d chars", Which->PopupTime, End - *Parser);
+ MessageBox(NULL, Debug, L"debug", MB_OK);
+ #endif
+
+ #ifdef DEBUG_FILEREAD
+ if (Stat = ReadStringFromMemoryW((wchar_t **)Parser, (wchar_t *)End, &Which->App, L"App"))
+ #else
+ if (Stat = ReadStringFromMemoryW((wchar_t **)Parser, (wchar_t *)End, &Which->App))
+ #endif
return Stat;
-#ifdef DEBUG_FILEREAD
- if (Stat=ReadStringFromMemoryW((wchar_t **)Parser,(wchar_t*)End,&Which->AppParam,L"AppParam"))
-#else
- if (Stat = ReadStringFromMemoryW((wchar_t **)Parser, (wchar_t*)End, &Which->AppParam))
-#endif
+ #ifdef DEBUG_FILEREAD
+ if (Stat = ReadStringFromMemoryW((wchar_t **)Parser, (wchar_t *)End, &Which->AppParam, L"AppParam"))
+ #else
+ if (Stat = ReadStringFromMemoryW((wchar_t **)Parser, (wchar_t *)End, &Which->AppParam))
+ #endif
return Stat;
return 0;
}
@@ -387,35 +366,32 @@ uint32_t ReadMessagesFromMemory(CAccount *Which, char **Parser, char *End)
struct CMimeItem *items;
char *ReadString;
-#ifdef DEBUG_FILEREAD
- MessageBox(NULL,L"going to read messages, if any...",L"debug",MB_OK);
-#endif
- do
- {
+ #ifdef DEBUG_FILEREAD
+ MessageBox(NULL, L"going to read messages, if any...", L"debug", MB_OK);
+ #endif
+ do {
Finder = *Parser;
while ((*Finder != (wchar_t)0) && (Finder <= End)) Finder++;
if (Finder >= End)
return EACC_FILECOMPATIBILITY;
- if (Size = Finder - *Parser)
- {
+ if (Size = Finder - *Parser) {
if (Which->Mails == nullptr) //First message in queue
{
if (nullptr == (Which->Mails = ActualMail = CreateAccountMail(Which)))
return EACC_ALLOC;
}
- else
- {
+ else {
if (nullptr == (ActualMail->Next = CreateAccountMail(Which))) {
return EACC_ALLOC;
}
ActualMail = ActualMail->Next;
}
items = nullptr;
-#ifdef DEBUG_FILEREADMESSAGES
- if (Stat=ReadStringFromMemory(Parser,End,&ActualMail->ID,L"ID"))
-#else
+ #ifdef DEBUG_FILEREADMESSAGES
+ if (Stat = ReadStringFromMemory(Parser, End, &ActualMail->ID, L"ID"))
+ #else
if (Stat = ReadStringFromMemory(Parser, End, &ActualMail->ID))
-#endif
+ #endif
return Stat;
// ActualMail->MailData=new MAILDATA; !!! mem leake !!! this is alloc by CreateAccountMail, no need for doubble alloc !!!!
@@ -435,25 +411,23 @@ uint32_t ReadMessagesFromMemory(CAccount *Which, char **Parser, char *End)
if ((nullptr != Which->Plugin->MailFcn) && (nullptr != Which->Plugin->MailFcn->ReadMailOptsFcnPtr))
Which->Plugin->MailFcn->ReadMailOptsFcnPtr(ActualMail, Parser, End); //read plugin mail settings from file
- do
- {
-#if defined(DEBUG_FILEREADMESSAGES) || defined(DEBUG_FILEREAD)
- if (Stat=ReadStringFromMemory(Parser,End,&ReadString,L"Name"))
-#else
+ do {
+ #if defined(DEBUG_FILEREADMESSAGES) || defined(DEBUG_FILEREAD)
+ if (Stat = ReadStringFromMemory(Parser, End, &ReadString, L"Name"))
+ #else
if (Stat = ReadStringFromMemory(Parser, End, &ReadString))
-#endif
+ #endif
return Stat;
if (ReadString == nullptr)
break;
-#ifdef DEBUG_DECODE
- DebugLog(DecodeFile,"<read name>%s</read name>",ReadString);
-#endif
+ #ifdef DEBUG_DECODE
+ DebugLog(DecodeFile, "<read name>%s</read name>", ReadString);
+ #endif
if (items == nullptr)
items = ActualMail->MailData->TranslatedHeader = new struct CMimeItem;
- else
- {
+ else {
items->Next = new struct CMimeItem;
items = items->Next;
}
@@ -461,16 +435,16 @@ uint32_t ReadMessagesFromMemory(CAccount *Which, char **Parser, char *End)
return EACC_ALLOC;
items->name = ReadString;
-#ifdef DEBUG_FILEREADMESSAGES
- if (Stat=ReadStringFromMemory(Parser,End,&ReadString,L"Value"))
-#else
+ #ifdef DEBUG_FILEREADMESSAGES
+ if (Stat = ReadStringFromMemory(Parser, End, &ReadString, L"Value"))
+ #else
if (Stat = ReadStringFromMemory(Parser, End, &ReadString))
-#endif
+ #endif
return Stat;
items->value = ReadString;
-#ifdef DEBUG_DECODE
- DebugLog(DecodeFile,"<read value>%s</read value>\n",ReadString);
-#endif
+ #ifdef DEBUG_DECODE
+ DebugLog(DecodeFile, "<read value>%s</read value>\n", ReadString);
+ #endif
} while (1);
}
else
@@ -484,46 +458,46 @@ uint32_t ReadMessagesFromMemory(CAccount *Which, char **Parser, char *End)
uint32_t ReadAccountFromMemory(CAccount *Which, char **Parser, char *End)
{
uint32_t Stat;
-#ifdef DEBUG_FILEREAD
+ #ifdef DEBUG_FILEREAD
wchar_t Debug[65536];
-#endif
+ #endif
//Read name of account
-#ifdef DEBUG_FILEREAD
- if (Stat=ReadStringFromMemory(Parser,End,&Which->Name,L"Name"))
-#else
+ #ifdef DEBUG_FILEREAD
+ if (Stat = ReadStringFromMemory(Parser, End, &Which->Name, L"Name"))
+ #else
if (Stat = ReadStringFromMemory(Parser, End, &Which->Name))
-#endif
+ #endif
return Stat;
if (Which->Name == nullptr)
return EACC_FILECOMPATIBILITY;
//Read server parameters
-#ifdef DEBUG_FILEREAD
- if (Stat=ReadStringFromMemory(Parser,End,&Which->Server->Name,L"Server"))
-#else
+ #ifdef DEBUG_FILEREAD
+ if (Stat = ReadStringFromMemory(Parser, End, &Which->Server->Name, L"Server"))
+ #else
if (Stat = ReadStringFromMemory(Parser, End, &Which->Server->Name))
-#endif
+ #endif
return Stat;
Which->Server->Port = *(uint16_t *)(*Parser);
(*Parser) += sizeof(uint16_t);
if (*Parser >= End)
return EACC_FILECOMPATIBILITY;
-#ifdef DEBUG_FILEREAD
- mir_snwprintf(Debug, L"Port: %d, remaining %d chars", Which->Server->Port, End-*Parser);
- MessageBox(NULL,Debug,L"debug",MB_OK);
-#endif
-#ifdef DEBUG_FILEREAD
- if (Stat=ReadStringFromMemory(Parser,End,&Which->Server->Login,L"Login"))
-#else
+ #ifdef DEBUG_FILEREAD
+ mir_snwprintf(Debug, L"Port: %d, remaining %d chars", Which->Server->Port, End - *Parser);
+ MessageBox(NULL, Debug, L"debug", MB_OK);
+ #endif
+ #ifdef DEBUG_FILEREAD
+ if (Stat = ReadStringFromMemory(Parser, End, &Which->Server->Login, L"Login"))
+ #else
if (Stat = ReadStringFromMemory(Parser, End, &Which->Server->Login))
-#endif
+ #endif
return Stat;
-#ifdef DEBUG_FILEREAD
- if (Stat=ReadStringFromMemory(Parser,End,&Which->Server->Passwd,L"Password"))
-#else
+ #ifdef DEBUG_FILEREAD
+ if (Stat = ReadStringFromMemory(Parser, End, &Which->Server->Passwd, L"Password"))
+ #else
if (Stat = ReadStringFromMemory(Parser, End, &Which->Server->Passwd))
-#endif
+ #endif
return Stat;
CodeDecodeString(Which->Server->Passwd, FALSE);
@@ -532,22 +506,22 @@ uint32_t ReadAccountFromMemory(CAccount *Which, char **Parser, char *End)
(*Parser) += sizeof(uint32_t);
if (*Parser >= End)
return EACC_FILECOMPATIBILITY;
-#ifdef DEBUG_FILEREAD
- mir_snwprintf(Debug, L"Flags: %04x, remaining %d chars", Which->Flags, End-*Parser);
- MessageBox(NULL,Debug,L"debug",MB_OK);
-#endif
+ #ifdef DEBUG_FILEREAD
+ mir_snwprintf(Debug, L"Flags: %04x, remaining %d chars", Which->Flags, End - *Parser);
+ MessageBox(NULL, Debug, L"debug", MB_OK);
+ #endif
Which->StatusFlags = *(uint32_t *)(*Parser);
(*Parser) += sizeof(uint32_t);
-#ifdef DEBUG_FILEREAD
- mir_snwprintf(Debug, L"STFlags: %04x, remaining %d chars", Which->StatusFlags, End-*Parser);
- MessageBox(NULL,Debug,L"debug",MB_OK);
-#endif
+ #ifdef DEBUG_FILEREAD
+ mir_snwprintf(Debug, L"STFlags: %04x, remaining %d chars", Which->StatusFlags, End - *Parser);
+ MessageBox(NULL, Debug, L"debug", MB_OK);
+ #endif
Which->PluginFlags = *(uint32_t *)(*Parser);
(*Parser) += sizeof(uint32_t);
-#ifdef DEBUG_FILEREAD
- mir_snwprintf(Debug, L"PFlags: %04x, remaining %d chars", Which->PluginFlags, End-*Parser);
- MessageBox(NULL,Debug,L"debug",MB_OK);
-#endif
+ #ifdef DEBUG_FILEREAD
+ mir_snwprintf(Debug, L"PFlags: %04x, remaining %d chars", Which->PluginFlags, End - *Parser);
+ MessageBox(NULL, Debug, L"debug", MB_OK);
+ #endif
//Read account miscellaneous parameters
Which->Interval = *(uint16_t *)(*Parser);
@@ -555,10 +529,10 @@ uint32_t ReadAccountFromMemory(CAccount *Which, char **Parser, char *End)
(*Parser) += sizeof(uint16_t);
if (*Parser >= End)
return EACC_FILECOMPATIBILITY;
-#ifdef DEBUG_FILEREAD
- mir_snwprintf(Debug, L"Interval: %d, remaining %d chars", Which->Interval, End-*Parser);
- MessageBox(NULL,Debug,L"debug",MB_OK);
-#endif
+ #ifdef DEBUG_FILEREAD
+ mir_snwprintf(Debug, L"Interval: %d, remaining %d chars", Which->Interval, End - *Parser);
+ MessageBox(NULL, Debug, L"debug", MB_OK);
+ #endif
//Read notification parameters
if (Stat = ReadNotificationFromMemory(Parser, End, &Which->NewMailN))
@@ -572,162 +546,108 @@ uint32_t ReadAccountFromMemory(CAccount *Which, char **Parser, char *End)
if (Which->Plugin->Fcn != nullptr && Which->Plugin->Fcn->ReadPluginOptsFcnPtr != nullptr)
if (Stat = Which->Plugin->Fcn->ReadPluginOptsFcnPtr(Which, Parser, End))
return Stat;
- //Read mails
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"ReadAccountFromMemory:ActualAccountMsgsSO-write wait\n");
-#endif
+
+ // Read mails
WaitToWriteFcn(Which->MessagesAccessSO);
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"ReadAccountFromMemory:ActualAccountMsgsSO-write enter\n");
-#endif
- if (Stat = ReadMessagesFromMemory(Which, Parser, End))
- {
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"ReadAccountFromMemory:ActualAccountMsgsSO-write done\n");
-#endif
+
+ if (Stat = ReadMessagesFromMemory(Which, Parser, End)) {
WriteDoneFcn(Which->MessagesAccessSO);
return Stat;
}
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"ReadAccountFromMemory:ActualAccountMsgsSO-write done\n");
-#endif
+
WriteDoneFcn(Which->MessagesAccessSO);
- //Read timestamps
+ // Read timestamps
Which->LastChecked = *(SYSTEMTIME *)(*Parser);
(*Parser) += sizeof(SYSTEMTIME);
if (*Parser >= End)
return EACC_FILECOMPATIBILITY;
-#ifdef DEBUG_FILEREAD
- mir_snwprintf(Debug, L"LastChecked: %04x, remaining %d chars", Which->LastChecked, End-*Parser);
- MessageBox(NULL,Debug,L"debug",MB_OK);
-#endif
+
Which->LastSChecked = *(SYSTEMTIME *)(*Parser);
(*Parser) += sizeof(SYSTEMTIME);
if (*Parser >= End)
return EACC_FILECOMPATIBILITY;
-#ifdef DEBUG_FILEREAD
- mir_snwprintf(Debug, L"LastSChecked: %04x, remaining %d chars", Which->LastSChecked, End-*Parser);
- MessageBox(NULL,Debug,L"debug",MB_OK);
-#endif
+
Which->LastSynchronised = *(SYSTEMTIME *)(*Parser);
(*Parser) += sizeof(SYSTEMTIME);
if (*Parser >= End)
return EACC_FILECOMPATIBILITY;
-#ifdef DEBUG_FILEREAD
- mir_snwprintf(Debug, L"LastSynchronised: %04x, remaining %d chars", Which->LastSynchronised, End-*Parser);
- MessageBox(NULL,Debug,L"debug",MB_OK);
-#endif
+
Which->LastMail = *(SYSTEMTIME *)(*Parser);
(*Parser) += sizeof(SYSTEMTIME);
if (*Parser > End) //WARNING! There's only > at the end of testing
return EACC_FILECOMPATIBILITY;
-#ifdef DEBUG_FILEREAD
- mir_snwprintf(Debug, L"LastMail: %04x, remaining %d chars", Which->LastMail, End-*Parser);
- MessageBox(NULL,Debug,L"debug",MB_OK);
-#endif
+
if (*Parser == End)
return EACC_ENDOFFILE;
return 0;
-
}
static INT_PTR PerformAccountReading(HYAMNPROTOPLUGIN Plugin, char *MemFile, char *End)
{
- //Retrieve info for account from memory
+ // Retrieve info for account from memory
char *Parser;
uint32_t Ver, Stat;
CAccount *ActualAccount, *FirstAllocatedAccount;
Ver = *(uint32_t *)MemFile;
- if (Ver > YAMN_ACCOUNTFILEVERSION)
- {
+ if (Ver > YAMN_ACCOUNTFILEVERSION) {
delete[] MemFile;
return EACC_FILEVERSION;
}
Parser = MemFile + sizeof(Ver);
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"AddAccountsFromFile:AccountBrowserSO-write wait\n");
-#endif
SWMRGWaitToWrite(Plugin->AccountBrowserSO, INFINITE);
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"AddAccountsFromFile:AccountBrowserSO-write enter\n");
-#endif
- if (nullptr == (ActualAccount = (CAccount *)CallService(MS_YAMN_GETNEXTFREEACCOUNT, (WPARAM)Plugin, (LPARAM)YAMN_ACCOUNTVERSION)))
- {
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"AddAccountsFromFile:AccountBrowserSO-write done\n");
-#endif
+
+ if (nullptr == (ActualAccount = (CAccount *)CallService(MS_YAMN_GETNEXTFREEACCOUNT, (WPARAM)Plugin, (LPARAM)YAMN_ACCOUNTVERSION))) {
SWMRGDoneWriting(Plugin->AccountBrowserSO);
delete[] MemFile;
return EACC_ALLOC;
}
+
FirstAllocatedAccount = ActualAccount;
- do
- {
+ do {
CAccount *Temp;
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"AddAccountsFromFile:ActualAccountSO-write wait\n");
-#endif
WaitToWriteFcn(ActualAccount->AccountAccessSO);
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"AddAccountsFromFile:ActualAccountSO-write enter\n");
-#endif
Stat = ReadAccountFromMemory(ActualAccount, &Parser, End);
if (ActualAccount->StatusFlags & (YAMN_ACC_STARTA | YAMN_ACC_STARTS))
ActualAccount->TimeLeft = 1; //check on loading
- if (Stat && (Stat != EACC_ENDOFFILE))
- {
- for (ActualAccount = FirstAllocatedAccount; ActualAccount != nullptr; ActualAccount = Temp)
- {
+ if (Stat && (Stat != EACC_ENDOFFILE)) {
+ for (ActualAccount = FirstAllocatedAccount; ActualAccount != nullptr; ActualAccount = Temp) {
Temp = ActualAccount->Next;
delete ActualAccount;
}
delete[] MemFile;
if (Plugin->FirstAccount == FirstAllocatedAccount)
Plugin->FirstAccount = nullptr;
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"AddAccountsFromFile:ActualAccountSO-write done\n");
-#endif
+
SWMRGDoneWriting(Plugin->AccountBrowserSO);
return (INT_PTR)Stat;
}
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"AddAccountsFromFile:ActualAccountSO-write done\n");
-#endif
WriteDoneFcn(ActualAccount->AccountAccessSO);
- if ((Stat != EACC_ENDOFFILE) && (nullptr == (ActualAccount = (CAccount *)CallService(MS_YAMN_GETNEXTFREEACCOUNT, (WPARAM)Plugin, (LPARAM)YAMN_ACCOUNTVERSION))))
- {
- for (ActualAccount = FirstAllocatedAccount; ActualAccount != nullptr; ActualAccount = Temp)
- {
+ if ((Stat != EACC_ENDOFFILE) && (nullptr == (ActualAccount = (CAccount *)CallService(MS_YAMN_GETNEXTFREEACCOUNT, (WPARAM)Plugin, (LPARAM)YAMN_ACCOUNTVERSION)))) {
+ for (ActualAccount = FirstAllocatedAccount; ActualAccount != nullptr; ActualAccount = Temp) {
Temp = ActualAccount->Next;
delete ActualAccount;
}
delete[] MemFile;
if (Plugin->FirstAccount == FirstAllocatedAccount)
Plugin->FirstAccount = nullptr;
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"AddAccountsFromFile:AccountBrowserSO-write done\n");
-#endif
+
SWMRGDoneWriting(Plugin->AccountBrowserSO);
return EACC_ALLOC;
}
} while (Stat != EACC_ENDOFFILE);
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"AddAccountsFromFile:AccountBrowserSO-write done\n");
-#endif
SWMRGDoneWriting(Plugin->AccountBrowserSO);
delete[] MemFile;
-
return 0;
}
@@ -735,7 +655,7 @@ static INT_PTR PerformAccountReading(HYAMNPROTOPLUGIN Plugin, char *MemFile, cha
INT_PTR AddAccountsFromFileSvc(WPARAM wParam, LPARAM lParam)
{
char *MemFile, *End;
- uint32_t Stat = FileToMemory((wchar_t*)lParam, &MemFile, &End);
+ uint32_t Stat = FileToMemory((wchar_t *)lParam, &MemFile, &End);
if (Stat != NO_ERROR)
return (INT_PTR)Stat;
@@ -765,15 +685,13 @@ uint32_t WriteStringToFileW(HANDLE File, wchar_t *Source)
DWORD Length, WrittenBytes;
wchar_t null = (wchar_t)0;
- if ((Source == nullptr) || !(Length = (uint32_t)mir_wstrlen(Source)))
- {
- if (!WriteFile(File, &null, sizeof(wchar_t), &WrittenBytes, nullptr))
- {
+ if ((Source == nullptr) || !(Length = (uint32_t)mir_wstrlen(Source))) {
+ if (!WriteFile(File, &null, sizeof(wchar_t), &WrittenBytes, nullptr)) {
CloseHandle(File);
return EACC_SYSTEM;
}
}
- else if (!WriteFile(File, Source, (Length + 1)*sizeof(wchar_t), &WrittenBytes, nullptr))
+ else if (!WriteFile(File, Source, (Length + 1) * sizeof(wchar_t), &WrittenBytes, nullptr))
return EACC_SYSTEM;
return 0;
}
@@ -784,19 +702,17 @@ DWORD WriteMessagesToFile(HANDLE File, CAccount *Which)
HYAMNMAIL ActualMail = (HYAMNMAIL)Which->Mails;
struct CMimeItem *items;
- while (ActualMail != nullptr)
- {
+ while (ActualMail != nullptr) {
if (Stat = WriteStringToFile(File, ActualMail->ID))
return Stat;
-
+
if (!WriteFile(File, (char *)&ActualMail->MailData->Size, sizeof(ActualMail->MailData->Size), &WrittenBytes, nullptr) ||
!WriteFile(File, (char *)&ActualMail->Flags, sizeof(ActualMail->Flags), &WrittenBytes, nullptr) ||
!WriteFile(File, (char *)&ActualMail->Number, sizeof(ActualMail->Number), &WrittenBytes, nullptr))
return EACC_SYSTEM;
if ((nullptr != Which->Plugin->MailFcn) && (nullptr != Which->Plugin->MailFcn->WriteMailOptsFcnPtr))
Which->Plugin->MailFcn->WriteMailOptsFcnPtr(File, ActualMail); //write plugin mail options to file
- for (items = ActualMail->MailData->TranslatedHeader; items != nullptr; items = items->Next)
- {
+ for (items = ActualMail->MailData->TranslatedHeader; items != nullptr; items = items->Next) {
if (Stat = WriteStringToFile(File, items->name))
return Stat;
if (Stat = WriteStringToFile(File, items->value))
@@ -819,45 +735,27 @@ static INT_PTR PerformAccountWriting(HYAMNPROTOPLUGIN Plugin, HANDLE File)
BOOL Writed = FALSE;
uint32_t ReturnValue = 0, EnterCode;
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"WriteAccountsToFile:AccountBrowserSO-read wait\n");
-#endif
SWMRGWaitToRead(Plugin->AccountBrowserSO, INFINITE);
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"WriteAccountsToFile:AccountBrowserSO-read enter\n");
-#endif
- try
- {
- for (ActualAccount = Plugin->FirstAccount; ActualAccount != nullptr; ActualAccount = ActualAccount->Next)
- {
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read wait\n");
-#endif
+
+ try {
+ for (ActualAccount = Plugin->FirstAccount; ActualAccount != nullptr; ActualAccount = ActualAccount->Next) {
EnterCode = WaitToReadFcn(ActualAccount->AccountAccessSO);
if (EnterCode == WAIT_FINISH) //account is about to delete
{
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read wait failed\n");
-#endif
ActualAccount = ActualAccount->Next;
continue;
}
if (EnterCode == WAIT_FAILED) //account is deleted
break;
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read enter\n");
-#endif
- if ((ActualAccount->Name == nullptr) || (*ActualAccount->Name == (wchar_t)0))
- {
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read done\n");
-#endif
+
+ if ((ActualAccount->Name == nullptr) || (*ActualAccount->Name == (wchar_t)0)) {
ReadDoneFcn(ActualAccount->AccountAccessSO);
continue;
}
if (!Writed && !WriteFile(File, &Ver, sizeof(Ver), &WrittenBytes, nullptr))
throw (uint32_t)EACC_SYSTEM;
+
Writed = TRUE;
if (Stat = WriteStringToFile(File, ActualAccount->Name))
@@ -874,8 +772,7 @@ static INT_PTR PerformAccountWriting(HYAMNPROTOPLUGIN Plugin, HANDLE File)
CodeDecodeString(ActualAccount->Server->Passwd, TRUE);
- if (Stat = WriteStringToFile(File, ActualAccount->Server->Passwd))
- {
+ if (Stat = WriteStringToFile(File, ActualAccount->Server->Passwd)) {
CodeDecodeString(ActualAccount->Server->Passwd, FALSE);
throw (uint32_t)Stat;
}
@@ -923,24 +820,15 @@ static INT_PTR PerformAccountWriting(HYAMNPROTOPLUGIN Plugin, HANDLE File)
if (ActualAccount->Plugin->Fcn != nullptr && ActualAccount->Plugin->Fcn->WritePluginOptsFcnPtr != nullptr)
if (Stat = ActualAccount->Plugin->Fcn->WritePluginOptsFcnPtr(File, ActualAccount))
throw (uint32_t)Stat;
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountMsgsSO-read wait\n");
-#endif
+
WaitToReadFcn(ActualAccount->MessagesAccessSO);
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountMsgsSO-read enter\n");
-#endif
- if (Stat = WriteMessagesToFile(File, ActualAccount))
- {
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountMsgsSO-read done\n");
-#endif
+
+ if (Stat = WriteMessagesToFile(File, ActualAccount)) {
+
ReadDoneFcn(ActualAccount->MessagesAccessSO);
throw (uint32_t)Stat;
}
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountMsgsSO-read done\n");
-#endif
+
ReadDoneFcn(ActualAccount->MessagesAccessSO);
if ((!WriteFile(File, (char *)&ActualAccount->LastChecked, sizeof(SYSTEMTIME), &WrittenBytes, nullptr)) ||
@@ -949,23 +837,14 @@ static INT_PTR PerformAccountWriting(HYAMNPROTOPLUGIN Plugin, HANDLE File)
(!WriteFile(File, (char *)&ActualAccount->LastMail, sizeof(SYSTEMTIME), &WrittenBytes, nullptr)))
throw (uint32_t)Stat;
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read done\n");
-#endif
ReadDoneFcn(ActualAccount->AccountAccessSO);
}
}
- catch (uint32_t ErrorCode)
- {
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read done\n");
-#endif
+ catch (uint32_t ErrorCode) {
ReadDoneFcn(ActualAccount->AccountAccessSO);
ReturnValue = ErrorCode;
}
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"WriteAccountsToFile:AccountBrowserSO-read done\n");
-#endif
+
SWMRGDoneReading(Plugin->AccountBrowserSO);
CloseHandle(File);
return 0;
@@ -977,7 +856,7 @@ INT_PTR WriteAccountsToFileSvc(WPARAM wParam, LPARAM lParam)
HYAMNPROTOPLUGIN Plugin = (HYAMNPROTOPLUGIN)wParam;
mir_cslock lck(csFileWritingCS);
- HANDLE hFile = CreateFile((wchar_t*)lParam, GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
+ HANDLE hFile = CreateFile((wchar_t *)lParam, GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (hFile == INVALID_HANDLE_VALUE)
return EACC_SYSTEM;
@@ -990,19 +869,12 @@ INT_PTR FindAccountByNameSvc(WPARAM wParam, LPARAM lParam)
char *SearchedAccount = (char *)lParam;
CAccount *Finder;
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"FindAccountByName:AccountBrowserSO-read wait\n");
-#endif
SWMRGWaitToRead(Plugin->AccountBrowserSO, INFINITE);
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"FindAccountByName:AccountBrowserSO-read enter\n");
-#endif
+
for (Finder = Plugin->FirstAccount; Finder != nullptr; Finder = Finder->Next)
if ((Finder->Name != nullptr) && (0 == mir_strcmp(SearchedAccount, Finder->Name)))
break;
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"FindAccountByName:AccountBrowserSO-read done\n");
-#endif
+
SWMRGDoneReading(Plugin->AccountBrowserSO);
return (INT_PTR)Finder;
}
@@ -1012,8 +884,7 @@ INT_PTR GetNextFreeAccountSvc(WPARAM wParam, LPARAM lParam)
HYAMNPROTOPLUGIN Plugin = (HYAMNPROTOPLUGIN)wParam;
CAccount *Finder;
- if (Plugin->FirstAccount == nullptr)
- {
+ if (Plugin->FirstAccount == nullptr) {
Plugin->FirstAccount = (CAccount *)CallService(MS_YAMN_CREATEPLUGINACCOUNT, wParam, lParam);
return (INT_PTR)Plugin->FirstAccount;
}
@@ -1022,18 +893,6 @@ INT_PTR GetNextFreeAccountSvc(WPARAM wParam, LPARAM lParam)
return (INT_PTR)Finder->Next;
}
-/*
-int FindPluginAccount(WPARAM wParam,LPARAM lParam)
-{
-HYAMNPROTOPLUGIN Plugin=(HYAMNPROTOPLUGIN)wParam;
-CAccount *Finder=(CAccount *)lParam;
-
-if (Finder=NULL) Finder=Plugin->FirstAccount;
-
-// for (;Finder != NULL && Finder->PluginID != Plugin->PluginInfo->PluginID;Finder=(CAccount *)Finder->Next);
-return (int)Finder;
-}
-*/
INT_PTR DeleteAccountSvc(WPARAM wParam, LPARAM lParam)
{
//Deleting account works on these steps:
@@ -1072,37 +931,23 @@ INT_PTR DeleteAccountSvc(WPARAM wParam, LPARAM lParam)
Plugin->Fcn->StopAccountFcnPtr(Which);
//2. wait to get write access
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"DeleteAccount:AccountBrowserSO-write wait\n");
-#endif
SWMRGWaitToWrite(Plugin->AccountBrowserSO, INFINITE);
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"DeleteAccount:AccountBrowserSO-write enter\n");
-#endif
//3. remove from queue (chained list)
- if (Plugin->FirstAccount == nullptr)
- {
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"DeleteAccount:AccountBrowserSO-write done\n");
-#endif
+ if (Plugin->FirstAccount == nullptr) {
SWMRGDoneWriting(Plugin->AccountBrowserSO);
return 0;
}
- if (Plugin->FirstAccount == Which)
- {
+ if (Plugin->FirstAccount == Which) {
Finder = Plugin->FirstAccount->Next;
Plugin->FirstAccount = Finder;
}
- else
- {
+ else {
for (Finder = Plugin->FirstAccount; Which != Finder->Next; Finder = Finder->Next);
Finder->Next = Finder->Next->Next;
}
+
//leave write access
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"DeleteAccount:AccountBrowserSO-write done\n");
-#endif
SWMRGDoneWriting(Plugin->AccountBrowserSO);
//4. wait while event "UsingThread" is not signaled
@@ -1113,7 +958,7 @@ INT_PTR DeleteAccountSvc(WPARAM wParam, LPARAM lParam)
if ((Plugin->Fcn != nullptr) && (Plugin->Fcn->WriteAccountsFcnPtr != nullptr))
Plugin->Fcn->WriteAccountsFcnPtr();
- CloseHandle(mir_forkthread(DeleteAccountInBackground, (void*)Which));
+ CloseHandle(mir_forkthread(DeleteAccountInBackground, (void *)Which));
//Now, plugin can consider account as deleted, but plugin really can achieve deleting this account from memory when using
//event UsingThreads.
@@ -1132,15 +977,9 @@ int StopAccounts(HYAMNPROTOPLUGIN Plugin)
CAccount *Finder;
//1. wait to get write access
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"StopAccounts:AccountBrowserSO-write wait\n");
-#endif
SWMRGWaitToWrite(Plugin->AccountBrowserSO, INFINITE);
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"StopAccounts:AccountBrowserSO-write enter\n");
-#endif
- for (Finder = Plugin->FirstAccount; Finder != nullptr; Finder = Finder->Next)
- {
+
+ for (Finder = Plugin->FirstAccount; Finder != nullptr; Finder = Finder->Next) {
//2. set stop signal
StopSignalFcn(Finder);
WindowList_BroadcastAsync(YAMNVar.MessageWnds, WM_YAMN_STOPACCOUNT, (WPARAM)Finder, 0);
@@ -1149,9 +988,6 @@ int StopAccounts(HYAMNPROTOPLUGIN Plugin)
}
//leave write access
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"StopAccounts:AccountBrowserSO-write done\n");
-#endif
SWMRGDoneWriting(Plugin->AccountBrowserSO);
//Now, account is stopped. It can be removed from memory...
@@ -1160,37 +996,17 @@ int StopAccounts(HYAMNPROTOPLUGIN Plugin)
int WaitForAllAccounts(HYAMNPROTOPLUGIN Plugin, BOOL GetAccountBrowserAccess)
{
- CAccount *Finder;
-
- if (GetAccountBrowserAccess)
- {
+ if (GetAccountBrowserAccess) {
//1. wait to get write access
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"WaitForAllAccounts:AccountBrowserSO-write wait\n");
-#endif
SWMRGWaitToWrite(Plugin->AccountBrowserSO, INFINITE);
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"WaitForAllAccounts:AccountBrowserSO-write enter\n");
-#endif
}
- for (Finder = Plugin->FirstAccount; Finder != nullptr; Finder = Finder->Next)
- {
+ for (CAccount *Finder = Plugin->FirstAccount; Finder != nullptr; Finder = Finder->Next) {
//2. wait for signal that account is not in use
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"WaitForAllAccounts:waiting for UsingThreadEV %x (account %x)\n",Finder->UsingThreads,Finder);
-#endif
WaitForSingleObject(Finder->UsingThreads->Event, INFINITE);
SetEvent(Finder->UsingThreads->Event);
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"WaitForAllAccounts:UsingThreadEV signaled\n");
-#endif
}
- if (GetAccountBrowserAccess)
- {
+ if (GetAccountBrowserAccess) {
//leave write access
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"WaitForAllAccounts:AccountBrowserSO-write done\n");
-#endif
SWMRGDoneWriting(Plugin->AccountBrowserSO);
}
@@ -1199,30 +1015,18 @@ int WaitForAllAccounts(HYAMNPROTOPLUGIN Plugin, BOOL GetAccountBrowserAccess)
int DeleteAccounts(HYAMNPROTOPLUGIN Plugin)
{
- CAccount *Finder;
-
//1. wait to get write access
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"DeleteAccounts:AccountBrowserSO-write wait\n");
-#endif
SWMRGWaitToWrite(Plugin->AccountBrowserSO, INFINITE);
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"DeleteAccounts:AccountBrowserSO-write enter\n");
-#endif
WaitForAllAccounts(Plugin, FALSE);
- for (Finder = Plugin->FirstAccount; Finder != nullptr;)
- {
+ for (CAccount *Finder = Plugin->FirstAccount; Finder != nullptr;) {
CAccount *Next = Finder->Next;
DeletePluginAccountSvc((WPARAM)Finder, 0);
Finder = Next;
}
//leave write access
-#ifdef DEBUG_SYNCHRO
- DebugLog(SynchroFile,"DeleteAccounts:AccountBrowserSO-write done\n");
-#endif
SWMRGDoneWriting(Plugin->AccountBrowserSO);
return 1;
}