void WINAPI ReadDoneFcn(PSWMRG SObject) { #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"\tSO ReadDone: %x\n",SObject); #endif SWMRGDoneReading(SObject); }
INT_PTR FindAccountByNameSvc(WPARAM wParam,LPARAM lParam) { HYAMNPROTOPLUGIN Plugin=(HYAMNPROTOPLUGIN)wParam; char *SearchedAccount=(char *)lParam; HACCOUNT 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 != NULL;Finder=Finder->Next) if ((Finder->Name != NULL) && (0 == strcmp(SearchedAccount,Finder->Name))) break; #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"FindAccountByName:AccountBrowserSO-read done\n"); #endif SWMRGDoneReading(Plugin->AccountBrowserSO); return (INT_PTR)Finder; }
void CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD) { PYAMN_PROTOPLUGINQUEUE ActualPlugin; HACCOUNT ActualAccount; HANDLE ThreadRunningEV; DWORD Status, tid; // we use event to signal, that running thread has all needed stack parameters copied if (NULL==(ThreadRunningEV=CreateEvent(NULL, FALSE, FALSE, NULL))) return; // if we want to close miranda, we get event and do not run checking anymore if (WAIT_OBJECT_0==WaitForSingleObject(ExitEV, 0)) return; // Get actual status of current user in Miranda Status=CallService(MS_CLIST_GETSTATUSMODE, 0, 0); EnterCriticalSection(&PluginRegCS); for (ActualPlugin=FirstProtoPlugin;ActualPlugin != NULL;ActualPlugin=ActualPlugin->Next) { #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile, "TimerProc:AccountBrowserSO-read wait\n"); #endif if (WAIT_OBJECT_0 != SWMRGWaitToRead(ActualPlugin->Plugin->AccountBrowserSO, 0)) //we want to access accounts immiadtelly { #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile, "TimerProc:AccountBrowserSO-read enter failed\n"); #endif LeaveCriticalSection(&PluginRegCS); return; } #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile, "TimerProc:AccountBrowserSO-read enter\n"); #endif for (ActualAccount=ActualPlugin->Plugin->FirstAccount;ActualAccount != NULL;ActualAccount=ActualAccount->Next) { if (ActualAccount->Plugin==NULL || ActualAccount->Plugin->Fcn==NULL) //account not inited continue; #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read wait\n"); #endif if (WAIT_OBJECT_0 != SWMRGWaitToRead(ActualAccount->AccountAccessSO, 0)) { #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read wait failed\n"); #endif continue; } #ifdef DEBUG_SYNCHRO switch(Status) { case ID_STATUS_OFFLINE: DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status offline\n"); break; case ID_STATUS_ONLINE: DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status online\n"); break; case ID_STATUS_AWAY: DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status away\n"); break; case ID_STATUS_DND: DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status dnd\n"); break; case ID_STATUS_NA: DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status na\n"); break; case ID_STATUS_OCCUPIED: DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status occupied\n"); break; case ID_STATUS_FREECHAT: DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status freechat\n"); break; case ID_STATUS_INVISIBLE: DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status invisible\n"); break; case ID_STATUS_ONTHEPHONE: DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status onthephone\n"); break; case ID_STATUS_OUTTOLUNCH: DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status outtolunch\n"); break; default: DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status unknown\n"); break; } #endif BOOL isAccountCounting = 0; if ( (ActualAccount->Flags & YAMN_ACC_ENA) && (((ActualAccount->StatusFlags & YAMN_ACC_ST0) && (Status<=ID_STATUS_OFFLINE)) || ((ActualAccount->StatusFlags & YAMN_ACC_ST1) && (Status==ID_STATUS_ONLINE)) || ((ActualAccount->StatusFlags & YAMN_ACC_ST2) && (Status==ID_STATUS_AWAY)) || ((ActualAccount->StatusFlags & YAMN_ACC_ST3) && (Status==ID_STATUS_DND)) || ((ActualAccount->StatusFlags & YAMN_ACC_ST4) && (Status==ID_STATUS_NA)) || ((ActualAccount->StatusFlags & YAMN_ACC_ST5) && (Status==ID_STATUS_OCCUPIED)) || ((ActualAccount->StatusFlags & YAMN_ACC_ST6) && (Status==ID_STATUS_FREECHAT)) || ((ActualAccount->StatusFlags & YAMN_ACC_ST7) && (Status==ID_STATUS_INVISIBLE)) || ((ActualAccount->StatusFlags & YAMN_ACC_ST8) && (Status==ID_STATUS_ONTHEPHONE)) || ((ActualAccount->StatusFlags & YAMN_ACC_ST9) && (Status==ID_STATUS_OUTTOLUNCH)))) { if ((!ActualAccount->Interval && !ActualAccount->TimeLeft) || ActualAccount->Plugin->Fcn->TimeoutFcnPtr==NULL) { goto ChangeIsCountingStatusLabel; } if (ActualAccount->TimeLeft) { ActualAccount->TimeLeft--; isAccountCounting = TRUE; } #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile, "TimerProc:time left : %i\n", ActualAccount->TimeLeft); #endif WindowList_BroadcastAsync(YAMNVar.MessageWnds, WM_YAMN_CHANGETIME, (WPARAM)ActualAccount, (LPARAM)ActualAccount->TimeLeft); if (!ActualAccount->TimeLeft) { struct CheckParam ParamToPlugin={YAMN_CHECKVERSION, ThreadRunningEV, ActualAccount, YAMN_NORMALCHECK, (void *)0, NULL}; HANDLE NewThread; ActualAccount->TimeLeft=ActualAccount->Interval; if (NULL==(NewThread=CreateThread(NULL, 0, (YAMN_STANDARDFCN)ActualAccount->Plugin->Fcn->TimeoutFcnPtr, &ParamToPlugin, 0, &tid))) { #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read done\n"); #endif ReadDoneFcn(ActualAccount->AccountAccessSO); continue; } else { WaitForSingleObject(ThreadRunningEV, INFINITE); CloseHandle(NewThread); } } } ChangeIsCountingStatusLabel: #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read done\n"); #endif if (((ActualAccount->isCounting) != 0) != isAccountCounting) { ActualAccount->isCounting=isAccountCounting; WORD cStatus = db_get_w(ActualAccount->hContact, YAMN_DBMODULE, "Status", 0); switch (cStatus) { case ID_STATUS_ONLINE: case ID_STATUS_OFFLINE: db_set_w(ActualAccount->hContact, YAMN_DBMODULE, "Status", isAccountCounting?ID_STATUS_ONLINE:ID_STATUS_OFFLINE); default: break; } } ReadDoneFcn(ActualAccount->AccountAccessSO); } #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile, "TimerProc:AccountBrowserSO-read done\n"); #endif SWMRGDoneReading(ActualPlugin->Plugin->AccountBrowserSO); } LeaveCriticalSection(&PluginRegCS); CloseHandle(ThreadRunningEV); return; }
INT_PTR ForceCheckSvc(WPARAM, LPARAM) { PYAMN_PROTOPLUGINQUEUE ActualPlugin; HACCOUNT ActualAccount; HANDLE ThreadRunningEV; DWORD tid; //we use event to signal, that running thread has all needed stack parameters copied if (NULL==(ThreadRunningEV=CreateEvent(NULL, FALSE, FALSE, 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)) return 0; EnterCriticalSection(&PluginRegCS); for (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); 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); } ReadDoneFcn(ActualAccount->AccountAccessSO); } #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile, "ForceCheck:AccountBrowserSO-read done\n"); #endif SWMRGDoneReading(ActualPlugin->Plugin->AccountBrowserSO); } LeaveCriticalSection(&PluginRegCS); CloseHandle(ThreadRunningEV); if (hTTButton) CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hTTButton, 0); return 1; }
static INT_PTR PerformAccountWriting(HYAMNPROTOPLUGIN Plugin,HANDLE File) { DWORD WrittenBytes,Stat; HACCOUNT ActualAccount; DWORD Ver=YAMN_ACCOUNTFILEVERSION; BOOL Writed=FALSE; DWORD 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 != NULL;ActualAccount=ActualAccount->Next) { #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read wait\n"); #endif 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==NULL) || (*ActualAccount->Name==(TCHAR)0)) { #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read done\n"); #endif ReadDoneFcn(ActualAccount->AccountAccessSO); continue; } if (!Writed && !WriteFile(File,&Ver,sizeof(Ver),&WrittenBytes,NULL)) throw (DWORD)EACC_SYSTEM; Writed=TRUE; if (Stat=WriteStringToFile(File,ActualAccount->Name)) throw (DWORD)Stat; if (Stat=WriteStringToFile(File,ActualAccount->Server->Name)) throw (DWORD)Stat; if (!WriteFile(File,(char *)&ActualAccount->Server->Port,2,&WrittenBytes,NULL)) throw (DWORD)EACC_SYSTEM; if ((Stat=WriteStringToFile(File,ActualAccount->Server->Login))) throw (DWORD)Stat; CodeDecodeString(ActualAccount->Server->Passwd,TRUE); if (Stat=WriteStringToFile(File,ActualAccount->Server->Passwd)) { CodeDecodeString(ActualAccount->Server->Passwd,FALSE); throw (DWORD)Stat; } CodeDecodeString(ActualAccount->Server->Passwd,FALSE); if ((!WriteFile(File,(char *)&ActualAccount->Flags,sizeof(DWORD),&WrittenBytes,NULL) || (!WriteFile(File,(char *)&ActualAccount->StatusFlags,sizeof(DWORD),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->PluginFlags,sizeof(DWORD),&WrittenBytes,NULL)))) throw (DWORD)EACC_SYSTEM; if (!WriteFile(File,(char *)&ActualAccount->Interval,sizeof(WORD),&WrittenBytes,NULL)) throw (DWORD)EACC_SYSTEM; if ((!WriteFile(File,(char *)&ActualAccount->NewMailN.Flags,sizeof(DWORD),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->NewMailN.PopupB,sizeof(COLORREF),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->NewMailN.PopupT,sizeof(COLORREF),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->NewMailN.PopupTime,sizeof(DWORD),&WrittenBytes,NULL))) throw (DWORD)EACC_SYSTEM; if ((Stat=WriteStringToFileW(File,ActualAccount->NewMailN.App)) || (Stat=WriteStringToFileW(File,ActualAccount->NewMailN.AppParam))) throw (DWORD)Stat; if ((!WriteFile(File,(char *)&ActualAccount->NoNewMailN.Flags,sizeof(DWORD),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->NoNewMailN.PopupB,sizeof(COLORREF),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->NoNewMailN.PopupT,sizeof(COLORREF),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->NoNewMailN.PopupTime,sizeof(DWORD),&WrittenBytes,NULL))) throw (DWORD)EACC_SYSTEM; if ((Stat=WriteStringToFileW(File,ActualAccount->NoNewMailN.App)) || (Stat=WriteStringToFileW(File,ActualAccount->NoNewMailN.AppParam))) throw (DWORD)Stat; if ((!WriteFile(File,(char *)&ActualAccount->BadConnectN.Flags,sizeof(DWORD),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->BadConnectN.PopupB,sizeof(COLORREF),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->BadConnectN.PopupT,sizeof(COLORREF),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->BadConnectN.PopupTime,sizeof(DWORD),&WrittenBytes,NULL))) throw (DWORD)EACC_SYSTEM; if ((Stat=WriteStringToFileW(File,ActualAccount->BadConnectN.App)) || (Stat=WriteStringToFileW(File,ActualAccount->BadConnectN.AppParam))) throw (DWORD)Stat; //Let plugin write its own values into file if (ActualAccount->Plugin->Fcn != NULL && ActualAccount->Plugin->Fcn->WritePluginOptsFcnPtr != NULL) if (Stat=ActualAccount->Plugin->Fcn->WritePluginOptsFcnPtr(File,ActualAccount)) throw (DWORD)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 ReadDoneFcn(ActualAccount->MessagesAccessSO); throw (DWORD)Stat; } #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountMsgsSO-read done\n"); #endif ReadDoneFcn(ActualAccount->MessagesAccessSO); if ((!WriteFile(File,(char *)&ActualAccount->LastChecked,sizeof(SYSTEMTIME),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->LastSChecked,sizeof(SYSTEMTIME),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->LastSynchronised,sizeof(SYSTEMTIME),&WrittenBytes,NULL)) || (!WriteFile(File,(char *)&ActualAccount->LastMail,sizeof(SYSTEMTIME),&WrittenBytes,NULL))) throw (DWORD)Stat; #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read done\n"); #endif ReadDoneFcn(ActualAccount->AccountAccessSO); } } catch(DWORD ErrorCode) { #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read done\n"); #endif ReadDoneFcn(ActualAccount->AccountAccessSO); ReturnValue=ErrorCode; } #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"WriteAccountsToFile:AccountBrowserSO-read done\n"); #endif SWMRGDoneReading(Plugin->AccountBrowserSO); CloseHandle(File); return 0; }