summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2014-03-15 10:22:52 +0000
committerGeorge Hazan <george.hazan@gmail.com>2014-03-15 10:22:52 +0000
commitcc728e869240bd88c968d50614f752d15c7369e4 (patch)
tree7dba936ab5b7bb45eade8bab60ad2d2da0daa021
parent7846764cedc3ebc2827e891d683fec31e2149baa (diff)
fix for a chaos with a netlib handle declaration
git-svn-id: http://svn.miranda-ng.org/main/trunk@8614 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--protocols/MRA/src/Mra.h4
-rw-r--r--protocols/MRA/src/MraAvatars.cpp65
-rw-r--r--protocols/MRA/src/MraFilesQueue.cpp70
-rw-r--r--protocols/MRA/src/MraMRIMProxy.cpp40
-rw-r--r--protocols/MRA/src/MraProto.cpp2
-rw-r--r--protocols/MRA/src/MraProto.h8
-rw-r--r--protocols/MRA/src/MraSendCommand.cpp4
-rw-r--r--protocols/MRA/src/Mra_functions.cpp4
-rw-r--r--protocols/MRA/src/Mra_proto.cpp7
9 files changed, 97 insertions, 107 deletions
diff --git a/protocols/MRA/src/Mra.h b/protocols/MRA/src/Mra.h
index 457d421ed7..a5d6d5d437 100644
--- a/protocols/MRA/src/Mra.h
+++ b/protocols/MRA/src/Mra.h
@@ -221,7 +221,7 @@ CMStringA CopyNumber(const CMStringA&);
CMStringW DecodeXML(const CMStringW &lptszMessage);
CMStringW EncodeXML(const CMStringW &lptszMessage);
-bool IsHTTPSProxyUsed(HANDLE m_hNetlibUser);
+bool IsHTTPSProxyUsed(HANDLE hConnection);
bool IsContactMraProto(MCONTACT hContact);
bool IsEMailMR(const CMStringA& szEmail);
bool GetEMailFromString(const CMStringA& szBuff, CMStringA& szEmail);
@@ -243,4 +243,6 @@ INT_PTR CALLBACK DlgProcAccount(HWND hwnd, UINT message, WPARAM wparam, LPARAM l
#define LPS2ANSI(var, p, size) char *var = (char*)alloca(size+1); memcpy(var, p, size); var[size]=0;
+#define NETLIB_CLOSEHANDLE(hConnection) {Netlib_CloseHandle(hConnection); hConnection = NULL;}
+
#endif // !defined(AFX_MRA_H__F58D13FF_F6F2_476C_B8F0_7B9E9357CF48__INCLUDED_)
diff --git a/protocols/MRA/src/MraAvatars.cpp b/protocols/MRA/src/MraAvatars.cpp
index c60a0197f2..440ba67102 100644
--- a/protocols/MRA/src/MraAvatars.cpp
+++ b/protocols/MRA/src/MraAvatars.cpp
@@ -20,7 +20,7 @@ struct MRA_AVATARS_QUEUE : public FIFO_MT
{
volatile LONG bIsRunning;
volatile LONG lThreadsRunningCount;
- HANDLE m_hNetlibUser;
+ HANDLE hNetlibUser;
HANDLE hThreadEvent;
int iThreadsCount;
HANDLE hThread[MAXIMUM_WAIT_OBJECTS];
@@ -40,16 +40,14 @@ struct MRA_AVATARS_QUEUE_ITEM : public FIFO_MT_ITEM
char szAvtSectName[MAX_PATH];
#define MRA_AVT_SECT_NAME szAvtSectName
-#define NETLIB_CLOSEHANDLE(m_hConnection) {Netlib_CloseHandle(m_hConnection); m_hConnection = NULL;}
-
-HANDLE MraAvatarsHttpConnect(HANDLE m_hNetlibUser, LPCSTR lpszHost, DWORD dwPort);
+HANDLE MraAvatarsHttpConnect(HANDLE hNetlibUser, LPCSTR lpszHost, DWORD dwPort);
#define MAHTRO_AVT 0
#define MAHTRO_AVTMRIM 1
#define MAHTRO_AVTSMALL 2
#define MAHTRO_AVTSMALLMRIM 3
-DWORD MraAvatarsHttpTransaction(HANDLE m_hConnection, DWORD dwRequestType, LPCSTR lpszUser, LPCSTR lpszDomain, LPCSTR lpszHost, DWORD dwReqObj, BOOL bUseKeepAliveConn, DWORD *pdwResultCode, BOOL *pbKeepAlive, DWORD *pdwFormat, size_t *pdwAvatarSize, INTERNET_TIME *pitLastModifiedTime);
+DWORD MraAvatarsHttpTransaction(HANDLE hConnection, DWORD dwRequestType, LPCSTR lpszUser, LPCSTR lpszDomain, LPCSTR lpszHost, DWORD dwReqObj, BOOL bUseKeepAliveConn, DWORD *pdwResultCode, BOOL *pbKeepAlive, DWORD *pdwFormat, size_t *pdwAvatarSize, INTERNET_TIME *pitLastModifiedTime);
DWORD CMraProto::MraAvatarsQueueInitialize(HANDLE *phAvatarsQueueHandle)
{
@@ -71,8 +69,8 @@ DWORD CMraProto::MraAvatarsQueueInitialize(HANDLE *phAvatarsQueueHandle)
nlu.flags = NUF_OUTGOING | NUF_HTTPCONNS;
nlu.szSettingsModule = MRA_AVT_SECT_NAME;
nlu.szDescriptiveName = szBuffer;
- pmraaqAvatarsQueue->m_hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
- if (pmraaqAvatarsQueue->m_hNetlibUser) {
+ pmraaqAvatarsQueue->hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
+ if (pmraaqAvatarsQueue->hNetlibUser) {
InterlockedExchange((volatile LONG*)&pmraaqAvatarsQueue->bIsRunning, TRUE);
pmraaqAvatarsQueue->hThreadEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
pmraaqAvatarsQueue->iThreadsCount = db_get_dw(NULL, MRA_AVT_SECT_NAME, "WorkThreadsCount", MRA_AVT_DEFAULT_WRK_THREAD_COUNTS);
@@ -132,7 +130,7 @@ void CMraProto::MraAvatarsQueueDestroy(HANDLE hAvatarsQueueHandle)
MraAvatarsQueueClear(hAvatarsQueueHandle);
FifoMTDestroy(pmraaqAvatarsQueue);
- Netlib_CloseHandle(pmraaqAvatarsQueue->m_hNetlibUser);
+ Netlib_CloseHandle(pmraaqAvatarsQueue->hNetlibUser);
mir_free(pmraaqAvatarsQueue);
}
@@ -170,7 +168,7 @@ void CMraProto::MraAvatarsThreadProc(LPVOID lpParameter)
size_t dwAvatarSizeServer;
FILETIME ftLastModifiedTimeServer, ftLastModifiedTimeLocal;
SYSTEMTIME stAvatarLastModifiedTimeLocal;
- HANDLE m_hConnection = NULL;
+ HANDLE hConnection = NULL;
NETLIBSELECT nls = { 0 };
INTERNET_TIME itAvatarLastModifiedTimeServer;
PROTO_AVATAR_INFORMATIONT pai;
@@ -183,7 +181,7 @@ void CMraProto::MraAvatarsThreadProc(LPVOID lpParameter)
while (InterlockedExchangeAdd((volatile LONG*)&pmraaqAvatarsQueue->bIsRunning, 0)) {
if (FifoMTItemPop(pmraaqAvatarsQueue, NULL, (LPVOID*)&pmraaqiAvatarsQueueItem) != NO_ERROR) { // waiting until service stop or new task
- NETLIB_CLOSEHANDLE(m_hConnection);
+ NETLIB_CLOSEHANDLE(hConnection);
WaitForSingleObjectEx(pmraaqAvatarsQueue->hThreadEvent, MRA_AVT_DEFAULT_QE_CHK_INTERVAL, FALSE);
continue;
}
@@ -205,12 +203,12 @@ void CMraProto::MraAvatarsThreadProc(LPVOID lpParameter)
CMStringA szDomain = szEmail.Tokenize("@", iStart);
if (!szUser.IsEmpty() && !szDomain.IsEmpty()) {
ProtoBroadcastAck(pmraaqiAvatarsQueueItem->hContact, ACKTYPE_AVATAR, ACKRESULT_CONNECTING, NULL, 0);
- if (m_hConnection == NULL)
- m_hConnection = MraAvatarsHttpConnect(pmraaqAvatarsQueue->m_hNetlibUser, szServer, dwServerPort);
- if (m_hConnection) {
+ if (hConnection == NULL)
+ hConnection = MraAvatarsHttpConnect(pmraaqAvatarsQueue->hNetlibUser, szServer, dwServerPort);
+ if (hConnection) {
ProtoBroadcastAck(pmraaqiAvatarsQueueItem->hContact, ACKTYPE_AVATAR, ACKRESULT_CONNECTED, NULL, 0);
ProtoBroadcastAck(pmraaqiAvatarsQueueItem->hContact, ACKTYPE_AVATAR, ACKRESULT_SENTREQUEST, NULL, 0);
- if (!MraAvatarsHttpTransaction(m_hConnection, REQUEST_HEAD, szUser, szDomain, szServer, MAHTRO_AVTMRIM, bUseKeepAliveConn, &dwResultCode, &bKeepAlive, &dwAvatarFormat, &dwAvatarSizeServer, &itAvatarLastModifiedTimeServer)) {
+ if (!MraAvatarsHttpTransaction(hConnection, REQUEST_HEAD, szUser, szDomain, szServer, MAHTRO_AVTMRIM, bUseKeepAliveConn, &dwResultCode, &bKeepAlive, &dwAvatarFormat, &dwAvatarSizeServer, &itAvatarLastModifiedTimeServer)) {
switch (dwResultCode) {
case 200:
if (MraAvatarsGetContactTime(pmraaqiAvatarsQueueItem->hContact, "AvatarLastModifiedTime", &stAvatarLastModifiedTimeLocal)) {
@@ -253,16 +251,16 @@ void CMraProto::MraAvatarsThreadProc(LPVOID lpParameter)
break;
}
}
- if (bUseKeepAliveConn == FALSE || bKeepAlive == FALSE) NETLIB_CLOSEHANDLE(m_hConnection);
+ if (bUseKeepAliveConn == FALSE || bKeepAlive == FALSE) NETLIB_CLOSEHANDLE(hConnection);
}
if (bDownloadNew) {
- if (m_hConnection == NULL)
- m_hConnection = MraAvatarsHttpConnect(pmraaqAvatarsQueue->m_hNetlibUser, szServer, dwServerPort);
+ if (hConnection == NULL)
+ hConnection = MraAvatarsHttpConnect(pmraaqAvatarsQueue->hNetlibUser, szServer, dwServerPort);
- if (m_hConnection) {
+ if (hConnection) {
ProtoBroadcastAck(pmraaqiAvatarsQueueItem->hContact, ACKTYPE_AVATAR, ACKRESULT_DATA, NULL, 0);
- if (MraAvatarsHttpTransaction(m_hConnection, REQUEST_GET, szUser, szDomain, szServer, MAHTRO_AVT, bUseKeepAliveConn, &dwResultCode, &bKeepAlive, &dwAvatarFormat, &dwAvatarSizeServer, &itAvatarLastModifiedTimeServer) == NO_ERROR && dwResultCode == 200) {
+ if (MraAvatarsHttpTransaction(hConnection, REQUEST_GET, szUser, szDomain, szServer, MAHTRO_AVT, bUseKeepAliveConn, &dwResultCode, &bKeepAlive, &dwAvatarFormat, &dwAvatarSizeServer, &itAvatarLastModifiedTimeServer) == NO_ERROR && dwResultCode == 200) {
if (bDefaultAvt)
dwAvatarFormat = PA_FORMAT_DEFAULT;
@@ -272,7 +270,7 @@ void CMraProto::MraAvatarsThreadProc(LPVOID lpParameter)
DWORD dwWritten = 0;
bContinue = TRUE;
nls.dwTimeout = (1000 * db_get_dw(NULL, MRA_AVT_SECT_NAME, "TimeOutReceive", MRA_AVT_DEFAULT_TIMEOUT_RECV));
- nls.hReadConns[0] = m_hConnection;
+ nls.hReadConns[0] = hConnection;
while (bContinue) {
switch (CallService(MS_NETLIB_SELECT, 0, (LPARAM)&nls)) {
@@ -283,7 +281,7 @@ void CMraProto::MraAvatarsThreadProc(LPVOID lpParameter)
bContinue = FALSE;
break;
case 1:
- dwReceived = Netlib_Recv(m_hConnection, (LPSTR)&btBuff, SIZEOF(btBuff), 0);
+ dwReceived = Netlib_Recv(hConnection, (LPSTR)&btBuff, SIZEOF(btBuff), 0);
if (dwReceived == 0 || dwReceived == SOCKET_ERROR) {
dwErrorCode = GetLastError();
ShowFormattedErrorMessage(L"Avatars: error on receive file data", dwErrorCode);
@@ -316,7 +314,8 @@ void CMraProto::MraAvatarsThreadProc(LPVOID lpParameter)
}
else _CrtDbgBreak();
- if (bUseKeepAliveConn == FALSE || bKeepAlive == FALSE) NETLIB_CLOSEHANDLE(m_hConnection);
+ if (bUseKeepAliveConn == FALSE || bKeepAlive == FALSE)
+ NETLIB_CLOSEHANDLE(hConnection);
}
}
}
@@ -347,34 +346,34 @@ void CMraProto::MraAvatarsThreadProc(LPVOID lpParameter)
ProtoBroadcastAck(pmraaqiAvatarsQueueItem->hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)&pai, 0);
}
mir_free(pmraaqiAvatarsQueueItem);
- } /* while */
+ }
InterlockedDecrement((volatile LONG*)&pmraaqAvatarsQueue->lThreadsRunningCount);
}
-HANDLE MraAvatarsHttpConnect(HANDLE m_hNetlibUser, LPCSTR lpszHost, DWORD dwPort)
+HANDLE MraAvatarsHttpConnect(HANDLE hNetlibUser, LPCSTR lpszHost, DWORD dwPort)
{
NETLIBOPENCONNECTION nloc = { 0 };
nloc.cbSize = sizeof(nloc);
nloc.flags = (NLOCF_HTTP | NLOCF_V2);
nloc.szHost = lpszHost;
- nloc.wPort = (IsHTTPSProxyUsed(m_hNetlibUser)) ? MRA_SERVER_PORT_HTTPS : dwPort;
+ nloc.wPort = (IsHTTPSProxyUsed(hNetlibUser)) ? MRA_SERVER_PORT_HTTPS : dwPort;
nloc.timeout = db_get_dw(NULL, MRA_AVT_SECT_NAME, "TimeOutConnect", MRA_AVT_DEFAULT_TIMEOUT_CONN);
if (nloc.timeout < MRA_TIMEOUT_CONN_MIN) nloc.timeout = MRA_TIMEOUT_CONN_MIN;
if (nloc.timeout > MRA_TIMEOUT_CONN_MAX) nloc.timeout = MRA_TIMEOUT_CONN_MAX;
DWORD dwConnectReTryCount = db_get_dw(NULL, MRA_AVT_SECT_NAME, "ConnectReTryCount", MRA_AVT_DEFAULT_CONN_RETRY_COUNT);
DWORD dwCurConnectReTryCount = dwConnectReTryCount;
- HANDLE m_hConnection;
+ HANDLE hConnection;
do {
- m_hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc);
+ hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)hNetlibUser, (LPARAM)&nloc);
}
- while (--dwCurConnectReTryCount && m_hConnection == NULL);
+ while (--dwCurConnectReTryCount && hConnection == NULL);
- return m_hConnection;
+ return hConnection;
}
-DWORD MraAvatarsHttpTransaction(HANDLE m_hConnection, DWORD dwRequestType, LPCSTR lpszUser, LPCSTR lpszDomain, LPCSTR lpszHost, DWORD dwReqObj, BOOL bUseKeepAliveConn, DWORD *pdwResultCode, BOOL *pbKeepAlive, DWORD *pdwFormat, size_t *pdwAvatarSize, INTERNET_TIME *pitLastModifiedTime)
+DWORD MraAvatarsHttpTransaction(HANDLE hConnection, DWORD dwRequestType, LPCSTR lpszUser, LPCSTR lpszDomain, LPCSTR lpszHost, DWORD dwReqObj, BOOL bUseKeepAliveConn, DWORD *pdwResultCode, BOOL *pbKeepAlive, DWORD *pdwFormat, size_t *pdwAvatarSize, INTERNET_TIME *pitLastModifiedTime)
{
if (pdwResultCode) *pdwResultCode = 0;
if (pbKeepAlive) *pbKeepAlive = FALSE;
@@ -382,7 +381,7 @@ DWORD MraAvatarsHttpTransaction(HANDLE m_hConnection, DWORD dwRequestType, LPCST
if (pdwAvatarSize) *pdwAvatarSize = 0;
if (pitLastModifiedTime) memset(pitLastModifiedTime, 0, sizeof(INTERNET_TIME));
- if (!m_hConnection)
+ if (!hConnection)
return ERROR_INVALID_HANDLE;
LPSTR lpszReqObj;
@@ -413,11 +412,11 @@ DWORD MraAvatarsHttpTransaction(HANDLE m_hConnection, DWORD dwRequestType, LPCST
nlhr.headers = (NETLIBHTTPHEADER*)&nlbhHeaders;
nlhr.headersCount = 4;
- DWORD dwSent = CallService(MS_NETLIB_SENDHTTPREQUEST, (WPARAM)m_hConnection, (LPARAM)&nlhr);
+ DWORD dwSent = CallService(MS_NETLIB_SENDHTTPREQUEST, (WPARAM)hConnection, (LPARAM)&nlhr);
if (dwSent == SOCKET_ERROR || !dwSent)
return GetLastError();
- NETLIBHTTPREQUEST *pnlhr = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_RECVHTTPHEADERS, (WPARAM)m_hConnection, 0);
+ NETLIBHTTPREQUEST *pnlhr = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_RECVHTTPHEADERS, (WPARAM)hConnection, 0);
if (!pnlhr)
return GetLastError();
diff --git a/protocols/MRA/src/MraFilesQueue.cpp b/protocols/MRA/src/MraFilesQueue.cpp
index 418f5cf060..eaca08cc52 100644
--- a/protocols/MRA/src/MraFilesQueue.cpp
+++ b/protocols/MRA/src/MraFilesQueue.cpp
@@ -37,7 +37,7 @@ struct MRA_FILES_QUEUE_ITEM : public LIST_MT_ITEM
LPWSTR lpwszPath;
size_t dwPathSize;
bool bSending;
- HANDLE m_hConnection;
+ HANDLE hConnection;
HANDLE hListen;
HANDLE hThread;
HANDLE hWaitHandle;
@@ -314,11 +314,8 @@ DWORD CMraProto::MraFilesQueueCancel(HANDLE hFilesQueueHandle, DWORD dwIDRequest
MraMrimProxyCloseConnection(dat->hMraMrimProxyData);
- Netlib_CloseHandle(dat->hListen);
- dat->hListen = NULL;
-
- Netlib_CloseHandle(dat->m_hConnection);
- dat->m_hConnection = NULL;
+ NETLIB_CLOSEHANDLE(dat->hListen);
+ NETLIB_CLOSEHANDLE(dat->hConnection);
SetEvent(dat->hWaitHandle);
@@ -381,15 +378,15 @@ DWORD CMraProto::MraFilesQueueSendMirror(HANDLE hFilesQueueHandle, DWORD dwIDReq
MraAddrListGetFromBuff(szAddresses, &dat->malAddrList);
MraAddrListStoreToContact(dat->hContact, &dat->malAddrList);
- dat->m_hConnection = NULL;
+ dat->hConnection = NULL;
SetEvent(dat->hWaitHandle);
}
return dwRetErrorCode;
}
-bool CMraProto::MraFilesQueueHandCheck(HANDLE m_hConnection, MRA_FILES_QUEUE_ITEM *dat)
+bool CMraProto::MraFilesQueueHandCheck(HANDLE hConnection, MRA_FILES_QUEUE_ITEM *dat)
{
- if (m_hConnection && dat) {
+ if (hConnection && dat) {
BYTE btBuff[((MAX_EMAIL_LEN * 2) + (sizeof(MRA_FT_HELLO)* 2) + 8)] = { 0 };
size_t dwBuffSize;
@@ -400,10 +397,10 @@ bool CMraProto::MraFilesQueueHandCheck(HANDLE m_hConnection, MRA_FILES_QUEUE_ITE
if (dat->bSending == FALSE) {
// receiving
dwBuffSize = mir_snprintf((LPSTR)btBuff, SIZEOF(btBuff), "%s %s", MRA_FT_HELLO, szEmailMy.c_str()) + 1;
- if (dwBuffSize == Netlib_Send(m_hConnection, (LPSTR)btBuff, (int)dwBuffSize, 0)) {
+ if (dwBuffSize == Netlib_Send(hConnection, (LPSTR)btBuff, (int)dwBuffSize, 0)) {
// my email sended
ProtoBroadcastAck(dat->hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, (HANDLE)dat->dwIDRequest, 0);
- dwBuffSize = Netlib_Recv(m_hConnection, (LPSTR)btBuff, sizeof(btBuff), 0);
+ dwBuffSize = Netlib_Recv(hConnection, (LPSTR)btBuff, sizeof(btBuff), 0);
if ((szEmail.GetLength() + sizeof(MRA_FT_HELLO)+1) == dwBuffSize) {
// email received
mir_snprintf(((LPSTR)btBuff + dwBuffSize), (SIZEOF(btBuff) - dwBuffSize), "%s %s", MRA_FT_HELLO, szEmail);
@@ -413,7 +410,7 @@ bool CMraProto::MraFilesQueueHandCheck(HANDLE m_hConnection, MRA_FILES_QUEUE_ITE
}
}
else {// sending
- dwBuffSize = Netlib_Recv(m_hConnection, (LPSTR)btBuff, sizeof(btBuff), 0);
+ dwBuffSize = Netlib_Recv(hConnection, (LPSTR)btBuff, sizeof(btBuff), 0);
if ((szEmail.GetLength() + sizeof(MRA_FT_HELLO)+1) == dwBuffSize) {
// email received
ProtoBroadcastAck(dat->hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, (HANDLE)dat->dwIDRequest, 0);
@@ -421,7 +418,7 @@ bool CMraProto::MraFilesQueueHandCheck(HANDLE m_hConnection, MRA_FILES_QUEUE_ITE
if (!_memicmp(btBuff, btBuff + dwBuffSize, dwBuffSize)) {
// email verified
dwBuffSize = (mir_snprintf((LPSTR)btBuff, SIZEOF(btBuff), "%s %s", MRA_FT_HELLO, szEmailMy.c_str()) + 1);
- if (dwBuffSize == Netlib_Send(m_hConnection, (LPSTR)btBuff, dwBuffSize, 0))
+ if (dwBuffSize == Netlib_Send(hConnection, (LPSTR)btBuff, dwBuffSize, 0))
return true;
}
}
@@ -460,7 +457,7 @@ HANDLE CMraProto::MraFilesQueueConnectOut(MRA_FILES_QUEUE_ITEM *dat)
dwAddrCount = dat->malAddrList.dwAddrCount;
if (dwAddrCount) {
- dat->m_hConnection = NULL;
+ dat->hConnection = NULL;
dwConnectReTryCount = getDword("ConnectReTryCountFileSend", MRA_DEFAULT_CONN_RETRY_COUNT_FILES);
nloc.cbSize = sizeof(nloc);
nloc.flags = NLOCF_V2;
@@ -478,29 +475,26 @@ HANDLE CMraProto::MraFilesQueueConnectOut(MRA_FILES_QUEUE_ITEM *dat)
dwCurConnectReTryCount = dwConnectReTryCount;
do {
- dat->m_hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc);
+ dat->hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc);
}
- while (--dwCurConnectReTryCount && dat->m_hConnection == NULL);
+ while (--dwCurConnectReTryCount && dat->hConnection == NULL);
- if (dat->m_hConnection) {
+ if (dat->hConnection) {
ProtoBroadcastAck(dat->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTED, (HANDLE)dat->dwIDRequest, 0);
- if (MraFilesQueueHandCheck(dat->m_hConnection, dat)) {
+ if (MraFilesQueueHandCheck(dat->hConnection, dat)) {
// связь установленная с тем кем нужно
setDword(dat->hContact, "OldIP", getDword(dat->hContact, "IP", 0));
setDword(dat->hContact, "IP", ntohl(dat->malAddrList.pMailAddress[i].dwAddr));
break;
}
- else {
- // кажется не туда подключились :)
- Netlib_CloseHandle(dat->m_hConnection);
- dat->m_hConnection = NULL;
- }
+ else // кажется не туда подключились :)
+ NETLIB_CLOSEHANDLE(dat->hConnection);
}
}
}
}
}
- return dat->m_hConnection;
+ return dat->hConnection;
}
LPWSTR GetFileNameFromFullPathW(LPWSTR lpwszFullPath, size_t dwFullPathSize)
@@ -593,7 +587,7 @@ HANDLE CMraProto::MraFilesQueueConnectIn(MRA_FILES_QUEUE_ITEM *dat)
dat->hWaitHandle = NULL;
}
}
- return dat->m_hConnection;
+ return dat->hConnection;
}
// This function is called from the Netlib when someone is connecting to
@@ -605,7 +599,7 @@ void MraFilesQueueConnectionReceived(HANDLE hNewConnection, DWORD dwRemoteIP, vo
ProtoBroadcastAck(dat->ppro->m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTED, (HANDLE)dat->dwIDRequest, 0);
if (dat->ppro->MraFilesQueueHandCheck(hNewConnection, dat)) { // связь установленная с тем кем нужно
- dat->m_hConnection = hNewConnection;
+ dat->hConnection = hNewConnection;
ProtoBroadcastAck(dat->ppro->m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTED, (HANDLE)dat->dwIDRequest, 0);
dat->ppro->setDword(dat->hContact, "OldIP", dat->ppro->getDword(dat->hContact, "IP", 0));
dat->ppro->setDword(dat->hContact, "IP", dwRemoteIP);
@@ -763,8 +757,8 @@ void CMraProto::MraFilesQueueRecvThreadProc(LPVOID lpParameter)
else {
if (InterlockedExchangeAdd((volatile LONG*)&dat->bIsWorking, 0)) {
ProtoBroadcastAck(dat->hContact, ACKRESULT_CONNECTPROXY, ACKRESULT_CONNECTED, (HANDLE)dat->dwIDRequest, 0);
- if (MraMrimProxyConnect(dat->hMraMrimProxyData, &dat->m_hConnection) == NO_ERROR) {// подключились к прокси, проверяем та ли сессия (ещё раз, на этот раз сами)
- if (MraFilesQueueHandCheck(dat->m_hConnection, dat)) {// связь установленная с тем кем нужно// dat->bSending
+ if (MraMrimProxyConnect(dat->hMraMrimProxyData, &dat->hConnection) == NO_ERROR) {// подключились к прокси, проверяем та ли сессия (ещё раз, на этот раз сами)
+ if (MraFilesQueueHandCheck(dat->hConnection, dat)) {// связь установленная с тем кем нужно// dat->bSending
ProtoBroadcastAck(dat->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTED, (HANDLE)dat->dwIDRequest, 0);
bConnected = TRUE;
}
@@ -806,7 +800,7 @@ void CMraProto::MraFilesQueueRecvThreadProc(LPVOID lpParameter)
btBuff[dwBuffSizeUsed] = 0;
dwBuffSizeUsed++;
- if (dwBuffSizeUsed == Netlib_Send(dat->m_hConnection, (LPSTR)btBuff, dwBuffSizeUsed, 0)) {// file request sended
+ if (dwBuffSizeUsed == Netlib_Send(dat->hConnection, (LPSTR)btBuff, dwBuffSizeUsed, 0)) {// file request sended
hFile = CreateFileW(wszFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE) {// file opened/created, pre allocating disk space, for best perfomance
bOK = FALSE;
@@ -823,7 +817,7 @@ void CMraProto::MraFilesQueueRecvThreadProc(LPVOID lpParameter)
bContinue = TRUE;
dwUpdateTimeNext = GetTickCount();
nls.dwTimeout = (1000 * getDword("TimeOutReceiveFileData", MRA_DEF_FS_TIMEOUT_RECV));
- nls.hReadConns[0] = dat->m_hConnection;
+ nls.hReadConns[0] = dat->hConnection;
ProtoBroadcastAck(dat->hContact, ACKTYPE_FILE, ACKRESULT_DATA, (HANDLE)dat->dwIDRequest, (LPARAM)&pfts);
while (bContinue) {
@@ -835,7 +829,7 @@ void CMraProto::MraFilesQueueRecvThreadProc(LPVOID lpParameter)
bContinue = FALSE;
break;
case 1:
- dwReceived = Netlib_Recv(dat->m_hConnection, (LPSTR)&btBuff, SIZEOF(btBuff), 0);
+ dwReceived = Netlib_Recv(dat->hConnection, (LPSTR)&btBuff, SIZEOF(btBuff), 0);
if (dwReceived == 0 || dwReceived == SOCKET_ERROR) {
dwRetErrorCode = GetLastError();
ShowFormattedErrorMessage(L"Receive files: error on receive file data", dwRetErrorCode);
@@ -898,8 +892,7 @@ void CMraProto::MraFilesQueueRecvThreadProc(LPVOID lpParameter)
}
}// end for
- Netlib_CloseHandle(dat->m_hConnection);
- dat->m_hConnection = NULL;
+ NETLIB_CLOSEHANDLE(dat->hConnection);
}
if (bFailed) {
@@ -1010,9 +1003,9 @@ void CMraProto::MraFilesQueueSendThreadProc(LPVOID lpParameter)
else {
if (InterlockedExchangeAdd((volatile LONG*)&dat->bIsWorking, 0)) {
ProtoBroadcastAck(dat->hContact, ACKRESULT_CONNECTPROXY, ACKRESULT_CONNECTED, (HANDLE)dat->dwIDRequest, 0);
- if (MraMrimProxyConnect(dat->hMraMrimProxyData, &dat->m_hConnection) == NO_ERROR) {
+ if (MraMrimProxyConnect(dat->hMraMrimProxyData, &dat->hConnection) == NO_ERROR) {
// подключились к прокси, проверяем та ли сессия (ещё раз, на этот раз сами)
- if (MraFilesQueueHandCheck(dat->m_hConnection, dat)) {
+ if (MraFilesQueueHandCheck(dat->hConnection, dat)) {
// связь установленная с тем кем нужно// dat->bSending
ProtoBroadcastAck(dat->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTED, (HANDLE)dat->dwIDRequest, 0);
bConnected = TRUE;
@@ -1028,7 +1021,7 @@ void CMraProto::MraFilesQueueSendThreadProc(LPVOID lpParameter)
dwBuffSizeUsed = 0;
while (TRUE) {
- dwReceived = Netlib_Recv(dat->m_hConnection, ((LPSTR)btBuff + dwBuffSizeUsed), (SIZEOF(btBuff) - dwBuffSizeUsed), 0);
+ dwReceived = Netlib_Recv(dat->hConnection, ((LPSTR)btBuff + dwBuffSizeUsed), (SIZEOF(btBuff) - dwBuffSizeUsed), 0);
if (dwReceived == 0 || dwReceived == SOCKET_ERROR) { // err on receive file name to send
dwRetErrorCode = GetLastError();
ShowFormattedErrorMessage(L"Send files: file send request not received, error", dwRetErrorCode);
@@ -1076,7 +1069,7 @@ void CMraProto::MraFilesQueueSendThreadProc(LPVOID lpParameter)
while (TRUE) { // read and sending
if (ReadFile(hFile, btBuff, dwSendBlockSize, (DWORD*)&dwBuffSizeUsed, NULL)) {
- dwReceived = Netlib_Send(dat->m_hConnection, (LPSTR)btBuff, dwBuffSizeUsed, 0);
+ dwReceived = Netlib_Send(dat->hConnection, (LPSTR)btBuff, dwBuffSizeUsed, 0);
if (dwBuffSizeUsed == dwReceived) {
pfts.currentFileProgress += dwBuffSizeUsed;
pfts.totalProgress += dwBuffSizeUsed;
@@ -1141,8 +1134,7 @@ void CMraProto::MraFilesQueueSendThreadProc(LPVOID lpParameter)
}
}// end for
- Netlib_CloseHandle(dat->m_hConnection);
- dat->m_hConnection = NULL;
+ NETLIB_CLOSEHANDLE(dat->hConnection);
}
if (bFailed) {
diff --git a/protocols/MRA/src/MraMRIMProxy.cpp b/protocols/MRA/src/MraMRIMProxy.cpp
index a285696590..689c560cb5 100644
--- a/protocols/MRA/src/MraMRIMProxy.cpp
+++ b/protocols/MRA/src/MraMRIMProxy.cpp
@@ -4,15 +4,15 @@
struct MRA_MRIMPROXY_DATA
{
- LPSTR szEmail; // LPS to
- DWORD dwIDRequest; // DWORD id_request
- DWORD dwDataType; // DWORD data_type
- LPSTR lpszUserData; // LPS user_data
- size_t dwUserDataSize;
- MRA_ADDR_LIST malAddrList; // LPS lps_ip_port
- MRA_GUID mguidSessionID; // DWORD session_id[4]
- HANDLE m_hConnection;
- HANDLE hWaitHandle; // internal
+ LPSTR szEmail; // LPS to
+ DWORD dwIDRequest; // DWORD id_request
+ DWORD dwDataType; // DWORD data_type
+ LPSTR lpszUserData; // LPS user_data
+ size_t dwUserDataSize;
+ MRA_ADDR_LIST malAddrList; // LPS lps_ip_port
+ MRA_GUID mguidSessionID; // DWORD session_id[4]
+ HANDLE hConnection;
+ HANDLE hWaitHandle; // internal
};
HANDLE MraMrimProxyCreate()
@@ -52,7 +52,7 @@ void MraMrimProxyFree(HANDLE hMraMrimProxyData)
MRA_MRIMPROXY_DATA *pmmpd = (MRA_MRIMPROXY_DATA*)hMraMrimProxyData;
CloseHandle(pmmpd->hWaitHandle);
- Netlib_CloseHandle(pmmpd->m_hConnection);
+ Netlib_CloseHandle(pmmpd->hConnection);
mir_free(pmmpd->szEmail);
mir_free(pmmpd->lpszUserData);
MraAddrListFree(&pmmpd->malAddrList);
@@ -65,7 +65,7 @@ void MraMrimProxyCloseConnection(HANDLE hMraMrimProxyData)
if (hMraMrimProxyData) {
MRA_MRIMPROXY_DATA *pmmpd = (MRA_MRIMPROXY_DATA*)hMraMrimProxyData;
SetEvent(pmmpd->hWaitHandle);
- Netlib_CloseHandle(pmmpd->m_hConnection);
+ NETLIB_CLOSEHANDLE(pmmpd->hConnection);
}
}
@@ -100,7 +100,7 @@ DWORD CMraProto::MraMrimProxyConnect(HANDLE hMraMrimProxyData, HANDLE *phConnect
dwRetErrorCode = ERROR_NO_NETWORK;
if (pmmpd->malAddrList.dwAddrCount) {
- pmmpd->m_hConnection = NULL;
+ pmmpd->hConnection = NULL;
bIsHTTPSProxyUsed = IsHTTPSProxyUsed(m_hNetlibUser);
dwConnectReTryCount = getDword("ConnectReTryCountMRIMProxy", MRA_DEFAULT_CONN_RETRY_COUNT_MRIMPROXY);
nloc.cbSize = sizeof(nloc);
@@ -121,14 +121,14 @@ DWORD CMraProto::MraMrimProxyConnect(HANDLE hMraMrimProxyData, HANDLE *phConnect
dwCurConnectReTryCount = dwConnectReTryCount;
do {
- pmmpd->m_hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc);
+ pmmpd->hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc);
}
- while (--dwCurConnectReTryCount && pmmpd->m_hConnection == NULL);
+ while (--dwCurConnectReTryCount && pmmpd->hConnection == NULL);
- if (pmmpd->m_hConnection) {
+ if (pmmpd->hConnection) {
nls.cbSize = sizeof(nls);
nls.dwTimeout = (MRA_TIMEOUT_DIRECT_CONN*1000*2);
- nls.hReadConns[0] = pmmpd->m_hConnection;
+ nls.hReadConns[0] = pmmpd->hConnection;
bContinue = TRUE;
dwRcvBuffSizeUsed = 0;
@@ -190,12 +190,10 @@ DWORD CMraProto::MraMrimProxyConnect(HANDLE hMraMrimProxyData, HANDLE *phConnect
}// filtered
}// end for
- if (dwRetErrorCode != NO_ERROR) { // кажется не туда подключились :)
- Netlib_CloseHandle(pmmpd->m_hConnection);
- pmmpd->m_hConnection = NULL;
- }
+ if (dwRetErrorCode != NO_ERROR) // кажется не туда подключились :)
+ NETLIB_CLOSEHANDLE(pmmpd->hConnection);
}
- *phConnection = pmmpd->m_hConnection;
+ *phConnection = pmmpd->hConnection;
}
else dwRetErrorCode = ERROR_INVALID_HANDLE;
return dwRetErrorCode;
diff --git a/protocols/MRA/src/MraProto.cpp b/protocols/MRA/src/MraProto.cpp
index 6491f7e6a7..1733019ddc 100644
--- a/protocols/MRA/src/MraProto.cpp
+++ b/protocols/MRA/src/MraProto.cpp
@@ -512,7 +512,7 @@ int CMraProto::SetStatus(int iNewStatus)
for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
SetContactBasicInfoW(hContact, SCBIFSI_LOCK_CHANGES_EVENTS, (SCBIF_ID|SCBIF_GROUP_ID|SCBIF_SERVER_FLAG|SCBIF_STATUS), -1, -1, 0, 0, ID_STATUS_OFFLINE, 0, 0, 0);
- Netlib_CloseHandle(m_hConnection);
+ NETLIB_CLOSEHANDLE(m_hConnection);
}
else {
// если offline то сразу ставим connecting, но обработка как offline
diff --git a/protocols/MRA/src/MraProto.h b/protocols/MRA/src/MraProto.h
index 7ef6c92490..39b193b185 100644
--- a/protocols/MRA/src/MraProto.h
+++ b/protocols/MRA/src/MraProto.h
@@ -173,8 +173,8 @@ struct CMraProto : public PROTO<CMraProto>
HANDLE m_heNudgeReceived;
HANDLE m_hConnection;
- DWORD m_dwNextPingSendTickTime;
- DWORD m_dwPingPeriod;
+ DWORD m_dwNextPingSendTickTime;
+ DWORD m_dwPingPeriod;
volatile DWORD m_dwThreadWorkerLastPingTime;
volatile DWORD m_dwThreadWorkerRunning;
volatile DWORD dwCMDNum;
@@ -220,7 +220,7 @@ struct CMraProto : public PROTO<CMraProto>
DWORD MraProxyAck(DWORD dwStatus, const CMStringA &szEmail, DWORD dwIDRequest, DWORD dwDataType, const CMStringA &lpszData, const CMStringA &szAddresses, MRA_GUID mguidSessionID);
DWORD MraChangeUserBlogStatus(DWORD dwFlags, const CMStringW &wszText, DWORDLONG dwBlogStatusID);
- DWORD MraSendPacket(HANDLE m_hConnection, DWORD dwCMDNum, DWORD dwType, LPVOID lpData, size_t dwDataSize);
+ DWORD MraSendPacket(HANDLE hConnection, DWORD dwCMDNum, DWORD dwType, LPVOID lpData, size_t dwDataSize);
DWORD MraSendCMD(DWORD dwType, LPVOID lpData, size_t dwDataSize);
DWORD MraSendQueueCMD(HANDLE hSendQueueHandle, DWORD dwFlags, MCONTACT hContact, DWORD dwAckType, LPBYTE lpbDataQueue, size_t dwDataQueueSize, DWORD dwType, LPVOID lpData, size_t dwDataSize);
@@ -307,7 +307,7 @@ struct CMraProto : public PROTO<CMraProto>
DWORD MraFilesQueueCancel(HANDLE hFilesQueueHandle, DWORD dwIDRequest, BOOL bSendDecline);
DWORD MraFilesQueueStartMrimProxy(HANDLE hFilesQueueHandle, DWORD dwIDRequest);
DWORD MraFilesQueueSendMirror(HANDLE hFilesQueueHandle, DWORD dwIDRequest, const CMStringA &szAddresses);
- bool MraFilesQueueHandCheck(HANDLE m_hConnection, MRA_FILES_QUEUE_ITEM *pmrafqFilesQueueItem);
+ bool MraFilesQueueHandCheck(HANDLE hConnection, MRA_FILES_QUEUE_ITEM *pmrafqFilesQueueItem);
HANDLE MraFilesQueueConnectOut(MRA_FILES_QUEUE_ITEM *pmrafqFilesQueueItem);
HANDLE MraFilesQueueConnectIn(MRA_FILES_QUEUE_ITEM *pmrafqFilesQueueItem);
DWORD MraFilesQueueAccept(HANDLE hFilesQueueHandle, DWORD dwIDRequest, LPCWSTR lpwszPath, size_t dwPathSize);
diff --git a/protocols/MRA/src/MraSendCommand.cpp b/protocols/MRA/src/MraSendCommand.cpp
index 8d5d5d47de..220d9a2c96 100644
--- a/protocols/MRA/src/MraSendCommand.cpp
+++ b/protocols/MRA/src/MraSendCommand.cpp
@@ -499,7 +499,7 @@ DWORD CMraProto::MraChangeUserBlogStatus(DWORD dwFlags, const CMStringW &wszText
return MraSendCMD(MRIM_CS_CHANGE_USER_BLOG_STATUS, buf.Data(), buf.Len());
}
-DWORD CMraProto::MraSendPacket(HANDLE m_hConnection, DWORD dwCMDNum, DWORD dwType, LPVOID lpData, size_t dwDataSize)
+DWORD CMraProto::MraSendPacket(HANDLE hConnection, DWORD dwCMDNum, DWORD dwType, LPVOID lpData, size_t dwDataSize)
{
LPBYTE lpbData = (LPBYTE)_alloca(dwDataSize + sizeof(mrim_packet_header_t));
@@ -514,7 +514,7 @@ DWORD CMraProto::MraSendPacket(HANDLE m_hConnection, DWORD dwCMDNum, DWORD dwTyp
debugLogA("Sending packet %08x\n", dwType);
memcpy((lpbData + sizeof(mrim_packet_header_t)), lpData, dwDataSize);
- return Netlib_Send(m_hConnection, (LPSTR)lpbData, (dwDataSize + sizeof(mrim_packet_header_t)), 0);
+ return Netlib_Send(hConnection, (LPSTR)lpbData, (dwDataSize + sizeof(mrim_packet_header_t)), 0);
}
DWORD CMraProto::MraSendCMD(DWORD dwType, LPVOID lpData, size_t dwDataSize)
diff --git a/protocols/MRA/src/Mra_functions.cpp b/protocols/MRA/src/Mra_functions.cpp
index 7e08b7f918..9a44569713 100644
--- a/protocols/MRA/src/Mra_functions.cpp
+++ b/protocols/MRA/src/Mra_functions.cpp
@@ -697,10 +697,10 @@ void CMraProto::MraUpdateEmailStatus(const CMStringA &pszFrom, const CMStringA &
}
}
-bool IsHTTPSProxyUsed(HANDLE m_hNetlibUser)
+bool IsHTTPSProxyUsed(HANDLE hNetlibUser)
{
NETLIBUSERSETTINGS nlus = { sizeof(nlus) };
- if (CallService(MS_NETLIB_GETUSERSETTINGS, (WPARAM)m_hNetlibUser, (LPARAM)&nlus))
+ if (CallService(MS_NETLIB_GETUSERSETTINGS, (WPARAM)hNetlibUser, (LPARAM)&nlus))
if (nlus.useProxy && nlus.proxyType == PROXYTYPE_HTTPS)
return true;
diff --git a/protocols/MRA/src/Mra_proto.cpp b/protocols/MRA/src/Mra_proto.cpp
index 1d7d523140..1f189c83a5 100644
--- a/protocols/MRA/src/Mra_proto.cpp
+++ b/protocols/MRA/src/Mra_proto.cpp
@@ -83,7 +83,7 @@ void CMraProto::MraThreadProc(LPVOID lpParameter)
InterlockedExchange((volatile LONG*)&m_dwThreadWorkerLastPingTime, GetTickCount());
m_hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc);
}
- while (--dwCurConnectReTryCount && m_hConnection == NULL);
+ while (--dwCurConnectReTryCount && m_hConnection == NULL);
if (m_hConnection) {
bConnected = TRUE;
@@ -102,8 +102,7 @@ void CMraProto::MraThreadProc(LPVOID lpParameter)
}
MraMPopSessionQueueFlush(hMPopSessionQueue);
- Netlib_CloseHandle(m_hConnection);// called twice, if user set offline, its normal
- m_hConnection = NULL;
+ NETLIB_CLOSEHANDLE(m_hConnection);
dwCMDNum = 0;
InterlockedExchange((volatile LONG*)&m_dwThreadWorkerRunning, FALSE);
@@ -145,7 +144,7 @@ DWORD CMraProto::MraGetNLBData(CMStringA &szHost, WORD *pwPort)
InterlockedExchange((volatile LONG*)&m_dwThreadWorkerLastPingTime, GetTickCount());
nls.hReadConns[0] = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc);
}
- while (--dwCurConnectReTryCount && nls.hReadConns[0] == NULL);
+ while (--dwCurConnectReTryCount && nls.hReadConns[0] == NULL);
if (nls.hReadConns[0]) {
nls.cbSize = sizeof(nls);