diff options
author | George Hazan <george.hazan@gmail.com> | 2012-09-27 12:37:42 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2012-09-27 12:37:42 +0000 |
commit | 3ef638023d476a91128f287fe454b547836a4b90 (patch) | |
tree | 46c8e3340f5ce59fdb8bce2ef758e3c32d78fb01 /protocols/MRA | |
parent | 6035c2ae283bd8743a7484ed8796bd845afec4d5 (diff) |
automatic lock management
git-svn-id: http://svn.miranda-ng.org/main/trunk@1680 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/MRA')
-rw-r--r-- | protocols/MRA/Mra.cpp | 2 | ||||
-rw-r--r-- | protocols/MRA/Mra.h | 1 | ||||
-rw-r--r-- | protocols/MRA/MraChat.cpp | 2 | ||||
-rw-r--r-- | protocols/MRA/MraFilesQueue.cpp | 115 | ||||
-rw-r--r-- | protocols/MRA/MraProto.cpp | 39 | ||||
-rw-r--r-- | protocols/MRA/MraProto.h | 10 | ||||
-rw-r--r-- | protocols/MRA/MraSendQueue.cpp | 305 | ||||
-rw-r--r-- | protocols/MRA/Mra_functions.cpp | 150 | ||||
-rw-r--r-- | protocols/MRA/Mra_proto.cpp | 42 | ||||
-rw-r--r-- | protocols/MRA/Mra_svcs.cpp | 2 | ||||
-rw-r--r-- | protocols/MRA/Sdk/FIFOMT.h | 34 | ||||
-rw-r--r-- | protocols/MRA/Sdk/ListMT.h | 20 |
12 files changed, 224 insertions, 498 deletions
diff --git a/protocols/MRA/Mra.cpp b/protocols/MRA/Mra.cpp index 0a8bae22b6..9b4e278fe6 100644 --- a/protocols/MRA/Mra.cpp +++ b/protocols/MRA/Mra.cpp @@ -28,7 +28,7 @@ BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID Reserved) case DLL_PROCESS_ATTACH:
bzero(&masMraSettings, sizeof(masMraSettings));
masMraSettings.hInstance = hInstance;
- masMraSettings.hHeap = HeapCreate(0, 0, 0);//GetProcessHeap();
+ masMraSettings.hHeap = HeapCreate(0, 0, 0);
DisableThreadLibraryCalls(hInstance);
break;
diff --git a/protocols/MRA/Mra.h b/protocols/MRA/Mra.h index c699229704..4cef21f83e 100644 --- a/protocols/MRA/Mra.h +++ b/protocols/MRA/Mra.h @@ -247,7 +247,6 @@ BOOL IsHTTPSProxyUsed (HANDLE hNetlibUser); BOOL IsContactMraProto (HANDLE hContact);
BOOL IsEMailMR (LPSTR lpszEMail, size_t dwEMailSize);
BOOL GetEMailFromString (LPSTR lpszBuff, size_t dwBuffSize, LPSTR *plpszEMail, size_t *pdwEMailSize);
-DWORD ProtoBroadcastAckAsynchEx (const char *szModule, HANDLE hContact, int type, int result, HANDLE hProcess, LPARAM lParam, size_t dwLparamSize);
DWORD CreateBlobFromContact (HANDLE hContact, LPWSTR lpwszRequestReason, size_t dwRequestReasonSize, LPBYTE lpbBuff, size_t dwBuffSize, size_t *pdwBuffSizeRet);
int ExtraSetIcon (HANDLE hExtraIcon, HANDLE hContact, HANDLE hImage, int iColumnType);
diff --git a/protocols/MRA/MraChat.cpp b/protocols/MRA/MraChat.cpp index 1dfb9dba8d..d9735081d0 100644 --- a/protocols/MRA/MraChat.cpp +++ b/protocols/MRA/MraChat.cpp @@ -241,7 +241,7 @@ int CMraProto::MraChatGcEventHook(WPARAM, LPARAM lParam) INT_PTR iSendRet = MraMessageW(bSlowSend, hContact, ACKTYPE_MESSAGE, dwFlags, szEMail, dwEMailSize, gch->ptszText, dwMessageSize, NULL, 0);
if (bSlowSend == FALSE)
- ProtoBroadcastAckAsynchEx(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)iSendRet, (LPARAM)NULL, 0);
+ ProtoBroadcastAckEx(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)iSendRet, 0);
MraChatSessionEventSendByHandle(hContact, GC_EVENT_MESSAGE, GCEF_ADDTOLOG, NULL, 0, NULL, gch->ptszText, 0, (DWORD)_time32(NULL));
}
diff --git a/protocols/MRA/MraFilesQueue.cpp b/protocols/MRA/MraFilesQueue.cpp index a5a3660c53..02564c0879 100644 --- a/protocols/MRA/MraFilesQueue.cpp +++ b/protocols/MRA/MraFilesQueue.cpp @@ -164,13 +164,11 @@ void MraFilesQueueDestroy(HANDLE hFilesQueueHandle) MRA_FILES_QUEUE *pmrafqFilesQueue = (MRA_FILES_QUEUE*)hFilesQueueHandle;
MRA_FILES_QUEUE_ITEM *dat;
-
- ListMTLock(pmrafqFilesQueue);
- while ( ListMTItemGetFirst(pmrafqFilesQueue, NULL, (LPVOID*)&dat) == NO_ERROR)
- MraFilesQueueItemFree(dat);
-
- ListMTUnLock(pmrafqFilesQueue);
-
+ {
+ mt_lock l(pmrafqFilesQueue);
+ while ( ListMTItemGetFirst(pmrafqFilesQueue, NULL, (LPVOID*)&dat) == NO_ERROR)
+ MraFilesQueueItemFree(dat);
+ }
ListMTDestroy(pmrafqFilesQueue);
mir_free(pmrafqFilesQueue);
}
@@ -184,22 +182,19 @@ DWORD MraFilesQueueItemFindByID(HANDLE hFilesQueueHandle, DWORD dwIDRequest, MRA MRA_FILES_QUEUE_ITEM *dat;
LIST_MT_ITERATOR lmtiIterator;
- DWORD dwRetErrorCode = ERROR_NOT_FOUND;
- ListMTLock(pmrafqFilesQueue);
+ mt_lock l(pmrafqFilesQueue);
ListMTIteratorMoveFirst(pmrafqFilesQueue, &lmtiIterator);
- do
- {// цикл
+ do {
if (ListMTIteratorGet(&lmtiIterator, NULL, (LPVOID*)&dat) == NO_ERROR)
- if (dat->dwIDRequest == dwIDRequest)
- {
- if (ppmrafqFilesQueueItem) (*ppmrafqFilesQueueItem) = dat;
- dwRetErrorCode = NO_ERROR;
- break;
+ if (dat->dwIDRequest == dwIDRequest) {
+ if (ppmrafqFilesQueueItem)
+ *ppmrafqFilesQueueItem = dat;
+ return 0;
}
}
while (ListMTIteratorMoveNext(&lmtiIterator));
- ListMTUnLock(pmrafqFilesQueue);
- return dwRetErrorCode;
+
+ return ERROR_NOT_FOUND;
}
HANDLE MraFilesQueueItemProxyByID(HANDLE hFilesQueueHandle, DWORD dwIDRequest)
@@ -224,9 +219,10 @@ void MraFilesQueueItemFree(MRA_FILES_QUEUE_ITEM *dat) MraAddrListFree(&dat->malAddrList);
MraMrimProxyFree(dat->hMraMrimProxyData);
mir_free(dat->lpwszPath);
- ListMTLock(plmtListMT);
- ListMTItemDelete(plmtListMT, dat);
- ListMTUnLock(plmtListMT);
+ {
+ mt_lock l(plmtListMT);
+ ListMTItemDelete(plmtListMT, dat);
+ }
mir_free(dat);
}
@@ -278,7 +274,7 @@ DWORD CMraProto::MraFilesQueueAccept(HANDLE hFilesQueueHandle, DWORD dwIDRequest MRA_FILES_QUEUE *pmrafqFilesQueue = (MRA_FILES_QUEUE*)hFilesQueueHandle;
MRA_FILES_QUEUE_ITEM *dat;
- ListMTLock(pmrafqFilesQueue);
+ mt_lock l(pmrafqFilesQueue);
DWORD dwRetErrorCode = MraFilesQueueItemFindByID(hFilesQueueHandle, dwIDRequest, &dat);
if (dwRetErrorCode == NO_ERROR) {
MRA_FILES_THREADPROC_PARAMS *pmftpp = (MRA_FILES_THREADPROC_PARAMS*)mir_calloc(sizeof(MRA_FILES_THREADPROC_PARAMS));
@@ -298,7 +294,6 @@ DWORD CMraProto::MraFilesQueueAccept(HANDLE hFilesQueueHandle, DWORD dwIDRequest dat->hThread = ForkThreadEx(&CMraProto::MraFilesQueueRecvThreadProc, pmftpp);
}
- ListMTUnLock(pmrafqFilesQueue);
return dwRetErrorCode;
}
@@ -310,7 +305,7 @@ DWORD CMraProto::MraFilesQueueCancel(HANDLE hFilesQueueHandle, DWORD dwIDRequest MRA_FILES_QUEUE *pmrafqFilesQueue = (MRA_FILES_QUEUE*)hFilesQueueHandle;
MRA_FILES_QUEUE_ITEM *dat;
- ListMTLock(pmrafqFilesQueue);
+ mt_lock l(pmrafqFilesQueue);
DWORD dwRetErrorCode = MraFilesQueueItemFindByID(hFilesQueueHandle, dwIDRequest, &dat);
if (dwRetErrorCode == NO_ERROR) { //***deb closesocket, send message to thread
InterlockedExchange((volatile LONG*)&dat->bIsWorking, FALSE);
@@ -336,41 +331,27 @@ DWORD CMraProto::MraFilesQueueCancel(HANDLE hFilesQueueHandle, DWORD dwIDRequest if (dat->hThread == NULL)
MraFilesQueueItemFree(dat);
}
- ListMTUnLock(pmrafqFilesQueue);
return dwRetErrorCode;
}
DWORD CMraProto::MraFilesQueueStartMrimProxy(HANDLE hFilesQueueHandle, DWORD dwIDRequest)
{
- DWORD dwRetErrorCode;
+ if (!hFilesQueueHandle || !mraGetByte(NULL, "FileSendEnableMRIMProxyCons", MRA_DEF_FS_ENABLE_MRIM_PROXY_CONS))
+ return ERROR_INVALID_HANDLE;
- if (hFilesQueueHandle && mraGetByte(NULL, "FileSendEnableMRIMProxyCons", MRA_DEF_FS_ENABLE_MRIM_PROXY_CONS))
- {
- MRA_FILES_QUEUE *pmrafqFilesQueue = (MRA_FILES_QUEUE*)hFilesQueueHandle;
- MRA_FILES_QUEUE_ITEM *dat;
+ MRA_FILES_QUEUE *pmrafqFilesQueue = (MRA_FILES_QUEUE*)hFilesQueueHandle;
+ MRA_FILES_QUEUE_ITEM *dat;
- ListMTLock(pmrafqFilesQueue);
- if ((dwRetErrorCode = MraFilesQueueItemFindByID(hFilesQueueHandle, dwIDRequest, &dat)) == NO_ERROR)
- {//***deb
- if (dat->bSending == FALSE)
- {// receiving
- SetEvent(dat->hWaitHandle);// cancel wait incomming connection
- }else {// sending
+ mt_lock l(pmrafqFilesQueue);
+ if ( !MraFilesQueueItemFindByID(hFilesQueueHandle, dwIDRequest, &dat))
+ if (dat->bSending == FALSE)
+ SetEvent(dat->hWaitHandle);// cancel wait incomming connection
- }
- }
- ListMTUnLock(pmrafqFilesQueue);
- }else {
- dwRetErrorCode = ERROR_INVALID_HANDLE;
- }
-return(dwRetErrorCode);
+ return 0;
}
-
DWORD MraFilesQueueFree(HANDLE hFilesQueueHandle, DWORD dwIDRequest)
{
- DWORD dwRetErrorCode;
-
if (!hFilesQueueHandle)
return ERROR_INVALID_HANDLE;
@@ -378,20 +359,18 @@ DWORD MraFilesQueueFree(HANDLE hFilesQueueHandle, DWORD dwIDRequest) MRA_FILES_QUEUE_ITEM *dat;
LIST_MT_ITERATOR lmtiIterator;
- dwRetErrorCode = ERROR_NOT_FOUND;
- ListMTLock(pmrafqFilesQueue);
+ mt_lock l(pmrafqFilesQueue);
ListMTIteratorMoveFirst(pmrafqFilesQueue, &lmtiIterator);
- do { // цикл
+ do {
if (ListMTIteratorGet(&lmtiIterator, NULL, (LPVOID*)&dat) == NO_ERROR)
if (dat->dwIDRequest == dwIDRequest) {
MraFilesQueueItemFree(dat);
- dwRetErrorCode = NO_ERROR;
- break;
+ return 0;
}
}
while (ListMTIteratorMoveNext(&lmtiIterator));
- ListMTUnLock(pmrafqFilesQueue);
- return dwRetErrorCode;
+
+ return ERROR_NOT_FOUND;
}
DWORD CMraProto::MraFilesQueueSendMirror(HANDLE hFilesQueueHandle, DWORD dwIDRequest, LPSTR lpszAddreses, size_t dwAddresesSize)
@@ -402,7 +381,7 @@ DWORD CMraProto::MraFilesQueueSendMirror(HANDLE hFilesQueueHandle, DWORD dwIDReq MRA_FILES_QUEUE *pmrafqFilesQueue = (MRA_FILES_QUEUE*)hFilesQueueHandle;
MRA_FILES_QUEUE_ITEM *dat;
- ListMTLock(pmrafqFilesQueue);
+ mt_lock l(pmrafqFilesQueue);
DWORD dwRetErrorCode = MraFilesQueueItemFindByID(hFilesQueueHandle, dwIDRequest, &dat);
if (dwRetErrorCode == NO_ERROR) {
MraAddrListGetFromBuff(lpszAddreses, dwAddresesSize, &dat->malAddrList);
@@ -411,7 +390,6 @@ DWORD CMraProto::MraFilesQueueSendMirror(HANDLE hFilesQueueHandle, DWORD dwIDReq dat->hConnection = NULL;
SetEvent(dat->hWaitHandle);
}
- ListMTUnLock(pmrafqFilesQueue);
return dwRetErrorCode;
}
@@ -742,10 +720,10 @@ DWORD CMraProto::MraFilesQueueAddReceive(HANDLE hFilesQueueHandle, DWORD dwFlags MraAddrListGetFromBuff(lpszAddreses, dwAddresesSize, &dat->malAddrList);
MraAddrListStoreToContact(dat->hContact, &dat->malAddrList);
-
- ListMTLock(pmrafqFilesQueue);
- ListMTItemAdd(pmrafqFilesQueue, dat, dat);
- ListMTUnLock(pmrafqFilesQueue);
+ {
+ mt_lock l(pmrafqFilesQueue);
+ ListMTItemAdd(pmrafqFilesQueue, dat, dat);
+ }
// Send chain event
PROTORECVFILET prf;
@@ -975,9 +953,8 @@ void CMraProto::MraFilesQueueRecvThreadProc(LPVOID lpParameter) }
else ProtoBroadcastAck(m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, (HANDLE)dat->dwIDRequest, 0);
- ListMTLock(pmrafqFilesQueue);
+ mt_lock l(pmrafqFilesQueue);
MraFilesQueueItemFree(dat);
- ListMTUnLock(pmrafqFilesQueue);
}
}
@@ -1023,13 +1000,12 @@ DWORD CMraProto::MraFilesQueueAddSend(HANDLE hFilesQueueHandle, DWORD dwFlags, H }
dat->bSending = TRUE;
- if (pdwIDRequest)
- *pdwIDRequest = dat->dwIDRequest;
-
- ListMTLock(pmrafqFilesQueue);
- ListMTItemAdd(pmrafqFilesQueue, dat, dat);
- ListMTUnLock(pmrafqFilesQueue);
+ if (pdwIDRequest) *pdwIDRequest = dat->dwIDRequest;
+ {
+ mt_lock l(pmrafqFilesQueue);
+ ListMTItemAdd(pmrafqFilesQueue, dat, dat);
+ }
MRA_FILES_THREADPROC_PARAMS *pmftpp = (MRA_FILES_THREADPROC_PARAMS*)mir_calloc(sizeof(MRA_FILES_THREADPROC_PARAMS));
pmftpp->hFilesQueueHandle = hFilesQueueHandle;
pmftpp->dat = dat;
@@ -1223,7 +1199,6 @@ void CMraProto::MraFilesQueueSendThreadProc(LPVOID lpParameter) }
else ProtoBroadcastAck(m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, (HANDLE)dat->dwIDRequest, 0);
- ListMTLock(pmrafqFilesQueue);
+ mt_lock l(pmrafqFilesQueue);
MraFilesQueueItemFree(dat);
- ListMTUnLock(pmrafqFilesQueue);
}
diff --git a/protocols/MRA/MraProto.cpp b/protocols/MRA/MraProto.cpp index 4694f956bb..efc61c4899 100644 --- a/protocols/MRA/MraProto.cpp +++ b/protocols/MRA/MraProto.cpp @@ -47,19 +47,6 @@ CMraProto::CMraProto(const char* _module, const TCHAR* _displayName) : if ( ServiceExists(MS_NUDGE_SEND))
heNudgeReceived = CreateHookableEvent(MS_NUDGE);
- FifoMTInitialize(&ffmtAPCQueue, 0);
- hWaitEventThreadAPCHandle = CreateEvent(NULL, FALSE, FALSE, NULL);
- InterlockedExchange((volatile LONG*)&dwAPCThreadRunning, TRUE);
- hThreadAPC = ForkThreadEx(&CMraProto::MraUserAPCThreadProc, NULL);
- if (hThreadAPC == NULL) {
- MraAPCQueueDestroy(&ffmtAPCQueue);
- CloseHandle(hWaitEventThreadAPCHandle);
- hWaitEventThreadAPCHandle = NULL;
- DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &hThreadAPC, THREAD_SET_CONTEXT, FALSE, 0);
- DebugPrintCRLFW(L"Fail on create event APC thread, using miranda main thread");
- MessageBox(NULL, L"Fail on create event APC thread, using miranda main thread", m_tszUserName, MB_OK | MB_ICONINFORMATION);
- }
-
TCHAR name[128];
mir_sntprintf( name, SIZEOF(name), TranslateT("%s connection"), m_tszUserName);
@@ -169,16 +156,6 @@ int CMraProto::OnPreShutdown(WPARAM, LPARAM) hThreadWorker = NULL;
}
- InterlockedExchange((volatile LONG*)&dwAPCThreadRunning, FALSE);
- if (hWaitEventThreadAPCHandle)
- if (IsThreadAlive(hThreadAPC))
- SetEvent(hWaitEventThreadAPCHandle);
- else {
- CloseHandle(hWaitEventThreadAPCHandle);
- hWaitEventThreadAPCHandle = NULL;
- hThreadAPC = NULL;
- }
-
return 0;
}
@@ -522,12 +499,12 @@ int CMraProto::SendContacts(HANDLE hContact, int flags, int nContacts, HANDLE* h bSlowSend = mraGetByte(NULL, "SlowSend", MRA_DEFAULT_SLOW_SEND);
iRet = MraMessageW(bSlowSend, hContact, ACKTYPE_CONTACTS, MESSAGE_FLAG_CONTACT, szEMail, dwEMailSize, lpwszData, (lpwszDataCurrent-lpwszData), NULL, 0);
if (bSlowSend == FALSE)
- ProtoBroadcastAckAsynchEx(hContact, ACKTYPE_CONTACTS, ACKRESULT_SUCCESS, (HANDLE)iRet, (LPARAM)NULL, 0);
+ ProtoBroadcastAckEx(hContact, ACKTYPE_CONTACTS, ACKRESULT_SUCCESS, (HANDLE)iRet, 0);
}
mir_free(lpwszData);
}
}
- else ProtoBroadcastAckAsynchEx(hContact, ACKTYPE_CONTACTS, ACKRESULT_FAILED, NULL, (LPARAM)"You cannot send when you are offline.", -1);
+ else ProtoBroadcastAckEx(hContact, ACKTYPE_CONTACTS, ACKRESULT_FAILED, NULL, (LPARAM)"You cannot send when you are offline.");
return iRet;
}
@@ -547,7 +524,7 @@ HANDLE CMraProto::SendFile(HANDLE hContact, const TCHAR* szDescription, TCHAR** int CMraProto::SendMsg(HANDLE hContact, int flags, const char *lpszMessage)
{
if (!m_bLoggedIn) {
- ProtoBroadcastAckAsynchEx(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, NULL, (LPARAM)"You cannot send when you are offline.", -1);
+ ProtoBroadcastAckEx(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, NULL, (LPARAM)"You cannot send when you are offline.");
return 0;
}
@@ -564,7 +541,7 @@ int CMraProto::SendMsg(HANDLE hContact, int flags, const char *lpszMessage) lpwszMessage = mir_a2t(lpszMessage);
if ( !lpwszMessage) {
- ProtoBroadcastAckAsynchEx(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, NULL, (LPARAM)"Cant allocate buffer for convert to unicode.", -1);
+ ProtoBroadcastAckEx(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, NULL, (LPARAM)"Cant allocate buffer for convert to unicode.");
return 0;
}
@@ -576,7 +553,7 @@ int CMraProto::SendMsg(HANDLE hContact, int flags, const char *lpszMessage) iRet = MraMessageW(bSlowSend, hContact, ACKTYPE_MESSAGE, dwFlags, szEMail, dwEMailSize, lpwszMessage, lstrlen(lpwszMessage), NULL, 0);
if (bSlowSend == FALSE)
- ProtoBroadcastAckAsynchEx(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)iRet, (LPARAM)NULL, 0);
+ ProtoBroadcastAckEx(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)iRet, 0);
}
mir_free(lpwszMessage);
@@ -658,7 +635,7 @@ int CMraProto::SetStatus(int iNewStatus) // nothing to change
if (InterlockedExchangeAdd((volatile LONG*)&m_iStatus, 0) == iNewStatus && iNewStatus != m_iDesiredStatus)
- ProtoBroadcastAckAsynchEx(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)iNewStatus, iNewStatus, 0);
+ ProtoBroadcastAckEx(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)iNewStatus, iNewStatus);
else {
DWORD dwOldStatusMode;
@@ -704,7 +681,7 @@ int CMraProto::SetStatus(int iNewStatus) }
}
MraSetContactStatus(NULL, m_iStatus);
- ProtoBroadcastAckAsynchEx(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)dwOldStatusMode, m_iStatus, 0);
+ ProtoBroadcastAckEx(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)dwOldStatusMode, m_iStatus);
}
return 0;
@@ -730,7 +707,7 @@ HANDLE CMraProto::GetAwayMsg(HANDLE hContact) dwStatusDescSize = mir_sntprintf(szStatusDesc, SIZEOF(szStatusDesc), _T("%s%s"), szTime, szBlogStatus);
iRet = GetTickCount();
- ProtoBroadcastAckAsynchEx(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)iRet, (LPARAM)szStatusDesc, dwStatusDescSize);
+ ProtoBroadcastAckEx(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)iRet, (LPARAM)szStatusDesc);
}
return (HANDLE)iRet;
}
diff --git a/protocols/MRA/MraProto.h b/protocols/MRA/MraProto.h index 91b0d70994..3cc7cb911e 100644 --- a/protocols/MRA/MraProto.h +++ b/protocols/MRA/MraProto.h @@ -205,7 +205,6 @@ struct CMraProto : public PROTO_INTERFACE, public MZeroedObject bool m_bLoggedIn;
HANDLE hSendQueueHandle, hFilesQueueHandle, hMPopSessionQueue;
- FIFO_MT ffmtAPCQueue;
HANDLE hNetlibUser, heNudgeReceived, hHookExtraIconsApply;
HANDLE hThreadWorker;
@@ -214,9 +213,6 @@ struct CMraProto : public PROTO_INTERFACE, public MZeroedObject DWORD dwThreadWorkerRunning;
DWORD dwCMDNum;
- HANDLE hThreadAPC; // APC thread, for queue tasks
- HANDLE hWaitEventThreadAPCHandle;
- DWORD dwAPCThreadRunning;
HANDLE hAvatarsQueueHandle;
HANDLE hMainMenuItems[MAIN_MENU_ITEMS_COUNT+4];
@@ -311,16 +307,12 @@ struct CMraProto : public PROTO_INTERFACE, public MZeroedObject DWORD MraAntiSpamReceivedMessageW(LPSTR lpszEMail, size_t dwEMailSize, DWORD dwMessageFlags, LPWSTR lpwszMessage, size_t dwMessageSize);
BOOL MraAntiSpamHasMessageBadWordsW(LPWSTR lpwszMessage, size_t dwMessageSize);
- DWORD MraAPCQueueAdd(PAPCFUNC pfnAPC, PFIFO_MT pffmtAPCQueue, ULONG_PTR dwData);
- void MraAPCQueueDestroy(PFIFO_MT pffmtAPCQueue);
- void __cdecl MraUserAPCThreadProc(LPVOID lpParameter);
-
void InitMainMenu();
void InitContactMenu();
void CListCreateMenu(LONG lPosition, LONG lPopupPosition, HICON hMainIcon, LPSTR pszContactOwner, BOOL bIsStatus, const struct GUI_DISPLAY_ITEM *pgdiItems, size_t dwCount, HANDLE *hResult);
void CListShowMenuItem(HANDLE hMenuItem, BOOL bShow);
- DWORD ProtoBroadcastAckAsynchEx(HANDLE hContact, int type, int hResult, HANDLE hProcess, LPARAM lParam, size_t dwLparamSize);
+ DWORD ProtoBroadcastAckEx(HANDLE hContact, int type, int hResult, HANDLE hProcess, LPARAM lParam);
DWORD CreateBlobFromContact(HANDLE hContact, LPWSTR lpwszRequestReason, size_t dwRequestReasonSize, LPBYTE lpbBuff, size_t dwBuffSize, size_t *pdwBuffSizeRet);
BOOL SetPassDB(LPSTR lpszBuff, size_t dwBuffSize);
diff --git a/protocols/MRA/MraSendQueue.cpp b/protocols/MRA/MraSendQueue.cpp index 7482e86863..53d6f1345d 100644 --- a/protocols/MRA/MraSendQueue.cpp +++ b/protocols/MRA/MraSendQueue.cpp @@ -1,225 +1,168 @@ #include "Mra.h"
#include "MraSendQueue.h"
-
-
-
-typedef struct
+struct MRA_SEND_QUEUE : public LIST_MT
{
- LIST_MT lmtListMT;
- DWORD dwSendTimeOutInterval;
-} MRA_SEND_QUEUE;
+ DWORD dwSendTimeOutInterval;
+};
-
-typedef struct
+struct MRA_SEND_QUEUE_ITEM : public LIST_MT_ITEM
{
// internal
- LIST_MT_ITEM lmtListMTItem;
- FILETIME ftSendTime;
- // external
- DWORD dwCMDNum;
- DWORD dwFlags;
- HANDLE hContact;
- DWORD dwAckType;
- LPBYTE lpbData;
- size_t dwDataSize;
-} MRA_SEND_QUEUE_ITEM;
-
+ FILETIME ftSendTime;
+ // external
+ DWORD dwCMDNum;
+ DWORD dwFlags;
+ HANDLE hContact;
+ DWORD dwAckType;
+ LPBYTE lpbData;
+ size_t dwDataSize;
+};
#define FILETIME_SECOND ((DWORDLONG)10000000)
-
-
-
DWORD MraSendQueueInitialize(DWORD dwSendTimeOutInterval, HANDLE *phSendQueueHandle)
{
- DWORD dwRetErrorCode;
-
- if (phSendQueueHandle)
- {
- MRA_SEND_QUEUE *pmrasqSendQueue;
-
- pmrasqSendQueue = (MRA_SEND_QUEUE*)mir_calloc(sizeof(MRA_SEND_QUEUE));
- if (pmrasqSendQueue)
- {
- dwRetErrorCode = ListMTInitialize(&pmrasqSendQueue->lmtListMT, 0);
- if (dwRetErrorCode == NO_ERROR)
- {
- pmrasqSendQueue->dwSendTimeOutInterval = dwSendTimeOutInterval;
- (*phSendQueueHandle) = (HANDLE)pmrasqSendQueue;
- }
- }else {
- dwRetErrorCode = GetLastError();
- }
- }else {
- dwRetErrorCode = ERROR_INVALID_HANDLE;
+ if (!phSendQueueHandle)
+ return ERROR_INVALID_HANDLE;
+
+ MRA_SEND_QUEUE *pmrasqSendQueue = (MRA_SEND_QUEUE*)mir_calloc(sizeof(MRA_SEND_QUEUE));
+ if (!pmrasqSendQueue)
+ return GetLastError();
+
+ DWORD dwRetErrorCode = ListMTInitialize(pmrasqSendQueue, 0);
+ if (dwRetErrorCode == NO_ERROR) {
+ pmrasqSendQueue->dwSendTimeOutInterval = dwSendTimeOutInterval;
+ *phSendQueueHandle = (HANDLE)pmrasqSendQueue;
}
-return(dwRetErrorCode);
+ return dwRetErrorCode;
}
-
void MraSendQueueDestroy(HANDLE hSendQueueHandle)
{
- if (hSendQueueHandle)
- {
- MRA_SEND_QUEUE *pmrasqSendQueue = (MRA_SEND_QUEUE*)hSendQueueHandle;
- MRA_SEND_QUEUE_ITEM *pmrasqiSendQueueItem;
+ if (!hSendQueueHandle)
+ return;
- ListMTLock(&pmrasqSendQueue->lmtListMT);
- while (ListMTItemGetFirst(&pmrasqSendQueue->lmtListMT, NULL, (LPVOID*)&pmrasqiSendQueueItem) == NO_ERROR)
- {
- ListMTItemDelete(&pmrasqSendQueue->lmtListMT, &pmrasqiSendQueueItem->lmtListMTItem);
- //mir_free(pmrasqiSendQueueItem->lpbData);
+ MRA_SEND_QUEUE *pmrasqSendQueue = (MRA_SEND_QUEUE*)hSendQueueHandle;
+ MRA_SEND_QUEUE_ITEM *pmrasqiSendQueueItem;
+ {
+ mt_lock l(pmrasqSendQueue);
+ while ( !ListMTItemGetFirst(pmrasqSendQueue, NULL, (LPVOID*)&pmrasqiSendQueueItem)) {
+ ListMTItemDelete(pmrasqSendQueue, pmrasqiSendQueueItem);
mir_free(pmrasqiSendQueueItem);
}
- ListMTUnLock(&pmrasqSendQueue->lmtListMT);
-
- ListMTDestroy(&pmrasqSendQueue->lmtListMT);
- mir_free(pmrasqSendQueue);
}
+
+ ListMTDestroy(pmrasqSendQueue);
+ mir_free(pmrasqSendQueue);
}
DWORD MraSendQueueAdd(HANDLE hSendQueueHandle, DWORD dwCMDNum, DWORD dwFlags, HANDLE hContact, DWORD dwAckType, LPBYTE lpbData, size_t dwDataSize)
{
- DWORD dwRetErrorCode;
-
- if (hSendQueueHandle && dwCMDNum)
- {
- MRA_SEND_QUEUE *pmrasqSendQueue = (MRA_SEND_QUEUE*)hSendQueueHandle;
- MRA_SEND_QUEUE_ITEM *pmrasqiSendQueueItem;
-
- pmrasqiSendQueueItem = (MRA_SEND_QUEUE_ITEM*)mir_calloc(sizeof(MRA_SEND_QUEUE_ITEM));
- if (pmrasqiSendQueueItem)
- {
- //pmrasqiSendQueueItem->lmtListMTItem;
- GetSystemTimeAsFileTime(&pmrasqiSendQueueItem->ftSendTime);
- pmrasqiSendQueueItem->dwCMDNum = dwCMDNum;
- pmrasqiSendQueueItem->dwFlags = dwFlags;
- pmrasqiSendQueueItem->hContact = hContact;
- pmrasqiSendQueueItem->dwAckType = dwAckType;
- pmrasqiSendQueueItem->lpbData = lpbData;
- pmrasqiSendQueueItem->dwDataSize = dwDataSize;
-
- ListMTLock(&pmrasqSendQueue->lmtListMT);
- ListMTItemAdd(&pmrasqSendQueue->lmtListMT, &pmrasqiSendQueueItem->lmtListMTItem, pmrasqiSendQueueItem);
- ListMTUnLock(&pmrasqSendQueue->lmtListMT);
- dwRetErrorCode = NO_ERROR;
- }else {
- dwRetErrorCode = GetLastError();
- }
- }else {
- dwRetErrorCode = ERROR_INVALID_HANDLE;
- }
-return(dwRetErrorCode);
+ if (!hSendQueueHandle || !dwCMDNum)
+ return ERROR_INVALID_HANDLE;
+
+ MRA_SEND_QUEUE *pmrasqSendQueue = (MRA_SEND_QUEUE*)hSendQueueHandle;
+ MRA_SEND_QUEUE_ITEM *pmrasqiSendQueueItem;
+
+ pmrasqiSendQueueItem = (MRA_SEND_QUEUE_ITEM*)mir_calloc(sizeof(MRA_SEND_QUEUE_ITEM));
+ if (!pmrasqiSendQueueItem)
+ return GetLastError();
+
+ GetSystemTimeAsFileTime(&pmrasqiSendQueueItem->ftSendTime);
+ pmrasqiSendQueueItem->dwCMDNum = dwCMDNum;
+ pmrasqiSendQueueItem->dwFlags = dwFlags;
+ pmrasqiSendQueueItem->hContact = hContact;
+ pmrasqiSendQueueItem->dwAckType = dwAckType;
+ pmrasqiSendQueueItem->lpbData = lpbData;
+ pmrasqiSendQueueItem->dwDataSize = dwDataSize;
+
+ mt_lock l(pmrasqSendQueue);
+ ListMTItemAdd(pmrasqSendQueue, pmrasqiSendQueueItem, pmrasqiSendQueueItem);
+ return 0;
}
-
DWORD MraSendQueueFree(HANDLE hSendQueueHandle, DWORD dwCMDNum)
{
- DWORD dwRetErrorCode;
-
- if (hSendQueueHandle)
- {
- MRA_SEND_QUEUE *pmrasqSendQueue = (MRA_SEND_QUEUE*)hSendQueueHandle;
- MRA_SEND_QUEUE_ITEM *pmrasqiSendQueueItem;
- LIST_MT_ITERATOR lmtiIterator;
-
- dwRetErrorCode = ERROR_NOT_FOUND;
- ListMTLock(&pmrasqSendQueue->lmtListMT);
- ListMTIteratorMoveFirst(&pmrasqSendQueue->lmtListMT, &lmtiIterator);
- do
- {// цикл
- if (ListMTIteratorGet(&lmtiIterator, NULL, (LPVOID*)&pmrasqiSendQueueItem) == NO_ERROR)
- if (pmrasqiSendQueueItem->dwCMDNum == dwCMDNum)
- {
- ListMTItemDelete(&pmrasqSendQueue->lmtListMT, &pmrasqiSendQueueItem->lmtListMTItem);
- //mir_free(pmrasqiSendQueueItem->lpbData);
- mir_free(pmrasqiSendQueueItem);
- dwRetErrorCode = NO_ERROR;
- break;
- }
- }while (ListMTIteratorMoveNext(&lmtiIterator));
- ListMTUnLock(&pmrasqSendQueue->lmtListMT);
- }else {
- dwRetErrorCode = ERROR_INVALID_HANDLE;
+ if (!hSendQueueHandle)
+ return ERROR_INVALID_HANDLE;
+
+ MRA_SEND_QUEUE *pmrasqSendQueue = (MRA_SEND_QUEUE*)hSendQueueHandle;
+ MRA_SEND_QUEUE_ITEM *pmrasqiSendQueueItem;
+ LIST_MT_ITERATOR lmtiIterator;
+
+ mt_lock l(pmrasqSendQueue);
+ ListMTIteratorMoveFirst(pmrasqSendQueue, &lmtiIterator);
+ do {
+ if ( !ListMTIteratorGet(&lmtiIterator, NULL, (LPVOID*)&pmrasqiSendQueueItem))
+ if (pmrasqiSendQueueItem->dwCMDNum == dwCMDNum) {
+ ListMTItemDelete(pmrasqSendQueue, pmrasqiSendQueueItem);
+ mir_free(pmrasqiSendQueueItem);
+ return 0;
+ }
}
-return(dwRetErrorCode);
-}
+ while (ListMTIteratorMoveNext(&lmtiIterator));
+ return ERROR_NOT_FOUND;
+}
DWORD MraSendQueueFind(HANDLE hSendQueueHandle, DWORD dwCMDNum, DWORD *pdwFlags, HANDLE *phContact, DWORD *pdwAckType, LPBYTE *plpbData, size_t *pdwDataSize)
{
- DWORD dwRetErrorCode;
-
- if (hSendQueueHandle)
- {
- MRA_SEND_QUEUE *pmrasqSendQueue = (MRA_SEND_QUEUE*)hSendQueueHandle;
- MRA_SEND_QUEUE_ITEM *pmrasqiSendQueueItem;
- LIST_MT_ITERATOR lmtiIterator;
-
- dwRetErrorCode = ERROR_NOT_FOUND;
- ListMTLock(&pmrasqSendQueue->lmtListMT);
- ListMTIteratorMoveFirst(&pmrasqSendQueue->lmtListMT, &lmtiIterator);
- do
- {// цикл
- if (ListMTIteratorGet(&lmtiIterator, NULL, (LPVOID*)&pmrasqiSendQueueItem) == NO_ERROR)
- if (pmrasqiSendQueueItem->dwCMDNum == dwCMDNum)
- {
- if (pdwFlags) (*pdwFlags) = pmrasqiSendQueueItem->dwFlags;
- if (phContact) (*phContact) = pmrasqiSendQueueItem->hContact;
- if (pdwAckType) (*pdwAckType) = pmrasqiSendQueueItem->dwAckType;
- if (plpbData) (*plpbData) = pmrasqiSendQueueItem->lpbData;
- if (pdwDataSize) (*pdwDataSize) = pmrasqiSendQueueItem->dwDataSize;
- dwRetErrorCode = NO_ERROR;
- break;
- }
- }while (ListMTIteratorMoveNext(&lmtiIterator));
- ListMTUnLock(&pmrasqSendQueue->lmtListMT);
- }else {
- dwRetErrorCode = ERROR_INVALID_HANDLE;
+ if (!hSendQueueHandle)
+ return ERROR_INVALID_HANDLE;
+
+ MRA_SEND_QUEUE *pmrasqSendQueue = (MRA_SEND_QUEUE*)hSendQueueHandle;
+ MRA_SEND_QUEUE_ITEM *pmrasqiSendQueueItem;
+ LIST_MT_ITERATOR lmtiIterator;
+
+ mt_lock l(pmrasqSendQueue);
+ ListMTIteratorMoveFirst(pmrasqSendQueue, &lmtiIterator);
+ do {
+ if ( !ListMTIteratorGet(&lmtiIterator, NULL, (LPVOID*)&pmrasqiSendQueueItem))
+ if (pmrasqiSendQueueItem->dwCMDNum == dwCMDNum) {
+ if (pdwFlags) (*pdwFlags) = pmrasqiSendQueueItem->dwFlags;
+ if (phContact) (*phContact) = pmrasqiSendQueueItem->hContact;
+ if (pdwAckType) (*pdwAckType) = pmrasqiSendQueueItem->dwAckType;
+ if (plpbData) (*plpbData) = pmrasqiSendQueueItem->lpbData;
+ if (pdwDataSize) (*pdwDataSize) = pmrasqiSendQueueItem->dwDataSize;
+ return 0;
+ }
}
-return(dwRetErrorCode);
-}
+ while (ListMTIteratorMoveNext(&lmtiIterator));
+ return ERROR_NOT_FOUND;
+}
DWORD MraSendQueueFindOlderThan(HANDLE hSendQueueHandle, DWORD dwTime, DWORD *pdwCMDNum, DWORD *pdwFlags, HANDLE *phContact, DWORD *pdwAckType, LPBYTE *plpbData, size_t *pdwDataSize)
{
- DWORD dwRetErrorCode;
-
- if (hSendQueueHandle)
- {
- FILETIME ftExpireTime;
- MRA_SEND_QUEUE *pmrasqSendQueue = (MRA_SEND_QUEUE*)hSendQueueHandle;
+ if (!hSendQueueHandle)
+ return ERROR_INVALID_HANDLE;
+
+ FILETIME ftExpireTime;
+ GetSystemTimeAsFileTime(&ftExpireTime);
+ (*((DWORDLONG*)&ftExpireTime))-=((DWORDLONG)dwTime*FILETIME_SECOND);
+
+ MRA_SEND_QUEUE *pmrasqSendQueue = (MRA_SEND_QUEUE*)hSendQueueHandle;
+ mt_lock l(pmrasqSendQueue);
+
+ LIST_MT_ITERATOR lmtiIterator;
+ ListMTIteratorMoveFirst(pmrasqSendQueue, &lmtiIterator);
+ do {
MRA_SEND_QUEUE_ITEM *pmrasqiSendQueueItem;
- LIST_MT_ITERATOR lmtiIterator;
-
- GetSystemTimeAsFileTime(&ftExpireTime);
- (*((DWORDLONG*)&ftExpireTime))-=((DWORDLONG)dwTime*FILETIME_SECOND);
- dwRetErrorCode = ERROR_NOT_FOUND;
- ListMTLock(&pmrasqSendQueue->lmtListMT);
- ListMTIteratorMoveFirst(&pmrasqSendQueue->lmtListMT, &lmtiIterator);
- do
- {// цикл
- if (ListMTIteratorGet(&lmtiIterator, NULL, (LPVOID*)&pmrasqiSendQueueItem) == NO_ERROR)
- if ((*((DWORDLONG*)&ftExpireTime))>(*((DWORDLONG*)&pmrasqiSendQueueItem->ftSendTime)))
- {
- if (pdwCMDNum) (*pdwCMDNum) = pmrasqiSendQueueItem->dwCMDNum;
- if (pdwFlags) (*pdwFlags) = pmrasqiSendQueueItem->dwFlags;
- if (phContact) (*phContact) = pmrasqiSendQueueItem->hContact;
- if (pdwAckType) (*pdwAckType) = pmrasqiSendQueueItem->dwAckType;
- if (plpbData) (*plpbData) = pmrasqiSendQueueItem->lpbData;
- if (pdwDataSize) (*pdwDataSize) = pmrasqiSendQueueItem->dwDataSize;
- dwRetErrorCode = NO_ERROR;
- break;
- }
- }while (ListMTIteratorMoveNext(&lmtiIterator));
- ListMTUnLock(&pmrasqSendQueue->lmtListMT);
- }else {
- dwRetErrorCode = ERROR_INVALID_HANDLE;
+ if ( !ListMTIteratorGet(&lmtiIterator, NULL, (LPVOID*)&pmrasqiSendQueueItem))
+ if ((*((DWORDLONG*)&ftExpireTime))>(*((DWORDLONG*)&pmrasqiSendQueueItem->ftSendTime))) {
+ if (pdwCMDNum) *pdwCMDNum = pmrasqiSendQueueItem->dwCMDNum;
+ if (pdwFlags) *pdwFlags = pmrasqiSendQueueItem->dwFlags;
+ if (phContact) *phContact = pmrasqiSendQueueItem->hContact;
+ if (pdwAckType) *pdwAckType = pmrasqiSendQueueItem->dwAckType;
+ if (plpbData) *plpbData = pmrasqiSendQueueItem->lpbData;
+ if (pdwDataSize) *pdwDataSize = pmrasqiSendQueueItem->dwDataSize;
+ return 0;
+ }
}
-return(dwRetErrorCode);
-}
-
+ while (ListMTIteratorMoveNext(&lmtiIterator));
+ return ERROR_NOT_FOUND;
+}
diff --git a/protocols/MRA/Mra_functions.cpp b/protocols/MRA/Mra_functions.cpp index 28799c574e..8c195fc63c 100644 --- a/protocols/MRA/Mra_functions.cpp +++ b/protocols/MRA/Mra_functions.cpp @@ -24,14 +24,6 @@ struct RECURSION_DATA_STACK_ITEM WIN32_FIND_DATA w32fdFindFileData;
};
-struct MRA_APC_QUEUE_ITEM
-{
- FIFO_MT_ITEM ffmtItem;
- PAPCFUNC pfnAPC;
-};
-
-void MraAPCQueueProcess(PFIFO_MT pffmtAPCQueue);
-void CALLBACK ThreadMarandaCallbackAck(ULONG_PTR dwParam);
LRESULT CALLBACK MessageEditSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
DWORD MraGetSelfVersionString(LPSTR lpszSelfVersion, size_t dwSelfVersionSize, size_t *pdwSelfVersionSizeRet)
@@ -1073,56 +1065,6 @@ BOOL CMraProto::GetContactFirstEMail(HANDLE hContact, BOOL bMRAOnly, LPSTR lpszR /////////////////////////////////////////////////////////////////////////////////////////
//
-DWORD CMraProto::MraAPCQueueAdd(PAPCFUNC pfnAPC, PFIFO_MT pffmtAPCQueue, ULONG_PTR dwData)
-{
- if (hThreadAPC && pffmtAPCQueue && pfnAPC) {
- MRA_APC_QUEUE_ITEM *pqiApcQueueItem;
-
- pqiApcQueueItem = (MRA_APC_QUEUE_ITEM*)mir_calloc(sizeof(MRA_APC_QUEUE_ITEM));
- if (pqiApcQueueItem) {
- pqiApcQueueItem->pfnAPC = pfnAPC;
- FifoMTItemPush(pffmtAPCQueue, (PCFIFO_MT_ITEM)pqiApcQueueItem, (LPVOID)dwData);
- SetEvent(hWaitEventThreadAPCHandle);
- return NO_ERROR;
- }
-
- return GetLastError();
- }
-
- return ERROR_INVALID_HANDLE;
-}
-
-void MraAPCQueueProcess(PFIFO_MT pffmtAPCQueue)
-{
- LPVOID lpData;
- MRA_APC_QUEUE_ITEM *pqiApcQueueItem;
-
- while (FifoMTItemPop(pffmtAPCQueue, (PFIFO_MT_ITEM*)&pqiApcQueueItem, &lpData) == NO_ERROR) {
- SleepEx(10, FALSE);
- pqiApcQueueItem->pfnAPC((ULONG_PTR)lpData);
- mir_free(pqiApcQueueItem);
- }
-}
-
-
-void CMraProto::MraAPCQueueDestroy(PFIFO_MT pffmtAPCQueue)
-{
- if (hThreadAPC) {
- LPVOID lpData;
- PFIFO_MT_ITEM pffmtiFifoItem;
-
- FifoMTLock(pffmtAPCQueue);
-
- while ( FifoMTItemPop(pffmtAPCQueue, &pffmtiFifoItem, &lpData) == NO_ERROR) {
- mir_free(lpData);
- mir_free(pffmtiFifoItem);
- }
-
- FifoMTUnLock(pffmtAPCQueue);
- FifoMTDestroy(pffmtAPCQueue);
- }
-}
-
void CMraProto::ShowFormattedErrorMessage(LPWSTR lpwszErrText, DWORD dwErrorCode)
{
WCHAR szErrorText[2048], szErrDescription[1024];
@@ -1138,100 +1080,12 @@ void CMraProto::ShowFormattedErrorMessage(LPWSTR lpwszErrText, DWORD dwErrorCode MraPopupShowFromAgentW(MRA_POPUP_TYPE_ERROR, 0, szErrorText);
}
-DWORD CMraProto::ProtoBroadcastAckAsynchEx(HANDLE hContact, int type, int hResult, HANDLE hProcess, LPARAM lParam, size_t dwLparamSize)
+DWORD CMraProto::ProtoBroadcastAckEx(HANDLE hContact, int type, int hResult, HANDLE hProcess, LPARAM lParam)
{
- size_t dwModuleSize;
-
- dwModuleSize = lstrlenA(m_szModuleName);
- if (dwLparamSize == -1)
- dwLparamSize = lstrlenA((LPSTR)lParam);
-
- ACKDATA *lpAck = (ACKDATA*)mir_calloc((sizeof(ACKDATA)+dwModuleSize+dwLparamSize+sizeof(DWORD)));
- if (!lpAck)
- return GetLastError();
-
- lpAck->cbSize = sizeof(ACKDATA);
- lpAck->szModule = (((char*)lpAck)+sizeof(ACKDATA));
- lpAck->hContact = hContact;
- lpAck->type = type;
- lpAck->result = hResult;
- lpAck->hProcess = hProcess;
- if (dwLparamSize)
- {
- lpAck->lParam = (LPARAM)(lpAck->szModule+dwModuleSize);
- memmove((LPVOID)lpAck->lParam, (LPVOID)lParam, dwLparamSize);
- }else {
- lpAck->lParam = lParam;
- }
- memmove((LPVOID)lpAck->szModule, (LPVOID)m_szModuleName, dwModuleSize);
-
- DWORD dwRetErrorCode = MraAPCQueueAdd(ThreadMarandaCallbackAck, &ffmtAPCQueue, (ULONG_PTR)lpAck);
- if (dwRetErrorCode != NO_ERROR) {
- CallService(MS_PROTO_BROADCASTACK, 0, (LPARAM)lpAck);
- mir_free(lpAck);
- return dwRetErrorCode;
- }
-
+ ProtoBroadcastAck(m_szModuleName, hContact, type, hResult, hProcess, lParam);
return 0;
}
-void CALLBACK ThreadMarandaCallbackAck(ULONG_PTR dwParam)
-{
- if (dwParam) {
- CallService(MS_PROTO_BROADCASTACK, 0, (LPARAM)dwParam);
- mir_free(( void* )dwParam);
- }
-}
-
-void CMraProto::MraUserAPCThreadProc(LPVOID lpParameter)
-{
- DWORD dwWaitRetCode = WAIT_TIMEOUT, dwCurTickTime, dwNextCheckTime, dwLastPingTime, dwFailCounter;
-
- dwNextCheckTime = 0;
- dwFailCounter = 0;
-
- while ( InterlockedExchangeAdd((volatile LONG*)&dwAPCThreadRunning, 0)) {
- MraAPCQueueProcess(&ffmtAPCQueue);
-
- if (hThreadWorker)
- if ( IsThreadAlive(hThreadWorker)) {// check man thread last answer time
- dwCurTickTime = GetTickCount();
-
- if (dwCurTickTime > dwNextCheckTime) {
- dwLastPingTime = InterlockedExchangeAdd((volatile LONG*)&dwThreadWorkerLastPingTime, 0);
- // ping failure, thread not answer
- if (dwCurTickTime > dwLastPingTime && dwCurTickTime - dwLastPingTime > THREAD_MAX_PING_TIME*1000) {
- dwFailCounter++;
- DebugPrintCRLFW(L"Watchdog: mra worker thread not answering");
- if (dwFailCounter > THREAD_MAX_PING_FAIL_COUNT) {
- DebugPrintCRLFW(L"Watchdog: TERMINATING mra worker thread");
- TerminateThread(hThreadWorker, WAIT_TIMEOUT);
- MraThreadClean();
- dwFailCounter = 0;
- }
- }
- else dwFailCounter = 0;
- dwNextCheckTime = (dwCurTickTime+(THREAD_MAX_PING_TIME*1000));
- }
- }
- else { // main thread is die, clean up
- DebugPrintCRLFW(L"Watchdog: mra worker thread is down!!!!");
- MraThreadClean();
- }
- dwWaitRetCode = WaitForSingleObjectEx(hWaitEventThreadAPCHandle, THREAD_SLEEP_TIME, FALSE);
- }
-
- if (hWaitEventThreadAPCHandle) {
- CloseHandle(hWaitEventThreadAPCHandle);
- hWaitEventThreadAPCHandle = NULL;
- }
- MraAPCQueueDestroy(&ffmtAPCQueue);
- hThreadAPC = NULL;
- InterlockedExchange((volatile LONG*)&dwAPCThreadRunning, FALSE);
-
- DebugPrintCRLFW(L"Watchdog: APC thread ended, no watching.");
-}
-
DWORD CMraProto::CreateBlobFromContact(HANDLE hContact, LPWSTR lpwszRequestReason, size_t dwRequestReasonSize, LPBYTE lpbBuff, size_t dwBuffSize, size_t *pdwBuffSizeRet)
{
DWORD dwRetErrorCode;
diff --git a/protocols/MRA/Mra_proto.cpp b/protocols/MRA/Mra_proto.cpp index 6abb2fbd3e..268834835e 100644 --- a/protocols/MRA/Mra_proto.cpp +++ b/protocols/MRA/Mra_proto.cpp @@ -107,7 +107,7 @@ void CMraProto::MraThreadProc(LPVOID lpParameter) else {
if (bConnected == FALSE) {
ShowFormattedErrorMessage(L"Can't connect to MRIM server, error", GetLastError());
- ProtoBroadcastAckAsynchEx(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_NONETWORK, 0);
+ ProtoBroadcastAckEx(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_NONETWORK);
}
}
@@ -270,13 +270,13 @@ DWORD CMraProto::MraNetworkDispatcher() //nothing to do
break;
case ACKTYPE_MESSAGE:
- ProtoBroadcastAckAsynchEx(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)dwCMDNum, (LPARAM)"Undefined message deliver error, time out", -1);
+ ProtoBroadcastAckEx(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)dwCMDNum, (LPARAM)"Undefined message deliver error, time out");
break;
case ACKTYPE_GETINFO:
- ProtoBroadcastAckAsynchEx(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)1, (LPARAM)NULL, 0);
+ ProtoBroadcastAckEx(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)1, (LPARAM)NULL);
break;
case ACKTYPE_SEARCH:
- ProtoBroadcastAckAsynchEx(hContact, dwAckType, ACKRESULT_SUCCESS, (HANDLE)dwCMDNum, (LPARAM)NULL, 0);
+ ProtoBroadcastAckEx(hContact, dwAckType, ACKRESULT_SUCCESS, (HANDLE)dwCMDNum, (LPARAM)NULL);
break;
case ICQACKTYPE_SMS:
mir_free(lpbData);
@@ -454,7 +454,7 @@ DWORD CMraProto::MraCommandDispatcher(mrim_packet_header_t *pmaHeader, DWORD *pd break;
case MRIM_CS_LOGIN_REJ: // Unsuccessful authorization //LPS ## reason ## причина отказа
- ProtoBroadcastAckAsynchEx(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_WRONGPASSWORD, 0);
+ ProtoBroadcastAckEx(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_WRONGPASSWORD);
GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
dwStringSize = MultiByteToWideChar(MRA_CODE_PAGE, 0, lpsString.lpszData, lpsString.dwSize, szBuff, SIZEOF(szBuff));
@@ -483,33 +483,33 @@ DWORD CMraProto::MraCommandDispatcher(mrim_packet_header_t *pmaHeader, DWORD *pd break;
case MRIM_CS_MESSAGE_STATUS:
- if (MraSendQueueFind(hSendQueueHandle, pmaHeader->seq, NULL, &hContact, &dwAckType, (LPBYTE*)&lpsString.lpszData, &lpsString.dwSize) == NO_ERROR) {
+ if ( !MraSendQueueFind(hSendQueueHandle, pmaHeader->seq, NULL, &hContact, &dwAckType, (LPBYTE*)&lpsString.lpszData, &lpsString.dwSize)) {
dwTemp = GetUL(&lpbDataCurrent);
switch (dwTemp) {
case MESSAGE_DELIVERED:// Message delivered directly to user
- ProtoBroadcastAckAsynchEx(hContact, dwAckType, ACKRESULT_SUCCESS, (HANDLE)pmaHeader->seq, (LPARAM)NULL, 0);
+ ProtoBroadcastAckEx(hContact, dwAckType, ACKRESULT_SUCCESS, (HANDLE)pmaHeader->seq, (LPARAM)NULL);
break;//***deb возможны сбои из-за асинхронности тк там передаётся указатель
case MESSAGE_REJECTED_NOUSER:// Message rejected - no such user
- ProtoBroadcastAckAsynchEx(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)pmaHeader->seq, (LPARAM)"Message rejected - no such user", -1);
+ ProtoBroadcastAckEx(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)pmaHeader->seq, (LPARAM)"Message rejected - no such user");
break;
case MESSAGE_REJECTED_INTERR:// Internal server error
- ProtoBroadcastAckAsynchEx(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)pmaHeader->seq, (LPARAM)"Internal server error", -1);
+ ProtoBroadcastAckEx(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)pmaHeader->seq, (LPARAM)"Internal server error");
break;
case MESSAGE_REJECTED_LIMIT_EXCEEDED:// Offline messages limit exceeded
- ProtoBroadcastAckAsynchEx(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)pmaHeader->seq, (LPARAM)"Offline messages limit exceeded", -1);
+ ProtoBroadcastAckEx(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)pmaHeader->seq, (LPARAM)"Offline messages limit exceeded");
break;
case MESSAGE_REJECTED_TOO_LARGE:// Message is too large
- ProtoBroadcastAckAsynchEx(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)pmaHeader->seq, (LPARAM)"Message is too large", -1);
+ ProtoBroadcastAckEx(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)pmaHeader->seq, (LPARAM)"Message is too large");
break;
case MESSAGE_REJECTED_DENY_OFFMSG:// User does not accept offline messages
- ProtoBroadcastAckAsynchEx(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)pmaHeader->seq, (LPARAM)"User does not accept offline messages", -1);
+ ProtoBroadcastAckEx(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)pmaHeader->seq, (LPARAM)"User does not accept offline messages");
break;
case MESSAGE_REJECTED_DENY_OFFFLSH:// User does not accept offline flash animation
- ProtoBroadcastAckAsynchEx(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)pmaHeader->seq, (LPARAM)"User does not accept offline flash animation", -1);
+ ProtoBroadcastAckEx(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)pmaHeader->seq, (LPARAM)"User does not accept offline flash animation");
break;
default:
dwTemp = mir_snprintf((LPSTR)szBuff, SIZEOF(szBuff), "Undefined message deliver error, code: %lu", dwTemp);
- ProtoBroadcastAckAsynchEx(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)pmaHeader->seq, (LPARAM)szBuff, dwTemp);
+ ProtoBroadcastAckEx(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)pmaHeader->seq, (LPARAM)szBuff);
break;
}
MraSendQueueFree(hSendQueueHandle, pmaHeader->seq);
@@ -1116,11 +1116,11 @@ DWORD CMraProto::MraCommandDispatcher(mrim_packet_header_t *pmaHeader, DWORD *pd switch (dwAckType) {
case ACKTYPE_GETINFO:
- ProtoBroadcastAckAsynchEx(hContact, dwAckType, ACKRESULT_SUCCESS, (HANDLE)1, (LPARAM)NULL, 0);
+ ProtoBroadcastAckEx(hContact, dwAckType, ACKRESULT_SUCCESS, (HANDLE)1, (LPARAM)NULL);
break;
case ACKTYPE_SEARCH:
default:
- ProtoBroadcastAckAsynchEx(hContact, dwAckType, ACKRESULT_SUCCESS, (HANDLE)pmaHeader->seq, (LPARAM)NULL, 0);
+ ProtoBroadcastAckEx(hContact, dwAckType, ACKRESULT_SUCCESS, (HANDLE)pmaHeader->seq, (LPARAM)NULL);
break;
}
break;
@@ -1131,10 +1131,10 @@ DWORD CMraProto::MraCommandDispatcher(mrim_packet_header_t *pmaHeader, DWORD *pd case MRIM_ANKETA_INFO_STATUS_RATELIMERR:// слишком много запросов, поиск временно запрещен
switch (dwAckType) {
case ACKTYPE_GETINFO:
- ProtoBroadcastAckAsynchEx(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)1, (LPARAM)NULL, 0);
+ ProtoBroadcastAckEx(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)1, (LPARAM)NULL);
break;
case ACKTYPE_SEARCH:
- ProtoBroadcastAckAsynchEx(hContact, dwAckType, ACKRESULT_SUCCESS, (HANDLE)pmaHeader->seq, (LPARAM)NULL, 0);
+ ProtoBroadcastAckEx(hContact, dwAckType, ACKRESULT_SUCCESS, (HANDLE)pmaHeader->seq, (LPARAM)NULL);
break;
default:
DebugBreak();
@@ -1576,7 +1576,7 @@ DWORD CMraProto::MraCommandDispatcher(mrim_packet_header_t *pmaHeader, DWORD *pd lpwszMessage = (LPWSTR)(lpszPhone+dwPhoneSize+1);
dwTemp = mir_snprintf((LPSTR)szBuff, SIZEOF(szBuff), "<sms_response><source>Mail.ru</source><deliverable>Yes</deliverable><network>Mail.ru, Russia</network><message_id>%s-1-1955988055-%s</message_id><destination>%s</destination><messages_left>0</messages_left></sms_response>\r\n", szEMail, lpszPhone, lpszPhone);
- ProtoBroadcastAckAsynchEx(NULL, dwAckType, ACKRESULT_SENTREQUEST, (HANDLE)pmaHeader->seq, (LPARAM)szBuff, dwTemp);
+ ProtoBroadcastAckEx(NULL, dwAckType, ACKRESULT_SENTREQUEST, (HANDLE)pmaHeader->seq, (LPARAM)szBuff);
}
mir_free(lpsString.lpszData);
@@ -1903,11 +1903,11 @@ DWORD CMraProto::MraRecvCommand_Message(DWORD dwTime, DWORD dwFlags, MRA_LPS *pl if (dwFlags & MESSAGE_SMS_DELIVERY_REPORT) {
dwBuffLen = mir_snprintf(lpszBuff, (dwBuffLen*sizeof(WCHAR)), "<sms_delivery_receipt><message_id>%s-1-1955988055-%s</message_id><destination>%s</destination><delivered>No</delivered><submition_time>%s</submition_time><error_code>0</error_code><error><id>15</id><params><param>%s</param></params></error></sms_delivery_receipt>", szEMail, szPhone, szPhone, szTime, lpszMessageUTF);
- ProtoBroadcastAckAsynchEx(NULL, ICQACKTYPE_SMS, ACKRESULT_FAILED, (HANDLE)0, (LPARAM)lpszBuff, dwBuffLen);
+ ProtoBroadcastAckEx(NULL, ICQACKTYPE_SMS, ACKRESULT_FAILED, (HANDLE)0, (LPARAM)lpszBuff);
}
else { // new sms
dwBuffLen = mir_snprintf(lpszBuff, (dwBuffLen*sizeof(WCHAR)), "<sms_message><source>Mail.ru</source><destination_UIN>%s</destination_UIN><sender>%s</sender><senders_network>Mail.ru</senders_network><text>%s</text><time>%s</time></sms_message>", szEMail, szPhone, lpszMessageUTF, szTime);
- ProtoBroadcastAckAsynchEx(NULL, ICQACKTYPE_SMS, ACKRESULT_SUCCESS, (HANDLE)0, (LPARAM)lpszBuff, dwBuffLen);
+ ProtoBroadcastAckEx(NULL, ICQACKTYPE_SMS, ACKRESULT_SUCCESS, (HANDLE)0, (LPARAM)lpszBuff);
}
}
else dwRetErrorCode = GetLastError();
diff --git a/protocols/MRA/Mra_svcs.cpp b/protocols/MRA/Mra_svcs.cpp index e5548986b4..9168ecc0a9 100644 --- a/protocols/MRA/Mra_svcs.cpp +++ b/protocols/MRA/Mra_svcs.cpp @@ -289,7 +289,7 @@ INT_PTR CMraProto::MraRequestAuthorization(WPARAM wParam, LPARAM lParam) BOOL bSlowSend = mraGetByte(NULL, "SlowSend", MRA_DEFAULT_SLOW_SEND);
int iRet = MraMessageW(bSlowSend, hContact, ACKTYPE_AUTHREQ, MESSAGE_FLAG_AUTHORIZE, szEMail, dwEMailSize, wszAuthMessage, dwMessageSize, NULL, 0);
if (bSlowSend == FALSE)
- ProtoBroadcastAckAsynchEx(hContact, ACKTYPE_AUTHREQ, ACKRESULT_SUCCESS, (HANDLE)iRet, (LPARAM)NULL, 0);
+ ProtoBroadcastAckEx(hContact, ACKTYPE_AUTHREQ, ACKRESULT_SUCCESS, (HANDLE)iRet, (LPARAM)NULL);
return 0;
}
diff --git a/protocols/MRA/Sdk/FIFOMT.h b/protocols/MRA/Sdk/FIFOMT.h index d15ae3e596..acff96f500 100644 --- a/protocols/MRA/Sdk/FIFOMT.h +++ b/protocols/MRA/Sdk/FIFOMT.h @@ -62,13 +62,8 @@ typedef PCLIST_MT_ITERATOR PCFIFO_MT_ITERATOR, LPCFIFO_MT_ITERATOR; __inline size_t FifoMTItemPush(PCFIFO_MT pcpmtFifoMT,PCFIFO_MT_ITEM pcffmtiFifoItem,LPVOID lpData)
{
- size_t dwRet;
-
- ListMTLock(pcpmtFifoMT);
- dwRet=ListMTItemAdd(pcpmtFifoMT,pcffmtiFifoItem,lpData);
- ListMTUnLock(pcpmtFifoMT);
-
-return(dwRet);
+ mt_lock l(pcpmtFifoMT);
+ return ListMTItemAdd(pcpmtFifoMT,pcffmtiFifoItem,lpData);
}
@@ -77,39 +72,28 @@ __inline DWORD FifoMTItemPop(PCFIFO_MT pcpmtFifoMT,PFIFO_MT_ITEM *ppffmtiFifoIte DWORD dwRetErrorCode;
PLIST_MT_ITEM plmtiItem;
- ListMTLock(pcpmtFifoMT);
+ mt_lock l(pcpmtFifoMT);
if ((dwRetErrorCode=ListMTItemGetFirst(pcpmtFifoMT,&plmtiItem,plpData))==NO_ERROR)
{
if (ppffmtiFifoItem) (*ppffmtiFifoItem)=plmtiItem;
- dwRetErrorCode=ListMTItemDelete(pcpmtFifoMT,plmtiItem);
+ return ListMTItemDelete(pcpmtFifoMT,plmtiItem);
}
- ListMTUnLock(pcpmtFifoMT);
-return(dwRetErrorCode);
+ return dwRetErrorCode;
}
__inline DWORD FifoMTItemGetFirst(PCFIFO_MT pcpmtFifoMT,PFIFO_MT_ITEM *ppffmtiFifoItem,LPVOID *plpData)
{
- DWORD dwRetErrorCode;
-
- ListMTLock(pcpmtFifoMT);
- dwRetErrorCode=ListMTItemGetFirst(pcpmtFifoMT,ppffmtiFifoItem,plpData);
- ListMTUnLock(pcpmtFifoMT);
-
-return(dwRetErrorCode);
+ mt_lock l(pcpmtFifoMT);
+ return ListMTItemGetFirst(pcpmtFifoMT,ppffmtiFifoItem,plpData);
}
__inline DWORD FifoMTItemGetLast(PCFIFO_MT pcpmtFifoMT,PFIFO_MT_ITEM *ppffmtiFifoItem,LPVOID *plpData)
{
- DWORD dwRetErrorCode;
-
- ListMTLock(pcpmtFifoMT);
- dwRetErrorCode=ListMTItemGetLast(pcpmtFifoMT,ppffmtiFifoItem,plpData);
- ListMTUnLock(pcpmtFifoMT);
-
-return(dwRetErrorCode);
+ mt_lock l(pcpmtFifoMT);
+ return ListMTItemGetLast(pcpmtFifoMT,ppffmtiFifoItem,plpData);
}
diff --git a/protocols/MRA/Sdk/ListMT.h b/protocols/MRA/Sdk/ListMT.h index d7ca6e0b12..38d9247488 100644 --- a/protocols/MRA/Sdk/ListMT.h +++ b/protocols/MRA/Sdk/ListMT.h @@ -126,18 +126,20 @@ __inline BOOL ListMTTryLock(PCLIST_MT pclmtListMT) #endif
}
-
-__inline void ListMTLock(PCLIST_MT pclmtListMT)
+class mt_lock
{
- EnterCriticalSection(&pclmtListMT->cs);
-}
+ PCLIST_MT m_list;
+public:
+ __forceinline mt_lock(PCLIST_MT _pList) :
+ m_list( _pList )
+ { EnterCriticalSection(&_pList->cs);
+ }
-__inline void ListMTUnLock(PCLIST_MT pclmtListMT)
-{
- LeaveCriticalSection(&pclmtListMT->cs);
-}
-
+ __forceinline ~mt_lock()
+ { LeaveCriticalSection(&m_list->cs);
+ }
+};
__inline size_t ListMTGetCount(PCLIST_MT pclmtListMT)
{
|