summaryrefslogtreecommitdiff
path: root/protocols/MRA/src/MraFilesQueue.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-09-01 19:08:53 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-09-01 19:08:53 +0000
commit84567ddcd9ff730cdcb7815b6ba0007d693cd52b (patch)
tree3ee57fc2ac744c030e86df86fcf56aaa8845938b /protocols/MRA/src/MraFilesQueue.cpp
parent856648d8c6f14c7d57aba610588f52c79ec18987 (diff)
VERY EXPERIMENTAL VERSION OF MEA, DON'T USE IN PRODUCTION
git-svn-id: http://svn.miranda-ng.org/main/trunk@5897 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/MRA/src/MraFilesQueue.cpp')
-rw-r--r--protocols/MRA/src/MraFilesQueue.cpp225
1 files changed, 102 insertions, 123 deletions
diff --git a/protocols/MRA/src/MraFilesQueue.cpp b/protocols/MRA/src/MraFilesQueue.cpp
index 7e61679761..aa0c907ae2 100644
--- a/protocols/MRA/src/MraFilesQueue.cpp
+++ b/protocols/MRA/src/MraFilesQueue.cpp
@@ -20,7 +20,7 @@ struct MRA_FILES_QUEUE_FILE
struct MRA_FILES_QUEUE_ITEM : public LIST_MT_ITEM
{
// internal
- BOOL bIsWorking;
+ bool bIsWorking;
DWORD dwSendTime;
// external
@@ -36,8 +36,8 @@ struct MRA_FILES_QUEUE_ITEM : public LIST_MT_ITEM
MRA_ADDR_LIST malAddrList;
LPWSTR lpwszPath;
size_t dwPathSize;
- BOOL bSending;
- HANDLE hConnection;
+ bool bSending;
+ HANDLE m_hConnection;
HANDLE hListen;
HANDLE hThread;
HANDLE hWaitHandle;
@@ -81,7 +81,6 @@ INT_PTR CALLBACK MraFilesQueueDlgProcOpts(HWND hWndDlg, UINT msg, WPARAM wParam,
SetWindowLongPtr(hWndDlg, GWLP_USERDATA, lParam);
ppro = (CMraProto*)lParam;
{
- WCHAR szBuff[MAX_PATH];
CHECK_DLG_BUTTON(hWndDlg, IDC_FILE_SEND_ENABLE_DIRECT_CONN, ppro->getByte("FileSendEnableDirectConn", MRA_DEF_FS_ENABLE_DIRECT_CONN));
CHECK_DLG_BUTTON(hWndDlg, IDC_FILE_SEND_NOOUTCONNECTIONONRECEIVE, ppro->getByte("FileSendNoOutConnOnRcv", MRA_DEF_FS_NO_OUT_CONN_ON_RCV));
CHECK_DLG_BUTTON(hWndDlg, IDC_FILE_SEND_NOOUTCONNECTIONONSEND, ppro->getByte("FileSendNoOutConnOnSend", MRA_DEF_FS_NO_OUT_CONN_ON_SEND));
@@ -89,8 +88,9 @@ INT_PTR CALLBACK MraFilesQueueDlgProcOpts(HWND hWndDlg, UINT msg, WPARAM wParam,
CHECK_DLG_BUTTON(hWndDlg, IDC_FILE_SEND_HIDE_MY_ADDRESSES, ppro->getByte("FileSendHideMyAddresses", MRA_DEF_FS_HIDE_MY_ADDRESSES));
CHECK_DLG_BUTTON(hWndDlg, IDC_FILE_SEND_ADD_EXTRA_ADDRESS, ppro->getByte("FileSendAddExtraAddresses", MRA_DEF_FS_ADD_EXTRA_ADDRESSES));
- if (ppro->mraGetStaticStringW(NULL, "FileSendExtraAddresses", szBuff, SIZEOF(szBuff), NULL))
- SET_DLG_ITEM_TEXT(hWndDlg, IDC_FILE_SEND_EXTRA_ADDRESS, szBuff);
+ CMStringW szBuff;
+ if (ppro->mraGetStringW(NULL, "FileSendExtraAddresses", szBuff))
+ SET_DLG_ITEM_TEXT(hWndDlg, IDC_FILE_SEND_EXTRA_ADDRESS, szBuff.c_str());
CHECK_DLG_BUTTON(hWndDlg, IDC_FILE_SEND_ENABLE_MRIMPROXY_CONS, ppro->getByte("FileSendEnableMRIMProxyCons", MRA_DEF_FS_ENABLE_MRIM_PROXY_CONS));
@@ -228,7 +228,6 @@ void MraFilesQueueItemFree(MRA_FILES_QUEUE_ITEM *dat)
size_t CMraProto::MraFilesQueueGetLocalAddressesList(LPSTR lpszBuff, size_t dwBuffSize, DWORD dwPort)
{
- CHAR szHostName[MAX_PATH] = {0};
LPSTR lpszCurPos = lpszBuff;
if (getByte("FileSendHideMyAddresses", MRA_DEF_FS_HIDE_MY_ADDRESSES))
@@ -250,6 +249,7 @@ size_t CMraProto::MraFilesQueueGetLocalAddressesList(LPSTR lpszBuff, size_t dwBu
lpszCurPos += mir_snprintf(lpszCurPos, (dwBuffSize-((size_t)lpszCurPos-(size_t)lpszBuff)), "%lu.%lu.%lu.%lu:%lu;", btAddress[0], btAddress[1], btAddress[2], btAddress[3], dwPort);
}
+ CHAR szHostName[MAX_PATH] = {0};
if (gethostname(szHostName, SIZEOF(szHostName)) == 0)
if ((sh = gethostbyname((LPSTR)&szHostName))) {
while (sh->h_addr_list[dwAdapter]) {
@@ -259,9 +259,10 @@ size_t CMraProto::MraFilesQueueGetLocalAddressesList(LPSTR lpszBuff, size_t dwBu
}
}
+ CMStringA szHostName;
if (getByte("FileSendAddExtraAddresses", MRA_DEF_FS_ADD_EXTRA_ADDRESSES))// добавляем произвольный адрес
- if (mraGetStaticStringA(NULL, "FileSendExtraAddresses", szHostName, SIZEOF(szHostName), NULL))
- lpszCurPos += mir_snprintf(lpszCurPos, (dwBuffSize-((size_t)lpszCurPos-(size_t)lpszBuff)), "%s:%lu;", szHostName, dwPort);
+ if (mraGetStringA(NULL, "FileSendExtraAddresses", szHostName))
+ lpszCurPos += mir_snprintf(lpszCurPos, (dwBuffSize-((size_t)lpszCurPos-(size_t)lpszBuff)), "%s:%lu;", szHostName.c_str(), dwPort);
return lpszCurPos - lpszBuff;
}
@@ -311,11 +312,9 @@ DWORD CMraProto::MraFilesQueueCancel(HANDLE hFilesQueueHandle, DWORD dwIDRequest
InterlockedExchange((volatile LONG*)&dat->bIsWorking, FALSE);
if (bSendDecline) {
- CHAR szEMail[MAX_EMAIL_LEN];
- size_t dwEMailSize;
-
- if (mraGetStaticStringA(dat->hContact, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize))
- MraFileTransferAck(FILE_TRANSFER_STATUS_DECLINE, szEMail, dwEMailSize, dwIDRequest, NULL, 0);
+ CMStringA szEmail;
+ if (mraGetStringA(dat->hContact, "e-mail", szEmail))
+ MraFileTransferAck(FILE_TRANSFER_STATUS_DECLINE, szEmail, dwIDRequest, NULL, 0);
}
MraMrimProxyCloseConnection(dat->hMraMrimProxyData);
@@ -323,8 +322,8 @@ DWORD CMraProto::MraFilesQueueCancel(HANDLE hFilesQueueHandle, DWORD dwIDRequest
Netlib_CloseHandle(dat->hListen);
dat->hListen = NULL;
- Netlib_CloseHandle(dat->hConnection);
- dat->hConnection = NULL;
+ Netlib_CloseHandle(dat->m_hConnection);
+ dat->m_hConnection = NULL;
SetEvent(dat->hWaitHandle);
@@ -373,7 +372,7 @@ DWORD MraFilesQueueFree(HANDLE hFilesQueueHandle, DWORD dwIDRequest)
return ERROR_NOT_FOUND;
}
-DWORD CMraProto::MraFilesQueueSendMirror(HANDLE hFilesQueueHandle, DWORD dwIDRequest, LPSTR lpszAddreses, size_t dwAddresesSize)
+DWORD CMraProto::MraFilesQueueSendMirror(HANDLE hFilesQueueHandle, DWORD dwIDRequest, const CMStringA &szAddresses)
{
if (!hFilesQueueHandle)
return ERROR_INVALID_HANDLE;
@@ -384,60 +383,56 @@ DWORD CMraProto::MraFilesQueueSendMirror(HANDLE hFilesQueueHandle, DWORD dwIDReq
mt_lock l(pmrafqFilesQueue);
DWORD dwRetErrorCode = MraFilesQueueItemFindByID(hFilesQueueHandle, dwIDRequest, &dat);
if (dwRetErrorCode == NO_ERROR) {
- MraAddrListGetFromBuff(lpszAddreses, dwAddresesSize, &dat->malAddrList);
+ MraAddrListGetFromBuff(szAddresses, &dat->malAddrList);
MraAddrListStoreToContact(dat->hContact, &dat->malAddrList);
- dat->hConnection = NULL;
+ dat->m_hConnection = NULL;
SetEvent(dat->hWaitHandle);
}
return dwRetErrorCode;
}
-BOOL CMraProto::MraFilesQueueHandCheck(HANDLE hConnection, MRA_FILES_QUEUE_ITEM *dat)
+bool CMraProto::MraFilesQueueHandCheck(HANDLE m_hConnection, MRA_FILES_QUEUE_ITEM *dat)
{
- BOOL bRet = FALSE;
-
- if (hConnection && dat)
- {
- CHAR szEMail[MAX_EMAIL_LEN] = {0}, szEMailMy[MAX_EMAIL_LEN] = {0};
+ if (m_hConnection && dat) {
BYTE btBuff[((MAX_EMAIL_LEN*2)+(sizeof(MRA_FT_HELLO)*2)+8)] = {0};
- size_t dwEMailSize, dwEMailMySize, dwBuffSize;
+ size_t dwBuffSize;
- mraGetStaticStringA(NULL, "e-mail", szEMailMy, SIZEOF(szEMailMy), &dwEMailMySize);BuffToLowerCase(szEMailMy, szEMailMy, dwEMailMySize);
- mraGetStaticStringA(dat->hContact, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize);BuffToLowerCase(szEMail, szEMail, dwEMailSize);
+ CMStringA szEmail, szEmailMy;
+ mraGetStringA(NULL, "e-mail", szEmailMy); szEmailMy.MakeLower();
+ mraGetStringA(dat->hContact, "e-mail", szEmail); szEmail.MakeLower();
- if (dat->bSending == FALSE)
- {// receiving
- dwBuffSize = mir_snprintf((LPSTR)btBuff, SIZEOF(btBuff), "%s %s", MRA_FT_HELLO, szEMailMy)+1;
- if (dwBuffSize == Netlib_Send(hConnection, (LPSTR)btBuff, (int)dwBuffSize, 0))
- {// my email sended
+ 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)) {
+ // my email sended
ProtoBroadcastAck(dat->hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, (HANDLE)dat->dwIDRequest, 0);
- dwBuffSize = Netlib_Recv(hConnection, (LPSTR)btBuff, sizeof(btBuff), 0);
- if ((dwEMailSize+sizeof(MRA_FT_HELLO)+1) == dwBuffSize)
- {// email received
- mir_snprintf(((LPSTR)btBuff+dwBuffSize), (SIZEOF(btBuff)-dwBuffSize), "%s %s", MRA_FT_HELLO, szEMail);
+ dwBuffSize = Netlib_Recv(m_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);
if (CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, (LPSTR)btBuff, dwBuffSize, ((LPSTR)btBuff+dwBuffSize), dwBuffSize) == CSTR_EQUAL)
- bRet = TRUE;
+ return true;
}
}
- }else {// sending
- dwBuffSize = Netlib_Recv(hConnection, (LPSTR)btBuff, sizeof(btBuff), 0);
- if ((dwEMailSize+sizeof(MRA_FT_HELLO)+1) == dwBuffSize)
- {// email received
+ }
+ else {// sending
+ dwBuffSize = Netlib_Recv(m_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);
- mir_snprintf(((LPSTR)btBuff+dwBuffSize), (SIZEOF(btBuff)-dwBuffSize), "%s %s", MRA_FT_HELLO, szEMail);
- if (CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, (LPSTR)btBuff, dwBuffSize, ((LPSTR)btBuff+dwBuffSize), dwBuffSize) == CSTR_EQUAL)
- {// email verified
- dwBuffSize = (mir_snprintf((LPSTR)btBuff, SIZEOF(btBuff), "%s %s", MRA_FT_HELLO, szEMailMy)+1);
- if (dwBuffSize == Netlib_Send(hConnection, (LPSTR)btBuff, dwBuffSize, 0))
- {// my email sended
- bRet = TRUE;
- }
+ mir_snprintf(((LPSTR)btBuff+dwBuffSize), (SIZEOF(btBuff)-dwBuffSize), "%s %s", MRA_FT_HELLO, szEmail);
+ if (CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, (LPSTR)btBuff, dwBuffSize, ((LPSTR)btBuff+dwBuffSize), dwBuffSize) == CSTR_EQUAL) {
+ // 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))
+ return true;
}
}
}
}
- return bRet;
+ return false;
}
HANDLE CMraProto::MraFilesQueueConnectOut(MRA_FILES_QUEUE_ITEM *dat)
@@ -446,7 +441,7 @@ HANDLE CMraProto::MraFilesQueueConnectOut(MRA_FILES_QUEUE_ITEM *dat)
return NULL;
if (getByte("FileSendEnableDirectConn", MRA_DEF_FS_ENABLE_DIRECT_CONN) && InterlockedExchangeAdd((volatile LONG*)&dat->bIsWorking, 0) && ((dat->bSending == FALSE && getByte("FileSendNoOutConnOnRcv", MRA_DEF_FS_NO_OUT_CONN_ON_RCV) == FALSE) || (dat->bSending == TRUE && getByte("FileSendNoOutConnOnSend", MRA_DEF_FS_NO_OUT_CONN_ON_SEND) == FALSE))) {
- BOOL bFiltering = FALSE, bIsHTTPSProxyUsed = IsHTTPSProxyUsed(hNetlibUser);
+ BOOL bFiltering = FALSE, bIsHTTPSProxyUsed = IsHTTPSProxyUsed(m_hNetlibUser);
DWORD dwLocalPort = 0, dwConnectReTryCount, dwCurConnectReTryCount;
size_t dwAddrCount;
NETLIBOPENCONNECTION nloc = {0};
@@ -460,7 +455,7 @@ HANDLE CMraProto::MraFilesQueueConnectOut(MRA_FILES_QUEUE_ITEM *dat)
dwAddrCount = 0;
for (size_t i = 0; i < dat->malAddrList.dwAddrCount; i++) {
- if (dwLocalPort == dat->malAddrList.pmaliAddress[i].dwPort) {
+ if (dwLocalPort == dat->malAddrList.pMailAddress[i].dwPort) {
bFiltering = TRUE;
dwAddrCount++;
}
@@ -471,7 +466,7 @@ HANDLE CMraProto::MraFilesQueueConnectOut(MRA_FILES_QUEUE_ITEM *dat)
dwAddrCount = dat->malAddrList.dwAddrCount;
if (dwAddrCount) {
- dat->hConnection = NULL;
+ dat->m_hConnection = NULL;
dwConnectReTryCount = getDword("ConnectReTryCountFileSend", MRA_DEFAULT_CONN_RETRY_COUNT_FILES);
nloc.cbSize = sizeof(nloc);
nloc.flags = NLOCF_V2;
@@ -481,37 +476,37 @@ HANDLE CMraProto::MraFilesQueueConnectOut(MRA_FILES_QUEUE_ITEM *dat)
// Set up the sockaddr structure
for (size_t i = 0;i<dat->malAddrList.dwAddrCount;i++) {
- if (dwLocalPort == dat->malAddrList.pmaliAddress[i].dwPort || bFiltering == FALSE) {
+ if (dwLocalPort == dat->malAddrList.pMailAddress[i].dwPort || bFiltering == FALSE) {
ProtoBroadcastAck(dat->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTING, (HANDLE)dat->dwIDRequest, 0);
- nloc.szHost = inet_ntoa((*((in_addr*)&dat->malAddrList.pmaliAddress[i].dwAddr)));
- nloc.wPort = (WORD)dat->malAddrList.pmaliAddress[i].dwPort;
+ nloc.szHost = inet_ntoa((*((in_addr*)&dat->malAddrList.pMailAddress[i].dwAddr)));
+ nloc.wPort = (WORD)dat->malAddrList.pMailAddress[i].dwPort;
dwCurConnectReTryCount = dwConnectReTryCount;
do {
- dat->hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)hNetlibUser, (LPARAM)&nloc);
+ dat->m_hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc);
}
- while (--dwCurConnectReTryCount && dat->hConnection == NULL);
+ while (--dwCurConnectReTryCount && dat->m_hConnection == NULL);
- if (dat->hConnection) {
+ if (dat->m_hConnection) {
ProtoBroadcastAck(dat->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTED, (HANDLE)dat->dwIDRequest, 0);
- if (MraFilesQueueHandCheck(dat->hConnection, dat)) {
+ if (MraFilesQueueHandCheck(dat->m_hConnection, dat)) {
// связь установленная с тем кем нужно
setDword(dat->hContact, "OldIP", getDword(dat->hContact, "IP", 0));
- setDword(dat->hContact, "IP", HTONL(dat->malAddrList.pmaliAddress[i].dwAddr));
+ setDword(dat->hContact, "IP", HTONL(dat->malAddrList.pMailAddress[i].dwAddr));
break;
}
else {
// кажется не туда подключились :)
- Netlib_CloseHandle(dat->hConnection);
- dat->hConnection = NULL;
+ Netlib_CloseHandle(dat->m_hConnection);
+ dat->m_hConnection = NULL;
}
}
}
}
}
}
- return dat->hConnection;
+ return dat->m_hConnection;
}
LPWSTR GetFileNameFromFullPathW(LPWSTR lpwszFullPath, size_t dwFullPathSize)
@@ -535,10 +530,8 @@ HANDLE CMraProto::MraFilesQueueConnectIn(MRA_FILES_QUEUE_ITEM *dat)
if ( !InterlockedExchangeAdd((volatile LONG*)&dat->bIsWorking, 0))
return NULL;
- CHAR szEMail[MAX_EMAIL_LEN];
- size_t dwEMailSize;
-
- if (mraGetStaticStringA(dat->hContact, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize)) {
+ CMStringA szEmail;
+ if (mraGetStringA(dat->hContact, "e-mail", szEmail)) {
CHAR szAddrList[2048] = {0};
size_t dwAddrListSize;
@@ -551,7 +544,7 @@ HANDLE CMraProto::MraFilesQueueConnectIn(MRA_FILES_QUEUE_ITEM *dat)
nlbBind.wPort = 0;
nlbBind.pExtra = (LPVOID)dat;
- dat->hListen = (HANDLE)CallService(MS_NETLIB_BINDPORT, (WPARAM)hNetlibUser, (LPARAM)&nlbBind);
+ dat->hListen = (HANDLE)CallService(MS_NETLIB_BINDPORT, (WPARAM)m_hNetlibUser, (LPARAM)&nlbBind);
if (dat->hListen) {
ProtoBroadcastAck(dat->hContact, ACKTYPE_FILE, ACKRESULT_LISTENING, (HANDLE)dat->dwIDRequest, 0);
dwAddrListSize = MraFilesQueueGetLocalAddressesList(szAddrList, sizeof(szAddrList), nlbBind.wPort);
@@ -574,7 +567,7 @@ HANDLE CMraProto::MraFilesQueueConnectIn(MRA_FILES_QUEUE_ITEM *dat)
if (dwAddrListSize) {
dat->hWaitHandle = CreateEvent(NULL, TRUE, FALSE, NULL);
if (dat->bSending == FALSE) // запрашиваем зеркальное соединение, тк сами подключится не смогли
- MraFileTransferAck(FILE_TRANSFER_MIRROR, szEMail, dwEMailSize, dat->dwIDRequest, (LPBYTE)szAddrList, dwAddrListSize);
+ MraFileTransferAck(FILE_TRANSFER_MIRROR, szEmail, dat->dwIDRequest, (LPBYTE)szAddrList, dwAddrListSize);
else { // здесь отправляем запрос на передачу(установление соединения)
// создаём текстовый список файлов для отправки другой стороне
LPWSTR lpwszFiles, lpwszCurPos;
@@ -593,18 +586,10 @@ HANDLE CMraProto::MraFilesQueueConnectIn(MRA_FILES_QUEUE_ITEM *dat)
if (dat->hMraMrimProxyData) {
// устанавливаем данные для майловской прокси, если она разрешена
- LPSTR lpszFiles;
- size_t dwFilesSizeA;
-
- dwFilesSizeA = WideCharToMultiByte(MRA_CODE_PAGE, 0, lpwszFiles, dwFilesSize, NULL, 0, NULL, NULL);
- lpszFiles = (LPSTR)mir_calloc((dwFilesSizeA+MAX_PATH));
- if (lpszFiles) {
- dwFilesSizeA = WideCharToMultiByte(MRA_CODE_PAGE, 0, lpwszFiles, dwFilesSize, lpszFiles, (dwFilesSizeA+MAX_PATH), NULL, NULL);
- MraMrimProxySetData(dat->hMraMrimProxyData, szEMail, dwEMailSize, dat->dwIDRequest, MRIM_PROXY_TYPE_FILES, lpszFiles, dwFilesSizeA, NULL, 0, NULL);
- mir_free(lpszFiles);
- }
+ CMStringA lpszFiles = lpwszFiles;
+ MraMrimProxySetData(dat->hMraMrimProxyData, szEmail, dat->dwIDRequest, MRIM_PROXY_TYPE_FILES, lpszFiles, "", NULL);
}
- MraFileTransfer(szEMail, dwEMailSize, dat->dwIDRequest, dat->dwFilesTotalSize, lpwszFiles, dwFilesSize, szAddrList, dwAddrListSize);
+ MraFileTransfer(szEmail, dat->dwIDRequest, dat->dwFilesTotalSize, lpwszFiles, szAddrList);
mir_free(lpwszFiles);
}
@@ -614,7 +599,7 @@ HANDLE CMraProto::MraFilesQueueConnectIn(MRA_FILES_QUEUE_ITEM *dat)
dat->hWaitHandle = NULL;
}
}
- return dat->hConnection;
+ return dat->m_hConnection;
}
// This function is called from the Netlib when someone is connecting to
@@ -626,7 +611,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->hConnection = hNewConnection;
+ dat->m_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);
@@ -642,7 +627,7 @@ void MraFilesQueueConnectionReceived(HANDLE hNewConnection, DWORD dwRemoteIP, vo
/////////////////////////////////////////////////////////////////////////////////////////
// Receive files
-DWORD CMraProto::MraFilesQueueAddReceive(HANDLE hFilesQueueHandle, DWORD dwFlags, HANDLE hContact, DWORD dwIDRequest, LPWSTR lpwszFiles, size_t dwFilesSize, LPSTR lpszAddreses, size_t dwAddresesSize)
+DWORD CMraProto::MraFilesQueueAddReceive(HANDLE hFilesQueueHandle, DWORD dwFlags, HANDLE hContact, DWORD dwIDRequest, const CMStringW &lpwszFiles, const CMStringA &szAddresses)
{
if (!hFilesQueueHandle || !dwIDRequest)
return ERROR_INVALID_HANDLE;
@@ -653,7 +638,6 @@ DWORD CMraProto::MraFilesQueueAddReceive(HANDLE hFilesQueueHandle, DWORD dwFlags
return GetLastError();
WCHAR szBuff[MAX_PATH];
- LPWSTR lpwszCurrentItem, lpwszDelimiter, lpwszEndItem;
size_t dwMemSize, dwAllocatedCount, dwFileNameTotalSize;
//dat->lmtListMTItem;
@@ -671,14 +655,15 @@ DWORD CMraProto::MraFilesQueueAddReceive(HANDLE hFilesQueueHandle, DWORD dwFlags
dat->dwFilesCount = 0;
dat->dwFilesTotalSize = 0;
dat->pmfqfFiles = (MRA_FILES_QUEUE_FILE*)mir_calloc((sizeof(MRA_FILES_QUEUE_FILE)*dwAllocatedCount));
- lpwszCurrentItem = lpwszFiles;
+
+ int iStart = 0;
while (TRUE) {
- lpwszDelimiter = (LPWSTR)MemoryFind(((size_t)lpwszCurrentItem-(size_t)lpwszFiles), lpwszFiles, (dwFilesSize*sizeof(WCHAR)), ";", 2);
- if (!lpwszDelimiter)
+ CMStringW wszCurrFile = lpwszFiles.Tokenize(L";", iStart);
+ if (iStart == -1)
break;
- lpwszEndItem = (LPWSTR)MemoryFind((((size_t)lpwszDelimiter+2)-(size_t)lpwszFiles), lpwszFiles, (dwFilesSize*sizeof(WCHAR)), ";", 2);
- if (!lpwszEndItem)
+ CMStringW wszCurrSize = lpwszFiles.Tokenize(L";", iStart);
+ if (iStart == -1)
break;
if (dat->dwFilesCount == dwAllocatedCount) {
@@ -687,24 +672,22 @@ DWORD CMraProto::MraFilesQueueAddReceive(HANDLE hFilesQueueHandle, DWORD dwFlags
}
MRA_FILES_QUEUE_FILE &p = dat->pmfqfFiles[dat->dwFilesCount];
- *lpwszDelimiter++ = 0;
- p.lpwszName = mir_wstrdup(lpwszCurrentItem);
+ p.lpwszName = mir_wstrdup(wszCurrFile);
p.dwNameLen = lstrlen(p.lpwszName);
- p.dwSize = StrToUNum64((LPSTR)lpwszDelimiter, (size_t)lpwszEndItem-(size_t)lpwszDelimiter+1);
+ p.dwSize = _wtoi(wszCurrSize);
dat->dwFilesTotalSize += p.dwSize;
dwFileNameTotalSize += p.dwNameLen * sizeof(TCHAR);
dat->dwFilesCount++;
- lpwszCurrentItem = lpwszEndItem+1;
}
dat->pmfqfFiles = (MRA_FILES_QUEUE_FILE*)mir_realloc(dat->pmfqfFiles, (sizeof(MRA_FILES_QUEUE_FILE)*(dat->dwFilesCount+4)));
- dwMemSize = (((dat->dwFilesCount+4)*64)+(dwFileNameTotalSize*sizeof(WCHAR))+(dwAddresesSize*sizeof(WCHAR))+128);
+ dwMemSize = (((dat->dwFilesCount+4)*64)+(dwFileNameTotalSize*sizeof(WCHAR))+(szAddresses.GetLength()*sizeof(WCHAR))+128);
dat->pwszFilesList = (LPWSTR)mir_calloc(dwMemSize);
dat->pwszDescription = (LPWSTR)mir_calloc(dwMemSize);
- lpwszDelimiter = dat->pwszFilesList;
- lpwszCurrentItem = dat->pwszDescription;
+ LPWSTR lpwszDelimiter = dat->pwszFilesList;
+ LPWSTR lpwszCurrentItem = dat->pwszDescription;
StrFormatByteSizeW(dat->dwFilesTotalSize, szBuff, SIZEOF(szBuff));
lpwszCurrentItem += mir_sntprintf(lpwszCurrentItem, ((dwMemSize-((size_t)lpwszCurrentItem-(size_t)dat->pwszDescription))/sizeof(WCHAR)), L"%I64u Files (%s)\r\n", dat->dwFilesCount, szBuff);
@@ -715,10 +698,10 @@ DWORD CMraProto::MraFilesQueueAddReceive(HANDLE hFilesQueueHandle, DWORD dwFlags
lpwszCurrentItem += mir_sntprintf(lpwszCurrentItem, ((dwMemSize-((size_t)lpwszCurrentItem-(size_t)dat->pwszDescription))/sizeof(WCHAR)), L"%s - %s\r\n", dat->pmfqfFiles[i].lpwszName, szBuff);
}
- lpwszCurrentItem += MultiByteToWideChar(MRA_CODE_PAGE, 0, lpszAddreses, dwAddresesSize, lpwszCurrentItem, ((dwMemSize-((size_t)lpwszCurrentItem-(size_t)dat->pwszDescription))/sizeof(WCHAR)));
+ lpwszCurrentItem += MultiByteToWideChar(MRA_CODE_PAGE, 0, szAddresses, szAddresses.GetLength(), lpwszCurrentItem, ((dwMemSize-((size_t)lpwszCurrentItem-(size_t)dat->pwszDescription))/sizeof(WCHAR)));
*lpwszCurrentItem = 0;
- MraAddrListGetFromBuff(lpszAddreses, dwAddresesSize, &dat->malAddrList);
+ MraAddrListGetFromBuff(szAddresses, &dat->malAddrList);
MraAddrListStoreToContact(dat->hContact, &dat->malAddrList);
{
mt_lock l(pmrafqFilesQueue);
@@ -787,9 +770,9 @@ void CMraProto::MraFilesQueueRecvThreadProc(LPVOID lpParameter)
if (InterlockedExchangeAdd((volatile LONG*)&dat->bIsWorking, 0))
{
ProtoBroadcastAck(dat->hContact, ACKRESULT_CONNECTPROXY, ACKRESULT_CONNECTED, (HANDLE)dat->dwIDRequest, 0);
- if (MraMrimProxyConnect(dat->hMraMrimProxyData, &dat->hConnection) == NO_ERROR)
+ if (MraMrimProxyConnect(dat->hMraMrimProxyData, &dat->m_hConnection) == NO_ERROR)
{// подключились к прокси, проверяем та ли сессия (ещё раз, на этот раз сами)
- if (MraFilesQueueHandCheck(dat->hConnection, dat))
+ if (MraFilesQueueHandCheck(dat->m_hConnection, dat))
{// связь установленная с тем кем нужно// dat->bSending
ProtoBroadcastAck(dat->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTED, (HANDLE)dat->dwIDRequest, 0);
bConnected = TRUE;
@@ -834,7 +817,7 @@ void CMraProto::MraFilesQueueRecvThreadProc(LPVOID lpParameter)
btBuff[dwBuffSizeUsed] = 0;
dwBuffSizeUsed++;
- if (dwBuffSizeUsed == Netlib_Send(dat->hConnection, (LPSTR)btBuff, dwBuffSizeUsed, 0))
+ if (dwBuffSizeUsed == Netlib_Send(dat->m_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)
@@ -855,7 +838,7 @@ void CMraProto::MraFilesQueueRecvThreadProc(LPVOID lpParameter)
bContinue = TRUE;
dwUpdateTimeNext = GetTickCount();
nls.dwTimeout = (1000*getDword("TimeOutReceiveFileData", MRA_DEF_FS_TIMEOUT_RECV));
- nls.hReadConns[0] = dat->hConnection;
+ nls.hReadConns[0] = dat->m_hConnection;
ProtoBroadcastAck(dat->hContact, ACKTYPE_FILE, ACKRESULT_DATA, (HANDLE)dat->dwIDRequest, (LPARAM)&pfts);
while (bContinue)
@@ -868,7 +851,7 @@ void CMraProto::MraFilesQueueRecvThreadProc(LPVOID lpParameter)
bContinue = FALSE;
break;
case 1:
- dwReceived = Netlib_Recv(dat->hConnection, (LPSTR)&btBuff, SIZEOF(btBuff), 0);
+ dwReceived = Netlib_Recv(dat->m_hConnection, (LPSTR)&btBuff, SIZEOF(btBuff), 0);
if (dwReceived == 0 || dwReceived == SOCKET_ERROR)
{
dwRetErrorCode = GetLastError();
@@ -931,16 +914,14 @@ void CMraProto::MraFilesQueueRecvThreadProc(LPVOID lpParameter)
}
}// end for
- Netlib_CloseHandle(dat->hConnection);
- dat->hConnection = NULL;
+ Netlib_CloseHandle(dat->m_hConnection);
+ dat->m_hConnection = NULL;
}
if (bFailed) {
- CHAR szEMail[MAX_EMAIL_LEN];
- size_t dwEMailSize;
-
- if (mraGetStaticStringA(dat->hContact, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize))
- MraFileTransferAck(FILE_TRANSFER_STATUS_ERROR, szEMail, dwEMailSize, dat->dwIDRequest, NULL, 0);
+ CMStringA szEmail;
+ if (mraGetStringA(dat->hContact, "e-mail", szEmail))
+ MraFileTransferAck(FILE_TRANSFER_STATUS_ERROR, szEmail, dat->dwIDRequest, NULL, 0);
ProtoBroadcastAck(dat->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)dat->dwIDRequest, 0);
}
@@ -1045,9 +1026,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->hConnection) == NO_ERROR) {
+ if (MraMrimProxyConnect(dat->hMraMrimProxyData, &dat->m_hConnection) == NO_ERROR) {
// подключились к прокси, проверяем та ли сессия (ещё раз, на этот раз сами)
- if (MraFilesQueueHandCheck(dat->hConnection, dat)) {
+ if (MraFilesQueueHandCheck(dat->m_hConnection, dat)) {
// связь установленная с тем кем нужно// dat->bSending
ProtoBroadcastAck(dat->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTED, (HANDLE)dat->dwIDRequest, 0);
bConnected = TRUE;
@@ -1063,7 +1044,7 @@ void CMraProto::MraFilesQueueSendThreadProc(LPVOID lpParameter)
dwBuffSizeUsed = 0;
while (TRUE) {
- dwReceived = Netlib_Recv(dat->hConnection, ((LPSTR)btBuff+dwBuffSizeUsed), (SIZEOF(btBuff)-dwBuffSizeUsed), 0);
+ dwReceived = Netlib_Recv(dat->m_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);
@@ -1111,7 +1092,7 @@ void CMraProto::MraFilesQueueSendThreadProc(LPVOID lpParameter)
while (TRUE) { // read and sending
if (ReadFile(hFile, btBuff, dwSendBlockSize, (DWORD*)&dwBuffSizeUsed, NULL)) {
- dwReceived = Netlib_Send(dat->hConnection, (LPSTR)btBuff, dwBuffSizeUsed, 0);
+ dwReceived = Netlib_Send(dat->m_hConnection, (LPSTR)btBuff, dwBuffSizeUsed, 0);
if (dwBuffSizeUsed == dwReceived) {
pfts.currentFileProgress += dwBuffSizeUsed;
pfts.totalProgress += dwBuffSizeUsed;
@@ -1176,16 +1157,14 @@ void CMraProto::MraFilesQueueSendThreadProc(LPVOID lpParameter)
}
}// end for
- Netlib_CloseHandle(dat->hConnection);
- dat->hConnection = NULL;
+ Netlib_CloseHandle(dat->m_hConnection);
+ dat->m_hConnection = NULL;
}
if (bFailed) {
- CHAR szEMail[MAX_EMAIL_LEN];
- size_t dwEMailSize;
-
- if (mraGetStaticStringA(dat->hContact, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize))
- MraFileTransferAck(FILE_TRANSFER_STATUS_ERROR, szEMail, dwEMailSize, dat->dwIDRequest, NULL, 0);
+ CMStringA szEmail;
+ if (mraGetStringA(dat->hContact, "e-mail", szEmail))
+ MraFileTransferAck(FILE_TRANSFER_STATUS_ERROR, szEmail, dat->dwIDRequest, NULL, 0);
ProtoBroadcastAck(dat->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)dat->dwIDRequest, 0);
}