From 5b796cb19202cbd63634ff68bda89520a5efc0c3 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 19 Feb 2016 12:05:55 +0000 Subject: YAMN: - incorrect Unicode processing fixed; - critical sections removed; - translation fix; - code cleaning; git-svn-id: http://svn.miranda-ng.org/main/trunk@16308 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- langpacks/russian/Plugins/YAMN.txt | 2 +- plugins/YAMN/src/account.cpp | 84 +++---------- plugins/YAMN/src/browser/badconnect.cpp | 32 ++--- plugins/YAMN/src/browser/mailbrowser.cpp | 45 +++---- plugins/YAMN/src/filterplugin.cpp | 20 ++-- plugins/YAMN/src/main.cpp | 11 -- plugins/YAMN/src/proto/pop3/pop3opt.cpp | 27 ++--- plugins/YAMN/src/protoplugin.cpp | 15 +-- plugins/YAMN/src/services.cpp | 197 +++++++++++++------------------ plugins/YAMN/src/stdafx.h | 16 +-- plugins/YAMN/src/yamn.cpp | 98 ++++++++------- 11 files changed, 205 insertions(+), 342 deletions(-) diff --git a/langpacks/russian/Plugins/YAMN.txt b/langpacks/russian/Plugins/YAMN.txt index caeb94ae08..23fd29bcca 100644 --- a/langpacks/russian/Plugins/YAMN.txt +++ b/langpacks/russian/Plugins/YAMN.txt @@ -188,7 +188,7 @@ YAMN: сбой подключения [%s - %d new mail messages, %d total] %s - %d новых писем (%d всего) [- new mail message(s)] -- новых писем +- есть новые сообщения [%s : %d new mail message(s), %d total] %s : %d новых писем (%d всего) [%d new mail message(s), %d total] diff --git a/plugins/YAMN/src/account.cpp b/plugins/YAMN/src/account.cpp index 676dfe0b50..3d7648a76f 100644 --- a/plugins/YAMN/src/account.cpp +++ b/plugins/YAMN/src/account.cpp @@ -8,14 +8,14 @@ #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. -CRITICAL_SECTION AccountStatusCS; +// 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 -//When 2 threads want to write to file... -CRITICAL_SECTION FileWritingCS; +// File Writing CS +// When 2 threads want to write to file... +static mir_cs csFileWritingCS; struct CExportedFunctions AccountExportedFcn[] = { @@ -970,23 +970,17 @@ static INT_PTR PerformAccountWriting(HYAMNPROTOPLUGIN Plugin, HANDLE File) return 0; } -//Writes accounts to file +// Writes accounts to file INT_PTR WriteAccountsToFileSvc(WPARAM wParam, LPARAM lParam) { HYAMNPROTOPLUGIN Plugin = (HYAMNPROTOPLUGIN)wParam; - TCHAR* tszFileName = (TCHAR*)lParam; - EnterCriticalSection(&FileWritingCS); - HANDLE hFile = CreateFile(tszFileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - if (hFile == INVALID_HANDLE_VALUE) { - LeaveCriticalSection(&FileWritingCS); + mir_cslock lck(csFileWritingCS); + HANDLE hFile = CreateFile((TCHAR*)lParam, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (hFile == INVALID_HANDLE_VALUE) return EACC_SYSTEM; - } - INT_PTR rv = PerformAccountWriting(Plugin, hFile); - LeaveCriticalSection(&FileWritingCS); - - return rv; + return PerformAccountWriting(Plugin, hFile); } INT_PTR FindAccountByNameSvc(WPARAM wParam, LPARAM lParam) @@ -1229,7 +1223,6 @@ int DeleteAccounts(HYAMNPROTOPLUGIN Plugin) DebugLog(SynchroFile,"DeleteAccounts:AccountBrowserSO-write done\n"); #endif SWMRGDoneWriting(Plugin->AccountBrowserSO); - return 1; } @@ -1238,59 +1231,16 @@ void WINAPI GetStatusFcn(HACCOUNT Which, TCHAR *Value) if (Which == NULL) return; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tGetStatus:AccountStatusCS-cs wait\n"); -#endif - EnterCriticalSection(&AccountStatusCS); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tGetStatus:AccountStatusCS-cs enter\n"); -#endif + mir_cslock lck(csAccountStatusCS); mir_tstrcpy(Value, Which->Status); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tGetStatus:AccountStatusCS-cs done\n"); -#endif - LeaveCriticalSection(&AccountStatusCS); - return; } void WINAPI SetStatusFcn(HACCOUNT Which, TCHAR *Value) { - if (Which == NULL) - return; + if (Which != NULL) { + mir_cslock lck(csAccountStatusCS); + mir_tstrcpy(Which->Status, Value); + } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tSetStatus:AccountStatusCS-cs wait\n"); -#endif - EnterCriticalSection(&AccountStatusCS); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tSetStatus:AccountStatusCS-cs enter\n"); -#endif - mir_tstrcpy(Which->Status, Value); WindowList_BroadcastAsync(YAMNVar.MessageWnds, WM_YAMN_CHANGESTATUS, (WPARAM)Which, 0); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tSetStatus:AccountStatusCS-cs done\n"); -#endif - LeaveCriticalSection(&AccountStatusCS); } - -/* -#ifdef DEBUG_ACCOUNTS -int GetAccounts() -{ -HACCOUNT Finder; -int cnt=0; - -for (Finder=Account;Finder != NULL;Finder=Finder->Next) -cnt++; -return cnt; -} - -void WriteAccounts() -{ -HACCOUNT Finder; - -for (Finder=Account;Finder != NULL;Finder=Finder->Next) -MessageBoxA(NULL,Finder->Name,"Browsing account",MB_OK); -} -#endif -*/ diff --git a/plugins/YAMN/src/browser/badconnect.cpp b/plugins/YAMN/src/browser/badconnect.cpp index 1285571205..69274be795 100644 --- a/plugins/YAMN/src/browser/badconnect.cpp +++ b/plugins/YAMN/src/browser/badconnect.cpp @@ -216,10 +216,6 @@ void __cdecl BadConnection(void *Param) MSG msg; HWND hBadConnect; HACCOUNT ActualAccount; - NOTIFYICONDATA nid; - char *NotIconText = Translate(" - connection error"), *src; - TCHAR *dest; - int i; struct BadConnectionParam MyParam = *(struct BadConnectionParam *)Param; ActualAccount = MyParam.account; @@ -237,19 +233,10 @@ void __cdecl BadConnection(void *Param) SendMessage(hBadConnect, WM_SETICON, ICON_BIG, (LPARAM)g_LoadIconEx(3)); SendMessage(hBadConnect, WM_SETICON, ICON_SMALL, (LPARAM)g_LoadIconEx(3)); - memset(&nid, 0, sizeof(nid)); - nid.cbSize = sizeof(NOTIFYICONDATA); - nid.hWnd = hBadConnect; - nid.hIcon = g_LoadIconEx(3); - nid.uID = 0; - nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; - nid.uCallbackMessage = WM_YAMN_NOTIFYICON; - #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read wait\n"); #endif - if (WAIT_OBJECT_0 != WaitToReadFcn(ActualAccount->AccountAccessSO)) - { + if (WAIT_OBJECT_0 != WaitToReadFcn(ActualAccount->AccountAccessSO)) { #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read wait failed\n"); #endif @@ -258,16 +245,23 @@ void __cdecl BadConnection(void *Param) #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read enter\n"); #endif - for (src = ActualAccount->Name, dest = nid.szTip, i = 0; (*src != (TCHAR)0) && (i + 1 < sizeof(nid.szTip)); *dest++ = *src++); - for (src = NotIconText; (*src != (TCHAR)0) && (i + 1 < sizeof(nid.szTip)); *dest++ = *src++); - *dest = (TCHAR)0; - if (ActualAccount->BadConnectN.Flags & YAMN_ACC_SND) CallService(MS_SKIN_PLAYSOUND, 0, (LPARAM)YAMN_CONNECTFAILSOUND); + if (ActualAccount->BadConnectN.Flags & YAMN_ACC_MSG) ShowWindow(hBadConnect, SW_SHOWNORMAL); - if (ActualAccount->BadConnectN.Flags & YAMN_ACC_ICO) + + if (ActualAccount->BadConnectN.Flags & YAMN_ACC_ICO) { + NOTIFYICONDATA nid = {}; + nid.cbSize = sizeof(nid); + nid.hWnd = hBadConnect; + nid.hIcon = g_LoadIconEx(3); + nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; + nid.uCallbackMessage = WM_YAMN_NOTIFYICON; + mir_sntprintf(nid.szTip, _T("%S%s"), ActualAccount->Name, TranslateT(" - connection error")); Shell_NotifyIcon(NIM_ADD, &nid); + } + #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read done\n"); #endif diff --git a/plugins/YAMN/src/browser/mailbrowser.cpp b/plugins/YAMN/src/browser/mailbrowser.cpp index ada976daa0..498f96a54a 100644 --- a/plugins/YAMN/src/browser/mailbrowser.cpp +++ b/plugins/YAMN/src/browser/mailbrowser.cpp @@ -622,36 +622,35 @@ int AddNewMailsToListView(HWND hListView, HACCOUNT ActualAccount, DWORD nflags) void DoMailActions(HWND hDlg, HACCOUNT ActualAccount, struct CMailNumbers *MN, DWORD nflags, DWORD nnflags) { - char *NotIconText = Translate("- new mail message(s)"); - NOTIFYICONDATA nid; - - memset(&nid, 0, sizeof(nid)); + NOTIFYICONDATA nid = {}; + nid.cbSize = sizeof(nid); + nid.hWnd = hDlg; if (MN->Real.EventNC + MN->Virtual.EventNC) NotifyEventHooks(hNewMailHook, 0, 0); - if ((nflags & YAMN_ACC_KBN) && (MN->Real.PopupRun + MN->Virtual.PopupRun)) { + if ((nflags & YAMN_ACC_KBN) && (MN->Real.PopupRun + MN->Virtual.PopupRun)) CallService(MS_KBDNOTIFY_STARTBLINK, (WPARAM)MN->Real.PopupNC + MN->Virtual.PopupNC, NULL); - } if ((nflags & YAMN_ACC_CONT) && (MN->Real.PopupRun + MN->Virtual.PopupRun)) { - char sMsg[250]; - mir_snprintf(sMsg, Translate("%s : %d new mail message(s), %d total"), ActualAccount->Name, MN->Real.PopupNC + MN->Virtual.PopupNC, MN->Real.PopupTC + MN->Virtual.PopupTC); + TCHAR tszMsg[250]; + mir_sntprintf(tszMsg, TranslateT("%s : %d new mail message(s), %d total"), _A2T(ActualAccount->Name), MN->Real.PopupNC + MN->Virtual.PopupNC, MN->Real.PopupTC + MN->Virtual.PopupTC); + if (!(nflags & YAMN_ACC_CONTNOEVENT)) { CLISTEVENT evt = {}; + evt.flags = CLEF_TCHAR; evt.hContact = ActualAccount->hContact; evt.hIcon = g_LoadIconEx(2); evt.hDbEvent = ActualAccount->hContact; evt.lParam = ActualAccount->hContact; evt.pszService = MS_YAMN_CLISTDBLCLICK; - evt.pszTooltip = sMsg; + evt.ptszTooltip = tszMsg; pcli->pfnAddEvent(&evt); } - db_set_s(ActualAccount->hContact, "CList", "StatusMsg", sMsg); + db_set_ts(ActualAccount->hContact, "CList", "StatusMsg", tszMsg); - if (nflags & YAMN_ACC_CONTNICK) { - db_set_s(ActualAccount->hContact, YAMN_DBMODULE, "Nick", sMsg); - } + if (nflags & YAMN_ACC_CONTNICK) + db_set_ts(ActualAccount->hContact, YAMN_DBMODULE, "Nick", tszMsg); } if ((nflags & YAMN_ACC_POP) && @@ -679,14 +678,11 @@ void DoMailActions(HWND hDlg, HACCOUNT ActualAccount, struct CMailNumbers *MN, D PUAddPopupT(&NewMailPopup); } - //destroy tray icon if no new mail - if ((MN->Real.SysTrayUC + MN->Virtual.SysTrayUC == 0) && (hDlg != NULL)) { - nid.hWnd = hDlg; - nid.uID = 0; + // destroy tray icon if no new mail + if ((MN->Real.SysTrayUC + MN->Virtual.SysTrayUC == 0) && (hDlg != NULL)) Shell_NotifyIcon(NIM_DELETE, &nid); - } - //and remove the event + // and remove the event if ((nflags & YAMN_ACC_CONT) && (!(nflags & YAMN_ACC_CONTNOEVENT)) && (MN->Real.UnSeen + MN->Virtual.UnSeen == 0)) pcli->pfnRemoveEvent(ActualAccount->hContact, ActualAccount->hContact); @@ -705,19 +701,10 @@ void DoMailActions(HWND hDlg, HACCOUNT ActualAccount, struct CMailNumbers *MN, D SendDlgItemMessageW(hDlg, IDC_LISTMAILS, LVM_SCROLL, 0, (LPARAM)0x7ffffff); if ((nflags & YAMN_ACC_ICO) && (MN->Real.SysTrayUC + MN->Virtual.SysTrayUC)) { - char* src; - TCHAR *dest; - int i; - - for (src = ActualAccount->Name, dest = nid.szTip, i = 0; (*src != (TCHAR)0) && (i + 1 < sizeof(nid.szTip)); *dest++ = *src++); - for (src = NotIconText; (*src != (TCHAR)0) && (i + 1 < sizeof(nid.szTip)); *dest++ = *src++); - *dest = (TCHAR)0; - nid.cbSize = sizeof(NOTIFYICONDATA); - nid.hWnd = hDlg; nid.hIcon = g_LoadIconEx(2); - nid.uID = 0; nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; nid.uCallbackMessage = WM_YAMN_NOTIFYICON; + mir_sntprintf(nid.szTip, _T("%S %s"), ActualAccount->Name, TranslateT("- new mail message(s)")); Shell_NotifyIcon(NIM_ADD, &nid); SetTimer(hDlg, TIMER_FLASHING, 500, NULL); } diff --git a/plugins/YAMN/src/filterplugin.cpp b/plugins/YAMN/src/filterplugin.cpp index 0f5ac0e20a..884330ed4d 100644 --- a/plugins/YAMN/src/filterplugin.cpp +++ b/plugins/YAMN/src/filterplugin.cpp @@ -107,19 +107,18 @@ INT_PTR UnregisterFilterPluginSvc(WPARAM wParam,LPARAM) { HYAMNFILTERPLUGIN Plugin=(HYAMNFILTERPLUGIN)wParam; - EnterCriticalSection(&PluginRegCS); + mir_cslock lck(PluginRegCS); UnregisterFilterPlugin(Plugin); - LeaveCriticalSection(&PluginRegCS); return 1; } INT_PTR UnregisterFilterPlugins() { - EnterCriticalSection(&PluginRegCS); -//We remove protocols from the protocol list + mir_cslock lck(PluginRegCS); + + // We remove protocols from the protocol list while(FirstFilterPlugin != NULL) UnregisterFilterPlugin(FirstFilterPlugin->Plugin); - LeaveCriticalSection(&PluginRegCS); return 1; } @@ -138,9 +137,9 @@ int WINAPI SetFilterPluginFcnImportFcn(HYAMNFILTERPLUGIN Plugin,DWORD Importance Plugin->Importance=Importance; Plugin->FilterFcn=YAMNFilterFcn; - EnterCriticalSection(&PluginRegCS); -//We add protocol to the protocol list - for (Previous=NULL,Parser=FirstFilterPlugin;Parser != NULL && Parser->Next != NULL && Parser->Plugin->Importance<=Importance;Previous=Parser,Parser=Parser->Next); + mir_cslock lck(PluginRegCS); + // We add protocol to the protocol list + for (Previous = NULL, Parser = FirstFilterPlugin; Parser != NULL && Parser->Next != NULL && Parser->Plugin->Importance <= Importance; Previous = Parser, Parser = Parser->Next); if (Previous==NULL) //insert to the beginnig of queue { FirstFilterPlugin=new YAMN_FILTERPLUGINQUEUE; @@ -154,8 +153,6 @@ int WINAPI SetFilterPluginFcnImportFcn(HYAMNFILTERPLUGIN Plugin,DWORD Importance Previous->Plugin=Plugin; Previous->Next=Parser; //and in actual plugin set, that next plugin is the one we insert in front of } - - LeaveCriticalSection(&PluginRegCS); return 1; } @@ -165,7 +162,7 @@ INT_PTR FilterMailSvc(WPARAM wParam,LPARAM lParam) HYAMNMAIL Mail=(HYAMNMAIL)lParam; PYAMN_FILTERPLUGINQUEUE ActualPlugin; - EnterCriticalSection(&PluginRegCS); + mir_cslock lck(PluginRegCS); #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"FilterMail:ActualAccountMsgsSO-write wait\n"); #endif @@ -199,6 +196,5 @@ INT_PTR FilterMailSvc(WPARAM wParam,LPARAM lParam) DebugLog(SynchroFile,"FilterMail:ActualAccountMsgsSO-write done\n"); #endif WriteDoneFcn(Account->MessagesAccessSO); - LeaveCriticalSection(&PluginRegCS); return 1; } diff --git a/plugins/YAMN/src/main.cpp b/plugins/YAMN/src/main.cpp index 16cbee69d9..b5cbb99264 100644 --- a/plugins/YAMN/src/main.cpp +++ b/plugins/YAMN/src/main.cpp @@ -290,10 +290,6 @@ extern "C" int __declspec(dllexport) Load(void) pd.type = PROTOTYPE_VIRTUAL; Proto_RegisterModule(&pd); - InitializeCriticalSection(&AccountStatusCS); - InitializeCriticalSection(&FileWritingCS); - InitializeCriticalSection(&PluginRegCS); - if (NULL == (NoWriterEV = CreateEvent(NULL, TRUE, TRUE, NULL))) return 1; if (NULL == (WriteToFileEV = CreateEvent(NULL, FALSE, FALSE, NULL))) @@ -384,13 +380,6 @@ extern "C" int __declspec(dllexport) Unload(void) CloseHandle(WriteToFileEV); CloseHandle(ExitEV); - DeleteCriticalSection(&AccountStatusCS); - DeleteCriticalSection(&FileWritingCS); - DeleteCriticalSection(&PluginRegCS); - - UnhookEvents(); - DestroyServiceFunctions(); - UnloadPlugins(); delete [] CodePageNamesSupp; diff --git a/plugins/YAMN/src/proto/pop3/pop3opt.cpp b/plugins/YAMN/src/proto/pop3/pop3opt.cpp index 14c24847ea..65730f6391 100644 --- a/plugins/YAMN/src/proto/pop3/pop3opt.cpp +++ b/plugins/YAMN/src/proto/pop3/pop3opt.cpp @@ -90,7 +90,8 @@ INT_PTR CALLBACK DlgProcPluginOpt(HWND hDlg, UINT msg, WPARAM wParam, LPARAM) if (CB_ERR == (index = SendMessage(hCombo, CB_GETCURSEL, 0, 0))) break; id = SendMessage(hCombo, CB_GETITEMDATA, (WPARAM)index, 0); - EnterCriticalSection(&PluginRegCS); + + mir_cslock lck(PluginRegCS); for (PParser = FirstProtoPlugin; PParser != NULL; PParser = PParser->Next) if (id == (INT_PTR)PParser->Plugin) { SetDlgItemTextA(hDlg, IDC_STVER, PParser->Plugin->PluginInfo->Ver); @@ -109,7 +110,6 @@ INT_PTR CALLBACK DlgProcPluginOpt(HWND hDlg, UINT msg, WPARAM wParam, LPARAM) SetDlgItemTextA(hDlg, IDC_STWWW, FParser->Plugin->PluginInfo->WWW == NULL ? "" : FParser->Plugin->PluginInfo->WWW); break; } - LeaveCriticalSection(&PluginRegCS); } break; case IDC_STWWW: @@ -125,21 +125,18 @@ INT_PTR CALLBACK DlgProcPluginOpt(HWND hDlg, UINT msg, WPARAM wParam, LPARAM) } case WM_SHOWWINDOW: if (TRUE == (BOOL)wParam) { - PYAMN_PROTOPLUGINQUEUE PParser; - PYAMN_FILTERPLUGINQUEUE FParser; - int index; - - EnterCriticalSection(&PluginRegCS); - for (PParser = FirstProtoPlugin; PParser != NULL; PParser = PParser->Next) { - index = SendDlgItemMessageA(hDlg, IDC_COMBOPLUGINS, CB_ADDSTRING, 0, (LPARAM)PParser->Plugin->PluginInfo->Name); - index = SendDlgItemMessage(hDlg, IDC_COMBOPLUGINS, CB_SETITEMDATA, (WPARAM)index, (LPARAM)PParser->Plugin); - } - for (FParser = FirstFilterPlugin; FParser != NULL; FParser = FParser->Next) { - index = SendDlgItemMessageA(hDlg, IDC_COMBOPLUGINS, CB_ADDSTRING, 0, (LPARAM)FParser->Plugin->PluginInfo->Name); - index = SendDlgItemMessage(hDlg, IDC_COMBOPLUGINS, CB_SETITEMDATA, (WPARAM)index, (LPARAM)FParser->Plugin); + { + mir_cslock lck(PluginRegCS); + for (PYAMN_PROTOPLUGINQUEUE PParser = FirstProtoPlugin; PParser != NULL; PParser = PParser->Next) { + int index = SendDlgItemMessageA(hDlg, IDC_COMBOPLUGINS, CB_ADDSTRING, 0, (LPARAM)PParser->Plugin->PluginInfo->Name); + SendDlgItemMessage(hDlg, IDC_COMBOPLUGINS, CB_SETITEMDATA, (WPARAM)index, (LPARAM)PParser->Plugin); + } + for (PYAMN_FILTERPLUGINQUEUE FParser = FirstFilterPlugin; FParser != NULL; FParser = FParser->Next) { + int index = SendDlgItemMessageA(hDlg, IDC_COMBOPLUGINS, CB_ADDSTRING, 0, (LPARAM)FParser->Plugin->PluginInfo->Name); + SendDlgItemMessage(hDlg, IDC_COMBOPLUGINS, CB_SETITEMDATA, (WPARAM)index, (LPARAM)FParser->Plugin); + } } - LeaveCriticalSection(&PluginRegCS); SendDlgItemMessage(hDlg, IDC_COMBOPLUGINS, CB_SETCURSEL, 0, 0); SendMessage(hDlg, WM_COMMAND, MAKELONG(IDC_COMBOPLUGINS, CBN_SELCHANGE), 0); break; diff --git a/plugins/YAMN/src/protoplugin.cpp b/plugins/YAMN/src/protoplugin.cpp index dcede55d82..485286c4ea 100644 --- a/plugins/YAMN/src/protoplugin.cpp +++ b/plugins/YAMN/src/protoplugin.cpp @@ -93,8 +93,8 @@ int WINAPI SetProtocolPluginFcnImportFcn(HYAMNPROTOPLUGIN Plugin,PYAMN_PROTOIMPO Plugin->Fcn=YAMNFcn; Plugin->MailFcn=YAMNMailFcn; - EnterCriticalSection(&PluginRegCS); -//We add protocol to the protocol list + mir_cslock lck(PluginRegCS); + // We add protocol to the protocol list for (Parser=FirstProtoPlugin;Parser != NULL && Parser->Next != NULL;Parser=Parser->Next); if (Parser==NULL) { @@ -109,8 +109,6 @@ int WINAPI SetProtocolPluginFcnImportFcn(HYAMNPROTOPLUGIN Plugin,PYAMN_PROTOIMPO Parser->Plugin=Plugin; Parser->Next=NULL; - - LeaveCriticalSection(&PluginRegCS); return 1; } @@ -161,20 +159,17 @@ INT_PTR UnregisterProtocolPluginSvc(WPARAM wParam,LPARAM) { HYAMNPROTOPLUGIN Plugin=(HYAMNPROTOPLUGIN)wParam; - EnterCriticalSection(&PluginRegCS); + mir_cslock lck(PluginRegCS); UnregisterProtocolPlugin(Plugin); - LeaveCriticalSection(&PluginRegCS); return 1; - } INT_PTR UnregisterProtoPlugins() { - EnterCriticalSection(&PluginRegCS); -//We remove protocols from the protocol list + mir_cslock lck(PluginRegCS); + // We remove protocols from the protocol list while(FirstProtoPlugin != NULL) UnregisterProtocolPlugin(FirstProtoPlugin->Plugin); - LeaveCriticalSection(&PluginRegCS); return 1; } diff --git a/plugins/YAMN/src/services.cpp b/plugins/YAMN/src/services.cpp index 7dc812ba0c..6bb3c1c21f 100644 --- a/plugins/YAMN/src/services.cpp +++ b/plugins/YAMN/src/services.cpp @@ -134,7 +134,7 @@ static INT_PTR AccountMailCheck(WPARAM wParam, LPARAM lParam) if (WAIT_OBJECT_0 == WaitForSingleObject(ExitEV, 0)) return 0; - EnterCriticalSection(&PluginRegCS); + mir_cslock lck(PluginRegCS); #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile, "AccountCheck:ActualAccountSO-read wait\n"); #endif @@ -160,7 +160,6 @@ static INT_PTR AccountMailCheck(WPARAM wParam, LPARAM lParam) } ReadDoneFcn(ActualAccount->AccountAccessSO); } - LeaveCriticalSection(&PluginRegCS); CloseHandle(ThreadRunningEV); } return 0; @@ -185,7 +184,7 @@ static INT_PTR ContactMailCheck(WPARAM hContact, LPARAM) //if we want to close miranda, we get event and do not run pop3 checking anymore if (WAIT_OBJECT_0 == WaitForSingleObject(ExitEV, 0)) return 0; - EnterCriticalSection(&PluginRegCS); + mir_cslock lck(PluginRegCS); #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read wait\n"); #endif @@ -214,7 +213,6 @@ static INT_PTR ContactMailCheck(WPARAM hContact, LPARAM) } ReadDoneFcn(ActualAccount->AccountAccessSO); } - LeaveCriticalSection(&PluginRegCS); CloseHandle(ThreadRunningEV); } db_free(&dbv); @@ -338,131 +336,100 @@ int Shutdown(WPARAM, LPARAM) } int SystemModulesLoaded(WPARAM, LPARAM); //in main.cpp -typedef struct { HANDLE hookHandle; const char *hookName; MIRANDAHOOK mirandaFunction;} HookDataType; -static HookDataType hookData[] = { - {0, ME_SYSTEM_MODULESLOADED, SystemModulesLoaded}, //pop3 plugin must be included after all miranda modules are loaded - {0, ME_TTB_MODULELOADED, AddTopToolbarIcon}, - {0, ME_OPT_INITIALISE, YAMNOptInitSvc}, - {0, ME_SYSTEM_PRESHUTDOWN, Shutdown}, - {0, ME_CLIST_DOUBLECLICKED, Service_ContactDoubleclicked}, - {0, 0, 0}//end marker -}; void HookEvents(void) { - //We set function which registers needed POP3 accounts. This is a part of internal POP3 plugin. - //Your plugin should do the same task in your Load fcn. Why we call it in MODULESLOADED? Because netlib - //user can be registered after all modules are loaded (see m_netlib.h in Miranda) - for (int i = 0;hookData[i].hookName;i++) { - hookData[i].hookHandle = HookEvent(hookData[i].hookName, hookData[i].mirandaFunction); - } + HookEvent(ME_SYSTEM_MODULESLOADED, SystemModulesLoaded); + HookEvent(ME_TTB_MODULELOADED, AddTopToolbarIcon); + HookEvent(ME_OPT_INITIALISE, YAMNOptInitSvc); + HookEvent(ME_SYSTEM_PRESHUTDOWN, Shutdown); + HookEvent(ME_CLIST_DOUBLECLICKED, Service_ContactDoubleclicked); } -void UnhookEvents(void) + +void CreateServiceFunctions(void) { - for (int i = 0;i<(sizeof(hookData)/sizeof(hookData[0]));i++) - if (hookData[i].hookHandle) - UnhookEvent(hookData[i].hookHandle); -} + // Standard 'protocol' services + CreateServiceFunction(YAMN_DBMODULE PS_GETCAPS, Service_GetCaps); + CreateServiceFunction(YAMN_DBMODULE PS_GETSTATUS, Service_GetStatus); + CreateServiceFunction(YAMN_DBMODULE PS_SETSTATUS, Service_SetStatus); + CreateServiceFunction(YAMN_DBMODULE PS_GETNAME, Service_GetName); + CreateServiceFunction(YAMN_DBMODULE PS_LOADICON, Service_LoadIcon); -typedef struct { HANDLE serviceHandle; const char *serviceName; MIRANDASERVICE serviceFunction;} ServiceDataType; -static ServiceDataType serviceData[] = { - {0, YAMN_DBMODULE PS_GETCAPS, Service_GetCaps}, - {0, YAMN_DBMODULE PS_GETSTATUS, Service_GetStatus}, - {0, YAMN_DBMODULE PS_SETSTATUS, Service_SetStatus}, - {0, YAMN_DBMODULE PS_GETNAME, Service_GetName}, - {0, YAMN_DBMODULE PS_LOADICON, Service_LoadIcon}, + // Function with which protocol plugin can register + CreateServiceFunction(MS_YAMN_GETFCNPTR, GetFcnPtrSvc); - //Function with which protocol plugin can register - {0, MS_YAMN_GETFCNPTR, GetFcnPtrSvc}, - - //Function returns pointer to YAMN variables - {0, MS_YAMN_GETVARIABLES, GetVariablesSvc}, - - //Function with which protocol plugin can register - {0, MS_YAMN_REGISTERPROTOPLUGIN, RegisterProtocolPluginSvc}, - - //Function with which protocol plugin can unregister - {0, MS_YAMN_UNREGISTERPROTOPLUGIN, UnregisterProtocolPluginSvc}, - - //Function creates an account for plugin - {0, MS_YAMN_CREATEPLUGINACCOUNT, CreatePluginAccountSvc}, - - //Function deletes plugin account - {0, MS_YAMN_DELETEPLUGINACCOUNT, DeletePluginAccountSvc}, - - //Finds account for plugin by name - {0, MS_YAMN_FINDACCOUNTBYNAME, FindAccountByNameSvc}, - - //Creates next account for plugin - {0, MS_YAMN_GETNEXTFREEACCOUNT, GetNextFreeAccountSvc}, - - //Function removes account from YAMN queue. Does not delete it from memory - {0, MS_YAMN_DELETEACCOUNT, DeleteAccountSvc}, - - //Function finds accounts for specified plugin - {0, MS_YAMN_READACCOUNTS, AddAccountsFromFileSvc}, - - //Function that stores all plugin mails to one file - {0, MS_YAMN_WRITEACCOUNTS, WriteAccountsToFileSvc}, - - //Function that returns user's filename - {0, MS_YAMN_GETFILENAME, GetFileNameSvc}, - - //Releases unicode string from memory - {0, MS_YAMN_DELETEFILENAME, DeleteFileNameSvc}, - - //Checks mail - {0, MS_YAMN_FORCECHECK, ForceCheckSvc}, - - //Runs YAMN's mail browser - {0, MS_YAMN_MAILBROWSER, RunMailBrowserSvc}, - - //Runs YAMN's bad conenction window - {0, MS_YAMN_BADCONNECTION, RunBadConnectionSvc}, - - //Function creates new mail for plugin - {0, MS_YAMN_CREATEACCOUNTMAIL, CreateAccountMailSvc}, - - //Function deletes plugin account - {0, MS_YAMN_DELETEACCOUNTMAIL, DeleteAccountMailSvc}, - - //Function with which filter plugin can register - {0, MS_YAMN_REGISTERFILTERPLUGIN, RegisterFilterPluginSvc}, - - //Function with which filter plugin can unregister - {0, MS_YAMN_UNREGISTERFILTERPLUGIN, UnregisterFilterPluginSvc}, - - //Function filters mail - {0, MS_YAMN_FILTERMAIL, FilterMailSvc}, + // Function returns pointer to YAMN variables + CreateServiceFunction(MS_YAMN_GETVARIABLES, GetVariablesSvc); - //Function contact list double click - {0, MS_YAMN_CLISTDBLCLICK, ClistContactDoubleclicked}, + // Function with which protocol plugin can register + CreateServiceFunction(MS_YAMN_REGISTERPROTOPLUGIN, RegisterProtocolPluginSvc); - //Function to check individual account - {0, MS_YAMN_ACCOUNTCHECK, AccountMailCheck}, + // Function with which protocol plugin can unregister + CreateServiceFunction(MS_YAMN_UNREGISTERPROTOPLUGIN, UnregisterProtocolPluginSvc); - //Function contact list context menu click - {0, MS_YAMN_CLISTCONTEXT, ContactMailCheck}, + // Function creates an account for plugin + CreateServiceFunction(MS_YAMN_CREATEPLUGINACCOUNT, CreatePluginAccountSvc); - //Function contact list context menu click - {0, MS_YAMN_CLISTCONTEXTAPP, ContactApplication}, + // Function deletes plugin account + CreateServiceFunction(MS_YAMN_DELETEPLUGINACCOUNT, DeletePluginAccountSvc); - {0, 0, 0}//end marker -}; + // Finds account for plugin by name + CreateServiceFunction(MS_YAMN_FINDACCOUNTBYNAME, FindAccountByNameSvc); -void CreateServiceFunctions(void) -{ - for (int i = 0;serviceData[i].serviceName;i++) { - serviceData[i].serviceHandle = CreateServiceFunction(serviceData[i].serviceName, serviceData[i].serviceFunction); - } -}; + // Creates next account for plugin + CreateServiceFunction(MS_YAMN_GETNEXTFREEACCOUNT, GetNextFreeAccountSvc); -void DestroyServiceFunctions(void) -{ - for (int i = 0;serviceData[i].serviceName;i++) { - if (serviceData[i].serviceHandle) DestroyServiceFunction(serviceData[i].serviceHandle); - } -}; + // Function removes account from YAMN queue. Does not delete it from memory + CreateServiceFunction(MS_YAMN_DELETEACCOUNT, DeleteAccountSvc); + + // Function finds accounts for specified plugin + CreateServiceFunction(MS_YAMN_READACCOUNTS, AddAccountsFromFileSvc); + + // Function that stores all plugin mails to one file + CreateServiceFunction(MS_YAMN_WRITEACCOUNTS, WriteAccountsToFileSvc); + + // Function that returns user's filename + CreateServiceFunction(MS_YAMN_GETFILENAME, GetFileNameSvc); + + // Releases unicode string from memory + CreateServiceFunction(MS_YAMN_DELETEFILENAME, DeleteFileNameSvc); + + // Checks mail + CreateServiceFunction(MS_YAMN_FORCECHECK, ForceCheckSvc); + + // Runs YAMN's mail browser + CreateServiceFunction(MS_YAMN_MAILBROWSER, RunMailBrowserSvc); + + // Runs YAMN's bad conenction window + CreateServiceFunction(MS_YAMN_BADCONNECTION, RunBadConnectionSvc); + + // Function creates new mail for plugin + CreateServiceFunction(MS_YAMN_CREATEACCOUNTMAIL, CreateAccountMailSvc); + + // Function deletes plugin account + CreateServiceFunction(MS_YAMN_DELETEACCOUNTMAIL, DeleteAccountMailSvc); + + // Function with which filter plugin can register + CreateServiceFunction(MS_YAMN_REGISTERFILTERPLUGIN, RegisterFilterPluginSvc); + + // Function with which filter plugin can unregister + CreateServiceFunction(MS_YAMN_UNREGISTERFILTERPLUGIN, UnregisterFilterPluginSvc); + + // Function filters mail + CreateServiceFunction(MS_YAMN_FILTERMAIL, FilterMailSvc); + + // Function contact list double click + CreateServiceFunction(MS_YAMN_CLISTDBLCLICK, ClistContactDoubleclicked); + + // Function to check individual account + CreateServiceFunction(MS_YAMN_ACCOUNTCHECK, AccountMailCheck); + + // Function contact list context menu click + CreateServiceFunction(MS_YAMN_CLISTCONTEXT, ContactMailCheck); + + // Function contact list context menu click + CreateServiceFunction(MS_YAMN_CLISTCONTEXTAPP, ContactApplication); +} //Function to put all enabled contact to the Online status void RefreshContact(void) diff --git a/plugins/YAMN/src/stdafx.h b/plugins/YAMN/src/stdafx.h index f454aa8829..f187b472c2 100644 --- a/plugins/YAMN/src/stdafx.h +++ b/plugins/YAMN/src/stdafx.h @@ -45,28 +45,23 @@ //From services.cpp void CreateServiceFunctions(void); -void DestroyServiceFunctions(void); void HookEvents(void); -void UnhookEvents(void); void RefreshContact(void); void ContactDoubleclicked(WPARAM wParam, LPARAM lParam); INT_PTR ClistContactDoubleclicked(WPARAM wParam, LPARAM lParam); -extern CRITICAL_SECTION PluginRegCS; +extern mir_cs PluginRegCS; extern SCOUNTER *AccountWriterSO; extern HANDLE ExitEV; extern HANDLE WriteToFileEV; -//From debug.cpp +// From debug.cpp #ifdef _DEBUG void InitDebug(); void UnInitDebug(); #endif -//From synchro.cpp -//struct CExportedFunctions SynchroExported[]; - -//From yamn.cpp +// From yamn.cpp INT_PTR GetFcnPtrSvc(WPARAM wParam, LPARAM lParam); INT_PTR GetVariablesSvc(WPARAM, LPARAM); void CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD); @@ -74,10 +69,7 @@ INT_PTR ForceCheckSvc(WPARAM, LPARAM); extern struct YAMNExportedFcns *pYAMNFcn; -//From account.cpp -extern CRITICAL_SECTION AccountStatusCS; -extern CRITICAL_SECTION FileWritingCS; - +// From account.cpp INT_PTR CreatePluginAccountSvc(WPARAM wParam, LPARAM lParam); INT_PTR DeletePluginAccountSvc(WPARAM wParam, LPARAM); int InitAccount(HACCOUNT Which); diff --git a/plugins/YAMN/src/yamn.cpp b/plugins/YAMN/src/yamn.cpp index 006c15643c..ee15e5c343 100644 --- a/plugins/YAMN/src/yamn.cpp +++ b/plugins/YAMN/src/yamn.cpp @@ -11,7 +11,7 @@ //Plugin registration CS //Used if we add (register) plugin to YAMN plugins and when we browse through registered plugins -CRITICAL_SECTION PluginRegCS; +mir_cs PluginRegCS; //AccountWriterCS //We want to store number of writers of Accounts (number of Accounts used for writing) @@ -109,9 +109,8 @@ void CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD) // Get actual status of current user in Miranda Status=CallService(MS_CLIST_GETSTATUSMODE, 0, 0); - EnterCriticalSection(&PluginRegCS); - for (PYAMN_PROTOPLUGINQUEUE ActualPlugin=FirstProtoPlugin;ActualPlugin != NULL;ActualPlugin=ActualPlugin->Next) - { + mir_cslock lck(PluginRegCS); + for (PYAMN_PROTOPLUGINQUEUE ActualPlugin = FirstProtoPlugin; ActualPlugin != NULL; ActualPlugin = ActualPlugin->Next) { #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile, "TimerProc:AccountBrowserSO-read wait\n"); #endif @@ -120,7 +119,6 @@ void CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD) #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile, "TimerProc:AccountBrowserSO-read enter failed\n"); #endif - LeaveCriticalSection(&PluginRegCS); return; } #ifdef DEBUG_SYNCHRO @@ -249,7 +247,6 @@ ChangeIsCountingStatusLabel: #endif SWMRGDoneReading(ActualPlugin->Plugin->AccountBrowserSO); } - LeaveCriticalSection(&PluginRegCS); CloseHandle(ThreadRunningEV); } @@ -263,62 +260,61 @@ INT_PTR ForceCheckSvc(WPARAM, LPARAM) if (ThreadRunningEV == NULL) return 0; //if we want to close miranda, we get event and do not run pop3 checking anymore - if (WAIT_OBJECT_0==WaitForSingleObject(ExitEV, 0)) + if (WAIT_OBJECT_0 == WaitForSingleObject(ExitEV, 0)) return 0; - EnterCriticalSection(&PluginRegCS); - for (PYAMN_PROTOPLUGINQUEUE ActualPlugin = FirstProtoPlugin; ActualPlugin != NULL; ActualPlugin=ActualPlugin->Next) + { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:AccountBrowserSO-read wait\n"); - #endif - SWMRGWaitToRead(ActualPlugin->Plugin->AccountBrowserSO, INFINITE); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:AccountBrowserSO-read enter\n"); - #endif - for (ActualAccount=ActualPlugin->Plugin->FirstAccount;ActualAccount != NULL;ActualAccount=ActualAccount->Next) - { - if (ActualAccount->Plugin->Fcn==NULL) //account not inited - continue; - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read wait\n"); - #endif - if (WAIT_OBJECT_0 != WaitToReadFcn(ActualAccount->AccountAccessSO)) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read wait failed\n"); - #endif - continue; - } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read enter\n"); - #endif - if ((ActualAccount->Flags & YAMN_ACC_ENA) && (ActualAccount->StatusFlags & YAMN_ACC_FORCE)) //account cannot be forced to check - { - if (ActualAccount->Plugin->Fcn->ForceCheckFcnPtr==NULL) - { - ReadDoneFcn(ActualAccount->AccountAccessSO); + mir_cslock lck(PluginRegCS); + for (PYAMN_PROTOPLUGINQUEUE ActualPlugin = FirstProtoPlugin; ActualPlugin != NULL; ActualPlugin = ActualPlugin->Next) { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "ForceCheck:AccountBrowserSO-read wait\n"); +#endif + SWMRGWaitToRead(ActualPlugin->Plugin->AccountBrowserSO, INFINITE); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "ForceCheck:AccountBrowserSO-read enter\n"); +#endif + for (ActualAccount = ActualPlugin->Plugin->FirstAccount; ActualAccount != NULL; ActualAccount = ActualAccount->Next) { + if (ActualAccount->Plugin->Fcn == NULL) //account not inited + continue; +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read wait\n"); +#endif + if (WAIT_OBJECT_0 != WaitToReadFcn(ActualAccount->AccountAccessSO)) { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read wait failed\n"); +#endif continue; } - struct CheckParam ParamToPlugin={YAMN_CHECKVERSION, ThreadRunningEV, ActualAccount, YAMN_FORCECHECK, (void *)0, NULL}; - - if (NULL==CreateThread(NULL, 0, (YAMN_STANDARDFCN)ActualAccount->Plugin->Fcn->ForceCheckFcnPtr, &ParamToPlugin, 0, &tid)) +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read enter\n"); +#endif + if ((ActualAccount->Flags & YAMN_ACC_ENA) && (ActualAccount->StatusFlags & YAMN_ACC_FORCE)) //account cannot be forced to check { - ReadDoneFcn(ActualAccount->AccountAccessSO); - continue; + if (ActualAccount->Plugin->Fcn->ForceCheckFcnPtr == NULL) { + ReadDoneFcn(ActualAccount->AccountAccessSO); + continue; + } + struct CheckParam ParamToPlugin = { YAMN_CHECKVERSION, ThreadRunningEV, ActualAccount, YAMN_FORCECHECK, (void *)0, NULL }; + + if (NULL == CreateThread(NULL, 0, (YAMN_STANDARDFCN)ActualAccount->Plugin->Fcn->ForceCheckFcnPtr, &ParamToPlugin, 0, &tid)) { + ReadDoneFcn(ActualAccount->AccountAccessSO); + continue; + } + else + WaitForSingleObject(ThreadRunningEV, INFINITE); } - else - WaitForSingleObject(ThreadRunningEV, INFINITE); + ReadDoneFcn(ActualAccount->AccountAccessSO); } - ReadDoneFcn(ActualAccount->AccountAccessSO); - } #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:AccountBrowserSO-read done\n"); + DebugLog(SynchroFile, "ForceCheck:AccountBrowserSO-read done\n"); #endif - SWMRGDoneReading(ActualPlugin->Plugin->AccountBrowserSO); + SWMRGDoneReading(ActualPlugin->Plugin->AccountBrowserSO); + } } - LeaveCriticalSection(&PluginRegCS); + CloseHandle(ThreadRunningEV); - if (hTTButton) CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hTTButton, 0); + if (hTTButton) + CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hTTButton, 0); return 1; } -- cgit v1.2.3