summaryrefslogtreecommitdiff
path: root/protocols/MRA/src
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
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')
-rw-r--r--protocols/MRA/src/Mra.h124
-rw-r--r--protocols/MRA/src/MraAdvancedSearch.cpp2
-rw-r--r--protocols/MRA/src/MraAntiSpam.cpp118
-rw-r--r--protocols/MRA/src/MraAvatars.cpp206
-rw-r--r--protocols/MRA/src/MraChat.cpp115
-rw-r--r--protocols/MRA/src/MraFilesQueue.cpp225
-rw-r--r--protocols/MRA/src/MraMPop.cpp66
-rw-r--r--protocols/MRA/src/MraMPop.h2
-rw-r--r--protocols/MRA/src/MraMRIMProxy.cpp69
-rw-r--r--protocols/MRA/src/MraMRIMProxy.h2
-rw-r--r--protocols/MRA/src/MraOfflineMsg.cpp142
-rw-r--r--protocols/MRA/src/MraOfflineMsg.h2
-rw-r--r--protocols/MRA/src/MraPopUp.cpp22
-rw-r--r--protocols/MRA/src/MraProto.cpp117
-rw-r--r--protocols/MRA/src/MraProto.h199
-rw-r--r--protocols/MRA/src/MraRTFMsg.cpp48
-rw-r--r--protocols/MRA/src/MraRTFMsg.h2
-rw-r--r--protocols/MRA/src/MraSelectEMail.cpp51
-rw-r--r--protocols/MRA/src/MraSendCommand.cpp892
-rw-r--r--protocols/MRA/src/MraSendQueue.cpp10
-rw-r--r--protocols/MRA/src/Mra_functions.cpp1028
-rw-r--r--protocols/MRA/src/Mra_options.cpp27
-rw-r--r--protocols/MRA/src/Mra_proto.cpp3041
-rw-r--r--protocols/MRA/src/Mra_svcs.cpp504
-rw-r--r--protocols/MRA/src/Sdk/InternetTime.h63
-rw-r--r--protocols/MRA/src/version.h6
26 files changed, 3175 insertions, 3908 deletions
diff --git a/protocols/MRA/src/Mra.h b/protocols/MRA/src/Mra.h
index d23224d6db..04dc97c624 100644
--- a/protocols/MRA/src/Mra.h
+++ b/protocols/MRA/src/Mra.h
@@ -58,6 +58,7 @@
#include <m_utils.h>
#include <m_database.h>
#include <m_langpack.h>
+#include <m_string.h>
#include <m_netlib.h>
#include <m_icolib.h>
#include <win2k.h>
@@ -92,22 +93,22 @@
#include "Sdk/SHA1.h"
// LPS
-typedef struct
+struct MRA_LPS
{
- size_t dwSize;
+ size_t dwSize;
union {
- LPSTR lpszData;
- LPWSTR lpwszData;
+ LPSTR lpszData;
+ LPWSTR lpwszData;
};
-} MRA_LPS;
+};
// GUID
-typedef struct
+struct MRA_GUID
{
DWORD id[4];
-} MRA_GUID;
+};
@@ -119,10 +120,28 @@ struct MRA_ADDR_LIST_ITEM
struct MRA_ADDR_LIST
{
- DWORD dwAddrCount;
- MRA_ADDR_LIST_ITEM *pmaliAddress;
+ DWORD dwAddrCount;
+ MRA_ADDR_LIST_ITEM *pMailAddress;
+};
+
+/////////////////////////////////////////////////////////////////////////////
+
+struct BinBuffer
+{
+ BinBuffer(LPBYTE data, size_t len) : m_data(data), m_len(len) {}
+
+ LPBYTE m_data;
+ size_t m_len;
};
+BinBuffer& operator >>(BinBuffer&, DWORD&);
+BinBuffer& operator >>(BinBuffer&, DWORDLONG&);
+BinBuffer& operator >>(BinBuffer&, MRA_GUID&);
+BinBuffer& operator >>(BinBuffer&, CMStringA&);
+BinBuffer& operator >>(BinBuffer&, CMStringW&);
+
+/////////////////////////////////////////////////////////////////////////////
+
#include "MraConstans.h"
#include "MraProto.h"
@@ -163,23 +182,24 @@ extern GUI_DISPLAY_ITEM gdiExtraStatusIconsItems[];
/////////////////////////////////////////////////////////////////////////////////////////
// plugin options
-typedef struct
+struct MRA_SETTINGS
{
- HANDLE hHeap;
- HINSTANCE hInstance;
- HMODULE hDLLXStatusIcons;
+ HANDLE hHeap;
+ HINSTANCE hInstance;
+ HMODULE hDLLXStatusIcons;
- DWORD dwGlobalPluginRunning;
- BOOL bChatExist;
+ DWORD dwGlobalPluginRunning;
+ bool bChatExist;
- size_t dwMirWorkDirPathLen;
- WCHAR szMirWorkDirPath[MAX_FILEPATH];
-} MRA_SETTINGS;
+ size_t dwMirWorkDirPathLen;
+ WCHAR szMirWorkDirPath[MAX_FILEPATH];
+};
+extern MRA_SETTINGS masMraSettings;
/////////////////////////////////////////////////////////////////////////////////////////
// External variables
-extern MRA_SETTINGS masMraSettings;
+
extern LIST<CMraProto> g_Instances;
extern HANDLE hXStatusAdvancedStatusIcons[];
@@ -188,7 +208,7 @@ INT_PTR LoadModules();
void UnloadModules();
void InitExtraIcons();
-DWORD MraGetSelfVersionString(LPSTR lpszSelfVersion, size_t dwSelfVersionSize, size_t *pdwSelfVersionSizeRet);
+CMStringA MraGetSelfVersionString();
#define GetContactNameA(Contact) (LPSTR)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)Contact, 0)
#define GetContactNameW(Contact) (LPWSTR)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)Contact, GCDNF_UNICODE)
@@ -221,45 +241,43 @@ DWORD MraGetSelfVersionString(LPSTR lpszSelfVersion, size_t dwSelfVersionSize,
#define GET_CURRENT_COMBO_DATA(hWndDlg, ControlID) SEND_DLG_ITEM_MESSAGE(hWndDlg, ControlID, CB_GETITEMDATA, SEND_DLG_ITEM_MESSAGE(hWndDlg, ControlID, CB_GETCURSEL, 0, 0), 0)
-
#define IsFileExist(FileName) (GetFileAttributes(FileName) != INVALID_FILE_ATTRIBUTES)
#define IsFileExistA(FileName) (GetFileAttributesA(FileName) != INVALID_FILE_ATTRIBUTES)
#define IsFileExistW(FileName) (GetFileAttributesW(FileName) != INVALID_FILE_ATTRIBUTES)
-
#define IsThreadAlive(hThread) (GetThreadPriority(hThread) != THREAD_PRIORITY_ERROR_RETURN)
-void MraAddrListFree(MRA_ADDR_LIST *pmalAddrList);
-DWORD MraAddrListGetFromBuff(LPSTR lpszAddreses, size_t dwAddresesSize, MRA_ADDR_LIST *pmalAddrList);
-DWORD MraAddrListGetToBuff(MRA_ADDR_LIST *pmalAddrList, LPSTR lpszBuff, size_t dwBuffSize, size_t *pdwBuffSizeRet);
-
-void InitXStatusIcons();
-void DestroyXStatusIcons();
-
-DWORD MraGetVersionStringFromFormatted (LPSTR dwUserAgentFormatted, size_t dwUserAgentFormattedSize, LPSTR lpszVersion, size_t dwVersionSize, size_t *pdwVersionSizeRet);
-BOOL IsUnicodeEnv ();
-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 CreateBlobFromContact (HANDLE hContact, LPWSTR lpwszRequestReason, size_t dwRequestReasonSize, LPBYTE lpbBuff, size_t dwBuffSize, size_t *pdwBuffSizeRet);
-size_t CopyNumber (LPCVOID lpcOutBuff, LPCVOID lpcBuff, size_t dwLen);
-BOOL IsPhone (LPSTR lpszString, size_t dwStringSize);
-BOOL IsContactPhone (HANDLE hContact, LPSTR lpszPhone, size_t dwPhoneSize);
-HANDLE MraHContactFromPhone (LPSTR lpszPhone, size_t dwPhoneSize, BOOL bAddIfNeeded, BOOL bTemporary, BOOL *pbAdded);
-void EnableControlsArray (HWND hWndDlg, WORD *pwControlsList, size_t dwControlsListCount, BOOL bEnabled);
-BOOL MraRequestXStatusDetails (DWORD dwXStatus);
-BOOL MraSendReplyBlogStatus (HANDLE hContact);
-DWORD GetYears (CONST PSYSTEMTIME pcstSystemTime);
-DWORD FindFile (LPWSTR lpszFolder, DWORD dwFolderLen, LPWSTR lpszFileName, DWORD dwFileNameLen, LPWSTR lpszRetFilePathName, DWORD dwRetFilePathLen, DWORD *pdwRetFilePathLen);
-DWORD MemFillRandom (LPVOID lpBuff, size_t dwBuffSize);
-DWORD DecodeXML (LPTSTR lptszMessage, size_t dwMessageSize, LPTSTR lptszMessageConverted, size_t dwMessageConvertedBuffSize, size_t *pdwMessageConvertedSize);
-DWORD EncodeXML (LPTSTR lptszMessage, size_t dwMessageSize, LPTSTR lptszMessageConverted, size_t dwMessageConvertedBuffSize, size_t *pdwMessageConvertedSize);
-
-DWORD GetMraStatusFromMiradaStatus (DWORD dwMirandaStatus, DWORD dwXStatusMir, DWORD *pdwXStatusMra);
-DWORD GetMiradaStatusFromMraStatus (DWORD dwMraStatus, DWORD dwXStatusMra, DWORD *pdwXStatusMir);
-DWORD GetMraXStatusIDFromMraUriStatus (LPSTR lpszStatusUri, size_t dwStatusUriSize);
+void MraAddrListFree(MRA_ADDR_LIST *pmalAddrList);
+DWORD MraAddrListGetFromBuff(const CMStringA &szAddresses, MRA_ADDR_LIST *pmalAddrList);
+CMStringA MraAddrListGetToBuff(MRA_ADDR_LIST *pmalAddrList);
+
+void InitXStatusIcons();
+void DestroyXStatusIcons();
+
+CMStringA MraGetVersionStringFromFormatted(const CMStringA& szUserAgentFormatted);
+CMStringA CopyNumber(const CMStringA&);
+
+CMStringW DecodeXML(const CMStringW &lptszMessage);
+CMStringW EncodeXML(const CMStringW &lptszMessage);
+
+bool IsHTTPSProxyUsed(HANDLE m_hNetlibUser);
+bool IsContactMraProto(HANDLE hContact);
+bool IsEMailMR(const CMStringA& szEmail);
+bool GetEMailFromString(const CMStringA& szBuff, CMStringA& szEmail);
+
+bool IsPhone(LPSTR lpszString, size_t dwStringSize);
+bool IsContactPhone(HANDLE hContact, LPSTR lpszPhone, size_t dwPhoneSize);
+HANDLE MraHContactFromPhone(LPSTR lpszPhone, size_t dwPhoneSize, BOOL bAddIfNeeded, BOOL bTemporary, BOOL *pbAdded);
+void EnableControlsArray(HWND hWndDlg, WORD *pwControlsList, size_t dwControlsListCount, BOOL bEnabled);
+bool MraRequestXStatusDetails(DWORD dwXStatus);
+bool MraSendReplyBlogStatus(HANDLE hContact);
+DWORD GetYears(CONST PSYSTEMTIME pcstSystemTime);
+DWORD FindFile(LPWSTR lpszFolder, DWORD dwFolderLen, LPWSTR lpszFileName, DWORD dwFileNameLen, LPWSTR lpszRetFilePathName, DWORD dwRetFilePathLen, DWORD *pdwRetFilePathLen);
+DWORD MemFillRandom(LPVOID lpBuff, size_t dwBuffSize);
+
+DWORD GetMraStatusFromMiradaStatus(DWORD dwMirandaStatus, DWORD dwXStatusMir, DWORD *pdwXStatusMra);
+DWORD GetMiradaStatusFromMraStatus(DWORD dwMraStatus, DWORD dwXStatusMra, DWORD *pdwXStatusMir);
+DWORD GetMraXStatusIDFromMraUriStatus(const char *lpszStatusUri);
INT_PTR CALLBACK DlgProcAccount(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
diff --git a/protocols/MRA/src/MraAdvancedSearch.cpp b/protocols/MRA/src/MraAdvancedSearch.cpp
index cf54c45733..43df36e4d9 100644
--- a/protocols/MRA/src/MraAdvancedSearch.cpp
+++ b/protocols/MRA/src/MraAdvancedSearch.cpp
@@ -349,7 +349,7 @@ HWND CMraProto::SearchAdvanced(HWND hWndDlg)
dwOnline = IS_DLG_BUTTON_CHECKED(hWndDlg, IDC_ONLINEONLY);
if (dwOnline) SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_ONLINE);
- return (HWND)MraWPRequestW(NULL, ACKTYPE_SEARCH, dwRequestFlags, szUser, dwUserSize, szDomain, dwDomainSize, wszNickName, dwNickNameSize, wszFirstName, dwFirstNameSize, wszLastName, dwLastNameSize, dwSex, dwDate1, dwDate2, dwCityID, dwZodiak, dwBirthdayMonth, dwBirthdayDay, dwCountryID, dwOnline);
+ return (HWND)MraWPRequestW(NULL, ACKTYPE_SEARCH, dwRequestFlags, szUser, szDomain, wszNickName, wszFirstName, wszLastName, dwSex, dwDate1, dwDate2, dwCityID, dwZodiak, dwBirthdayMonth, dwBirthdayDay, dwCountryID, dwOnline);
}
HWND CMraProto::CreateExtendedSearchUI(HWND owner)
diff --git a/protocols/MRA/src/MraAntiSpam.cpp b/protocols/MRA/src/MraAntiSpam.cpp
index 4e19e005e6..7508570bc3 100644
--- a/protocols/MRA/src/MraAntiSpam.cpp
+++ b/protocols/MRA/src/MraAntiSpam.cpp
@@ -96,15 +96,15 @@ INT_PTR CALLBACK MraAntiSpamDlgProcOpts(HWND hWndDlg, UINT msg, WPARAM wParam, L
{
// fill list
char szSettingName[MAX_PATH];
- WCHAR wszBuff[MAX_PATH];
+ CMStringW wszBuff;
SEND_DLG_ITEM_MESSAGE(hWndDlg, IDC_BAD_WORDS_LIST, LB_RESETCONTENT, 0, 0);
SEND_DLG_ITEM_MESSAGE(hWndDlg, IDC_BAD_WORDS_LIST, LB_INITSTORAGE, (WPARAM)1024, (LPARAM)32768);
for (size_t i = 0; TRUE; i++) {
mir_snprintf(szSettingName, SIZEOF(szSettingName), "AntiSpamBadWord %lu", i);
- if (ppro->mraGetStaticStringW(NULL, szSettingName, wszBuff, SIZEOF(wszBuff), NULL)) {
- if (SEND_DLG_ITEM_MESSAGE(hWndDlg, IDC_BAD_WORDS_LIST, LB_FINDSTRING, -1, (LPARAM)wszBuff) == LB_ERR)
- SEND_DLG_ITEM_MESSAGE(hWndDlg, IDC_BAD_WORDS_LIST, LB_ADDSTRING, 0, (LPARAM)wszBuff);
+ if (ppro->mraGetStringW(NULL, szSettingName, wszBuff)) {
+ if (SEND_DLG_ITEM_MESSAGE(hWndDlg, IDC_BAD_WORDS_LIST, LB_FINDSTRING, -1, (LPARAM)wszBuff.c_str()) == LB_ERR)
+ SEND_DLG_ITEM_MESSAGE(hWndDlg, IDC_BAD_WORDS_LIST, LB_ADDSTRING, 0, (LPARAM)wszBuff.c_str());
}
else break;
}
@@ -136,15 +136,15 @@ INT_PTR CALLBACK MraAntiSpamDlgProcOpts(HWND hWndDlg, UINT msg, WPARAM wParam, L
MraAntiSpamResetBadWordsList();
char szSettingName[MAX_PATH];
- WCHAR wszBuff[MAX_PATH];
+ CMStringW wszBuff;
SEND_DLG_ITEM_MESSAGE(hWndDlg, IDC_BAD_WORDS_LIST, LB_RESETCONTENT, 0, 0);
SEND_DLG_ITEM_MESSAGE(hWndDlg, IDC_BAD_WORDS_LIST, LB_INITSTORAGE, (WPARAM)1024, (LPARAM)32768);
for (size_t i = 0;TRUE;i++) {
mir_snprintf(szSettingName, SIZEOF(szSettingName), "AntiSpamBadWord %lu", i);
- if (ppro->mraGetStaticStringW(NULL, szSettingName, wszBuff, SIZEOF(wszBuff), NULL)) {
- if (SEND_DLG_ITEM_MESSAGE(hWndDlg, IDC_BAD_WORDS_LIST, LB_FINDSTRING, -1, (LPARAM)wszBuff) == LB_ERR)
- SEND_DLG_ITEM_MESSAGE(hWndDlg, IDC_BAD_WORDS_LIST, LB_ADDSTRING, 0, (LPARAM)wszBuff);
+ if (ppro->mraGetStringW(NULL, szSettingName, wszBuff)) {
+ if (SEND_DLG_ITEM_MESSAGE(hWndDlg, IDC_BAD_WORDS_LIST, LB_FINDSTRING, -1, (LPARAM)wszBuff.c_str()) == LB_ERR)
+ SEND_DLG_ITEM_MESSAGE(hWndDlg, IDC_BAD_WORDS_LIST, LB_ADDSTRING, 0, (LPARAM)wszBuff.c_str());
}
else break;
}
@@ -246,19 +246,19 @@ BOOL MraAntiSpamIsCharExcepted(WCHAR wcTestChar)
return FALSE;
}
-size_t MraAntiSpamCalcLangChanges(LPWSTR lpwszMessage, size_t dwMessageSize)
+size_t MraAntiSpamCalcLangChanges(const CMStringW &wszMessage)
{
size_t dwRet = 0;
- if (lpwszMessage && dwMessageSize) {
+ if (!wszMessage.IsEmpty()) {
WCHAR wcPrevChar = 0;
- for (size_t i = 1; i < dwMessageSize; i++) {
- if (MraAntiSpamIsCharExcepted(lpwszMessage[i]) == FALSE) {
+ for (size_t i = 1; i < wszMessage.GetLength(); i++) {
+ if (MraAntiSpamIsCharExcepted(wszMessage[i]) == FALSE) {
if (wcPrevChar)
- if ( (max(wcPrevChar, lpwszMessage[i])-min(wcPrevChar, lpwszMessage[i])) > 255)
+ if ( (max(wcPrevChar, wszMessage[i])-min(wcPrevChar, wszMessage[i])) > 255)
dwRet++;
- wcPrevChar = lpwszMessage[i];
+ wcPrevChar = wszMessage[i];
}
}
}
@@ -283,65 +283,57 @@ size_t MraAntiSpamCleanNonAlphaNumeric(LPWSTR lpwszMessage, size_t dwMessageSize
}
-BOOL MraAntiSpamTestMessageForBadWordsW(LPWSTR lpwszMessage, size_t dwMessageSize)
+bool MraAntiSpamTestMessageForBadWordsW(const CMStringW &wszMessage)
{
- if (lpwszMessage && dwMessageSize)
+ if (!wszMessage.IsEmpty())
for (size_t i = 0; i < dwBadWordsCount; i++)
- if (MemoryFind(0, lpwszMessage, (dwMessageSize*sizeof(WCHAR)), pmabwBadWords[i].lpwszBadWord, (pmabwBadWords[i].dwBadWordLen*sizeof(WCHAR))))
- return TRUE;
+ if ( wcsstr(wszMessage, pmabwBadWords[i].lpwszBadWord))
+ return true;
- return FALSE;
+ return false;
}
-BOOL CMraProto::MraAntiSpamHasMessageBadWordsW(LPWSTR lpwszMessage, size_t dwMessageSize)
+bool CMraProto::MraAntiSpamHasMessageBadWordsW(const CMStringW &wszMessage)
{
- BOOL bRet = FALSE;
-
- if (lpwszMessage && dwMessageSize) {
- LPWSTR lpwszMessageConverted = (LPWSTR)mir_alloc((dwMessageSize+1)*sizeof(WCHAR));
- if (lpwszMessageConverted) {
- size_t dwtm;
-
- // в нижний регистр всё сообщение
- memmove(lpwszMessageConverted, lpwszMessage, (dwMessageSize*sizeof(WCHAR)));
- CharLowerBuffW(lpwszMessageConverted, DWORD(dwMessageSize));
-
- // 1 проход: считаем колличество переключений языка
- dwtm = getDword("AntiSpamMaxLangChanges", MRA_ANTISPAM_DEFAULT_MAX_LNG_CHANGES);
- if (dwtm)
- if (dwtm <= MraAntiSpamCalcLangChanges(lpwszMessageConverted, dwMessageSize))
- bRet = TRUE;
-
- // 2 проход: ищем плохие слова
- if (bRet == FALSE)
- bRet = MraAntiSpamTestMessageForBadWordsW(lpwszMessageConverted, dwMessageSize);
-
- // 3 проход: оставляем только буквы + цифры и снова ищем плохие слова
- if (bRet == FALSE)
- if (getByte("AntiSpamCleanNonAlphaNumeric", MRA_ANTISPAM_DEFAULT_ENABLE)) {
- dwMessageSize = MraAntiSpamCleanNonAlphaNumeric(lpwszMessageConverted, dwMessageSize);
- bRet = MraAntiSpamTestMessageForBadWordsW(lpwszMessageConverted, dwMessageSize);
- }
-
- mir_free(lpwszMessageConverted);
+ bool bRet = false;
+
+ if (!wszMessage.IsEmpty()) {
+ CMStringW wszMessageConverted = wszMessage;
+ wszMessageConverted.MakeLower();
+
+ // 1 проход: считаем колличество переключений языка
+ size_t dwtm = getDword("AntiSpamMaxLangChanges", MRA_ANTISPAM_DEFAULT_MAX_LNG_CHANGES);
+ if (dwtm)
+ if (dwtm <= MraAntiSpamCalcLangChanges(wszMessageConverted))
+ bRet = true;
+
+ // 2 проход: ищем плохие слова
+ if (bRet == false)
+ bRet = MraAntiSpamTestMessageForBadWordsW(wszMessageConverted);
+
+ // 3 проход: оставляем только буквы + цифры и снова ищем плохие слова
+ if (bRet == false)
+ if (getByte("AntiSpamCleanNonAlphaNumeric", MRA_ANTISPAM_DEFAULT_ENABLE)) {
+ MraAntiSpamCleanNonAlphaNumeric(wszMessageConverted.GetBuffer(), wszMessageConverted.GetLength());
+ bRet = MraAntiSpamTestMessageForBadWordsW(wszMessageConverted);
}
}
return bRet;
}
-DWORD CMraProto::MraAntiSpamReceivedMessageW(LPSTR lpszEMail, size_t dwEMailSize, DWORD dwMessageFlags, LPWSTR lpwszMessage, size_t dwMessageSize)
+DWORD CMraProto::MraAntiSpamReceivedMessageW(const CMStringA &szEmail, DWORD dwMessageFlags, const CMStringW &wszMessage)
{
DWORD dwRet = MESSAGE_NOT_SPAM;;
if ((dwMessageFlags&(MESSAGE_FLAG_SYSTEM|MESSAGE_FLAG_CONTACT|MESSAGE_FLAG_NOTIFY|MESSAGE_FLAG_SMS|MESSAGE_SMS_DELIVERY_REPORT|MESSAGE_FLAG_ALARM|MESSAGE_FLAG_MULTICHAT)) == 0)
if (getByte("AntiSpamEnable", MRA_ANTISPAM_DEFAULT_ENABLE))
- if (IsEMailChatAgent(lpszEMail, dwEMailSize) == FALSE) { // enabled, message must be checked
+ if (IsEMailChatAgent(szEmail) == FALSE) { // enabled, message must be checked
BOOL bCheckMessage = TRUE;
dwRet = MESSAGE_SPAM;
- HANDLE hContact = MraHContactFromEmail(lpszEMail, dwEMailSize, FALSE, TRUE, NULL);
+ HANDLE hContact = MraHContactFromEmail(szEmail, FALSE, TRUE, NULL);
if (hContact) {
DWORD dwID, dwGroupID, dwContactFlag, dwContactSeverFlags;
- GetContactBasicInfoW(hContact, &dwID, &dwGroupID, &dwContactFlag, &dwContactSeverFlags, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, NULL);
+ GetContactBasicInfoW(hContact, &dwID, &dwGroupID, &dwContactFlag, &dwContactSeverFlags, NULL, NULL, NULL, NULL);
// not temp contact, OK
if ((dwID != -1 && db_get_b(hContact, "CList", "NotOnList", 0) == 0) || dwGroupID == -2) {
@@ -359,7 +351,7 @@ DWORD CMraProto::MraAntiSpamReceivedMessageW(LPSTR lpszEMail, size_t dwEMailSize
}
if (bCheckMessage)
- if (MraAntiSpamHasMessageBadWordsW(lpwszMessage, dwMessageSize) == FALSE)
+ if (MraAntiSpamHasMessageBadWordsW(wszMessage) == FALSE)
dwRet = MESSAGE_NOT_SPAM;
if (dwRet == MESSAGE_SPAM) {
@@ -370,18 +362,20 @@ DWORD CMraProto::MraAntiSpamReceivedMessageW(LPSTR lpszEMail, size_t dwEMailSize
bAntiSpamDeteleSpamBotContacts = (BOOL)getByte("AntiSpamDeteleSpamBotContacts", MRA_ANTISPAM_DEFAULT_DELETE_SPAMBOT_CONTACT);
if (bAntiSpamShowPopup || bAntiSpamWriteToSystemHistory) {
- char szEMail[MAX_EMAIL_LEN];
WCHAR wszBuff[MRA_MAXLENOFMESSAGE*2];
size_t dwDBMessageSize;
- memmove(szEMail, lpszEMail, dwEMailSize);
- (*((WORD*)(szEMail+dwEMailSize))) = 0;
+ char szTmp[MAX_PATH];
+ memmove(szTmp, szEmail, szEmail.GetLength());
+ *((WORD*)(szTmp+szEmail.GetLength())) = 0;
- dwDBMessageSize = mir_sntprintf(wszBuff, SIZEOF(wszBuff), L"%s: %S\r\n", TranslateW(L"Spam bot blocked"), szEMail);
- if (dwMessageSize>(SIZEOF(wszBuff)-(dwDBMessageSize+sizeof(DWORD)))) dwMessageSize = (SIZEOF(wszBuff)-(dwDBMessageSize+sizeof(DWORD)));
- memmove((wszBuff+dwDBMessageSize), lpwszMessage, (dwMessageSize*sizeof(WCHAR)));
+ dwDBMessageSize = mir_sntprintf(wszBuff, SIZEOF(wszBuff), L"%s: %S\r\n", TranslateW(L"Spam bot blocked"), szEmail);
+ DWORD dwMessageSize = wszMessage.GetLength();
+ if (dwMessageSize > (SIZEOF(wszBuff)-(dwDBMessageSize+sizeof(DWORD))))
+ dwMessageSize = (SIZEOF(wszBuff)-(dwDBMessageSize+sizeof(DWORD)));
+ memmove(wszBuff+dwDBMessageSize, wszMessage, (dwMessageSize*sizeof(WCHAR)));
dwDBMessageSize += dwMessageSize;
- (*((DWORD*)(wszBuff+dwDBMessageSize))) = 0;
+ *((DWORD*)(wszBuff+dwDBMessageSize)) = 0;
dwDBMessageSize += sizeof(DWORD);
if (bAntiSpamShowPopup)
@@ -402,7 +396,7 @@ DWORD CMraProto::MraAntiSpamReceivedMessageW(LPSTR lpszEMail, size_t dwEMailSize
}
if (hContact && bAntiSpamDeteleSpamBotContacts) {
- dwDBMessageSize = mir_sntprintf(wszBuff, SIZEOF(wszBuff), L"%s: %S", TranslateW(L"Spam bot contact deleted"), szEMail);
+ dwDBMessageSize = mir_sntprintf(wszBuff, SIZEOF(wszBuff), L"%s: %S", TranslateW(L"Spam bot contact deleted"), szEmail);
if (bAntiSpamShowPopup)
MraPopupShowFromAgentW(MRA_POPUP_TYPE_INFORMATION, 0, wszBuff);
diff --git a/protocols/MRA/src/MraAvatars.cpp b/protocols/MRA/src/MraAvatars.cpp
index e80ee2e9df..e190e7577d 100644
--- a/protocols/MRA/src/MraAvatars.cpp
+++ b/protocols/MRA/src/MraAvatars.cpp
@@ -30,8 +30,8 @@ const LPSTR lpcszContentType[9] =
struct MRA_AVATARS_QUEUE : public FIFO_MT
{
- BOOL bIsRunning;
- HANDLE hNetlibUser;
+ bool bIsRunning;
+ HANDLE m_hNetlibUser;
HANDLE hThreadEvent;
int iThreadsCount;
HANDLE hThread[MAXIMUM_WAIT_OBJECTS];
@@ -53,17 +53,17 @@ struct MRA_AVATARS_QUEUE_ITEM : public FIFO_MT_ITEM
char szAvtSectName[MAX_PATH];
#define MRA_AVT_SECT_NAME szAvtSectName
-#define NETLIB_CLOSEHANDLE(hConnection) {Netlib_CloseHandle(hConnection);hConnection = NULL;}
+#define NETLIB_CLOSEHANDLE(m_hConnection) {Netlib_CloseHandle(m_hConnection);m_hConnection = NULL;}
-HANDLE MraAvatarsHttpConnect(HANDLE hNetlibUser, LPSTR lpszHost, DWORD dwPort);
+HANDLE MraAvatarsHttpConnect(HANDLE m_hNetlibUser, LPCSTR lpszHost, DWORD dwPort);
#define MAHTRO_AVT 0
#define MAHTRO_AVTMRIM 1
#define MAHTRO_AVTSMALL 2
#define MAHTRO_AVTSMALLMRIM 3
-DWORD MraAvatarsHttpTransaction (HANDLE hConnection, DWORD dwRequestType, LPSTR lpszUser, LPSTR lpszDomain, LPSTR lpszHost, DWORD dwReqObj, BOOL bUseKeepAliveConn, DWORD *pdwResultCode, BOOL *pbKeepAlive, DWORD *pdwFormat, size_t *pdwAvatarSize, INTERNET_TIME *pitLastModifiedTime);
-DWORD MraAvatarsGetFileFormat (LPTSTR lpszPath, size_t dwPathSize);
+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 MraAvatarsGetFileFormat(const CMString &lpszPath);
DWORD CMraProto::MraAvatarsQueueInitialize(HANDLE *phAvatarsQueueHandle)
{
@@ -86,8 +86,8 @@ DWORD CMraProto::MraAvatarsQueueInitialize(HANDLE *phAvatarsQueueHandle)
nlu.flags = NUF_OUTGOING | NUF_HTTPCONNS;
nlu.szSettingsModule = MRA_AVT_SECT_NAME;
nlu.szDescriptiveName = szBuffer;
- pmraaqAvatarsQueue->hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
- if (pmraaqAvatarsQueue->hNetlibUser) {
+ pmraaqAvatarsQueue->m_hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
+ if (pmraaqAvatarsQueue->m_hNetlibUser) {
TCHAR tszPath[ MAX_PATH ];
mir_sntprintf( tszPath, SIZEOF(tszPath), _T("%%miranda_avatarcache%%\\%s"), m_tszUserName);
pmraaqAvatarsQueue->hAvatarsPath = FoldersRegisterCustomPathT(LPGEN("Avatars"), m_szModuleName, tszPath, m_tszUserName);
@@ -151,7 +151,7 @@ void CMraProto::MraAvatarsQueueDestroy(HANDLE hAvatarsQueueHandle)
MraAvatarsQueueClear(hAvatarsQueueHandle);
FifoMTDestroy(pmraaqAvatarsQueue);
- Netlib_CloseHandle(pmraaqAvatarsQueue->hNetlibUser);
+ Netlib_CloseHandle(pmraaqAvatarsQueue->m_hNetlibUser);
mir_free(pmraaqAvatarsQueue);
}
@@ -181,19 +181,19 @@ void CMraProto::MraAvatarsThreadProc(LPVOID lpParameter)
MRA_AVATARS_QUEUE *pmraaqAvatarsQueue = (MRA_AVATARS_QUEUE*)lpParameter;
MRA_AVATARS_QUEUE_ITEM *pmraaqiAvatarsQueueItem;
- char szEMail[MAX_EMAIL_LEN], szServer[MAX_PATH];
- WCHAR wszFileName[MAX_FILEPATH], szErrorText[2048];
+ CMStringA szEmail, szServer;
+ CMStringW wszFileName;
BOOL bContinue, bKeepAlive, bUseKeepAliveConn, bFailed, bDownloadNew, bDefaultAvt;
BYTE btBuff[BUFF_SIZE_RCV];
DWORD dwResultCode, dwAvatarFormat, dwReceived, dwServerPort, dwErrorCode;
- LPSTR lpszUser, lpszDomain;
- size_t dwEMailSize, dwAvatarSizeServer, dwFileNameSize;
+ size_t dwAvatarSizeServer;
FILETIME ftLastModifiedTimeServer, ftLastModifiedTimeLocal;
SYSTEMTIME stAvatarLastModifiedTimeLocal;
- HANDLE hConnection = NULL;
+ HANDLE m_hConnection = NULL;
NETLIBSELECT nls = {0};
INTERNET_TIME itAvatarLastModifiedTimeServer;
PROTO_AVATAR_INFORMATIONT pai;
+ WCHAR szErrorText[2048];
nls.cbSize = sizeof(nls);
pai.cbSize = sizeof(pai);
@@ -206,27 +206,25 @@ void CMraProto::MraAvatarsThreadProc(LPVOID lpParameter)
bDownloadNew = FALSE;
bDefaultAvt = FALSE;
- if (DB_GetStaticStringA(NULL, MRA_AVT_SECT_NAME, "Server", szServer, SIZEOF(szServer), NULL) == FALSE) memmove(szServer, MRA_AVT_DEFAULT_SERVER, sizeof(MRA_AVT_DEFAULT_SERVER));
+ if ( !DB_GetStringA(NULL, MRA_AVT_SECT_NAME, "Server", szServer))
+ szServer = MRA_AVT_DEFAULT_SERVER;
dwServerPort = db_get_dw(NULL, MRA_AVT_SECT_NAME, "ServerPort", MRA_AVT_DEFAULT_SERVER_PORT);
bUseKeepAliveConn = db_get_b(NULL, MRA_AVT_SECT_NAME, "UseKeepAliveConn", MRA_AVT_DEFAULT_USE_KEEPALIVE_CONN);
- if ( mraGetStaticStringA(pmraaqiAvatarsQueueItem->hContact, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize)) {
- BuffToLowerCase(szEMail, szEMail, dwEMailSize);
- lpszDomain = (LPSTR)MemoryFindByte(0, szEMail, dwEMailSize, '@');
- lpszUser = (LPSTR)MemoryFindByte((lpszDomain-szEMail), szEMail, dwEMailSize, '.');
- if (lpszDomain && lpszUser) {
- *lpszUser = 0;
- lpszUser = szEMail;
- *lpszDomain = 0;
- lpszDomain++;
+ if ( mraGetStringA(pmraaqiAvatarsQueueItem->hContact, "e-mail", szEmail)) {
+ szEmail.MakeLower();
+ int iStart = 0;
+ CMStringA szUser = szEmail.Tokenize("@", iStart);
+ CMStringA szDomain = szEmail.Tokenize("@", iStart);
+ if (!szUser.IsEmpty() && !szDomain.IsEmpty()) {
ProtoBroadcastAck(pmraaqiAvatarsQueueItem->hContact, ACKTYPE_AVATAR, ACKRESULT_CONNECTING, NULL, 0);
- if (hConnection == NULL)
- hConnection = MraAvatarsHttpConnect(pmraaqAvatarsQueue->hNetlibUser, szServer, dwServerPort);
- if (hConnection) {
+ if (m_hConnection == NULL)
+ m_hConnection = MraAvatarsHttpConnect(pmraaqAvatarsQueue->m_hNetlibUser, szServer, dwServerPort);
+ if (m_hConnection) {
ProtoBroadcastAck(pmraaqiAvatarsQueueItem->hContact, ACKTYPE_AVATAR, ACKRESULT_CONNECTED, NULL, 0);
ProtoBroadcastAck(pmraaqiAvatarsQueueItem->hContact, ACKTYPE_AVATAR, ACKRESULT_SENTREQUEST, NULL, 0);
- if ( !MraAvatarsHttpTransaction(hConnection, REQUEST_HEAD, lpszUser, lpszDomain, szServer, MAHTRO_AVTMRIM, bUseKeepAliveConn, &dwResultCode, &bKeepAlive, &dwAvatarFormat, &dwAvatarSizeServer, &itAvatarLastModifiedTimeServer)) {
+ if ( !MraAvatarsHttpTransaction(m_hConnection, REQUEST_HEAD, szUser, szDomain, szServer, MAHTRO_AVTMRIM, bUseKeepAliveConn, &dwResultCode, &bKeepAlive, &dwAvatarFormat, &dwAvatarSizeServer, &itAvatarLastModifiedTimeServer)) {
switch (dwResultCode) {
case 200:
if (MraAvatarsGetContactTime(pmraaqiAvatarsQueueItem->hContact, "AvatarLastModifiedTime", &stAvatarLastModifiedTimeLocal)) {
@@ -239,7 +237,7 @@ void CMraProto::MraAvatarsThreadProc(LPVOID lpParameter)
//ProtoBroadcastAck(pmraaqiAvatarsQueueItem->hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, 0, 0);
}
else {// avatar is valid
- if (MraAvatarsGetFileName(pmraaqAvatarsQueue, pmraaqiAvatarsQueueItem->hContact, dwAvatarFormat, wszFileName, SIZEOF(wszFileName), NULL) == NO_ERROR) {
+ if (MraAvatarsGetFileName(pmraaqAvatarsQueue, pmraaqiAvatarsQueueItem->hContact, dwAvatarFormat, wszFileName) == NO_ERROR) {
if ( IsFileExist( wszFileName ))
bFailed = FALSE;
else
@@ -252,9 +250,9 @@ void CMraProto::MraAvatarsThreadProc(LPVOID lpParameter)
break;
case 404:// return def avatar
- if (MraAvatarsGetFileName((HANDLE)pmraaqAvatarsQueue, NULL, PA_FORMAT_DEFAULT, wszFileName, SIZEOF(wszFileName), &dwFileNameSize) == NO_ERROR) {
+ if (MraAvatarsGetFileName((HANDLE)pmraaqAvatarsQueue, NULL, PA_FORMAT_DEFAULT, wszFileName) == NO_ERROR) {
if ( IsFileExist( wszFileName )) {
- dwAvatarFormat = MraAvatarsGetFileFormat(wszFileName, dwFileNameSize);
+ dwAvatarFormat = MraAvatarsGetFileFormat(wszFileName);
bFailed = FALSE;
}
else//loading default avatar
@@ -270,26 +268,26 @@ void CMraProto::MraAvatarsThreadProc(LPVOID lpParameter)
break;
}
}
- if (bUseKeepAliveConn == FALSE || bKeepAlive == FALSE) NETLIB_CLOSEHANDLE(hConnection);
+ if (bUseKeepAliveConn == FALSE || bKeepAlive == FALSE) NETLIB_CLOSEHANDLE(m_hConnection);
}
if (bDownloadNew) {
- if (hConnection == NULL)
- hConnection = MraAvatarsHttpConnect(pmraaqAvatarsQueue->hNetlibUser, szServer, dwServerPort);
+ if (m_hConnection == NULL)
+ m_hConnection = MraAvatarsHttpConnect(pmraaqAvatarsQueue->m_hNetlibUser, szServer, dwServerPort);
- if (hConnection) {
+ if (m_hConnection) {
ProtoBroadcastAck(pmraaqiAvatarsQueueItem->hContact, ACKTYPE_AVATAR, ACKRESULT_DATA, NULL, 0);
- if (MraAvatarsHttpTransaction(hConnection, REQUEST_GET, lpszUser, lpszDomain, szServer, MAHTRO_AVT, bUseKeepAliveConn, &dwResultCode, &bKeepAlive, &dwAvatarFormat, &dwAvatarSizeServer, &itAvatarLastModifiedTimeServer) == NO_ERROR && dwResultCode == 200) {
+ if (MraAvatarsHttpTransaction(m_hConnection, REQUEST_GET, szUser, szDomain, szServer, MAHTRO_AVT, bUseKeepAliveConn, &dwResultCode, &bKeepAlive, &dwAvatarFormat, &dwAvatarSizeServer, &itAvatarLastModifiedTimeServer) == NO_ERROR && dwResultCode == 200) {
if (bDefaultAvt)
dwAvatarFormat = PA_FORMAT_DEFAULT;
- if ( !MraAvatarsGetFileName(pmraaqAvatarsQueue, pmraaqiAvatarsQueueItem->hContact, dwAvatarFormat, wszFileName, SIZEOF(wszFileName), NULL)) {
+ if ( !MraAvatarsGetFileName(pmraaqAvatarsQueue, pmraaqiAvatarsQueueItem->hContact, dwAvatarFormat, wszFileName)) {
HANDLE hFile = CreateFile(wszFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE) {
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] = hConnection;
+ nls.hReadConns[0] = m_hConnection;
while ( bContinue ) {
switch (CallService(MS_NETLIB_SELECT, 0, (LPARAM)&nls)) {
@@ -300,7 +298,7 @@ void CMraProto::MraAvatarsThreadProc(LPVOID lpParameter)
bContinue = FALSE;
break;
case 1:
- dwReceived = Netlib_Recv(hConnection, (LPSTR)&btBuff, SIZEOF(btBuff), 0);
+ dwReceived = Netlib_Recv(m_hConnection, (LPSTR)&btBuff, SIZEOF(btBuff), 0);
if (dwReceived == 0 || dwReceived == SOCKET_ERROR) {
dwErrorCode = GetLastError();
ShowFormattedErrorMessage(L"Avatars: error on receive file data", dwErrorCode);
@@ -333,7 +331,7 @@ void CMraProto::MraAvatarsThreadProc(LPVOID lpParameter)
}
else DebugBreak();
- if (bUseKeepAliveConn == FALSE || bKeepAlive == FALSE) NETLIB_CLOSEHANDLE(hConnection);
+ if (bUseKeepAliveConn == FALSE || bKeepAlive == FALSE) NETLIB_CLOSEHANDLE(m_hConnection);
}
}
}
@@ -366,7 +364,7 @@ void CMraProto::MraAvatarsThreadProc(LPVOID lpParameter)
mir_free(pmraaqiAvatarsQueueItem);
}
else { // waiting until service stop or new task
- NETLIB_CLOSEHANDLE(hConnection);
+ NETLIB_CLOSEHANDLE(m_hConnection);
WaitForSingleObjectEx(pmraaqAvatarsQueue->hThreadEvent, MRA_AVT_DEFAULT_QE_CHK_INTERVAL, FALSE);
}
}
@@ -374,29 +372,29 @@ void CMraProto::MraAvatarsThreadProc(LPVOID lpParameter)
InterlockedDecrement((volatile LONG*)&pmraaqAvatarsQueue->lThreadsRunningCount);
}
-HANDLE MraAvatarsHttpConnect(HANDLE hNetlibUser, LPSTR lpszHost, DWORD dwPort)
+HANDLE MraAvatarsHttpConnect(HANDLE m_hNetlibUser, LPCSTR lpszHost, DWORD dwPort)
{
NETLIBOPENCONNECTION nloc = {0};
nloc.cbSize = sizeof(nloc);
nloc.flags = (NLOCF_HTTP|NLOCF_V2);
nloc.szHost = lpszHost;
- nloc.wPort = ( IsHTTPSProxyUsed(hNetlibUser)) ? MRA_SERVER_PORT_HTTPS : dwPort;
+ nloc.wPort = ( IsHTTPSProxyUsed(m_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_МАХ) nloc.timeout = MRA_TIMEOUT_CONN_МАХ;
DWORD dwConnectReTryCount = db_get_dw(NULL, MRA_AVT_SECT_NAME, "ConnectReTryCount", MRA_AVT_DEFAULT_CONN_RETRY_COUNT);
DWORD dwCurConnectReTryCount = dwConnectReTryCount;
- HANDLE hConnection;
+ HANDLE m_hConnection;
do {
- hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)hNetlibUser, (LPARAM)&nloc);
+ m_hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc);
}
- while (--dwCurConnectReTryCount && hConnection == NULL);
+ while (--dwCurConnectReTryCount && m_hConnection == NULL);
- return hConnection;
+ return m_hConnection;
}
-DWORD MraAvatarsHttpTransaction(HANDLE hConnection, DWORD dwRequestType, LPSTR lpszUser, LPSTR lpszDomain, LPSTR lpszHost, DWORD dwReqObj, BOOL bUseKeepAliveConn, DWORD *pdwResultCode, BOOL *pbKeepAlive, DWORD *pdwFormat, size_t *pdwAvatarSize, INTERNET_TIME *pitLastModifiedTime)
+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)
{
if (pdwResultCode) *pdwResultCode = 0;
if (pbKeepAlive) *pbKeepAlive = FALSE;
@@ -404,7 +402,7 @@ DWORD MraAvatarsHttpTransaction(HANDLE hConnection, DWORD dwRequestType, LPSTR l
if (pdwAvatarSize) *pdwAvatarSize = 0;
if (pitLastModifiedTime) bzero(pitLastModifiedTime, sizeof(INTERNET_TIME));
- if (!hConnection)
+ if (!m_hConnection)
return ERROR_INVALID_HANDLE;
LPSTR lpszReqObj;
@@ -417,12 +415,12 @@ DWORD MraAvatarsHttpTransaction(HANDLE hConnection, DWORD dwRequestType, LPSTR l
default: lpszReqObj = ""; break;
}
- char szBuff[4096], szSelfVersionString[MAX_PATH];
+ char szBuff[4096];
DWORD dwBuffSize = mir_snprintf(szBuff, SIZEOF(szBuff), "http://%s/%s/%s/%s", lpszHost, lpszDomain, lpszUser, lpszReqObj);
- MraGetSelfVersionString(szSelfVersionString, SIZEOF(szSelfVersionString), NULL);
+ CMStringA szSelfVersionString = MraGetSelfVersionString();
NETLIBHTTPHEADER nlbhHeaders[8] = {0};
- nlbhHeaders[0].szName = "User-Agent"; nlbhHeaders[0].szValue = szSelfVersionString;
+ nlbhHeaders[0].szName = "User-Agent"; nlbhHeaders[0].szValue = (LPSTR)szSelfVersionString.c_str();
nlbhHeaders[1].szName = "Accept-Encoding"; nlbhHeaders[1].szValue = "deflate";
nlbhHeaders[2].szName = "Pragma"; nlbhHeaders[2].szValue = "no-cache";
nlbhHeaders[3].szName = "Connection"; nlbhHeaders[3].szValue = (bUseKeepAliveConn)? "keep-alive":"close";
@@ -435,11 +433,11 @@ DWORD MraAvatarsHttpTransaction(HANDLE hConnection, DWORD dwRequestType, LPSTR l
nlhr.headers = (NETLIBHTTPHEADER*)&nlbhHeaders;
nlhr.headersCount = 4;
- DWORD dwSent = CallService(MS_NETLIB_SENDHTTPREQUEST, (WPARAM)hConnection, (LPARAM)&nlhr);
+ DWORD dwSent = CallService(MS_NETLIB_SENDHTTPREQUEST, (WPARAM)m_hConnection, (LPARAM)&nlhr);
if (dwSent == SOCKET_ERROR || !dwSent)
return GetLastError();
- pnlhr = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_RECVHTTPHEADERS, (WPARAM)hConnection, 0);
+ pnlhr = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_RECVHTTPHEADERS, (WPARAM)m_hConnection, 0);
if (!pnlhr)
return GetLastError();
@@ -464,7 +462,7 @@ DWORD MraAvatarsHttpTransaction(HANDLE hConnection, DWORD dwRequestType, LPSTR l
}
else if ( !_strnicmp(pnlhr->headers[i].szName, "Last-Modified", 13)) {
if (pitLastModifiedTime)
- InternetTimeGetTime(pnlhr->headers[i].szValue, lstrlenA(pnlhr->headers[i].szValue), pitLastModifiedTime);
+ InternetTimeGetTime(pnlhr->headers[i].szValue, pitLastModifiedTime);
}
}
@@ -473,15 +471,13 @@ DWORD MraAvatarsHttpTransaction(HANDLE hConnection, DWORD dwRequestType, LPSTR l
return 0;
}
-BOOL CMraProto::MraAvatarsGetContactTime(HANDLE hContact, LPSTR lpszValueName, SYSTEMTIME *pstTime)
+bool CMraProto::MraAvatarsGetContactTime(HANDLE hContact, LPSTR lpszValueName, SYSTEMTIME *pstTime)
{
if (lpszValueName && pstTime) {
- char szBuff[MAX_PATH];
- size_t dwBuffSize;
INTERNET_TIME itAvatarLastModifiedTimeLocal;
-
- if (mraGetStaticStringA(hContact, lpszValueName, (LPSTR)szBuff, SIZEOF(szBuff), &dwBuffSize))
- if (InternetTimeGetTime(szBuff, dwBuffSize, &itAvatarLastModifiedTimeLocal) == NO_ERROR) {
+ CMStringA szBuff;
+ if (mraGetStringA(hContact, lpszValueName, szBuff))
+ if (InternetTimeGetTime(szBuff, &itAvatarLastModifiedTimeLocal) == NO_ERROR) {
memmove(pstTime, &itAvatarLastModifiedTimeLocal.stTime, sizeof(SYSTEMTIME));
return TRUE;
}
@@ -495,27 +491,23 @@ void CMraProto::MraAvatarsSetContactTime(HANDLE hContact, LPSTR lpszValueName, S
if (!lpszValueName)
return;
- char szBuff[MAX_PATH];
- size_t dwBuffUsedSize;
INTERNET_TIME itTime;
-
if (pstTime) {
itTime.lTimeZone = 0;
memmove(&itTime.stTime, pstTime, sizeof(SYSTEMTIME));
}
else InternetTimeGetCurrentTime(&itTime);
- if (itTime.stTime.wYear) {
- InternetTimeGetString(&itTime, (LPSTR)szBuff, SIZEOF(szBuff), &dwBuffUsedSize);
- mraSetStringExA(hContact, lpszValueName, (LPSTR)szBuff, dwBuffUsedSize);
- }
- else delSetting(hContact, lpszValueName);
+ if (itTime.stTime.wYear)
+ mraSetStringExA(hContact, lpszValueName, InternetTimeGetString(&itTime));
+ else
+ delSetting(hContact, lpszValueName);
}
-DWORD MraAvatarsGetFileFormat(LPTSTR lpszPath, size_t dwPathSize)
+DWORD MraAvatarsGetFileFormat(const CMString &lpszPath)
{
TCHAR dwExt[ 5 ];
- BuffToLowerCase(&dwExt, lpszPath+(dwPathSize-4), 4);
+ BuffToLowerCase(&dwExt, lpszPath.c_str()+lpszPath.GetLength()-4, 4);
for ( DWORD i = 0; i < PA_FORMAT_MAX; i++ )
if ( !_tcscmp( dwExt, lpcszExtensions[i]))
@@ -525,57 +517,43 @@ DWORD MraAvatarsGetFileFormat(LPTSTR lpszPath, size_t dwPathSize)
}
-DWORD CMraProto::MraAvatarsGetFileName(HANDLE hAvatarsQueueHandle, HANDLE hContact, DWORD dwFormat, LPTSTR lpszPath, size_t dwPathSize, size_t *pdwPathSizeRet)
+DWORD CMraProto::MraAvatarsGetFileName(HANDLE hAvatarsQueueHandle, HANDLE hContact, DWORD dwFormat, CMStringW &res)
{
+ res.Empty();
if (hAvatarsQueueHandle == NULL)
return ERROR_INVALID_HANDLE;
if (IsContactChatAgent(hContact))
return ERROR_NOT_SUPPORTED;
- LPTSTR lpszCurPath = lpszPath;
- size_t dwEMailSize;
MRA_AVATARS_QUEUE *pmraaqAvatarsQueue = (MRA_AVATARS_QUEUE*)hAvatarsQueueHandle;
+ WCHAR wszBase[MAX_PATH];
if (pmraaqAvatarsQueue->hAvatarsPath == NULL)
// default path
- dwEMailSize = mir_sntprintf(lpszPath, dwPathSize, _T("%s\\%s\\"), (TCHAR*)VARST( _T("%miranda_avatarcache%")), m_tszUserName);
+ mir_snwprintf(wszBase, SIZEOF(wszBase), _T("%s\\%s\\"), (TCHAR*)VARST( _T("%miranda_avatarcache%")), m_tszUserName);
else {
- FoldersGetCustomPathT(pmraaqAvatarsQueue->hAvatarsPath, lpszCurPath, int(dwPathSize), _T(""));
- dwEMailSize = lstrlen( lpszCurPath );
- _tcscpy( lpszCurPath + dwEMailSize, _T("\\"));
- dwEMailSize++;
+ FoldersGetCustomPathW(pmraaqAvatarsQueue->hAvatarsPath, wszBase, SIZEOF(wszBase), _T(""));
+ wcscat(wszBase, L"\\");
}
+ res = wszBase;
- dwPathSize -= dwEMailSize;
- lpszCurPath += dwEMailSize;
-
- if (dwPathSize) {
- // some path in buff and free space for file name is avaible
- CreateDirectoryTreeT(lpszPath);
-
- if (dwFormat != PA_FORMAT_DEFAULT) {
- if ( mraGetStaticStringW(hContact, "e-mail", lpszCurPath, dwPathSize-5, &dwEMailSize)) {
- BuffToLowerCase(lpszCurPath, lpszCurPath, dwEMailSize);
- lpszCurPath += dwEMailSize;
- _tcscpy( lpszCurPath, lpcszExtensions[dwFormat] );
- lpszCurPath += 4;
- *lpszCurPath = 0;
+ // some path in buff and free space for file name is avaible
+ CreateDirectoryTreeT(res);
- if ( pdwPathSizeRet )
- *pdwPathSizeRet = lpszCurPath - lpszPath;
- return NO_ERROR;
- }
+ if (dwFormat != PA_FORMAT_DEFAULT) {
+ CMStringW szEmail;
+ if ( mraGetStringW(hContact, "e-mail", szEmail)) {
+ szEmail.MakeLower();
+ res += szEmail + lpcszExtensions[dwFormat];
+ return NO_ERROR;
}
- else {
- if ( DB_GetStaticStringW(NULL, MRA_AVT_SECT_NAME, "DefaultAvatarFileName", lpszCurPath, dwPathSize-5, &dwEMailSize ) == FALSE) {
- _tcscpy(lpszCurPath, MRA_AVT_DEFAULT_AVT_FILENAME);
- lpszCurPath += SIZEOF( MRA_AVT_DEFAULT_AVT_FILENAME )-1;
-
- if (pdwPathSizeRet)
- *pdwPathSizeRet = lpszCurPath - lpszPath;
- return NO_ERROR;
- }
+ }
+ else {
+ CMStringW szDefName;
+ if ( !DB_GetStringW(NULL, MRA_AVT_SECT_NAME, "DefaultAvatarFileName", szDefName)) {
+ res += MRA_AVT_DEFAULT_AVT_FILENAME;
+ return NO_ERROR;
}
}
@@ -596,8 +574,7 @@ DWORD CMraProto::MraAvatarsQueueGetAvatar(HANDLE hAvatarsQueueHandle, DWORD dwFl
if ((dwFlags & GAIF_FORCE) == 0)// если флаг принудит. обновления, то даже не проверяем времени последнего обновления
if (MraAvatarsGetContactTime(hContact, "AvatarLastCheckTime", &stAvatarLastCheckTime)) {
- TCHAR wszFileName[MAX_FILEPATH];
- size_t dwPathSize;
+ CMStringW wszFileName;
FILETIME ftCurrentTime, ftExpireTime;
GetSystemTimeAsFileTime(&ftCurrentTime);
@@ -605,7 +582,7 @@ DWORD CMraProto::MraAvatarsQueueGetAvatar(HANDLE hAvatarsQueueHandle, DWORD dwFl
(*((DWORDLONG*)&ftExpireTime)) += (FILETIME_MINUTE*(DWORDLONG)db_get_dw(NULL, MRA_AVT_SECT_NAME, "CheckInterval", MRA_AVT_DEFAULT_CHK_INTERVAL));
if ((*((DWORDLONG*)&ftExpireTime))>(*((DWORDLONG*)&ftCurrentTime)))
- if ( MraAvatarsGetFileName(hAvatarsQueueHandle, hContact, GetContactAvatarFormat(hContact, PA_FORMAT_DEFAULT), wszFileName, SIZEOF(wszFileName), &dwPathSize) == NO_ERROR)
+ if ( MraAvatarsGetFileName(hAvatarsQueueHandle, hContact, GetContactAvatarFormat(hContact, PA_FORMAT_DEFAULT), wszFileName) == NO_ERROR)
if ( IsFileExist( wszFileName )) {
// файл с аватаром существует и не устарел/не было комманды обновлять(просто запрос имени)
if (lpszPath) {
@@ -670,12 +647,11 @@ INT_PTR CALLBACK MraAvatarsQueueDlgProcOpts(HWND hWndDlg, UINT msg, WPARAM wPara
SetWindowLongPtr(hWndDlg, GWLP_USERDATA, lParam);
ppro = (CMraProto*)lParam;
{
- WCHAR szServer[MAX_PATH];
-
CHECK_DLG_BUTTON(hWndDlg, IDC_ENABLE, db_get_b(NULL, MRA_AVT_SECT_NAME, "Enable", MRA_AVT_DEFAULT_ENABLE));
- if (DB_GetStaticStringW(NULL, MRA_AVT_SECT_NAME, "Server", szServer, MAX_PATH, NULL))
- SET_DLG_ITEM_TEXT(hWndDlg, IDC_SERVER, szServer);
+ CMStringW szServer;
+ if (DB_GetStringW(NULL, MRA_AVT_SECT_NAME, "Server", szServer))
+ SET_DLG_ITEM_TEXT(hWndDlg, IDC_SERVER, szServer.c_str());
else
SET_DLG_ITEM_TEXTA(hWndDlg, IDC_SERVER, MRA_AVT_DEFAULT_SERVER);
@@ -735,8 +711,8 @@ DWORD CMraProto::MraAvatarsDeleteContactAvatarFile(HANDLE hAvatarsQueueHandle, H
DWORD dwAvatarFormat = GetContactAvatarFormat(hContact, PA_FORMAT_UNKNOWN);
if ( db_get_b(NULL, MRA_AVT_SECT_NAME, "DeleteAvtOnContactDelete", MRA_DELETE_AVT_ON_CONTACT_DELETE) && dwAvatarFormat != PA_FORMAT_DEFAULT) {
- TCHAR szFileName[MAX_FILEPATH];
- if ( !MraAvatarsGetFileName(hAvatarsQueueHandle, hContact, dwAvatarFormat, szFileName, SIZEOF(szFileName), NULL))
+ CMStringW szFileName;
+ if ( !MraAvatarsGetFileName(hAvatarsQueueHandle, hContact, dwAvatarFormat, szFileName))
return DeleteFile(szFileName);
}
return NO_ERROR;
diff --git a/protocols/MRA/src/MraChat.cpp b/protocols/MRA/src/MraChat.cpp
index beb07b9dcc..b607571436 100644
--- a/protocols/MRA/src/MraChat.cpp
+++ b/protocols/MRA/src/MraChat.cpp
@@ -7,14 +7,12 @@ static LPWSTR lpwszStatuses[] = { L"Owners", L"Inviter", L"Visitors" };
#define MRA_CHAT_STATUS_INVITER 1
#define MRA_CHAT_STATUS_VISITOR 2
-void MraChatSendPrivateMessage(LPWSTR lpwszEMail);
-
void CMraProto::MraChatDllError()
{
MessageBoxW(NULL, TranslateW(L"CHAT plugin is required for conferences. Install it before chatting"), m_tszUserName, (MB_OK|MB_ICONWARNING));
}
-BOOL CMraProto::MraChatRegister()
+bool CMraProto::MraChatRegister()
{
if ( !ServiceExists(MS_GC_REGISTER))
return FALSE;
@@ -37,25 +35,23 @@ INT_PTR CMraProto::MraChatSessionNew(HANDLE hContact)
if (bChatExists)
if (hContact) {
GCSESSION gcw = {0};
- WCHAR wszEMail[MAX_EMAIL_LEN] = {0};
+ CMStringW wszEMail;
+ mraGetStringW(hContact, "e-mail", wszEMail);
gcw.cbSize = sizeof(GCSESSION);
gcw.iType = GCW_CHATROOM;
gcw.pszModule = m_szModuleName;
gcw.ptszName = GetContactNameW(hContact);
- gcw.ptszID = (LPWSTR)wszEMail;
+ gcw.ptszID = wszEMail;
gcw.ptszStatusbarText = L"status bar";
gcw.dwFlags = GC_UNICODE;
gcw.dwItemData = (DWORD)hContact;
- mraGetStaticStringW(hContact, "e-mail", wszEMail, SIZEOF(wszEMail), NULL);
if ( !CallServiceSync(MS_GC_NEWSESSION, NULL, (LPARAM)&gcw)) {
- CHAR szEMail[MAX_EMAIL_LEN] = {0};
- size_t dwEMailSize;
GCDEST gcd = {0};
GCEVENT gce = {0};
gcd.pszModule = m_szModuleName;
- gcd.ptszID = (LPWSTR)wszEMail;
+ gcd.ptszID = (TCHAR*)wszEMail.c_str();
gcd.iType = GC_EVENT_ADDGROUP;
gce.cbSize = sizeof(GCEVENT);
@@ -73,10 +69,10 @@ INT_PTR CMraProto::MraChatSessionNew(HANDLE hContact)
CallServiceSync(MS_GC_EVENT, SESSION_INITDONE, (LPARAM)&gce);
CallServiceSync(MS_GC_EVENT, SESSION_ONLINE, (LPARAM)&gce);
- //MraChatSessionJoinUser(hContact, NULL, 0, 0);
- (*(DWORD*)wszEMail) = MULTICHAT_GET_MEMBERS;
- mraGetStaticStringA(hContact, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize);
- MraMessageW(FALSE, NULL, 0, MESSAGE_FLAG_MULTICHAT, szEMail, dwEMailSize, NULL, 0, (LPBYTE)wszEMail, 4);
+ DWORD opcode = MULTICHAT_GET_MEMBERS;
+ CMStringA szEmail;
+ mraGetStringA(hContact, "e-mail", szEmail);
+ MraMessageW(FALSE, NULL, 0, MESSAGE_FLAG_MULTICHAT, szEmail, L"", (LPBYTE)&opcode, sizeof(opcode));
return 0;
}
}
@@ -90,13 +86,13 @@ void CMraProto::MraChatSessionDestroy(HANDLE hContact)
GCDEST gcd = {0};
GCEVENT gce = {0};
- WCHAR wszEMail[MAX_EMAIL_LEN] = {0};
+ CMStringW wszEMail;
gcd.pszModule = m_szModuleName;
gcd.iType = GC_EVENT_CONTROL;
if (hContact) {
- gcd.ptszID = (LPWSTR)wszEMail;
- mraGetStaticStringW(hContact, "e-mail", wszEMail, SIZEOF(wszEMail), NULL);
+ mraGetStringW(hContact, "e-mail", wszEMail);
+ gcd.ptszID = (LPWSTR)wszEMail.c_str();
}
gce.cbSize = sizeof(GCEVENT);
gce.pDest = &gcd;
@@ -106,18 +102,18 @@ void CMraProto::MraChatSessionDestroy(HANDLE hContact)
CallServiceSync(MS_GC_EVENT, WINDOW_CLEARLOG, (LPARAM)&gce);
}
-INT_PTR CMraProto::MraChatSessionEventSendByHandle(HANDLE hContactChatSession, DWORD dwType, DWORD dwFlags, LPSTR lpszUID, size_t dwUIDSize, LPWSTR lpwszStatus, LPWSTR lpwszMessage, DWORD_PTR dwItemData, DWORD dwTime)
+INT_PTR CMraProto::MraChatSessionEventSendByHandle(HANDLE hContactChatSession, DWORD dwType, DWORD dwFlags, const CMStringA &lpszUID, LPCWSTR lpwszStatus, LPCWSTR lpwszMessage, DWORD_PTR dwItemData, DWORD dwTime)
{
if (!bChatExists)
return 1;
- WCHAR wszID[MAX_EMAIL_LEN] = {0}, wszUID[MAX_EMAIL_LEN] = {0}, wszNick[MAX_EMAIL_LEN] = {0};
+ CMStringW wszID, wszUID, wszNick;
GCDEST gcd = {0};
gcd.pszModule = m_szModuleName;
if (hContactChatSession) {
- gcd.ptszID = (LPWSTR)wszID;
- mraGetStaticStringW(hContactChatSession, "e-mail", wszID, SIZEOF(wszID), NULL);
+ mraGetStringW(hContactChatSession, "e-mail", wszID);
+ gcd.ptszID = (LPWSTR)wszID.c_str();
}
gcd.iType = dwType;
@@ -131,19 +127,19 @@ INT_PTR CMraProto::MraChatSessionEventSendByHandle(HANDLE hContactChatSession, D
gce.dwItemData = dwItemData;
gce.time = dwTime;
- if (lpszUID && dwUIDSize)
- gce.bIsMe = IsEMailMy(lpszUID, dwUIDSize);
+ if (!lpszUID.IsEmpty())
+ gce.bIsMe = IsEMailMy(lpszUID);
else
gce.bIsMe = TRUE;
if (gce.bIsMe) {
- mraGetStaticStringW(NULL, "e-mail", wszUID, SIZEOF(wszUID), NULL);
- mraGetStaticStringW(NULL, "Nick", wszNick, SIZEOF(wszNick), NULL);
+ mraGetStringW(NULL, "e-mail", wszUID);
+ mraGetStringW(NULL, "Nick", wszNick);
gce.ptszNick = wszNick;
}
else {
- HANDLE hContactSender = MraHContactFromEmail(lpszUID, dwUIDSize, FALSE, TRUE, NULL);
- MultiByteToWideChar(MRA_CODE_PAGE, 0, lpszUID, (DWORD)dwUIDSize, wszUID, SIZEOF(wszUID));
+ HANDLE hContactSender = MraHContactFromEmail(lpszUID, FALSE, TRUE, NULL);
+ wszUID = lpszUID;
if (hContactSender)
gce.ptszNick = GetContactNameW(hContactSender);
else
@@ -153,68 +149,64 @@ INT_PTR CMraProto::MraChatSessionEventSendByHandle(HANDLE hContactChatSession, D
return CallServiceSync(MS_GC_EVENT, NULL, (LPARAM)&gce);
}
-INT_PTR CMraProto::MraChatSessionInvite(HANDLE hContactChatSession, LPSTR lpszEMailInMultiChat, size_t dwEMailInMultiChatSize, DWORD dwTime)
+INT_PTR CMraProto::MraChatSessionInvite(HANDLE hContactChatSession, const CMStringA &lpszEMailInMultiChat, DWORD dwTime)
{
if (!hContactChatSession)
return 1;
- WCHAR wszBuff[((MAX_EMAIL_LEN*2)+MAX_PATH)];
- mir_sntprintf(wszBuff, SIZEOF(wszBuff), L"[%s]: %s", _A2T(lpszEMailInMultiChat), TranslateW(L"invite sender"));
- return MraChatSessionEventSendByHandle(hContactChatSession, GC_EVENT_ACTION, GCEF_ADDTOLOG, lpszEMailInMultiChat, dwEMailInMultiChatSize, NULL, wszBuff, 0, dwTime);
+ CMStringW wszBuff;
+ wszBuff.Format(L"[%s]: %s", _A2T(lpszEMailInMultiChat.c_str()), TranslateW(L"invite sender"));
+ return MraChatSessionEventSendByHandle(hContactChatSession, GC_EVENT_ACTION, GCEF_ADDTOLOG, lpszEMailInMultiChat, NULL, wszBuff, 0, dwTime);
}
-INT_PTR CMraProto::MraChatSessionMembersAdd(HANDLE hContactChatSession, LPSTR lpszEMailInMultiChat, size_t dwEMailInMultiChatSize, DWORD dwTime)
+INT_PTR CMraProto::MraChatSessionMembersAdd(HANDLE hContactChatSession, const CMStringA &lpszEMailInMultiChat, DWORD dwTime)
{
if (!hContactChatSession)
return 1;
- WCHAR wszBuff[((MAX_EMAIL_LEN*2)+MAX_PATH)];
- mir_sntprintf(wszBuff, SIZEOF(wszBuff), L"[%s]: %s", _A2T(lpszEMailInMultiChat), TranslateW(L"invite new members"));
- return MraChatSessionEventSendByHandle(hContactChatSession, GC_EVENT_ACTION, GCEF_ADDTOLOG, lpszEMailInMultiChat, dwEMailInMultiChatSize, NULL, wszBuff, 0, dwTime);
+ CMStringW wszBuff;
+ wszBuff.Format(L"[%s]: %s", _A2T(lpszEMailInMultiChat), TranslateW(L"invite new members"));
+ return MraChatSessionEventSendByHandle(hContactChatSession, GC_EVENT_ACTION, GCEF_ADDTOLOG, lpszEMailInMultiChat, NULL, wszBuff, 0, dwTime);
}
-INT_PTR CMraProto::MraChatSessionJoinUser(HANDLE hContactChatSession, LPSTR lpszEMailInMultiChat, size_t dwEMailInMultiChatSize, DWORD dwTime)
+INT_PTR CMraProto::MraChatSessionJoinUser(HANDLE hContactChatSession, const CMStringA &lpszEMailInMultiChat, DWORD dwTime)
{
if (hContactChatSession)
- return MraChatSessionEventSendByHandle(hContactChatSession, GC_EVENT_JOIN, GCEF_ADDTOLOG, lpszEMailInMultiChat, dwEMailInMultiChatSize, lpwszStatuses[MRA_CHAT_STATUS_VISITOR], L"", 0, dwTime);
+ return MraChatSessionEventSendByHandle(hContactChatSession, GC_EVENT_JOIN, GCEF_ADDTOLOG, lpszEMailInMultiChat, lpwszStatuses[MRA_CHAT_STATUS_VISITOR], L"", 0, dwTime);
return 1;
}
-INT_PTR CMraProto::MraChatSessionLeftUser(HANDLE hContactChatSession, LPSTR lpszEMailInMultiChat, size_t dwEMailInMultiChatSize, DWORD dwTime)
+INT_PTR CMraProto::MraChatSessionLeftUser(HANDLE hContactChatSession, const CMStringA &lpszEMailInMultiChat, DWORD dwTime)
{
if (hContactChatSession)
- return MraChatSessionEventSendByHandle(hContactChatSession, GC_EVENT_PART, GCEF_ADDTOLOG, lpszEMailInMultiChat, dwEMailInMultiChatSize, NULL, NULL, 0, dwTime);
+ return MraChatSessionEventSendByHandle(hContactChatSession, GC_EVENT_PART, GCEF_ADDTOLOG, lpszEMailInMultiChat, NULL, NULL, 0, dwTime);
return 1;
}
-INT_PTR CMraProto::MraChatSessionSetIviter(HANDLE hContactChatSession, LPSTR lpszEMailInMultiChat, size_t dwEMailInMultiChatSize)
+INT_PTR CMraProto::MraChatSessionSetIviter(HANDLE hContactChatSession, const CMStringA &lpszEMailInMultiChat)
{
- if (hContactChatSession && lpszEMailInMultiChat && dwEMailInMultiChatSize)
- return MraChatSessionEventSendByHandle(hContactChatSession, GC_EVENT_ADDSTATUS, 0, lpszEMailInMultiChat, dwEMailInMultiChatSize, lpwszStatuses[MRA_CHAT_STATUS_INVITER], NULL, 0, 0);
+ if (hContactChatSession && !lpszEMailInMultiChat.IsEmpty())
+ return MraChatSessionEventSendByHandle(hContactChatSession, GC_EVENT_ADDSTATUS, 0, lpszEMailInMultiChat, lpwszStatuses[MRA_CHAT_STATUS_INVITER], NULL, 0, 0);
return 1;
}
-INT_PTR CMraProto::MraChatSessionSetOwner(HANDLE hContactChatSession, LPSTR lpszEMailInMultiChat, size_t dwEMailInMultiChatSize)
+INT_PTR CMraProto::MraChatSessionSetOwner(HANDLE hContactChatSession, const CMStringA &lpszEMailInMultiChat)
{
- if (hContactChatSession && lpszEMailInMultiChat && dwEMailInMultiChatSize)
- return MraChatSessionEventSendByHandle(hContactChatSession, GC_EVENT_ADDSTATUS, 0, lpszEMailInMultiChat, dwEMailInMultiChatSize, lpwszStatuses[MRA_CHAT_STATUS_OWNER], NULL, 0, 0);
+ if (hContactChatSession && !lpszEMailInMultiChat.IsEmpty())
+ return MraChatSessionEventSendByHandle(hContactChatSession, GC_EVENT_ADDSTATUS, 0, lpszEMailInMultiChat, lpwszStatuses[MRA_CHAT_STATUS_OWNER], NULL, 0, 0);
return 1;
}
-INT_PTR CMraProto::MraChatSessionMessageAdd(HANDLE hContactChatSession, LPSTR lpszEMailInMultiChat, size_t dwEMailInMultiChatSize, LPWSTR lpwszMessage, size_t dwMessageSize, DWORD dwTime)
+INT_PTR CMraProto::MraChatSessionMessageAdd(HANDLE hContactChatSession, const CMStringA &lpszEMailInMultiChat, const CMStringW &lpwszMessage, DWORD dwTime)
{
- if (hContactChatSession) {
- LPWSTR lpwszMessageLocal = (LPWSTR)_alloca((dwMessageSize*sizeof(WCHAR)));
- if (lpwszMessageLocal) { // we need zeros after text allways
- memmove((LPVOID)lpwszMessageLocal, lpwszMessage, (dwMessageSize*sizeof(WCHAR)));//gce.ptszText = lpwszMessage;
- return MraChatSessionEventSendByHandle(hContactChatSession, GC_EVENT_MESSAGE, GCEF_ADDTOLOG, lpszEMailInMultiChat, dwEMailInMultiChatSize, NULL, lpwszMessageLocal, 0, dwTime);
- }
- }
+ if (hContactChatSession)
+ return MraChatSessionEventSendByHandle(hContactChatSession, GC_EVENT_MESSAGE, GCEF_ADDTOLOG, lpszEMailInMultiChat, NULL, lpwszMessage, 0, dwTime);
+
return 1;
}
@@ -228,27 +220,25 @@ int CMraProto::MraChatGcEventHook(WPARAM, LPARAM lParam)
switch (gch->pDest->iType) {
case GC_USER_MESSAGE:
if (gch->ptszText && lstrlen(gch->ptszText)) {
- CHAR szEMail[MAX_EMAIL_LEN] = {0};
-
size_t dwMessageSize = lstrlenW(gch->ptszText);
- size_t dwEMailSize = (WideCharToMultiByte(MRA_CODE_PAGE, 0, gch->pDest->ptszID, -1, szEMail, SIZEOF(szEMail), NULL, NULL)-1);
- HANDLE hContact = MraHContactFromEmail(szEMail, dwEMailSize, FALSE, TRUE, NULL);
+ CMStringA szEmail = gch->pDest->ptszID;
+ HANDLE hContact = MraHContactFromEmail(szEmail, FALSE, TRUE, NULL);
BOOL bSlowSend = getByte("SlowSend", MRA_DEFAULT_SLOW_SEND);
DWORD dwFlags = 0;
if (getByte("RTFSendEnable", MRA_DEFAULT_RTF_SEND_ENABLE) && (MraContactCapabilitiesGet(hContact)&FEATURE_FLAG_RTF_MESSAGE))
dwFlags |= MESSAGE_FLAG_RTF;
- INT_PTR iSendRet = MraMessageW(bSlowSend, hContact, ACKTYPE_MESSAGE, dwFlags, szEMail, dwEMailSize, gch->ptszText, dwMessageSize, NULL, 0);
+ INT_PTR iSendRet = MraMessageW(bSlowSend, hContact, ACKTYPE_MESSAGE, dwFlags, szEmail, gch->ptszText, NULL, 0);
if (bSlowSend == FALSE)
ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)iSendRet, 0);
- MraChatSessionEventSendByHandle(hContact, GC_EVENT_MESSAGE, GCEF_ADDTOLOG, NULL, 0, NULL, gch->ptszText, 0, (DWORD)_time32(NULL));
+ MraChatSessionEventSendByHandle(hContact, GC_EVENT_MESSAGE, GCEF_ADDTOLOG, "", NULL, gch->ptszText, 0, (DWORD)_time32(NULL));
}
break;
case GC_USER_PRIVMESS:
- MraChatSendPrivateMessage(gch->ptszUID);
+ MraChatSendPrivateMessage( _T2A(gch->ptszUID));
break;
case GC_USER_LOGMENU:
@@ -270,13 +260,10 @@ int CMraProto::MraChatGcEventHook(WPARAM, LPARAM lParam)
return 0;
}
-void CMraProto::MraChatSendPrivateMessage(LPWSTR lpwszEMail)
+void CMraProto::MraChatSendPrivateMessage(LPSTR lpszEMail)
{
- CHAR szEMail[MAX_EMAIL_LEN] = {0};
- size_t dwEMailSize = WideCharToMultiByte(MRA_CODE_PAGE, 0, lpwszEMail, -1, szEMail, SIZEOF(szEMail), NULL, NULL)-1;
-
BOOL bAdded;
- HANDLE hContact = MraHContactFromEmail(szEMail, dwEMailSize, TRUE, TRUE, &bAdded);
+ HANDLE hContact = MraHContactFromEmail(lpszEMail, TRUE, TRUE, &bAdded);
if (bAdded)
db_set_b(hContact, "CList", "Hidden", 1);
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);
}
diff --git a/protocols/MRA/src/MraMPop.cpp b/protocols/MRA/src/MraMPop.cpp
index 16f28645d7..ca40b233e9 100644
--- a/protocols/MRA/src/MraMPop.cpp
+++ b/protocols/MRA/src/MraMPop.cpp
@@ -4,7 +4,7 @@
// MPOP_SESSION
struct MRA_MPOP_SESSION_QUEUE : public FIFO_MT
{
- BOOL bKeyValid;
+ bool bKeyValid;
LPSTR lpszMPOPKey;
size_t dwMPOPKeySize;
};
@@ -53,7 +53,7 @@ void CMraProto::MraMPopSessionQueueFlush(HANDLE hMPopSessionQueue)
if (hMPopSessionQueue) {
MRA_MPOP_SESSION_QUEUE *pmpsqMPopSessionQueue = (MRA_MPOP_SESSION_QUEUE*)hMPopSessionQueue;
while ( FifoMTGetCount(pmpsqMPopSessionQueue)) {
- MraMPopSessionQueueSetNewMPopKey(hMPopSessionQueue, NULL, 0);
+ MraMPopSessionQueueSetNewMPopKey(hMPopSessionQueue, "");
MraMPopSessionQueueStart(hMPopSessionQueue);
}
}
@@ -69,19 +69,19 @@ void MraMPopSessionQueueDestroy(HANDLE hMPopSessionQueue)
}
}
-DWORD CMraProto::MraMPopSessionQueueAddUrl(HANDLE hMPopSessionQueue, LPSTR lpszUrl, size_t dwUrlSize)
+DWORD CMraProto::MraMPopSessionQueueAddUrl(HANDLE hMPopSessionQueue, const CMStringA &szUrl)
{
- if (!hMPopSessionQueue || !lpszUrl || !dwUrlSize)
+ if (!hMPopSessionQueue || szUrl.IsEmpty())
return ERROR_INVALID_HANDLE;
MRA_MPOP_SESSION_QUEUE *pmpsqMPopSessionQueue = (MRA_MPOP_SESSION_QUEUE*)hMPopSessionQueue;
- MRA_MPOP_SESSION_QUEUE_ITEM *pmpsqi = (MRA_MPOP_SESSION_QUEUE_ITEM*)mir_calloc((sizeof(MRA_MPOP_SESSION_QUEUE_ITEM)+dwUrlSize+sizeof(size_t)));
+ MRA_MPOP_SESSION_QUEUE_ITEM *pmpsqi = (MRA_MPOP_SESSION_QUEUE_ITEM*)mir_calloc((sizeof(MRA_MPOP_SESSION_QUEUE_ITEM)+szUrl.GetLength()+sizeof(size_t)));
if (!pmpsqi)
return GetLastError();
- pmpsqi->dwUrlSize = dwUrlSize;
+ pmpsqi->dwUrlSize = szUrl.GetLength();
pmpsqi->lpszUrl = (LPSTR)(pmpsqi+1);
- memmove(pmpsqi->lpszUrl, lpszUrl, dwUrlSize);
+ memmove(pmpsqi->lpszUrl, szUrl, szUrl.GetLength());
FifoMTItemPush(pmpsqMPopSessionQueue, pmpsqi, (LPVOID)pmpsqi);
if (pmpsqMPopSessionQueue->bKeyValid)
return MraMPopSessionQueueStart(hMPopSessionQueue);
@@ -94,27 +94,20 @@ DWORD CMraProto::MraMPopSessionQueueAddUrl(HANDLE hMPopSessionQueue, LPSTR lpszU
return NO_ERROR;
}
-DWORD CMraProto::MraMPopSessionQueueAddUrlAndEMail(HANDLE hMPopSessionQueue, LPSTR lpszUrl, size_t dwUrlSize, LPSTR lpszEMail, size_t dwEMailSize)
+DWORD CMraProto::MraMPopSessionQueueAddUrlAndEMail(HANDLE hMPopSessionQueue, const CMStringA &lpszUrl, CMStringA &szEmail)
{
- if (!hMPopSessionQueue || !lpszUrl || !dwUrlSize || !lpszEMail || !dwEMailSize)
+ if (!hMPopSessionQueue || lpszUrl.IsEmpty() || szEmail.IsEmpty())
return ERROR_INVALID_HANDLE;
- char szUrl[BUFF_SIZE_URL], szEMail[MAX_EMAIL_LEN];
- LPSTR lpszUser, lpszDomain;
+ szEmail.MakeLower();
- BuffToLowerCase(szEMail, lpszEMail, dwEMailSize);
- lpszDomain = (LPSTR)MemoryFindByte(0, szEMail, dwEMailSize, '@');
- if (lpszDomain)
- if (lpszUser = (LPSTR)MemoryFindByte((lpszDomain-szEMail), szEMail, dwEMailSize, '.')) {
- *lpszUser = 0;
- lpszUser = szEMail;
- *lpszDomain = 0;
- lpszDomain++;
+ int iStart = 0;
+ CMStringA szDomain = szEmail.Tokenize("@", iStart);
+ CMStringA szUser = szEmail.Tokenize("@", iStart);
- dwUrlSize = mir_snprintf(szUrl, SIZEOF(szUrl), "%s/%s/%s", lpszUrl, lpszDomain, lpszUser);
- return MraMPopSessionQueueAddUrl(hMPopSessionQueue, szUrl, dwUrlSize);
- }
- return ERROR_INVALID_DATA;
+ CMStringA szUrl;
+ szUrl.Format("%s/%s/%s", lpszUrl.c_str(), szDomain.c_str(), szUser.c_str());
+ return MraMPopSessionQueueAddUrl(hMPopSessionQueue, szUrl);
}
DWORD CMraProto::MraMPopSessionQueueStart(HANDLE hMPopSessionQueue)
@@ -130,15 +123,12 @@ DWORD CMraProto::MraMPopSessionQueueStart(HANDLE hMPopSessionQueue)
dwRetErrorCode = NO_ERROR;
if (pmpsqMPopSessionQueue->bKeyValid == TRUE)
if ( FifoMTItemPop(pmpsqMPopSessionQueue, NULL, (LPVOID*)&pmpsqi) == NO_ERROR) {
- char szUrl[BUFF_SIZE_URL], szEMail[MAX_EMAIL_LEN];
- size_t dwUrlSize, dwEMailSize;
-
- if (mraGetStaticStringA(NULL, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize)) {
+ CMStringA szUrl, szEmail;
+ if (mraGetStringA(NULL, "e-mail", szEmail)) {
pmpsqMPopSessionQueue->bKeyValid = FALSE;
- BuffToLowerCase(szEMail, szEMail, dwEMailSize);
- dwUrlSize = mir_snprintf(szUrl, SIZEOF(szUrl), MRA_MPOP_AUTH_URL, szEMail, pmpsqMPopSessionQueue->lpszMPOPKey, pmpsqi->lpszUrl);
-
- CallService(MS_UTILS_OPENURL, TRUE, (LPARAM)szUrl);
+ szEmail.MakeLower();
+ szUrl.Format(MRA_MPOP_AUTH_URL, szEmail, pmpsqMPopSessionQueue->lpszMPOPKey, pmpsqi->lpszUrl);
+ CallService(MS_UTILS_OPENURL, TRUE, (LPARAM)szUrl.c_str());
DebugPrint(L"Opening URL: ");DebugPrintCRLFA(szUrl);
}
mir_free(pmpsqi);
@@ -146,24 +136,22 @@ DWORD CMraProto::MraMPopSessionQueueStart(HANDLE hMPopSessionQueue)
return NO_ERROR;
}
-DWORD MraMPopSessionQueueSetNewMPopKey(HANDLE hMPopSessionQueue, LPSTR lpszKey, size_t dwKeySize)
+DWORD MraMPopSessionQueueSetNewMPopKey(HANDLE hMPopSessionQueue, const CMStringA &szKey)
{
if (!hMPopSessionQueue)
return ERROR_INVALID_HANDLE;
- if (lpszKey == NULL) dwKeySize = 0;
-
MRA_MPOP_SESSION_QUEUE *pmpsqMPopSessionQueue = (MRA_MPOP_SESSION_QUEUE*)hMPopSessionQueue;
- if (pmpsqMPopSessionQueue->dwMPOPKeySize<dwKeySize || dwKeySize == 0) {
+ if (pmpsqMPopSessionQueue->dwMPOPKeySize < szKey.GetLength() || szKey.IsEmpty()) {
mir_free(pmpsqMPopSessionQueue->lpszMPOPKey);
- pmpsqMPopSessionQueue->lpszMPOPKey = (LPSTR)mir_calloc(dwKeySize+sizeof(size_t));
+ pmpsqMPopSessionQueue->lpszMPOPKey = (LPSTR)mir_calloc(szKey.GetLength()+sizeof(size_t));
}
if (pmpsqMPopSessionQueue->lpszMPOPKey) {
pmpsqMPopSessionQueue->bKeyValid = TRUE;
- pmpsqMPopSessionQueue->dwMPOPKeySize = dwKeySize;
- memmove(pmpsqMPopSessionQueue->lpszMPOPKey, lpszKey, dwKeySize);
- (*(pmpsqMPopSessionQueue->lpszMPOPKey+dwKeySize)) = 0;
+ pmpsqMPopSessionQueue->dwMPOPKeySize = szKey.GetLength();
+ memmove(pmpsqMPopSessionQueue->lpszMPOPKey, szKey, szKey.GetLength());
+ (*(pmpsqMPopSessionQueue->lpszMPOPKey + szKey.GetLength())) = 0;
DebugPrint(L"New MPOP session key: ");DebugPrintCRLFA(pmpsqMPopSessionQueue->lpszMPOPKey);
return NO_ERROR;
diff --git a/protocols/MRA/src/MraMPop.h b/protocols/MRA/src/MraMPop.h
index 18aef30f27..3d012235a0 100644
--- a/protocols/MRA/src/MraMPop.h
+++ b/protocols/MRA/src/MraMPop.h
@@ -8,6 +8,6 @@
DWORD MraMPopSessionQueueInitialize (HANDLE *phMPopSessionQueue);
void MraMPopSessionQueueDestroy (HANDLE hMPopSessionQueue);
-DWORD MraMPopSessionQueueSetNewMPopKey (HANDLE hMPopSessionQueue, LPSTR lpszKey, size_t dwKeySize);
+DWORD MraMPopSessionQueueSetNewMPopKey (HANDLE hMPopSessionQueue, const CMStringA &szKey);
#endif // !defined(AFX_MRA_MPOP_H__F58D13FF_F6F2_476C_B8F0_7B9E9357CF48__INCLUDED_)
diff --git a/protocols/MRA/src/MraMRIMProxy.cpp b/protocols/MRA/src/MraMRIMProxy.cpp
index 485cf14c6b..6a84e441ec 100644
--- a/protocols/MRA/src/MraMRIMProxy.cpp
+++ b/protocols/MRA/src/MraMRIMProxy.cpp
@@ -4,15 +4,14 @@
struct MRA_MRIMPROXY_DATA
{
- LPSTR lpszEMail; // LPS to
- size_t dwEMailSize;
+ 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 m_hConnection;
HANDLE hWaitHandle; // internal
};
@@ -22,32 +21,24 @@ HANDLE MraMrimProxyCreate()
return (HANDLE)pmmpd;
}
-DWORD MraMrimProxySetData(HANDLE hMraMrimProxyData, LPSTR lpszEMail, size_t dwEMailSize, DWORD dwIDRequest, DWORD dwDataType, LPSTR lpszUserData, size_t dwUserDataSize, LPSTR lpszAddreses, size_t dwAddresesSize, MRA_GUID *pmguidSessionID)
+DWORD MraMrimProxySetData(HANDLE hMraMrimProxyData, const CMStringA &szEmail, DWORD dwIDRequest, DWORD dwDataType, const CMStringA &lpszUserData, const CMStringA &szAddresses, MRA_GUID *pmguidSessionID)
{
if (!hMraMrimProxyData)
return ERROR_INVALID_HANDLE;
MRA_MRIMPROXY_DATA *pmmpd = (MRA_MRIMPROXY_DATA*)hMraMrimProxyData;
- if (lpszEMail && dwEMailSize) {
- mir_free(pmmpd->lpszEMail);
- pmmpd->lpszEMail = (LPSTR)mir_calloc(dwEMailSize);
- memmove(pmmpd->lpszEMail, lpszEMail, dwEMailSize);
- pmmpd->dwEMailSize = dwEMailSize;
- }
+ if (!szEmail.IsEmpty())
+ replaceStr(pmmpd->szEmail, szEmail);
if (dwIDRequest) pmmpd->dwIDRequest = dwIDRequest;
if (dwDataType) pmmpd->dwDataType = dwDataType;
- if (lpszUserData) {
- mir_free(pmmpd->lpszUserData);
- pmmpd->lpszUserData = (LPSTR)mir_calloc(dwUserDataSize);
- memmove(pmmpd->lpszUserData, lpszUserData, dwUserDataSize);
- pmmpd->dwUserDataSize = dwUserDataSize;
- }
+ if (!lpszUserData.IsEmpty())
+ replaceStr(pmmpd->lpszUserData, lpszUserData);
- if (lpszAddreses && dwAddresesSize)
- MraAddrListGetFromBuff(lpszAddreses, dwAddresesSize, &pmmpd->malAddrList);
+ if (!szAddresses.IsEmpty())
+ MraAddrListGetFromBuff(szAddresses, &pmmpd->malAddrList);
if (pmguidSessionID)
memmove(&pmmpd->mguidSessionID, pmguidSessionID, sizeof(MRA_GUID));
@@ -61,8 +52,8 @@ void MraMrimProxyFree(HANDLE hMraMrimProxyData)
MRA_MRIMPROXY_DATA *pmmpd = (MRA_MRIMPROXY_DATA*)hMraMrimProxyData;
CloseHandle(pmmpd->hWaitHandle);
- Netlib_CloseHandle(pmmpd->hConnection);
- mir_free(pmmpd->lpszEMail);
+ Netlib_CloseHandle(pmmpd->m_hConnection);
+ mir_free(pmmpd->szEmail);
mir_free(pmmpd->lpszUserData);
MraAddrListFree(&pmmpd->malAddrList);
mir_free(hMraMrimProxyData);
@@ -74,7 +65,7 @@ void MraMrimProxyCloseConnection(HANDLE hMraMrimProxyData)
if (hMraMrimProxyData) {
MRA_MRIMPROXY_DATA *pmmpd = (MRA_MRIMPROXY_DATA*)hMraMrimProxyData;
SetEvent(pmmpd->hWaitHandle);
- Netlib_CloseHandle(pmmpd->hConnection);
+ Netlib_CloseHandle(pmmpd->m_hConnection);
}
}
@@ -93,14 +84,14 @@ DWORD CMraProto::MraMrimProxyConnect(HANDLE hMraMrimProxyData, HANDLE *phConnect
// адреса есть, значит инициаторы не мы
if (pmmpd->malAddrList.dwAddrCount) {
- MraAddrListGetToBuff(&pmmpd->malAddrList, (LPSTR)lpbBufferRcv, SIZEOF(lpbBufferRcv), &dwRcvBuffSizeUsed);
- MraProxyAck(PROXY_STATUS_OK, pmmpd->lpszEMail, pmmpd->dwEMailSize, pmmpd->dwIDRequest, pmmpd->dwDataType, pmmpd->lpszUserData, pmmpd->dwUserDataSize, (LPSTR)lpbBufferRcv, dwRcvBuffSizeUsed, pmmpd->mguidSessionID);
+ CMStringA szAddresses = MraAddrListGetToBuff(&pmmpd->malAddrList);
+ MraProxyAck(PROXY_STATUS_OK, pmmpd->szEmail, pmmpd->dwIDRequest, pmmpd->dwDataType, pmmpd->lpszUserData, szAddresses, pmmpd->mguidSessionID);
}
// мы инициаторы
else {
pmmpd->hWaitHandle = CreateEvent(NULL, TRUE, FALSE, NULL);
- if (pmmpd->lpszEMail && pmmpd->dwEMailSize)
- if (MraProxy(pmmpd->lpszEMail, pmmpd->dwEMailSize, pmmpd->dwIDRequest, pmmpd->dwDataType, pmmpd->lpszUserData, pmmpd->dwUserDataSize, NULL, 0, pmmpd->mguidSessionID))
+ if (pmmpd->szEmail)
+ if (MraProxy(pmmpd->szEmail, pmmpd->dwIDRequest, pmmpd->dwDataType, pmmpd->lpszUserData, "", pmmpd->mguidSessionID))
WaitForSingleObjectEx(pmmpd->hWaitHandle, INFINITE, FALSE);
CloseHandle(pmmpd->hWaitHandle);
@@ -109,8 +100,8 @@ DWORD CMraProto::MraMrimProxyConnect(HANDLE hMraMrimProxyData, HANDLE *phConnect
dwRetErrorCode = ERROR_NO_NETWORK;
if (pmmpd->malAddrList.dwAddrCount) {
- pmmpd->hConnection = NULL;
- bIsHTTPSProxyUsed = IsHTTPSProxyUsed(hNetlibUser);
+ pmmpd->m_hConnection = NULL;
+ bIsHTTPSProxyUsed = IsHTTPSProxyUsed(m_hNetlibUser);
dwConnectReTryCount = getDword("ConnectReTryCountMRIMProxy", MRA_DEFAULT_CONN_RETRY_COUNT_MRIMPROXY);
nloc.cbSize = sizeof(nloc);
nloc.flags = NLOCF_V2;
@@ -121,28 +112,28 @@ DWORD CMraProto::MraMrimProxyConnect(HANDLE hMraMrimProxyData, HANDLE *phConnect
// Set up the sockaddr structure
for (size_t i = 0; i < pmmpd->malAddrList.dwAddrCount && dwRetErrorCode != NO_ERROR; i++) {
// через https прокси только 443 порт
- if ((pmmpd->malAddrList.pmaliAddress[i].dwPort == MRA_SERVER_PORT_HTTPS && bIsHTTPSProxyUsed) || bIsHTTPSProxyUsed == FALSE) {
+ if ((pmmpd->malAddrList.pMailAddress[i].dwPort == MRA_SERVER_PORT_HTTPS && bIsHTTPSProxyUsed) || bIsHTTPSProxyUsed == FALSE) {
if (pmmpd->dwDataType == MRIM_PROXY_TYPE_FILES)
- ProtoBroadcastAck(MraHContactFromEmail(pmmpd->lpszEMail, pmmpd->dwEMailSize, FALSE, TRUE, NULL), ACKTYPE_FILE, ACKRESULT_CONNECTING, (HANDLE)pmmpd->dwIDRequest, 0);
+ ProtoBroadcastAck(MraHContactFromEmail(pmmpd->szEmail, FALSE, TRUE, NULL), ACKTYPE_FILE, ACKRESULT_CONNECTING, (HANDLE)pmmpd->dwIDRequest, 0);
- nloc.szHost = inet_ntoa((*((in_addr*)&pmmpd->malAddrList.pmaliAddress[i].dwAddr)));
- nloc.wPort = (WORD)pmmpd->malAddrList.pmaliAddress[i].dwPort;
+ nloc.szHost = inet_ntoa((*((in_addr*)&pmmpd->malAddrList.pMailAddress[i].dwAddr)));
+ nloc.wPort = (WORD)pmmpd->malAddrList.pMailAddress[i].dwPort;
dwCurConnectReTryCount = dwConnectReTryCount;
do {
- pmmpd->hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)hNetlibUser, (LPARAM)&nloc);
+ pmmpd->m_hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc);
}
- while (--dwCurConnectReTryCount && pmmpd->hConnection == NULL);
+ while (--dwCurConnectReTryCount && pmmpd->m_hConnection == NULL);
- if (pmmpd->hConnection) {
+ if (pmmpd->m_hConnection) {
nls.cbSize = sizeof(nls);
nls.dwTimeout = (MRA_TIMEOUT_DIRECT_CONN*1000*2);
- nls.hReadConns[0] = pmmpd->hConnection;
+ nls.hReadConns[0] = pmmpd->m_hConnection;
bContinue = TRUE;
dwRcvBuffSizeUsed = 0;
if (pmmpd->dwDataType == MRIM_PROXY_TYPE_FILES)
- ProtoBroadcastAck(MraHContactFromEmail(pmmpd->lpszEMail, pmmpd->dwEMailSize, FALSE, TRUE, NULL), ACKTYPE_FILE, ACKRESULT_CONNECTED, (HANDLE)pmmpd->dwIDRequest, 0);
+ ProtoBroadcastAck(MraHContactFromEmail(pmmpd->szEmail, FALSE, TRUE, NULL), ACKTYPE_FILE, ACKRESULT_CONNECTED, (HANDLE)pmmpd->dwIDRequest, 0);
MraSendPacket(nls.hReadConns[0], 0, MRIM_CS_PROXY_HELLO, &pmmpd->mguidSessionID, sizeof(MRA_GUID));
while (bContinue) {
@@ -200,11 +191,11 @@ DWORD CMraProto::MraMrimProxyConnect(HANDLE hMraMrimProxyData, HANDLE *phConnect
}// end for
if (dwRetErrorCode != NO_ERROR) { // кажется не туда подключились :)
- Netlib_CloseHandle(pmmpd->hConnection);
- pmmpd->hConnection = NULL;
+ Netlib_CloseHandle(pmmpd->m_hConnection);
+ pmmpd->m_hConnection = NULL;
}
}
- *phConnection = pmmpd->hConnection;
+ *phConnection = pmmpd->m_hConnection;
}
else dwRetErrorCode = ERROR_INVALID_HANDLE;
return dwRetErrorCode;
diff --git a/protocols/MRA/src/MraMRIMProxy.h b/protocols/MRA/src/MraMRIMProxy.h
index c0051daec9..5aac9c5fbd 100644
--- a/protocols/MRA/src/MraMRIMProxy.h
+++ b/protocols/MRA/src/MraMRIMProxy.h
@@ -6,7 +6,7 @@
#pragma once
#endif // _MSC_VER > 1000
-DWORD MraMrimProxySetData(HANDLE hMraMrimProxyData, LPSTR lpszEMail, size_t dwEMailSize, DWORD dwIDRequest, DWORD dwDataType, LPSTR lpszUserData, size_t dwUserDataSize, LPSTR lpszAddreses, size_t dwAddresesSize, MRA_GUID *pmguidSessionID);
+DWORD MraMrimProxySetData(HANDLE hMraMrimProxyData, const CMStringA &szEmail, DWORD dwIDRequest, DWORD dwDataType, const CMStringA &lpszUserData, const CMStringA &szAddresses, MRA_GUID *pmguidSessionID);
HANDLE MraMrimProxyCreate();
void MraMrimProxyFree(HANDLE hMraMrimProxyData);
diff --git a/protocols/MRA/src/MraOfflineMsg.cpp b/protocols/MRA/src/MraOfflineMsg.cpp
index 829bca6b27..259d18f0ae 100644
--- a/protocols/MRA/src/MraOfflineMsg.cpp
+++ b/protocols/MRA/src/MraOfflineMsg.cpp
@@ -2,74 +2,69 @@
#include "MraOfflineMsg.h"
#include "MraConstans.h"
-
#define LF "\n"
#define LFLF "\n\n"
#define CRLF "\r\n"
#define CRLFCRLF "\r\n\r\n"
+DWORD MraOfflineMessageGetMIMEHeadAndBody(LPCSTR lpszMessage, size_t dwMessageSize, LPSTR *plpszHeader, size_t *pdwHeaderSize, LPSTR *plpszBody, size_t *pdwBodySize);
+DWORD MraOfflineMessageGetNextMIMEPart(LPSTR lpszBody, size_t dwBodySize, LPSTR lpszBoundary, size_t dwBoundarySize, LPSTR *plpszCurMIMEPos, LPSTR *plpszMIMEPart, size_t *pdwMIMEPartSize);
+DWORD MraOfflineMessageGetHeaderValue(LPSTR lpszHeader, LPSTR lpszHeaderLow, size_t dwHeaderSize, LPSTR lpszValueName, size_t dwValueNameSize, CMStringA &plpszValue);
+DWORD MraOfflineMessageGetHeaderValueLow(LPSTR lpszHeaderLow, size_t dwHeaderSize, LPSTR lpszValueName, size_t dwValueNameSize, LPSTR *plpszValue, size_t *pdwValueSize);
+DWORD MraOfflineMessageConvertTime(INTERNET_TIME *pitTime);
-DWORD MraOfflineMessageGetMIMEHeadAndBody (LPSTR lpszMessage, size_t dwMessageSize, LPSTR *plpszHeader, size_t *pdwHeaderSize, LPSTR *plpszBody, size_t *pdwBodySize);
-DWORD MraOfflineMessageGetNextMIMEPart (LPSTR lpszBody, size_t dwBodySize, LPSTR lpszBoundary, size_t dwBoundarySize, LPSTR *plpszCurMIMEPos, LPSTR *plpszMIMEPart, size_t *pdwMIMEPartSize);
-DWORD MraOfflineMessageGetHeaderValue (LPSTR lpszHeader, LPSTR lpszHeaderLow, size_t dwHeaderSize, LPSTR lpszValueName, size_t dwValueNameSize, LPSTR *plpszValue, size_t *pdwValueSize);
-DWORD MraOfflineMessageGetHeaderValueLow (LPSTR lpszHeaderLow, size_t dwHeaderSize, LPSTR lpszValueName, size_t dwValueNameSize, LPSTR *plpszValue, size_t *pdwValueSize);
-DWORD MraOfflineMessageConvertTime (INTERNET_TIME *pitTime);
-
-DWORD MraOfflineMessageGet(MRA_LPS *plpsMsg, DWORD *pdwTime, DWORD *pdwFlags, MRA_LPS *plpsEMail, MRA_LPS *plpsText, MRA_LPS *plpsRTFText, MRA_LPS *plpsMultiChatData, LPBYTE *plpbBuff)
-{// Сообщение
+// Сообщение
+DWORD MraOfflineMessageGet(CMStringA *plpsMsg, DWORD *pdwTime, DWORD *pdwFlags, CMStringA *plpsEMail, CMStringA *plpsText, CMStringA *plpsRTFText, CMStringA *plpsMultiChatData, LPBYTE *plpbBuff)
+{
DWORD dwRetErrorCode = ERROR_INVALID_HANDLE;
if (plpsMsg)
- if (plpsMsg->lpszData && plpsMsg->dwSize) {
- LPSTR lpszHeader, lpszHeaderLow, lpszBody, lpszContentTypeLow, lpszTemp;
- size_t dwHeaderSize, dwBodySize, dwContentTypeSize, dwTempSize;
+ if (!plpsMsg->IsEmpty()) {
+ LPSTR lpszHeader, lpszHeaderLow, lpszBody, lpszContentTypeLow;
+ size_t dwHeaderSize, dwBodySize, dwContentTypeSize;
DWORD dwMultichatType;
+ CMStringA szTemp;
#ifdef _DEBUG
- DebugPrintCRLFA(plpsMsg->lpszData);
+ DebugPrintCRLFA(plpsMsg->GetString());
#endif
- if (MraOfflineMessageGetMIMEHeadAndBody(plpsMsg->lpszData, plpsMsg->dwSize, &lpszHeader, &dwHeaderSize, &lpszBody, &dwBodySize) == NO_ERROR) {
+ if (MraOfflineMessageGetMIMEHeadAndBody(plpsMsg->GetString(), plpsMsg->GetLength(), &lpszHeader, &dwHeaderSize, &lpszBody, &dwBodySize) == NO_ERROR) {
lpszHeaderLow = (LPSTR)mir_calloc(dwHeaderSize);
if (lpszHeaderLow) BuffToLowerCase(lpszHeaderLow, lpszHeader, dwHeaderSize);
if (pdwTime)
- if (MraOfflineMessageGetHeaderValue(lpszHeader, lpszHeaderLow, dwHeaderSize, "date", 4, &lpszTemp, &dwTempSize) == NO_ERROR) {
+ if (MraOfflineMessageGetHeaderValue(lpszHeader, lpszHeaderLow, dwHeaderSize, "date", 4, szTemp) == NO_ERROR) {
INTERNET_TIME itTime;
- InternetTimeGetTime(lpszTemp, dwTempSize, &itTime);
+ InternetTimeGetTime(szTemp, &itTime);
(*pdwTime) = MraOfflineMessageConvertTime(&itTime);
}
else (*pdwTime) = 0;
if (pdwFlags)
- if (MraOfflineMessageGetHeaderValue(lpszHeader, lpszHeaderLow, dwHeaderSize, "x-mrim-flags", 12, &lpszTemp, &dwTempSize) == NO_ERROR)
- (*pdwFlags) = StrHexToUNum32(lpszTemp, dwTempSize);
+ if (MraOfflineMessageGetHeaderValue(lpszHeader, lpszHeaderLow, dwHeaderSize, "x-mrim-flags", 12, szTemp) == NO_ERROR)
+ *pdwFlags = StrHexToUNum32(szTemp, szTemp.GetLength());
else
- (*pdwFlags) = 0;
+ *pdwFlags = 0;
- if (MraOfflineMessageGetHeaderValue(lpszHeader, lpszHeaderLow, dwHeaderSize, "x-mrim-multichat-type", 21, &lpszTemp, &dwTempSize) == NO_ERROR)
- dwMultichatType = StrHexToUNum32(lpszTemp, dwTempSize);
+ if (MraOfflineMessageGetHeaderValue(lpszHeader, lpszHeaderLow, dwHeaderSize, "x-mrim-multichat-type", 21, szTemp) == NO_ERROR)
+ dwMultichatType = StrHexToUNum32(szTemp, szTemp.GetLength());
else
dwMultichatType = 0;
if (plpsEMail)
- if (MraOfflineMessageGetHeaderValue(lpszHeader, lpszHeaderLow, dwHeaderSize, "from", 4, &plpsEMail->lpszData, &plpsEMail->dwSize) != NO_ERROR) {
- plpsEMail->lpszData = NULL;
- plpsEMail->dwSize = 0;
- }
+ if (MraOfflineMessageGetHeaderValue(lpszHeader, lpszHeaderLow, dwHeaderSize, "from", 4, *plpsEMail) != NO_ERROR)
+ plpsEMail->Empty();
+
+ if (plpsText)
+ plpsText->Empty();
+
+ if (plpsRTFText)
+ plpsRTFText->Empty();
+
+ if (plpsMultiChatData)
+ plpsMultiChatData->Empty();
- if (plpsText) {
- plpsText->lpszData = NULL;
- plpsText->dwSize = 0;
- }
- if (plpsRTFText) {
- plpsRTFText->lpszData = NULL;
- plpsRTFText->dwSize = 0;
- }
- if (plpsMultiChatData) {
- plpsMultiChatData->lpszData = NULL;
- plpsMultiChatData->dwSize = 0;
- }
if (plpbBuff) (*plpbBuff) = NULL;
if (plpsText || plpsRTFText)
@@ -103,8 +98,7 @@ DWORD MraOfflineMessageGet(MRA_LPS *plpsMsg, DWORD *pdwTime, DWORD *pdwFlags, MR
unsigned dwTextSize;
LPWSTR lpwszText = (LPWSTR)mir_base64_decode(szMime, &dwTextSize);
if (lpwszText) {
- plpsText->lpwszData = lpwszText;
- plpsText->dwSize = dwTextSize;
+ *plpsText = CMStringW(lpwszText, dwTextSize);
if (pdwFlags) {
(*pdwFlags) |= MESSAGE_FLAG_v1p16; // set unocode flag if not exist
(*pdwFlags) &= ~MESSAGE_FLAG_CP1251; // reset ansi flag if exist
@@ -116,8 +110,7 @@ DWORD MraOfflineMessageGet(MRA_LPS *plpsMsg, DWORD *pdwTime, DWORD *pdwFlags, MR
}
else if ( MemoryFind(0, lpszMIMEContentType, dwMIMEContentTypeSize, "cp-1251", 7)) {
// charset = CP-1251
- plpsText->lpszData = lpszMIMEBody;
- plpsText->dwSize = dwMIMEBodySize;
+ *plpsText = CMStringA(lpszMIMEBody, dwMIMEBodySize);
if (pdwFlags) {
(*pdwFlags) &= ~MESSAGE_FLAG_v1p16; // reset unocode flag if exist
(*pdwFlags) |= MESSAGE_FLAG_CP1251; // set ansi flag
@@ -129,17 +122,17 @@ DWORD MraOfflineMessageGet(MRA_LPS *plpsMsg, DWORD *pdwTime, DWORD *pdwFlags, MR
}
else if (MemoryFind(0, lpszMIMEContentType, dwMIMEContentTypeSize, "application/x-mrim-rtf", 22)) {
if (plpsRTFText) {
- plpsRTFText->lpszData = lpszMIMEBody;
- plpsRTFText->dwSize = dwMIMEBodySize;
- if (pdwFlags) (*pdwFlags) |= MESSAGE_FLAG_RTF; // set RTF flag if not exist
+ *plpsRTFText = CMStringA(lpszMIMEBody, dwMIMEBodySize);
+ if (pdwFlags)
+ (*pdwFlags) |= MESSAGE_FLAG_RTF; // set RTF flag if not exist
dwRetErrorCode = NO_ERROR;
}
}
else if (MemoryFind(0, lpszMIMEContentType, dwMIMEContentTypeSize, "application/x-mrim+xml", 22)) {
if (plpsMultiChatData) {
- plpsMultiChatData->lpszData = lpszMIMEBody;
- plpsMultiChatData->dwSize = dwMIMEBodySize;
- if (pdwFlags) (*pdwFlags) |= MESSAGE_FLAG_MULTICHAT; // set MESSAGE_FLAG_MULTICHAT flag if not exist
+ *plpsMultiChatData = CMStringA(lpszMIMEBody, dwMIMEBodySize);
+ if (pdwFlags)
+ (*pdwFlags) |= MESSAGE_FLAG_MULTICHAT; // set MESSAGE_FLAG_MULTICHAT flag if not exist
dwRetErrorCode = NO_ERROR;
}
}
@@ -164,11 +157,9 @@ DWORD MraOfflineMessageGet(MRA_LPS *plpsMsg, DWORD *pdwTime, DWORD *pdwFlags, MR
LPS2ANSI(szMime, lpszBody, dwBodySize);
unsigned dwTextSize;
LPWSTR lpwszText = (LPWSTR)mir_base64_decode(szMime, &dwTextSize);
- if (lpwszText) {
- plpsText->lpwszData = lpwszText;
- plpsText->dwSize = dwTextSize;
- if (pdwFlags)
- {
+ if (lpwszText) {
+ *plpsText = CMStringW(lpwszText, dwTextSize);
+ if (pdwFlags) {
(*pdwFlags) |= MESSAGE_FLAG_v1p16; // set unocode flag if not exist
(*pdwFlags) &= ~MESSAGE_FLAG_CP1251; // reset ansi flag if exist
}
@@ -179,10 +170,8 @@ DWORD MraOfflineMessageGet(MRA_LPS *plpsMsg, DWORD *pdwTime, DWORD *pdwFlags, MR
}else
if (MemoryFind(0, lpszContentTypeLow, dwContentTypeSize, "cp-1251", 7))
{// charset = CP-1251
- plpsText->lpszData = lpszBody;
- plpsText->dwSize = dwBodySize;
- if (pdwFlags)
- {
+ *plpsText = CMStringA(lpszBody, dwBodySize);
+ if (pdwFlags) {
(*pdwFlags) &= ~MESSAGE_FLAG_v1p16; // reset unocode flag if exist
(*pdwFlags) |= MESSAGE_FLAG_CP1251; // set ansi flag
}
@@ -194,17 +183,12 @@ DWORD MraOfflineMessageGet(MRA_LPS *plpsMsg, DWORD *pdwTime, DWORD *pdwFlags, MR
if (MemoryFind(0, lpszContentTypeLow, dwContentTypeSize, "application/x-mrim-auth-req", 27))
{// Content-Type: application/x-mrim-auth-req
if (plpsText)
- {
- plpsText->lpszData = lpszBody;
- plpsText->dwSize = dwBodySize;
- }
+ *plpsText = CMStringA(lpszBody, dwBodySize);
dwRetErrorCode = NO_ERROR;
- }else {
- DebugBreak();
}
- }else {
- DebugBreak();
+ else DebugBreak();
}
+ else DebugBreak();
mir_free(lpszHeaderLow);
}
@@ -214,7 +198,7 @@ return(dwRetErrorCode);
}
-DWORD MraOfflineMessageGetMIMEHeadAndBody(LPSTR lpszMessage, size_t dwMessageSize, LPSTR *plpszHeader, size_t *pdwHeaderSize, LPSTR *plpszBody, size_t *pdwBodySize)
+DWORD MraOfflineMessageGetMIMEHeadAndBody(LPCSTR lpszMessage, size_t dwMessageSize, LPSTR *plpszHeader, size_t *pdwHeaderSize, LPSTR *plpszBody, size_t *pdwBodySize)
{
DWORD dwRetErrorCode = ERROR_NOT_FOUND;
@@ -237,10 +221,10 @@ DWORD MraOfflineMessageGetMIMEHeadAndBody(LPSTR lpszMessage, size_t dwMessageSiz
{// нашли начало контента миме части
dwBodySize = (dwMessageSize-(lpszBody-lpszMessage));
- if (plpszHeader) (*plpszHeader) = lpszMessage;
- if (pdwHeaderSize) (*pdwHeaderSize) = ((lpszBody-(sizeof(LFLF)-1))-lpszMessage);
- if (plpszBody) (*plpszBody) = lpszBody;
- if (pdwBodySize) (*pdwBodySize) = dwBodySize;
+ if (plpszHeader) (*plpszHeader) = (LPSTR)lpszMessage;
+ if (pdwHeaderSize) (*pdwHeaderSize) = ((lpszBody-(sizeof(LFLF)-1))-lpszMessage);
+ if (plpszBody) (*plpszBody) = lpszBody;
+ if (pdwBodySize) (*pdwBodySize) = dwBodySize;
dwRetErrorCode = NO_ERROR;
}
@@ -316,30 +300,24 @@ return(dwRetErrorCode);
}
-DWORD MraOfflineMessageGetHeaderValue(LPSTR lpszHeader, LPSTR lpszHeaderLow, size_t dwHeaderSize, LPSTR lpszValueName, size_t dwValueNameSize, LPSTR *plpszValue, size_t *pdwValueSize)
+DWORD MraOfflineMessageGetHeaderValue(LPSTR lpszHeader, LPSTR lpszHeaderLow, size_t dwHeaderSize, LPSTR lpszValueName, size_t dwValueNameSize, CMStringA &plpszValue)
{
- DWORD dwRetErrorCode = ERROR_NOT_FOUND;
- LPSTR lpszValue, lpszValueEnd;
- size_t dwValueSize;
-
- lpszValue = (LPSTR)MemoryFind(0, lpszHeaderLow, dwHeaderSize, lpszValueName, dwValueNameSize);
+ LPSTR lpszValue = (LPSTR)MemoryFind(0, lpszHeaderLow, dwHeaderSize, lpszValueName, dwValueNameSize);
if (lpszValue)
{
lpszValue += dwValueNameSize;
- lpszValueEnd = (LPSTR)MemoryFind((lpszValue-lpszHeaderLow), lpszHeaderLow, dwHeaderSize, CRLF, (sizeof(CRLF)-1));
+ LPSTR lpszValueEnd = (LPSTR)MemoryFind((lpszValue-lpszHeaderLow), lpszHeaderLow, dwHeaderSize, CRLF, (sizeof(CRLF)-1));
if (lpszValueEnd == NULL) lpszValueEnd = (LPSTR)MemoryFind((lpszValue-lpszHeaderLow), lpszHeaderLow, dwHeaderSize, LF, (sizeof(LF)-1));
if (lpszValueEnd == NULL) lpszValueEnd = (LPSTR)(lpszHeaderLow+dwHeaderSize);
lpszValue = (LPSTR)MemoryFind((lpszValue-lpszHeaderLow), lpszHeaderLow, (lpszValueEnd-lpszHeaderLow), ":", 1);
- if (lpszValue)
- {
+ if (lpszValue) {
lpszValue++;
- dwValueSize = (lpszValueEnd-lpszValue);
- SkeepSPWSP((lpszHeader+(lpszValue-lpszHeaderLow)), dwValueSize, plpszValue, pdwValueSize);
- dwRetErrorCode = NO_ERROR;
+ plpszValue = CMStringA(lpszHeader+(lpszValue-lpszHeaderLow), (lpszValueEnd-lpszValue));
+ return NO_ERROR;
}
}
-return(dwRetErrorCode);
+ return ERROR_NOT_FOUND;
}
diff --git a/protocols/MRA/src/MraOfflineMsg.h b/protocols/MRA/src/MraOfflineMsg.h
index 2958fbe4a9..de4173a23e 100644
--- a/protocols/MRA/src/MraOfflineMsg.h
+++ b/protocols/MRA/src/MraOfflineMsg.h
@@ -10,7 +10,7 @@
-DWORD MraOfflineMessageGet(MRA_LPS *plpsMsg, DWORD *pdwTime, DWORD *pdwFlags, MRA_LPS *plpsEMail, MRA_LPS *plpsText, MRA_LPS *plpsRTFText, MRA_LPS *plpsMultiChatData, LPBYTE *plpbBuff);
+DWORD MraOfflineMessageGet(CMStringA *plpsMsg, DWORD *pdwTime, DWORD *pdwFlags, CMStringA *plpsEMail, CMStringA *plpsText, CMStringA *plpsRTFText, CMStringA *plpsMultiChatData, LPBYTE *plpbBuff);
diff --git a/protocols/MRA/src/MraPopUp.cpp b/protocols/MRA/src/MraPopUp.cpp
index 135ba88f80..896b06f7ee 100644
--- a/protocols/MRA/src/MraPopUp.cpp
+++ b/protocols/MRA/src/MraPopUp.cpp
@@ -212,22 +212,22 @@ LRESULT CALLBACK MraPopupDlgProc(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM l
return DefWindowProc(hWndDlg, msg, wParam, lParam);
}
-void CMraProto::MraPopupShowFromContactW(HANDLE hContact, DWORD dwType, DWORD dwFlags, LPWSTR lpszMessage)
+void CMraProto::MraPopupShowFromContactW(HANDLE hContact, DWORD dwType, DWORD dwFlags, LPCWSTR lpszMessage)
{
- WCHAR szNick[MAX_EMAIL_LEN], szEMail[MAX_EMAIL_LEN], szTitle[MAX_CONTACTNAME];
-
- mraGetStaticStringW(hContact, "Nick", szNick, SIZEOF(szNick), NULL);
- mraGetStaticStringW(hContact, "e-mail", szEMail, SIZEOF(szEMail), NULL);
- if (hContact) {
- mir_sntprintf(szTitle, SIZEOF(szTitle), L"%s <%s>", szNick, szEMail);
- }else {
- mir_sntprintf(szTitle, SIZEOF(szTitle), L"%s: %s <%s>", m_tszUserName, szNick, szEMail);
- }
+ WCHAR szTitle[MAX_CONTACTNAME];
+ CMStringW szNick, szEmail;
+ mraGetStringW(hContact, "Nick", szNick);
+ mraGetStringW(hContact, "e-mail", szEmail);
+ if (hContact)
+ mir_snwprintf(szTitle, SIZEOF(szTitle), L"%s <%s>", szNick, szEmail);
+ else
+ mir_snwprintf(szTitle, SIZEOF(szTitle), L"%s: %s <%s>", m_tszUserName, szNick, szEmail);
+
MraPopupShowW(hContact, dwType, dwFlags, szTitle, lpszMessage);
}
-void CMraProto::MraPopupShowW(HANDLE hContact, DWORD dwType, DWORD dwFlags, LPWSTR lpszTitle, LPWSTR lpszMessage)
+void CMraProto::MraPopupShowW(HANDLE hContact, DWORD dwType, DWORD dwFlags, LPWSTR lpszTitle, LPCWSTR lpszMessage)
{
if (getByte("PopupsEnabled", MRA_DEFAULT_POPUPS_ENABLED))
if (GetBit(getDword("PopupsEventFilter", MRA_DEFAULT_POPUPS_EVENT_FILTER), dwType))
diff --git a/protocols/MRA/src/MraProto.cpp b/protocols/MRA/src/MraProto.cpp
index f7dc6eb9c6..cbe12c5f6a 100644
--- a/protocols/MRA/src/MraProto.cpp
+++ b/protocols/MRA/src/MraProto.cpp
@@ -32,7 +32,7 @@ CMraProto::CMraProto(const char* _module, const TCHAR* _displayName) :
CreateProtoService(PS_SEND_NUDGE, &CMraProto::MraSendNudge);
if ( ServiceExists(MS_NUDGE_SEND))
- heNudgeReceived = CreateProtoEvent(PE_NUDGE);
+ m_heNudgeReceived = CreateProtoEvent(PE_NUDGE);
TCHAR name[128];
mir_sntprintf( name, SIZEOF(name), TranslateT("%s connection"), m_tszUserName);
@@ -41,7 +41,7 @@ CMraProto::CMraProto(const char* _module, const TCHAR* _displayName) :
nlu.flags = NUF_INCOMING | NUF_OUTGOING | NUF_HTTPCONNS | NUF_UNICODE;
nlu.szSettingsModule = m_szModuleName;
nlu.ptszDescriptiveName = name;
- hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
+ m_hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
HookProtoEvent(ME_SYSTEM_PRESHUTDOWN, &CMraProto::OnPreShutdown);
@@ -72,10 +72,10 @@ CMraProto::CMraProto(const char* _module, const TCHAR* _displayName) :
CMraProto::~CMraProto()
{
- Netlib_CloseHandle(hNetlibUser);
+ Netlib_CloseHandle(m_hNetlibUser);
- if (heNudgeReceived)
- DestroyHookableEvent(heNudgeReceived);
+ if (m_heNudgeReceived)
+ DestroyHookableEvent(m_heNudgeReceived);
MraMPopSessionQueueDestroy(hMPopSessionQueue);
MraFilesQueueDestroy(hFilesQueueHandle);
@@ -100,7 +100,7 @@ int CMraProto::OnModulesLoaded(WPARAM, LPARAM)
// всех в offline // тк unsaved values сохраняются их нужно инициализировать
for (HANDLE hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact))
- SetContactBasicInfoW(hContact, SCBIFSI_LOCK_CHANGES_EVENTS, (SCBIF_ID|SCBIF_GROUP_ID|SCBIF_SERVER_FLAG|SCBIF_STATUS), -1, -1, 0, 0, ID_STATUS_OFFLINE, NULL, 0, NULL, 0, NULL, 0);
+ SetContactBasicInfoW(hContact, SCBIFSI_LOCK_CHANGES_EVENTS, (SCBIF_ID|SCBIF_GROUP_ID|SCBIF_SERVER_FLAG|SCBIF_STATUS), -1, -1, 0, 0, ID_STATUS_OFFLINE, "", L"", "");
// unsaved values
db_set_resident(m_szModuleName, "Status");// NOTE: XStatus cannot be temporary
@@ -130,11 +130,11 @@ int CMraProto::OnPreShutdown(WPARAM, LPARAM)
SetStatus(ID_STATUS_OFFLINE);
MraAvatarsQueueDestroy(hAvatarsQueueHandle); hAvatarsQueueHandle = NULL;
- if (hThreadWorker) {
- if (IsThreadAlive(hThreadWorker))
- WaitForSingleObjectEx(hThreadWorker, (WAIT_FOR_THREAD_TIMEOUT*1000), FALSE);
- CloseHandle(hThreadWorker);
- hThreadWorker = NULL;
+ if (m_hThreadWorker) {
+ if (IsThreadAlive(m_hThreadWorker))
+ WaitForSingleObjectEx(m_hThreadWorker, (WAIT_FOR_THREAD_TIMEOUT*1000), FALSE);
+ CloseHandle(m_hThreadWorker);
+ m_hThreadWorker = NULL;
}
return 0;
@@ -148,7 +148,7 @@ HANDLE CMraProto::AddToListByEmail(LPCTSTR plpsEMail, LPCTSTR plpsNick, LPCTSTR
return NULL;
BOOL bAdded;
- HANDLE hContact = MraHContactFromEmail( _T2A(plpsEMail), lstrlen(plpsEMail), TRUE, TRUE, &bAdded);
+ HANDLE hContact = MraHContactFromEmail(plpsEMail, TRUE, TRUE, &bAdded);
if (hContact) {
if (plpsNick)
mraSetStringW(hContact, "Nick", plpsNick);
@@ -225,8 +225,7 @@ int CMraProto::Authorize(HANDLE hDBEvent)
LPSTR lpszNick = (LPSTR)(dbei.pBlob + sizeof(DWORD)*2);
LPSTR lpszFirstName = lpszNick + lstrlenA(lpszNick) + 1;
LPSTR lpszLastName = lpszFirstName + lstrlenA(lpszFirstName) + 1;
- LPSTR lpszEMail = lpszLastName + lstrlenA(lpszLastName) + 1;
- MraAuthorize(lpszEMail, lstrlenA(lpszEMail));
+ MraAuthorize( CMStringA(lpszLastName + lstrlenA(lpszLastName) + 1));
return 0;
}
@@ -246,9 +245,9 @@ int CMraProto::AuthDeny(HANDLE hDBEvent, const TCHAR* szReason)
LPSTR lpszNick = (LPSTR)(dbei.pBlob + sizeof(DWORD)*2);
LPSTR lpszFirstName = lpszNick + lstrlenA(lpszNick) + 1;
LPSTR lpszLastName = lpszFirstName + lstrlenA(lpszFirstName) + 1;
- LPSTR lpszEMail = lpszLastName + lstrlenA(lpszLastName) + 1;
+ LPSTR szEmail = lpszLastName + lstrlenA(lpszLastName) + 1;
- MraMessageW(FALSE, NULL, 0, 0, lpszEMail, lstrlenA(lpszEMail), szReason, lstrlen(szReason), NULL, 0);
+ MraMessageW(FALSE, NULL, 0, 0, szEmail, szReason, NULL, 0);
return 0;
}
@@ -340,7 +339,7 @@ HANDLE CMraProto::SearchBasic(const TCHAR *id)
HANDLE CMraProto::SearchByEmail(const TCHAR *email)
{
if (m_bLoggedIn && email)
- return MraWPRequestByEMail(NULL, ACKTYPE_SEARCH, _T2A(email), lstrlen(email));
+ return MraWPRequestByEMail(NULL, ACKTYPE_SEARCH, CMStringA(email));
return NULL;
}
@@ -354,8 +353,7 @@ HANDLE CMraProto::SearchByName(const TCHAR *pszNick, const TCHAR *pszFirstName,
if (*pszNick) SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_NICKNAME);
if (*pszFirstName) SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_FIRSTNAME);
if (*pszLastName) SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_LASTNAME);
- return MraWPRequestW(NULL, ACKTYPE_SEARCH, dwRequestFlags, NULL, 0, NULL, 0,
- pszNick, lstrlen(pszNick), pszFirstName, lstrlen(pszFirstName), pszLastName, lstrlen(pszLastName), 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ return MraWPRequestW(NULL, ACKTYPE_SEARCH, dwRequestFlags, "", "", pszNick, pszFirstName, pszLastName, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
return NULL;
@@ -394,35 +392,19 @@ int CMraProto::SendContacts(HANDLE hContact, int flags, int nContacts, HANDLE* h
if (m_bLoggedIn && hContact) {
BOOL bSlowSend;
- CHAR szEMail[MAX_EMAIL_LEN];
- LPWSTR lpwszData, lpwszDataCurrent, lpwszNick;
- size_t dwDataBuffSize, dwEMailSize, dwStringSize, dwNickSize;
-
- dwDataBuffSize = (nContacts*(MAX_EMAIL_LEN*2));
- lpwszData = (LPWSTR)mir_calloc((dwDataBuffSize*sizeof(WCHAR)));
- if (lpwszData) {
- lpwszDataCurrent = lpwszData;
- if ( mraGetStaticStringA(hContact, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize)) {
- for (int i = 0; i < nContacts; i++) {
- if ( IsContactMra( hContactsList[i] ))
- if ( mraGetStaticStringW(hContactsList[i], "e-mail", lpwszDataCurrent, dwDataBuffSize-(lpwszDataCurrent-lpwszData), &dwStringSize)) {
- lpwszDataCurrent += dwStringSize;
- *lpwszDataCurrent++ = ';';
-
- lpwszNick = GetContactNameW(hContactsList[i]);
- dwNickSize = lstrlenW(lpwszNick);
- memmove(lpwszDataCurrent, lpwszNick, dwNickSize*sizeof(WCHAR));
- lpwszDataCurrent += dwNickSize;
- *lpwszDataCurrent++ = ';';
- }
- }
-
- bSlowSend = getByte("SlowSend", MRA_DEFAULT_SLOW_SEND);
- iRet = MraMessageW(bSlowSend, hContact, ACKTYPE_CONTACTS, MESSAGE_FLAG_CONTACT, szEMail, dwEMailSize, lpwszData, (lpwszDataCurrent-lpwszData), NULL, 0);
- if (bSlowSend == FALSE)
- ProtoBroadcastAck(hContact, ACKTYPE_CONTACTS, ACKRESULT_SUCCESS, (HANDLE)iRet, 0);
+ CMStringW wszData, wszEmail;
+ CMStringA szEmail;
+ if ( mraGetStringA(hContact, "e-mail", szEmail)) {
+ for (int i = 0; i < nContacts; i++) {
+ if ( IsContactMra( hContactsList[i] ))
+ if ( mraGetStringW(hContactsList[i], "e-mail", wszEmail))
+ wszData += wszEmail + ';' + GetContactNameW(hContactsList[i]) + ';';
}
- mir_free(lpwszData);
+
+ bSlowSend = getByte("SlowSend", MRA_DEFAULT_SLOW_SEND);
+ iRet = MraMessageW(bSlowSend, hContact, ACKTYPE_CONTACTS, MESSAGE_FLAG_CONTACT, szEmail, wszData, NULL, 0);
+ if (bSlowSend == FALSE)
+ ProtoBroadcastAck(hContact, ACKTYPE_CONTACTS, ACKRESULT_SUCCESS, (HANDLE)iRet, 0);
}
}
else ProtoBroadcastAck(hContact, ACKTYPE_CONTACTS, ACKRESULT_FAILED, NULL, (LPARAM)"You cannot send when you are offline.");
@@ -449,7 +431,6 @@ int CMraProto::SendMsg(HANDLE hContact, int flags, const char *lpszMessage)
return 0;
}
- CHAR szEMail[MAX_EMAIL_LEN];
DWORD dwFlags = 0;
LPWSTR lpwszMessage = NULL;
int iRet = 0;
@@ -466,13 +447,13 @@ int CMraProto::SendMsg(HANDLE hContact, int flags, const char *lpszMessage)
return 0;
}
- size_t dwEMailSize;
- if ( mraGetStaticStringA(hContact, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize)) {
+ CMStringA szEmail;
+ if ( mraGetStringA(hContact, "e-mail", szEmail)) {
BOOL bSlowSend = getByte("SlowSend", MRA_DEFAULT_SLOW_SEND);
if ( getByte("RTFSendEnable", MRA_DEFAULT_RTF_SEND_ENABLE) && (MraContactCapabilitiesGet(hContact) & FEATURE_FLAG_RTF_MESSAGE))
dwFlags |= MESSAGE_FLAG_RTF;
- iRet = MraMessageW(bSlowSend, hContact, ACKTYPE_MESSAGE, dwFlags, szEMail, dwEMailSize, lpwszMessage, lstrlen(lpwszMessage), NULL, 0);
+ iRet = MraMessageW(bSlowSend, hContact, ACKTYPE_MESSAGE, dwFlags, szEmail, lpwszMessage, NULL, 0);
if (bSlowSend == FALSE)
ProtoBroadcastAckAsync(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)iRet, 0);
}
@@ -494,12 +475,11 @@ int CMraProto::SetApparentMode(HANDLE hContact, int mode)
// Dont send redundant updates
if (mode != dwOldMode) {
- CHAR szEMail[MAX_EMAIL_LEN], szPhones[MAX_EMAIL_LEN];
- WCHAR wszNick[MAX_EMAIL_LEN];
+ CMStringA szEmail, szPhones;
+ CMStringW wszNick;
DWORD dwID, dwGroupID, dwContactFlag = 0;
- size_t dwEMailSize, dwNickSize, dwPhonesSize;
- GetContactBasicInfoW(hContact, &dwID, &dwGroupID, &dwContactFlag, NULL, NULL, szEMail, SIZEOF(szEMail), &dwEMailSize, wszNick, SIZEOF(wszNick), &dwNickSize, szPhones, SIZEOF(szPhones), &dwPhonesSize);
+ GetContactBasicInfoW(hContact, &dwID, &dwGroupID, &dwContactFlag, NULL, NULL, &szEmail, &wszNick, &szPhones);
dwContactFlag &= ~(CONTACT_FLAG_INVISIBLE | CONTACT_FLAG_VISIBLE);
switch (mode) {
@@ -511,8 +491,8 @@ int CMraProto::SetApparentMode(HANDLE hContact, int mode)
break;
}
- if (MraModifyContactW(hContact, dwID, dwContactFlag, dwGroupID, szEMail, dwEMailSize, wszNick, dwNickSize, szPhones, dwPhonesSize)) {
- SetContactBasicInfoW(hContact, 0, SCBIF_FLAG, 0, 0, dwContactFlag, 0, 0, NULL, 0, NULL, 0, NULL, 0);
+ if (MraModifyContactW(hContact, dwID, dwContactFlag, dwGroupID, szEmail, wszNick, szPhones)) {
+ SetContactBasicInfoW(hContact, 0, SCBIF_FLAG, 0, 0, dwContactFlag, 0, 0, "", L"", "");
return 0; // Success
}
}
@@ -550,9 +530,9 @@ int CMraProto::SetStatus(int iNewStatus)
if (dwOldStatusMode > ID_STATUS_OFFLINE) {
// функция сама проверяет принадлежность контакта к MRA
for (HANDLE hContact = db_find_first();hContact != NULL;hContact = db_find_next(hContact))
- SetContactBasicInfoW(hContact, SCBIFSI_LOCK_CHANGES_EVENTS, (SCBIF_ID|SCBIF_GROUP_ID|SCBIF_SERVER_FLAG|SCBIF_STATUS), -1, -1, 0, 0, ID_STATUS_OFFLINE, NULL, 0, NULL, 0, NULL, 0);
+ SetContactBasicInfoW(hContact, SCBIFSI_LOCK_CHANGES_EVENTS, (SCBIF_ID|SCBIF_GROUP_ID|SCBIF_SERVER_FLAG|SCBIF_STATUS), -1, -1, 0, 0, ID_STATUS_OFFLINE, "", L"", "");
}
- Netlib_CloseHandle(hConnection);
+ Netlib_CloseHandle(m_hConnection);
}
else {
// если offline то сразу ставим connecting, но обработка как offline
@@ -571,7 +551,7 @@ int CMraProto::SetStatus(int iNewStatus)
case ID_STATUS_DND:
case ID_STATUS_FREECHAT:
case ID_STATUS_INVISIBLE:
- MraSendNewStatus(m_iDesiredStatus, m_iXStatus, NULL, 0, NULL, 0);
+ MraSendNewStatus(m_iDesiredStatus, m_iXStatus, L"", L"");
case ID_STATUS_CONNECTING:
// предотвращаем переход в любой статус (кроме offline) из статуса connecting, если он не вызван самим плагином
if (dwOldStatusMode == ID_STATUS_CONNECTING && iNewStatus != m_iDesiredStatus)
@@ -592,11 +572,12 @@ HANDLE CMraProto::GetAwayMsg(HANDLE hContact)
if (!m_bLoggedIn || ! hContact)
return 0;
- TCHAR szStatusDesc[MICBLOG_STATUS_MAX+MICBLOG_STATUS_MAX+MAX_PATH], szBlogStatus[MICBLOG_STATUS_MAX+4], szTime[64];
+ TCHAR szStatusDesc[MICBLOG_STATUS_MAX+MICBLOG_STATUS_MAX+MAX_PATH], szTime[64];
DWORD dwTime;
int iRet = 0;
- if ( mraGetStaticStringW(hContact, DBSETTING_BLOGSTATUS, szBlogStatus, SIZEOF(szBlogStatus), NULL)) {
+ CMStringW szBlogStatus;
+ if ( mraGetStringW(hContact, DBSETTING_BLOGSTATUS, szBlogStatus)) {
SYSTEMTIME tt = {0};
dwTime = getDword(hContact, DBSETTING_BLOGSTATUSTIME, 0);
if (dwTime && MakeLocalSystemTimeFromTime32(dwTime, &tt))
@@ -604,7 +585,7 @@ HANDLE CMraProto::GetAwayMsg(HANDLE hContact)
else
szTime[0] = 0;
- mir_sntprintf(szStatusDesc, SIZEOF(szStatusDesc), _T("%s%s"), szTime, szBlogStatus);
+ mir_sntprintf(szStatusDesc, SIZEOF(szStatusDesc), _T("%s%s"), szTime, szBlogStatus.c_str());
iRet = GetTickCount();
ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)iRet, (LPARAM)szStatusDesc);
}
@@ -623,7 +604,7 @@ int CMraProto::SetAwayMsg(int m_iStatus, const TCHAR* msg)
// не отправляем новый статусный текст для хстатусов, для хстатусов только эвей сообщения
if (dwStatus != ID_STATUS_ONLINE || IsXStatusValid(dwXStatus) == FALSE) {
dwStatusDescSize = min(dwStatusDescSize, STATUS_DESC_MAX);
- MraSendNewStatus(dwStatus, dwXStatus, NULL, 0, msg, dwStatusDescSize);
+ MraSendNewStatus(dwStatus, dwXStatus, L"", msg);
}
return 0;
}
@@ -633,12 +614,10 @@ int CMraProto::UserIsTyping(HANDLE hContact, int type)
if (!m_bLoggedIn || !hContact || type == PROTOTYPE_SELFTYPING_OFF)
return 1;
- CHAR szEMail[MAX_EMAIL_LEN];
- size_t dwEMailSize;
-
+ CMStringA szEmail;
if ( MraGetContactStatus(hContact) != ID_STATUS_OFFLINE && m_iStatus != ID_STATUS_INVISIBLE)
- if ( mraGetStaticStringA(hContact, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize))
- if ( MraMessageW(FALSE, hContact, 0, MESSAGE_FLAG_NOTIFY, szEMail, dwEMailSize, L" ", 1, NULL, 0))
+ if ( mraGetStringA(hContact, "e-mail", szEmail))
+ if ( MraMessageW(FALSE, hContact, 0, MESSAGE_FLAG_NOTIFY, szEmail, L" ", NULL, 0))
return 0;
return 1;
diff --git a/protocols/MRA/src/MraProto.h b/protocols/MRA/src/MraProto.h
index 341398d368..e0f7e06254 100644
--- a/protocols/MRA/src/MraProto.h
+++ b/protocols/MRA/src/MraProto.h
@@ -21,8 +21,11 @@ struct MRA_FILES_QUEUE_ITEM;
BOOL DB_GetStaticStringA(HANDLE hContact, LPCSTR lpszModule, LPCSTR lpszValueName, LPSTR lpszRetBuff, size_t dwRetBuffSize, size_t *pdwRetBuffSize);
BOOL DB_GetStaticStringW(HANDLE hContact, LPCSTR lpszModule, LPCSTR lpszValueName, LPWSTR lpszRetBuff, size_t dwRetBuffSize, size_t *pdwRetBuffSize);
-BOOL DB_SetStringExA(HANDLE hContact, LPCSTR lpszModule, LPCSTR lpszValueName, LPCSTR lpszValue, size_t dwValueSize);
-BOOL DB_SetStringExW(HANDLE hContact, LPCSTR lpszModule, LPCSTR lpszValueName, LPCWSTR lpwszValue, size_t dwValueSize);
+BOOL DB_GetStringA(HANDLE hContact, LPCSTR lpszModule, LPCSTR lpszValueName, CMStringA &Ret);
+BOOL DB_GetStringW(HANDLE hContact, LPCSTR lpszModule, LPCSTR lpszValueName, CMStringW &Ret);
+
+BOOL DB_SetStringExA(HANDLE hContact, LPCSTR lpszModule, LPCSTR lpszValueName, const CMStringA &value);
+BOOL DB_SetStringExW(HANDLE hContact, LPCSTR lpszModule, LPCSTR lpszValueName, const CMStringW &value);
BOOL DB_GetContactSettingBlob(HANDLE hContact, LPCSTR lpszModule, LPCSTR lpszValueName, LPVOID lpRet, size_t dwRetBuffSize, size_t *pdwRetBuffSize);
@@ -82,9 +85,9 @@ struct CMraProto : public PROTO<CMraProto>
virtual int __cdecl OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM lParam);
void ShowFormattedErrorMessage(LPWSTR lpwszErrText, DWORD dwErrorCode);
- void MraPopupShowW(HANDLE hContact, DWORD dwType, DWORD dwFlags, LPWSTR lpszTitle, LPWSTR lpszMessage);
- void MraPopupShowFromContactW(HANDLE hContact, DWORD dwType, DWORD dwFlags, LPWSTR lpszMessage);
- __forceinline void MraPopupShowFromAgentW(DWORD dwType, DWORD dwFlags, LPWSTR lpszMessage) {
+ void MraPopupShowW(HANDLE hContact, DWORD dwType, DWORD dwFlags, LPWSTR lpszTitle, LPCWSTR lpszMessage);
+ void MraPopupShowFromContactW(HANDLE hContact, DWORD dwType, DWORD dwFlags, LPCWSTR lpszMessage);
+ __forceinline void MraPopupShowFromAgentW(DWORD dwType, DWORD dwFlags, LPCWSTR lpszMessage) {
MraPopupShowFromContactW(NULL, dwType, dwFlags, lpszMessage); }
__forceinline BOOL mraGetStaticStringA(HANDLE Contact, const char *ValueName, char *Ret, size_t RetBuffSize, size_t *pRetBuffSize) {
@@ -92,20 +95,20 @@ struct CMraProto : public PROTO<CMraProto>
__forceinline BOOL mraGetStaticStringW(HANDLE Contact, const char *ValueName, WCHAR *Ret, size_t RetBuffSize, size_t *pRetBuffSize) {
return DB_GetStaticStringW(Contact, m_szModuleName, ValueName, Ret, RetBuffSize, pRetBuffSize); }
- __forceinline BOOL mraSetStringA(HANDLE Contact, const char *valueName, const char *parValue) {
- return DB_SetStringExA(Contact, m_szModuleName, valueName, parValue, lstrlenA(parValue)); }
- __forceinline BOOL mraSetStringW(HANDLE Contact, const char *valueName, const WCHAR *parValue) {
- return db_set_ws(Contact, m_szModuleName, valueName, parValue); }
+ __forceinline BOOL mraGetStringA(HANDLE Contact, const char *ValueName, CMStringA &Ret) {
+ return DB_GetStringA(Contact, m_szModuleName, ValueName, Ret); }
+ __forceinline BOOL mraGetStringW(HANDLE Contact, const char *ValueName, CMStringW &Ret) {
+ return DB_GetStringW(Contact, m_szModuleName, ValueName, Ret); }
- __forceinline BOOL mraSetLPSStringA(HANDLE Contact, const char *valueName, MRA_LPS *parValue) {
- return DB_SetStringExA(Contact, m_szModuleName, valueName, parValue->lpszData, parValue->dwSize); }
- __forceinline BOOL mraSetLPSStringW(HANDLE Contact, const char *valueName, MRA_LPS *parValue) {
- return DB_SetStringExW(Contact, m_szModuleName, valueName, parValue->lpwszData, parValue->dwSize/sizeof(WCHAR)); }
+ __forceinline BOOL mraSetStringA(HANDLE Contact, const char *valueName, const CMStringA &parValue) {
+ return DB_SetStringExA(Contact, m_szModuleName, valueName, parValue); }
+ __forceinline BOOL mraSetStringW(HANDLE Contact, const char *valueName, const CMStringW &parValue) {
+ return DB_SetStringExW(Contact, m_szModuleName, valueName, parValue); }
- __forceinline BOOL mraSetStringExA(HANDLE Contact, const char *valueName, const char *parValue, size_t parValueSize) {
- return DB_SetStringExA(Contact, m_szModuleName, valueName, parValue, parValueSize); }
- __forceinline BOOL mraSetStringExW(HANDLE Contact, const char *valueName, const WCHAR *parValue, size_t parValueSize) {
- return DB_SetStringExW(Contact, m_szModuleName, valueName, parValue, parValueSize); }
+ __forceinline BOOL mraSetStringExA(HANDLE Contact, const char *valueName, const CMStringA &parValue) {
+ return DB_SetStringExA(Contact, m_szModuleName, valueName, parValue); }
+ __forceinline BOOL mraSetStringExW(HANDLE Contact, const char *valueName, const CMStringW &parValue) {
+ return DB_SetStringExW(Contact, m_szModuleName, valueName, parValue); }
__forceinline BOOL mraWriteContactSettingBlob(HANDLE hContact, const char *lpszValueName, LPVOID lpbValue, size_t dwValueSize) {
return db_set_blob(hContact, m_szModuleName, lpszValueName, lpbValue, dwValueSize); }
@@ -165,26 +168,26 @@ struct CMraProto : public PROTO<CMraProto>
int __cdecl MraMusicChanged(WPARAM, LPARAM);
// ====| Data |========================================================================
- bool m_bLoggedIn;
+ bool m_bLoggedIn;
- HANDLE hSendQueueHandle, hFilesQueueHandle, hMPopSessionQueue;
+ HANDLE hSendQueueHandle, hFilesQueueHandle, hMPopSessionQueue;
- HANDLE hNetlibUser, heNudgeReceived;
- HANDLE hThreadWorker;
- HANDLE hConnection;
- DWORD dwThreadWorkerLastPingTime;
- DWORD dwThreadWorkerRunning;
- DWORD dwCMDNum;
+ HANDLE m_hNetlibUser, m_heNudgeReceived;
+ HANDLE m_hThreadWorker;
+ HANDLE m_hConnection;
+ DWORD m_dwThreadWorkerLastPingTime, m_dwNextPingSendTickTime, m_dwPingPeriod;
+ DWORD m_dwThreadWorkerRunning;
+ DWORD dwCMDNum;
- HANDLE hAvatarsQueueHandle;
+ HANDLE hAvatarsQueueHandle;
HGENMENU hMainMenuItems[MAIN_MENU_ITEMS_COUNT+4];
HGENMENU hContactMenuItems[CONTACT_MENU_ITEMS_COUNT+4];
HWND hWndEMailPopupStatus;
- DWORD dwEmailMessagesTotal, dwEmailMessagesUnread;
+ DWORD dwEmailMessagesTotal, m_dwEmailMessagesUnread;
- BOOL bHideXStatusUI;
+ bool bHideXStatusUI;
HGENMENU hXStatusMenuItems[MRA_XSTATUS_COUNT+4];
HANDLE hExtraXstatusIcon;
HANDLE hExtraInfo;
@@ -195,102 +198,122 @@ struct CMraProto : public PROTO<CMraProto>
HANDLE AddToListByEmail(LPCTSTR plpsEMail, LPCTSTR plpsNick, LPCTSTR plpsFirstName, LPCTSTR plpsLastName, DWORD dwFlags);
- DWORD MraMessageW(BOOL bAddToQueue, HANDLE hContact, DWORD dwAckType, DWORD dwFlags, LPSTR lpszEMail, size_t dwEMailSize, LPCWSTR lpwszMessage, size_t dwMessageSize, LPBYTE lpbMultiChatData, size_t dwMultiChatDataSize);
- DWORD MraMessageAskW(DWORD dwMsgID, DWORD dwFlags, LPSTR lpszEMail, size_t dwEMailSize, LPWSTR lpwszMessage, size_t dwMessageSize, LPSTR lpwszMessageRTF, size_t dwMessageRTFSize);
- DWORD MraMessageRecv(LPSTR lpszFrom, size_t dwFromSize, DWORD dwMsgID);
- DWORD MraAddContactW(HANDLE hContact, DWORD dwContactFlag, DWORD dwGroupID, LPSTR lpszEMail, size_t dwEMailSize, LPWSTR lpwszCustomName, size_t dwCustomNameSize, LPSTR lpszPhones, size_t dwPhonesSize, LPWSTR lpwszAuthMessage, size_t dwAuthMessageSize, DWORD dwActions);
- DWORD MraModifyContactW(HANDLE hContact, DWORD dwID, DWORD dwContactFlag, DWORD dwGroupID, LPSTR lpszEMail, size_t dwEMailSize, LPWSTR lpwszCustomName, size_t dwCustomNameSize, LPSTR lpszPhones, size_t dwPhonesSize);
+ DWORD MraMessageW(BOOL bAddToQueue, HANDLE hContact, DWORD dwAckType, DWORD dwFlags, const CMStringA &szEmail, const CMStringW &wszMessage, LPBYTE lpbMultiChatData, size_t dwMultiChatDataSize);
+ DWORD MraMessageAskW(DWORD dwMsgID, DWORD dwFlags, const CMStringA &szEmail, const CMStringW &wszMessage, const CMStringW &wszMessageRTF);
+ DWORD MraMessageRecv(const CMStringA &szFrom, DWORD dwMsgID);
+ DWORD MraAddContactW(HANDLE hContact, DWORD dwContactFlag, DWORD dwGroupID, const CMStringA &szEmail, const CMStringW &wszCustomName, const CMStringA &szPhones, const CMStringW &wszAuthMessage, DWORD dwActions);
+ DWORD MraModifyContactW(HANDLE hContact, DWORD dwID, DWORD dwContactFlag, DWORD dwGroupID, const CMStringA &szEmail, const CMStringW &wszCustomName, const CMStringA &szPhones);
DWORD MraOfflineMessageDel(DWORDLONG dwMsgUIDL);
- DWORD MraAuthorize(LPSTR lpszEMail, size_t dwEMailSize);
- DWORD MraChangeStatusW(DWORD dwStatus, LPSTR lpszStatusUri, size_t dwStatusUriSize, LPCWSTR lpwszStatusTitle, size_t dwStatusTitleSize, LPCWSTR lpwszStatusDesc, size_t dwStatusDescSize, DWORD dwFutureFlags);
- DWORD MraFileTransfer(LPSTR lpszEMail, size_t dwEMailSize, DWORD dwIdRequest, DWORD dwFilesTotalSize, LPWSTR lpwszFiles, size_t dwFilesSize, LPSTR lpszAddreses, size_t dwAddresesSize);
- DWORD MraFileTransferAck(DWORD dwStatus, LPSTR lpszEMail, size_t dwEMailSize, DWORD dwIdRequest, LPBYTE lpbDescription, size_t dwDescriptionSize);
- HANDLE MraWPRequestW(HANDLE hContact, DWORD dwAckType, DWORD dwRequestFlags, LPSTR lpszUser, size_t dwUserSize, LPSTR lpszDomain, size_t dwDomainSize, LPCWSTR lpwszNickName, size_t dwNickNameSize, LPCWSTR lpwszFirstName, size_t dwFirstNameSize, LPCWSTR lpwszLastName, size_t dwLastNameSize, DWORD dwSex, DWORD dwDate1, DWORD dwDate2, DWORD dwCityID, DWORD dwZodiak, DWORD dwBirthdayMonth, DWORD dwBirthdayDay, DWORD dwCountryID, DWORD dwOnline);
- HANDLE MraWPRequestA(HANDLE hContact, DWORD dwAckType, DWORD dwRequestFlags, LPSTR lpszUser, size_t dwUserSize, LPSTR lpszDomain, size_t dwDomainSize, LPSTR lpszNickName, size_t dwNickNameSize, LPSTR lpszFirstName, size_t dwFirstNameSize, LPSTR lpszLastName, size_t dwLastNameSize, DWORD dwSex, DWORD dwDate1, DWORD dwDate2, DWORD dwCityID, DWORD dwZodiak, DWORD dwBirthdayMonth, DWORD dwBirthdayDay, DWORD dwCountryID, DWORD dwOnline);
- HANDLE MraWPRequestByEMail(HANDLE hContact, DWORD dwAckType, LPCSTR lpszEMail, size_t dwEMailSize);
- DWORD MraGame(LPSTR lpszEMail, size_t dwEMailSize, DWORD dwGameSessionID, DWORD dwGameMsg, DWORD dwGameMsgID, LPSTR lpszData, size_t dwDataSize);
- DWORD MraLogin2W(LPSTR lpszLogin, size_t dwLoginSize, LPSTR lpszPassword, size_t dwPasswordSize, DWORD dwStatus, LPSTR lpszStatusUri, size_t dwStatusUriSize, LPWSTR lpwszStatusTitle, size_t dwStatusTitleSize, LPWSTR lpwszStatusDesc, size_t dwStatusDescSize, DWORD dwFutureFlags, LPSTR dwUserAgentFormatted, size_t dwUserAgentFormattedSize, LPSTR lpszUserAgent, size_t dwUserAgentSize);
- DWORD MraSMSW(HANDLE hContact, LPSTR lpszPhone, size_t dwPhoneSize, LPWSTR lpwszMessage, size_t dwMessageSize);
- DWORD MraProxy(LPSTR lpszEMail, size_t dwEMailSize, DWORD dwIDRequest, DWORD dwDataType, LPSTR lpszData, size_t dwDataSize, LPSTR lpszAddreses, size_t dwAddresesSize, MRA_GUID mguidSessionID);
- DWORD MraProxyAck(DWORD dwStatus, LPSTR lpszEMail, size_t dwEMailSize, DWORD dwIDRequest, DWORD dwDataType, LPSTR lpszData, size_t dwDataSize, LPSTR lpszAddreses, size_t dwAddresesSize, MRA_GUID mguidSessionID);
- DWORD MraChangeUserBlogStatus(DWORD dwFlags, LPWSTR lpwszText, size_t dwTextSize, DWORDLONG dwBlogStatusID);
-
- DWORD MraSendPacket(HANDLE hConnection, DWORD dwCMDNum, DWORD dwType, LPVOID lpData, size_t dwDataSize);
+ DWORD MraAuthorize(const CMStringA &szEmail);
+ DWORD MraChangeStatusW(DWORD dwStatus, const CMStringA &szStatusUri, const CMStringW &wszStatusTitle, const CMStringW &wszStatusDesc, DWORD dwFutureFlags);
+ DWORD MraFileTransfer(const CMStringA &szEmail, DWORD dwIdRequest, DWORD dwFilesTotalSize, const CMStringW &lpwszFiles, const CMStringA &szAddresses);
+ DWORD MraFileTransferAck(DWORD dwStatus, const CMStringA &szEmail, DWORD dwIdRequest, LPBYTE lpbDescription, size_t dwDescriptionSize);
+ HANDLE MraWPRequestW(HANDLE hContact, DWORD dwAckType, DWORD dwRequestFlags, const CMStringA &szUser, const CMStringA &szDomain, const CMStringW &wszNickName, const CMStringW &wszFirstName, const CMStringW &wszLastName, DWORD dwSex, DWORD dwDate1, DWORD dwDate2, DWORD dwCityID, DWORD dwZodiak, DWORD dwBirthdayMonth, DWORD dwBirthdayDay, DWORD dwCountryID, DWORD dwOnline);
+ HANDLE MraWPRequestByEMail(HANDLE hContact, DWORD dwAckType, CMStringA &szEmail);
+ DWORD MraGame(const CMStringA &szEmail, DWORD dwGameSessionID, DWORD dwGameMsg, DWORD dwGameMsgID, const CMStringA &lpszData);
+ DWORD MraLogin2W(CMStringA &szLogin, CMStringA &szPassword, DWORD dwStatus, CMStringA &szStatusUri, CMStringW &wszStatusTitle, CMStringW &wszStatusDesc, DWORD dwFutureFlags, CMStringA &szUserAgentFormatted, CMStringA &szUserAgent);
+ DWORD MraSMSW(HANDLE hContact, const CMStringA &lpszPhone, const CMStringW &lpwszMessage);
+ DWORD MraProxy(const CMStringA &szEmail, DWORD dwIDRequest, DWORD dwDataType, const CMStringA &lpszData, const CMStringA &szAddresses, MRA_GUID mguidSessionID);
+ 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 MraSendCMD(DWORD dwType, LPVOID lpData, size_t dwDataSize);
DWORD MraSendQueueCMD(HANDLE hSendQueueHandle, DWORD dwFlags, HANDLE hContact, DWORD dwAckType, LPBYTE lpbDataQueue, size_t dwDataQueueSize, DWORD dwType, LPVOID lpData, size_t dwDataSize);
- DWORD MraSendNewStatus(DWORD dwStatusMir, DWORD dwXStatusMir, LPCWSTR lpwszStatusTitle, size_t dwStatusTitleSize, LPCWSTR lpwszStatusDesc, size_t dwStatusDescSize);
+ DWORD MraSendNewStatus(DWORD dwStatusMir, DWORD dwXStatusMir, const CMStringW &wszStatusTitle, const CMStringW &wszStatusDesc);
void MraAddrListStoreToContact(HANDLE hContact, MRA_ADDR_LIST *pmalAddrList);
DWORD GetContactFlags(HANDLE hContact);
DWORD SetContactFlags(HANDLE hContact, DWORD dwContactFlag);
- DWORD GetContactBasicInfoW(HANDLE hContact, DWORD *pdwID, DWORD *pdwGroupID, DWORD *pdwContactFlag, DWORD *pdwContactSeverFlags, DWORD *pdwStatus, LPSTR lpszEMail, size_t dwEMailSize, size_t *pdwEMailSize, LPWSTR lpwszNick, size_t dwNickSize, size_t *pdwNickSize, LPSTR lpszPhones, size_t dwPhonesSize, size_t *pdwPhonesSize);
- DWORD SetContactBasicInfoW(HANDLE hContact, DWORD dwSetInfoFlags, DWORD dwFlags, DWORD dwID, DWORD dwGroupID, DWORD dwContactFlag, DWORD dwContactSeverFlags, DWORD dwStatus, LPSTR lpszEMail, size_t dwEMailSize, LPWSTR lpwszNick, size_t dwNickSize, LPSTR lpszPhones, size_t dwPhonesSize);
+ DWORD GetContactBasicInfoW(HANDLE hContact, DWORD *pdwID, DWORD *pdwGroupID, DWORD *pdwContactFlag, DWORD *pdwContactSeverFlags, DWORD *pdwStatus, CMStringA *szEmail, CMStringW *wszNick, CMStringA *szPhones);
+ DWORD SetContactBasicInfoW(HANDLE hContact, DWORD dwSetInfoFlags, DWORD dwFlags, DWORD dwID, DWORD dwGroupID, DWORD dwContactFlag, DWORD dwContactSeverFlags, DWORD dwStatus, const CMStringA &szEmail, const CMStringW &wszNick, const CMStringA &szPhones);
DWORD GetContactEMailCount(HANDLE hContact, BOOL bMRAOnly);
- BOOL GetContactFirstEMail(HANDLE hContact, BOOL bMRAOnly, LPSTR lpszRetBuff, size_t dwRetBuffSize, size_t *pdwRetBuffSize);
+ bool GetContactFirstEMail(HANDLE hContact, BOOL bMRAOnly, CMStringA &szRetBuff);
- BOOL IsContactMra(HANDLE hContact);
- BOOL IsEMailMy(LPSTR lpszEMail, size_t dwEMailSize);
- BOOL IsEMailChatAgent(LPSTR lpszEMail, size_t dwEMailSize);
- BOOL IsContactChatAgent(HANDLE hContact);
+ bool IsContactMra(HANDLE hContact);
+ bool IsEMailMy(const CMStringA &szEmail);
+ bool IsEMailChatAgent(const CMStringA &szEmail);
+ bool IsContactChatAgent(HANDLE hContact);
- HANDLE MraHContactFromEmail(LPSTR lpszEMail, size_t dwEMailSize, BOOL bAddIfNeeded, BOOL bTemporary, BOOL *pbAdded);
- BOOL MraUpdateContactInfo(HANDLE hContact);
+ HANDLE MraHContactFromEmail(const CMStringA &szEmail, BOOL bAddIfNeeded, BOOL bTemporary, BOOL *pbAdded);
+ bool MraUpdateContactInfo(HANDLE hContact);
DWORD MraSetXStatusInternal(DWORD dwXStatus);
DWORD MraGetContactStatus(HANDLE hContact);
DWORD MraSetContactStatus(HANDLE hContact, DWORD dwNewStatus);
DWORD MraContactCapabilitiesGet(HANDLE hContact);
void MraContactCapabilitiesSet(HANDLE hContact, DWORD dwFutureFlags);
- void MraUpdateEmailStatus(LPSTR lpszFrom, size_t dwFromSize, LPSTR lpszSubject, size_t dwSubjectSize, DWORD dwDate, DWORD dwUIDL);
- DWORD MraConvertToRTFW(LPCWSTR lpwszMessage, size_t dwMessageSize, LPSTR lpszMessageRTF, size_t dwMessageRTFBuffSize, size_t *pdwMessageRTFSize);
+ void MraUpdateEmailStatus(const CMStringA &szFrom, const CMStringA &szSubject, DWORD dwDate, DWORD dwUIDL);
+ DWORD MraConvertToRTFW(const CMStringW &wszMessage, CMStringA &szMessageRTF);
void MraThreadClean();
DWORD StartConnect();
void __cdecl MraThreadProc(LPVOID lpParameter);
- DWORD MraGetNLBData(LPSTR lpszHost, size_t dwHostBuffSize, WORD *pwPort);
+ DWORD MraGetNLBData(CMStringA &szHost, WORD *pwPort);
DWORD MraNetworkDispatcher();
- DWORD MraCommandDispatcher(struct mrim_packet_header_t *pmaHeader, DWORD *pdwPingPeriod, DWORD *pdwNextPingSendTickTime, BOOL *pbContinue);
- DWORD MraRecvCommand_Message(DWORD dwTime, DWORD dwFlags, MRA_LPS *plpsFrom, MRA_LPS *plpsText, MRA_LPS *plpsRFTText, MRA_LPS *plpsMultiChatData);
+ bool MraCommandDispatcher(struct mrim_packet_header_t *pmaHeader);
+ bool CmdHelloAck(BinBuffer &buf);
+ bool CmdLoginAck();
+ bool CmdLoginRejected(BinBuffer &buf);
+ bool CmdMessageAck(BinBuffer &buf);
+ bool CmdMessageStatus(ULONG seq, BinBuffer &buf);
+ bool CmdOfflineMessageAck(BinBuffer &buf);
+ bool CmdAuthAck(BinBuffer &buf);
+ bool CmdPopSession(BinBuffer &buf);
+ bool CmdFileTransfer(BinBuffer &buf);
+ bool CmdFileTransferAck(BinBuffer &buf);
+ bool CmdUserInfo(BinBuffer &buf);
+ bool CmdUserStatus(BinBuffer &buf);
+ bool CmdContactAck(int cmd, int seq, BinBuffer &buf);
+ bool CmdAnketaInfo(int seq, BinBuffer &buf);
+ bool CmdGame(BinBuffer &buf);
+ bool CmdClist2(BinBuffer &buf);
+ bool CmdProxy(BinBuffer &buf);
+ bool CmdProxyAck(BinBuffer &buf);
+ bool CmdNewMail(BinBuffer &buf);
+ bool CmdBlogStatus(BinBuffer &buf);
+
+ DWORD MraRecvCommand_Message(DWORD dwTime, DWORD dwFlags, CMStringA &plpsFrom, CMStringA &plpsText, CMStringA &plpsRFTText, CMStringA &plpsMultiChatData);
void SetExtraIcons(HANDLE hContact);
#define MESSAGE_NOT_SPAM 1
#define MESSAGE_SPAM 2
- DWORD MraAntiSpamReceivedMessageW(LPSTR lpszEMail, size_t dwEMailSize, DWORD dwMessageFlags, LPWSTR lpwszMessage, size_t dwMessageSize);
- BOOL MraAntiSpamHasMessageBadWordsW(LPWSTR lpwszMessage, size_t dwMessageSize);
+ DWORD MraAntiSpamReceivedMessageW(const CMStringA &szEmail, DWORD dwMessageFlags, const CMStringW &wszMessage);
+ bool MraAntiSpamHasMessageBadWordsW(const CMStringW &wszMessage);
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, HGENMENU *hResult);
DWORD ProtoBroadcastAckAsync(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);
+ CMStringA CreateBlobFromContact(HANDLE hContact, const CMStringW &wszRequestReason);
- BOOL SetPassDB(LPSTR lpszBuff, size_t dwBuffSize);
- BOOL GetPassDB(LPSTR lpszBuff, size_t dwBuffSize, size_t *pdwBuffSize);
+ bool SetPassDB(const CMStringA& pass);
+ bool GetPassDB(CMStringA& pass);
- BOOL MraRequestXStatusDetails(DWORD dwXStatus);
- BOOL MraSendReplyBlogStatus(HANDLE hContact);
+ bool MraRequestXStatusDetails(DWORD dwXStatus);
+ bool MraSendReplyBlogStatus(HANDLE hContact);
DWORD MraSelectEMailDlgShow(HANDLE hContact, DWORD dwType);
DWORD MraMrimProxyConnect(HANDLE hMraMrimProxyData, HANDLE *phConnection);
- DWORD MraMPopSessionQueueAddUrl(HANDLE hMPopSessionQueue, LPSTR lpszUrl, size_t dwUrlSize);
- DWORD MraMPopSessionQueueAddUrlAndEMail(HANDLE hMPopSessionQueue, LPSTR lpszUrl, size_t dwUrlSize, LPSTR lpszEMail, size_t dwEMailSize);
+ DWORD MraMPopSessionQueueAddUrl(HANDLE hMPopSessionQueue, const CMStringA &szUrl);
+ DWORD MraMPopSessionQueueAddUrlAndEMail(HANDLE hMPopSessionQueue, const CMStringA &, CMStringA &szEmail);
DWORD MraMPopSessionQueueStart(HANDLE hMPopSessionQueue);
void MraMPopSessionQueueFlush(HANDLE hMPopSessionQueue);
size_t MraFilesQueueGetLocalAddressesList(LPSTR lpszBuff, size_t dwBuffSize, DWORD dwPort);
- DWORD MraFilesQueueAddReceive(HANDLE hFilesQueueHandle, DWORD dwFlags, HANDLE hContact, DWORD dwIDRequest, LPWSTR lpwszFiles, size_t dwFilesSize, LPSTR lpszAddreses, size_t dwAddresesSize);
+ DWORD MraFilesQueueAddReceive(HANDLE hFilesQueueHandle, DWORD dwFlags, HANDLE hContact, DWORD dwIDRequest, const CMStringW &wszFiles, const CMStringA &szAddresses);
DWORD MraFilesQueueAddSend(HANDLE hFilesQueueHandle, DWORD dwFlags, HANDLE hContact, LPWSTR *plpwszFiles, size_t dwFilesCount, DWORD *pdwIDRequest);
DWORD MraFilesQueueCancel(HANDLE hFilesQueueHandle, DWORD dwIDRequest, BOOL bSendDecline);
DWORD MraFilesQueueStartMrimProxy(HANDLE hFilesQueueHandle, DWORD dwIDRequest);
- DWORD MraFilesQueueSendMirror(HANDLE hFilesQueueHandle, DWORD dwIDRequest, LPSTR lpszAddreses, size_t dwAddresesSize);
- BOOL MraFilesQueueHandCheck(HANDLE hConnection, MRA_FILES_QUEUE_ITEM *pmrafqFilesQueueItem);
+ DWORD MraFilesQueueSendMirror(HANDLE hFilesQueueHandle, DWORD dwIDRequest, const CMStringA &szAddresses);
+ bool MraFilesQueueHandCheck(HANDLE m_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);
@@ -298,29 +321,29 @@ struct CMraProto : public PROTO<CMraProto>
void __cdecl MraFilesQueueRecvThreadProc(LPVOID lpParameter);
void __cdecl MraFilesQueueSendThreadProc(LPVOID lpParameter);
- BOOL bChatExists;
+ bool bChatExists;
void MraChatDllError();
- BOOL MraChatRegister();
+ bool MraChatRegister();
INT_PTR MraChatSessionNew(HANDLE hContactChatSession);
void MraChatSessionDestroy(HANDLE hContactChatSession);
- void MraChatSendPrivateMessage(LPWSTR lpwszEMail);
+ void MraChatSendPrivateMessage(LPSTR lpwszEMail);
- INT_PTR MraChatSessionEventSendByHandle(HANDLE hContactChatSession, DWORD dwType, DWORD dwFlags, LPSTR lpszUID, size_t dwUIDSize, LPWSTR lpwszStatus, LPWSTR lpwszMessage, DWORD_PTR dwItemData, DWORD dwTime);
- INT_PTR MraChatSessionInvite(HANDLE hContactChatSession, LPSTR lpszEMailInMultiChat, size_t dwEMailInMultiChatSize, DWORD dwTime);
- INT_PTR MraChatSessionMembersAdd(HANDLE hContactChatSession, LPSTR lpszEMailInMultiChat, size_t dwEMailInMultiChatSize, DWORD dwTime);
- INT_PTR MraChatSessionJoinUser(HANDLE hContactChatSession, LPSTR lpszEMailInMultiChat, size_t dwEMailInMultiChatSize, DWORD dwTime);
- INT_PTR MraChatSessionLeftUser(HANDLE hContactChatSession, LPSTR lpszEMailInMultiChat, size_t dwEMailInMultiChatSize, DWORD dwTime);
- INT_PTR MraChatSessionSetIviter(HANDLE hContactChatSession, LPSTR lpszEMailInMultiChat, size_t dwEMailInMultiChatSize);
- INT_PTR MraChatSessionSetOwner(HANDLE hContactChatSession, LPSTR lpszEMailInMultiChat, size_t dwEMailInMultiChatSize);
- INT_PTR MraChatSessionMessageAdd(HANDLE hContactChatSession, LPSTR lpszEMailInMultiChat, size_t dwEMailInMultiChatSize, LPWSTR lpwszMessage, size_t dwMessageSize, DWORD dwTime);
+ INT_PTR MraChatSessionEventSendByHandle(HANDLE hContactChatSession, DWORD dwType, DWORD dwFlags, const CMStringA &szUID, LPCWSTR lpwszStatus, LPCWSTR lpwszMessage, DWORD_PTR dwItemData, DWORD dwTime);
+ INT_PTR MraChatSessionInvite(HANDLE hContactChatSession, const CMStringA &lpszEMailInMultiChat, DWORD dwTime);
+ INT_PTR MraChatSessionMembersAdd(HANDLE hContactChatSession, const CMStringA &lpszEMailInMultiChat, DWORD dwTime);
+ INT_PTR MraChatSessionJoinUser(HANDLE hContactChatSession, const CMStringA &lpszEMailInMultiChat, DWORD dwTime);
+ INT_PTR MraChatSessionLeftUser(HANDLE hContactChatSession, const CMStringA &lpszEMailInMultiChat, DWORD dwTime);
+ INT_PTR MraChatSessionSetIviter(HANDLE hContactChatSession, const CMStringA &lpszEMailInMultiChat);
+ INT_PTR MraChatSessionSetOwner(HANDLE hContactChatSession, const CMStringA &lpszEMailInMultiChat);
+ INT_PTR MraChatSessionMessageAdd(HANDLE hContactChatSession, const CMStringA &lpszEMailInMultiChat, const CMStringW &wszMessage, DWORD dwTime);
DWORD MraAvatarsQueueInitialize(HANDLE *phAvatarsQueueHandle);
void MraAvatarsQueueClear(HANDLE hAvatarsQueueHandle);
void MraAvatarsQueueDestroy(HANDLE hAvatarsQueueHandle);
DWORD MraAvatarsQueueAdd(HANDLE hAvatarsQueueHandle, DWORD dwFlags, HANDLE hContact, DWORD *pdwAvatarsQueueID);
- BOOL MraAvatarsGetContactTime (HANDLE hContact, LPSTR lpszValueName, SYSTEMTIME *pstTime);
+ bool MraAvatarsGetContactTime (HANDLE hContact, LPSTR lpszValueName, SYSTEMTIME *pstTime);
void MraAvatarsSetContactTime (HANDLE hContact, LPSTR lpszValueName, SYSTEMTIME *pstTime);
- DWORD MraAvatarsGetFileName(HANDLE hAvatarsQueueHandle, HANDLE hContact, DWORD dwFormat, LPTSTR lpszPath, size_t dwPathSize, size_t *pdwPathSizeRet);
+ DWORD MraAvatarsGetFileName(HANDLE hAvatarsQueueHandle, HANDLE hContact, DWORD dwFormat, CMStringW &res);
DWORD MraAvatarsQueueGetAvatar(HANDLE hAvatarsQueueHandle, DWORD dwFlags, HANDLE hContact, DWORD *pdwAvatarsQueueID, DWORD *pdwFormat, LPTSTR lpszPath);
DWORD MraAvatarsQueueGetAvatarSimple(HANDLE hAvatarsQueueHandle, DWORD dwFlags, HANDLE hContact, DWORD dwSourceID);
DWORD MraAvatarsDeleteContactAvatarFile(HANDLE hAvatarsQueueHandle, HANDLE hContact);
diff --git a/protocols/MRA/src/MraRTFMsg.cpp b/protocols/MRA/src/MraRTFMsg.cpp
index fd7fa41bd9..94c845fa6f 100644
--- a/protocols/MRA/src/MraRTFMsg.cpp
+++ b/protocols/MRA/src/MraRTFMsg.cpp
@@ -98,15 +98,14 @@ static const size_t dwcRTFTagsCount[SYMBOLS_COUNT] =
DWORD MraTextToRTFData(LPSTR lpszMessage, size_t dwMessageSize, LPSTR lpszMessageConverted, size_t dwMessageConvertedBuffSize, size_t *pdwMessageConvertedSize);
-BOOL MraIsMessageFlashAnimation(LPCWSTR lpwszMessage, size_t dwMessageSize)
+bool MraIsMessageFlashAnimation(const CMStringW &lpwszMessage)
{
- dwMessageSize *= sizeof(WCHAR);
- LPWSTR lpwszFound = (LPWSTR)MemoryFind(0, lpwszMessage, dwMessageSize, L"<SMILE>id = flas", 28);
- if (lpwszFound)
- if (MemoryFind(((lpwszFound-lpwszMessage)+32), lpwszMessage, dwMessageSize, L"'</SMILE>", 18))
- return TRUE;
+ int iStart = lpwszMessage.Find(L"<SMILE>id = flas");
+ if (iStart != -1)
+ if (lpwszMessage.Find(L"'</SMILE>", iStart) != -1)
+ return true;
- return FALSE;
+ return false;
}
DWORD MraTextToRTFData(LPSTR lpszMessage, size_t dwMessageSize, LPSTR lpszMessageConverted, size_t dwMessageConvertedBuffSize, size_t *pdwMessageConvertedSize)
@@ -191,28 +190,21 @@ DWORD MraSymbolsToRTFTags(DWORD dwFlags, LPSTR lpszMessage, size_t dwMessageSize
return(dwRetErrorCode);
}
-DWORD CMraProto::MraConvertToRTFW(LPCWSTR lpwszMessage, size_t dwMessageSize, LPSTR lpszMessageRTF, size_t dwMessageRTFBuffSize, size_t *pdwMessageRTFSize)
+DWORD CMraProto::MraConvertToRTFW(const CMStringW &wszMessage, CMStringA &szMessageRTF)
{
- if (!lpwszMessage || !lpszMessageRTF)
+ if (wszMessage.IsEmpty())
return ERROR_INVALID_HANDLE;
- if ((dwMessageSize+1024) > dwMessageRTFBuffSize) {
- if (pdwMessageRTFSize)
- *pdwMessageRTFSize = dwMessageSize;
- return ERROR_BUFFER_OVERFLOW;
- }
-
- ptrA lpszMessage((LPSTR)mir_calloc(dwMessageSize+32));
+ ptrA lpszMessage( mir_u2a(wszMessage));
if (!lpszMessage)
return GetLastError();
- LPSTR lpszMessageRTFCur = lpszMessageRTF;
+ LPCSTR lpszBase = szMessageRTF;
+ LPSTR lpszMessageRTFCur = (LPSTR)lpszBase;
size_t dwtm;
DWORD dwRTFFontColour, dwFontSize;
LOGFONT lf = {0};
- WideCharToMultiByte(MRA_CODE_PAGE, 0, lpwszMessage, dwMessageSize, lpszMessage, (dwMessageSize+32), NULL, NULL);
-
dwRTFFontColour = getDword("RTFFontColour", MRA_DEFAULT_RTF_FONT_COLOUR);
if ( !mraGetContactSettingBlob(NULL, "RTFFont", &lf, sizeof(LOGFONT), NULL)) {
HDC hDC = GetDC(NULL);// kegl
@@ -223,32 +215,30 @@ DWORD CMraProto::MraConvertToRTFW(LPCWSTR lpwszMessage, size_t dwMessageSize, LP
}
dwFontSize = ((-lf.lfHeight)+(((-lf.lfHeight)+4)/8));
- lpszMessageRTFCur += mir_snprintf(lpszMessageRTFCur, (dwMessageRTFBuffSize-((size_t)lpszMessageRTFCur-(size_t)lpszMessageRTF)), "{\\rtf1\\ansi\\ansicpg1251\\deff0\\deflang1049{\\fonttbl{\\f0\\fnil\\fcharset%lu %s;}}\r\n", lf.lfCharSet, lf.lfFaceName);
+ lpszMessageRTFCur += mir_snprintf(lpszMessageRTFCur, (szMessageRTF.GetLength()-(lpszMessageRTFCur-lpszBase)), "{\\rtf1\\ansi\\ansicpg1251\\deff0\\deflang1049{\\fonttbl{\\f0\\fnil\\fcharset%lu %s;}}\r\n", lf.lfCharSet, lf.lfFaceName);
- if (MemoryFind(0, lpszMessage, dwMessageSize, BB_COLOR_TAG, (sizeof(BB_COLOR_TAG)-1)))
- lpszMessageRTFCur += mir_snprintf(lpszMessageRTFCur, (dwMessageRTFBuffSize-((size_t)lpszMessageRTFCur-(size_t)lpszMessageRTF)), "{\\colortbl;\\red%lu\\green%lu\\blue%lu;%s}\r\n", (*((RGBTRIPLE*)&dwRTFFontColour)).rgbtBlue, (*((RGBTRIPLE*)&dwRTFFontColour)).rgbtGreen, (*((RGBTRIPLE*)&dwRTFFontColour)).rgbtRed, RTF_COLORTBLCOLOURS);
+ if (MemoryFind(0, lpszMessage, wszMessage.GetLength(), BB_COLOR_TAG, (sizeof(BB_COLOR_TAG)-1)))
+ lpszMessageRTFCur += mir_snprintf(lpszMessageRTFCur, (szMessageRTF.GetLength()-(lpszMessageRTFCur-lpszBase)), "{\\colortbl;\\red%lu\\green%lu\\blue%lu;%s}\r\n", (*((RGBTRIPLE*)&dwRTFFontColour)).rgbtBlue, (*((RGBTRIPLE*)&dwRTFFontColour)).rgbtGreen, (*((RGBTRIPLE*)&dwRTFFontColour)).rgbtRed, RTF_COLORTBLCOLOURS);
else
- lpszMessageRTFCur += mir_snprintf(lpszMessageRTFCur, (dwMessageRTFBuffSize-((size_t)lpszMessageRTFCur-(size_t)lpszMessageRTF)), "{\\colortbl;\\red%lu\\green%lu\\blue%lu;}\r\n", (*((RGBTRIPLE*)&dwRTFFontColour)).rgbtBlue, (*((RGBTRIPLE*)&dwRTFFontColour)).rgbtGreen, (*((RGBTRIPLE*)&dwRTFFontColour)).rgbtRed);
+ lpszMessageRTFCur += mir_snprintf(lpszMessageRTFCur, (szMessageRTF.GetLength()-(lpszMessageRTFCur-lpszBase)), "{\\colortbl;\\red%lu\\green%lu\\blue%lu;}\r\n", (*((RGBTRIPLE*)&dwRTFFontColour)).rgbtBlue, (*((RGBTRIPLE*)&dwRTFFontColour)).rgbtGreen, (*((RGBTRIPLE*)&dwRTFFontColour)).rgbtRed);
LPSTR lpszNotfink = "",
lpszBold = ((lf.lfWeight == FW_BOLD)? "\\b1":lpszNotfink),
lpszItalic = (lf.lfItalic? "\\i1":lpszNotfink),
lpszUnderline = (lf.lfUnderline? "\\ul1":lpszNotfink),
lpszStrikeOut = (lf.lfStrikeOut? "\\strike1":lpszNotfink);
- lpszMessageRTFCur += mir_snprintf(lpszMessageRTFCur, (dwMessageRTFBuffSize-((size_t)lpszMessageRTFCur-(size_t)lpszMessageRTF)), "\\viewkind4\\uc1\\pard\\cf1\\f0\\fs%lu%s%s%s%s", dwFontSize, lpszBold, lpszItalic, lpszUnderline, lpszStrikeOut);
+ lpszMessageRTFCur += mir_snprintf(lpszMessageRTFCur, (szMessageRTF.GetLength()-(lpszMessageRTFCur-lpszBase)), "\\viewkind4\\uc1\\pard\\cf1\\f0\\fs%lu%s%s%s%s", dwFontSize, lpszBold, lpszItalic, lpszUnderline, lpszStrikeOut);
- if ( !MraSymbolsToRTFTags(0, lpszMessage, dwMessageSize, lpszMessageRTFCur, (dwMessageRTFBuffSize-(lpszMessageRTFCur-lpszMessageRTF)), &dwtm)) {
+ if ( !MraSymbolsToRTFTags(0, lpszMessage, wszMessage.GetLength(), lpszMessageRTFCur, (szMessageRTF.GetLength()-(lpszMessageRTFCur-lpszBase)), &dwtm)) {
lpszMessageRTFCur += dwtm;
- if ((lpszMessageRTF+dwMessageRTFBuffSize) >= (lpszMessageRTFCur+sizeof(PAR)+sizeof(CRLF)+2)) {
+ if ((lpszBase + szMessageRTF.GetLength()) >= (lpszMessageRTFCur+sizeof(PAR)+sizeof(CRLF)+2)) {
memmove(lpszMessageRTFCur, PAR, sizeof(PAR));lpszMessageRTFCur += (sizeof(PAR)-1);
memmove(lpszMessageRTFCur, CRLF, sizeof(CRLF));lpszMessageRTFCur += (sizeof(CRLF)-1);
memmove(lpszMessageRTFCur, "}", 2);lpszMessageRTFCur += 2;
- if (pdwMessageRTFSize) (*pdwMessageRTFSize) = (lpszMessageRTFCur-lpszMessageRTF);
- DebugPrintCRLFA(lpszMessageRTF);
+ DebugPrintCRLFA(szMessageRTF);
return NO_ERROR;
}
- if (pdwMessageRTFSize) *pdwMessageRTFSize = dwMessageRTFBuffSize+1024;
return ERROR_BUFFER_OVERFLOW;
}
diff --git a/protocols/MRA/src/MraRTFMsg.h b/protocols/MRA/src/MraRTFMsg.h
index 1dadb5a801..85d88697bc 100644
--- a/protocols/MRA/src/MraRTFMsg.h
+++ b/protocols/MRA/src/MraRTFMsg.h
@@ -6,6 +6,6 @@
#pragma once
#endif // _MSC_VER > 1000
-BOOL MraIsMessageFlashAnimation (LPCWSTR lpwszMessage, size_t dwMessageSize);
+bool MraIsMessageFlashAnimation(const CMStringW &lpwszMessage);
#endif // !defined(AFX_MRA_RTFMSG_H__F58D13FF_F6F2_476C_B8F0_7B9E9357CF48__INCLUDED_)
diff --git a/protocols/MRA/src/MraSelectEMail.cpp b/protocols/MRA/src/MraSelectEMail.cpp
index 6cb9a80b0d..f05e009b70 100644
--- a/protocols/MRA/src/MraSelectEMail.cpp
+++ b/protocols/MRA/src/MraSelectEMail.cpp
@@ -10,22 +10,23 @@ struct MraSelectEMailDlgData
void AddContactEMailToListParam(HANDLE hContact, BOOL bMRAOnly, LPSTR lpszModule, LPSTR lpszValueName, HWND hWndList)
{
- CHAR szBuff[MAX_PATH], szEMail[MAX_EMAIL_LEN];
- WCHAR wszBuff[MAX_PATH];
- size_t i, dwEMailSize;
-
- if (DB_GetStaticStringA(hContact, lpszModule, lpszValueName, szEMail, SIZEOF(szEMail), &dwEMailSize)) {
- if (bMRAOnly == FALSE || IsEMailMR(szEMail, dwEMailSize)) {
- MultiByteToWideChar(MRA_CODE_PAGE, 0, szEMail, (dwEMailSize+1), wszBuff, SIZEOF(wszBuff));
- if (SendMessage(hWndList, LB_FINDSTRING, -1, (LPARAM)wszBuff) == LB_ERR) SendMessage(hWndList, LB_ADDSTRING, 0, (LPARAM)wszBuff);
+ CMStringA szEmail;
+ if (DB_GetStringA(hContact, lpszModule, lpszValueName, szEmail)) {
+ if (bMRAOnly == FALSE || IsEMailMR(szEmail)) {
+ WCHAR wszBuff[MAX_EMAIL_LEN];
+ MultiByteToWideChar(MRA_CODE_PAGE, 0, szEmail, -1, wszBuff, SIZEOF(wszBuff));
+ if (SendMessage(hWndList, LB_FINDSTRING, -1, (LPARAM)wszBuff) == LB_ERR)
+ SendMessage(hWndList, LB_ADDSTRING, 0, (LPARAM)wszBuff);
}
}
- for (i = 0;TRUE;i++) {
+ for (int i = 0; true; i++) {
+ char szBuff[MAX_PATH];
mir_snprintf(szBuff, SIZEOF(szBuff), "%s%lu", lpszValueName, i);
- if (DB_GetStaticStringA(hContact, lpszModule, szBuff, szEMail, SIZEOF(szEMail), &dwEMailSize)) {
- if (bMRAOnly == FALSE || IsEMailMR(szEMail, dwEMailSize)) {
- MultiByteToWideChar(MRA_CODE_PAGE, 0, szEMail, (dwEMailSize+1), wszBuff, SIZEOF(wszBuff));
+ if (DB_GetStringA(hContact, lpszModule, szBuff, szEmail)) {
+ if (bMRAOnly == FALSE || IsEMailMR(szEmail)) {
+ WCHAR wszBuff[MAX_EMAIL_LEN];
+ MultiByteToWideChar(MRA_CODE_PAGE, 0, szEmail, -1, wszBuff, SIZEOF(wszBuff));
if (SendMessage(hWndList, LB_FINDSTRING, -1, (LPARAM)wszBuff) == LB_ERR) SendMessage(hWndList, LB_ADDSTRING, 0, (LPARAM)wszBuff);
}
}
@@ -95,37 +96,35 @@ INT_PTR CALLBACK MraSelectEMailDlgProc(HWND hWndDlg, UINT message, WPARAM wParam
case IDOK:
{
- CHAR szEMail[MAX_EMAIL_LEN];
+ CMStringA szEmail;
WCHAR wszBuff[MAX_PATH];
- size_t dwEMailSize;
- dwEMailSize = SendMessage(GetDlgItem(hWndDlg, IDC_LIST_EMAILS), LB_GETTEXT, SendMessage(GetDlgItem(hWndDlg, IDC_LIST_EMAILS), LB_GETCURSEL, 0, 0), (LPARAM)wszBuff);
- WideCharToMultiByte(MRA_CODE_PAGE, 0, wszBuff, (dwEMailSize+1), szEMail, SIZEOF(szEMail), NULL, NULL);
- BuffToLowerCase(szEMail, szEMail, dwEMailSize);
+ SendMessage(GetDlgItem(hWndDlg, IDC_LIST_EMAILS), LB_GETTEXT, SendMessage(GetDlgItem(hWndDlg, IDC_LIST_EMAILS), LB_GETCURSEL, 0, 0), (LPARAM)wszBuff);
+ szEmail = wszBuff;
+ szEmail.MakeLower();
switch (dat->dwType) {
case MRA_SELECT_EMAIL_TYPE_SEND_POSTCARD:
{
- size_t dwUrlSize;
- CHAR szUrl[BUFF_SIZE_URL];
- dwUrlSize = mir_snprintf(szUrl, SIZEOF(szUrl), "http://cards.mail.ru/event.html?rcptname=%s&rcptemail=%s", GetContactNameA(dat->hContact), szEMail);
- dat->ppro->MraMPopSessionQueueAddUrl(dat->ppro->hMPopSessionQueue, szUrl, dwUrlSize);
+ CMStringA szUrl;
+ szUrl.Format("http://cards.mail.ru/event.html?rcptname=%s&rcptemail=%s", GetContactNameA(dat->hContact), szEmail);
+ dat->ppro->MraMPopSessionQueueAddUrl(dat->ppro->hMPopSessionQueue, szUrl);
}
break;
case MRA_SELECT_EMAIL_TYPE_VIEW_ALBUM:
- dat->ppro->MraMPopSessionQueueAddUrlAndEMail(dat->ppro->hMPopSessionQueue, MRA_FOTO_URL, sizeof(MRA_FOTO_URL), szEMail, dwEMailSize);
+ dat->ppro->MraMPopSessionQueueAddUrlAndEMail(dat->ppro->hMPopSessionQueue, MRA_FOTO_URL, szEmail);
break;
case MRA_SELECT_EMAIL_TYPE_READ_BLOG:
- dat->ppro->MraMPopSessionQueueAddUrlAndEMail(dat->ppro->hMPopSessionQueue, MRA_BLOGS_URL, sizeof(MRA_BLOGS_URL), szEMail, dwEMailSize);
+ dat->ppro->MraMPopSessionQueueAddUrlAndEMail(dat->ppro->hMPopSessionQueue, MRA_BLOGS_URL, szEmail);
break;
case MRA_SELECT_EMAIL_TYPE_VIEW_VIDEO:
- dat->ppro->MraMPopSessionQueueAddUrlAndEMail(dat->ppro->hMPopSessionQueue, MRA_VIDEO_URL, sizeof(MRA_VIDEO_URL), szEMail, dwEMailSize);
+ dat->ppro->MraMPopSessionQueueAddUrlAndEMail(dat->ppro->hMPopSessionQueue, MRA_VIDEO_URL, szEmail);
break;
case MRA_SELECT_EMAIL_TYPE_ANSWERS:
- dat->ppro->MraMPopSessionQueueAddUrlAndEMail(dat->ppro->hMPopSessionQueue, MRA_ANSWERS_URL, sizeof(MRA_ANSWERS_URL), szEMail, dwEMailSize);
+ dat->ppro->MraMPopSessionQueueAddUrlAndEMail(dat->ppro->hMPopSessionQueue, MRA_ANSWERS_URL, szEmail);
break;
case MRA_SELECT_EMAIL_TYPE_WORLD:
- dat->ppro->MraMPopSessionQueueAddUrlAndEMail(dat->ppro->hMPopSessionQueue, MRA_WORLD_URL, sizeof(MRA_WORLD_URL), szEMail, dwEMailSize);
+ dat->ppro->MraMPopSessionQueueAddUrlAndEMail(dat->ppro->hMPopSessionQueue, MRA_WORLD_URL, szEmail);
break;
}
}
diff --git a/protocols/MRA/src/MraSendCommand.cpp b/protocols/MRA/src/MraSendCommand.cpp
index fb4a9e711a..33796b5c36 100644
--- a/protocols/MRA/src/MraSendCommand.cpp
+++ b/protocols/MRA/src/MraSendCommand.cpp
@@ -3,143 +3,134 @@
#include "MraRTFMsg.h"
#include "proto.h"
-static void SetUL(LPBYTE *plpBuff, DWORD dwData)
+class OutBuffer
{
- (*(DWORD*)(*plpBuff)) = dwData;
- (*plpBuff) += sizeof(DWORD);
-}
+ PBYTE m_buf;
+ size_t m_max, m_actual;
-static void SetUIDL(LPBYTE *plpBuff, DWORDLONG dwData)
-{
- (*(DWORDLONG*)(*plpBuff)) = dwData;
- (*plpBuff) += sizeof(DWORDLONG);
-}
+public:
+ OutBuffer() : m_buf(0), m_max(0), m_actual(0) {}
-static void SetGUID(LPBYTE *plpBuff, MRA_GUID guidData)
-{
- (*(MRA_GUID*)(*plpBuff)) = guidData;
- (*plpBuff) += sizeof(MRA_GUID);
-}
+ void* Allocate(size_t len)
+ {
+ if (m_actual + len >= m_max) {
+ size_t increment = (len > 4096) ? len+4096 : 4096;
+ m_buf = (PBYTE)realloc(m_buf, m_max += increment);
+ }
-static void SetLPS(LPBYTE *plpBuff, LPCSTR lpszData, DWORD dwSize)
-{
- (*(DWORD*)(*plpBuff)) = dwSize;
- (*plpBuff) += sizeof(DWORD);
- memmove((*plpBuff), lpszData, dwSize);
- (*plpBuff) += dwSize;
-}
+ void *res = m_buf + m_actual; m_actual += len;
+ return res;
+ }
-static void SetLPSW(LPBYTE *plpBuff, LPCWSTR lpwszData, DWORD dwSize)
-{
- dwSize *= sizeof(WCHAR);
- (*(DWORD*)(*plpBuff)) = dwSize;
- (*plpBuff) += sizeof(DWORD);
- memmove((*plpBuff), lpwszData, dwSize);
- (*plpBuff) += dwSize;
-}
+ PBYTE Data() const { return m_buf; }
+ size_t Len() const { return m_actual; }
-static void SetLPSWtoA(LPBYTE *plpBuff, LPCWSTR lpwszData, DWORD dwSize)
-{
- dwSize = WideCharToMultiByte(MRA_CODE_PAGE, 0, lpwszData, dwSize, (LPSTR)((*plpBuff)+sizeof(DWORD)), (dwSize*sizeof(WCHAR)), NULL, NULL);
- (*(DWORD*)(*plpBuff)) = dwSize;
- (*plpBuff) += (sizeof(DWORD)+dwSize);
-}
+ void SetUL(DWORD dwData)
+ {
+ *(DWORD*)Allocate(sizeof(DWORD)) = dwData;
+ }
-static void SetLPSLowerCase(LPBYTE *plpBuff, LPCSTR lpszData, DWORD dwSize)
-{
- (*(DWORD*)(*plpBuff)) = dwSize;
- (*plpBuff) += sizeof(DWORD);
- BuffToLowerCase((*plpBuff), lpszData, dwSize);
- (*plpBuff) += dwSize;
-}
+ void SetUIDL(DWORDLONG dwData)
+ {
+ *(DWORDLONG*)Allocate(sizeof(dwData)) = dwData;
+ }
-static void SetLPSLowerCaseW(LPBYTE *plpBuff, LPCWSTR lpwszData, DWORD dwSize)
-{
- dwSize *= sizeof(WCHAR);
- (*(DWORD*)(*plpBuff)) = dwSize;
- (*plpBuff) += sizeof(DWORD);
- memmove((*plpBuff), lpwszData, dwSize);
- CharLowerBuff((LPWSTR)(*plpBuff), (dwSize/sizeof(WCHAR)));
- (*plpBuff) += dwSize;
-}
+ void SetGUID(MRA_GUID guidData)
+ {
+ *(MRA_GUID*)Allocate(sizeof(guidData)) = guidData;
+ }
+
+ void SetLPS(const CMStringA &str)
+ {
+ SetUL(str.GetLength());
+ memcpy( Allocate(str.GetLength()), str, str.GetLength());
+ }
+
+ void SetLPSW(const CMStringW &str)
+ {
+ DWORD dwBytes = str.GetLength() * sizeof(WCHAR);
+ SetUL(dwBytes);
+ memcpy( Allocate(dwBytes), str, dwBytes);
+ }
+
+ void SetLPSLowerCase(const CMStringA &str)
+ {
+ SetUL(str.GetLength());
+ BuffToLowerCase((LPSTR)Allocate(str.GetLength()), str, str.GetLength());
+ }
+
+ void SetLPSLowerCaseW(const CMStringW &str)
+ {
+ DWORD dwSize = str.GetLength() * sizeof(WCHAR);
+ SetUL(dwSize);
+ WCHAR *buf = (WCHAR*)Allocate(dwSize);
+ memcpy(buf, str, dwSize);
+ CharLowerBuff(buf, str.GetLength());
+ }
+};
/////////////////////////////////////////////////////////////////////////////////////////
-DWORD CMraProto::MraMessageW(BOOL bAddToQueue, HANDLE hContact, DWORD dwAckType, DWORD dwFlags, LPSTR lpszEMail, size_t dwEMailSize, LPCWSTR lpwszMessage, size_t dwMessageSize, LPBYTE lpbMultiChatData, size_t dwMultiChatDataSize)
+DWORD CMraProto::MraMessageW(BOOL bAddToQueue, HANDLE hContact, DWORD dwAckType, DWORD dwFlags, const CMStringA &szEmail, const CMStringW &lpwszMessage, LPBYTE lpbMultiChatData, size_t dwMultiChatDataSize)
{
- Netlib_Logf(hNetlibUser, "Sending message: flags %08x, to '%S', message '%S'\n", dwFlags, lpszEMail, lpwszMessage);
+ Netlib_Logf(m_hNetlibUser, "Sending message: flags %08x, to '%S', message '%S'\n", dwFlags, szEmail, lpwszMessage);
DWORD dwRet = 0;
- LPBYTE lpbData, lpbDataCurrent;
- LPSTR lpszMessageConverted = (LPSTR)lpwszMessage;
+ LPSTR lpszMessageConverted = (LPSTR)lpwszMessage.GetString();
LPSTR lpszMessageRTF = NULL;
- size_t dwMessageConvertedSize = (dwMessageSize*sizeof(WCHAR)), dwMessageRTFSize = 0;
+ size_t dwMessageConvertedSize = lpwszMessage.GetLength()*sizeof(WCHAR), dwMessageRTFSize = 0;
- if ( MraIsMessageFlashAnimation(lpwszMessage, dwMessageSize))
+ if ( MraIsMessageFlashAnimation(lpwszMessage))
dwFlags |= MESSAGE_FLAG_FLASH;
// pack auth message
if (dwFlags & MESSAGE_FLAG_AUTHORIZE) {
- LPBYTE lpbAuthMsgBuff = (LPBYTE)mir_calloc(((dwMessageSize*sizeof(WCHAR))+1024));
- if (lpbAuthMsgBuff) {
- lpbDataCurrent = lpbAuthMsgBuff;
- SetUL(&lpbDataCurrent, 2);
- SetLPSW(&lpbDataCurrent, NULL, 0);//***deb possible nick here
- SetLPSW(&lpbDataCurrent, lpwszMessage, dwMessageSize);
-
- lpszMessageConverted = mir_base64_encode(lpbAuthMsgBuff, (lpbDataCurrent-lpbAuthMsgBuff));
- dwMessageConvertedSize = strlen(lpszMessageConverted);
- }
- else lpszMessageConverted = (LPSTR)lpwszMessage;
-
- mir_free(lpbAuthMsgBuff);
+ OutBuffer buf;
+ buf.SetUL(2);
+ buf.SetLPSW(L"");//***deb possible nick here
+ buf.SetLPSW(lpwszMessage);
+ lpszMessageConverted = mir_base64_encode(buf.Data(), buf.Len());
+ dwMessageConvertedSize = strlen(lpszMessageConverted);
}
// messages with Flash
else if (dwFlags & MESSAGE_FLAG_FLASH) {
- size_t dwRFTBuffSize = (((dwMessageSize*sizeof(WCHAR))*4)+8192), dwRTFDataSize;
-
dwFlags |= MESSAGE_FLAG_RTF;
- ptrA lpbRTFData((char*)mir_calloc(dwRFTBuffSize));
- if (lpbRTFData) {
- DWORD dwBackColour = getDword("RTFBackgroundColour", MRA_DEFAULT_RTF_BACKGROUND_COLOUR);
- lpbDataCurrent = (LPBYTE)lpszMessageRTF;
-
- WideCharToMultiByte(MRA_CODE_PAGE, 0, lpwszMessage, dwMessageSize, (LPSTR)lpbRTFData, dwRFTBuffSize, NULL, NULL);
-
- SetUL(&lpbDataCurrent, 4);
- SetLPS(&lpbDataCurrent, (LPSTR)lpbRTFData, dwMessageSize);// сообщение что у собеседника плохая версия :)
- SetLPS(&lpbDataCurrent, (LPSTR)&dwBackColour, sizeof(DWORD));// цвет фона
- SetLPS(&lpbDataCurrent, (LPSTR)lpbRTFData, dwMessageSize);// сам мульт ANSI
- SetLPSW(&lpbDataCurrent, lpwszMessage, dwMessageSize);// сам мульт UNICODE
-
- dwRTFDataSize = dwRFTBuffSize;
- if ( compress2((LPBYTE)(LPSTR)lpbRTFData, (DWORD*)&dwRTFDataSize, (LPBYTE)lpszMessageRTF, (lpbDataCurrent-(LPBYTE)lpszMessageRTF), Z_BEST_COMPRESSION) == Z_OK) {
- lpszMessageRTF = mir_base64_encode((LPBYTE)(char*)lpbRTFData, dwRTFDataSize);
- dwMessageRTFSize = lstrlenA(lpszMessageRTF);
- }
+
+ DWORD dwBackColour = getDword("RTFBackgroundColour", MRA_DEFAULT_RTF_BACKGROUND_COLOUR);
+ char lpbRTFData[10000];
+
+ OutBuffer buf;
+ buf.SetUL(4);
+ buf.SetLPS(lpbRTFData);// сообщение что у собеседника плохая версия :)
+ buf.SetUL(4);
+ buf.SetUL(dwBackColour);
+ buf.SetLPS(lpbRTFData);// сам мульт ANSI
+ buf.SetLPSW(lpwszMessage);// сам мульт UNICODE
+
+ DWORD dwRTFDataSize = buf.Len();
+ if ( compress2((LPBYTE)lpbRTFData, &dwRTFDataSize, buf.Data(), buf.Len(), Z_BEST_COMPRESSION) == Z_OK) {
+ lpszMessageRTF = mir_base64_encode((LPBYTE)lpbRTFData, dwRTFDataSize);
+ dwMessageRTFSize = lstrlenA(lpszMessageRTF);
}
}
// standart message
else if ((dwFlags & (MESSAGE_FLAG_CONTACT | MESSAGE_FLAG_NOTIFY | MESSAGE_FLAG_SMS)) == 0) {
// Only if message is simple text message or RTF or ALARM
if (dwFlags & MESSAGE_FLAG_RTF) { // add RFT part
- size_t dwRFTBuffSize = (((dwMessageSize*sizeof(WCHAR))*16)+8192), dwRTFDataSize;
-
- ptrA lpbRTFData((char*)mir_calloc(dwRFTBuffSize));
- if (lpbRTFData) {
- if ( !MraConvertToRTFW(lpwszMessage, dwMessageSize, (LPSTR)lpbRTFData, dwRFTBuffSize, &dwRTFDataSize)) {
- DWORD dwBackColour = getDword("RTFBackgroundColour", MRA_DEFAULT_RTF_BACKGROUND_COLOUR);
- lpbDataCurrent = (LPBYTE)lpszMessageRTF;
-
- SetUL(&lpbDataCurrent, 2);
- SetLPS(&lpbDataCurrent, (LPSTR)lpbRTFData, dwRTFDataSize);
- SetLPS(&lpbDataCurrent, (LPSTR)&dwBackColour, sizeof(DWORD));
-
- dwRTFDataSize = dwRFTBuffSize;
- if ( compress2((LPBYTE)(LPSTR)lpbRTFData, (DWORD*)&dwRTFDataSize, (LPBYTE)lpszMessageRTF, (lpbDataCurrent-(LPBYTE)lpszMessageRTF), Z_BEST_COMPRESSION) == Z_OK) {
- lpszMessageRTF = mir_base64_encode((LPBYTE)(char*)lpbRTFData, dwRTFDataSize);
- dwMessageRTFSize = lstrlenA(lpszMessageRTF);
- }
+ CMStringA lpbRTFData; lpbRTFData.Truncate(lpwszMessage.GetLength()*16 + 4096);
+ if ( !MraConvertToRTFW(lpwszMessage, lpbRTFData)) {
+ DWORD dwBackColour = getDword("RTFBackgroundColour", MRA_DEFAULT_RTF_BACKGROUND_COLOUR);
+
+ OutBuffer buf;
+ buf.SetUL(2);
+ buf.SetLPS(lpbRTFData);
+ buf.SetUL(4);
+ buf.SetUL(dwBackColour);
+
+ DWORD dwRTFDataSize = lpbRTFData.GetLength();
+ if ( compress2((LPBYTE)(LPCSTR)lpbRTFData, &dwRTFDataSize, buf.Data(), buf.Len(), Z_BEST_COMPRESSION) == Z_OK) {
+ lpszMessageRTF = mir_base64_encode((LPBYTE)(LPCSTR)lpbRTFData, dwRTFDataSize);
+ dwMessageRTFSize = lstrlenA(lpszMessageRTF);
}
}
}
@@ -148,141 +139,94 @@ DWORD CMraProto::MraMessageW(BOOL bAddToQueue, HANDLE hContact, DWORD dwAckType,
if (lpszMessageRTF == NULL || dwMessageRTFSize == 0) dwFlags &= ~(MESSAGE_FLAG_RTF|MESSAGE_FLAG_FLASH);
if (lpbMultiChatData == NULL || dwMultiChatDataSize == 0) dwFlags &= ~MESSAGE_FLAG_MULTICHAT;
- lpbData = (LPBYTE)mir_calloc((sizeof(DWORD)+dwEMailSize+dwMessageConvertedSize+dwMessageRTFSize+dwMultiChatDataSize+128));
- if (lpbData) {
- lpbDataCurrent = lpbData;
- SetUL(&lpbDataCurrent, dwFlags);
- SetLPSLowerCase(&lpbDataCurrent, lpszEMail, dwEMailSize);
- SetLPS(&lpbDataCurrent, lpszMessageConverted, dwMessageConvertedSize);
- SetLPS(&lpbDataCurrent, lpszMessageRTF, dwMessageRTFSize);
- if (dwFlags&MESSAGE_FLAG_MULTICHAT) SetLPS(&lpbDataCurrent, (LPSTR)lpbMultiChatData, dwMultiChatDataSize);
-
- if (bAddToQueue)
- dwRet = MraSendQueueCMD(hSendQueueHandle, 0, hContact, dwAckType, (LPBYTE)lpwszMessage, (dwMessageSize*sizeof(WCHAR)), MRIM_CS_MESSAGE, lpbData, (lpbDataCurrent-lpbData));
- else
- dwRet = MraSendCMD(MRIM_CS_MESSAGE, lpbData, (lpbDataCurrent-lpbData));
- mir_free(lpbData);
- }
+ OutBuffer buf;
+ buf.SetUL(dwFlags);
+ buf.SetLPSLowerCase(szEmail);
+ buf.SetLPS(CMStringA(lpszMessageConverted, dwMessageConvertedSize));
+ buf.SetLPS(lpszMessageRTF);
+ if (dwFlags & MESSAGE_FLAG_MULTICHAT)
+ buf.SetLPS(CMStringA((LPSTR)lpbMultiChatData, dwMultiChatDataSize));
- if (lpszMessageConverted != (LPSTR)lpwszMessage)
- mir_free(lpszMessageConverted);
- mir_free(lpszMessageRTF);
+ if (bAddToQueue)
+ dwRet = MraSendQueueCMD(hSendQueueHandle, 0, hContact, dwAckType, (LPBYTE)(LPCWSTR)lpwszMessage, lpwszMessage.GetLength()*sizeof(WCHAR), MRIM_CS_MESSAGE, buf.Data(), buf.Len());
+ else
+ dwRet = MraSendCMD(MRIM_CS_MESSAGE, buf.Data(), buf.Len());
return dwRet;
}
// Send confirmation
-DWORD CMraProto::MraMessageAskW(DWORD dwMsgID, DWORD dwFlags, LPSTR lpszEMail, size_t dwEMailSize, LPWSTR lpwszMessage, size_t dwMessageSize, LPSTR lpwszMessageRTF, size_t dwMessageRTFSize)
+DWORD CMraProto::MraMessageAskW(DWORD dwMsgID, DWORD dwFlags, const CMStringA &szEmail, const CMStringW &lpwszMessage, const CMStringW &lpwszMessageRTF)
{
- DWORD dwRet = 0;
-
- if (lpszEMail && dwEMailSize>4 && lpwszMessage && dwMessageSize) {
- LPBYTE lpbData, lpbDataCurrent;
- lpbData = (LPBYTE)mir_calloc((sizeof(DWORD)+sizeof(DWORD)+dwEMailSize+dwMessageSize+dwMessageRTFSize+32));
- if (lpbData) {
- lpbDataCurrent = lpbData;
- SetUL(&lpbDataCurrent, dwMsgID);//UL msg_id
- SetUL(&lpbDataCurrent, dwFlags);//UL flags
- SetLPSLowerCase(&lpbDataCurrent, lpszEMail, dwEMailSize);// LPS from e-mail ANSI
- SetLPS(&lpbDataCurrent, (LPSTR)lpwszMessage, dwMessageSize);// LPS message UNICODE
- if (dwFlags&MESSAGE_FLAG_RTF)
- SetLPS(&lpbDataCurrent, (LPSTR)lpwszMessageRTF, dwMessageRTFSize);// LPS //rtf-formatted message ( >= 1.1) - MESSAGE_FLAG_RTF
-
- dwRet = MraSendCMD(MRIM_CS_MESSAGE_ACK, lpbData, (lpbDataCurrent-lpbData));
- mir_free(lpbData);
- }
- }
-
- return dwRet;
+ if (szEmail.GetLength() <= 4 || lpwszMessage.IsEmpty())
+ return 0;
+
+ OutBuffer buf;
+ buf.SetUL(dwMsgID);//UL msg_id
+ buf.SetUL(dwFlags);//UL flags
+ buf.SetLPSLowerCase(szEmail);// LPS from e-mail ANSI
+ buf.SetLPSW(lpwszMessage);// LPS message UNICODE
+ if (dwFlags & MESSAGE_FLAG_RTF)
+ buf.SetLPSW(lpwszMessageRTF);// LPS //rtf-formatted message ( >= 1.1) - MESSAGE_FLAG_RTF
+
+ return MraSendCMD(MRIM_CS_MESSAGE_ACK, buf.Data(), buf.Len());
}
-DWORD CMraProto::MraMessageRecv(LPSTR lpszFrom, size_t dwFromSize, DWORD dwMsgID)
+DWORD CMraProto::MraMessageRecv(const CMStringA &szFrom, DWORD dwMsgID)
{
- DWORD dwRet = 0;
+ if (szFrom.GetLength() <= 4)
+ return 0;
- if (lpszFrom && dwFromSize>4) {
- LPBYTE lpbData, lpbDataCurrent;
- lpbData = (LPBYTE)mir_calloc((dwFromSize+sizeof(DWORD)+32));
- if (lpbData) {
- lpbDataCurrent = lpbData;
- SetLPSLowerCase(&lpbDataCurrent, lpszFrom, dwFromSize);
- SetUL(&lpbDataCurrent, dwMsgID);
-
- dwRet = MraSendCMD(MRIM_CS_MESSAGE_RECV, lpbData, (lpbDataCurrent-lpbData));
- mir_free(lpbData);
- }
- }
- return dwRet;
+ OutBuffer buf;
+ buf.SetLPSLowerCase(szFrom);
+ buf.SetUL(dwMsgID);
+ return MraSendCMD(MRIM_CS_MESSAGE_RECV, buf.Data(), buf.Len());
}
// Adds new contact
-DWORD CMraProto::MraAddContactW(HANDLE hContact, DWORD dwContactFlag, DWORD dwGroupID, LPSTR lpszEMail, size_t dwEMailSize, LPWSTR lpwszCustomName, size_t dwCustomNameSize, LPSTR lpszPhones, size_t dwPhonesSize, LPWSTR lpwszAuthMessage, size_t dwAuthMessageSize, DWORD dwActions)
+DWORD CMraProto::MraAddContactW(HANDLE hContact, DWORD dwContactFlag, DWORD dwGroupID, const CMStringA &szEmail, const CMStringW &wszCustomName, const CMStringA &szPhones, const CMStringW &wszAuthMessage, DWORD dwActions)
{
- DWORD dwRet = 0;
+ if (szEmail.GetLength() <= 4)
+ return 0;
- if (lpszEMail && dwEMailSize>4) {
- LPBYTE lpbData = (LPBYTE)mir_calloc((sizeof(DWORD)+sizeof(DWORD)+dwEMailSize+(dwCustomNameSize*sizeof(WCHAR))+dwPhonesSize+(((((dwAuthMessageSize*sizeof(WCHAR))+1024)+2)/3)*4)+32)+sizeof(DWORD));
- if (lpbData) {
- dwContactFlag |= CONTACT_FLAG_UNICODE_NAME;
-
- LPBYTE lpbDataCurrent = lpbData;
- SetUL(&lpbDataCurrent, dwContactFlag);
- SetUL(&lpbDataCurrent, dwGroupID);
- SetLPSLowerCase(&lpbDataCurrent, lpszEMail, dwEMailSize);
- SetLPSW(&lpbDataCurrent, lpwszCustomName, dwCustomNameSize);
- SetLPS(&lpbDataCurrent, lpszPhones, dwPhonesSize);
-
- // pack auth message
- LPBYTE lpbAuthMsgBuff, lpbAuthDataCurrent;
- LPSTR lpszAuthMessageConverted;
- size_t dwAuthMessageConvertedBuffSize = (((((dwAuthMessageSize*sizeof(WCHAR))+1024)+2)/3)*4), dwAuthMessageConvertedSize = 0;
-
- lpbAuthMsgBuff = (LPBYTE)mir_calloc(((dwAuthMessageSize*sizeof(WCHAR))+1024));
- if (lpbAuthMsgBuff) {
- lpbAuthDataCurrent = lpbAuthMsgBuff;
- SetUL(&lpbAuthDataCurrent, 2);
- SetLPSW(&lpbAuthDataCurrent, NULL, 0);//***deb possible nick here
- SetLPSW(&lpbAuthDataCurrent, lpwszAuthMessage, dwAuthMessageSize);
-
- lpszAuthMessageConverted = mir_base64_encode(lpbAuthMsgBuff, (lpbAuthDataCurrent-lpbAuthMsgBuff));
- dwAuthMessageConvertedSize = lstrlenA(lpszAuthMessageConverted);
- }
- SetLPS(&lpbDataCurrent, (LPSTR)lpszAuthMessageConverted, dwAuthMessageConvertedSize);
- mir_free(lpbAuthMsgBuff);
- mir_free(lpszAuthMessageConverted);
+ dwContactFlag |= CONTACT_FLAG_UNICODE_NAME;
- SetUL(&lpbDataCurrent, dwActions);
+ OutBuffer buf;
+ buf.SetUL(dwContactFlag);
+ buf.SetUL(dwGroupID);
+ buf.SetLPSLowerCase(szEmail);
+ buf.SetLPSW(wszCustomName);
+ buf.SetLPS(szPhones);
- dwRet = MraSendQueueCMD(hSendQueueHandle, 0, hContact, ACKTYPE_ADDED, NULL, 0, MRIM_CS_ADD_CONTACT, lpbData, (lpbDataCurrent-lpbData));
- mir_free(lpbData);
- }
- }
- return dwRet;
+ // pack auth message
+ OutBuffer buf2;
+ buf2.SetUL(2);
+ buf2.SetLPSW(L"");//***deb possible nick here
+ buf2.SetLPSW(wszAuthMessage);
+ buf.SetLPS(CMStringA( ptrA( mir_base64_encode(buf2.Data(), buf2.Len()))));
+
+ buf.SetUL(dwActions);
+
+ return MraSendQueueCMD(hSendQueueHandle, 0, hContact, ACKTYPE_ADDED, NULL, 0, MRIM_CS_ADD_CONTACT, buf.Data(), buf.Len());
}
// change contact
-DWORD CMraProto::MraModifyContactW(HANDLE hContact, DWORD dwID, DWORD dwContactFlag, DWORD dwGroupID, LPSTR lpszEMail, size_t dwEMailSize, LPWSTR lpwszCustomName, size_t dwCustomNameSize, LPSTR lpszPhones, size_t dwPhonesSize)
+DWORD CMraProto::MraModifyContactW(HANDLE hContact, DWORD dwID, DWORD dwContactFlag, DWORD dwGroupID, const CMStringA &szEmail, const CMStringW &wszCustomName, const CMStringA &szPhones)
{
- DWORD dwRet = 0;
- if (dwID != -1) {
- LPBYTE lpbData = (LPBYTE)mir_calloc((sizeof(DWORD)+sizeof(DWORD)+sizeof(DWORD)+dwEMailSize+(dwCustomNameSize*sizeof(WCHAR))+dwPhonesSize+32));
- if (lpbData)
- {
- dwContactFlag |= CONTACT_FLAG_UNICODE_NAME;
-
- LPBYTE lpbDataCurrent = lpbData;
- SetUL(&lpbDataCurrent, dwID);
- SetUL(&lpbDataCurrent, dwContactFlag);
- SetUL(&lpbDataCurrent, dwGroupID);
- SetLPSLowerCase(&lpbDataCurrent, lpszEMail, dwEMailSize);
- SetLPSW(&lpbDataCurrent, lpwszCustomName, dwCustomNameSize);
- SetLPS(&lpbDataCurrent, lpszPhones, dwPhonesSize);
-
- dwRet = MraSendQueueCMD(hSendQueueHandle, 0, hContact, ACKTYPE_ADDED, NULL, 0, MRIM_CS_MODIFY_CONTACT, lpbData, (lpbDataCurrent-lpbData));
- mir_free(lpbData);
- }
- }
- return dwRet;
+ if (dwID == -1)
+ return 0;
+
+ dwContactFlag |= CONTACT_FLAG_UNICODE_NAME;
+
+ OutBuffer buf;
+ buf.SetUL(dwID);
+ buf.SetUL(dwContactFlag);
+ buf.SetUL(dwGroupID);
+ buf.SetLPSLowerCase(szEmail);
+ buf.SetLPSW(wszCustomName);
+ buf.SetLPS(szPhones);
+
+ return MraSendQueueCMD(hSendQueueHandle, 0, hContact, ACKTYPE_ADDED, NULL, 0, MRIM_CS_MODIFY_CONTACT, buf.Data(), buf.Len());
}
// remove stored message
@@ -292,375 +236,267 @@ DWORD CMraProto::MraOfflineMessageDel(DWORDLONG dwMsgUIDL)
}
// autorize a user & add him to a roster
-DWORD CMraProto::MraAuthorize(LPSTR lpszEMail, size_t dwEMailSize)
+DWORD CMraProto::MraAuthorize(const CMStringA& szEmail)
{
- DWORD dwRet = 0;
+ if ( szEmail.GetLength() <= 4)
+ return 0;
- if (lpszEMail && dwEMailSize>4) {
- LPBYTE lpbData;
- lpbData = (LPBYTE)mir_calloc((dwEMailSize+32));
- if (lpbData) {
- LPBYTE lpbDataCurrent = lpbData;
- SetLPSLowerCase(&lpbDataCurrent, lpszEMail, dwEMailSize);
- dwRet = MraSendCMD(MRIM_CS_AUTHORIZE, lpbData, (lpbDataCurrent-lpbData));
- mir_free(lpbData);
- }
- }
- return dwRet;
+ OutBuffer buf;
+ buf.SetLPSLowerCase(szEmail);
+ return MraSendCMD(MRIM_CS_AUTHORIZE, buf.Data(), buf.Len());
}
// change status
-DWORD CMraProto::MraChangeStatusW(DWORD dwStatus, LPSTR lpszStatusUri, size_t dwStatusUriSize, LPCWSTR lpwszStatusTitle, size_t dwStatusTitleSize, LPCWSTR lpwszStatusDesc, size_t dwStatusDescSize, DWORD dwFutureFlags)
+DWORD CMraProto::MraChangeStatusW(DWORD dwStatus, const CMStringA &szStatusUri, const CMStringW &wszStatusTitle, const CMStringW &wszStatusDesc, DWORD dwFutureFlags)
{
- DWORD dwRet = 0;
-
- if (dwStatusUriSize > SPEC_STATUS_URI_MAX) dwStatusUriSize = SPEC_STATUS_URI_MAX;
- if (dwStatusTitleSize > STATUS_TITLE_MAX) dwStatusTitleSize = STATUS_TITLE_MAX;
- if (dwStatusDescSize > STATUS_DESC_MAX) dwStatusDescSize = STATUS_DESC_MAX;
-
- LPBYTE lpbData = (LPBYTE)mir_calloc((sizeof(DWORD)+dwStatusUriSize+(dwStatusTitleSize*sizeof(WCHAR))+(dwStatusDescSize*sizeof(WCHAR))+sizeof(DWORD)+32));
- if (lpbData) {
- LPBYTE lpbDataCurrent = lpbData;
- SetUL(&lpbDataCurrent, dwStatus);
- SetLPS(&lpbDataCurrent, lpszStatusUri, dwStatusUriSize);
- SetLPSW(&lpbDataCurrent, lpwszStatusTitle, dwStatusTitleSize);
- SetLPSW(&lpbDataCurrent, lpwszStatusDesc, dwStatusDescSize);
- SetUL(&lpbDataCurrent, dwFutureFlags);
-
- dwRet = MraSendCMD(MRIM_CS_CHANGE_STATUS, lpbData, (lpbDataCurrent-lpbData));
- mir_free(lpbData);
- }
- return dwRet;
+ OutBuffer buf;
+ buf.SetUL(dwStatus);
+ buf.SetLPS(szStatusUri);
+ buf.SetLPSW(wszStatusTitle);
+ buf.SetLPSW(wszStatusDesc);
+ buf.SetUL(dwFutureFlags);
+ return MraSendCMD(MRIM_CS_CHANGE_STATUS, buf.Data(), buf.Len());
}
// Отправка файлов
-DWORD CMraProto::MraFileTransfer(LPSTR lpszEMail, size_t dwEMailSize, DWORD dwIDRequest, DWORD dwFilesTotalSize, LPWSTR lpwszFiles, size_t dwFilesSize, LPSTR lpszAddreses, size_t dwAddressesSize)
+DWORD CMraProto::MraFileTransfer(const CMStringA &szEmail, DWORD dwIDRequest, DWORD dwFilesTotalSize, const CMStringW &wszFiles, const CMStringA &szAddresses)
{
- DWORD dwRet = 0;
+ if (szEmail.GetLength() <= 4)
+ return 0;
- if (lpszEMail && dwEMailSize>4) {
- int dwFilesSizeA = WideCharToMultiByte(MRA_CODE_PAGE, 0, lpwszFiles, dwFilesSize, NULL, 0, NULL, NULL);
- LPBYTE lpbData = (LPBYTE)mir_calloc((dwEMailSize+dwFilesSizeA+(dwFilesSize*sizeof(WCHAR))+dwAddressesSize+MAX_PATH));
- if (lpbData) {
- LPBYTE lpbDataCurrent = lpbData;
- SetLPSLowerCase(&lpbDataCurrent, lpszEMail, dwEMailSize);
- SetUL(&lpbDataCurrent, dwIDRequest);
- SetUL(&lpbDataCurrent, dwFilesTotalSize);
- SetUL(&lpbDataCurrent, sizeof(DWORD)*5 + dwFilesSizeA + dwFilesSize*sizeof(WCHAR) + DWORD(dwAddressesSize));
+ CMStringA szFiles = wszFiles;
- SetLPSWtoA(&lpbDataCurrent, lpwszFiles, dwFilesSize);
- SetUL(&lpbDataCurrent, sizeof(DWORD)*2 + dwFilesSize*sizeof(WCHAR));
+ OutBuffer buf;
+ buf.SetLPSLowerCase(szEmail);
+ buf.SetUL(dwIDRequest);
+ buf.SetUL(dwFilesTotalSize);
+ buf.SetUL(sizeof(DWORD)*5 + szFiles.GetLength() + wszFiles.GetLength()*sizeof(WCHAR) + szAddresses.GetLength());
- SetUL(&lpbDataCurrent, 1);
- SetLPSW(&lpbDataCurrent, lpwszFiles, dwFilesSize);
+ buf.SetLPS(szFiles);
+ buf.SetUL(sizeof(DWORD)*2 + wszFiles.GetLength()*sizeof(WCHAR));
- SetLPS(&lpbDataCurrent, lpszAddreses, dwAddressesSize);
+ buf.SetUL(1);
+ buf.SetLPSW(wszFiles);
- dwRet = MraSendCMD(MRIM_CS_FILE_TRANSFER, lpbData, lpbDataCurrent-lpbData);
- mir_free(lpbData);
- }
- }
- return dwRet;
+ buf.SetLPS(szAddresses);
+ return MraSendCMD(MRIM_CS_FILE_TRANSFER, buf.Data(), buf.Len());
}
// Ответ на отправку файлов
-DWORD CMraProto::MraFileTransferAck(DWORD dwStatus, LPSTR lpszEMail, size_t dwEMailSize, DWORD dwIDRequest, LPBYTE lpbDescription, size_t dwDescriptionSize)
+DWORD CMraProto::MraFileTransferAck(DWORD dwStatus, const CMStringA &szEmail, DWORD dwIDRequest, LPBYTE lpbDescription, size_t dwDescriptionSize)
{
- DWORD dwRet = 0;
-
- if (lpszEMail && dwEMailSize>4) {
- LPBYTE lpbData = (LPBYTE)mir_calloc((dwEMailSize+dwDescriptionSize+32));
- if (lpbData) {
- LPBYTE lpbDataCurrent = lpbData;
- SetUL(&lpbDataCurrent, dwStatus);
- SetLPSLowerCase(&lpbDataCurrent, lpszEMail, dwEMailSize);
- SetUL(&lpbDataCurrent, dwIDRequest);
- SetLPS(&lpbDataCurrent, (LPSTR)lpbDescription, dwDescriptionSize);
-
- dwRet = MraSendCMD(MRIM_CS_FILE_TRANSFER_ACK, lpbData, (lpbDataCurrent-lpbData));
- mir_free(lpbData);
- }
- }
- return dwRet;
+ if (szEmail.GetLength() <= 4)
+ return 0;
+
+ OutBuffer buf;
+ buf.SetUL(dwStatus);
+ buf.SetLPSLowerCase(szEmail);
+ buf.SetUL(dwIDRequest);
+ buf.SetLPS(lpbDescription);
+ return MraSendCMD(MRIM_CS_FILE_TRANSFER_ACK, buf.Data(), buf.Len());
}
// Поиск контакта
-HANDLE CMraProto::MraWPRequestW(HANDLE hContact, DWORD dwAckType, DWORD dwRequestFlags, LPSTR lpszUser, size_t dwUserSize, LPSTR lpszDomain, size_t dwDomainSize, LPCWSTR lpwszNickName, size_t dwNickNameSize, LPCWSTR lpwszFirstName, size_t dwFirstNameSize, LPCWSTR lpwszLastName, size_t dwLastNameSize, DWORD dwSex, DWORD dwDate1, DWORD dwDate2, DWORD dwCityID, DWORD dwZodiak, DWORD dwBirthdayMonth, DWORD dwBirthdayDay, DWORD dwCountryID, DWORD dwOnline)
+HANDLE CMraProto::MraWPRequestW(HANDLE hContact, DWORD dwAckType, DWORD dwRequestFlags, const CMStringA &szUser, const CMStringA &szDomain, const CMStringW &wszNickName, const CMStringW &wszFirstName, const CMStringW &wszLastName, DWORD dwSex, DWORD dwDate1, DWORD dwDate2, DWORD dwCityID, DWORD dwZodiak, DWORD dwBirthdayMonth, DWORD dwBirthdayDay, DWORD dwCountryID, DWORD dwOnline)
{
- DWORD dwRet = 0;
- LPBYTE lpbData = (LPBYTE)mir_calloc(((dwUserSize+dwDomainSize+dwNickNameSize+dwFirstNameSize+dwLastNameSize)*sizeof(WCHAR))+4096);
- if (lpbData) {
- CHAR szBuff[MAX_PATH];
- size_t dwBuffSize;
-
- LPBYTE lpbDataCurrent = lpbData;
-
- if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_USER)) { SetUL(&lpbDataCurrent, MRIM_CS_WP_REQUEST_PARAM_USER);SetLPSLowerCase(&lpbDataCurrent, lpszUser, dwUserSize); }
- if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_DOMAIN)) { SetUL(&lpbDataCurrent, MRIM_CS_WP_REQUEST_PARAM_DOMAIN);SetLPSLowerCase(&lpbDataCurrent, lpszDomain, dwDomainSize); }
- if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_NICKNAME)) { SetUL(&lpbDataCurrent, MRIM_CS_WP_REQUEST_PARAM_NICKNAME);SetLPSW(&lpbDataCurrent, lpwszNickName, dwNickNameSize); }
- if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_FIRSTNAME)) { SetUL(&lpbDataCurrent, MRIM_CS_WP_REQUEST_PARAM_FIRSTNAME);SetLPSW(&lpbDataCurrent, lpwszFirstName, dwFirstNameSize); }
- if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_LASTNAME)) { SetUL(&lpbDataCurrent, MRIM_CS_WP_REQUEST_PARAM_LASTNAME);SetLPSW(&lpbDataCurrent, lpwszLastName, dwLastNameSize); }
-
- if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_SEX)) {
- dwBuffSize = mir_snprintf(szBuff, SIZEOF(szBuff), "%lu", dwSex);
- SetUL(&lpbDataCurrent, MRIM_CS_WP_REQUEST_PARAM_SEX);
- SetLPS(&lpbDataCurrent, szBuff, dwBuffSize);
- }
-
- if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_DATE1)) {
- dwBuffSize = mir_snprintf(szBuff, SIZEOF(szBuff), "%lu", dwDate1);
- SetUL(&lpbDataCurrent, MRIM_CS_WP_REQUEST_PARAM_DATE1);
- SetLPS(&lpbDataCurrent, szBuff, dwBuffSize);
- }
+ OutBuffer buf;
+ CMStringA tmp;
+
+ if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_USER)) { buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_USER);buf.SetLPSLowerCase(szUser); }
+ if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_DOMAIN)) { buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_DOMAIN);buf.SetLPSLowerCase(szDomain); }
+ if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_NICKNAME)) { buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_NICKNAME);buf.SetLPSW(wszNickName); }
+ if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_FIRSTNAME)) { buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_FIRSTNAME);buf.SetLPSW(wszFirstName); }
+ if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_LASTNAME)) { buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_LASTNAME);buf.SetLPSW(wszLastName); }
+
+ if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_SEX)) {
+ tmp.Format("%lu", dwSex);
+ buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_SEX);
+ buf.SetLPS(tmp);
+ }
- if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_DATE2)) {
- dwBuffSize = mir_snprintf(szBuff, SIZEOF(szBuff), "%lu", dwDate2);
- SetUL(&lpbDataCurrent, MRIM_CS_WP_REQUEST_PARAM_DATE2);
- SetLPS(&lpbDataCurrent, szBuff, dwBuffSize);
- }
+ if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_DATE1)) {
+ tmp.Format("%lu", dwDate1);
+ buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_DATE1);
+ buf.SetLPS(tmp);
+ }
- if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_CITY_ID)) {
- dwBuffSize = mir_snprintf(szBuff, SIZEOF(szBuff), "%lu", dwCityID);
- SetUL(&lpbDataCurrent, MRIM_CS_WP_REQUEST_PARAM_CITY_ID);
- SetLPS(&lpbDataCurrent, szBuff, dwBuffSize);
- }
+ if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_DATE2)) {
+ tmp.Format("%lu", dwDate2);
+ buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_DATE2);
+ buf.SetLPS(tmp);
+ }
- if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_ZODIAC)) {
- dwBuffSize = mir_snprintf(szBuff, SIZEOF(szBuff), "%lu", dwZodiak);
- SetUL(&lpbDataCurrent, MRIM_CS_WP_REQUEST_PARAM_ZODIAC);
- SetLPS(&lpbDataCurrent, szBuff, dwBuffSize);
- }
+ if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_CITY_ID)) {
+ tmp.Format("%lu", dwCityID);
+ buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_CITY_ID);
+ buf.SetLPS(tmp);
+ }
- if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_BIRTHDAY_MONTH)) {
- dwBuffSize = mir_snprintf(szBuff, SIZEOF(szBuff), "%lu", dwBirthdayMonth);
- SetUL(&lpbDataCurrent, MRIM_CS_WP_REQUEST_PARAM_BIRTHDAY_MONTH);
- SetLPS(&lpbDataCurrent, szBuff, dwBuffSize);
- }
+ if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_ZODIAC)) {
+ tmp.Format("%lu", dwZodiak);
+ buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_ZODIAC);
+ buf.SetLPS(tmp);
+ }
- if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_BIRTHDAY_DAY)) {
- dwBuffSize = mir_snprintf(szBuff, SIZEOF(szBuff), "%lu", dwBirthdayDay);
- SetUL(&lpbDataCurrent, MRIM_CS_WP_REQUEST_PARAM_BIRTHDAY_DAY);
- SetLPS(&lpbDataCurrent, szBuff, dwBuffSize);
- }
+ if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_BIRTHDAY_MONTH)) {
+ tmp.Format("%lu", dwBirthdayMonth);
+ buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_BIRTHDAY_MONTH);
+ buf.SetLPS(tmp);
+ }
- if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_COUNTRY_ID)) {
- dwBuffSize = mir_snprintf(szBuff, SIZEOF(szBuff), "%lu", dwCountryID);
- SetUL(&lpbDataCurrent, MRIM_CS_WP_REQUEST_PARAM_COUNTRY_ID);
- SetLPS(&lpbDataCurrent, szBuff, dwBuffSize);
- }
+ if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_BIRTHDAY_DAY)) {
+ tmp.Format("%lu", dwBirthdayDay);
+ buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_BIRTHDAY_DAY);
+ buf.SetLPS(tmp);
+ }
- if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_ONLINE)) {
- dwBuffSize = mir_snprintf(szBuff, SIZEOF(szBuff), "%lu", dwOnline);
- SetUL(&lpbDataCurrent, MRIM_CS_WP_REQUEST_PARAM_ONLINE);
- SetLPS(&lpbDataCurrent, szBuff, dwBuffSize);
- }
+ if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_COUNTRY_ID)) {
+ tmp.Format("%lu", dwCountryID);
+ buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_COUNTRY_ID);
+ buf.SetLPS(tmp);
+ }
- dwRet = MraSendQueueCMD(hSendQueueHandle, 0, hContact, dwAckType, NULL, 0, MRIM_CS_WP_REQUEST, lpbData, (lpbDataCurrent-lpbData));
- mir_free(lpbData);
+ if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_ONLINE)) {
+ tmp.Format("%lu", dwOnline);
+ buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_ONLINE);
+ buf.SetLPS(tmp);
}
- return (HANDLE)dwRet;
+
+ return (HANDLE)MraSendQueueCMD(hSendQueueHandle, 0, hContact, dwAckType, NULL, 0, MRIM_CS_WP_REQUEST, buf.Data(), buf.Len());
}
// Поиск контакта по EMail
-HANDLE CMraProto::MraWPRequestByEMail(HANDLE hContact, DWORD dwAckType, LPCSTR lpszEMail, size_t dwEMailSize)
+HANDLE CMraProto::MraWPRequestByEMail(HANDLE hContact, DWORD dwAckType, CMStringA &szEmail)
{
- HANDLE dwRet = 0;
-
- if (lpszEMail && dwEMailSize>4) {
- size_t dwUserSize, dwDomainSize;
- LPSTR lpszDomain = (LPSTR)MemoryFindByte(0, lpszEMail, dwEMailSize, '@');
- if (lpszDomain) {
- LPSTR lpszUser = (LPSTR)lpszEMail;
- dwUserSize = (lpszDomain-lpszEMail);
- lpszDomain++;
- dwDomainSize = (dwEMailSize-(dwUserSize+1));
-
- DWORD dwRequestFlags = 0;
- SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_USER);
- SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_DOMAIN);
-
- dwRet = MraWPRequestW(hContact, dwAckType, dwRequestFlags, lpszUser, dwUserSize, lpszDomain, dwDomainSize, NULL, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
- }
- }
- return dwRet;
+ if (szEmail.GetLength() <= 4)
+ return 0;
+
+ int iStart = 0;
+ CMStringA szDomain = szEmail.Tokenize("@", iStart);
+ CMStringA szUser = szEmail.Tokenize("@", iStart);
+
+ DWORD dwRequestFlags = 0;
+ SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_USER);
+ SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_DOMAIN);
+ return MraWPRequestW(hContact, dwAckType, dwRequestFlags, szUser, szDomain, L"", L"", L"", 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
// Отправка файлов
-DWORD CMraProto::MraGame(LPSTR lpszEMail, size_t dwEMailSize, DWORD dwGameSessionID, DWORD dwGameMsg, DWORD dwGameMsgID, LPSTR lpszData, size_t dwDataSize)
+DWORD CMraProto::MraGame(const CMStringA &szEmail, DWORD dwGameSessionID, DWORD dwGameMsg, DWORD dwGameMsgID, const CMStringA &szData)
{
- DWORD dwRet = 0;
-
- if (lpszEMail && dwEMailSize>4) {
- LPBYTE lpbData = (LPBYTE)mir_calloc((dwEMailSize+(sizeof(DWORD)*4)+dwDataSize+32));
- if (lpbData) {
- LPBYTE lpbDataCurrent = lpbData;
- SetLPSLowerCase(&lpbDataCurrent, lpszEMail, dwEMailSize);
- SetUL(&lpbDataCurrent, dwGameSessionID);
- SetUL(&lpbDataCurrent, dwGameMsg);
- SetUL(&lpbDataCurrent, dwGameMsgID);
- SetUL(&lpbDataCurrent, _time32(NULL));
- SetLPS(&lpbDataCurrent, lpszData, dwDataSize);
-
- dwRet = MraSendCMD(MRIM_CS_GAME, lpbData, (lpbDataCurrent-lpbData));
- mir_free(lpbData);
- }
- }
- return dwRet;
+ if (szEmail.GetLength() <= 4)
+ return 0;
+
+ OutBuffer buf;
+ buf.SetLPSLowerCase(szEmail);
+ buf.SetUL(dwGameSessionID);
+ buf.SetUL(dwGameMsg);
+ buf.SetUL(dwGameMsgID);
+ buf.SetUL(_time32(NULL));
+ buf.SetLPS(szData);
+ return MraSendCMD(MRIM_CS_GAME, buf.Data(), buf.Len());
}
// Авторизация
-DWORD CMraProto::MraLogin2W(LPSTR lpszLogin, size_t dwLoginSize, LPSTR lpszPassword, size_t dwPasswordSize, DWORD dwStatus, LPSTR lpszStatusUri, size_t dwStatusUriSize, LPWSTR lpwszStatusTitle, size_t dwStatusTitleSize, LPWSTR lpwszStatusDesc, size_t dwStatusDescSize, DWORD dwFutureFlags, LPSTR dwUserAgentFormatted, size_t dwUserAgentFormattedSize, LPSTR lpszUserAgent, size_t dwUserAgentSize)
+DWORD CMraProto::MraLogin2W(CMStringA &szLogin, CMStringA &szPassword, DWORD dwStatus, CMStringA &szStatusUri, CMStringW &wszStatusTitle, CMStringW &wszStatusDesc, DWORD dwFutureFlags, CMStringA &szUserAgentFormatted, CMStringA &szUserAgent)
{
- DWORD dwRet = 0;
-
- if (dwStatusUriSize>SPEC_STATUS_URI_MAX) dwStatusUriSize = SPEC_STATUS_URI_MAX;
- if (dwStatusTitleSize>STATUS_TITLE_MAX) dwStatusTitleSize = STATUS_TITLE_MAX;
- if (dwStatusDescSize>STATUS_DESC_MAX) dwStatusDescSize = STATUS_DESC_MAX;
- if (dwUserAgentFormattedSize>USER_AGENT_MAX) dwUserAgentFormattedSize = USER_AGENT_MAX;
- if (dwUserAgentSize>MAX_CLIENT_DESCRIPTION) dwUserAgentSize = MAX_CLIENT_DESCRIPTION;
-
- LPBYTE lpbData = (LPBYTE)mir_calloc((dwLoginSize+dwPasswordSize+sizeof(DWORD)+dwStatusUriSize+(dwStatusTitleSize*sizeof(WCHAR))+(dwStatusDescSize*sizeof(WCHAR))+2+sizeof(DWORD)+(sizeof(DWORD)*2)+dwUserAgentFormattedSize+dwUserAgentSize+32));
- if (lpbData) {
- LPBYTE lpbDataCurrent = lpbData;
- SetLPS(&lpbDataCurrent, lpszLogin, dwLoginSize);
- SetLPS(&lpbDataCurrent, lpszPassword, dwPasswordSize);
- SetUL(&lpbDataCurrent, dwStatus);
- SetLPS(&lpbDataCurrent, lpszStatusUri, dwStatusUriSize);
- SetLPSW(&lpbDataCurrent, lpwszStatusTitle, dwStatusTitleSize);
- SetLPSW(&lpbDataCurrent, lpwszStatusDesc, dwStatusDescSize);
- SetUL(&lpbDataCurrent, dwFutureFlags);
- SetLPS(&lpbDataCurrent, dwUserAgentFormatted, dwUserAgentFormattedSize);
- SetLPS(&lpbDataCurrent, "ru", 2);
- SetLPS(&lpbDataCurrent, NULL, 0);
- SetLPS(&lpbDataCurrent, NULL, 0);
- SetLPS(&lpbDataCurrent, lpszUserAgent, dwUserAgentSize);// LPS client description /max 256
-
- dwRet = MraSendCMD(MRIM_CS_LOGIN2, lpbData, (lpbDataCurrent-lpbData));
- mir_free(lpbData);
- }
- return dwRet;
+ if (szStatusUri.GetLength() > SPEC_STATUS_URI_MAX) szStatusUri.Truncate(SPEC_STATUS_URI_MAX);
+ if (wszStatusTitle.GetLength() > STATUS_TITLE_MAX) wszStatusTitle.Truncate(STATUS_TITLE_MAX);
+ if (wszStatusDesc.GetLength() > STATUS_DESC_MAX) wszStatusDesc.Truncate(STATUS_DESC_MAX);
+ if (szUserAgentFormatted.GetLength() > USER_AGENT_MAX) szUserAgentFormatted.Truncate(USER_AGENT_MAX);
+ if (szUserAgent.GetLength() > MAX_CLIENT_DESCRIPTION) szUserAgent.Truncate(MAX_CLIENT_DESCRIPTION);
+
+ OutBuffer buf;
+ buf.SetLPS(szLogin);
+ buf.SetLPS(szPassword);
+ buf.SetUL(dwStatus);
+ buf.SetLPS(szStatusUri);
+ buf.SetLPSW(wszStatusTitle);
+ buf.SetLPSW(wszStatusDesc);
+ buf.SetUL(dwFutureFlags);
+ buf.SetLPS(szUserAgentFormatted);
+ buf.SetLPS("ru");
+ buf.SetLPS("");
+ buf.SetLPS("");
+ buf.SetLPS(szUserAgent);// LPS client description /max 256
+
+ return MraSendCMD(MRIM_CS_LOGIN2, buf.Data(), buf.Len());
}
// Отправка SMS
-DWORD CMraProto::MraSMSW(HANDLE hContact, LPSTR lpszPhone, size_t dwPhoneSize, LPWSTR lpwszMessage, size_t dwMessageSize)
+DWORD CMraProto::MraSMSW(HANDLE hContact, const CMStringA &lpszPhone, const CMStringW &lpwszMessage)
{
- DWORD dwRet = 0;
- LPBYTE lpbData = (LPBYTE)mir_calloc((dwPhoneSize+(dwMessageSize*sizeof(WCHAR))+32));
- LPBYTE lpbDataQueue = (LPBYTE)mir_calloc((dwPhoneSize+(dwMessageSize*sizeof(WCHAR))+32));
- LPSTR lpszPhoneLocal = (LPSTR)mir_calloc((dwPhoneSize+32));
- if (lpbData && lpbDataQueue && lpszPhoneLocal) {
- lpszPhoneLocal[0] = '+';
- dwPhoneSize = 1+CopyNumber((lpszPhoneLocal+1), lpszPhone, dwPhoneSize);
-
- LPBYTE lpbDataCurrent = lpbData;
- SetUL(&lpbDataCurrent, 0);
- SetLPS(&lpbDataCurrent, lpszPhoneLocal, dwPhoneSize);
- SetLPSW(&lpbDataCurrent, lpwszMessage, dwMessageSize);
-
- (*(DWORD*)lpbDataQueue) = dwPhoneSize;
- memmove((lpbDataQueue+sizeof(DWORD)), lpszPhoneLocal, (dwPhoneSize+1));
- memmove((lpbDataQueue+sizeof(DWORD)+dwPhoneSize+1), lpwszMessage, ((dwMessageSize*sizeof(WCHAR))+1));
-
- dwRet = MraSendQueueCMD(hSendQueueHandle, 0, hContact, ICQACKTYPE_SMS, lpbDataQueue, (dwPhoneSize+(dwMessageSize*sizeof(WCHAR))+sizeof(DWORD)+2), MRIM_CS_SMS, lpbData, (lpbDataCurrent-lpbData));
- mir_free(lpbData);
- mir_free(lpszPhoneLocal);
- }
- else {
- mir_free(lpbData);
- mir_free(lpbDataQueue);
- mir_free(lpszPhoneLocal);
- }
- return dwRet;
+ CMStringA szPhoneLocal = "+" + CopyNumber(lpszPhone);
+
+ OutBuffer buf, buf2;
+ buf.SetUL(0);
+ buf.SetLPS(szPhoneLocal);
+ buf.SetLPSW(lpwszMessage);
+
+ buf2.SetLPS(szPhoneLocal);
+ buf.SetLPSW(lpwszMessage);
+ return MraSendQueueCMD(hSendQueueHandle, 0, hContact, ICQACKTYPE_SMS, buf2.Data(), buf2.Len(), MRIM_CS_SMS, buf.Data(), buf.Len());
}
// Соединение с прокси
-DWORD CMraProto::MraProxy(LPSTR lpszEMail, size_t dwEMailSize, DWORD dwIDRequest, DWORD dwDataType, LPSTR lpszData, size_t dwDataSize, LPSTR lpszAddreses, size_t dwAddressesSize, MRA_GUID mguidSessionID)
+DWORD CMraProto::MraProxy(const CMStringA &szEmail, DWORD dwIDRequest, DWORD dwDataType, const CMStringA &lpszData, const CMStringA &szAddresses, MRA_GUID mguidSessionID)
{
- DWORD dwRet = 0;
-
- if (lpszEMail && dwEMailSize>4) {
- LPBYTE lpbData = (LPBYTE)mir_calloc((dwEMailSize+(sizeof(DWORD)*2)+dwDataSize+dwAddressesSize+sizeof(MRA_GUID)+32));
- if (lpbData) {
- LPBYTE lpbDataCurrent = lpbData;
- SetLPSLowerCase(&lpbDataCurrent, lpszEMail, dwEMailSize);
- SetUL(&lpbDataCurrent, dwIDRequest);
- SetUL(&lpbDataCurrent, dwDataType);
- SetLPS(&lpbDataCurrent, lpszData, dwDataSize);
- SetLPS(&lpbDataCurrent, lpszAddreses, dwAddressesSize);
- SetGUID(&lpbDataCurrent, mguidSessionID);
-
- dwRet = MraSendCMD(MRIM_CS_PROXY, lpbData, (lpbDataCurrent-lpbData));
- mir_free(lpbData);
- }
- }
- return dwRet;
+ if (szEmail.GetLength() <= 4)
+ return 0;
+
+ OutBuffer buf;
+ buf.SetLPSLowerCase(szEmail);
+ buf.SetUL(dwIDRequest);
+ buf.SetUL(dwDataType);
+ buf.SetLPS(lpszData);
+ buf.SetLPS(szAddresses);
+ buf.SetGUID(mguidSessionID);
+ return MraSendCMD(MRIM_CS_PROXY, buf.Data(), buf.Len());
}
// Ответ на соединение с прокси
-DWORD CMraProto::MraProxyAck(DWORD dwStatus, LPSTR lpszEMail, size_t dwEMailSize, DWORD dwIDRequest, DWORD dwDataType, LPSTR lpszData, size_t dwDataSize, LPSTR lpszAddreses, size_t dwAddressesSize, MRA_GUID mguidSessionID)
+DWORD CMraProto::MraProxyAck(DWORD dwStatus, const CMStringA &szEmail, DWORD dwIDRequest, DWORD dwDataType, const CMStringA &lpszData, const CMStringA &szAddresses, MRA_GUID mguidSessionID)
{
- DWORD dwRet = 0;
-
- if (lpszEMail && dwEMailSize>4) {
- LPBYTE lpbData = (LPBYTE)mir_calloc((dwEMailSize+(sizeof(DWORD)*3)+dwDataSize+dwAddressesSize+sizeof(MRA_GUID)+32));
- if (lpbData) {
- LPBYTE lpbDataCurrent = lpbData;
- SetUL(&lpbDataCurrent, dwStatus);
- SetLPSLowerCase(&lpbDataCurrent, lpszEMail, dwEMailSize);
- SetUL(&lpbDataCurrent, dwIDRequest);
- SetUL(&lpbDataCurrent, dwDataType);
- SetLPS(&lpbDataCurrent, lpszData, dwDataSize);
- SetLPS(&lpbDataCurrent, lpszAddreses, dwAddressesSize);
- SetGUID(&lpbDataCurrent, mguidSessionID);
-
- dwRet = MraSendCMD(MRIM_CS_PROXY_ACK, lpbData, (lpbDataCurrent-lpbData));
- mir_free(lpbData);
- }
- }
- return dwRet;
+ if (szEmail.GetLength() <= 4)
+ return 0;
+
+ OutBuffer buf;
+ buf.SetUL(dwStatus);
+ buf.SetLPSLowerCase(szEmail);
+ buf.SetUL(dwIDRequest);
+ buf.SetUL(dwDataType);
+ buf.SetLPS(lpszData);
+ buf.SetLPS(szAddresses);
+ buf.SetGUID(mguidSessionID);
+ return MraSendCMD(MRIM_CS_PROXY_ACK, buf.Data(), buf.Len());
}
// Отправка сообщения в микроблог
-DWORD CMraProto::MraChangeUserBlogStatus(DWORD dwFlags, LPWSTR lpwszText, size_t dwTextSize, DWORDLONG dwBlogStatusID)
+DWORD CMraProto::MraChangeUserBlogStatus(DWORD dwFlags, const CMStringW &wszText, DWORDLONG dwBlogStatusID)
{
- DWORD dwRet = 0;
- if (dwTextSize > MICBLOG_STATUS_MAX)
- dwTextSize = MICBLOG_STATUS_MAX;
-
- LPBYTE lpbData = (LPBYTE)mir_calloc((sizeof(DWORD)+(dwTextSize*sizeof(WCHAR))+sizeof(DWORDLONG)+32));
- if (lpbData) {
- LPBYTE lpbDataCurrent = lpbData;
- SetUL(&lpbDataCurrent, dwFlags);
- SetLPSW(&lpbDataCurrent, lpwszText, dwTextSize);
- SetUIDL(&lpbDataCurrent, dwBlogStatusID);
-
- dwRet = MraSendCMD(MRIM_CS_CHANGE_USER_BLOG_STATUS, lpbData, (lpbDataCurrent-lpbData));
- mir_free(lpbData);
- }
-
- return dwRet;
+ OutBuffer buf;
+ buf.SetUL(dwFlags);
+ buf.SetLPSW(wszText);
+ buf.SetUIDL(dwBlogStatusID);
+ return MraSendCMD(MRIM_CS_CHANGE_USER_BLOG_STATUS, buf.Data(), buf.Len());
}
-DWORD CMraProto::MraSendPacket(HANDLE hConnection, DWORD dwCMDNum, DWORD dwType, LPVOID lpData, size_t dwDataSize)
+DWORD CMraProto::MraSendPacket(HANDLE m_hConnection, DWORD dwCMDNum, DWORD dwType, LPVOID lpData, size_t dwDataSize)
{
- DWORD dwRet;
-
- LPBYTE lpbData = (LPBYTE)mir_calloc((dwDataSize+sizeof(mrim_packet_header_t)));
- if (lpbData) {
- mrim_packet_header_t *pmaHeader = (mrim_packet_header_t*)lpbData;
- pmaHeader->magic = CS_MAGIC;
- pmaHeader->proto = (PROTO_VERSION_MAJOR<<16) + PROTO_VERSION_MINOR; // Версия протокола
- pmaHeader->seq = dwCMDNum;// Sequence
- pmaHeader->msg = dwType;// Тип пакета
- pmaHeader->dlen = dwDataSize;// Длина данных
-
- Netlib_Logf(hNetlibUser, "Sending packet %08x\n", dwType);
-
- memmove((lpbData+sizeof(mrim_packet_header_t)), lpData, dwDataSize);
- dwRet = Netlib_Send(hConnection, (LPSTR)lpbData, (dwDataSize+sizeof(mrim_packet_header_t)), 0);
- mir_free(lpbData);
- }
- return dwRet;
+ LPBYTE lpbData = (LPBYTE)_alloca(dwDataSize+sizeof(mrim_packet_header_t));
+
+ mrim_packet_header_t *pmaHeader = (mrim_packet_header_t*)lpbData;
+ memset(pmaHeader, 0, sizeof(mrim_packet_header_t));
+ pmaHeader->magic = CS_MAGIC;
+ pmaHeader->proto = (PROTO_VERSION_MAJOR<<16) + PROTO_VERSION_MINOR; // Версия протокола
+ pmaHeader->seq = dwCMDNum;// Sequence
+ pmaHeader->msg = dwType;// Тип пакета
+ pmaHeader->dlen = dwDataSize;// Длина данных
+
+ Netlib_Logf(m_hNetlibUser, "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);
}
DWORD CMraProto::MraSendCMD(DWORD dwType, LPVOID lpData, size_t dwDataSize)
@@ -668,7 +504,7 @@ DWORD CMraProto::MraSendCMD(DWORD dwType, LPVOID lpData, size_t dwDataSize)
DWORD dwRet = InterlockedIncrement((LONG volatile*)&dwCMDNum);
mir_cslock l(csCriticalSectionSend); // guarding winsock internal buffers
- return !MraSendPacket(hConnection, dwRet, dwType, lpData, dwDataSize) ? 0 : dwRet;
+ return !MraSendPacket(m_hConnection, dwRet, dwType, lpData, dwDataSize) ? 0 : dwRet;
}
@@ -677,7 +513,7 @@ DWORD CMraProto::MraSendQueueCMD(HANDLE hSendQueueHandle, DWORD dwFlags, HANDLE
DWORD dwRet = InterlockedIncrement((LONG volatile*)&dwCMDNum);
if ( !MraSendQueueAdd(hSendQueueHandle, dwRet, dwFlags, hContact, dwAckType, lpbDataQueue, dwDataQueueSize)) {
mir_cslock l(csCriticalSectionSend); // guarding winsock internal buffers
- if ( !MraSendPacket(hConnection, dwRet, dwType, lpData, dwDataSize)) {
+ if ( !MraSendPacket(m_hConnection, dwRet, dwType, lpData, dwDataSize)) {
MraSendQueueFree(hSendQueueHandle, dwRet);
dwRet = 0;
}
diff --git a/protocols/MRA/src/MraSendQueue.cpp b/protocols/MRA/src/MraSendQueue.cpp
index 1178495dec..496468c646 100644
--- a/protocols/MRA/src/MraSendQueue.cpp
+++ b/protocols/MRA/src/MraSendQueue.cpp
@@ -122,11 +122,11 @@ DWORD MraSendQueueFind(HANDLE hSendQueueHandle, DWORD dwCMDNum, DWORD *pdwFlags,
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;
+ 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;
}
}
diff --git a/protocols/MRA/src/Mra_functions.cpp b/protocols/MRA/src/Mra_functions.cpp
index 23b19814f3..daa6cdb00d 100644
--- a/protocols/MRA/src/Mra_functions.cpp
+++ b/protocols/MRA/src/Mra_functions.cpp
@@ -26,156 +26,127 @@ struct RECURSION_DATA_STACK_ITEM
LRESULT CALLBACK MessageEditSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
-DWORD MraGetSelfVersionString(LPSTR lpszSelfVersion, size_t dwSelfVersionSize, size_t *pdwSelfVersionSizeRet)
+CMStringA MraGetSelfVersionString()
{
- if (!lpszSelfVersion || !dwSelfVersionSize)
- return ERROR_INVALID_HANDLE;
-
WORD v[4];
DWORD dwMirVer = CallService(MS_SYSTEM_GETFILEVERSION, 0, (LPARAM)v);
- LPSTR lpszUnicode = (IsUnicodeEnv()? " Unicode":""),
- lpszSecIM = ( ServiceExists("SecureIM/IsContactSecured")? " + SecureIM":"");
- size_t dwSelfVersionSizeRet;
+ LPSTR lpszSecIM = ServiceExists("SecureIM/IsContactSecured") ? " + SecureIM" : "";
- dwSelfVersionSizeRet = mir_snprintf(lpszSelfVersion, dwSelfVersionSize, "Miranda NG %lu.%lu.%lu.%lu%s (MRA v%lu.%lu.%lu.%lu)%s, version: %lu.%lu",
- v[0], v[1], v[2], v[3], lpszUnicode,
- __FILEVERSION_STRING, lpszSecIM, PROTO_VERSION_MAJOR, PROTO_VERSION_MINOR);
-
- if (pdwSelfVersionSizeRet)
- *pdwSelfVersionSizeRet = dwSelfVersionSizeRet;
- return 0;
+ CMStringA szSelfVersion;
+ szSelfVersion.Format("Miranda NG %lu.%lu.%lu.%lu Unicode (MRA v%lu.%lu.%lu.%lu)%s, version: %lu.%lu",
+ v[0], v[1], v[2], v[3], __FILEVERSION_STRING, lpszSecIM, PROTO_VERSION_MAJOR, PROTO_VERSION_MINOR);
+ return szSelfVersion;
}
-DWORD GetParamValue(LPSTR lpszData, size_t dwDataSize, LPSTR lpszParamName, size_t dwParamNameSize, LPSTR lpszParamValue, size_t dwParamValueSize, size_t *pParamValueSizeRet)
+static DWORD GetParamValue(const CMStringA &szData, LPCSTR szParamName, DWORD dwParamNameSize, CMStringA &szParamValue)
{
- if (!lpszData || !dwDataSize || !lpszParamName || !dwParamNameSize || !lpszParamValue || !dwParamValueSize)
+ if (szData.IsEmpty())
return ERROR_INVALID_HANDLE;
- char szData[USER_AGENT_MAX+4096];
+ char tmp[USER_AGENT_MAX+4096];
LPSTR lpszParamDataStart, lpszParamDataEnd;
- dwDataSize = ((dwDataSize<SIZEOF(szData))? dwDataSize:SIZEOF(szData));
- BuffToLowerCase(szData, lpszData, dwDataSize);
+ DWORD dwDataSize = min(szData.GetLength(), SIZEOF(szData));
+ BuffToLowerCase(szData, tmp, dwDataSize);
- lpszParamDataStart = (LPSTR)MemoryFind(0, szData, dwDataSize, lpszParamName, dwParamNameSize);
+ lpszParamDataStart = strstr(tmp, szParamName);
if (lpszParamDataStart)
if ((*((WORD*)(lpszParamDataStart+dwParamNameSize))) == (*((WORD*)"=\""))) {
lpszParamDataStart += dwParamNameSize+2;
- lpszParamDataEnd = (LPSTR)MemoryFindByte((lpszParamDataStart-szData), szData, dwDataSize, '"');
+ lpszParamDataEnd = strchr(lpszParamDataStart, '"');
if (lpszParamDataEnd) {
- memmove(lpszParamValue, (lpszData+(lpszParamDataStart-szData)), (lpszParamDataEnd-lpszParamDataStart));
- if (pParamValueSizeRet) (*pParamValueSizeRet) = (lpszParamDataEnd-lpszParamDataStart);
+ szParamValue = CMStringA(szData.c_str()+(lpszParamDataStart-szData), lpszParamDataEnd-lpszParamDataStart);
return NO_ERROR;
}
}
return ERROR_NOT_FOUND;
}
-DWORD MraGetVersionStringFromFormatted(LPSTR dwUserAgentFormatted, size_t dwUserAgentFormattedSize, LPSTR lpszVersion, size_t dwVersionSize, size_t *pdwVersionSizeRet)
+CMStringA MraGetVersionStringFromFormatted(const CMStringA &szUserAgentFormatted)
{
- if (!dwUserAgentFormatted || !dwUserAgentFormattedSize || !lpszVersion || !dwVersionSize)
- return ERROR_INVALID_HANDLE;
+ if (szUserAgentFormatted.IsEmpty())
+ return "";
- char szBuff[4096];
- size_t dwBuffSize, dwVersionSizeRet;
+ CMStringA res, tmp;
- if ( !GetParamValue(dwUserAgentFormatted, dwUserAgentFormattedSize, "name", 4, szBuff, SIZEOF(szBuff), &dwBuffSize))
- if ( !_strnicmp(szBuff, "Miranda IM", dwBuffSize) || !_strnicmp(szBuff, "Miranda NG", dwBuffSize)) {
- GetParamValue(dwUserAgentFormatted, dwUserAgentFormattedSize, "title", 5, lpszVersion, dwVersionSize, pdwVersionSizeRet);
- return 0;
+ if ( !GetParamValue(szUserAgentFormatted, "name", 4, tmp))
+ if (tmp == "Miranda IM" || tmp == "Miranda NG") {
+ GetParamValue(szUserAgentFormatted, "title", 5, res);
+ return res;
}
- dwVersionSizeRet = 0;
- if ( !GetParamValue(dwUserAgentFormatted, dwUserAgentFormattedSize, "client", 6, lpszVersion, dwVersionSize, &dwBuffSize)) {
- dwVersionSizeRet += dwBuffSize;
- *((BYTE*)(lpszVersion+dwVersionSizeRet)) = ' ';
- }
+ if ( !GetParamValue(szUserAgentFormatted, "client", 6, tmp))
+ res += tmp + " ";
- if ( !GetParamValue(dwUserAgentFormatted, dwUserAgentFormattedSize, "name", 4, lpszVersion, dwVersionSize, &dwBuffSize)) {
- dwVersionSizeRet += dwBuffSize;
- *((BYTE*)(lpszVersion+dwVersionSizeRet)) = ' ';
- }
+ if ( !GetParamValue(szUserAgentFormatted, "name", 4, tmp))
+ res += tmp + " ";
- if ( !GetParamValue(dwUserAgentFormatted, dwUserAgentFormattedSize, "title", 5, lpszVersion, dwVersionSize, &dwBuffSize)) {
- dwVersionSizeRet += dwBuffSize;
- *((BYTE*)(lpszVersion+dwVersionSizeRet)) = ' ';
- }
+ if ( !GetParamValue(szUserAgentFormatted, "title", 5, tmp))
+ res += tmp + " ";
- if ( !GetParamValue(dwUserAgentFormatted, dwUserAgentFormattedSize, "version", 7, (lpszVersion+dwVersionSizeRet+1), (dwVersionSize-dwVersionSizeRet), &dwBuffSize)) {
- dwVersionSizeRet += (dwBuffSize+1);
- *((BYTE*)(lpszVersion+dwVersionSizeRet)) = '.';
- if ( !GetParamValue(dwUserAgentFormatted, dwUserAgentFormattedSize, "build", 5, (lpszVersion+dwVersionSizeRet+1), (dwVersionSize-dwVersionSizeRet), &dwBuffSize))
- dwVersionSizeRet += (dwBuffSize+1);
+ if ( !GetParamValue(szUserAgentFormatted, "version", 7, tmp)) {
+ res += tmp + " ";
+ if ( !GetParamValue(szUserAgentFormatted, "build", 5, tmp))
+ res += tmp;
}
// no data extracted, copy raw
- if (dwVersionSizeRet == 0) {
- dwVersionSizeRet = (dwUserAgentFormattedSize < dwVersionSize) ? dwUserAgentFormattedSize : dwVersionSize;
- memmove(lpszVersion, dwUserAgentFormatted, dwVersionSizeRet);
- }
-
- if (pdwVersionSizeRet)
- *pdwVersionSizeRet = dwVersionSizeRet;
-
- return 0;
+ return (res.IsEmpty()) ? szUserAgentFormatted : res;
}
-DWORD MraAddrListGetFromBuff(LPSTR lpszAddreses, size_t dwAddresesSize, MRA_ADDR_LIST *pmalAddrList)
+DWORD MraAddrListGetFromBuff(const CMStringA &szAddresses, MRA_ADDR_LIST *pmalAddrList)
{
- if (!lpszAddreses || !dwAddresesSize || !pmalAddrList)
+ if (szAddresses.IsEmpty() || !pmalAddrList)
return ERROR_INVALID_HANDLE;
-
- LPSTR lpszCurrentItem, lpszDelimiter, lpszEndItem;
- DWORD dwAllocatedCount;
-
- dwAllocatedCount = ALLOCATED_COUNT;
+
+ DWORD dwAllocatedCount = ALLOCATED_COUNT;
pmalAddrList->dwAddrCount = 0;
- pmalAddrList->pmaliAddress = (MRA_ADDR_LIST_ITEM*)mir_calloc(sizeof(MRA_ADDR_LIST_ITEM)*dwAllocatedCount);
- lpszCurrentItem = lpszAddreses;
+ pmalAddrList->pMailAddress = (MRA_ADDR_LIST_ITEM*)mir_calloc(sizeof(MRA_ADDR_LIST_ITEM)*dwAllocatedCount);
+
+ LPSTR buf = NEWSTR_ALLOCA(szAddresses.c_str()), lpszCurrentItem = buf;
while (TRUE) {
- lpszEndItem = (LPSTR)MemoryFindByte((lpszCurrentItem-lpszAddreses), lpszAddreses, dwAddresesSize, ';');
- if (lpszEndItem == NULL) lpszEndItem = (lpszAddreses+dwAddresesSize);
+ LPSTR lpszEndItem = strchr(lpszCurrentItem, ';');
+ if (lpszEndItem == NULL) lpszEndItem = buf + szAddresses.GetLength();
if (!lpszEndItem)
break;
- lpszDelimiter = (LPSTR)MemoryFindByte((lpszCurrentItem-lpszAddreses), lpszAddreses, dwAddresesSize, ':');
+ LPSTR lpszDelimiter = strchr(lpszCurrentItem, ':');
if (!lpszDelimiter)
break;
if (pmalAddrList->dwAddrCount == dwAllocatedCount) {
dwAllocatedCount += ALLOCATED_COUNT;
- pmalAddrList->pmaliAddress = (MRA_ADDR_LIST_ITEM*)mir_realloc(pmalAddrList->pmaliAddress, (sizeof(MRA_ADDR_LIST_ITEM)*dwAllocatedCount));
+ pmalAddrList->pMailAddress = (MRA_ADDR_LIST_ITEM*)mir_realloc(pmalAddrList->pMailAddress, (sizeof(MRA_ADDR_LIST_ITEM)*dwAllocatedCount));
}
- (*lpszDelimiter) = 0;
- pmalAddrList->pmaliAddress[pmalAddrList->dwAddrCount].dwAddr = inet_addr(lpszCurrentItem);
- pmalAddrList->pmaliAddress[pmalAddrList->dwAddrCount].dwPort = StrToUNum32((lpszDelimiter+1), (lpszEndItem-(lpszDelimiter+1)));
- (*lpszDelimiter) = ':';
+ *lpszDelimiter = 0;
+ pmalAddrList->pMailAddress[pmalAddrList->dwAddrCount].dwAddr = inet_addr(lpszCurrentItem);
+ pmalAddrList->pMailAddress[pmalAddrList->dwAddrCount].dwPort = StrToUNum32((lpszDelimiter+1), (lpszEndItem-(lpszDelimiter+1)));
+ *lpszDelimiter = ':';
pmalAddrList->dwAddrCount++;
- lpszCurrentItem = (lpszEndItem+1);
+ lpszCurrentItem = lpszEndItem+1;
- if (lpszEndItem == lpszAddreses + dwAddresesSize)
+ if (lpszEndItem == buf + szAddresses.GetLength())
break;
}
- pmalAddrList->pmaliAddress = (MRA_ADDR_LIST_ITEM*)mir_realloc(pmalAddrList->pmaliAddress, (sizeof(MRA_ADDR_LIST_ITEM)*pmalAddrList->dwAddrCount));
+ pmalAddrList->pMailAddress = (MRA_ADDR_LIST_ITEM*)mir_realloc(pmalAddrList->pMailAddress, (sizeof(MRA_ADDR_LIST_ITEM)*pmalAddrList->dwAddrCount));
return NO_ERROR;
}
-DWORD MraAddrListGetToBuff(MRA_ADDR_LIST *pmalAddrList, LPSTR lpszBuff, size_t dwBuffSize, size_t *pdwBuffSizeRet)
+CMStringA MraAddrListGetToBuff(MRA_ADDR_LIST *pmalAddrList)
{
- if (!pmalAddrList || !lpszBuff || !dwBuffSize)
- return ERROR_INVALID_HANDLE;
-
- LPSTR lpszCurPos = lpszBuff;
-
- for (size_t i = 0;i<pmalAddrList->dwAddrCount;i++)
- lpszCurPos += mir_snprintf(lpszCurPos, (dwBuffSize-((size_t)lpszCurPos-(size_t)lpszBuff)), "%s:%lu;",
- inet_ntoa((*((in_addr*)&pmalAddrList->pmaliAddress[i].dwAddr))), pmalAddrList->pmaliAddress[i].dwPort);
+ if (!pmalAddrList)
+ return "";
+
+ CMStringA res;
+ for (size_t i = 0; i < pmalAddrList->dwAddrCount; i++) {
+ char buf[100];
+ mir_snprintf(buf, sizeof(buf), "%s:%lu;", inet_ntoa((*((in_addr*)&pmalAddrList->pMailAddress[i].dwAddr))), pmalAddrList->pMailAddress[i].dwPort);
+ res += buf;
+ }
- if (pdwBuffSizeRet)
- *pdwBuffSizeRet = lpszCurPos - lpszBuff;
- return NO_ERROR;
+ return res;
}
void CMraProto::MraAddrListStoreToContact(HANDLE hContact, MRA_ADDR_LIST *pmalAddrList)
@@ -187,17 +158,17 @@ void CMraProto::MraAddrListStoreToContact(HANDLE hContact, MRA_ADDR_LIST *pmalAd
return;
setDword(hContact, "OldIP", getDword(hContact, "IP", 0));
- setDword(hContact, "IP", HTONL(pmalAddrList->pmaliAddress[0].dwAddr));
+ setDword(hContact, "IP", HTONL(pmalAddrList->pMailAddress[0].dwAddr));
if (pmalAddrList->dwAddrCount > 1) {
setDword(hContact, "OldRealIP", getDword(hContact, "RealIP", 0));
- setDword(hContact, "RealIP", HTONL(pmalAddrList->pmaliAddress[1].dwAddr));
+ setDword(hContact, "RealIP", HTONL(pmalAddrList->pMailAddress[1].dwAddr));
}
}
void MraAddrListFree(MRA_ADDR_LIST *pmalAddrList)
{
if (pmalAddrList) {
- mir_free(pmalAddrList->pmaliAddress);
+ mir_free(pmalAddrList->pMailAddress);
pmalAddrList->dwAddrCount = 0;
}
}
@@ -222,16 +193,17 @@ BOOL DB_GetStaticStringA(HANDLE hContact, LPCSTR lpszModule, LPCSTR lpszValueNam
if (pdwRetBuffSize) (*pdwRetBuffSize) = dwRetBuffSizeLocal;
db_free(&dbv);
- }else {
+ }
+ else {
if (lpszRetBuff && dwRetBuffSize >= sizeof(WORD)) (*((WORD*)lpszRetBuff)) = 0;
if (pdwRetBuffSize) (*pdwRetBuffSize) = 0;
}
return bRet;
}
-
+// sizes in wchars
BOOL DB_GetStaticStringW(HANDLE hContact, LPCSTR lpszModule, LPCSTR lpszValueName, LPWSTR lpwszRetBuff, size_t dwRetBuffSize, size_t *pdwRetBuffSize)
-{// sizes in wchars
+{
BOOL bRet = FALSE;
size_t dwReadedStringLen;
DBVARIANT dbv = {0};
@@ -249,65 +221,59 @@ BOOL DB_GetStaticStringW(HANDLE hContact, LPCSTR lpszModule, LPCSTR lpszValueNam
if (pdwRetBuffSize) (*pdwRetBuffSize) = dwReadedStringLen;
db_free(&dbv);
- }else {
+ }
+ else {
if (lpwszRetBuff && dwRetBuffSize >= sizeof(WCHAR)) (*((WCHAR*)lpwszRetBuff)) = 0;
if (pdwRetBuffSize) (*pdwRetBuffSize) = 0;
}
return bRet;
}
-BOOL DB_SetStringExA(HANDLE hContact, LPCSTR lpszModule, LPCSTR lpszValueName, LPCSTR lpszValue, size_t dwValueSize)
+BOOL DB_GetStringA(HANDLE hContact, LPCSTR lpszModule, LPCSTR lpszValueName, CMStringA& res)
{
- BOOL bRet = FALSE;
-
- if (lpszValue && dwValueSize) {
- LPWSTR lpwszValueLocal;
- size_t dwValueSizeLocal;
-
- dwValueSizeLocal = (dwValueSize+MAX_PATH);
- lpwszValueLocal = (LPWSTR)mir_calloc((dwValueSizeLocal*sizeof(WCHAR)));
-
- if (lpwszValueLocal) {
- DBVARIANT dbv = {0};
- dbv.type = DBVT_WCHAR;
- dbv.pwszVal = (WCHAR*)lpwszValueLocal;
+ char *szRes = db_get_sa(hContact, lpszModule, lpszValueName);
+ if (szRes) {
+ res = szRes;
+ mir_free(szRes);
+ return TRUE;
+ }
+
+ res.Empty();
+ return FALSE;
+}
- dwValueSizeLocal = MultiByteToWideChar(MRA_CODE_PAGE, 0, lpszValue, dwValueSize, lpwszValueLocal, dwValueSizeLocal);
- lpwszValueLocal[dwValueSizeLocal] = 0;
- bRet = (db_set(hContact, lpszModule, lpszValueName, &dbv) == 0);
- mir_free(lpwszValueLocal);
- }
- }
- else {
- bRet = TRUE;
- db_unset(hContact, lpszModule, lpszValueName);
+BOOL DB_GetStringW(HANDLE hContact, LPCSTR lpszModule, LPCSTR lpszValueName, CMStringW& res)
+{
+ WCHAR *szRes = db_get_wsa(hContact, lpszModule, lpszValueName);
+ if (szRes) {
+ res = szRes;
+ mir_free(szRes);
+ return TRUE;
}
- return bRet;
+
+ res.Empty();
+ return FALSE;
}
-BOOL DB_SetStringExW(HANDLE hContact, LPCSTR lpszModule, LPCSTR lpszValueName, LPCWSTR lpwszValue, size_t dwValueSize)
+BOOL DB_SetStringExA(HANDLE hContact, LPCSTR lpszModule, LPCSTR lpszValueName, const CMStringA &szValue)
{
- BOOL bRet = FALSE;
-
- if (lpwszValue && dwValueSize) {
- LPWSTR lpwszValueLocal = (LPWSTR)mir_calloc(((dwValueSize+MAX_PATH)*sizeof(WCHAR)));
+ if (szValue.IsEmpty()) {
+ db_unset(hContact, lpszModule, lpszValueName);
+ return true;
+ }
- if (lpwszValueLocal) {
- DBVARIANT dbv = {0};
- dbv.type = DBVT_WCHAR;
- dbv.pwszVal = (WCHAR*)lpwszValueLocal;
- memmove(lpwszValueLocal, lpwszValue, (dwValueSize*sizeof(WCHAR)));
- bRet = (db_set(hContact, lpszModule, lpszValueName, &dbv) == 0);
+ return db_set_s(hContact, lpszModule, lpszValueName, szValue);
+}
- mir_free(lpwszValueLocal);
- }
- }
- else {
- bRet = TRUE;
+BOOL DB_SetStringExW(HANDLE hContact, LPCSTR lpszModule, LPCSTR lpszValueName, const CMStringW &szValue)
+{
+ if (szValue.IsEmpty()) {
db_unset(hContact, lpszModule, lpszValueName);
+ return true;
}
- return bRet;
+
+ return db_set_ws(hContact, lpszModule, lpszValueName, szValue);
}
BOOL DB_GetContactSettingBlob(HANDLE hContact, LPCSTR lpszModule, LPCSTR lpszValueName, LPVOID lpRet, size_t dwRetBuffSize, size_t *pdwRetBuffSize)
@@ -340,22 +306,17 @@ DWORD CMraProto::GetContactFlags(HANDLE hContact)
if (IsContactMra(hContact))
{
- CHAR szEMail[MAX_EMAIL_LEN];
- size_t dwEMailSize;
-
dwRet = getDword(hContact, "ContactFlags", 0);
dwRet &= ~(CONTACT_FLAG_REMOVED|CONTACT_FLAG_GROUP|CONTACT_FLAG_INVISIBLE|CONTACT_FLAG_VISIBLE|CONTACT_FLAG_IGNORE|CONTACT_FLAG_SHADOW|CONTACT_FLAG_MULTICHAT);
dwRet |= CONTACT_FLAG_UNICODE_NAME;
- if (mraGetStaticStringA(hContact, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize))
- {
- if (IsEMailChatAgent(szEMail, dwEMailSize))
- {
+ CMStringA szEmail;
+ if (mraGetStringA(hContact, "e-mail", szEmail))
+ if (IsEMailChatAgent(szEmail))
dwRet |= CONTACT_FLAG_MULTICHAT;
- }
- }
- if (db_get_b(hContact, "CList", "Hidden", 0)) dwRet |= CONTACT_FLAG_SHADOW;
+ if (db_get_b(hContact, "CList", "Hidden", 0))
+ dwRet |= CONTACT_FLAG_SHADOW;
switch (getWord(hContact, "ApparentMode", 0)) {
case ID_STATUS_OFFLINE:
@@ -403,7 +364,7 @@ DWORD CMraProto::SetContactFlags(HANDLE hContact, DWORD dwContactFlag)
return 0;
}
-DWORD CMraProto::GetContactBasicInfoW(HANDLE hContact, DWORD *pdwID, DWORD *pdwGroupID, DWORD *pdwContactFlag, DWORD *pdwContactSeverFlags, DWORD *pdwStatus, LPSTR lpszEMail, size_t dwEMailSize, size_t *pdwEMailSize, LPWSTR lpwszNick, size_t dwNickSize, size_t *pdwNickSize, LPSTR lpszPhones, size_t dwPhonesSize, size_t *pdwPhonesSize)
+DWORD CMraProto::GetContactBasicInfoW(HANDLE hContact, DWORD *pdwID, DWORD *pdwGroupID, DWORD *pdwContactFlag, DWORD *pdwContactSeverFlags, DWORD *pdwStatus, CMStringA *szEmail, CMStringW *wszNick, CMStringA *szPhones)
{
if ( !IsContactMra(hContact))
return ERROR_INVALID_HANDLE;
@@ -418,29 +379,28 @@ DWORD CMraProto::GetContactBasicInfoW(HANDLE hContact, DWORD *pdwID, DWORD *pdwG
*pdwStatus = MraGetContactStatus(hContact);
if (pdwContactFlag)
*pdwContactFlag = GetContactFlags(hContact);
- if (lpszEMail && pdwEMailSize)
- mraGetStaticStringA(hContact, "e-mail", lpszEMail, dwEMailSize, pdwEMailSize);
- if (lpwszNick && pdwNickSize)
- DB_GetStaticStringW(hContact, "CList", "MyHandle", lpwszNick, dwNickSize, pdwNickSize);
-
- if (lpszPhones && pdwPhonesSize) {
- char szPhone[MAX_PATH], szValue[MAX_PATH];
- size_t dwPhoneSize, dwCopied = 0;
-
- for (size_t i = 0; i < 3; i++) {
- mir_snprintf(szValue, SIZEOF(szValue), "MyPhone%lu", i);
- if ( DB_GetStaticStringA(hContact, "UserInfo", szValue, szPhone, SIZEOF(szPhone), &dwPhoneSize)) {
- if (dwCopied)
- *((LPBYTE)(lpszPhones+dwCopied++)) = ',';
- dwCopied += CopyNumber((lpszPhones+dwCopied), szPhone, dwPhoneSize);
+ if (szEmail)
+ mraGetStringA(hContact, "e-mail", *szEmail);
+ if (wszNick)
+ DB_GetStringW(hContact, "CList", "MyHandle", *wszNick);
+
+ if (szPhones) {
+ CMStringA szPhone;
+
+ for (int i = 0; i < 3; i++) {
+ char szValue[50];
+ mir_snprintf(szValue, SIZEOF(szValue), "MyPhone%d", i);
+ if ( DB_GetStringA(hContact, "UserInfo", szValue, szPhone)) {
+ if (szPhones->GetLength())
+ szPhones->AppendChar(',');
+ szPhones->Append(szPhone);
}
}
- *pdwPhonesSize = dwCopied;
}
return 0;
}
-DWORD CMraProto::SetContactBasicInfoW(HANDLE hContact, DWORD dwSetInfoFlags, DWORD dwFlags, DWORD dwID, DWORD dwGroupID, DWORD dwContactFlag, DWORD dwContactSeverFlags, DWORD dwStatus, LPSTR lpszEMail, size_t dwEMailSize, LPWSTR lpwszNick, size_t dwNickSize, LPSTR lpszPhones, size_t dwPhonesSize)
+DWORD CMraProto::SetContactBasicInfoW(HANDLE hContact, DWORD dwSetInfoFlags, DWORD dwFlags, DWORD dwID, DWORD dwGroupID, DWORD dwContactFlag, DWORD dwContactSeverFlags, DWORD dwStatus, const CMStringA &szEmail, const CMStringW &wszNick, const CMStringA &szPhones)
{
if ( !IsContactMra(hContact))
return ERROR_INVALID_HANDLE;
@@ -453,50 +413,43 @@ DWORD CMraProto::SetContactBasicInfoW(HANDLE hContact, DWORD dwSetInfoFlags, DWO
if (dwFlags & SCBIF_ID)
setDword(hContact, "ContactID", dwID);
- if (dwFlags & SCBIF_EMAIL)
- if (lpszEMail && dwEMailSize)
- mraSetStringExA(hContact, "e-mail", lpszEMail, dwEMailSize);
+ if ((dwFlags & SCBIF_EMAIL) && !szEmail.IsEmpty())
+ mraSetStringExA(hContact, "e-mail", szEmail);
// поля изменения которых отслеживаются
if (dwFlags & SCBIF_GROUP_ID)
setDword(hContact, "GroupID", dwGroupID);
- if (dwFlags & SCBIF_NICK) {
- if ((dwFlags & SCBIF_FLAG) && ((dwContactFlag&CONTACT_FLAG_UNICODE_NAME) == 0))
- {
- if (lpwszNick && dwNickSize)
- DB_SetStringExA(hContact, "CList", "MyHandle", (LPSTR)lpwszNick, dwNickSize);
- }
- else {
- if (lpwszNick && dwNickSize)
- DB_SetStringExW(hContact, "CList", "MyHandle", lpwszNick, dwNickSize);
- }
+ if ((dwFlags & SCBIF_NICK) && !wszNick.IsEmpty()) {
+ if ((dwFlags & SCBIF_FLAG) && ((dwContactFlag & CONTACT_FLAG_UNICODE_NAME) == 0))
+ DB_SetStringExA(hContact, "CList", "MyHandle", CMStringA(wszNick));
+ else
+ DB_SetStringExW(hContact, "CList", "MyHandle", wszNick);
}
- if (dwFlags & SCBIF_PHONES) {
- if (lpszPhones && dwPhonesSize) {
- char szPhone[MAX_PATH], szValue[MAX_PATH];
- LPSTR lpszCurPhone, lpszPhoneNext;
- size_t i, dwCurPhoneSize;
-
- i = 0;
- lpszCurPhone = lpszPhones;
- lpszPhoneNext = lpszPhones;
- while (lpszPhoneNext) {
- lpszPhoneNext = (LPSTR)MemoryFindByte((lpszCurPhone-lpszPhones), lpszPhones, dwPhonesSize, ',');
- if (lpszPhoneNext)
- dwCurPhoneSize = lpszPhoneNext - lpszCurPhone;
- else
- dwCurPhoneSize = (lpszPhones + dwPhonesSize) - lpszCurPhone;
-
- szPhone[0] = '+';
- memmove((szPhone+1), lpszCurPhone, min(dwCurPhoneSize, (SIZEOF(szPhone)-1)));
- mir_snprintf(szValue, SIZEOF(szValue), "MyPhone%lu", i);
- DB_SetStringExA(hContact, "UserInfo", szValue, szPhone, (1+dwCurPhoneSize));
-
- i++;
- lpszCurPhone = (lpszPhoneNext+1);
- }
+ if ((dwFlags & SCBIF_PHONES) && !szPhones.IsEmpty()) {
+ char szPhone[MAX_PATH], szValue[MAX_PATH];
+ LPCSTR lpszCurPhone, lpszPhoneNext;
+ size_t i, dwCurPhoneSize;
+
+ i = 0;
+ lpszPhoneNext = lpszCurPhone = szPhones.c_str();
+ while (lpszPhoneNext) {
+ lpszPhoneNext = (LPSTR)MemoryFindByte((lpszCurPhone-szPhones), szPhones, szPhones.GetLength(), ',');
+ if (lpszPhoneNext)
+ dwCurPhoneSize = lpszPhoneNext - lpszCurPhone;
+ else
+ dwCurPhoneSize = (szPhones.c_str() + szPhones.GetLength()) - lpszCurPhone;
+
+ szPhone[0] = '+';
+ memmove(szPhone+1, lpszCurPhone, min(dwCurPhoneSize, (SIZEOF(szPhone)-1)));
+ szPhone[dwCurPhoneSize+1] = 0;
+
+ mir_snprintf(szValue, SIZEOF(szValue), "MyPhone%lu", i);
+ DB_SetStringExA(hContact, "UserInfo", szValue, szPhone);
+
+ i++;
+ lpszCurPhone = (lpszPhoneNext+1);
}
}
@@ -517,92 +470,86 @@ DWORD CMraProto::SetContactBasicInfoW(HANDLE hContact, DWORD dwSetInfoFlags, DWO
return 0;
}
-HANDLE CMraProto::MraHContactFromEmail(LPSTR lpszEMail, size_t dwEMailSize, BOOL bAddIfNeeded, BOOL bTemporary, BOOL *pbAdded)
+HANDLE CMraProto::MraHContactFromEmail(const CMStringA& szEmail, BOOL bAddIfNeeded, BOOL bTemporary, BOOL *pbAdded)
{
+ if ( szEmail.IsEmpty())
+ return NULL;
+
HANDLE hContact = NULL;
+ bool bFound = false;
- if (lpszEMail && dwEMailSize)
- {
- BOOL bFound = FALSE;
- CHAR szEMailLocal[MAX_EMAIL_LEN];
- size_t dwEMailLocalSize;
-
- if (dwEMailSize == -1) dwEMailSize = lstrlenA(lpszEMail);
- //check not already on list
- for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
- if (mraGetStaticStringA(hContact, "e-mail", szEMailLocal, SIZEOF(szEMailLocal), &dwEMailLocalSize))
- if (CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, szEMailLocal, dwEMailLocalSize, lpszEMail, dwEMailSize) == CSTR_EQUAL) {
+ //check not already on list
+ CMStringA szEMailLocal;
+ for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
+ if (mraGetStringA(hContact, "e-mail", szEMailLocal))
+ if (CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, szEMailLocal, szEMailLocal.GetLength(), szEmail, szEmail.GetLength()) == CSTR_EQUAL) {
if (bTemporary == FALSE) db_unset(hContact, "CList", "NotOnList");
- bFound = TRUE;
+ bFound = true;
break;
}
- }
- if (bFound == FALSE && bAddIfNeeded)
- {//not already there: add
- if (IsEMailChatAgent(lpszEMail, dwEMailSize))
- {
- GCSESSION gcw = {0};
- WCHAR wszEMail[MAX_EMAIL_LEN] = {0};
-
- gcw.cbSize = sizeof(GCSESSION);
- gcw.iType = GCW_CHATROOM;
- gcw.pszModule = m_szModuleName;
- gcw.ptszName = wszEMail;
- gcw.ptszID = (LPWSTR)wszEMail;
- gcw.dwFlags = GC_UNICODE;
- MultiByteToWideChar(MRA_CODE_PAGE, 0, lpszEMail, dwEMailSize, wszEMail, SIZEOF(wszEMail));
-
- if (CallServiceSync(MS_GC_NEWSESSION, NULL, (LPARAM)&gcw) == 0) {
- BOOL bChatAdded = FALSE;
- for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
- if (mraGetStaticStringA(hContact, "ChatRoomID", szEMailLocal, SIZEOF(szEMailLocal), &dwEMailLocalSize))
- if (CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, szEMailLocal, dwEMailLocalSize, lpszEMail, dwEMailSize) == CSTR_EQUAL) {
+ if (!bFound && bAddIfNeeded) {
+ //not already there: add
+ if (IsEMailChatAgent(szEmail)) {
+ GCSESSION gcw = {0};
+ CMStringW wszEMail = szEmail;
+
+ gcw.cbSize = sizeof(GCSESSION);
+ gcw.iType = GCW_CHATROOM;
+ gcw.pszModule = m_szModuleName;
+ gcw.ptszName = wszEMail;
+ gcw.ptszID = (LPWSTR)wszEMail.c_str();
+ gcw.dwFlags = GC_UNICODE;
+
+ if (CallServiceSync(MS_GC_NEWSESSION, NULL, (LPARAM)&gcw) == 0) {
+ BOOL bChatAdded = FALSE;
+ for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ if (mraGetStringA(hContact, "ChatRoomID", szEMailLocal)) {
+ if (CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, szEMailLocal, szEMailLocal.GetLength(), szEmail, szEmail.GetLength()) == CSTR_EQUAL) {
bChatAdded = TRUE;
break;
}
}
- if (bChatAdded == FALSE) hContact = NULL;
}
- }else {
- hContact = (HANDLE)CallService(MS_DB_CONTACT_ADD, 0, 0);
- CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)m_szModuleName);
+ if (bChatAdded == FALSE)
+ hContact = NULL;
}
+ }
+ else {
+ hContact = (HANDLE)CallService(MS_DB_CONTACT_ADD, 0, 0);
+ CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)m_szModuleName);
+ }
- if (hContact) {
- if (IsEMailChatAgent(lpszEMail, dwEMailSize))
- SetContactBasicInfoW(hContact, SCBIFSI_LOCK_CHANGES_EVENTS, (SCBIF_ID|SCBIF_GROUP_ID|SCBIF_SERVER_FLAG|SCBIF_STATUS|SCBIF_EMAIL), -1, -1, 0, CONTACT_INTFLAG_NOT_AUTHORIZED, ID_STATUS_ONLINE, lpszEMail, dwEMailSize, NULL, 0, NULL, 0);
- else {
- if (bTemporary)
- db_set_b(hContact, "CList", "NotOnList", 1);
- mraSetStringExA(hContact, "MirVer", MIRVER_UNKNOWN, (sizeof(MIRVER_UNKNOWN)-1));
- SetContactBasicInfoW(hContact, SCBIFSI_LOCK_CHANGES_EVENTS, (SCBIF_ID|SCBIF_GROUP_ID|SCBIF_SERVER_FLAG|SCBIF_STATUS|SCBIF_EMAIL), -1, -1, 0, CONTACT_INTFLAG_NOT_AUTHORIZED, ID_STATUS_OFFLINE, lpszEMail, dwEMailSize, NULL, 0, NULL, 0);
- }
+ if (hContact) {
+ if ( IsEMailChatAgent(szEmail))
+ SetContactBasicInfoW(hContact, SCBIFSI_LOCK_CHANGES_EVENTS, (SCBIF_ID|SCBIF_GROUP_ID|SCBIF_SERVER_FLAG|SCBIF_STATUS|SCBIF_EMAIL), -1, -1, 0, CONTACT_INTFLAG_NOT_AUTHORIZED, ID_STATUS_ONLINE, szEmail, L"", "");
+ else {
+ if (bTemporary)
+ db_set_b(hContact, "CList", "NotOnList", 1);
+ mraSetStringExA(hContact, "MirVer", MIRVER_UNKNOWN);
+ SetContactBasicInfoW(hContact, SCBIFSI_LOCK_CHANGES_EVENTS, (SCBIF_ID|SCBIF_GROUP_ID|SCBIF_SERVER_FLAG|SCBIF_STATUS|SCBIF_EMAIL), -1, -1, 0, CONTACT_INTFLAG_NOT_AUTHORIZED, ID_STATUS_OFFLINE, szEmail, L"", "");
}
}
-
- if (pbAdded) (*pbAdded) = (bFound == FALSE && bAddIfNeeded && hContact);
}
+
+ if (pbAdded)
+ *pbAdded = (bFound == FALSE && bAddIfNeeded && hContact);
+
return hContact;
}
-BOOL CMraProto::MraUpdateContactInfo(HANDLE hContact)
+bool CMraProto::MraUpdateContactInfo(HANDLE hContact)
{
- BOOL bRet = FALSE;
-
if (m_bLoggedIn && hContact)
if (IsContactMra(hContact)) {
- CHAR szEMail[MAX_EMAIL_LEN];
- size_t dwEMailSize;
-
- if (mraGetStaticStringA(hContact, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize)) {
+ CMStringA szEmail;
+ if (mraGetStringA(hContact, "e-mail", szEmail)) {
MraAvatarsQueueGetAvatarSimple(hAvatarsQueueHandle, GAIF_FORCE, hContact, 0);
-
- if (MraWPRequestByEMail(hContact, ACKTYPE_GETINFO, szEMail, dwEMailSize))
- bRet = TRUE;
+ if ( MraWPRequestByEMail(hContact, ACKTYPE_GETINFO, szEmail))
+ return true;
}
}
- return bRet;
+ return false;
}
DWORD CMraProto::MraContactCapabilitiesGet(HANDLE hContact)
@@ -665,41 +612,28 @@ DWORD CMraProto::MraSetContactStatus(HANDLE hContact, DWORD dwNewStatus)
return(dwOldStatus);
}
-void CMraProto::MraUpdateEmailStatus(LPSTR lpszFrom, size_t dwFromSize, LPSTR lpszSubject, size_t dwSubjectSize, DWORD dwDate, DWORD dwUIDL)
+void CMraProto::MraUpdateEmailStatus(const CMStringA &pszFrom, const CMStringA &pszSubject, DWORD dwDate, DWORD dwUIDL)
{
BOOL bTrayIconNewMailNotify;
WCHAR szStatusText[MAX_SECONDLINE];
bTrayIconNewMailNotify = getByte("TrayIconNewMailNotify", MRA_DEFAULT_TRAYICON_NEW_MAIL_NOTIFY);
- if (dwEmailMessagesUnread)
- {
- LPSTR lpszEMail;
- size_t dwEMailSize;
+ if (m_dwEmailMessagesUnread) {
+ CMStringA szEmail;
HANDLE hContact = NULL;
WCHAR szMailBoxStatus[MAX_SECONDLINE];
- mir_sntprintf(szMailBoxStatus, SIZEOF(szMailBoxStatus), TranslateW(L"Unread mail is available: %lu/%lu messages"), dwEmailMessagesUnread, dwEmailMessagesTotal);
-
- if ((lpszFrom && dwFromSize) || (lpszSubject && dwSubjectSize))
- {
- WCHAR szFrom[MAX_PATH] = {0}, szSubject[MAX_PATH] = {0};
-
- if (GetEMailFromString(lpszFrom, dwFromSize, &lpszEMail, &dwEMailSize))
- {
- hContact = MraHContactFromEmail(lpszEMail, dwEMailSize, FALSE, TRUE, NULL);
- }
+ mir_sntprintf(szMailBoxStatus, SIZEOF(szMailBoxStatus), TranslateW(L"Unread mail is available: %lu/%lu messages"), m_dwEmailMessagesUnread, dwEmailMessagesTotal);
- dwFromSize = MultiByteToWideChar(MRA_CODE_PAGE, 0, lpszFrom, dwFromSize, szFrom, SIZEOF(szFrom));
- szFrom[dwFromSize] = 0;
+ if ( !pszFrom.IsEmpty() || !pszSubject.IsEmpty()) {
+ CMStringA szFrom, szSubject;
+ if ( GetEMailFromString(szFrom, szEmail))
+ hContact = MraHContactFromEmail(szEmail, FALSE, TRUE, NULL);
- dwSubjectSize = MultiByteToWideChar(MRA_CODE_PAGE, 0, lpszSubject, dwSubjectSize, szSubject, SIZEOF(szSubject));
- szSubject[dwSubjectSize] = 0;
-
- mir_sntprintf(szStatusText, SIZEOF(szStatusText), TranslateW(L"From: %s\r\nSubject: %s\r\n%s"), szFrom, szSubject, szMailBoxStatus);
- }else {
- lstrcpynW(szStatusText, szMailBoxStatus, SIZEOF(szStatusText));
+ mir_sntprintf(szStatusText, SIZEOF(szStatusText), TranslateW(L"From: %S\r\nSubject: %S\r\n%s"), pszFrom.c_str(), szSubject.c_str(), szMailBoxStatus);
}
+ else lstrcpynW(szStatusText, szMailBoxStatus, SIZEOF(szStatusText));
if (bTrayIconNewMailNotify) {
char szServiceFunction[MAX_PATH], *pszServiceFunctionName;
@@ -745,271 +679,170 @@ void CMraProto::MraUpdateEmailStatus(LPSTR lpszFrom, size_t dwFromSize, LPSTR lp
}
}
-
-BOOL IsUnicodeEnv()
-{// Are we running under unicode Miranda core ?
- return TRUE;
-}
-
-
-BOOL IsHTTPSProxyUsed(HANDLE hNetlibUser)
+bool IsHTTPSProxyUsed(HANDLE m_hNetlibUser)
{
- BOOL bRet = FALSE;
- NETLIBUSERSETTINGS nlus = {0};
+ NETLIBUSERSETTINGS nlus = { sizeof(nlus) };
+ if (CallService(MS_NETLIB_GETUSERSETTINGS, (WPARAM)m_hNetlibUser, (LPARAM)&nlus))
+ if (nlus.useProxy && nlus.proxyType == PROXYTYPE_HTTPS)
+ return true;
- nlus.cbSize = sizeof(nlus);
- if (CallService(MS_NETLIB_GETUSERSETTINGS, (WPARAM)hNetlibUser, (LPARAM)&nlus))
- {
- if (nlus.useProxy && nlus.proxyType == PROXYTYPE_HTTPS) bRet = TRUE;
- }
- return(bRet);
+ return false;
}
// определяет принадлежность контакта данной копии плагина
-BOOL CMraProto::IsContactMra(HANDLE hContact)
+bool CMraProto::IsContactMra(HANDLE hContact)
{
- return(CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)m_szModuleName));
+ return CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)m_szModuleName) != 0;
}
// определяется является ли контакт контактом MRA протокола, не зависимо от того какому плагину он принадлежит
-BOOL IsContactMraProto(HANDLE hContact)
+bool IsContactMraProto(HANDLE hContact)
{
- BOOL bRet = FALSE;
LPSTR lpszProto = GetContactProto(hContact);
-
- if (lpszProto)
- {
- WCHAR szBuff[MAX_PATH];
-
- if (DB_GetStaticStringW(hContact, lpszProto, "AvatarLastCheckTime", szBuff, SIZEOF(szBuff), NULL))
- if (DB_GetStaticStringW(hContact, lpszProto, "AvatarLastModifiedTime", szBuff, SIZEOF(szBuff), NULL))
- {
- bRet = TRUE;
- }
+ if (lpszProto) {
+ CMStringW szBuff;
+ if ( DB_GetStringW(hContact, lpszProto, "AvatarLastCheckTime", szBuff))
+ if ( DB_GetStringW(hContact, lpszProto, "AvatarLastModifiedTime", szBuff))
+ return true;
}
- return(bRet);
+ return false;
}
-BOOL CMraProto::IsEMailMy(LPSTR lpszEMail, size_t dwEMailSize)
+bool CMraProto::IsEMailMy(const CMStringA &szEmail)
{
- BOOL bRet = FALSE;
-
- if (lpszEMail)
- {
- CHAR szEMailMy[MAX_EMAIL_LEN];
- size_t dwEMailMySize;
-
- if (mraGetStaticStringA(NULL, "e-mail", szEMailMy, SIZEOF(szEMailMy), &dwEMailMySize))
- {
- if (dwEMailSize == 0) dwEMailSize = lstrlenA(lpszEMail);
-
- if (dwEMailMySize == dwEMailSize)
- if (CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, lpszEMail, dwEMailSize, szEMailMy, dwEMailMySize) == CSTR_EQUAL)
- {
- bRet = TRUE;
- }
+ if (!szEmail.IsEmpty()) {
+ CMStringA szEmailMy;
+ if (mraGetStringA(NULL, "e-mail", szEmailMy)) {
+ if (szEmail.GetLength() == szEmailMy.GetLength())
+ if (!_stricmp(szEmail, szEmailMy))
+ return true;
}
}
-return(bRet);
+ return false;
}
-BOOL CMraProto::IsEMailChatAgent(LPSTR lpszEMail, size_t dwEMailSize)
+bool CMraProto::IsEMailChatAgent(const CMStringA &szEmail)
{
- BOOL bRet = FALSE;
-
- if (lpszEMail)
- {
- if (dwEMailSize == 0) dwEMailSize = lstrlenA(lpszEMail);
- if ((sizeof(MAILRU_CHAT_CONF_DOMAIN)-1)<dwEMailSize)
- if (CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, MAILRU_CHAT_CONF_DOMAIN, (sizeof(MAILRU_CHAT_CONF_DOMAIN)-1), (lpszEMail+(dwEMailSize-(sizeof(MAILRU_CHAT_CONF_DOMAIN)-1))), (sizeof(MAILRU_CHAT_CONF_DOMAIN)-1)) == CSTR_EQUAL)
- {
- if ( (*(BYTE*)(lpszEMail+((dwEMailSize-(sizeof(MAILRU_CHAT_CONF_DOMAIN)-1))-1))) == '@' )
- {
- bRet = TRUE;
- }
- }
+ if (!szEmail.IsEmpty()) {
+ CMStringA domain = szEmail.Right(sizeof(MAILRU_CHAT_CONF_DOMAIN));
+ if (domain[0] == '@' && _stricmp(domain.c_str()+1, MAILRU_CHAT_CONF_DOMAIN))
+ return true;
}
-return(bRet);
+ return false;
}
-
-BOOL CMraProto::IsContactChatAgent(HANDLE hContact)
+bool CMraProto::IsContactChatAgent(HANDLE hContact)
{
- BOOL bRet = FALSE;
-
- if (hContact)
- {
- CHAR szEMail[MAX_EMAIL_LEN];
- size_t dwEMailSize;
+ if (hContact == NULL)
+ return false;
- if (mraGetStaticStringA(hContact, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize))
- {
- bRet = IsEMailChatAgent(szEMail, dwEMailSize);
- }
- //bRet = ((GetContactFlags(hContact)&CONTACT_FLAG_MULTICHAT) != 0);
- }
-return(bRet);
+ CMStringA szEmail;
+ return mraGetStringA(hContact, "e-mail", szEmail) ? IsEMailChatAgent(szEmail) : false;
}
-
-
-BOOL IsEMailMR(LPSTR lpszEMail, size_t dwEMailSize)
+bool IsEMailMR(const CMStringA &szEmail)
{
- BOOL bRet = FALSE;
-
- if (lpszEMail)
- {
- size_t i, dwDomainLen;
-
- if (dwEMailSize == 0) dwEMailSize = lstrlenA(lpszEMail);
- for (i = 0;lpcszMailRuDomains[i];i++)
- {
- dwDomainLen = lstrlenA(lpcszMailRuDomains[i]);
- if (dwDomainLen<dwEMailSize)
- if (CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, lpcszMailRuDomains[i], dwDomainLen, (lpszEMail+(dwEMailSize-dwDomainLen)), dwDomainLen) == CSTR_EQUAL)
- {
- if ( (*(BYTE*)(lpszEMail+((dwEMailSize-dwDomainLen)-1))) == '@' )
- {
- bRet = TRUE;
- break;
- }
- }
+ if (szEmail) {
+ for (int i = 0; lpcszMailRuDomains[i]; i++) {
+ int dwDomainLen = lstrlenA(lpcszMailRuDomains[i]);
+ if (dwDomainLen < szEmail.GetLength())
+ if (!_stricmp(lpcszMailRuDomains[i], szEmail.c_str()+szEmail.GetLength()-dwDomainLen))
+ if (szEmail[szEmail.GetLength()-dwDomainLen-1] == '@')
+ return true;
}
}
-return(bRet);
+ return false;
}
-
-BOOL GetEMailFromString(LPSTR lpszBuff, size_t dwBuffSize, LPSTR *plpszEMail, size_t *pdwEMailSize)
+bool GetEMailFromString(const CMStringA& szBuff, CMStringA& szEmail)
{
- BOOL bRet = FALSE;
-
- if (lpszBuff && dwBuffSize)
- {
- LPSTR lpszEMailStart, lpszEMailEnd;
-
- if ((lpszEMailStart = (LPSTR)MemoryFindByte(0, lpszBuff, dwBuffSize, '<')))
- {
- lpszEMailStart++;
- if ((lpszEMailEnd = (LPSTR)MemoryFindByte((lpszEMailStart-lpszBuff), lpszBuff, dwBuffSize, '>')))
- {
- if (plpszEMail) (*plpszEMail) = lpszEMailStart;
- if (pdwEMailSize) (*pdwEMailSize) = (lpszEMailEnd-lpszEMailStart);
-
- bRet = TRUE;
+ if (!szBuff.IsEmpty()) {
+ int Start, End;
+ if ((Start = szBuff.Find('<')) != -1) {
+ Start++;
+ if ((End = szBuff.Find('>', Start)) != -1) {
+ szEmail = szBuff.Mid(Start, End-Start-1);
+ return true;
}
}
}
- if (bRet == FALSE)
- {
- if (plpszEMail) (*plpszEMail) = NULL;
- if (pdwEMailSize) (*pdwEMailSize) = 0;
- }
-
-return(bRet);
+ szEmail.Empty();
+ return false;
}
-
DWORD GetContactEMailCountParam(HANDLE hContact, BOOL bMRAOnly, LPSTR lpszModule, LPSTR lpszValueName)
{
DWORD dwRet = 0;
- CHAR szBuff[MAX_PATH], szEMail[MAX_EMAIL_LEN];
- size_t i, dwEMailSize;
+ CMStringA szEmail;
- if (DB_GetStaticStringA(hContact, lpszModule, lpszValueName, szEMail, SIZEOF(szEMail), &dwEMailSize))
- {
- if (bMRAOnly == FALSE || IsEMailMR(szEMail, dwEMailSize)) dwRet++;
- }
+ if ( DB_GetStringA(hContact, lpszModule, lpszValueName, szEmail))
+ if (bMRAOnly == FALSE || IsEMailMR(szEmail))
+ dwRet++;
- for (i = 0;TRUE;i++)
- {
+ for (int i=0; TRUE; i++) {
+ char szBuff[100];
mir_snprintf(szBuff, SIZEOF(szBuff), "%s%lu", lpszValueName, i);
- if (DB_GetStaticStringA(hContact, lpszModule, szBuff, szEMail, SIZEOF(szEMail), &dwEMailSize))
- {
- if (bMRAOnly == FALSE || IsEMailMR(szEMail, dwEMailSize)) dwRet++;
- }else {
- if (i>EMAILS_MIN_COUNT) break;
+ if (DB_GetStringA(hContact, lpszModule, szBuff, szEmail)) {
+ if (bMRAOnly == FALSE || IsEMailMR(szEmail))
+ dwRet++;
+ }
+ else {
+ if (i > EMAILS_MIN_COUNT)
+ break;
}
}
-return(dwRet);
+ return dwRet;
}
-
DWORD CMraProto::GetContactEMailCount(HANDLE hContact, BOOL bMRAOnly)
{
- DWORD dwRet = 0;
- LPSTR lpszProto;
-
- if (hContact)
- lpszProto = GetContactProto(hContact);
- else
- lpszProto = m_szModuleName;
+ LPSTR lpszProto = (hContact) ? GetContactProto(hContact) : m_szModuleName;
+ DWORD dwRet = 0;
dwRet += GetContactEMailCountParam(hContact, bMRAOnly, lpszProto, "e-mail");
dwRet += GetContactEMailCountParam(hContact, bMRAOnly, "UserInfo", "e-mail");
dwRet += GetContactEMailCountParam(hContact, bMRAOnly, "UserInfo", "Mye-mail");
dwRet += GetContactEMailCountParam(hContact, bMRAOnly, "UserInfo", "Companye-mail");
dwRet += GetContactEMailCountParam(hContact, bMRAOnly, "UserInfo", "MyCompanye-mail");
-
-return(dwRet);
+ return dwRet;
}
-
-
-BOOL GetContactFirstEMailParam(HANDLE hContact, BOOL bMRAOnly, LPSTR lpszModule, LPSTR lpszValueName, LPSTR lpszRetBuff, size_t dwRetBuffSize, size_t *pdwRetBuffSize)
+bool GetContactFirstEMailParam(HANDLE hContact, BOOL bMRAOnly, LPSTR lpszModule, LPSTR lpszValueName, CMStringA &res)
{
- BOOL bRet = FALSE;
- CHAR szBuff[MAX_PATH], szEMail[MAX_EMAIL_LEN];
- size_t i, dwEMailSize;
+ CMStringA szEmail;
- if (DB_GetStaticStringA(hContact, lpszModule, lpszValueName, szEMail, SIZEOF(szEMail), &dwEMailSize))
- {
- if (bMRAOnly == FALSE || IsEMailMR(szEMail, dwEMailSize))
- {
- lstrcpynA(lpszRetBuff, szEMail, dwRetBuffSize);
- if (pdwRetBuffSize) (*pdwRetBuffSize) = dwEMailSize;
- bRet = TRUE;
+ if ( DB_GetStringA(hContact, lpszModule, lpszValueName, szEmail))
+ if (bMRAOnly == FALSE || IsEMailMR(szEmail)) {
+ res = szEmail;
+ return true;
}
- }
- for (i = 0;bRet == FALSE;i++)
- {
+ for (int i = 0; true; i++) {
+ char szBuff[100];
mir_snprintf(szBuff, SIZEOF(szBuff), "%s%lu", lpszValueName, i);
- if (DB_GetStaticStringA(hContact, lpszModule, szBuff, szEMail, SIZEOF(szEMail), &dwEMailSize))
- {
- if (bMRAOnly == FALSE || IsEMailMR(szEMail, dwEMailSize))
- {
- lstrcpynA(lpszRetBuff, szEMail, dwRetBuffSize);
- if (pdwRetBuffSize) (*pdwRetBuffSize) = dwEMailSize;
- bRet = TRUE;
- break;
+ if ( DB_GetStringA(hContact, lpszModule, szBuff, szEmail)) {
+ if (bMRAOnly == FALSE || IsEMailMR(szEmail)) {
+ res = szEmail;
+ return true;
}
- }else {
- if (i>EMAILS_MIN_COUNT) break;
}
+ else if (i>EMAILS_MIN_COUNT)
+ break;
}
-return(bRet);
+ return false;
}
-
-BOOL CMraProto::GetContactFirstEMail(HANDLE hContact, BOOL bMRAOnly, LPSTR lpszRetBuff, size_t dwRetBuffSize, size_t *pdwRetBuffSize)
+bool CMraProto::GetContactFirstEMail(HANDLE hContact, BOOL bMRAOnly, CMStringA &res)
{
- BOOL bRet = FALSE;
- LPSTR lpszProto;
-
- if (hContact)
- lpszProto = GetContactProto(hContact);
- else
- lpszProto = m_szModuleName;
-
- bRet = GetContactFirstEMailParam(hContact, bMRAOnly, lpszProto, "e-mail", lpszRetBuff, dwRetBuffSize, pdwRetBuffSize);
- if (bRet == FALSE) bRet = GetContactFirstEMailParam(hContact, bMRAOnly, "UserInfo", "e-mail", lpszRetBuff, dwRetBuffSize, pdwRetBuffSize);
- if (bRet == FALSE) bRet = GetContactFirstEMailParam(hContact, bMRAOnly, "UserInfo", "Mye-mail", lpszRetBuff, dwRetBuffSize, pdwRetBuffSize);
- if (bRet == FALSE) bRet = GetContactFirstEMailParam(hContact, bMRAOnly, "UserInfo", "Companye-mail", lpszRetBuff, dwRetBuffSize, pdwRetBuffSize);
- if (bRet == FALSE) bRet = GetContactFirstEMailParam(hContact, bMRAOnly, "UserInfo", "MyCompanye-mail", lpszRetBuff, dwRetBuffSize, pdwRetBuffSize);
+ LPSTR lpszProto = (hContact) ? GetContactProto(hContact) : m_szModuleName;
+ bool bRet = GetContactFirstEMailParam(hContact, bMRAOnly, lpszProto, "e-mail", res);
+ if (!bRet) bRet = GetContactFirstEMailParam(hContact, bMRAOnly, "UserInfo", "e-mail", res);
+ if (!bRet) bRet = GetContactFirstEMailParam(hContact, bMRAOnly, "UserInfo", "Mye-mail", res);
+ if (!bRet) bRet = GetContactFirstEMailParam(hContact, bMRAOnly, "UserInfo", "Companye-mail", res);
+ if (!bRet) bRet = GetContactFirstEMailParam(hContact, bMRAOnly, "UserInfo", "MyCompanye-mail", res);
return bRet;
}
@@ -1053,59 +886,38 @@ DWORD CMraProto::ProtoBroadcastAckAsync(HANDLE hContact, int type, int hResult,
return 0;
}
-DWORD CMraProto::CreateBlobFromContact(HANDLE hContact, LPWSTR lpwszRequestReason, size_t dwRequestReasonSize, LPBYTE lpbBuff, size_t dwBuffSize, size_t *pdwBuffSizeRet)
+CMStringA CMraProto::CreateBlobFromContact(HANDLE hContact, const CMStringW &wszRequestReason)
{
- DWORD dwRetErrorCode;
- size_t dwBuffSizeRet = ((sizeof(DWORD)*2)+dwRequestReasonSize+5), dwSize;
-
- if (dwBuffSize >= dwBuffSizeRet) {
- PBYTE pCurBlob = lpbBuff;
+ CMStringA res('\0', 8), tmp;
+ DWORD *p = (DWORD*)res.c_str();
+ p[0] = 0; p[1] = (DWORD)hContact;
- *(DWORD*)pCurBlob = 0; pCurBlob += sizeof(DWORD);
- *(DWORD*)pCurBlob = (DWORD)hContact; pCurBlob += sizeof(DWORD);
+ mraGetStringA(hContact, "Nick", tmp);
+ res += tmp; res.AppendChar(0);
- mraGetStaticStringA(hContact, "Nick", (LPSTR)pCurBlob, (dwBuffSize-(pCurBlob-lpbBuff)), &dwSize);
- *(pCurBlob+dwSize) = 0;
- pCurBlob += (dwSize+1);
+ mraGetStringA(hContact, "FirstName", tmp);
+ res += tmp; res.AppendChar(0);
- mraGetStaticStringA(hContact, "FirstName", (LPSTR)pCurBlob, (dwBuffSize-(pCurBlob-lpbBuff)), &dwSize);
- *(pCurBlob+dwSize) = 0;
- pCurBlob += (dwSize+1);
+ mraGetStringA(hContact, "LastName", tmp);
+ res += tmp; res.AppendChar(0);
- mraGetStaticStringA(hContact, "LastName", (LPSTR)pCurBlob, (dwBuffSize-(pCurBlob-lpbBuff)), &dwSize);
- *(pCurBlob+dwSize) = 0;
- pCurBlob += (dwSize+1);
+ mraGetStringA(hContact, "e-mail", tmp);
+ res += tmp; res.AppendChar(0);
- mraGetStaticStringA(hContact, "e-mail", (LPSTR)pCurBlob, (dwBuffSize-(pCurBlob-lpbBuff)), &dwSize);
- *(pCurBlob+dwSize) = 0;
- pCurBlob += (dwSize+1);
-
- dwSize = WideCharToMultiByte(MRA_CODE_PAGE, 0, lpwszRequestReason, dwRequestReasonSize, (LPSTR)pCurBlob, (dwBuffSize-(pCurBlob-lpbBuff)), NULL, NULL);
- *(pCurBlob+dwSize) = 0;
- pCurBlob += (dwSize+1);
-
- dwBuffSizeRet = (pCurBlob-lpbBuff);
- dwRetErrorCode = NO_ERROR;
- }
- else dwRetErrorCode = ERROR_INSUFFICIENT_BUFFER;
-
- if (pdwBuffSizeRet)
- *pdwBuffSizeRet = dwBuffSizeRet;
- return dwRetErrorCode;
+ tmp = wszRequestReason;
+ res += tmp; res.AppendChar(0);
+ return res;
}
-size_t CopyNumber(LPCVOID lpcOutBuff, LPCVOID lpcBuff, size_t dwLen)
+CMStringA CopyNumber(const CMStringA &str)
{
- BYTE btChar;
- LPBYTE lpbOutBuff = (LPBYTE)lpcOutBuff, lpbInBuff = (LPBYTE)lpcBuff;
+ CMStringA res;
- for (size_t i = 0; i < dwLen; i++) {
- btChar = (*lpbInBuff++);
- if (btChar >= '0' && btChar <= '9') (*lpbOutBuff++) = btChar;
- }
- *lpbOutBuff = 0;
+ for (LPCSTR p = str; *p; p++)
+ if (*p >= '0' && *p <= '9')
+ res.AppendChar(*p);
- return lpbOutBuff-(LPBYTE)lpcOutBuff;
+ return res;
}
void EnableControlsArray(HWND hWndDlg, WORD *pwControlsList, size_t dwControlsListCount, BOOL bEnabled)
@@ -1149,7 +961,7 @@ INT_PTR CALLBACK SetXStatusDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LP
dat = (SetXStatusData*)lParam;
if (dat) {
char szValueName[MAX_PATH];
- WCHAR szBuff[STATUS_TITLE_MAX+STATUS_DESC_MAX];
+ CMStringW szBuff;
dat->hDlgIcon = IconLibGetIcon(hXStatusAdvancedStatusIcons[dat->dwXStatus]);
dat->dwCountdown = 5;
@@ -1164,14 +976,14 @@ INT_PTR CALLBACK SetXStatusDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LP
SendMessage(hWndDlg, WM_SETTEXT, 0, (LPARAM)TranslateW(lpcszXStatusNameDef[dat->dwXStatus]));
mir_snprintf(szValueName, SIZEOF(szValueName), "XStatus%ldName", dat->dwXStatus);
- if (dat->ppro->mraGetStaticStringW(NULL, szValueName, szBuff, (STATUS_TITLE_MAX+1), NULL))
- SET_DLG_ITEM_TEXT(hWndDlg, IDC_XTITLE, szBuff); // custom xstatus name
+ if (dat->ppro->mraGetStringW(NULL, szValueName, szBuff))
+ SET_DLG_ITEM_TEXT(hWndDlg, IDC_XTITLE, szBuff.c_str()); // custom xstatus name
else // default xstatus name
SET_DLG_ITEM_TEXT(hWndDlg, IDC_XTITLE, TranslateW(lpcszXStatusNameDef[dat->dwXStatus]));
mir_snprintf(szValueName, SIZEOF(szValueName), "XStatus%ldMsg", dat->dwXStatus);
- if (dat->ppro->mraGetStaticStringW(NULL, szValueName, szBuff, (STATUS_DESC_MAX+1), NULL))
- SET_DLG_ITEM_TEXT(hWndDlg, IDC_XMSG, szBuff); // custom xstatus description
+ if (dat->ppro->mraGetStringW(NULL, szValueName, szBuff))
+ SET_DLG_ITEM_TEXT(hWndDlg, IDC_XMSG, szBuff.c_str()); // custom xstatus description
else // default xstatus description
SET_DLG_ITEM_TEXT(hWndDlg, IDC_XMSG, L"");
@@ -1212,7 +1024,6 @@ INT_PTR CALLBACK SetXStatusDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LP
char szValueName[MAX_PATH];
HWND hWndEdit;
WCHAR szBuff[STATUS_TITLE_MAX+STATUS_DESC_MAX];
- size_t dwBuffSize;
WNDPROC OldMessageEditProc;
SetWindowLongPtr(hWndDlg, GWLP_USERDATA, (LONG_PTR)0);
@@ -1227,10 +1038,10 @@ INT_PTR CALLBACK SetXStatusDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LP
SetWindowLongPtr(hWndEdit, GWLP_WNDPROC, (LONG_PTR)OldMessageEditProc);
SetWindowLongPtr(hWndEdit, GWLP_USERDATA, (LONG_PTR)0);
- dwBuffSize = GET_DLG_ITEM_TEXT(hWndDlg, IDC_XMSG, szBuff, (STATUS_DESC_MAX+1));
+ DWORD dwBuffSize = GET_DLG_ITEM_TEXT(hWndDlg, IDC_XMSG, szBuff, (STATUS_DESC_MAX+1));
mir_snprintf(szValueName, SIZEOF(szValueName), "XStatus%ldMsg", dat->dwXStatus);
- dat->ppro->mraSetStringExW(NULL, szValueName, szBuff, dwBuffSize);
- dat->ppro->mraSetStringExW(NULL, DBSETTING_XSTATUSMSG, szBuff, dwBuffSize);
+ dat->ppro->mraSetStringExW(NULL, szValueName, szBuff);
+ dat->ppro->mraSetStringExW(NULL, DBSETTING_XSTATUSMSG, szBuff);
dwBuffSize = GET_DLG_ITEM_TEXT(hWndDlg, IDC_XTITLE, szBuff, (STATUS_TITLE_MAX+1));
if (dwBuffSize == 0) { // user delete all text
@@ -1238,8 +1049,8 @@ INT_PTR CALLBACK SetXStatusDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LP
dwBuffSize = lstrlenW(szBuff);
}
mir_snprintf(szValueName, SIZEOF(szValueName), "XStatus%dName", dat->dwXStatus);
- dat->ppro->mraSetStringExW(NULL, szValueName, szBuff, dwBuffSize);
- dat->ppro->mraSetStringExW(NULL, DBSETTING_XSTATUSNAME, szBuff, dwBuffSize);
+ dat->ppro->mraSetStringExW(NULL, szValueName, szBuff);
+ dat->ppro->mraSetStringExW(NULL, DBSETTING_XSTATUSNAME, szBuff);
CLISTMENUITEM mi = { sizeof(mi) };
mi.flags = (CMIM_NAME|CMIF_UNICODE);
@@ -1256,7 +1067,7 @@ INT_PTR CALLBACK SetXStatusDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LP
return iRet;
}
-BOOL CMraProto::MraRequestXStatusDetails(DWORD dwXStatus)
+bool CMraProto::MraRequestXStatusDetails(DWORD dwXStatus)
{
if ( IsXStatusValid(dwXStatus)) {
SetXStatusData *dat = (SetXStatusData*)mir_calloc(sizeof(SetXStatusData));
@@ -1265,7 +1076,7 @@ BOOL CMraProto::MraRequestXStatusDetails(DWORD dwXStatus)
return DialogBoxParam(masMraSettings.hInstance, MAKEINTRESOURCE(IDD_SETXSTATUS), NULL, SetXStatusDlgProc, (LPARAM)dat) != -1;
}
- return FALSE;
+ return false;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -1281,7 +1092,6 @@ INT_PTR CALLBACK SendReplyBlogStatusDlgProc(HWND hWndDlg, UINT message, WPARAM w
dat = (SetBlogStatusData*)lParam;
if (dat) {
- WCHAR szBuff[MICBLOG_STATUS_MAX];
SYSTEMTIME stBlogStatusTime = {0};
SetWindowLongPtr(hWndDlg, GWLP_USERDATA, (LONG_PTR)dat);
@@ -1294,23 +1104,25 @@ INT_PTR CALLBACK SendReplyBlogStatusDlgProc(HWND hWndDlg, UINT message, WPARAM w
SendMessage(hWndDlg, WM_SETICON, ICON_BIG, (LPARAM)IconLibGetIcon(gdiMenuItems[5].hIconHandle));
// blog status message
- if (dat->ppro->mraGetStaticStringW(dat->hContact, DBSETTING_BLOGSTATUS, szBuff, SIZEOF(szBuff), NULL))
- SET_DLG_ITEM_TEXT(hWndDlg, IDC_USER_BLOG_STATUS_MSG, szBuff);
+ CMStringW szBuff;
+ if (dat->ppro->mraGetStringW(dat->hContact, DBSETTING_BLOGSTATUS, szBuff))
+ SET_DLG_ITEM_TEXT(hWndDlg, IDC_USER_BLOG_STATUS_MSG, szBuff.c_str());
// reply to some user blog
if (dat->hContact) {
- mir_sntprintf(szBuff, SIZEOF(szBuff), TranslateW(L"Reply to %s blog status"), GetContactNameW(dat->hContact));
- SendMessage(hWndDlg, WM_SETTEXT, 0, (LPARAM)szBuff);
+ szBuff.Format( TranslateW(L"Reply to %s blog status"), GetContactNameW(dat->hContact));
+ SendMessage(hWndDlg, WM_SETTEXT, 0, (LPARAM)szBuff.c_str());
}
else SendMessage(hWndDlg, WM_SETTEXT, 0, (LPARAM)TranslateW(L"Set my blog status"));
DWORD dwTime = dat->ppro->getDword(dat->hContact, DBSETTING_BLOGSTATUSTIME, 0);
if (dwTime && MakeLocalSystemTimeFromTime32(dwTime, &stBlogStatusTime))
- mir_sntprintf(szBuff, SIZEOF(szBuff), L"%s: %04ld.%02ld.%02ld %02ld:%02ld", TranslateW(L"Writed"), stBlogStatusTime.wYear, stBlogStatusTime.wMonth, stBlogStatusTime.wDay, stBlogStatusTime.wHour, stBlogStatusTime.wMinute);
+ szBuff.Format(L"%s: %04ld.%02ld.%02ld %02ld:%02ld", TranslateW(L"Writed"),
+ stBlogStatusTime.wYear, stBlogStatusTime.wMonth, stBlogStatusTime.wDay, stBlogStatusTime.wHour, stBlogStatusTime.wMinute);
else
- szBuff[0] = 0;
+ szBuff.Empty();
- SET_DLG_ITEM_TEXT(hWndDlg, IDC_STATIC_WRITED_TIME, szBuff);
+ SET_DLG_ITEM_TEXT(hWndDlg, IDC_STATIC_WRITED_TIME, szBuff.c_str());
EnableWindow(GetDlgItem(hWndDlg, IDC_CHK_NOTIFY), (dat->hContact == NULL));
iRet = TRUE;
}
@@ -1332,14 +1144,19 @@ INT_PTR CALLBACK SendReplyBlogStatusDlgProc(HWND hWndDlg, UINT message, WPARAM w
dwBuffSize = GET_DLG_ITEM_TEXT(hWndDlg, IDC_MSG_TO_SEND, szBuff, SIZEOF(szBuff));
if (dat->hContact) {
dwFlags = (MRIM_BLOG_STATUS_REPLY|MRIM_BLOG_STATUS_NOTIFY);
- dat->ppro->mraGetContactSettingBlob(dat->hContact, DBSETTING_BLOGSTATUSID, &dwBlogStatusID, sizeof(DWORDLONG), NULL);
+
+ DBVARIANT dbv;
+ dbv.type = DBVT_BLOB;
+ dbv.pbVal = (PBYTE)&dwBlogStatusID;
+ dbv.cpbVal = sizeof(DWORDLONG);
+ db_get(dat->hContact, dat->ppro->m_szModuleName, DBSETTING_BLOGSTATUSID, &dbv);
}
else {
dwFlags = MRIM_BLOG_STATUS_UPDATE;
if (IS_DLG_BUTTON_CHECKED(hWndDlg, IDC_CHK_NOTIFY)) dwFlags |= MRIM_BLOG_STATUS_NOTIFY;
dwBlogStatusID = 0;
}
- dat->ppro->MraChangeUserBlogStatus(dwFlags, szBuff, dwBuffSize, dwBlogStatusID);
+ dat->ppro->MraChangeUserBlogStatus(dwFlags, szBuff, dwBlogStatusID);
}
case IDCANCEL:
DestroyWindow(hWndDlg);
@@ -1377,7 +1194,7 @@ INT_PTR CALLBACK SendReplyBlogStatusDlgProc(HWND hWndDlg, UINT message, WPARAM w
return iRet;
}
-BOOL CMraProto::MraSendReplyBlogStatus(HANDLE hContact)
+bool CMraProto::MraSendReplyBlogStatus(HANDLE hContact)
{
SetBlogStatusData* dat = (SetBlogStatusData*)mir_calloc( sizeof(SetBlogStatusData));
dat->ppro = this;
@@ -1410,6 +1227,8 @@ DWORD GetYears(CONST PSYSTEMTIME pcstSystemTime)
return dwRet;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
DWORD FindFile(LPWSTR lpszFolder, DWORD dwFolderLen, LPWSTR lpszFileName, DWORD dwFileNameLen, LPWSTR lpszRetFilePathName, DWORD dwRetFilePathLen, DWORD *pdwRetFilePathLen)
{
DWORD dwRetErrorCode;
@@ -1495,8 +1314,9 @@ DWORD FindFile(LPWSTR lpszFolder, DWORD dwFolderLen, LPWSTR lpszFileName, DWORD
return dwRetErrorCode;
}
+/////////////////////////////////////////////////////////////////////////////////////////
-DWORD MemFillRandom(LPVOID lpBuff, size_t dwBuffSize)
+static DWORD MemFillRandom(LPVOID lpBuff, size_t dwBuffSize)
{
DWORD dwRetErrorCode;
@@ -1521,94 +1341,84 @@ DWORD MemFillRandom(LPVOID lpBuff, size_t dwBuffSize)
return dwRetErrorCode;
}
-BOOL CMraProto::SetPassDB(LPSTR lpszBuff, size_t dwBuffSize)
+bool CMraProto::SetPassDB(const CMStringA& pass)
{
- BOOL bRet = FALSE;
- BYTE btRandomData[256], btCryptedPass[256] = {0}, bthmacSHA1[MIR_SHA1_HASH_SIZE] = {0};
- char szEMail[MAX_EMAIL_LEN] = {0};
- size_t dwEMailSize;
-
-#if /*defined (_DEBUG) ||*/ defined (REL_DEB)
+ if (pass.GetLength() >= 128)
+ return false;
- mraSetStringExA(NULL, "Pass", lpszBuff, dwBuffSize);
- bRet = TRUE;
-#else
- if (dwBuffSize < 128)
- if (mraGetStaticStringA(NULL, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize)) {
- MemFillRandom(btRandomData, sizeof(btRandomData));
+ CMStringA szEmail;
+ if ( !mraGetStringA(NULL, "e-mail", szEmail))
+ return false;
- SHA1GetDigest(lpszBuff, dwBuffSize, &btCryptedPass[1]);
+ BYTE btRandomData[256], btCryptedPass[256] = {0}, bthmacSHA1[MIR_SHA1_HASH_SIZE] = {0};
+ MemFillRandom(btRandomData, sizeof(btRandomData));
- //BASE64EncodeUnSafe(lpszBuff, dwBuffSize, &btCryptedPass[(1+MIR_SHA1_HASH_SIZE)], (sizeof(btCryptedPass)-1), &dwBuffSize);
- memmove(&btCryptedPass[(1+MIR_SHA1_HASH_SIZE)], lpszBuff, dwBuffSize);
- btCryptedPass[0] = (BYTE)dwBuffSize;
- //memmove(&btCryptedPass[1], lpszBuff, dwBuffSize);
+ SHA1GetDigest((void*)pass.c_str(), pass.GetLength(), &btCryptedPass[1]);
- mir_hmac_sha1(bthmacSHA1, (BYTE*)szEMail, dwEMailSize, btRandomData, sizeof(btRandomData));
+ //BASE64EncodeUnSafe(lpszBuff, dwBuffSize, &btCryptedPass[(1+MIR_SHA1_HASH_SIZE)], (sizeof(btCryptedPass)-1), &dwBuffSize);
+ memmove(&btCryptedPass[(1+MIR_SHA1_HASH_SIZE)], pass.c_str(), pass.GetLength());
+ btCryptedPass[0] = (BYTE)pass.GetLength();
+ //memmove(&btCryptedPass[1], lpszBuff, dwBuffSize);
- RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, MIR_SHA1_HASH_SIZE);
- RC4(btCryptedPass, sizeof(btCryptedPass), btRandomData, sizeof(btRandomData));
- CopyMemoryReverseDWORD(btCryptedPass, btCryptedPass, sizeof(btCryptedPass));
- RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, MIR_SHA1_HASH_SIZE);
+ mir_hmac_sha1(bthmacSHA1, (BYTE*)szEmail.c_str(), szEmail.GetLength(), btRandomData, sizeof(btRandomData));
- setDword("pCryptVer", MRA_PASS_CRYPT_VER);
- mraWriteContactSettingBlob(NULL, "pCryptData", btRandomData, sizeof(btRandomData));
- mraWriteContactSettingBlob(NULL, "pCryptPass", btCryptedPass, sizeof(btCryptedPass));
+ RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, MIR_SHA1_HASH_SIZE);
+ RC4(btCryptedPass, sizeof(btCryptedPass), btRandomData, sizeof(btRandomData));
+ CopyMemoryReverseDWORD(btCryptedPass, btCryptedPass, sizeof(btCryptedPass));
+ RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, MIR_SHA1_HASH_SIZE);
- bRet = TRUE;
- }
-#endif
-return(bRet);
+ setDword("pCryptVer", MRA_PASS_CRYPT_VER);
+ mraWriteContactSettingBlob(NULL, "pCryptData", btRandomData, sizeof(btRandomData));
+ mraWriteContactSettingBlob(NULL, "pCryptPass", btCryptedPass, sizeof(btCryptedPass));
+ return true;
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
-
-BOOL CMraProto::GetPassDB(LPSTR lpszBuff, size_t dwBuffSize, size_t *pdwBuffSize)
+bool CMraProto::GetPassDB(CMStringA &res)
{
switch (getDword("pCryptVer", 0)) {
case 1:
MessageBox(NULL, TranslateT("Your password expired. Please reenter password in the Options dialog"), TranslateT("Error"), MB_OK);
- return FALSE;
+ return false;
case 2:
break;
default:
- return FALSE;
+ return false;
}
+ CMStringA szEmail;
BYTE btRandomData[256] = {0}, btCryptedPass[256] = {0}, bthmacSHA1[MIR_SHA1_HASH_SIZE] = {0};
- char szEMail[MAX_EMAIL_LEN] = {0};
- size_t dwRandomDataSize, dwCryptedPass, dwEMailSize, dwPassSize;
+ size_t dwRandomDataSize, dwCryptedPass;
if (mraGetContactSettingBlob(NULL, "pCryptData", btRandomData, sizeof(btRandomData), &dwRandomDataSize))
if (dwRandomDataSize == sizeof(btRandomData))
if (mraGetContactSettingBlob(NULL, "pCryptPass", btCryptedPass, sizeof(btCryptedPass), &dwCryptedPass))
if (dwCryptedPass == sizeof(btCryptedPass))
- if (mraGetStaticStringA(NULL, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize)) {
- mir_hmac_sha1(bthmacSHA1, (BYTE*)szEMail, dwEMailSize, btRandomData, sizeof(btRandomData));
+ if (mraGetStringA(NULL, "e-mail", szEmail)) {
+ mir_hmac_sha1(bthmacSHA1, (BYTE*)szEmail.GetString(), szEmail.GetLength(), btRandomData, sizeof(btRandomData));
RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, MIR_SHA1_HASH_SIZE);
CopyMemoryReverseDWORD(btCryptedPass, btCryptedPass, sizeof(btCryptedPass));
RC4(btCryptedPass, sizeof(btCryptedPass), btRandomData, dwRandomDataSize);
RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, MIR_SHA1_HASH_SIZE);
- dwPassSize = ((*btCryptedPass)&0xff);
+ DWORD dwPassSize = ((*btCryptedPass)&0xff);
SHA1GetDigest(&btCryptedPass[(1+MIR_SHA1_HASH_SIZE)], dwPassSize, btRandomData);
if (MemoryCompare(&btCryptedPass[1], MIR_SHA1_HASH_SIZE, btRandomData, MIR_SHA1_HASH_SIZE) == CMEM_EQUAL)
- if (dwBuffSize >= dwPassSize) {
- memmove(lpszBuff, &btCryptedPass[(1+MIR_SHA1_HASH_SIZE)], dwPassSize);
- (*(lpszBuff+dwPassSize)) = 0;
-
- if (pdwBuffSize) (*pdwBuffSize) = dwPassSize;
- return TRUE;
- }
+ res = CMStringA((char*)&btCryptedPass[(1+MIR_SHA1_HASH_SIZE)], dwPassSize);
+ return true;
}
- return FALSE;
+ return false;
}
-DWORD ReplaceInBuff(LPVOID lpInBuff, size_t dwInBuffSize, size_t dwReplaceItemsCount, LPVOID *plpInReplaceItems, size_t *pdwInReplaceItemsCounts, LPVOID *plpOutReplaceItems, size_t *pdwOutReplaceItemsCounts, LPVOID lpOutBuff, size_t dwOutBuffSize, size_t *pdwOutBuffSize)
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static DWORD ReplaceInBuff(LPVOID lpInBuff, size_t dwInBuffSize, size_t dwReplaceItemsCount, LPVOID *plpInReplaceItems, size_t *pdwInReplaceItemsCounts, LPVOID *plpOutReplaceItems, size_t *pdwOutReplaceItemsCounts, CMStringW &ret)
{
DWORD dwRetErrorCode = NO_ERROR;
- LPBYTE *plpbtFounded;
+
#ifdef _DEBUG //check tables
for (size_t i = 0;i<dwReplaceItemsCount;i++)
{
@@ -1617,14 +1427,14 @@ DWORD ReplaceInBuff(LPVOID lpInBuff, size_t dwInBuffSize, size_t dwReplaceItemsC
}
#endif
- plpbtFounded = (LPBYTE*)mir_calloc((sizeof(LPBYTE)*dwReplaceItemsCount));
+ LPBYTE *plpbtFounded = (LPBYTE*)mir_calloc((sizeof(LPBYTE)*dwReplaceItemsCount));
if (plpbtFounded) {
LPBYTE lpbtOutBuffCur, lpbtInBuffCur, lpbtInBuffCurPrev, lpbtOutBuffMax;
size_t i, dwFirstFoundIndex = 0, dwFoundCount = 0, dwMemPartToCopy;
lpbtInBuffCurPrev = (LPBYTE)lpInBuff;
- lpbtOutBuffCur = (LPBYTE)lpOutBuff;
- lpbtOutBuffMax = (((LPBYTE)lpOutBuff)+dwOutBuffSize);
+ lpbtOutBuffCur = (LPBYTE)ret.GetString();
+ lpbtOutBuffMax = LPBYTE(lpbtOutBuffCur) + ret.GetLength();
for (i = 0; i < dwReplaceItemsCount; i++) {// looking for the first time
plpbtFounded[i] = (LPBYTE)MemoryFind((lpbtInBuffCurPrev-(LPBYTE)lpInBuff), lpInBuff, dwInBuffSize, plpInReplaceItems[i], pdwInReplaceItemsCounts[i]);
if (plpbtFounded[i])
@@ -1668,7 +1478,7 @@ DWORD ReplaceInBuff(LPVOID lpInBuff, size_t dwInBuffSize, size_t dwReplaceItemsC
mir_free(plpbtFounded);
- if (pdwOutBuffSize) (*pdwOutBuffSize) = (lpbtOutBuffCur-((LPBYTE)lpOutBuff));
+ ret.Truncate(lpbtOutBuffCur-((LPBYTE)ret.GetString()));
}
else dwRetErrorCode = GetLastError();
@@ -1681,19 +1491,17 @@ static const LPTSTR lpszXMLSymbols[] = {TEXT("\'"), TEXT("\""), TEXT("&")
static const size_t dwXMLSymbolsCount[] = {sizeof(TCHAR), sizeof(TCHAR), sizeof(TCHAR), sizeof(TCHAR), sizeof(TCHAR)};
//Decode XML coded string. The function translate special xml code into standard characters.
-DWORD DecodeXML(LPTSTR lptszMessage, size_t dwMessageSize, LPTSTR lptszMessageConverted, size_t dwMessageConvertedBuffSize, size_t *pdwMessageConvertedSize)
+CMStringW DecodeXML(const CMStringW &lptszMessage)
{
- DWORD dwRet = ReplaceInBuff(lptszMessage, (dwMessageSize*sizeof(TCHAR)), SIZEOF(lpszXMLTags), (LPVOID*)lpszXMLTags, (size_t*)dwXMLTagsCount, (LPVOID*)lpszXMLSymbols, (size_t*)dwXMLSymbolsCount, lptszMessageConverted, (dwMessageConvertedBuffSize*sizeof(TCHAR)), pdwMessageConvertedSize);
- if (pdwMessageConvertedSize)
- *pdwMessageConvertedSize /= sizeof(TCHAR);
- return dwRet;
+ CMStringW ret('\0', lptszMessage.GetLength());
+ ReplaceInBuff((void*)lptszMessage.GetString(), lptszMessage.GetLength()*sizeof(TCHAR), SIZEOF(lpszXMLTags), (LPVOID*)lpszXMLTags, (size_t*)dwXMLTagsCount, (LPVOID*)lpszXMLSymbols, (size_t*)dwXMLSymbolsCount, ret);
+ return ret;
}
//Encode XML coded string. The function translate special saved xml characters into special characters.
-DWORD EncodeXML(LPTSTR lptszMessage, size_t dwMessageSize, LPTSTR lptszMessageConverted, size_t dwMessageConvertedBuffSize, size_t *pdwMessageConvertedSize)
+CMStringW EncodeXML(const CMStringW &lptszMessage)
{
- DWORD dwRet = ReplaceInBuff(lptszMessage, (dwMessageSize*sizeof(TCHAR)), SIZEOF(lpszXMLTags), (LPVOID*)lpszXMLSymbols, (size_t*)dwXMLSymbolsCount, (LPVOID*)lpszXMLTags, (size_t*)dwXMLTagsCount, lptszMessageConverted, (dwMessageConvertedBuffSize*sizeof(TCHAR)), pdwMessageConvertedSize);
- if (pdwMessageConvertedSize)
- *pdwMessageConvertedSize /= sizeof(TCHAR);
- return dwRet;
+ CMStringW ret;
+ ReplaceInBuff((void*)lptszMessage.GetString(), lptszMessage.GetLength()*sizeof(TCHAR), SIZEOF(lpszXMLTags), (LPVOID*)lpszXMLSymbols, (size_t*)dwXMLSymbolsCount, (LPVOID*)lpszXMLTags, (size_t*)dwXMLTagsCount, ret);
+ return ret;
}
diff --git a/protocols/MRA/src/Mra_options.cpp b/protocols/MRA/src/Mra_options.cpp
index 82b0885e47..e4ae3f5eab 100644
--- a/protocols/MRA/src/Mra_options.cpp
+++ b/protocols/MRA/src/Mra_options.cpp
@@ -3,7 +3,7 @@
INT_PTR CALLBACK DlgProcOptsAccount(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
CMraProto *ppro = (CMraProto*)GetWindowLongPtr(hWndDlg, GWLP_USERDATA);
- WCHAR szBuff[MAX_EMAIL_LEN];
+ CMStringW szBuff;
switch (msg) {
case WM_INITDIALOG:
@@ -11,8 +11,8 @@ INT_PTR CALLBACK DlgProcOptsAccount(HWND hWndDlg, UINT msg, WPARAM wParam, LPARA
SetWindowLongPtr(hWndDlg, GWLP_USERDATA, lParam);
ppro = (CMraProto*)lParam;
- if ( ppro->mraGetStaticStringW(NULL, "e-mail", szBuff, SIZEOF(szBuff), NULL))
- SET_DLG_ITEM_TEXTW(hWndDlg, IDC_LOGIN, szBuff);
+ if ( ppro->mraGetStringW(NULL, "e-mail", szBuff))
+ SET_DLG_ITEM_TEXTW(hWndDlg, IDC_LOGIN, szBuff.c_str());
SET_DLG_ITEM_TEXTW(hWndDlg, IDC_PASSWORD, (LPWSTR)L"");
return TRUE;
@@ -36,11 +36,12 @@ INT_PTR CALLBACK DlgProcOptsAccount(HWND hWndDlg, UINT msg, WPARAM wParam, LPARA
case WM_NOTIFY:
switch (((LPNMHDR)lParam)->code) {
case PSN_APPLY:
+ WCHAR szBuff[MAX_EMAIL_LEN];
GET_DLG_ITEM_TEXT(hWndDlg, IDC_LOGIN, szBuff, SIZEOF(szBuff));
- ppro->mraSetStringW(NULL, "e-mail", szBuff);
+ ppro->setWString(NULL, "e-mail", szBuff);
if (GET_DLG_ITEM_TEXTA(hWndDlg, IDC_PASSWORD, (LPSTR)szBuff, SIZEOF(szBuff))) {
- ppro->SetPassDB((LPSTR)szBuff, lstrlenA((LPSTR)szBuff));
+ ppro->SetPassDB((LPSTR)szBuff);
SecureZeroMemory(szBuff, sizeof(szBuff));
}
return TRUE;
@@ -53,7 +54,7 @@ INT_PTR CALLBACK DlgProcOptsAccount(HWND hWndDlg, UINT msg, WPARAM wParam, LPARA
INT_PTR CALLBACK DlgProcAccount(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
CMraProto *ppro = (CMraProto*)GetWindowLongPtr(hWndDlg, GWLP_USERDATA);
- WCHAR szBuff[MAX_EMAIL_LEN];
+ CMStringW szBuff;
switch (msg) {
case WM_INITDIALOG:
@@ -61,8 +62,8 @@ INT_PTR CALLBACK DlgProcAccount(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lP
SetWindowLongPtr(hWndDlg, GWLP_USERDATA, lParam);
ppro = (CMraProto*)lParam;
- if ( ppro->mraGetStaticStringW(NULL, "e-mail", szBuff, SIZEOF(szBuff), NULL))
- SET_DLG_ITEM_TEXTW(hWndDlg, IDC_LOGIN, szBuff);
+ if ( ppro->mraGetStringW(NULL, "e-mail", szBuff))
+ SET_DLG_ITEM_TEXTW(hWndDlg, IDC_LOGIN, szBuff.c_str());
SET_DLG_ITEM_TEXTW(hWndDlg, IDC_PASSWORD, (LPWSTR)L"");
return TRUE;
@@ -87,11 +88,12 @@ INT_PTR CALLBACK DlgProcAccount(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lP
case WM_NOTIFY:
switch (((LPNMHDR)lParam)->code) {
case PSN_APPLY:
+ WCHAR szBuff[MAX_EMAIL_LEN];
GET_DLG_ITEM_TEXT(hWndDlg, IDC_LOGIN, szBuff, SIZEOF(szBuff));
ppro->mraSetStringW(NULL, "e-mail", szBuff);
if (GET_DLG_ITEM_TEXTA(hWndDlg, IDC_PASSWORD, (LPSTR)szBuff, SIZEOF(szBuff))) {
- ppro->SetPassDB((LPSTR)szBuff, lstrlenA((LPSTR)szBuff));
+ ppro->SetPassDB((LPSTR)szBuff);
SecureZeroMemory(szBuff, sizeof(szBuff));
}
return TRUE;
@@ -104,7 +106,7 @@ INT_PTR CALLBACK DlgProcAccount(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lP
INT_PTR CALLBACK DlgProcOptsConnections(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
CMraProto *ppro = (CMraProto*)GetWindowLongPtr(hWndDlg, GWLP_USERDATA);
- WCHAR szBuff[MAX_PATH];
+ CMStringW szBuff;
switch (msg) {
case WM_INITDIALOG:
@@ -112,8 +114,8 @@ INT_PTR CALLBACK DlgProcOptsConnections(HWND hWndDlg, UINT msg, WPARAM wParam, L
SetWindowLongPtr(hWndDlg, GWLP_USERDATA, lParam);
ppro = (CMraProto*)lParam;
- if (ppro->mraGetStaticStringW(NULL, "Server", szBuff, SIZEOF(szBuff), NULL))
- SET_DLG_ITEM_TEXT(hWndDlg, IDC_SERVER, szBuff);
+ if (ppro->mraGetStringW(NULL, "Server", szBuff))
+ SET_DLG_ITEM_TEXT(hWndDlg, IDC_SERVER, szBuff.c_str());
else
SET_DLG_ITEM_TEXTA(hWndDlg, IDC_SERVER, MRA_DEFAULT_SERVER);
@@ -191,6 +193,7 @@ INT_PTR CALLBACK DlgProcOptsConnections(HWND hWndDlg, UINT msg, WPARAM wParam, L
case WM_NOTIFY:
switch (((LPNMHDR)lParam)->code) {
case PSN_APPLY:
+ WCHAR szBuff[MAX_PATH];
GET_DLG_ITEM_TEXT(hWndDlg, IDC_SERVER, szBuff, SIZEOF(szBuff));
ppro->mraSetStringW(NULL, "Server", szBuff);
ppro->setWord("ServerPort", (WORD)GetDlgItemInt(hWndDlg, IDC_SERVERPORT, NULL, FALSE));
diff --git a/protocols/MRA/src/Mra_proto.cpp b/protocols/MRA/src/Mra_proto.cpp
index 08f933154d..d9bbd00642 100644
--- a/protocols/MRA/src/Mra_proto.cpp
+++ b/protocols/MRA/src/Mra_proto.cpp
@@ -3,41 +3,34 @@
#include "MraRTFMsg.h"
#include "MraPlaces.h"
-DWORD GetUL(LPBYTE *plpData);
-DWORDLONG GetUIDL(LPBYTE *plpData);
-MRA_GUID GetGUID(LPBYTE *plpData);
-DWORD GetLPS(LPBYTE lpbData, DWORD dwDataSize, LPBYTE *plpCurrentData, MRA_LPS *plpsString);
-
DWORD CMraProto::StartConnect()
{
if ( !InterlockedExchangeAdd((volatile LONG*)&masMraSettings.dwGlobalPluginRunning, 0))
return ERROR_OPERATION_ABORTED;
// поток ещё/уже не работал, поставили статус что работает и запускаем
- if (InterlockedCompareExchange((volatile LONG*)&dwThreadWorkerRunning, TRUE, FALSE) == FALSE) {
- char szPass[MAX_PATH];
- size_t dwEMailSize = 0, dwPasswordSize = 0;
-
- mraGetStaticStringA(NULL, "e-mail", NULL, 0, &dwEMailSize);
-
- if (dwEMailSize > 5 && GetPassDB(szPass, sizeof(szPass), &dwPasswordSize)) {
- InterlockedExchange((volatile LONG*)&dwThreadWorkerLastPingTime, GetTickCount());
- hThreadWorker = ForkThreadEx(&CMraProto::MraThreadProc, NULL, 0);
- if (hThreadWorker == NULL) {
+ if (InterlockedCompareExchange((volatile LONG*)&m_dwThreadWorkerRunning, TRUE, FALSE) == FALSE) {
+ CMStringA szEmail;
+ mraGetStringA(NULL, "e-mail", szEmail);
+
+ CMStringA szPass;
+ if (szEmail.GetLength() > 5 && GetPassDB(szPass)) {
+ InterlockedExchange((volatile LONG*)&m_dwThreadWorkerLastPingTime, GetTickCount());
+ m_hThreadWorker = ForkThreadEx(&CMraProto::MraThreadProc, NULL, 0);
+ if (m_hThreadWorker == NULL) {
DWORD dwRetErrorCode = GetLastError();
- InterlockedExchange((volatile LONG*)&dwThreadWorkerRunning, FALSE);
+ InterlockedExchange((volatile LONG*)&m_dwThreadWorkerRunning, FALSE);
SetStatus(ID_STATUS_OFFLINE);
return dwRetErrorCode;
}
}
else {
MraThreadClean();
- if (dwEMailSize <= 5)
+ if (szEmail.GetLength() <= 5)
MraPopupShowFromAgentW(MRA_POPUP_TYPE_WARNING, 0, TranslateW(L"Please, setup e-mail in options"));
else
MraPopupShowFromAgentW(MRA_POPUP_TYPE_WARNING, 0, TranslateW(L"Please, setup password in options"));
}
- SecureZeroMemory(szPass, sizeof(szPass));
}
return 0;
@@ -48,7 +41,7 @@ void CMraProto::MraThreadProc(LPVOID lpParameter)
DWORD dwRetErrorCode = NO_ERROR;
BOOL bConnected = FALSE;
- char szHost[MAX_PATH];
+ CMStringA szHost;
DWORD dwConnectReTryCount, dwCurConnectReTryCount;
NETLIBOPENCONNECTION nloc = {0};
@@ -58,27 +51,27 @@ void CMraProto::MraThreadProc(LPVOID lpParameter)
nloc.cbSize = sizeof(nloc);
nloc.flags = NLOCF_V2;
- nloc.szHost = szHost;
nloc.timeout = getDword("TimeOutConnectMRIM", MRA_DEFAULT_TIMEOUT_CONN_MRIM);
if (nloc.timeout<MRA_TIMEOUT_CONN_MIN) nloc.timeout = MRA_TIMEOUT_CONN_MIN;
if (nloc.timeout>MRA_TIMEOUT_CONN_МАХ) nloc.timeout = MRA_TIMEOUT_CONN_МАХ;
- InterlockedExchange((volatile LONG*)&dwThreadWorkerLastPingTime, GetTickCount());
- if (MraGetNLBData((LPSTR)nloc.szHost, MAX_PATH, &nloc.wPort) == NO_ERROR) {
+ InterlockedExchange((volatile LONG*)&m_dwThreadWorkerLastPingTime, GetTickCount());
+ if (MraGetNLBData(szHost, &nloc.wPort) == NO_ERROR) {
+ nloc.szHost = szHost;
dwCurConnectReTryCount = dwConnectReTryCount;
do {
- InterlockedExchange((volatile LONG*)&dwThreadWorkerLastPingTime, GetTickCount());
- hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)hNetlibUser, (LPARAM)&nloc);
+ InterlockedExchange((volatile LONG*)&m_dwThreadWorkerLastPingTime, GetTickCount());
+ m_hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc);
}
- while (--dwCurConnectReTryCount && hConnection == NULL);
+ while (--dwCurConnectReTryCount && m_hConnection == NULL);
- if (hConnection)
+ if (m_hConnection)
bConnected = TRUE;
}
if (bConnected == FALSE)
if (getByte("NLBFailDirectConnect", MRA_DEFAULT_NLB_FAIL_DIRECT_CONNECT)) {
- if (IsHTTPSProxyUsed(hNetlibUser))
+ if (IsHTTPSProxyUsed(m_hNetlibUser))
nloc.wPort = MRA_SERVER_PORT_HTTPS;
else {
nloc.wPort = getWord("ServerPort", MRA_DEFAULT_SERVER_PORT);
@@ -86,16 +79,16 @@ void CMraProto::MraThreadProc(LPVOID lpParameter)
}
for (DWORD i = 1;(i<MRA_MAX_MRIM_SERVER && m_iStatus != ID_STATUS_OFFLINE); i++) {
- mir_snprintf(szHost, SIZEOF(szHost), "mrim%lu.mail.ru", i);
+ szHost.Format("mrim%lu.mail.ru", i);
dwCurConnectReTryCount = dwConnectReTryCount;
do {
- InterlockedExchange((volatile LONG*)&dwThreadWorkerLastPingTime, GetTickCount());
- hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)hNetlibUser, (LPARAM)&nloc);
+ InterlockedExchange((volatile LONG*)&m_dwThreadWorkerLastPingTime, GetTickCount());
+ m_hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc);
}
- while (--dwCurConnectReTryCount && hConnection == NULL);
+ while (--dwCurConnectReTryCount && m_hConnection == NULL);
- if (hConnection) {
+ if (m_hConnection) {
bConnected = TRUE;
break;
}
@@ -117,21 +110,21 @@ void CMraProto::MraThreadProc(LPVOID lpParameter)
void CMraProto::MraThreadClean()
{
MraMPopSessionQueueFlush(hMPopSessionQueue);
- Netlib_CloseHandle(hConnection);// called twice, if user set offline, its normal
- hConnection = NULL;
+ Netlib_CloseHandle(m_hConnection);// called twice, if user set offline, its normal
+ m_hConnection = NULL;
dwCMDNum = 0;
SleepEx(100, FALSE);// to prevent high CPU load by some status plugins like allwaysonline
- if (hThreadWorker) {
- CloseHandle(hThreadWorker);
- hThreadWorker = NULL;
+ if (m_hThreadWorker) {
+ CloseHandle(m_hThreadWorker);
+ m_hThreadWorker = NULL;
}
- InterlockedExchange((volatile LONG*)&dwThreadWorkerRunning, FALSE);
+ InterlockedExchange((volatile LONG*)&m_dwThreadWorkerRunning, FALSE);
SetStatus(ID_STATUS_OFFLINE);
}
-DWORD CMraProto::MraGetNLBData(LPSTR lpszHost, size_t dwHostBuffSize, WORD *pwPort)
+DWORD CMraProto::MraGetNLBData(CMStringA &szHost, WORD *pwPort)
{
DWORD dwRetErrorCode;
@@ -147,12 +140,12 @@ DWORD CMraProto::MraGetNLBData(LPSTR lpszHost, size_t dwHostBuffSize, WORD *pwPo
nloc.cbSize = sizeof(nloc);
nloc.flags = NLOCF_V2;
- if (mraGetStaticStringA(NULL, "Server", (LPSTR)btBuff, SIZEOF(btBuff), NULL))
- nloc.szHost = (LPSTR)btBuff;
+ if (mraGetStringA(NULL, "Server", szHost))
+ nloc.szHost = szHost;
else
nloc.szHost = MRA_DEFAULT_SERVER;
- if ( IsHTTPSProxyUsed(hNetlibUser))
+ if ( IsHTTPSProxyUsed(m_hNetlibUser))
nloc.wPort = MRA_SERVER_PORT_HTTPS;
else
nloc.wPort = getWord("ServerPort", MRA_DEFAULT_SERVER_PORT);
@@ -163,15 +156,15 @@ DWORD CMraProto::MraGetNLBData(LPSTR lpszHost, size_t dwHostBuffSize, WORD *pwPo
dwCurConnectReTryCount = dwConnectReTryCount;
do {
- InterlockedExchange((volatile LONG*)&dwThreadWorkerLastPingTime, GetTickCount());
- nls.hReadConns[0] = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)hNetlibUser, (LPARAM)&nloc);
+ 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);
if (nls.hReadConns[0]) {
nls.cbSize = sizeof(nls);
nls.dwTimeout = 1000 * getDword("TimeOutReceiveNLB", MRA_DEFAULT_TIMEOUT_RECV_NLB);
- InterlockedExchange((volatile LONG*)&dwThreadWorkerLastPingTime, GetTickCount());
+ InterlockedExchange((volatile LONG*)&m_dwThreadWorkerLastPingTime, GetTickCount());
while (m_iStatus != ID_STATUS_OFFLINE && bContinue) {
switch (CallService(MS_NETLIB_SELECT, 0, (LPARAM)&nls)) {
@@ -187,7 +180,7 @@ DWORD CMraProto::MraGetNLBData(LPSTR lpszHost, size_t dwHostBuffSize, WORD *pwPo
bContinue = FALSE;
break;
}
- InterlockedExchange((volatile LONG*)&dwThreadWorkerLastPingTime, GetTickCount());
+ InterlockedExchange((volatile LONG*)&m_dwThreadWorkerLastPingTime, GetTickCount());
}
Netlib_CloseHandle(nls.hReadConns[0]);
@@ -197,7 +190,7 @@ DWORD CMraProto::MraGetNLBData(LPSTR lpszHost, size_t dwHostBuffSize, WORD *pwPo
(*lpszPort) = 0;
lpszPort++;
- lstrcpynA(lpszHost, (LPSTR)btBuff, dwHostBuffSize);
+ szHost = (LPSTR)btBuff;
if (pwPort) (*pwPort) = (WORD)StrToUNum32(lpszPort, (dwRcvBuffSizeUsed-(lpszPort-(LPSTR)btBuff)));
dwRetErrorCode = NO_ERROR;
}
@@ -223,25 +216,24 @@ DWORD CMraProto::MraNetworkDispatcher()
{
DWORD dwRetErrorCode = NO_ERROR;
- BOOL bContinue = TRUE;
- DWORD dwSelectRet, dwBytesReceived, dwDataCurrentBuffSize, dwDataCurrentBuffSizeUsed, dwPingPeriod = MAXDWORD, dwNextPingSendTickTime = MAXDWORD;
+ bool bContinue = true;
+ DWORD dwDataCurrentBuffSize, dwDataCurrentBuffSizeUsed;
size_t dwRcvBuffSize = BUFF_SIZE_RCV, dwRcvBuffSizeUsed = 0, dwDataCurrentBuffOffset = 0;
LPBYTE lpbBufferRcv;
mrim_packet_header_t *pmaHeader;
- NETLIBSELECT nls = {0};
- nls.cbSize = sizeof(nls);
+ NETLIBSELECT nls = { sizeof(nls) };
nls.dwTimeout = NETLIB_SELECT_TIMEOUT;
- nls.hReadConns[0] = hConnection;
+ nls.hReadConns[0] = m_hConnection;
lpbBufferRcv = (LPBYTE)mir_calloc(dwRcvBuffSize);
+ m_dwNextPingSendTickTime = m_dwPingPeriod = MAXDWORD;
dwCMDNum = 0;
MraSendCMD(MRIM_CS_HELLO, NULL, 0);
- InterlockedExchange((volatile LONG*)&dwThreadWorkerLastPingTime, GetTickCount());
- while (m_iStatus != ID_STATUS_OFFLINE && bContinue)
- {
- dwSelectRet = CallService(MS_NETLIB_SELECT, 0, (LPARAM)&nls);
+ m_dwThreadWorkerLastPingTime = GetTickCount();
+ while (m_iStatus != ID_STATUS_OFFLINE && bContinue) {
+ DWORD dwSelectRet = CallService(MS_NETLIB_SELECT, 0, (LPARAM)&nls);
switch (dwSelectRet) {
case SOCKET_ERROR:
if (m_iStatus != ID_STATUS_OFFLINE) {
@@ -253,11 +245,10 @@ DWORD CMraProto::MraNetworkDispatcher()
case 0:// Time out
case 1:
- dwBytesReceived = GetTickCount();
- InterlockedExchange((volatile LONG*)&dwThreadWorkerLastPingTime, dwBytesReceived);
+ m_dwThreadWorkerLastPingTime = GetTickCount();
// server ping
- if (dwNextPingSendTickTime <= dwBytesReceived) {
- dwNextPingSendTickTime = (dwBytesReceived+(dwPingPeriod*1000));
+ if (m_dwNextPingSendTickTime <= m_dwThreadWorkerLastPingTime) {
+ m_dwNextPingSendTickTime = (m_dwThreadWorkerLastPingTime+(m_dwPingPeriod*1000));
MraSendCMD(MRIM_CS_PING, NULL, 0);
}
{
@@ -298,7 +289,7 @@ DWORD CMraProto::MraNetworkDispatcher()
lpbBufferRcv = (LPBYTE)mir_realloc(lpbBufferRcv, dwRcvBuffSize);
}
- dwBytesReceived = Netlib_Recv(nls.hReadConns[0], (LPSTR)(lpbBufferRcv+dwRcvBuffSizeUsed), (dwRcvBuffSize-dwRcvBuffSizeUsed), 0);
+ DWORD dwBytesReceived = Netlib_Recv(nls.hReadConns[0], (LPSTR)(lpbBufferRcv+dwRcvBuffSizeUsed), (dwRcvBuffSize-dwRcvBuffSizeUsed), 0);
if (dwBytesReceived && dwBytesReceived != SOCKET_ERROR) {
dwRcvBuffSizeUsed += dwBytesReceived;
@@ -314,7 +305,7 @@ DWORD CMraProto::MraNetworkDispatcher()
// full packet received, may be more than one
if ((dwDataCurrentBuffSizeUsed-sizeof(mrim_packet_header_t)) >= pmaHeader->dlen) {
- MraCommandDispatcher(pmaHeader, &dwPingPeriod, &dwNextPingSendTickTime, &bContinue);
+ bContinue = MraCommandDispatcher(pmaHeader);
// move pointer to next packet in buffer
if (dwDataCurrentBuffSizeUsed - sizeof(mrim_packet_header_t) > pmaHeader->dlen)
@@ -376,1341 +367,1235 @@ DWORD CMraProto::MraNetworkDispatcher()
return dwRetErrorCode;
}
-DWORD CMraProto::MraCommandDispatcher(mrim_packet_header_t *pmaHeader, DWORD *pdwPingPeriod, DWORD *pdwNextPingSendTickTime, BOOL *pbContinue)
+//Подтверждение установки соединения// UL ## ping_period ## Ожидаемая частота подтверждения соединения (в секундах)
+bool CMraProto::CmdHelloAck(BinBuffer &buf)
{
- WCHAR szBuff[4096] = {0};
- DWORD dwDataSize, dwTemp, dwAckType;
- size_t dwStringSize;
- MRA_LPS lpsString = {0}, lpsEMail = {0};
- HANDLE hContact = NULL;
- LPBYTE lpbData, lpbDataCurrent;
+ buf >> m_dwPingPeriod;
- lpbData = ((((LPBYTE)pmaHeader))+sizeof(mrim_packet_header_t));
- lpbDataCurrent = lpbData;
- dwDataSize = pmaHeader->dlen;
+ CMStringA szPass;
+ if ( !GetPassDB(szPass))
+ return false;
- Netlib_Logf(hNetlibUser, "Received packet %x\n", pmaHeader->msg);
+ char szValueName[MAX_PATH];
+ CMStringA szUserAgentFormatted, szEmail;
+ CMStringW wszStatusTitle, wszStatusDesc;
- switch (pmaHeader->msg) {
- case MRIM_CS_HELLO_ACK://Подтверждение установки соединения// UL ## ping_period ## Ожидаемая частота подтверждения соединения (в секундах)
- //bit of a security hole here, since it's easy to extract a password from an edit box
- if (GetPassDB((LPSTR)szBuff, SIZEOF(szBuff), &dwStringSize)) {
- CHAR szEMail[MAX_EMAIL_LEN], szSelfVersionString[MAX_PATH], szUserAgentFormated[USER_AGENT_MAX+MAX_PATH], szValueName[MAX_PATH];
- WCHAR wszStatusTitle[STATUS_TITLE_MAX+4], wszStatusDesc[STATUS_DESC_MAX+4];
- DWORD dwStatus, dwXStatus, dwXStatusMir, dwFutureFlags;
- LPWSTR lpwszStatusTitle, lpwszStatusDesc;
- size_t dwEMailSize, dwSelfVersionSize, dwStatusTitleSize, dwStatusDescSize, dwUserAgentFormattedSize;
-
- dwXStatusMir = m_iXStatus;
- dwStatus = GetMraStatusFromMiradaStatus(m_iDesiredStatus, dwXStatusMir, &dwXStatus);
- if ( IsXStatusValid(dwXStatusMir)) {// xstatuses
- mir_snprintf(szValueName, SIZEOF(szValueName), "XStatus%ldName", dwXStatusMir);
- if (mraGetStaticStringW(NULL, szValueName, wszStatusTitle, (STATUS_TITLE_MAX+1), &dwStatusTitleSize))
- lpwszStatusTitle = wszStatusTitle;
- else { // default xstatus name
- lpwszStatusTitle = TranslateW(lpcszXStatusNameDef[dwXStatusMir]);
- dwStatusTitleSize = lstrlenW(lpwszStatusTitle);
- }
+ DWORD dwXStatusMir = m_iXStatus, dwXStatus;
+ DWORD dwStatus = GetMraStatusFromMiradaStatus(m_iDesiredStatus, dwXStatusMir, &dwXStatus);
+ if ( IsXStatusValid(dwXStatusMir)) {// xstatuses
+ mir_snprintf(szValueName, SIZEOF(szValueName), "XStatus%ldName", dwXStatusMir);
+ if ( !mraGetStringW(NULL, szValueName, wszStatusTitle))
+ wszStatusTitle = TranslateW(lpcszXStatusNameDef[dwXStatusMir]);
- mir_snprintf(szValueName, SIZEOF(szValueName), "XStatus%ldMsg", dwXStatusMir);
- if (mraGetStaticStringW(NULL, szValueName, wszStatusDesc, (STATUS_DESC_MAX+1), &dwStatusDescSize))
- lpwszStatusDesc = wszStatusDesc;
- else { // default xstatus description
- lpwszStatusDesc = NULL;
- dwStatusDescSize = 0;
- }
- }
- else { // not xstatuses
- lpwszStatusTitle = GetStatusModeDescriptionW(m_iDesiredStatus);
- dwStatusTitleSize = lstrlenW(lpwszStatusTitle);
- lpwszStatusDesc = NULL;
- dwStatusDescSize = 0;
- }
+ mir_snprintf(szValueName, SIZEOF(szValueName), "XStatus%ldMsg", dwXStatusMir);
+ mraGetStringW(NULL, szValueName, wszStatusDesc);
+ }
+ else wszStatusTitle = GetStatusModeDescriptionW(m_iDesiredStatus);
- MraGetSelfVersionString(szSelfVersionString, SIZEOF(szSelfVersionString), &dwSelfVersionSize);
- if ( mraGetStaticStringA(NULL, "MirVerCustom", szUserAgentFormated, SIZEOF(szUserAgentFormated), &dwUserAgentFormattedSize) == FALSE) {
- dwUserAgentFormattedSize = mir_snprintf(szUserAgentFormated, SIZEOF(szUserAgentFormated),
- "client=\"magent\" name=\"Miranda NG\" title=\"%s\" version=\"777.%lu.%lu.%lu\" build=\"%lu\" protocol=\"%lu.%lu\"",
- szSelfVersionString, __FILEVERSION_STRING, PROTO_VERSION_MAJOR, PROTO_VERSION_MINOR);
- }
+ CMStringA szSelfVersionString = MraGetSelfVersionString();
+ if ( !mraGetStringA(NULL, "MirVerCustom", szUserAgentFormatted))
+ szUserAgentFormatted.Format(
+ "client=\"magent\" name=\"Miranda NG\" title=\"%s\" version=\"777.%lu.%lu.%lu\" build=\"%lu\" protocol=\"%lu.%lu\"",
+ szSelfVersionString, __FILEVERSION_STRING, PROTO_VERSION_MAJOR, PROTO_VERSION_MINOR);
- dwFutureFlags = ((getByte("RTFReceiveEnable", MRA_DEFAULT_RTF_RECEIVE_ENABLE)? FEATURE_FLAG_RTF_MESSAGE:0)|MRA_FEATURE_FLAGS);
+ DWORD dwFutureFlags = (getByte("RTFReceiveEnable", MRA_DEFAULT_RTF_RECEIVE_ENABLE) ? FEATURE_FLAG_RTF_MESSAGE : 0) | MRA_FEATURE_FLAGS;
- if (mraGetStaticStringA(NULL, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize))
- MraLogin2W(szEMail, dwEMailSize, (LPSTR)szBuff, dwStringSize, dwStatus, lpcszStatusUri[dwXStatus], lstrlenA(lpcszStatusUri[dwXStatus]), lpwszStatusTitle, dwStatusTitleSize, lpwszStatusDesc, dwStatusDescSize, dwFutureFlags, szUserAgentFormated, dwUserAgentFormattedSize, szSelfVersionString, dwSelfVersionSize);
- else
- *pbContinue = FALSE;
+ if ( !mraGetStringA(NULL, "e-mail", szEmail))
+ return false;
- SecureZeroMemory(szBuff, sizeof(szBuff));
- }
- else *pbContinue = FALSE;
+ MraLogin2W(szEmail, szPass, dwStatus, CMStringA(lpcszStatusUri[dwXStatus]), wszStatusTitle, wszStatusDesc, dwFutureFlags, szUserAgentFormatted, szSelfVersionString);
+ return true;
+}
- *pdwPingPeriod = GetUL(&lpbDataCurrent);
- break;
+// Successful authorization
+bool CMraProto::CmdLoginAck()
+{
+ m_bLoggedIn = TRUE;
+ m_dwNextPingSendTickTime = 0; // force send ping
+ MraSendCMD(MRIM_CS_PING, NULL, 0);
+ SetStatus(m_iDesiredStatus);
+ MraAvatarsQueueGetAvatarSimple(hAvatarsQueueHandle, GAIF_FORCE, NULL, 0);
+ return true;
+}
- case MRIM_CS_LOGIN_ACK: // Successful authorization
- m_bLoggedIn = TRUE;
- *pdwNextPingSendTickTime = 0; // force send ping
- MraSendCMD(MRIM_CS_PING, NULL, 0);
- SetStatus(m_iDesiredStatus);
- MraAvatarsQueueGetAvatarSimple(hAvatarsQueueHandle, GAIF_FORCE, NULL, 0);
- break;
+// Unsuccessful authorization //LPS ## reason ## причина отказа
+bool CMraProto::CmdLoginRejected(BinBuffer &buf)
+{
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_WRONGPASSWORD);
- case MRIM_CS_LOGIN_REJ: // Unsuccessful authorization //LPS ## reason ## причина отказа
- ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_WRONGPASSWORD);
+ CMStringA reason; buf >> reason;
+ MraPopupShowW(NULL, MRA_POPUP_TYPE_ERROR, 0, TranslateW(L"Logon error: invalid login/password"), _A2T(reason.c_str()));
+ return false;
+}
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- dwStringSize = MultiByteToWideChar(MRA_CODE_PAGE, 0, lpsString.lpszData, lpsString.dwSize, szBuff, SIZEOF(szBuff));
- szBuff[dwStringSize] = 0;
- MraPopupShowW(NULL, MRA_POPUP_TYPE_ERROR, 0, TranslateW(L"Logon error: invalid login/password"), szBuff);
- *pbContinue = FALSE;
- break;
+// Message delivery
+//LPS ## from ## Адрес отправителя
+//LPS ## message ## текстовая версия сообщения
+//LPS ## rtf-message ## форматированная версия сообщения
+bool CMraProto::CmdMessageAck(BinBuffer &buf)
+{
+ DWORD dwMsgID, dwFlags;
+ CMStringA szEmail, szText, szRTFText, szMultiChatData;
+ buf >> dwMsgID >> dwFlags >> szEmail >> szText >> szRTFText;
+ if (dwFlags & MESSAGE_FLAG_MULTICHAT)
+ buf >> szMultiChatData; // LPS multichat_data
+
+ // подтверждаем получение, только если удалось его обработать
+ if (MraRecvCommand_Message((DWORD)_time32(NULL), dwFlags, szEmail, szText, szRTFText, szMultiChatData) == NO_ERROR)
+ if ((dwFlags & MESSAGE_FLAG_NORECV) == 0)
+ MraMessageRecv(szEmail, dwMsgID);
+ return true;
+}
- case MRIM_CS_MESSAGE_ACK:// Message delivery
- {
- DWORD dwMsgID, dwFlags;
- MRA_LPS lpsText, lpsRTFText, lpsMultiChatData;
-
- dwMsgID = GetUL(&lpbDataCurrent);
- dwFlags = GetUL(&lpbDataCurrent);
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsEMail);//LPS ## from ## Адрес отправителя
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsText);//LPS ## message ## текстовая версия сообщения
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsRTFText);//LPS ## rtf-message ## форматированная версия сообщения
- if (dwFlags&MESSAGE_FLAG_MULTICHAT) GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsMultiChatData); // LPS multichat_data
-
- // подтверждаем получение, только если удалось его обработать
- if (MraRecvCommand_Message((DWORD)_time32(NULL), dwFlags, &lpsEMail, &lpsText, &lpsRTFText, &lpsMultiChatData) == NO_ERROR)
- if ((dwFlags&MESSAGE_FLAG_NORECV) == 0)
- MraMessageRecv(lpsEMail.lpszData, lpsEMail.dwSize, dwMsgID);
+bool CMraProto::CmdMessageStatus(ULONG seq, BinBuffer &buf)
+{
+ DWORD dwAckType, dwTemp; buf >> dwTemp;
+ HANDLE hContact;
+ if ( !MraSendQueueFind(hSendQueueHandle, seq, NULL, &hContact, &dwAckType, NULL, NULL)) {
+ switch (dwTemp) {
+ case MESSAGE_DELIVERED:// Message delivered directly to user
+ ProtoBroadcastAckAsync(hContact, dwAckType, ACKRESULT_SUCCESS, (HANDLE)seq, 0);
+ break;//***deb возможны сбои из-за асинхронности тк там передаётся указатель
+ case MESSAGE_REJECTED_NOUSER:// Message rejected - no such user
+ ProtoBroadcastAck(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)seq, (LPARAM)"Message rejected - no such user");
+ break;
+ case MESSAGE_REJECTED_INTERR:// Internal server error
+ ProtoBroadcastAck(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)seq, (LPARAM)"Internal server error");
+ break;
+ case MESSAGE_REJECTED_LIMIT_EXCEEDED:// Offline messages limit exceeded
+ ProtoBroadcastAck(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)seq, (LPARAM)"Offline messages limit exceeded");
+ break;
+ case MESSAGE_REJECTED_TOO_LARGE:// Message is too large
+ ProtoBroadcastAck(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)seq, (LPARAM)"Message is too large");
+ break;
+ case MESSAGE_REJECTED_DENY_OFFMSG:// User does not accept offline messages
+ ProtoBroadcastAck(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)seq, (LPARAM)"User does not accept offline messages");
+ break;
+ case MESSAGE_REJECTED_DENY_OFFFLSH:// User does not accept offline flash animation
+ ProtoBroadcastAck(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)seq, (LPARAM)"User does not accept offline flash animation");
+ break;
+ default:
+ CMStringA szMsg;
+ szMsg.Format("Undefined message delivery error, code: %lu", dwTemp);
+ ProtoBroadcastAck(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)seq, (LPARAM)szMsg.c_str());
+ break;
}
- break;
+ MraSendQueueFree(hSendQueueHandle, seq);
+ }
+ // not found in queue
+ else if (dwTemp != MESSAGE_DELIVERED)
+ MraPopupShowFromAgentW(MRA_POPUP_TYPE_DEBUG, 0, TranslateW(L"MRIM_CS_MESSAGE_STATUS: not found in queue"));
+ return true;
+}
- case MRIM_CS_MESSAGE_STATUS:
- 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
- ProtoBroadcastAckAsync(hContact, dwAckType, ACKRESULT_SUCCESS, (HANDLE)pmaHeader->seq, 0);
- break;//***deb возможны сбои из-за асинхронности тк там передаётся указатель
- case MESSAGE_REJECTED_NOUSER:// Message rejected - no such user
- ProtoBroadcastAck(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)pmaHeader->seq, (LPARAM)"Message rejected - no such user");
- break;
- case MESSAGE_REJECTED_INTERR:// Internal server error
- ProtoBroadcastAck(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)pmaHeader->seq, (LPARAM)"Internal server error");
- break;
- case MESSAGE_REJECTED_LIMIT_EXCEEDED:// Offline messages limit exceeded
- ProtoBroadcastAck(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)pmaHeader->seq, (LPARAM)"Offline messages limit exceeded");
- break;
- case MESSAGE_REJECTED_TOO_LARGE:// Message is too large
- ProtoBroadcastAck(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)pmaHeader->seq, (LPARAM)"Message is too large");
- break;
- case MESSAGE_REJECTED_DENY_OFFMSG:// User does not accept offline messages
- ProtoBroadcastAck(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
- ProtoBroadcastAck(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 delivery error, code: %lu", dwTemp);
- ProtoBroadcastAck(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)pmaHeader->seq, (LPARAM)szBuff);
- break;
- }
- MraSendQueueFree(hSendQueueHandle, pmaHeader->seq);
+bool CMraProto::CmdUserInfo(BinBuffer &buf)
+{
+ CMStringA szString;
+ CMStringW szStringW;
+ while (buf.m_len > 0) {
+ buf >> szString;
+ if ( !_strnicmp(szString, "MESSAGES.TOTAL", 14)) {
+ buf >> szString;
+ dwEmailMessagesTotal = atoi(szString);
}
- // not found in queue
- else if ( GetUL(&lpbDataCurrent) != MESSAGE_DELIVERED)
- MraPopupShowFromAgentW(MRA_POPUP_TYPE_DEBUG, 0, TranslateW(L"MRIM_CS_MESSAGE_STATUS: not found in queue"));
- break;
-
- case MRIM_CS_CONNECTION_PARAMS:// Изменение параметров соединения
- *pdwPingPeriod = GetUL(&lpbDataCurrent);
- *pdwNextPingSendTickTime = 0; // force send ping
- MraSendCMD(MRIM_CS_PING, NULL, 0);
- break;
-
- case MRIM_CS_USER_INFO:
- while (lpbDataCurrent < lpbData + dwDataSize) {
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- if ( !_strnicmp(lpsString.lpszData, "MESSAGES.TOTAL", 14)) {
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- dwEmailMessagesTotal = StrToUNum32(lpsString.lpszData, lpsString.dwSize);
- }
- else if ( !_strnicmp(lpsString.lpszData, "MESSAGES.UNREAD", 15)) {
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- dwEmailMessagesUnread = StrToUNum32(lpsString.lpszData, lpsString.dwSize);
- }
- else if ( !_strnicmp(lpsString.lpszData, "MRIM.NICKNAME", 13)) {
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- mraSetLPSStringW(NULL, "Nick", &lpsString);
- }
- else if ( !_strnicmp(lpsString.lpszData, "client.endpoint", 15)) {
- LPSTR lpszDelimiter;
-
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- dwStringSize = WideCharToMultiByte(MRA_CODE_PAGE, 0, lpsString.lpwszData, lpsString.dwSize, (LPSTR)szBuff, sizeof(szBuff), NULL, NULL);
- lpszDelimiter = (LPSTR)MemoryFind(0, szBuff, dwStringSize, ":", 1);
- if (lpszDelimiter) {
- (*lpszDelimiter) = 0;
- lpszDelimiter = (LPSTR)szBuff;
- setDword("IP", HTONL(inet_addr(lpszDelimiter)));
- }
- }
- else if ( !_strnicmp(lpsString.lpszData, "connect.xml", 11)) {
- DebugPrintA(lpsString.lpszData);
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- DebugPrintCRLFW(lpsString.lpwszData);
- }
- else if ( !_strnicmp(lpsString.lpszData, "micblog.show_title", 18)) {
- DebugPrintA(lpsString.lpszData);
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- DebugPrintCRLFW(lpsString.lpwszData);
- }
- else if ( !_strnicmp(lpsString.lpszData, "micblog.status.id", 17)) {
- DWORDLONG dwBlogStatusID;
-
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- dwBlogStatusID = StrToUNum64(lpsString.lpszData, lpsString.dwSize);
- mraWriteContactSettingBlob(NULL, DBSETTING_BLOGSTATUSID, &dwBlogStatusID, sizeof(DWORDLONG));
- }
- else if ( !_strnicmp(lpsString.lpszData, "micblog.status.time", 19)) {
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- setDword(DBSETTING_BLOGSTATUSTIME, StrToUNum32(lpsString.lpszData, lpsString.dwSize));
- }
- else if ( !_strnicmp(lpsString.lpszData, "micblog.status.text", 19)) {
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- mraSetLPSStringW(NULL, DBSETTING_BLOGSTATUS, &lpsString);
- }
- else if ( !_strnicmp(lpsString.lpszData, "HAS_MYMAIL", 10)) {
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- //setDword(DBSETTING_BLOGSTATUSTIME, StrToUNum32(lpsString.lpszData, lpsString.dwSize));
- }
- else if ( !_strnicmp(lpsString.lpszData, "mrim.status.open_search", 23)) {
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- //setDword(DBSETTING_BLOGSTATUSTIME, StrToUNum32(lpsString.lpszData, lpsString.dwSize));
- }
- else if ( !_strnicmp(lpsString.lpszData, "rb.target.cookie", 16)) {
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- //setDword(DBSETTING_BLOGSTATUSTIME, StrToUNum32(lpsString.lpszData, lpsString.dwSize));
- }
- else if ( !_strnicmp(lpsString.lpszData, "show_web_history_link", 21)) {
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- //setDword(DBSETTING_BLOGSTATUSTIME, StrToUNum32(lpsString.lpszData, lpsString.dwSize));
- }
- else if ( !_strnicmp(lpsString.lpszData, "friends_suggest", 15)) {
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- //setDword(DBSETTING_BLOGSTATUSTIME, StrToUNum32(lpsString.lpszData, lpsString.dwSize));
- }
- else if ( !_strnicmp(lpsString.lpszData, "timestamp", 9)) {
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- //setDword(DBSETTING_BLOGSTATUSTIME, StrToUNum32(lpsString.lpszData, lpsString.dwSize));
- }
- else if ( !_strnicmp(lpsString.lpszData, "trusted_update", 14)) {
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- //setDword(DBSETTING_BLOGSTATUSTIME, StrToUNum32(lpsString.lpszData, lpsString.dwSize));
- }
- else {
- #ifdef _DEBUG
- LPSTR lpszCurrentPos = (LPSTR)szBuff;
- memmove(lpszCurrentPos, lpsString.lpszData, lpsString.dwSize);
- lpszCurrentPos += lpsString.dwSize;
- *((WORD*)lpszCurrentPos) = *((WORD*)": ");
- lpszCurrentPos += sizeof(WORD);
-
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- memmove(lpszCurrentPos, lpsString.lpszData, lpsString.dwSize);
- lpszCurrentPos += lpsString.dwSize;
- *((WORD*)lpszCurrentPos) = *((WORD*)szCRLF);
- lpszCurrentPos += sizeof(WORD);(*((WORD*)lpszCurrentPos)) = 0;
-
- DebugPrintCRLFA((LPSTR)szBuff);
- DebugBreak();
- #endif
- }
+ else if ( !_strnicmp(szString, "MESSAGES.UNREAD", 15)) {
+ buf >> szString;
+ m_dwEmailMessagesUnread = atoi(szString);
}
- MraUpdateEmailStatus(NULL, 0, NULL, 0, 0, 0);
- break;
-
- case MRIM_CS_OFFLINE_MESSAGE_ACK://Сообщение доставленное, пока пользователь не был подключен к сети
- {
- DWORD dwTime, dwFlags;
- MRA_LPS lpsText, lpsRTFText, lpsMultiChatData;
- LPBYTE lpbBuff = NULL;
- DWORDLONG dwMsgUIDL = GetUIDL(&lpbDataCurrent);
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
-
- if (MraOfflineMessageGet(&lpsString, &dwTime, &dwFlags, &lpsEMail, &lpsText, &lpsRTFText, &lpsMultiChatData, &lpbBuff) == NO_ERROR) {
- dwTemp = MraRecvCommand_Message(dwTime, dwFlags, &lpsEMail, &lpsText, &lpsRTFText, &lpsMultiChatData);
- if (dwTemp == NO_ERROR || dwTemp == ERROR_ACCESS_DENIED)
- MraOfflineMessageDel(dwMsgUIDL);
- else
- ShowFormattedErrorMessage(L"Offline message processing error, message will not deleted from server", NO_ERROR);
- }
- else ShowFormattedErrorMessage(L"Offline message processing error, message will not deleted from server", NO_ERROR);
-
- mir_free(lpbBuff);
+ else if ( !_strnicmp(szString, "MRIM.NICKNAME", 13)) {
+ buf >> szStringW;
+ mraSetStringW(NULL, "Nick", szStringW);
}
- break;
-
- case MRIM_CS_AUTHORIZE_ACK: // Auth confirmation
- {
- BOOL bAdded;
- BYTE btBuff[BUFF_SIZE_BLOB];
-
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsEMail);
- hContact = MraHContactFromEmail(lpsEMail.lpszData, lpsEMail.dwSize, TRUE, TRUE, &bAdded);
- if (bAdded) MraUpdateContactInfo(hContact);
-
- if (IsEMailChatAgent(lpsEMail.lpszData, lpsEMail.dwSize) == FALSE) {
- DBEVENTINFO dbei = { sizeof(dbei) };
- dbei.szModule = m_szModuleName;
- dbei.timestamp = (DWORD)_time32(NULL);
- dbei.flags = 0;
- dbei.eventType = EVENTTYPE_ADDED;
- CreateBlobFromContact(hContact, NULL, 0, (LPBYTE)&btBuff, SIZEOF(btBuff), &dwStringSize);
- dbei.cbBlob = dwStringSize;
- dbei.pBlob = btBuff;
- db_event_add(0, &dbei);
+ else if ( !_strnicmp(szString, "client.endpoint", 15)) {
+ buf >> szStringW;
+ szString = szStringW;
+ int lpszDelimiter = szString.Find(':');
+ if (lpszDelimiter != -1) {
+ CMStringA szAddr(szString, lpszDelimiter);
+ setDword("IP", HTONL(inet_addr(szAddr.c_str())));
}
-
- GetContactBasicInfoW(hContact, NULL, NULL, NULL, &dwTemp, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, NULL);
- dwTemp &= ~CONTACT_INTFLAG_NOT_AUTHORIZED;
- SetContactBasicInfoW(hContact, SCBIFSI_LOCK_CHANGES_EVENTS, SCBIF_SERVER_FLAG, 0, 0, 0, dwTemp, 0, NULL, 0, NULL, 0, NULL, 0);
- setDword(hContact, "HooksLocked", TRUE);
- db_unset(hContact, "CList", "NotOnList");
- setDword(hContact, "HooksLocked", FALSE);
}
- break;
-
- case MRIM_CS_MPOP_SESSION: // Web auth key
- if ( GetUL(&lpbDataCurrent)) {
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- MraMPopSessionQueueSetNewMPopKey(hMPopSessionQueue, lpsString.lpszData, lpsString.dwSize);
- MraMPopSessionQueueStart(hMPopSessionQueue);
+ else if ( !_strnicmp(szString, "connect.xml", 11)) {
+ DebugPrintA(szString);
+ buf >> szStringW;
+ DebugPrintCRLFW(szStringW);
}
- else { //error
- MraPopupShowFromAgentW(MRA_POPUP_TYPE_WARNING, 0, TranslateW(L"Server error: cant get MPOP key for web authorize"));
- MraMPopSessionQueueFlush(hMPopSessionQueue);
+ else if ( !_strnicmp(szString, "micblog.show_title", 18)) {
+ DebugPrintA(szString);
+ buf >> szStringW;
+ DebugPrintCRLFW(szStringW);
}
- break;
-
- /////////////////////////////////////////////////////////////////////////////////////
- case MRIM_CS_FILE_TRANSFER:
- {
- BOOL bAdded;
- DWORD dwIDRequest, dwFilesTotalSize;
- MRA_LPS lpsFiles = {0}, lpsFilesW = {0}, lpsAddreses = {0};
-
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsEMail);// LPS TO/FROM ANSI
- dwIDRequest = GetUL(&lpbDataCurrent);// DWORD id_request
- dwFilesTotalSize = GetUL(&lpbDataCurrent);// DWORD FILESIZE
- if ( GetUL(&lpbDataCurrent)) {
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsFiles);// LPS Files (FileName;FileSize;FileName;FileSize;) ANSI
- if ( GetUL(&lpbDataCurrent)) { // LPS DESCRIPTION
- dwTemp = GetUL(&lpbDataCurrent);
- DebugBreakIf(dwTemp != 1);
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsFilesW);// LPS Files (FileName;FileSize;FileName;FileSize;) UNICODE
- }
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsAddreses);// LPS Conn (IP:Port;IP:Port;) ANSI
- }
+ else if ( !_strnicmp(szString, "micblog.status.id", 17)) {
+ buf >> szString;
+ DWORDLONG dwBlogStatusID = StrToUNum64(szString, szString.GetLength());
+ mraWriteContactSettingBlob(NULL, DBSETTING_BLOGSTATUSID, &dwBlogStatusID, sizeof(DWORDLONG));
+ }
+ else if ( !_strnicmp(szString, "micblog.status.time", 19)) {
+ buf >> szString;
+ setDword(DBSETTING_BLOGSTATUSTIME, atoi(szString));
+ }
+ else if ( !_strnicmp(szString, "micblog.status.text", 19)) {
+ buf >> szStringW;
+ mraSetStringW(NULL, DBSETTING_BLOGSTATUS, szStringW);
+ }
+ else if ( !_strnicmp(szString, "HAS_MYMAIL", 10)) {
+ buf >> szString;
+ //setDword(DBSETTING_BLOGSTATUSTIME, StrToUNum32(szString.lpszData, szString.dwSize));
+ }
+ else if ( !_strnicmp(szString, "mrim.status.open_search", 23)) {
+ buf >> szString;
+ //setDword(DBSETTING_BLOGSTATUSTIME, StrToUNum32(szString.lpszData, szString.dwSize));
+ }
+ else if ( !_strnicmp(szString, "rb.target.cookie", 16)) {
+ buf >> szString;
+ //setDword(DBSETTING_BLOGSTATUSTIME, StrToUNum32(szString.lpszData, szString.dwSize));
+ }
+ else if ( !_strnicmp(szString, "show_web_history_link", 21)) {
+ buf >> szString;
+ //setDword(DBSETTING_BLOGSTATUSTIME, StrToUNum32(szString.lpszData, szString.dwSize));
+ }
+ else if ( !_strnicmp(szString, "friends_suggest", 15)) {
+ buf >> szString;
+ //setDword(DBSETTING_BLOGSTATUSTIME, StrToUNum32(szString.lpszData, szString.dwSize));
+ }
+ else if ( !_strnicmp(szString, "timestamp", 9)) {
+ buf >> szString;
+ //setDword(DBSETTING_BLOGSTATUSTIME, StrToUNum32(szString.lpszData, szString.dwSize));
+ }
+ else if ( !_strnicmp(szString, "trusted_update", 14)) {
+ buf >> szString;
+ //setDword(DBSETTING_BLOGSTATUSTIME, StrToUNum32(szString.lpszData, szString.dwSize));
+ }
+ else {
+ #ifdef _DEBUG
+ DebugBreak();
+ #endif
+ }
+ }
+ MraUpdateEmailStatus("", "", 0, 0);
+ return true;
+}
- hContact = MraHContactFromEmail(lpsEMail.lpszData, lpsEMail.dwSize, TRUE, TRUE, &bAdded);
- if (bAdded) MraUpdateContactInfo(hContact);
+//Сообщение доставленное, пока пользователь не был подключен к сети
+bool CMraProto::CmdOfflineMessageAck(BinBuffer &buf)
+{
+ CMStringA szEmail, lpsText, lpsRTFText, lpsMultiChatData, szString;
+ DWORDLONG dwMsgUIDL;
+ buf >> dwMsgUIDL >> szString;
+
+ DWORD dwTime, dwFlags;
+ if (MraOfflineMessageGet(&szString, &dwTime, &dwFlags, &szEmail, &lpsText, &lpsRTFText, &lpsMultiChatData, NULL) == NO_ERROR) {
+ DWORD dwTemp = MraRecvCommand_Message(dwTime, dwFlags, szEmail, lpsText, lpsRTFText, lpsMultiChatData);
+ if (dwTemp == NO_ERROR || dwTemp == ERROR_ACCESS_DENIED)
+ MraOfflineMessageDel(dwMsgUIDL);
+ else
+ ShowFormattedErrorMessage(L"Offline message processing error, message will not deleted from server", NO_ERROR);
+ }
+ else ShowFormattedErrorMessage(L"Offline message processing error, message will not deleted from server", NO_ERROR);
- bAdded = FALSE;
- if (lpsFilesW.dwSize == 0) {
- lpsFilesW.lpwszData = (LPWSTR)mir_calloc((lpsFiles.dwSize+MAX_PATH)*sizeof(WCHAR));
- if (lpsFilesW.lpwszData) {
- lpsFilesW.dwSize = MultiByteToWideChar(MRA_CODE_PAGE, 0, lpsFiles.lpszData, lpsFiles.dwSize, lpsFilesW.lpwszData, (lpsFiles.dwSize+MAX_PATH));
- bAdded = TRUE;
- }
- }
+ return true;
+}
- if (lpsFilesW.dwSize)
- MraFilesQueueAddReceive(hFilesQueueHandle, 0, hContact, dwIDRequest, lpsFilesW.lpwszData, lpsFilesW.dwSize, lpsAddreses.lpszData, lpsAddreses.dwSize);
- if (bAdded)
- mir_free(lpsFilesW.lpwszData);
- }
- break;
+// Auth confirmation
+bool CMraProto::CmdAuthAck(BinBuffer &buf)
+{
+ CMStringA szEmail;
+ buf >> szEmail;
- case MRIM_CS_FILE_TRANSFER_ACK:
- dwAckType = GetUL(&lpbDataCurrent);// DWORD status
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsEMail);// LPS TO/FROM
- dwTemp = GetUL(&lpbDataCurrent);// DWORD id_request
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);// LPS DESCRIPTION
+ BOOL bAdded;
+ HANDLE hContact = MraHContactFromEmail(szEmail, TRUE, TRUE, &bAdded);
+ if (bAdded)
+ MraUpdateContactInfo(hContact);
+
+ if (IsEMailChatAgent(szEmail) == FALSE) {
+ CMStringA szBuff = CreateBlobFromContact(hContact, L"");
+
+ DBEVENTINFO dbei = { sizeof(dbei) };
+ dbei.szModule = m_szModuleName;
+ dbei.timestamp = (DWORD)_time32(NULL);
+ dbei.eventType = EVENTTYPE_ADDED;
+ dbei.cbBlob = szBuff.GetLength();
+ dbei.pBlob = (PBYTE)szBuff.GetBuffer();
+ db_event_add(0, &dbei);
+ }
- switch (dwAckType) {
- case FILE_TRANSFER_STATUS_OK:// игнорируем, мы и так уже слушаем порт(ждём), то что кто то согласился ничего не меняет
- //hContact = MraHContactFromEmail(lpsEMail.lpszData, lpsEMail.dwSize, TRUE, TRUE, NULL);
- break;
- case FILE_TRANSFER_STATUS_DECLINE:
- MraFilesQueueCancel(hFilesQueueHandle, dwTemp, FALSE);
- break;
- case FILE_TRANSFER_STATUS_ERROR:
- ShowFormattedErrorMessage(L"File transfer: error", NO_ERROR);
- MraFilesQueueCancel(hFilesQueueHandle, dwTemp, FALSE);
- break;
- case FILE_TRANSFER_STATUS_INCOMPATIBLE_VERS:
- ShowFormattedErrorMessage(L"File transfer: incompatible versions", NO_ERROR);
- MraFilesQueueCancel(hFilesQueueHandle, dwTemp, FALSE);
- break;
- case FILE_TRANSFER_MIRROR:
- MraFilesQueueSendMirror(hFilesQueueHandle, dwTemp, lpsString.lpszData, lpsString.dwSize);
- break;
- default:// ## unknown error
- mir_sntprintf(szBuff, SIZEOF(szBuff), TranslateW(L"MRIM_CS_FILE_TRANSFER_ACK: unknown error, code: %lu"), dwAckType);
- ShowFormattedErrorMessage(szBuff, NO_ERROR);
- break;
- }
- break;
+ DWORD dwTemp;
+ GetContactBasicInfoW(hContact, NULL, NULL, NULL, &dwTemp, NULL, NULL, NULL, NULL);
+ dwTemp &= ~CONTACT_INTFLAG_NOT_AUTHORIZED;
+ SetContactBasicInfoW(hContact, SCBIFSI_LOCK_CHANGES_EVENTS, SCBIF_SERVER_FLAG, 0, 0, 0, dwTemp, 0, "", L"", "");
+ setDword(hContact, "HooksLocked", TRUE);
+ db_unset(hContact, "CList", "NotOnList");
+ setDword(hContact, "HooksLocked", FALSE);
+ return true;
+}
- /////////////////////////////////////////////////////////////////////////////////////
- case MRIM_CS_USER_STATUS://Смена статуса другого пользователя
- {
- BOOL bAdded;
- DWORD dwStatus, dwXStatus, dwFutureFlags;
- MRA_LPS lpsSpecStatusUri, lpsStatusTitle, lpsStatusDesc, lpsUserAgentFormated;
-
- dwStatus = GetUL(&lpbDataCurrent);
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsSpecStatusUri);
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsStatusTitle);
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsStatusDesc);
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsEMail);
- dwFutureFlags = GetUL(&lpbDataCurrent);// com_support ( >= 1.14)
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsUserAgentFormated);
-
- if ((hContact = MraHContactFromEmail(lpsEMail.lpszData, lpsEMail.dwSize, TRUE, TRUE, &bAdded))) {
- if (bAdded)
- MraUpdateContactInfo(hContact);
+// Web auth key
+bool CMraProto::CmdPopSession(BinBuffer &buf)
+{
+ DWORD dwTemp; buf >> dwTemp;
+ if (dwTemp) {
+ CMStringA szString; buf >> szString;
+ MraMPopSessionQueueSetNewMPopKey(hMPopSessionQueue, szString);
+ MraMPopSessionQueueStart(hMPopSessionQueue);
+ }
+ else { //error
+ MraPopupShowFromAgentW(MRA_POPUP_TYPE_WARNING, 0, TranslateW(L"Server error: cant get MPOP key for web authorize"));
+ MraMPopSessionQueueFlush(hMPopSessionQueue);
+ }
+ return true;
+}
- dwTemp = GetMiradaStatusFromMraStatus(dwStatus, GetMraXStatusIDFromMraUriStatus(lpsSpecStatusUri.lpszData, lpsSpecStatusUri.dwSize), &dwXStatus);
+bool CMraProto::CmdFileTransfer(BinBuffer &buf)
+{
+ DWORD dwIDRequest, dwFilesTotalSize, dwTemp;
+ CMStringA szFiles, szEmail, szAddresses;
+ CMStringW wszFilesW;
+
+ buf >> szEmail >> dwIDRequest >> dwFilesTotalSize >> dwTemp;
+ if (dwTemp) {
+ buf >> szFiles >> dwTemp;
+ if (dwTemp) { // LPS DESCRIPTION
+ buf >> dwTemp >> wszFilesW;
+ DebugBreakIf(dwTemp != 1);
+ }
+ buf >> szAddresses;
+ }
- MraContactCapabilitiesSet(hContact, dwFutureFlags);
- setByte(hContact, DBSETTING_XSTATUSID, (BYTE)dwXStatus);
- mraSetLPSStringW(hContact, DBSETTING_XSTATUSNAME, &lpsStatusTitle);
- mraSetLPSStringW(hContact, DBSETTING_XSTATUSMSG, &lpsStatusDesc);
+ BOOL bAdded = FALSE;
+ HANDLE hContact = MraHContactFromEmail(szEmail, TRUE, TRUE, &bAdded);
+ if (bAdded)
+ MraUpdateContactInfo(hContact);
- if (dwTemp != ID_STATUS_OFFLINE) { // пишем клиента только если юзер не отключён, иначе не затираем старое
- if (lpsUserAgentFormated.dwSize) {
- if (getByte("MirVerRaw", MRA_DEFAULT_MIRVER_RAW) == FALSE) {
- MraGetVersionStringFromFormatted(lpsUserAgentFormated.lpszData, lpsUserAgentFormated.dwSize, (LPSTR)szBuff, SIZEOF(szBuff), &dwStringSize);
- lpsUserAgentFormated.lpszData = (LPSTR)szBuff;
- lpsUserAgentFormated.dwSize = dwStringSize;
- }
- }
- else { // хз чё за клиент
- lpsUserAgentFormated.lpszData = MIRVER_UNKNOWN;
- lpsUserAgentFormated.dwSize = (sizeof(MIRVER_UNKNOWN)-1);
- }
- mraSetLPSStringA(hContact, "MirVer", &lpsUserAgentFormated);
- }
+ if ( wszFilesW.IsEmpty())
+ wszFilesW = szFiles;
- if (dwTemp == MraGetContactStatus(hContact)) {// меняем шило на шило, подозрительно? ;)
- if (dwTemp == ID_STATUS_OFFLINE) { // was/now invisible
- WCHAR szEMail[MAX_EMAIL_LEN];
+ if ( !wszFilesW.IsEmpty())
+ MraFilesQueueAddReceive(hFilesQueueHandle, 0, hContact, dwIDRequest, wszFilesW, szAddresses);
+ return true;
+}
- mraGetStaticStringW(hContact, "e-mail", szEMail, SIZEOF(szEMail), NULL);
- mir_sntprintf(szBuff, SIZEOF(szBuff), L"%s <%s> - %s", GetContactNameW(hContact), szEMail, TranslateW(L"invisible status changed"));
- MraPopupShowFromContactW(hContact, MRA_POPUP_TYPE_INFORMATION, 0, szBuff);
+bool CMraProto::CmdFileTransferAck(BinBuffer &buf)
+{
+ CMStringA szEmail, szString;
+ DWORD dwAckType, dwTemp;
+ buf >> dwAckType >> szEmail >> dwTemp >> szString;
- MraSetContactStatus(hContact, ID_STATUS_INVISIBLE);
- }
- }
- MraSetContactStatus(hContact, dwTemp);
- SetExtraIcons(hContact);
- }
- }
+ switch (dwAckType) {
+ case FILE_TRANSFER_STATUS_OK:// игнорируем, мы и так уже слушаем порт(ждём), то что кто то согласился ничего не меняет
+ //hContact = MraHContactFromEmail(szEmail.lpszData, szEmail.dwSize, TRUE, TRUE, NULL);
break;
-
- case MRIM_CS_LOGOUT:// Пользователь отключен из-за параллельного входа с его логином.
- if ( GetUL(&lpbDataCurrent) == LOGOUT_NO_RELOGIN_FLAG)
- ShowFormattedErrorMessage(L"Another user connected with your login", NO_ERROR);
- *pbContinue = FALSE;
+ case FILE_TRANSFER_STATUS_DECLINE:
+ MraFilesQueueCancel(hFilesQueueHandle, dwTemp, FALSE);
break;
-
- case MRIM_CS_ADD_CONTACT_ACK:
- case MRIM_CS_MODIFY_CONTACT_ACK:
- if ( !MraSendQueueFind(hSendQueueHandle, pmaHeader->seq, NULL, &hContact, &dwAckType, (LPBYTE*)&lpsString.lpszData, &lpsString.dwSize)) {
- dwTemp = GetUL(&lpbDataCurrent);
- switch (dwTemp) {
- case CONTACT_OPER_SUCCESS:// ## добавление произведено успешно
- if (pmaHeader->msg == MRIM_CS_ADD_CONTACT_ACK) SetContactBasicInfoW(hContact, 0, (SCBIF_ID|SCBIF_SERVER_FLAG), GetUL(&lpbDataCurrent), 0, 0, CONTACT_INTFLAG_NOT_AUTHORIZED, 0, NULL, 0, NULL, 0, NULL, 0);
- break;
- case CONTACT_OPER_ERROR:// ## переданные данные были некорректны
- ShowFormattedErrorMessage(L"Data been sent are invalid", NO_ERROR);
- break;
- case CONTACT_OPER_INTERR:// ## при обработке запроса произошла внутренняя ошибка
- ShowFormattedErrorMessage(L"Internal server error", NO_ERROR);
- break;
- case CONTACT_OPER_NO_SUCH_USER:// ## добавляемого пользователя не существует в системе
- SetContactBasicInfoW(hContact, 0, SCBIF_SERVER_FLAG, 0, 0, 0, -1, 0, NULL, 0, NULL, 0, NULL, 0);
- ShowFormattedErrorMessage(L"User does not registred", NO_ERROR);
- break;
- case CONTACT_OPER_INVALID_INFO:// ## некорректное имя пользователя
- ShowFormattedErrorMessage(L"Invalid user name", NO_ERROR);
- break;
- case CONTACT_OPER_USER_EXISTS:// ## пользователь уже есть в контакт-листе
- ShowFormattedErrorMessage(L"User allready added", NO_ERROR);
- break;
- case CONTACT_OPER_GROUP_LIMIT:// ## превышено максимально допустимое количество групп (20)
- ShowFormattedErrorMessage(L"Group limit is 20", NO_ERROR);
- break;
- default:// ## unknown error
- mir_sntprintf(szBuff, SIZEOF(szBuff), TranslateW(L"MRIM_CS_*_CONTACT_ACK: unknown server error, code: %lu"), dwTemp);
- MraPopupShowFromAgentW(MRA_POPUP_TYPE_DEBUG, 0, szBuff);
- break;
- }
- MraSendQueueFree(hSendQueueHandle, pmaHeader->seq);
- }
- else MraPopupShowFromAgentW(MRA_POPUP_TYPE_DEBUG, 0, TranslateW(L"MRIM_CS_*_CONTACT_ACK: not found in queue"));
+ case FILE_TRANSFER_STATUS_ERROR:
+ ShowFormattedErrorMessage(L"File transfer: error", NO_ERROR);
+ MraFilesQueueCancel(hFilesQueueHandle, dwTemp, FALSE);
+ break;
+ case FILE_TRANSFER_STATUS_INCOMPATIBLE_VERS:
+ ShowFormattedErrorMessage(L"File transfer: incompatible versions", NO_ERROR);
+ MraFilesQueueCancel(hFilesQueueHandle, dwTemp, FALSE);
+ break;
+ case FILE_TRANSFER_MIRROR:
+ MraFilesQueueSendMirror(hFilesQueueHandle, dwTemp, szString);
break;
+ default:// ## unknown error
+ TCHAR szBuff[1024];
+ mir_sntprintf(szBuff, SIZEOF(szBuff), TranslateW(L"MRIM_CS_FILE_TRANSFER_ACK: unknown error, code: %lu"), dwAckType);
+ ShowFormattedErrorMessage(szBuff, NO_ERROR);
+ break;
+ }
+ return true;
+}
- case MRIM_CS_ANKETA_INFO:
- if ( !MraSendQueueFind(hSendQueueHandle, pmaHeader->seq, NULL, &hContact, &dwAckType, (LPBYTE*)&lpsString.lpszData, &lpsString.dwSize)) {
- switch (GetUL(&lpbDataCurrent)) {
- case MRIM_ANKETA_INFO_STATUS_OK:// поиск успешно завершен
- {
- DWORD dwFeildsNum, dwMaxRows, dwServerTime, dwStatus;
- size_t i;
- MRA_LPS *pmralpsFeilds, *pmralpsValues;
-
- dwFeildsNum = GetUL(&lpbDataCurrent);
- dwMaxRows = GetUL(&lpbDataCurrent);
- dwServerTime = GetUL(&lpbDataCurrent);
-
- pmralpsFeilds = (MRA_LPS*)mir_calloc(((dwFeildsNum*2)+4)*sizeof(MRA_LPS));
- if (pmralpsFeilds) {
- pmralpsValues = (pmralpsFeilds+dwFeildsNum);
- // read headers name
- for (i = 0; i < dwFeildsNum; i++) {
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &pmralpsFeilds[i]);
- DebugPrintCRLFA(pmralpsFeilds[i].lpszData);
- }
+// Смена статуса другого пользователя
+bool CMraProto::CmdUserStatus(BinBuffer &buf)
+{
+ DWORD dwStatus, dwXStatus, dwFutureFlags;
+ CMStringA szSpecStatusUri, szUserAgentFormatted, szEmail;
+ CMStringW szStatusTitle, szStatusDesc;
+ buf >> dwStatus >> szSpecStatusUri >> szStatusTitle >> szStatusDesc >> szEmail >> dwFutureFlags >> szUserAgentFormatted;
- while (lpbDataCurrent < lpbData+dwDataSize) {
- // read values
- for (i = 0;i<dwFeildsNum;i++)
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &pmralpsValues[i]);
-
- // write to DB and exit loop
- if (dwAckType == ACKTYPE_GETINFO && hContact) {
- setDword(hContact, "InfoTS", (DWORD)_time32(NULL));
- //MRA_LPS mralpsUsernameValue;
- for (i = 0; i < dwFeildsNum; i++) {
- if ( !_strnicmp(pmralpsFeilds[i].lpszData, "Username", 8))
- ; //mralpsUsernameValue = pmralpsValues[i];
- else if ( !_strnicmp(pmralpsFeilds[i].lpszData, "Domain", 6))
- ;
- else if ( !_strnicmp(pmralpsFeilds[i].lpszData, "Flags", 5))
- ;
- else if ( !_strnicmp(pmralpsFeilds[i].lpszData, "Nickname", 8))
- mraSetLPSStringW(hContact, "Nick", &pmralpsValues[i]);
- else if ( !_strnicmp(pmralpsFeilds[i].lpszData, "FirstName", 9))
- mraSetLPSStringW(hContact, "FirstName", &pmralpsValues[i]);
- else if ( !_strnicmp(pmralpsFeilds[i].lpszData, "LastName", 8))
- mraSetLPSStringW(hContact, "LastName", &pmralpsValues[i]);
- else if ( !_strnicmp(pmralpsFeilds[i].lpszData, "Sex", 3)) {
- switch (StrToUNum32(pmralpsValues[i].lpszData, pmralpsValues[i].dwSize)) {
- case 1:// мужской
- setByte(hContact, "Gender", 'M');
- break;
- case 2:// женский
- setByte(hContact, "Gender", 'F');
- break;
- default:// а фиг его знает
- delSetting(hContact, "Gender");
- break;
- }
- }
- else if ( !_strnicmp(pmralpsFeilds[i].lpszData, "Birthday", 8)) {
- if (pmralpsValues[i].dwSize > 9) {// calc "Age"
- SYSTEMTIME stTime = {0};
-
- stTime.wYear = (WORD)StrToUNum32(pmralpsValues[i].lpszData, 4);
- stTime.wMonth = (WORD)StrToUNum32((pmralpsValues[i].lpszData+5), 2);
- stTime.wDay = (WORD)StrToUNum32((pmralpsValues[i].lpszData+8), 2);
- setWord(hContact, "BirthYear", stTime.wYear);
- setByte(hContact, "BirthMonth", (BYTE)stTime.wMonth);
- setByte(hContact, "BirthDay", (BYTE)stTime.wDay);
-
- setWord(hContact, "Age", (WORD)GetYears(&stTime));
- }
- else {
- delSetting(hContact, "BirthYear");
- delSetting(hContact, "BirthMonth");
- delSetting(hContact, "BirthDay");
- delSetting(hContact, "Age");
- }
- }
- else if ( !_strnicmp(pmralpsFeilds[i].lpszData, "City_id", 7)) {
- dwTemp = StrToUNum32(pmralpsValues[i].lpszData, pmralpsValues[i].dwSize);
- if (dwTemp) {
- for (size_t j = 0;mrapPlaces[j].lpszData;j++) {
- if (mrapPlaces[j].dwCityID == dwTemp) {
- mraSetStringW(hContact, "City", mrapPlaces[j].lpszData);
- break;
- }
- }
- }
- else delSetting(hContact, "City");
- }
- else if ( !_strnicmp(pmralpsFeilds[i].lpszData, "Location", 8))
- mraSetLPSStringW(hContact, "About", &pmralpsValues[i]);
- else if ( !_strnicmp(pmralpsFeilds[i].lpszData, "Zodiac", 6))
- ;
- else if ( !_strnicmp(pmralpsFeilds[i].lpszData, "BMonth", 6))
- ;
- else if ( !_strnicmp(pmralpsFeilds[i].lpszData, "BDay", 4))
- ;
- else if ( !_strnicmp(pmralpsFeilds[i].lpszData, "Country_id", 10)) {
- dwTemp = StrToUNum32(pmralpsValues[i].lpszData, pmralpsValues[i].dwSize);
- if (dwTemp) {
- for (size_t j = 0; mrapPlaces[j].lpszData; j++) {
- if (mrapPlaces[j].dwCountryID == dwTemp) {
- mraSetStringW(hContact, "Country", mrapPlaces[j].lpszData);
- break;
- }
- }
- }
- else delSetting(hContact, "Country");
- }
- else if ( !_strnicmp(pmralpsFeilds[i].lpszData, "Phone", 5)) {
- delSetting(hContact, "Phone");
- delSetting(hContact, "Cellular");
- delSetting(hContact, "Fax");
-
- if (pmralpsValues[i].dwSize) {
- lpsString.lpszData = pmralpsValues[i].lpszData;
- LPSTR lpszCurPos = (LPSTR)MemoryFindByte(0, pmralpsValues[i].lpszData, pmralpsValues[i].dwSize, ',');
- if (lpszCurPos)
- lpsString.dwSize = (lpszCurPos-lpsString.lpszData);
- else
- lpsString.dwSize = ((pmralpsValues[i].lpszData+pmralpsValues[i].dwSize)-lpsString.lpszData);
-
- mraSetLPSStringA(hContact, "Phone", &lpsString);
-
- if (lpszCurPos) {
- lpsString.lpszData = (++lpszCurPos);
- lpszCurPos = (LPSTR)MemoryFindByte((lpszCurPos-pmralpsValues[i].lpszData), pmralpsValues[i].lpszData, pmralpsValues[i].dwSize, ',');
- if (lpszCurPos)
- lpsString.dwSize = (lpszCurPos-lpsString.lpszData);
- else
- lpsString.dwSize = ((pmralpsValues[i].lpszData+pmralpsValues[i].dwSize)-lpsString.lpszData);
-
- mraSetLPSStringA(hContact, "Cellular", &lpsString);
- }
-
- if (lpszCurPos) {
- lpsString.lpszData = (++lpszCurPos);
- lpszCurPos = (LPSTR)MemoryFindByte((lpszCurPos-pmralpsValues[i].lpszData), pmralpsValues[i].lpszData, pmralpsValues[i].dwSize, ',');
- if (lpszCurPos)
- lpsString.dwSize = (lpszCurPos-lpsString.lpszData);
- else
- lpsString.dwSize = ((pmralpsValues[i].lpszData+pmralpsValues[i].dwSize)-lpsString.lpszData);
-
- mraSetLPSStringA(hContact, "Fax", &lpsString);
- }
- }
- }
- else if ( !_strnicmp(pmralpsFeilds[i].lpszData, "mrim_status", 11)) {
- if (pmralpsValues[i].dwSize) {
- DWORD dwID, dwContactSeverFlags;
-
- GetContactBasicInfoW(hContact, &dwID, NULL, NULL, &dwContactSeverFlags, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, NULL);
- // для авторизованного нам и так присылают правильный статус
- if (dwID == -1 || (dwContactSeverFlags & CONTACT_INTFLAG_NOT_AUTHORIZED)) {
- dwStatus = StrHexToUNum32(pmralpsValues[i].lpszData, pmralpsValues[i].dwSize);
- MraSetContactStatus(hContact, GetMiradaStatusFromMraStatus(dwStatus, MRA_MIR_XSTATUS_NONE, NULL));
- setByte(hContact, DBSETTING_XSTATUSID, (BYTE)MRA_MIR_XSTATUS_NONE);
- }
- }
- }
- else if ( !_strnicmp(pmralpsFeilds[i].lpszData, "status_uri", 10)) {
- if (pmralpsValues[i].dwSize) {
- DWORD dwID, dwContactSeverFlags, dwXStatus;
-
- GetContactBasicInfoW(hContact, &dwID, NULL, NULL, &dwContactSeverFlags, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, NULL);
- if (dwID == -1 || dwContactSeverFlags&CONTACT_INTFLAG_NOT_AUTHORIZED) {
- MraSetContactStatus(hContact, GetMiradaStatusFromMraStatus(dwStatus, GetMraXStatusIDFromMraUriStatus(pmralpsValues[i].lpszData, pmralpsValues[i].dwSize), &dwXStatus));
- setByte(hContact, DBSETTING_XSTATUSID, (BYTE)dwXStatus);
- }
- }
- }
- else if ( !_strnicmp(pmralpsFeilds[i].lpszData, "status_title", 12)) {
- if (pmralpsValues[i].dwSize) {
- DWORD dwID, dwContactSeverFlags;
-
- GetContactBasicInfoW(hContact, &dwID, NULL, NULL, &dwContactSeverFlags, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, NULL);
- if (dwID == -1 || dwContactSeverFlags&CONTACT_INTFLAG_NOT_AUTHORIZED)
- mraSetLPSStringW(hContact, DBSETTING_XSTATUSNAME, &pmralpsValues[i]);
- }
- }
- else if ( !_strnicmp(pmralpsFeilds[i].lpszData, "status_desc", 11)) {
- if (pmralpsValues[i].dwSize) {
- DWORD dwID, dwContactSeverFlags;
-
- GetContactBasicInfoW(hContact, &dwID, NULL, NULL, &dwContactSeverFlags, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, NULL);
- if (dwID == -1 || dwContactSeverFlags&CONTACT_INTFLAG_NOT_AUTHORIZED)
- mraSetLPSStringW(hContact, DBSETTING_XSTATUSMSG, &pmralpsValues[i]);
- }
- }
- else {// for DEBUG ONLY
- #ifdef _DEBUG
- DebugPrintCRLFA(pmralpsFeilds[i].lpszData);
- DebugPrintCRLFA(pmralpsValues[i].lpszData);
- //DebugBreak();
- #endif
- }
- }
- }
- else if (dwAckType == ACKTYPE_SEARCH) {
- WCHAR szNick[MAX_EMAIL_LEN] = {0},
- szFirstName[MAX_EMAIL_LEN] = {0},
- szLastName[MAX_EMAIL_LEN] = {0},
- szEMail[MAX_EMAIL_LEN] = {0};
- MRA_LPS mralpsUsernameValue = {0};
- PROTOSEARCHRESULT psr = {0};
-
- psr.cbSize = sizeof(psr);
- psr.flags = PSR_UNICODE;
- psr.nick = szNick;
- psr.firstName = szFirstName;
- psr.lastName = szLastName;
- psr.email = szEMail;
- psr.id = szEMail;
-
- for (i = 0;i<dwFeildsNum;i++) {
- if ( !_strnicmp(pmralpsFeilds[i].lpszData, "Username", 8))
- mralpsUsernameValue = pmralpsValues[i];
- else if ( !_strnicmp(pmralpsFeilds[i].lpszData, "Domain", 6)) { // имя было уже задано ранее
- dwStringSize = MultiByteToWideChar(MRA_CODE_PAGE, 0, mralpsUsernameValue.lpszData, mralpsUsernameValue.dwSize, szEMail, SIZEOF(szEMail));
-
- szEMail[dwStringSize] = (*((WCHAR*)L"@"));
- dwStringSize++;
-
- dwStringSize += MultiByteToWideChar(MRA_CODE_PAGE, 0, pmralpsValues[i].lpszData, pmralpsValues[i].dwSize, &szEMail[dwStringSize], (SIZEOF(szEMail)-(dwStringSize+1)));
- szEMail[dwStringSize] = 0;
- }
- else if ( !_strnicmp(pmralpsFeilds[i].lpszData, "Nickname", 8)) {
- dwStringSize = min((sizeof(szNick)-sizeof(WCHAR)), pmralpsValues[i].dwSize);
- memmove(szNick, pmralpsValues[i].lpwszData, dwStringSize);
- szNick[dwStringSize] = 0;
- }
- else if ( !_strnicmp(pmralpsFeilds[i].lpszData, "FirstName", 9)) {
- dwStringSize = min((sizeof(szFirstName)-sizeof(WCHAR)), pmralpsValues[i].dwSize);
- memmove(szFirstName, pmralpsValues[i].lpwszData, dwStringSize);
- szFirstName[dwStringSize] = 0;
- }
- else if ( !_strnicmp(pmralpsFeilds[i].lpszData, "LastName", 8)) {
- dwStringSize = min((sizeof(szLastName)-sizeof(WCHAR)), pmralpsValues[i].dwSize);
- memmove(szLastName, pmralpsValues[i].lpwszData, dwStringSize);
- szLastName[dwStringSize] = 0;
- }
- }// end for
- ProtoBroadcastAck(hContact, dwAckType, ACKRESULT_DATA, (HANDLE)pmaHeader->seq, (LPARAM)&psr);
- }
- }// end while
+ BOOL bAdded;
+ if (HANDLE hContact = MraHContactFromEmail(szEmail, TRUE, TRUE, &bAdded)) {
+ if (bAdded)
+ MraUpdateContactInfo(hContact);
- mir_free(pmralpsFeilds);
- }
- }
+ DWORD dwTemp = GetMiradaStatusFromMraStatus(dwStatus, GetMraXStatusIDFromMraUriStatus(szSpecStatusUri), &dwXStatus);
- switch (dwAckType) {
- case ACKTYPE_GETINFO:
- ProtoBroadcastAck(hContact, dwAckType, ACKRESULT_SUCCESS, (HANDLE)1, 0);
- break;
- case ACKTYPE_SEARCH:
- default:
- ProtoBroadcastAck(hContact, dwAckType, ACKRESULT_SUCCESS, (HANDLE)pmaHeader->seq, 0);
- break;
- }
- break;
+ MraContactCapabilitiesSet(hContact, dwFutureFlags);
+ setByte(hContact, DBSETTING_XSTATUSID, (BYTE)dwXStatus);
+ mraSetStringW(hContact, DBSETTING_XSTATUSNAME, szStatusTitle);
+ mraSetStringW(hContact, DBSETTING_XSTATUSMSG, szStatusDesc);
- case MRIM_ANKETA_INFO_STATUS_NOUSER:// не найдено ни одной подходящей записи
- SetContactBasicInfoW(hContact, 0, SCBIF_SERVER_FLAG, 0, 0, 0, -1, 0, NULL, 0, NULL, 0, NULL, 0);
- case MRIM_ANKETA_INFO_STATUS_DBERR:// ошибка базы данных
- case MRIM_ANKETA_INFO_STATUS_RATELIMERR:// слишком много запросов, поиск временно запрещен
- switch (dwAckType) {
- case ACKTYPE_GETINFO:
- ProtoBroadcastAck(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)1, 0);
- break;
- case ACKTYPE_SEARCH:
- ProtoBroadcastAck(hContact, dwAckType, ACKRESULT_SUCCESS, (HANDLE)pmaHeader->seq, 0);
- break;
- default:
- DebugBreak();
- break;
- }
- break;
- default:// unknown
- DebugBreak();
- break;
+ if (dwTemp != ID_STATUS_OFFLINE) { // пишем клиента только если юзер не отключён, иначе не затираем старое
+ if (!szUserAgentFormatted.IsEmpty()) {
+ if (getByte("MirVerRaw", MRA_DEFAULT_MIRVER_RAW) == FALSE)
+ szUserAgentFormatted = MraGetVersionStringFromFormatted(szUserAgentFormatted);
}
- MraSendQueueFree(hSendQueueHandle, pmaHeader->seq);
+ else szUserAgentFormatted = MIRVER_UNKNOWN;
+ mraSetStringA(hContact, "MirVer", szUserAgentFormatted);
}
- else MraPopupShowFromAgentW(MRA_POPUP_TYPE_DEBUG, 0, TranslateW(L"MRIM_ANKETA_INFO: not found in queue"));
- break;
-
- case MRIM_CS_MAILBOX_STATUS:
- dwTemp = GetUL(&lpbDataCurrent);
- if (dwTemp > dwEmailMessagesTotal)
- dwEmailMessagesTotal += (dwTemp - dwEmailMessagesUnread);
- dwAckType = dwEmailMessagesUnread;// save old value
- dwEmailMessagesUnread = dwTemp;// store new value
- if (getByte("IncrementalNewMailNotify", MRA_DEFAULT_INC_NEW_MAIL_NOTIFY) == 0 || dwAckType<dwTemp || dwTemp == 0)
- MraUpdateEmailStatus(NULL, 0, NULL, 0, 0, 0);
- break;
+ if (dwTemp == MraGetContactStatus(hContact)) {// меняем шило на шило, подозрительно? ;)
+ if (dwTemp == ID_STATUS_OFFLINE) { // was/now invisible
+ CMStringW szEmail, szBuff;
+ mraGetStringW(hContact, "e-mail", szEmail);
+ szBuff.Format(L"%s <%s> - %s", GetContactNameW(hContact), szEmail, TranslateW(L"invisible status changed"));
+ MraPopupShowFromContactW(hContact, MRA_POPUP_TYPE_INFORMATION, 0, szBuff);
- case MRIM_CS_GAME:
- {
- DWORD dwGameSessionID, dwGameMsg, dwGameMsgID;
+ MraSetContactStatus(hContact, ID_STATUS_INVISIBLE);
+ }
+ }
+ MraSetContactStatus(hContact, dwTemp);
+ SetExtraIcons(hContact);
+ }
+ return true;
+}
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsEMail);//LPS to/from
- dwGameSessionID = GetUL(&lpbDataCurrent);//DWORD session unique per game
- dwGameMsg = GetUL(&lpbDataCurrent);//DWORD msg internal game message
- dwGameMsgID = GetUL(&lpbDataCurrent);//DWORD msg_id id for ack
- dwTemp = GetUL(&lpbDataCurrent);//DWORD time_send time of client
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);//LPS data
+bool CMraProto::CmdContactAck(int cmd, int seq, BinBuffer &buf)
+{
+ CMStringA szString; buf >> szString;
+
+ DWORD dwAckType; HANDLE hContact; LPBYTE pData; size_t dataLen;
+ if ( !MraSendQueueFind(hSendQueueHandle, seq, NULL, &hContact, &dwAckType, &pData, &dataLen)) {
+ DWORD dwTemp; buf >> dwTemp;
+ switch (dwTemp) {
+ case CONTACT_OPER_SUCCESS:// ## добавление произведено успешно
+ buf >> dwTemp;
+ if (cmd == MRIM_CS_ADD_CONTACT_ACK)
+ SetContactBasicInfoW(hContact, 0, (SCBIF_ID|SCBIF_SERVER_FLAG), dwTemp, 0, 0, CONTACT_INTFLAG_NOT_AUTHORIZED, 0, "", L"", "");
+ break;
+ case CONTACT_OPER_ERROR:// ## переданные данные были некорректны
+ ShowFormattedErrorMessage(L"Data been sent are invalid", NO_ERROR);
+ break;
+ case CONTACT_OPER_INTERR:// ## при обработке запроса произошла внутренняя ошибка
+ ShowFormattedErrorMessage(L"Internal server error", NO_ERROR);
+ break;
+ case CONTACT_OPER_NO_SUCH_USER:// ## добавляемого пользователя не существует в системе
+ SetContactBasicInfoW(hContact, 0, SCBIF_SERVER_FLAG, 0, 0, 0, -1, 0, "", L"", "");
+ ShowFormattedErrorMessage(L"User does not registred", NO_ERROR);
+ break;
+ case CONTACT_OPER_INVALID_INFO:// ## некорректное имя пользователя
+ ShowFormattedErrorMessage(L"Invalid user name", NO_ERROR);
+ break;
+ case CONTACT_OPER_USER_EXISTS:// ## пользователь уже есть в контакт-листе
+ ShowFormattedErrorMessage(L"User allready added", NO_ERROR);
+ break;
+ case CONTACT_OPER_GROUP_LIMIT:// ## превышено максимально допустимое количество групп (20)
+ ShowFormattedErrorMessage(L"Group limit is 20", NO_ERROR);
+ break;
+ default:// ## unknown error
+ TCHAR szBuff[1024];
+ mir_sntprintf(szBuff, SIZEOF(szBuff), TranslateW(L"MRIM_CS_*_CONTACT_ACK: unknown server error, code: %lu"), dwTemp);
+ MraPopupShowFromAgentW(MRA_POPUP_TYPE_DEBUG, 0, szBuff);
+ break;
+ }
+ MraSendQueueFree(hSendQueueHandle, seq);
+ }
+ else MraPopupShowFromAgentW(MRA_POPUP_TYPE_DEBUG, 0, TranslateW(L"MRIM_CS_*_CONTACT_ACK: not found in queue"));
+ return true;
+}
- #ifdef _DEBUG
- BYTE btBuff[1024] = {0};
- memmove(btBuff, lpsString.lpszData, lpsString.dwSize);
- #endif
+bool CMraProto::CmdAnketaInfo(int seq, BinBuffer &buf)
+{
+ DWORD dwAckType; HANDLE hContact; LPBYTE pData; size_t dataLen;
+ if ( MraSendQueueFind(hSendQueueHandle, seq, NULL, &hContact, &dwAckType, &pData, &dataLen)) {
+ MraPopupShowFromAgentW(MRA_POPUP_TYPE_DEBUG, 0, TranslateW(L"MRIM_ANKETA_INFO: not found in queue"));
+ return true;
+ }
- switch (dwGameMsg) {
- case GAME_CONNECTION_INVITE:
- if (m_iStatus != ID_STATUS_INVISIBLE)
- MraGame(lpsEMail.lpszData, lpsEMail.dwSize, dwGameSessionID, GAME_DECLINE, dwGameMsgID, lpsString.lpszData, lpsString.dwSize);
- break;
- case GAME_CONNECTION_ACCEPT:
- break;
- case GAME_DECLINE:
- break;
- case GAME_INC_VERSION:
- break;
- case GAME_NO_SUCH_GAME:// user invisible
- if ((hContact = MraHContactFromEmail(lpsEMail.lpszData, lpsEMail.dwSize, FALSE, TRUE, NULL)))
- if (MraGetContactStatus(hContact) == ID_STATUS_OFFLINE)
- MraSetContactStatus(hContact, ID_STATUS_INVISIBLE);
- break;
- case GAME_JOIN:
- break;
- case GAME_CLOSE:
- break;
- case GAME_SPEED:
- break;
- case GAME_SYNCHRONIZATION:
- break;
- case GAME_USER_NOT_FOUND:
- break;
- case GAME_ACCEPT_ACK:
- break;
- case GAME_PING:
- break;
- case GAME_RESULT:
- break;
- case GAME_MESSAGES_NUMBER:
- break;
- default:
- mir_sntprintf(szBuff, SIZEOF(szBuff), TranslateW(L"MRIM_CS_GAME: unknown internal game message code: %lu"), dwGameMsg);
- MraPopupShowFromAgentW(MRA_POPUP_TYPE_DEBUG, 0, szBuff);
- break;
- }
+ DWORD dwTemp; buf >> dwTemp;
+ switch(dwTemp) {
+ case MRIM_ANKETA_INFO_STATUS_NOUSER:// не найдено ни одной подходящей записи
+ SetContactBasicInfoW(hContact, 0, SCBIF_SERVER_FLAG, 0, 0, 0, -1, 0, "", L"", "");
+ case MRIM_ANKETA_INFO_STATUS_DBERR:// ошибка базы данных
+ case MRIM_ANKETA_INFO_STATUS_RATELIMERR:// слишком много запросов, поиск временно запрещен
+ switch (dwAckType) {
+ case ACKTYPE_GETINFO:
+ ProtoBroadcastAck(hContact, dwAckType, ACKRESULT_FAILED, (HANDLE)1, 0);
+ break;
+ case ACKTYPE_SEARCH:
+ ProtoBroadcastAck(hContact, dwAckType, ACKRESULT_SUCCESS, (HANDLE)seq, 0);
+ break;
}
break;
- case MRIM_CS_CONTACT_LIST2:
- dwTemp = GetUL(&lpbDataCurrent);
- if (dwTemp == GET_CONTACTS_OK) { // received contact list
- BOOL bAdded;
- char szGroupMask[MAX_PATH], szContactMask[MAX_PATH];
- DWORD dwID, dwGroupFlags, dwContactFlag, dwGroupID, dwContactSeverFlags, dwStatus, dwXStatus, dwFutureFlags, dwBlogStatusTime;
- MRA_LPS mralpsGroupName, mralpsNick, mralpsCustomPhones, lpsSpecStatusUri, lpsStatusTitle, lpsStatusDesc, lpsUserAgentFormated, lpsBlogStatus, lpsBlogStatusMusic;
- size_t i, j, dwGroupsCount, dwGroupMaskSize, dwContactMaskSize, dwControlParam;
- ULARGE_INTEGER dwBlogStatusID;
-
- dwGroupsCount = GetUL(&lpbDataCurrent);
-
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- dwGroupMaskSize = lpsString.dwSize;
- memmove(szGroupMask, lpsString.lpszData, dwGroupMaskSize);(*(szGroupMask+dwGroupMaskSize)) = 0;
-
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- dwContactMaskSize = lpsString.dwSize;
- memmove(szContactMask, lpsString.lpszData, dwContactMaskSize);(*(szContactMask+dwContactMaskSize)) = 0;
-
- DebugPrintCRLFW(L"Groups:");
- DebugPrintCRLFA(szGroupMask);
- dwID = 0;
- for (i = 0; i < dwGroupsCount; i++) { //groups handle
- dwControlParam = 0;
- for (j = 0; j < dwGroupMaskSize; j++) { //enumerating parameters
- switch (szGroupMask[j]) {
- case 's'://LPS
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- break;
- case 'u'://UL
- dwTemp = GetUL(&lpbDataCurrent);
- break;
- case 'z'://sz
- lpsString.lpszData = (LPSTR)lpbDataCurrent;
- lpsString.dwSize = lstrlenA((LPSTR)lpbDataCurrent);
- lpbDataCurrent += lpsString.dwSize;
- DebugBreak();
- break;
- }
- if (j == 0 && szGroupMask[j] == 'u') {// GroupFlags
- dwGroupFlags = dwTemp;
- dwControlParam++;
- }
- else if (j == 1 && szGroupMask[j] == 's') {// GroupName
- mralpsGroupName = lpsString;
- dwControlParam++;
- }
- }
+ case MRIM_ANKETA_INFO_STATUS_OK:
+ // поиск успешно завершен
+ DWORD dwFieldsNum, dwMaxRows, dwServerTime, dwStatus;
+ buf >> dwFieldsNum >> dwMaxRows >> dwServerTime;
- // add/modify group
- if (dwControlParam > 1) { // все параметры правильно инициализированны!
- #ifdef _DEBUG
- memmove(szBuff, mralpsGroupName.lpszData, mralpsGroupName.dwSize);
- szBuff[(mralpsGroupName.dwSize/sizeof(WCHAR))] = 0;
- DebugPrintW(szBuff);
-
- mir_snprintf((LPSTR)szBuff, SIZEOF(szBuff), ": flags: %lu (", dwGroupFlags);
- DebugPrintA((LPSTR)szBuff);
- if (dwGroupFlags&CONTACT_FLAG_REMOVED) DebugPrintA("CONTACT_FLAG_REMOVED, ");
- if (dwGroupFlags&CONTACT_FLAG_GROUP) DebugPrintA("CONTACT_FLAG_GROUP, ");
- if (dwGroupFlags&CONTACT_FLAG_INVISIBLE) DebugPrintA("CONTACT_FLAG_INVISIBLE, ");
- if (dwGroupFlags&CONTACT_FLAG_VISIBLE) DebugPrintA("CONTACT_FLAG_VISIBLE, ");
- if (dwGroupFlags&CONTACT_FLAG_IGNORE) DebugPrintA("CONTACT_FLAG_IGNORE, ");
- if (dwGroupFlags&CONTACT_FLAG_SHADOW) DebugPrintA("CONTACT_FLAG_SHADOW, ");
- if (dwGroupFlags&CONTACT_FLAG_AUTHORIZED) DebugPrintA("CONTACT_FLAG_AUTHORIZED, ");
- if (dwGroupFlags&CONTACT_FLAG_MULTICHAT) DebugPrintA("CONTACT_FLAG_MULTICHAT, ");
- if (dwGroupFlags&CONTACT_FLAG_UNICODE_NAME) DebugPrintA("CONTACT_FLAG_UNICODE_NAME, ");
- if (dwGroupFlags&CONTACT_FLAG_PHONE) DebugPrintA("CONTACT_FLAG_PHONE, ");
- DebugPrintCRLFA(")");
- #endif//*/
- }
- dwID++;
- }// end for (processing groups)
-
- DebugPrintCRLFW(L"Contacts:");
- DebugPrintCRLFA(szContactMask);
- dwID = 20;
- while (lpbDataCurrent < lpbData + dwDataSize) {
- dwControlParam = 0;
- for (j = 0; j < dwContactMaskSize; j++) { //enumerating parameters
- switch (szContactMask[j]) {
- case 's'://LPS
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);
- break;
- case 'u'://UL
- dwTemp = GetUL(&lpbDataCurrent);
- break;
- case 'z'://sz
- lpsString.lpszData = (LPSTR)lpbDataCurrent;
- lpsString.dwSize = lstrlenA((LPSTR)lpbDataCurrent);
- lpbDataCurrent += lpsString.dwSize;
- DebugBreak();
- break;
- }
+ CMStringA *pmralpsFields = new CMStringA[dwFieldsNum];
+ CMStringA val;
+ CMStringW valW;
- if (j == 0 && szContactMask[j] == 'u') { // Flags
- dwContactFlag = dwTemp;
- dwControlParam++;
- }
- else if (j == 1 && szContactMask[j] == 'u') { // Group id
- dwGroupID = dwTemp;
- dwControlParam++;
- }
- else if (j == 2 && szContactMask[j] == 's') { // Email
- lpsEMail = lpsString;
- dwControlParam++;
+ // read headers name
+ for (unsigned i = 0; i < dwFieldsNum; i++) {
+ buf >> pmralpsFields[i];
+ DebugPrintCRLFA(pmralpsFields[i]);
+ }
+
+ while (buf.m_len > 0) {
+ // write to DB and exit loop
+ if (dwAckType == ACKTYPE_GETINFO && hContact) {
+ setDword(hContact, "InfoTS", (DWORD)_time32(NULL));
+ //MRA_LPS mralpsUsernameValue;
+ for (unsigned i = 0; i < dwFieldsNum; i++) {
+ CMStringA &fld = pmralpsFields[i];
+ if (fld == "Nickname") {
+ buf >> valW;
+ mraSetStringW(hContact, "Nick", valW);
}
- else if (j == 3 && szContactMask[j] == 's') { // Nick
- mralpsNick = lpsString;
- dwControlParam++;
+ else if (fld == "FirstName") {
+ buf >> valW;
+ mraSetStringW(hContact, "FirstName", valW);
}
- else if (j == 4 && szContactMask[j] == 'u') { // Server flags
- dwContactSeverFlags = dwTemp;
- dwControlParam++;
+ else if (fld == "LastName") {
+ buf >> valW;
+ mraSetStringW(hContact, "LastName", valW);
}
- else if (j == 5 && szContactMask[j] == 'u') { // Status
- dwStatus = dwTemp;
- dwControlParam++;
+ else if (fld == "Sex") {
+ buf >> valW;
+ switch (_wtoi(valW)) {
+ case 1:// мужской
+ setByte(hContact, "Gender", 'M');
+ break;
+ case 2:// женский
+ setByte(hContact, "Gender", 'F');
+ break;
+ default:// а фиг его знает
+ delSetting(hContact, "Gender");
+ break;
+ }
}
- else if (j == 6 && szContactMask[j] == 's') { // Custom Phone number,
- mralpsCustomPhones = lpsString;
- dwControlParam++;
+ else if (fld == "Birthday") {
+ buf >> val;
+ if (val.GetLength() > 9) {// calc "Age"
+ SYSTEMTIME stTime = {0};
+ stTime.wYear = (WORD)StrToUNum32(val.c_str(), 4);
+ stTime.wMonth = (WORD)StrToUNum32(val.c_str()+5, 2);
+ stTime.wDay = (WORD)StrToUNum32(val.c_str()+8, 2);
+ setWord(hContact, "BirthYear", stTime.wYear);
+ setByte(hContact, "BirthMonth", (BYTE)stTime.wMonth);
+ setByte(hContact, "BirthDay", (BYTE)stTime.wDay);
+ setWord(hContact, "Age", (WORD)GetYears(&stTime));
+ }
+ else {
+ delSetting(hContact, "BirthYear");
+ delSetting(hContact, "BirthMonth");
+ delSetting(hContact, "BirthDay");
+ delSetting(hContact, "Age");
+ }
}
- else if (j == 7 && szContactMask[j] == 's') { // spec_status_uri
- lpsSpecStatusUri = lpsString;
- dwControlParam++;
+ else if (fld == "City_id") {
+ buf >> val;
+ dwTemp = atoi(val);
+ if (dwTemp) {
+ for (size_t j = 0; mrapPlaces[j].lpszData; j++) {
+ if (mrapPlaces[j].dwCityID == dwTemp) {
+ mraSetStringW(hContact, "City", mrapPlaces[j].lpszData);
+ break;
+ }
+ }
+ }
+ else delSetting(hContact, "City");
}
- else if (j == 8 && szContactMask[j] == 's') { // status_title
- lpsStatusTitle = lpsString;
- dwControlParam++;
+ else if (fld == "Location") {
+ buf >> valW;
+ mraSetStringW(hContact, "About", valW);
}
- else if (j == 9 && szContactMask[j] == 's') { // status_desc
- lpsStatusDesc = lpsString;
- dwControlParam++;
+ else if (fld == "Country_id") {
+ buf >> val;
+ dwTemp = atoi(val);
+ if (dwTemp) {
+ for (size_t j = 0; mrapPlaces[j].lpszData; j++) {
+ if (mrapPlaces[j].dwCountryID == dwTemp) {
+ mraSetStringW(hContact, "Country", mrapPlaces[j].lpszData);
+ break;
+ }
+ }
+ }
+ else delSetting(hContact, "Country");
}
- else if (j == 10 && szContactMask[j] == 'u') { // com_support (future flags)
- dwFutureFlags = dwTemp;
- dwControlParam++;
+ else if (fld == "Phone") {
+ delSetting(hContact, "Phone");
+ delSetting(hContact, "Cellular");
+ delSetting(hContact, "Fax");
+
+ buf >> val;
+ if (val.GetLength()) {
+ int iStart = 0;
+ CMStringA szPhone = val.Tokenize(",", iStart);
+ if (iStart != -1) {
+ mraSetStringA(hContact, "Phone", szPhone);
+ szPhone = val.Tokenize(",", iStart);
+ }
+ if (iStart != -1) {
+ mraSetStringA(hContact, "Cellular", szPhone);
+ szPhone = val.Tokenize(",", iStart);
+ }
+ if (iStart != -1)
+ mraSetStringA(hContact, "Fax", szPhone);
+ }
}
- else if (j == 11 && szContactMask[j] == 's') { // user_agent (formated string)
- lpsUserAgentFormated = lpsString;
- dwControlParam++;
+ else if (fld == "mrim_status") {
+ buf >> val;
+ if (val.GetLength()) {
+ DWORD dwID, dwContactSeverFlags;
+ GetContactBasicInfoW(hContact, &dwID, NULL, NULL, &dwContactSeverFlags, NULL, NULL, NULL, NULL);
+ // для авторизованного нам и так присылают правильный статус
+ if (dwID == -1 || (dwContactSeverFlags & CONTACT_INTFLAG_NOT_AUTHORIZED)) {
+ MraSetContactStatus(hContact, GetMiradaStatusFromMraStatus(atoi(val), MRA_MIR_XSTATUS_NONE, NULL));
+ setByte(hContact, DBSETTING_XSTATUSID, (BYTE)MRA_MIR_XSTATUS_NONE);
+ }
+ }
}
- else if (j == 12 && szContactMask[j] == 'u') { // BlogStatusID
- dwBlogStatusID.LowPart = dwTemp;
- dwControlParam++;
+ else if (fld == "status_uri") {
+ buf >> val;
+ if (val.GetLength()) {
+ DWORD dwID, dwContactSeverFlags, dwXStatus;
+ GetContactBasicInfoW(hContact, &dwID, NULL, NULL, &dwContactSeverFlags, NULL, NULL, NULL, NULL);
+ if (dwID == -1 || (dwContactSeverFlags & CONTACT_INTFLAG_NOT_AUTHORIZED)) {
+ MraSetContactStatus(hContact, GetMiradaStatusFromMraStatus(dwStatus, GetMraXStatusIDFromMraUriStatus(val), &dwXStatus));
+ setByte(hContact, DBSETTING_XSTATUSID, (BYTE)dwXStatus);
+ }
+ }
}
- else if (j == 13 && szContactMask[j] == 'u') { // BlogStatusID
- dwBlogStatusID.HighPart = dwTemp;
- dwControlParam++;
+ else if (fld == "status_title") {
+ buf >> valW;
+ if (valW.GetLength()) {
+ DWORD dwID, dwContactSeverFlags;
+ GetContactBasicInfoW(hContact, &dwID, NULL, NULL, &dwContactSeverFlags, NULL, NULL, NULL, NULL);
+ if (dwID == -1 || (dwContactSeverFlags & CONTACT_INTFLAG_NOT_AUTHORIZED))
+ mraSetStringW(hContact, DBSETTING_XSTATUSNAME, valW);
+ }
}
- else if (j == 14 && szContactMask[j] == 'u') { // BlogStatusTime
- dwBlogStatusTime = dwTemp;
- dwControlParam++;
+ else if (fld == "status_desc") {
+ buf >> valW;
+ if (valW.GetLength()) {
+ DWORD dwID, dwContactSeverFlags;
+ GetContactBasicInfoW(hContact, &dwID, NULL, NULL, &dwContactSeverFlags, NULL, NULL, NULL, NULL);
+ if (dwID == -1 || dwContactSeverFlags&CONTACT_INTFLAG_NOT_AUTHORIZED)
+ mraSetStringW(hContact, DBSETTING_XSTATUSMSG, valW);
+ }
}
- else if (j == 15 && szContactMask[j] == 's') { // BlogStatus
- lpsBlogStatus = lpsString;
- dwControlParam++;
+ else {// for DEBUG ONLY
+ buf >> val;
+#ifdef _DEBUG
+ DebugPrintCRLFA(fld);
+ DebugPrintCRLFA(val);
+#endif
}
- else if (j == 16 && szContactMask[j] == 's') { // BlogStatusMusic
- lpsBlogStatusMusic = lpsString;
- dwControlParam++;
+ }
+ }
+ else if (dwAckType == ACKTYPE_SEARCH) {
+ WCHAR szNick[MAX_EMAIL_LEN] = {0},
+ szFirstName[MAX_EMAIL_LEN] = {0},
+ szLastName[MAX_EMAIL_LEN] = {0},
+ szEmail[MAX_EMAIL_LEN] = {0};
+ CMStringA mralpsUsernameValue;
+ PROTOSEARCHRESULT psr = {0};
+
+ psr.cbSize = sizeof(psr);
+ psr.flags = PSR_UNICODE;
+ psr.nick = szNick;
+ psr.firstName = szFirstName;
+ psr.lastName = szLastName;
+ psr.email = szEmail;
+ psr.id = szEmail;
+
+ for (unsigned i = 0; i < dwFieldsNum; i++) {
+ CMStringA &fld = pmralpsFields[i];
+ if (fld == "Username") {
+ buf >> val;
+ mralpsUsernameValue = val;
}
- else if (j == 17 && szContactMask[j] == 's') { // BlogStatusSender // ignory
- lpsString = lpsString;
- dwControlParam++;
+ else if (fld == "Domain") { // имя было уже задано ранее
+ buf >> val;
+ wcsncpy_s(szEmail, _A2T(mralpsUsernameValue + "@" + val), SIZEOF(szEmail));
}
- else if (j == 18 && szContactMask[j] == 's') { // geo data ?
- lpsString = lpsString;
- dwControlParam++;
+ else if (fld == "Nickname") {
+ buf >> valW;
+ wcsncpy_s(szNick, valW, SIZEOF(szNick));
}
- else if (j == 19 && szContactMask[j] == 's') { // ?????? ?
- lpsString = lpsString;
- dwControlParam++;
- DebugBreakIf(lpsString.dwSize);
+ else if (fld == "FirstName") {
+ buf >> valW;
+ wcsncpy_s(szFirstName, valW, SIZEOF(szFirstName));
}
- else {
- if (szContactMask[j] == 's') {
- if (lpsString.dwSize) {
- DebugPrintCRLFW(lpsString.lpwszData);
- }
- }
- else if (szContactMask[j] == 'u') {
- mir_snprintf((LPSTR)szBuff, SIZEOF(szBuff), "%lu, ", dwTemp);//;
- DebugPrintCRLFA((LPSTR)szBuff);
- }
- else DebugBreak();
+ else if (fld == "LastName") {
+ buf >> valW;
+ wcsncpy_s(szLastName, valW, SIZEOF(szLastName));
}
+ else buf >> val;
}
+ ProtoBroadcastAck(hContact, dwAckType, ACKRESULT_DATA, (HANDLE)seq, (LPARAM)&psr);
+ }
+ }
+
+ delete[] pmralpsFields;
+
+ switch (dwAckType) {
+ case ACKTYPE_GETINFO:
+ ProtoBroadcastAck(hContact, dwAckType, ACKRESULT_SUCCESS, (HANDLE)1, 0);
+ break;
+ case ACKTYPE_SEARCH:
+ default:
+ ProtoBroadcastAck(hContact, dwAckType, ACKRESULT_SUCCESS, (HANDLE)seq, 0);
+ break;
+ }
+ break;
+ }
+ MraSendQueueFree(hSendQueueHandle, seq);
+ return true;
+}
+bool CMraProto::CmdGame(BinBuffer &buf)
+{
+ HANDLE hContact;
+ CMStringA szEmail, szData;
+ DWORD dwGameSessionID, dwGameMsg, dwGameMsgID, dwTemp;
+ buf >> szEmail >> dwGameSessionID >> dwGameMsg >> dwGameMsgID >> dwTemp >> szData;
+
+ switch (dwGameMsg) {
+ case GAME_CONNECTION_INVITE:
+ if (m_iStatus != ID_STATUS_INVISIBLE)
+ MraGame(szEmail, dwGameSessionID, GAME_DECLINE, dwGameMsgID, szData);
+ break;
+ case GAME_CONNECTION_ACCEPT:
+ break;
+ case GAME_DECLINE:
+ break;
+ case GAME_INC_VERSION:
+ break;
+ case GAME_NO_SUCH_GAME:// user invisible
+ if ((hContact = MraHContactFromEmail(szEmail, FALSE, TRUE, NULL)))
+ if (MraGetContactStatus(hContact) == ID_STATUS_OFFLINE)
+ MraSetContactStatus(hContact, ID_STATUS_INVISIBLE);
+ break;
+ case GAME_JOIN:
+ break;
+ case GAME_CLOSE:
+ break;
+ case GAME_SPEED:
+ break;
+ case GAME_SYNCHRONIZATION:
+ break;
+ case GAME_USER_NOT_FOUND:
+ break;
+ case GAME_ACCEPT_ACK:
+ break;
+ case GAME_PING:
+ break;
+ case GAME_RESULT:
+ break;
+ case GAME_MESSAGES_NUMBER:
+ break;
+ default:
+ WCHAR szBuff[1024];
+ mir_sntprintf(szBuff, SIZEOF(szBuff), TranslateW(L"MRIM_CS_GAME: unknown internal game message code: %lu"), dwGameMsg);
+ MraPopupShowFromAgentW(MRA_POPUP_TYPE_DEBUG, 0, szBuff);
+ break;
+ }
+ return true;
+}
+
+bool CMraProto::CmdClist2(BinBuffer &buf)
+{
+ DWORD dwTemp; buf >> dwTemp;
+ if (dwTemp == GET_CONTACTS_OK) { // received contact list
+ BOOL bAdded;
+ DWORD dwID, dwGroupsCount, dwGroupFlags, dwContactFlag, dwGroupID, dwContactSeverFlags, dwStatus, dwXStatus, dwFutureFlags, dwBlogStatusTime;
+ size_t i, j, dwControlParam;
+ ULARGE_INTEGER dwBlogStatusID;
+
+ CMStringA szGroupMask, szContactMask, szEmail, szString;
+ CMStringA szCustomPhones, szSpecStatusUri, szUserAgentFormatted;
+ CMStringW wszNick, wszString, wszGroupName, wszStatusTitle, wszStatusDesc, wszBlogStatus, wszBlogStatusMusic;
+ buf >> dwGroupsCount >> szGroupMask >> szContactMask;
+
+ char szBuff[200];
+ DebugPrintCRLFW(L"Groups:");
+ DebugPrintCRLFA(szGroupMask);
+ dwID = 0;
+ for (i = 0; i < dwGroupsCount; i++) { //groups handle
+ dwControlParam = 0;
+ for (j = 0; j < szGroupMask.GetLength(); j++) { //enumerating parameters
+ switch (szGroupMask[j]) {
+ case 's'://LPS
+ buf >> wszString;
+ break;
+ case 'u'://UL
+ buf >> dwTemp;
+ break;
+ }
+
+ if (j == 0 && szGroupMask[j] == 'u') { // GroupFlags
+ dwGroupFlags = dwTemp;
+ dwControlParam++;
+ }
+ else if (j == 1 && szGroupMask[j] == 's') { // GroupName
+ wszGroupName = wszString;
+ dwControlParam++;
+ }
+ }
+
+ // add/modify group
+ if (dwControlParam > 1) { // все параметры правильно инициализированны!
#ifdef _DEBUG
- mir_snprintf((LPSTR)szBuff, SIZEOF(szBuff), "ID: %lu, Group id: %lu, ", dwID, dwGroupID);
- DebugPrintA((LPSTR)szBuff);
-
- memmove(szBuff, lpsEMail.lpszData, lpsEMail.dwSize);
- szBuff[(lpsEMail.dwSize/sizeof(WCHAR))] = 0;
- DebugPrintA((LPSTR)szBuff);
-
- mir_snprintf((LPSTR)szBuff, SIZEOF(szBuff), ": flags: %lu (", dwContactFlag);
- DebugPrintA((LPSTR)szBuff);
- if (dwContactFlag&CONTACT_FLAG_REMOVED) DebugPrintA("CONTACT_FLAG_REMOVED, ");
- if (dwContactFlag&CONTACT_FLAG_GROUP) DebugPrintA("CONTACT_FLAG_GROUP, ");
- if (dwContactFlag&CONTACT_FLAG_INVISIBLE) DebugPrintA("CONTACT_FLAG_INVISIBLE, ");
- if (dwContactFlag&CONTACT_FLAG_VISIBLE) DebugPrintA("CONTACT_FLAG_VISIBLE, ");
- if (dwContactFlag&CONTACT_FLAG_IGNORE) DebugPrintA("CONTACT_FLAG_IGNORE, ");
- if (dwContactFlag&CONTACT_FLAG_SHADOW) DebugPrintA("CONTACT_FLAG_SHADOW, ");
- if (dwContactFlag&CONTACT_FLAG_AUTHORIZED) DebugPrintA("CONTACT_FLAG_AUTHORIZED, ");
- if (dwContactFlag&CONTACT_FLAG_MULTICHAT) DebugPrintA("CONTACT_FLAG_MULTICHAT, ");
- if (dwContactFlag&CONTACT_FLAG_UNICODE_NAME)DebugPrintA("CONTACT_FLAG_UNICODE_NAME, ");
- if (dwContactFlag&CONTACT_FLAG_PHONE) DebugPrintA("CONTACT_FLAG_PHONE, ");
- DebugPrintA(")");
-
- mir_snprintf((LPSTR)szBuff, SIZEOF(szBuff), ": server flags: %lu (", dwContactSeverFlags);
- DebugPrintA((LPSTR)szBuff);
- if (dwContactSeverFlags&CONTACT_INTFLAG_NOT_AUTHORIZED) DebugPrintA("CONTACT_INTFLAG_NOT_AUTHORIZED, ");
+ DebugPrintW(wszGroupName);
+
+ mir_snprintf(szBuff, SIZEOF(szBuff), ": flags: %lu (", dwGroupFlags);
+ DebugPrintA(szBuff);
+
+ if (dwGroupFlags & CONTACT_FLAG_REMOVED) DebugPrintA("CONTACT_FLAG_REMOVED, ");
+ if (dwGroupFlags & CONTACT_FLAG_GROUP) DebugPrintA("CONTACT_FLAG_GROUP, ");
+ if (dwGroupFlags & CONTACT_FLAG_INVISIBLE) DebugPrintA("CONTACT_FLAG_INVISIBLE, ");
+ if (dwGroupFlags & CONTACT_FLAG_VISIBLE) DebugPrintA("CONTACT_FLAG_VISIBLE, ");
+ if (dwGroupFlags & CONTACT_FLAG_IGNORE) DebugPrintA("CONTACT_FLAG_IGNORE, ");
+ if (dwGroupFlags & CONTACT_FLAG_SHADOW) DebugPrintA("CONTACT_FLAG_SHADOW, ");
+ if (dwGroupFlags & CONTACT_FLAG_AUTHORIZED) DebugPrintA("CONTACT_FLAG_AUTHORIZED, ");
+ if (dwGroupFlags & CONTACT_FLAG_MULTICHAT) DebugPrintA("CONTACT_FLAG_MULTICHAT, ");
+ if (dwGroupFlags & CONTACT_FLAG_UNICODE_NAME) DebugPrintA("CONTACT_FLAG_UNICODE_NAME, ");
+ if (dwGroupFlags & CONTACT_FLAG_PHONE) DebugPrintA("CONTACT_FLAG_PHONE, ");
DebugPrintCRLFA(")");
#endif
+ }
+ dwID++;
+ }
- // add/modify contact
- if (dwGroupID != 103)//***deb filtering phone/sms contats
- if ( _strnicmp(lpsEMail.lpszData, "phone", 5))
- if (dwControlParam>5)// все параметры правильно инициализированны!
- if ((dwContactFlag&(CONTACT_FLAG_GROUP|CONTACT_FLAG_REMOVED)) == 0) {
- hContact = MraHContactFromEmail(lpsEMail.lpszData, lpsEMail.dwSize, TRUE, FALSE, &bAdded);
- if (hContact) {
- // already in list, remove the duplicate
- if (GetContactBasicInfoW(hContact, &dwTemp, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, NULL) == NO_ERROR && dwTemp != -1) {
- dwTemp = dwTemp;
- DebugBreak();
- }
- else {
- dwTemp = GetMiradaStatusFromMraStatus(dwStatus, GetMraXStatusIDFromMraUriStatus(lpsSpecStatusUri.lpszData, lpsSpecStatusUri.dwSize), &dwXStatus);
- if ((dwContactFlag&CONTACT_FLAG_UNICODE_NAME))
- mralpsNick.dwSize /= sizeof(WCHAR);
-
- if (bAdded) { // update user info
- SetContactBasicInfoW(hContact, SCBIFSI_LOCK_CHANGES_EVENTS, (SCBIF_ID|SCBIF_GROUP_ID|SCBIF_FLAG|SCBIF_SERVER_FLAG|SCBIF_STATUS|SCBIF_NICK|SCBIF_PHONES), dwID, dwGroupID, dwContactFlag, dwContactSeverFlags, dwTemp, NULL, 0, mralpsNick.lpwszData, mralpsNick.dwSize, mralpsCustomPhones.lpszData, mralpsCustomPhones.dwSize);
- // request user info from server
- MraUpdateContactInfo(hContact);
- }
- else { //****deb - check group ID param
- SetContactBasicInfoW(hContact, SCBIFSI_LOCK_CHANGES_EVENTS, (SCBIF_ID|SCBIF_GROUP_ID|SCBIF_SERVER_FLAG|SCBIF_STATUS), dwID, dwGroupID, dwContactFlag, dwContactSeverFlags, dwTemp, NULL, 0, mralpsNick.lpwszData, mralpsNick.dwSize, mralpsCustomPhones.lpszData, mralpsCustomPhones.dwSize);
- if (mralpsNick.dwSize == 0) { // set the server-side nick
- lstrcpynW(szBuff, GetContactNameW(hContact), SIZEOF(szBuff));
- mralpsNick.lpwszData = szBuff;
- mralpsNick.dwSize = lstrlenW(mralpsNick.lpwszData);
-
- MraModifyContactW(hContact, dwID, dwContactFlag, dwGroupID, lpsEMail.lpszData, lpsEMail.dwSize, mralpsNick.lpwszData, mralpsNick.dwSize, mralpsCustomPhones.lpszData, mralpsCustomPhones.dwSize);
- }
- }
-
- MraContactCapabilitiesSet(hContact, dwFutureFlags);
- setByte(hContact, DBSETTING_XSTATUSID, (BYTE)dwXStatus);
- mraSetLPSStringW(hContact, DBSETTING_XSTATUSNAME, &lpsStatusTitle);
- mraSetLPSStringW(hContact, DBSETTING_XSTATUSMSG, &lpsStatusDesc);
- setDword(hContact, DBSETTING_BLOGSTATUSTIME, dwBlogStatusTime);
- mraWriteContactSettingBlob(hContact, DBSETTING_BLOGSTATUSID, &dwBlogStatusID.QuadPart, sizeof(DWORDLONG));
- mraSetLPSStringW(hContact, DBSETTING_BLOGSTATUS, &lpsBlogStatus);
- mraSetLPSStringW(hContact, DBSETTING_BLOGSTATUSMUSIC, &lpsBlogStatusMusic);
- if ( IsXStatusValid(dwXStatus))
- SetExtraIcons(hContact);
-
- if (dwTemp != ID_STATUS_OFFLINE) { // пишем клиента только если юзер не отключён, иначе не затираем старое
- if (lpsUserAgentFormated.dwSize) {
- if (getByte("MirVerRaw", MRA_DEFAULT_MIRVER_RAW) == FALSE) {
- MraGetVersionStringFromFormatted(lpsUserAgentFormated.lpszData, lpsUserAgentFormated.dwSize, (LPSTR)szBuff, SIZEOF(szBuff), &dwStringSize);
- lpsUserAgentFormated.lpszData = (LPSTR)szBuff;
- lpsUserAgentFormated.dwSize = dwStringSize;
- }
- }
- else {
- lpsUserAgentFormated.lpszData = MIRVER_UNKNOWN;
- lpsUserAgentFormated.dwSize = (sizeof(MIRVER_UNKNOWN)-1);
- }
- mraSetLPSStringA(hContact, "MirVer", &lpsUserAgentFormated);
- }
+ DebugPrintCRLFA("Contacts:");
+ DebugPrintCRLFA(szContactMask);
+ dwID = 20;
+ while (buf.m_len > 0) {
+ dwControlParam = 0;
+ for (j = 0; j < szContactMask.GetLength(); j++) { //enumerating parameters
+ switch (szContactMask[j]) {
+ case 's'://LPS
+ break;
+ case 'u'://UL
+ buf >> dwTemp;
+ break;
+ }
- if (dwContactSeverFlags & CONTACT_INTFLAG_NOT_AUTHORIZED)
- if (getByte("AutoAuthRequestOnLogon", MRA_DEFAULT_AUTO_AUTH_REQ_ON_LOGON))
- CallProtoService(m_szModuleName, MRA_REQ_AUTH, (WPARAM)hContact, 0);
- }
+ if (j == 0 && szContactMask[j] == 'u') { // Flags
+ dwContactFlag = dwTemp;
+ dwControlParam++;
+ }
+ else if (j == 1 && szContactMask[j] == 'u') { // Group id
+ dwGroupID = dwTemp;
+ dwControlParam++;
+ }
+ else if (j == 2 && szContactMask[j] == 's') { // Email
+ buf >> szEmail;
+ dwControlParam++;
+ }
+ else if (j == 3 && szContactMask[j] == 's') { // Nick
+ buf >> wszNick;
+ dwControlParam++;
+ }
+ else if (j == 4 && szContactMask[j] == 'u') { // Server flags
+ dwContactSeverFlags = dwTemp;
+ dwControlParam++;
+ }
+ else if (j == 5 && szContactMask[j] == 'u') { // Status
+ dwStatus = dwTemp;
+ dwControlParam++;
+ }
+ else if (j == 6 && szContactMask[j] == 's') { // Custom Phone number,
+ buf >> szCustomPhones;
+ dwControlParam++;
+ }
+ else if (j == 7 && szContactMask[j] == 's') { // spec_status_uri
+ buf >> szSpecStatusUri;
+ dwControlParam++;
+ }
+ else if (j == 8 && szContactMask[j] == 's') { // status_title
+ buf >> wszStatusTitle;
+ dwControlParam++;
+ }
+ else if (j == 9 && szContactMask[j] == 's') { // status_desc
+ buf >> wszStatusDesc;
+ dwControlParam++;
+ }
+ else if (j == 10 && szContactMask[j] == 'u') { // com_support (future flags)
+ dwFutureFlags = dwTemp;
+ dwControlParam++;
+ }
+ else if (j == 11 && szContactMask[j] == 's') { // user_agent (formated string)
+ buf >> szUserAgentFormatted;
+ dwControlParam++;
+ }
+ else if (j == 12 && szContactMask[j] == 'u') { // BlogStatusID
+ dwBlogStatusID.LowPart = dwTemp;
+ dwControlParam++;
+ }
+ else if (j == 13 && szContactMask[j] == 'u') { // BlogStatusID
+ dwBlogStatusID.HighPart = dwTemp;
+ dwControlParam++;
+ }
+ else if (j == 14 && szContactMask[j] == 'u') { // BlogStatusTime
+ dwBlogStatusTime = dwTemp;
+ dwControlParam++;
+ }
+ else if (j == 15 && szContactMask[j] == 's') { // BlogStatus
+ buf >> wszBlogStatus;
+ dwControlParam++;
+ }
+ else if (j == 16 && szContactMask[j] == 's') { // BlogStatusMusic
+ buf >> wszBlogStatusMusic;
+ dwControlParam++;
+ }
+ else if (j == 17 && szContactMask[j] == 's') { // BlogStatusSender // ignory
+ buf >> szString;
+ dwControlParam++;
+ }
+ else if (j == 18 && szContactMask[j] == 's') { // geo data ?
+ buf >> szString;
+ dwControlParam++;
+ }
+ else if (j == 19 && szContactMask[j] == 's') { // ?????? ?
+ buf >> szString;
+ dwControlParam++;
+ DebugBreakIf(szString.GetLength());
+ }
+ else {
+ if (szContactMask[j] == 's') {
+ buf >> szString;
+ if (szString.GetLength())
+ DebugPrintCRLFA(szString);
}
+ else if (szContactMask[j] == 'u') {
+ mir_snprintf(szBuff, SIZEOF(szBuff), "%lu, ", dwTemp);//;
+ DebugPrintCRLFA(szBuff);
+ }
+ else DebugBreak();
}
- dwID++;
- }// end while (processing contacts)
+ }
- // post processing contact list
- {
- CHAR szEMail[MAX_EMAIL_LEN], szPhones[MAX_EMAIL_LEN];
- WCHAR wszAuthMessage[MAX_PATH], wszNick[MAX_EMAIL_LEN];
- size_t dwEMailSize, dwNickSize, dwPhonesSize, dwAuthMessageSize;
+ #ifdef _DEBUG
+ mir_snprintf(szBuff, SIZEOF(szBuff), "ID: %lu, Group id: %lu, ", dwID, dwGroupID);
+ DebugPrintA(szBuff);
+ DebugPrintA(szEmail);
+
+ mir_snprintf(szBuff, SIZEOF(szBuff), ": flags: %lu (", dwContactFlag);
+ DebugPrintA(szBuff);
+ if (dwContactFlag & CONTACT_FLAG_REMOVED) DebugPrintA("CONTACT_FLAG_REMOVED, ");
+ if (dwContactFlag & CONTACT_FLAG_GROUP) DebugPrintA("CONTACT_FLAG_GROUP, ");
+ if (dwContactFlag & CONTACT_FLAG_INVISIBLE) DebugPrintA("CONTACT_FLAG_INVISIBLE, ");
+ if (dwContactFlag & CONTACT_FLAG_VISIBLE) DebugPrintA("CONTACT_FLAG_VISIBLE, ");
+ if (dwContactFlag & CONTACT_FLAG_IGNORE) DebugPrintA("CONTACT_FLAG_IGNORE, ");
+ if (dwContactFlag & CONTACT_FLAG_SHADOW) DebugPrintA("CONTACT_FLAG_SHADOW, ");
+ if (dwContactFlag & CONTACT_FLAG_AUTHORIZED) DebugPrintA("CONTACT_FLAG_AUTHORIZED, ");
+ if (dwContactFlag & CONTACT_FLAG_MULTICHAT) DebugPrintA("CONTACT_FLAG_MULTICHAT, ");
+ if (dwContactFlag & CONTACT_FLAG_UNICODE_NAME) DebugPrintA("CONTACT_FLAG_UNICODE_NAME, ");
+ if (dwContactFlag & CONTACT_FLAG_PHONE) DebugPrintA("CONTACT_FLAG_PHONE, ");
+ DebugPrintA(")");
+
+ mir_snprintf(szBuff, SIZEOF(szBuff), ": server flags: %lu (", dwContactSeverFlags);
+ DebugPrintA(szBuff);
+ if (dwContactSeverFlags & CONTACT_INTFLAG_NOT_AUTHORIZED)
+ DebugPrintA("CONTACT_INTFLAG_NOT_AUTHORIZED, ");
+ DebugPrintCRLFA(")");
+ #endif
- if (mraGetStaticStringW(NULL, "AuthMessage", wszAuthMessage, SIZEOF(wszAuthMessage), &dwAuthMessageSize) == FALSE) { // def auth message
- lstrcpynW(wszAuthMessage, TranslateW(MRA_DEFAULT_AUTH_MESSAGE), SIZEOF(wszAuthMessage));
- dwAuthMessageSize = lstrlenW(wszAuthMessage);
- }
+ // add/modify contact
+ if (dwGroupID != 103)//***deb filtering phone/sms contats
+ if ( _strnicmp(szEmail, "phone", 5))
+ if (dwControlParam>5)// все параметры правильно инициализированны!
+ if ((dwContactFlag & (CONTACT_FLAG_GROUP | CONTACT_FLAG_REMOVED)) == 0) {
+ HANDLE hContact = MraHContactFromEmail(szEmail, TRUE, FALSE, &bAdded);
+ if (hContact) {
+ // already in list, remove the duplicate
+ if (GetContactBasicInfoW(hContact, &dwTemp, NULL, NULL, NULL, NULL, NULL, NULL, NULL) == NO_ERROR && dwTemp != -1) {
+ dwTemp = dwTemp;
+ DebugBreak();
+ }
+ else {
+ dwTemp = GetMiradaStatusFromMraStatus(dwStatus, GetMraXStatusIDFromMraUriStatus(szSpecStatusUri), &dwXStatus);
+
+ if (bAdded) { // update user info
+ SetContactBasicInfoW(hContact, SCBIFSI_LOCK_CHANGES_EVENTS, (SCBIF_ID|SCBIF_GROUP_ID|SCBIF_FLAG|SCBIF_SERVER_FLAG|SCBIF_STATUS|SCBIF_NICK|SCBIF_PHONES),
+ dwID, dwGroupID, dwContactFlag, dwContactSeverFlags, dwTemp, "", wszNick, szCustomPhones);
+ // request user info from server
+ MraUpdateContactInfo(hContact);
+ }
+ else { //****deb - check group ID param
+ SetContactBasicInfoW(hContact, SCBIFSI_LOCK_CHANGES_EVENTS, (SCBIF_ID|SCBIF_GROUP_ID|SCBIF_SERVER_FLAG|SCBIF_STATUS),
+ dwID, dwGroupID, dwContactFlag, dwContactSeverFlags, dwTemp, "", wszNick, szCustomPhones);
+ if (wszNick.IsEmpty()) { // set the server-side nick
+ wszNick = GetContactNameW(hContact);
+ MraModifyContactW(hContact, dwID, dwContactFlag, dwGroupID, szEmail, wszNick, szCustomPhones);
+ }
+ }
- for (hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- if (GetContactBasicInfoW(hContact, &dwID, NULL, NULL, NULL, NULL, szEMail, SIZEOF(szEMail), &dwEMailSize, NULL, 0, NULL, NULL, 0, NULL) == NO_ERROR)
- if (dwID == -1) {
- if (IsEMailChatAgent(szEMail, dwEMailSize)) {// чат: ещё раз запросим авторизацию, пометим как видимый в списке, постоянный
- db_unset(hContact, "CList", "Hidden");
- db_unset(hContact, "CList", "NotOnList");
+ MraContactCapabilitiesSet(hContact, dwFutureFlags);
+ setByte(hContact, DBSETTING_XSTATUSID, (BYTE)dwXStatus);
+ mraSetStringW(hContact, DBSETTING_XSTATUSNAME, wszStatusTitle);
+ mraSetStringW(hContact, DBSETTING_XSTATUSMSG, wszStatusDesc);
+ setDword(hContact, DBSETTING_BLOGSTATUSTIME, dwBlogStatusTime);
+ mraWriteContactSettingBlob(hContact, DBSETTING_BLOGSTATUSID, &dwBlogStatusID.QuadPart, sizeof(DWORDLONG));
+ mraSetStringW(hContact, DBSETTING_BLOGSTATUS, wszBlogStatus);
+ mraSetStringW(hContact, DBSETTING_BLOGSTATUSMUSIC, wszBlogStatusMusic);
+ if ( IsXStatusValid(dwXStatus))
SetExtraIcons(hContact);
- MraSetContactStatus(hContact, ID_STATUS_ONLINE);
- lstrcpynW(szBuff, GetContactNameW(hContact), SIZEOF(szBuff));
- MraAddContactW(hContact, (CONTACT_FLAG_VISIBLE|CONTACT_FLAG_MULTICHAT|CONTACT_FLAG_UNICODE_NAME), -1, szEMail, dwEMailSize, szBuff, lstrlenW(szBuff), NULL, 0, NULL, 0, 0);
- }
- else {
- if (db_get_b(hContact, "CList", "NotOnList", 0) == 0) { // set extra icons and upload contact
- SetExtraIcons(hContact);
- if (getByte("AutoAddContactsToServer", MRA_DEFAULT_AUTO_ADD_CONTACTS_TO_SERVER)) { //add all contacts to server
- GetContactBasicInfoW(hContact, NULL, &dwGroupID, NULL, NULL, NULL, NULL, 0, NULL, wszNick, SIZEOF(wszNick), &dwNickSize, szPhones, SIZEOF(szPhones), &dwPhonesSize);
- MraAddContactW(hContact, (CONTACT_FLAG_VISIBLE|CONTACT_FLAG_UNICODE_NAME), dwGroupID, szEMail, dwEMailSize, wszNick, dwNickSize, szPhones, dwPhonesSize, wszAuthMessage, dwAuthMessageSize, 0);
- }
+ if (dwTemp != ID_STATUS_OFFLINE) { // пишем клиента только если юзер не отключён, иначе не затираем старое
+ if (szUserAgentFormatted.GetLength()) {
+ if (getByte("MirVerRaw", MRA_DEFAULT_MIRVER_RAW) == FALSE)
+ szUserAgentFormatted = MraGetVersionStringFromFormatted(szUserAgentFormatted);
}
+ else szUserAgentFormatted = MIRVER_UNKNOWN;
+ mraSetStringA(hContact, "MirVer", szUserAgentFormatted);
}
- MraUpdateContactInfo(hContact);
+
+ if (dwContactSeverFlags & CONTACT_INTFLAG_NOT_AUTHORIZED)
+ if (getByte("AutoAuthRequestOnLogon", MRA_DEFAULT_AUTO_AUTH_REQ_ON_LOGON))
+ CallProtoService(m_szModuleName, MRA_REQ_AUTH, (WPARAM)hContact, 0);
}
}
}
- }
- else { // контакт лист почемуто не получили
- // всех в offline и id в нестандарт
- for (HANDLE hContact = db_find_first();hContact != NULL;hContact = db_find_next(hContact)) {
- SetContactBasicInfoW(hContact, SCBIFSI_LOCK_CHANGES_EVENTS, (SCBIF_ID|SCBIF_GROUP_ID|SCBIF_SERVER_FLAG|SCBIF_STATUS), -1, -2, 0, 0, ID_STATUS_OFFLINE, NULL, 0, NULL, 0, NULL, 0);
- // request user info from server
- MraUpdateContactInfo(hContact);
- }
+ dwID++;
+ }// end while (processing contacts)
- if (dwTemp == GET_CONTACTS_ERROR) // найденный контакт-лист некорректен
- ShowFormattedErrorMessage(L"MRIM_CS_CONTACT_LIST2: bad contact list", NO_ERROR);
- else if (dwTemp == GET_CONTACTS_INTERR) // произошла внутренняя ошибка
- ShowFormattedErrorMessage(L"MRIM_CS_CONTACT_LIST2: internal server error", NO_ERROR);
- else {
- mir_sntprintf(szBuff, SIZEOF(szBuff), TranslateW(L"MRIM_CS_CONTACT_LIST2: unknown server error, code: %lu"), dwTemp);
- MraPopupShowFromAgentW(MRA_POPUP_TYPE_DEBUG, 0, szBuff);
+ // post processing contact list
+ {
+ CMStringA szEmail, szPhones;
+ CMStringW wszAuthMessage, wszNick;
+
+ if (mraGetStringW(NULL, "AuthMessage", wszAuthMessage) == FALSE) // def auth message
+ wszAuthMessage = TranslateW(MRA_DEFAULT_AUTH_MESSAGE);
+
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ if (GetContactBasicInfoW(hContact, &dwID, NULL, NULL, NULL, NULL, &szEmail, NULL, NULL) == NO_ERROR)
+ if (dwID == -1) {
+ if (IsEMailChatAgent(szEmail)) {// чат: ещё раз запросим авторизацию, пометим как видимый в списке, постоянный
+ db_unset(hContact, "CList", "Hidden");
+ db_unset(hContact, "CList", "NotOnList");
+ SetExtraIcons(hContact);
+ MraSetContactStatus(hContact, ID_STATUS_ONLINE);
+
+ CMStringW wszCustomName = GetContactNameW(hContact);
+ MraAddContactW(hContact, (CONTACT_FLAG_VISIBLE|CONTACT_FLAG_MULTICHAT|CONTACT_FLAG_UNICODE_NAME),
+ -1, szEmail, wszCustomName, "", L"", 0);
+ }
+ else {
+ if (db_get_b(hContact, "CList", "NotOnList", 0) == 0) { // set extra icons and upload contact
+ SetExtraIcons(hContact);
+ if (getByte("AutoAddContactsToServer", MRA_DEFAULT_AUTO_ADD_CONTACTS_TO_SERVER)) { //add all contacts to server
+ GetContactBasicInfoW(hContact, NULL, &dwGroupID, NULL, NULL, NULL, NULL, &wszNick, &szPhones);
+ MraAddContactW(hContact, (CONTACT_FLAG_VISIBLE|CONTACT_FLAG_UNICODE_NAME), dwGroupID, szEmail, wszNick, szPhones, wszAuthMessage, 0);
+ }
+ }
+ }
+ MraUpdateContactInfo(hContact);
+ }
}
}
- break;
+ }
+ else { // контакт лист почемуто не получили
+ // всех в offline и id в нестандарт
+ for (HANDLE hContact = db_find_first();hContact != NULL;hContact = db_find_next(hContact)) {
+ SetContactBasicInfoW(hContact, SCBIFSI_LOCK_CHANGES_EVENTS, (SCBIF_ID|SCBIF_GROUP_ID|SCBIF_SERVER_FLAG|SCBIF_STATUS),
+ -1, -2, 0, 0, ID_STATUS_OFFLINE, "", L"", "");
+ // request user info from server
+ MraUpdateContactInfo(hContact);
+ }
- case MRIM_CS_SMS_ACK:
- dwTemp = GetUL(&lpbDataCurrent);
- if ( MraSendQueueFind(hSendQueueHandle, pmaHeader->seq, NULL, &hContact, &dwAckType, (LPBYTE*)&lpsString.lpszData, &lpsString.dwSize) == NO_ERROR) {
- char szEMail[MAX_EMAIL_LEN];
- LPSTR lpszPhone;
- LPWSTR lpwszMessage;
- size_t dwEMailSize, dwPhoneSize, dwMessageSize;
-
- if (mraGetStaticStringA(NULL, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize)) {
- dwPhoneSize = (*(DWORD*)lpsString.lpszData);
- dwMessageSize = lpsString.dwSize-(dwPhoneSize+sizeof(DWORD)+2);
- lpszPhone = (lpsString.lpszData+sizeof(DWORD));
- 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);
- ProtoBroadcastAck(NULL, dwAckType, ACKRESULT_SENTREQUEST, (HANDLE)pmaHeader->seq, (LPARAM)szBuff);
- }
+ if (dwTemp == GET_CONTACTS_ERROR) // найденный контакт-лист некорректен
+ ShowFormattedErrorMessage(L"MRIM_CS_CONTACT_LIST2: bad contact list", NO_ERROR);
+ else if (dwTemp == GET_CONTACTS_INTERR) // произошла внутренняя ошибка
+ ShowFormattedErrorMessage(L"MRIM_CS_CONTACT_LIST2: internal server error", NO_ERROR);
+ else {
+ TCHAR szBuff[1024];
+ mir_sntprintf(szBuff, SIZEOF(szBuff), TranslateW(L"MRIM_CS_CONTACT_LIST2: unknown server error, code: %lu"), dwTemp);
+ MraPopupShowFromAgentW(MRA_POPUP_TYPE_DEBUG, 0, szBuff);
+ }
+ }
+ return true;
+}
- mir_free(lpsString.lpszData);
- MraSendQueueFree(hSendQueueHandle, pmaHeader->seq);
+bool CMraProto::CmdProxy(BinBuffer &buf)
+{
+ DWORD dwIDRequest, dwAckType;
+ CMStringA szAddresses, szEmail, szString;
+ MRA_GUID mguidSessionID;
+
+ buf >> szEmail >> dwIDRequest >> dwAckType >> szString >> szAddresses >> mguidSessionID;
+ if (dwAckType == MRIM_PROXY_TYPE_FILES) { // файлы, on file recv
+ // set proxy info to file transfer context
+ if ( !MraMrimProxySetData(MraFilesQueueItemProxyByID(hFilesQueueHandle, dwIDRequest), szEmail, dwIDRequest, dwAckType, szString, szAddresses, &mguidSessionID))
+ MraFilesQueueStartMrimProxy(hFilesQueueHandle, dwIDRequest);
+ else { // empty/invalid session
+ MraProxyAck(PROXY_STATUS_ERROR, szEmail, dwIDRequest, dwAckType, szString, szAddresses, mguidSessionID);
+ DebugBreak();
}
- else MraPopupShowFromAgentW(MRA_POPUP_TYPE_DEBUG, 0, TranslateW(L"MRIM_CS_SMS_ACK: not found in queue"));
- break;
+ }
+ return true;
+}
- case MRIM_CS_PROXY:
- {
- DWORD dwIDRequest;
- MRA_LPS lpsAddreses = {0};
- MRA_GUID mguidSessionID;
-
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsEMail);// LPS to
- dwIDRequest = GetUL(&lpbDataCurrent);// DWORD id_request
- dwAckType = GetUL(&lpbDataCurrent);// DWORD data_type
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);// LPS user_data
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsAddreses);// LPS lps_ip_port
- mguidSessionID = GetGUID(&lpbDataCurrent);// DWORD session_id[4]
-
- if (dwAckType == MRIM_PROXY_TYPE_FILES) { // файлы, on file recv
+bool CMraProto::CmdProxyAck(BinBuffer &buf)
+{
+ DWORD dwIDRequest, dwTemp, dwAckType;
+ HANDLE hMraMrimProxyData;
+ CMStringA szAddresses, szEmail, szString;
+ MRA_GUID mguidSessionID;
+ buf >> dwTemp >> szEmail >> dwIDRequest >> dwAckType >> szString >> szAddresses >> mguidSessionID;
+
+ if (dwAckType == MRIM_PROXY_TYPE_FILES) { // on file send
+ if ((hMraMrimProxyData = MraFilesQueueItemProxyByID(hFilesQueueHandle, dwIDRequest))) {
+ switch (dwTemp) {
+ case PROXY_STATUS_DECLINE:
+ MraFilesQueueCancel(hFilesQueueHandle, dwIDRequest, FALSE);
+ break;
+ case PROXY_STATUS_OK:
// set proxy info to file transfer context
- if ( !MraMrimProxySetData(MraFilesQueueItemProxyByID(hFilesQueueHandle, dwIDRequest), lpsEMail.lpszData, lpsEMail.dwSize, dwIDRequest, dwAckType, lpsString.lpszData, lpsString.dwSize, lpsAddreses.lpszData, lpsAddreses.dwSize, &mguidSessionID))
+ if ( !MraMrimProxySetData(hMraMrimProxyData, szEmail, dwIDRequest, dwAckType, szString, szAddresses, &mguidSessionID))
MraFilesQueueStartMrimProxy(hFilesQueueHandle, dwIDRequest);
- else { // empty/invalid session
- MraProxyAck(PROXY_STATUS_ERROR, lpsEMail.lpszData, lpsEMail.dwSize, dwIDRequest, dwAckType, lpsString.lpszData, lpsString.dwSize, lpsAddreses.lpszData, lpsAddreses.dwSize, mguidSessionID);
- DebugBreak();
- }
+ break;
+ case PROXY_STATUS_ERROR:
+ ShowFormattedErrorMessage(L"Proxy File transfer: error", NO_ERROR);
+ MraFilesQueueCancel(hFilesQueueHandle, dwIDRequest, FALSE);
+ break;
+ case PROXY_STATUS_INCOMPATIBLE_VERS:
+ ShowFormattedErrorMessage(L"Proxy File transfer: incompatible versions", NO_ERROR);
+ MraFilesQueueCancel(hFilesQueueHandle, dwIDRequest, FALSE);
+ break;
+ case PROXY_STATUS_NOHARDWARE:
+ case PROXY_STATUS_MIRROR:
+ case PROXY_STATUS_CLOSED:
+ default:
+ DebugBreak();
+ break;
}
}
- break;
+ else DebugBreak();
+ }
+ return true;
+}
- case MRIM_CS_PROXY_ACK:
- {
- DWORD dwIDRequest;
- HANDLE hMraMrimProxyData;
- MRA_LPS lpsAddreses = {0};
- MRA_GUID mguidSessionID;
-
- dwTemp = GetUL(&lpbDataCurrent);// DWORD status
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsEMail);// LPS to
- dwIDRequest = GetUL(&lpbDataCurrent);// DWORD id_request
- dwAckType = GetUL(&lpbDataCurrent);// DWORD data_type
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);// LPS user_data
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsAddreses);// LPS lps_ip_port
- mguidSessionID = GetGUID(&lpbDataCurrent);// DWORD session_id[4]
-
- if (dwAckType == MRIM_PROXY_TYPE_FILES) { // on file send
- if ((hMraMrimProxyData = MraFilesQueueItemProxyByID(hFilesQueueHandle, dwIDRequest))) {
- switch (dwTemp) {
- case PROXY_STATUS_DECLINE:
- MraFilesQueueCancel(hFilesQueueHandle, dwIDRequest, FALSE);
- break;
- case PROXY_STATUS_OK:
- // set proxy info to file transfer context
- if ( !MraMrimProxySetData(hMraMrimProxyData, lpsEMail.lpszData, lpsEMail.dwSize, dwIDRequest, dwAckType, lpsString.lpszData, lpsString.dwSize, lpsAddreses.lpszData, lpsAddreses.dwSize, &mguidSessionID))
- MraFilesQueueStartMrimProxy(hFilesQueueHandle, dwIDRequest);
- break;
- case PROXY_STATUS_ERROR:
- ShowFormattedErrorMessage(L"Proxy File transfer: error", NO_ERROR);
- MraFilesQueueCancel(hFilesQueueHandle, dwIDRequest, FALSE);
- break;
- case PROXY_STATUS_INCOMPATIBLE_VERS:
- ShowFormattedErrorMessage(L"Proxy File transfer: incompatible versions", NO_ERROR);
- MraFilesQueueCancel(hFilesQueueHandle, dwIDRequest, FALSE);
- break;
- case PROXY_STATUS_NOHARDWARE:
- case PROXY_STATUS_MIRROR:
- case PROXY_STATUS_CLOSED:
- default:
- DebugBreak();
- break;
- }
- }
- else DebugBreak();
- }
+bool CMraProto::CmdNewMail(BinBuffer &buf)
+{
+ DWORD dwDate, dwUIDL, dwUnreadCount;
+ CMStringA szEmail, szString;
+ buf >> dwUnreadCount >> szEmail >> szString >> dwDate >> dwUIDL;
+
+ if (dwUnreadCount > dwEmailMessagesTotal)
+ dwEmailMessagesTotal += (dwUnreadCount - m_dwEmailMessagesUnread);
+
+ DWORD dwSave = m_dwEmailMessagesUnread;
+ m_dwEmailMessagesUnread = dwUnreadCount;// store new value
+ if (getByte("IncrementalNewMailNotify", MRA_DEFAULT_INC_NEW_MAIL_NOTIFY) == 0 || dwSave < dwUnreadCount || dwUnreadCount == 0)
+ MraUpdateEmailStatus(szEmail, szString, dwDate, dwUIDL);
+ return true;
+}
+
+bool CMraProto::CmdBlogStatus(BinBuffer &buf)
+{
+ DWORD dwTime, dwFlags;
+ CMStringA szEmail, szString;
+ CMStringW lpsText;
+ DWORDLONG dwBlogStatusID;
+
+ buf >> dwFlags >> szEmail >> dwBlogStatusID >> dwTime >> lpsText >> szString;
+
+ if (HANDLE hContact = MraHContactFromEmail(szEmail, FALSE, TRUE, NULL)) {
+ if (dwFlags & MRIM_BLOG_STATUS_MUSIC)
+ mraSetStringW(hContact, DBSETTING_BLOGSTATUSMUSIC, lpsText);
+ else {
+ setDword(hContact, DBSETTING_BLOGSTATUSTIME, dwTime);
+ mraWriteContactSettingBlob(hContact, DBSETTING_BLOGSTATUSID, &dwBlogStatusID, sizeof(DWORDLONG));
+ mraSetStringW(hContact, DBSETTING_BLOGSTATUS, lpsText);
}
- break;
+ }
+ return true;
+}
- case MRIM_CS_PROXY_HELLO:
- // DWORD[4] Session_id
- DebugBreak();
- break;
+bool CMraProto::MraCommandDispatcher(mrim_packet_header_t *pmaHeader)
+{
+ WCHAR szBuff[4096] = {0};
+ DWORD dwTemp, dwAckType;
+ size_t dwSize;
+ HANDLE hContact = NULL;
+ LPBYTE pByte;
- case MRIM_CS_PROXY_HELLO_ACK:
- DebugBreak();
- break;
+ Netlib_Logf(m_hNetlibUser, "Received packet %x\n", pmaHeader->msg);
- case MRIM_CS_NEW_MAIL:
- {
- DWORD dwDate, dwUIDL;
+ BinBuffer buf((LPBYTE)pmaHeader + sizeof(mrim_packet_header_t), pmaHeader->dlen);
- dwTemp = GetUL(&lpbDataCurrent);// UL unread count
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsEMail);// LPS from
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);// LPS subject
- dwDate = GetUL(&lpbDataCurrent);// UL date
- dwUIDL = GetUL(&lpbDataCurrent);// UL uidl
+ switch (pmaHeader->msg) {
+ case MRIM_CS_HELLO_ACK: return CmdHelloAck(buf);
+ case MRIM_CS_LOGIN_ACK: return CmdLoginAck();
+ case MRIM_CS_LOGIN_REJ: return CmdLoginRejected(buf);
+ case MRIM_CS_MESSAGE_ACK: return CmdMessageAck(buf);
+ case MRIM_CS_MESSAGE_STATUS: return CmdMessageStatus(pmaHeader->seq, buf);
+ case MRIM_CS_USER_INFO: return CmdUserInfo(buf);
+ case MRIM_CS_OFFLINE_MESSAGE_ACK: return CmdOfflineMessageAck(buf);
+ case MRIM_CS_AUTHORIZE_ACK: return CmdAuthAck(buf);
+ case MRIM_CS_MPOP_SESSION: return CmdPopSession(buf);
+ case MRIM_CS_FILE_TRANSFER: return CmdFileTransfer(buf);
+ case MRIM_CS_FILE_TRANSFER_ACK: return CmdFileTransferAck(buf);
+ case MRIM_CS_USER_STATUS: return CmdUserStatus(buf);
+ case MRIM_CS_ADD_CONTACT_ACK:
+ case MRIM_CS_MODIFY_CONTACT_ACK: return CmdContactAck(pmaHeader->msg, pmaHeader->seq, buf);
+ case MRIM_CS_ANKETA_INFO: return CmdAnketaInfo(pmaHeader->seq, buf);
+ case MRIM_CS_GAME: return CmdGame(buf);
+ case MRIM_CS_CONTACT_LIST2: return CmdClist2(buf);
+ case MRIM_CS_PROXY: return CmdProxy(buf);
+ case MRIM_CS_PROXY_ACK: return CmdProxyAck(buf);
+ case MRIM_CS_NEW_MAIL: return CmdNewMail(buf);
+ case MRIM_CS_USER_BLOG_STATUS: return CmdBlogStatus(buf);
+
+ case MRIM_CS_CONNECTION_PARAMS:// Изменение параметров соединения
+ buf >> m_dwPingPeriod;
+ m_dwNextPingSendTickTime = 0; // force send ping
+ MraSendCMD(MRIM_CS_PING, NULL, 0);
+ break;
- if (dwTemp > dwEmailMessagesTotal)
- dwEmailMessagesTotal += (dwTemp-dwEmailMessagesUnread);
+ case MRIM_CS_LOGOUT:// Пользователь отключен из-за параллельного входа с его логином.
+ buf >> dwTemp;
+ if (dwTemp == LOGOUT_NO_RELOGIN_FLAG)
+ ShowFormattedErrorMessage(L"Another user connected with your login", NO_ERROR);
+ return false;
- dwAckType = dwEmailMessagesUnread;// save old value
- dwEmailMessagesUnread = dwTemp;// store new value
- if (getByte("IncrementalNewMailNotify", MRA_DEFAULT_INC_NEW_MAIL_NOTIFY) == 0 || dwAckType<dwTemp || dwTemp == 0)
- MraUpdateEmailStatus(lpsEMail.lpszData, lpsEMail.dwSize, lpsString.lpszData, lpsString.dwSize, dwDate, dwUIDL);
- }
+ case MRIM_CS_MAILBOX_STATUS:
+ buf >> dwTemp;
+ if (dwTemp > dwEmailMessagesTotal)
+ dwEmailMessagesTotal += (dwTemp - m_dwEmailMessagesUnread);
+
+ dwAckType = m_dwEmailMessagesUnread;// save old value
+ m_dwEmailMessagesUnread = dwTemp;// store new value
+ if (getByte("IncrementalNewMailNotify", MRA_DEFAULT_INC_NEW_MAIL_NOTIFY) == 0 || dwAckType<dwTemp || dwTemp == 0)
+ MraUpdateEmailStatus("", "", 0, 0);
break;
- case MRIM_CS_USER_BLOG_STATUS:
- {
- DWORD dwTime, dwFlags;
- MRA_LPS lpsText;
- LPBYTE lpbBuff = NULL;
- DWORDLONG dwBlogStatusID;
-
- dwFlags = GetUL(&lpbDataCurrent);// UL flags
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsEMail);// LPS user
- dwBlogStatusID = GetUIDL(&lpbDataCurrent);// UINT64 id
- dwTime = GetUL(&lpbDataCurrent);// UL time
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsText);// LPS text (MRIM_BLOG_STATUS_MUSIC: track)
- GetLPS(lpbData, dwDataSize, &lpbDataCurrent, &lpsString);// LPS reply_user_nick
-
- if ((hContact = MraHContactFromEmail(lpsEMail.lpszData, lpsEMail.dwSize, FALSE, TRUE, NULL))) {
- if (dwFlags & MRIM_BLOG_STATUS_MUSIC)
- mraSetLPSStringW(hContact, DBSETTING_BLOGSTATUSMUSIC, &lpsText);
- else {
- setDword(hContact, DBSETTING_BLOGSTATUSTIME, dwTime);
- mraWriteContactSettingBlob(hContact, DBSETTING_BLOGSTATUSID, &dwBlogStatusID, sizeof(DWORDLONG));
- mraSetLPSStringW(hContact, DBSETTING_BLOGSTATUS, &lpsText);
- }
+ case MRIM_CS_SMS_ACK:
+ buf >> dwTemp;
+ if ( MraSendQueueFind(hSendQueueHandle, pmaHeader->seq, NULL, &hContact, &dwAckType, &pByte, &dwSize) == NO_ERROR) {
+ CMStringA szEmail;
+ if (mraGetStringA(NULL, "e-mail", szEmail)) {
+ DWORD dwPhoneSize = *(DWORD*)pByte;
+ DWORD dwMessageSize = dwSize-(dwPhoneSize+sizeof(DWORD)+2);
+ LPSTR lpszPhone = (LPSTR)pByte + sizeof(DWORD);
+ LPWSTR lpwszMessage = (LPWSTR)(lpszPhone + dwPhoneSize + 1);
+
+ 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.c_str(), lpszPhone, lpszPhone);
+ ProtoBroadcastAck(NULL, dwAckType, ACKRESULT_SENTREQUEST, (HANDLE)pmaHeader->seq, (LPARAM)szBuff);
}
+
+ mir_free(pByte);
+ MraSendQueueFree(hSendQueueHandle, pmaHeader->seq);
}
+ else MraPopupShowFromAgentW(MRA_POPUP_TYPE_DEBUG, 0, TranslateW(L"MRIM_CS_SMS_ACK: not found in queue"));
+ break;
+
+ case MRIM_CS_PROXY_HELLO:
+ DebugBreak();
+ break;
+
+ case MRIM_CS_PROXY_HELLO_ACK:
+ DebugBreak();
break;
case MRIM_CS_UNKNOWN:
@@ -1720,380 +1605,290 @@ DWORD CMraProto::MraCommandDispatcher(mrim_packet_header_t *pmaHeader, DWORD *pd
default:
#ifdef _DEBUG
- BYTE btBuff[8192] = {0};
- memmove(btBuff, lpbData, dwDataSize);
DebugBreak();
#endif
break;
}
- return 0;
+ return true;
}
-DWORD CMraProto::MraRecvCommand_Message(DWORD dwTime, DWORD dwFlags, MRA_LPS *plpsFrom, MRA_LPS *plpsText, MRA_LPS *plpsRFTText, MRA_LPS *plpsMultiChatData)
-{// Сообщение
- BOOL bAdded;
+// Сообщение
+DWORD CMraProto::MraRecvCommand_Message(DWORD dwTime, DWORD dwFlags, CMStringA &plpsFrom, CMStringA &plpsText, CMStringA &plpsRFTText, CMStringA &plpsMultiChatData)
+{
DWORD dwRetErrorCode = NO_ERROR, dwBackColour;
- LPSTR lpszMessageExt = NULL;
- LPWSTR lpwszMessage = NULL;
- size_t dwMessageSize = 0, dwMessageExtSize = 0;
+ CMStringA lpszMessageExt;
+ CMStringW wszMessage;
PROTORECVEVENT pre = {0};
pre.timestamp = dwTime;
// check flags and datas
- if (dwFlags & MESSAGE_FLAG_RTF) {
- if (plpsRFTText) {
- if (plpsRFTText->lpszData == NULL || plpsRFTText->dwSize == 0)
- dwFlags &= ~MESSAGE_FLAG_RTF;
- }
- else dwFlags &= ~MESSAGE_FLAG_RTF;
- }
+ if ((dwFlags & MESSAGE_FLAG_RTF) && plpsRFTText.IsEmpty())
+ dwFlags &= ~MESSAGE_FLAG_RTF;
- if (dwFlags & MESSAGE_FLAG_MULTICHAT) {
- if (plpsMultiChatData) {
- if (plpsMultiChatData->lpszData == NULL || plpsMultiChatData->dwSize == 0)
- dwFlags &= ~MESSAGE_FLAG_MULTICHAT;
- }
- else dwFlags &= ~MESSAGE_FLAG_MULTICHAT;
- }
+ if ((dwFlags & MESSAGE_FLAG_MULTICHAT) && plpsMultiChatData.IsEmpty())
+ dwFlags &= ~MESSAGE_FLAG_MULTICHAT;
// pre processing - extracting/decoding
if (dwFlags & MESSAGE_FLAG_AUTHORIZE) { // extract auth message из обычного текста
- size_t dwAuthPartsCount, dwAuthBuffSize = (plpsText->dwSize+32);
- LPBYTE lpbDataCurrent;
- MRA_LPS lpsAuthFrom, lpsAuthMessage;
-
- LPS2ANSI(szText, plpsText->lpszData, plpsText->dwSize);
unsigned dwAuthDataSize;
- LPBYTE lpbAuthData = (LPBYTE)mir_base64_decode(szText, &dwAuthDataSize);
+ LPBYTE lpbAuthData = (LPBYTE)mir_base64_decode(plpsText, &dwAuthDataSize);
if (lpbAuthData) {
- lpbDataCurrent = lpbAuthData;
- dwAuthPartsCount = GetUL(&lpbDataCurrent);
- if ( !GetLPS(lpbAuthData, dwAuthDataSize, &lpbDataCurrent, &lpsAuthFrom))
- if ( !GetLPS(lpbAuthData, dwAuthDataSize, &lpbDataCurrent, &lpsAuthMessage)) {
- if (dwFlags&MESSAGE_FLAG_v1p16 && (dwFlags&MESSAGE_FLAG_CP1251) == 0) { // unicode text
- memmove(lpbAuthData, lpsAuthMessage.lpszData, lpsAuthMessage.dwSize);
- lpwszMessage = (LPWSTR)lpbAuthData;
- dwMessageSize = (lpsAuthMessage.dwSize/sizeof(WCHAR));
- }
- else { // преобразуем в юникод текст только если он в АНСИ и если это не Флэш мультик и будильник тоже не нуждается в этом
- lpwszMessage = (LPWSTR)mir_calloc(((lpsAuthMessage.dwSize+MAX_PATH)*sizeof(WCHAR)));
- if (lpwszMessage) {
- dwMessageSize = MultiByteToWideChar(MRA_CODE_PAGE, 0, lpsAuthMessage.lpszData, lpsAuthMessage.dwSize, lpwszMessage, (lpsAuthMessage.dwSize+MAX_PATH));
- (*(lpwszMessage+dwMessageSize)) = 0;
- }
- else dwRetErrorCode = GetLastError();
- }
+ BinBuffer buf(lpbAuthData, dwAuthDataSize);
+
+ DWORD dwAuthPartsCount;
+ CMStringA lpsAuthFrom;
+ buf >> dwAuthPartsCount >> lpsAuthFrom;
+ if (dwFlags & MESSAGE_FLAG_v1p16 && (dwFlags & MESSAGE_FLAG_CP1251) == 0) { // unicode text
+ CMStringW lpsAuthMessageW;
+ buf >> lpsAuthMessageW;
+ wszMessage = lpsAuthMessageW;
+ }
+ else { // преобразуем в юникод текст только если он в АНСИ и если это не Флэш мультик и будильник тоже не нуждается в этом
+ CMStringA lpsAuthMessage;
+ buf >> lpsAuthMessage;
+ wszMessage = ptrW( mir_a2u_cp(lpsAuthMessage, MRA_CODE_PAGE));
}
- if (lpwszMessage != (LPWSTR)lpbAuthData)
- mir_free(lpbAuthData);
+ mir_free(lpbAuthData);
}
}
else {
// unicode text
if ((dwFlags & (MESSAGE_FLAG_ALARM|MESSAGE_FLAG_FLASH|MESSAGE_FLAG_v1p16)) && (dwFlags & MESSAGE_FLAG_CP1251) == 0) {
- lpwszMessage = plpsText->lpwszData;
- dwMessageSize = (plpsText->dwSize/sizeof(WCHAR));
- }
- else {
- lpwszMessage = (LPWSTR)mir_calloc(((plpsText->dwSize+MAX_PATH)*sizeof(WCHAR)));
- if (lpwszMessage) {
- dwMessageSize = MultiByteToWideChar(MRA_CODE_PAGE, 0, plpsText->lpszData, plpsText->dwSize, lpwszMessage, (plpsText->dwSize+MAX_PATH));
- (*(lpwszMessage+dwMessageSize)) = 0;
- }
- else dwRetErrorCode = GetLastError();
+ plpsText.AppendChar(0); // compensate difference between ASCIIZ & WCHARZ
+ wszMessage = (WCHAR*)plpsText.GetString();
}
+ else wszMessage = plpsText;
if (dwFlags & (MESSAGE_FLAG_CONTACT|MESSAGE_FLAG_NOTIFY|MESSAGE_FLAG_SMS|MESSAGE_SMS_DELIVERY_REPORT|MESSAGE_FLAG_ALARM))
; // do nothing; there's no extra part in a message
else {
- if ((dwFlags & MESSAGE_FLAG_RTF) && plpsRFTText) //MESSAGE_FLAG_FLASH there
- if (plpsRFTText->lpszData && plpsRFTText->dwSize) { // decode RTF
- size_t dwRTFPartsCount, dwRFTBuffSize = ((plpsRFTText->dwSize*16)+8192), dwRTFDataSize;
- LPBYTE lpbDataCurrent;
- MRA_LPS lpsRTFString, lpsBackColour, lpsString;
+ if ((dwFlags & MESSAGE_FLAG_RTF) && !plpsRFTText.IsEmpty()) { //MESSAGE_FLAG_FLASH there
+ size_t dwRFTBuffSize = ((plpsRFTText.GetLength()*16)+8192);
mir_ptr<BYTE> lpbRTFData((LPBYTE)mir_calloc(dwRFTBuffSize));
if (lpbRTFData) {
- LPS2ANSI(szRtf, plpsRFTText->lpszData, plpsRFTText->dwSize);
unsigned dwCompressedSize;
- mir_ptr<BYTE> lpbCompressed((LPBYTE)mir_base64_decode(szRtf, &dwCompressedSize));
- dwRTFDataSize = dwRFTBuffSize;
- if ( uncompress(lpbRTFData, (DWORD*)&dwRTFDataSize, lpbCompressed, dwCompressedSize) == Z_OK) {
- lpbDataCurrent = lpbRTFData;
- dwRTFPartsCount = GetUL(&lpbDataCurrent);// колличество частей в некоторых случаях больше 2, тогда нужно игнорировать первый текст, тк там сообщения об ущербности
- if (GetLPS(lpbRTFData, dwRTFDataSize, &lpbDataCurrent, &lpsRTFString) == NO_ERROR)
- if (GetLPS(lpbRTFData, dwRTFDataSize, &lpbDataCurrent, &lpsBackColour) == NO_ERROR) {
- dwBackColour = (*(DWORD*)lpsBackColour.lpszData);
- if (dwFlags & MESSAGE_FLAG_FLASH) {
- if (dwRTFPartsCount == 3) { // ansi text only
- GetLPS(lpbRTFData, dwRTFDataSize, &lpbDataCurrent, &lpsString);
- lpwszMessage = (LPWSTR)mir_calloc(((lpsString.dwSize+MAX_PATH)*sizeof(WCHAR)));
- if (lpwszMessage) {
- memmove(lpwszMessage, lpsString.lpszData, lpsString.dwSize);
- dwMessageSize = MultiByteToWideChar(MRA_CODE_PAGE, 0, lpsString.lpszData, lpsString.dwSize, lpwszMessage, (lpsString.dwSize+MAX_PATH));
- (*(lpwszMessage+dwMessageSize)) = 0;
- }
- else dwRetErrorCode = GetLastError();
- }
- else if (dwRTFPartsCount == 4) {
- GetLPS(lpbRTFData, dwRTFDataSize, &lpbDataCurrent, &lpsString);
- GetLPS(lpbRTFData, dwRTFDataSize, &lpbDataCurrent, &lpsString);
- lpwszMessage = (LPWSTR)mir_calloc(lpsString.dwSize);
- if (lpwszMessage) {
- memmove(lpwszMessage, lpsString.lpszData, lpsString.dwSize);
- dwMessageSize = lpsString.dwSize;
- }
- else dwRetErrorCode = GetLastError();
- }
- else DebugBreak();
+ mir_ptr<BYTE> lpbCompressed((LPBYTE)mir_base64_decode(plpsRFTText, &dwCompressedSize));
+ DWORD dwRTFDataSize = dwRFTBuffSize;
+ if ( uncompress(lpbRTFData, &dwRTFDataSize, lpbCompressed, dwCompressedSize) == Z_OK) {
+ BinBuffer buf(lpbRTFData, dwRTFDataSize);
+
+ CMStringA lpsRTFString, lpsBackColour, szString;
+ DWORD dwRTFPartsCount;
+
+ // количество частей в некоторых случаях больше 2, тогда нужно игнорировать первый текст, тк там сообщения об ущербности
+ buf >> dwRTFPartsCount >> lpsRTFString >> dwBackColour;
+ if (dwFlags & MESSAGE_FLAG_FLASH) {
+ if (dwRTFPartsCount == 4) {
+ buf >> szString;
+ dwRTFPartsCount--;
}
- else { // RTF text
- if (dwRTFPartsCount > 2) {
- GetLPS(lpbRTFData, dwRTFDataSize, &lpbDataCurrent, &lpsString);
- DebugBreak();
- }
-
- lpszMessageExt = (LPSTR)mir_calloc(lpsRTFString.dwSize);
- if (lpszMessageExt) {
- memmove(lpszMessageExt, lpsRTFString.lpszData, lpsRTFString.dwSize);
- dwMessageExtSize = lpsRTFString.dwSize;
- }
- else DebugBreak();
+ if (dwRTFPartsCount == 3) { // ansi text only
+ buf >> szString;
+ wszMessage = ptrW(mir_a2u_cp(szString, MRA_CODE_PAGE));
}
+ else DebugBreak();
+ }
+ else { // RTF text
+ if (dwRTFPartsCount > 2) {
+ buf >> szString;
+ DebugBreak();
+ }
+
+ lpszMessageExt = lpsRTFString;
}
- }else {
- mir_free(lpszMessageExt);
- dwMessageExtSize = 0;
- DebugBreak();
}
+ else DebugBreak();
}
}
}
}
- Netlib_Logf(hNetlibUser, "Processing message: %08X, from '%s', text '%S'\n", dwFlags, plpsFrom->lpszData, lpwszMessage);
+ Netlib_Logf(m_hNetlibUser, "Processing message: %08X, from '%s', text '%S'\n", dwFlags, plpsFrom.c_str(), wszMessage.c_str());
// processing
if (dwRetErrorCode == NO_ERROR)
- if (MraAntiSpamReceivedMessageW(plpsFrom->lpszData, plpsFrom->dwSize, dwFlags, lpwszMessage, dwMessageSize) == MESSAGE_NOT_SPAM) {
- if (dwFlags & (MESSAGE_FLAG_SMS | MESSAGE_SMS_DELIVERY_REPORT)) {// SMS //if (IsPhone(plpsFrom->lpszData, plpsFrom->dwSize))
- char szPhone[MAX_EMAIL_LEN], szEMail[MAX_EMAIL_LEN], szTime[MAX_PATH];
- LPSTR lpszMessageUTF, lpszBuff;
- LPWSTR lpwszMessageXMLEncoded;
- size_t dwBuffLen, dwMessageXMLEncodedSize;
- INTERNET_TIME itTime;
-
- dwBuffLen = ((dwMessageSize+MAX_PATH)*6);
- lpszMessageUTF = (LPSTR)mir_calloc(dwBuffLen);
- lpwszMessageXMLEncoded = (LPWSTR)mir_calloc((dwBuffLen*sizeof(WCHAR)));
- if (lpszMessageUTF && lpwszMessageXMLEncoded) {
- InternetTimeGetCurrentTime(&itTime);
- InternetTimeGetString(&itTime, szTime, SIZEOF(szTime), NULL);
- CopyNumber(szPhone, plpsFrom->lpszData, plpsFrom->dwSize);
- mraGetStaticStringA(NULL, "e-mail", szEMail, SIZEOF(szEMail), NULL);
-
- EncodeXML(lpwszMessage, dwMessageSize, lpwszMessageXMLEncoded, dwBuffLen, &dwMessageXMLEncodedSize);
- WideCharToMultiByte(CP_UTF8, 0, lpwszMessageXMLEncoded, dwMessageXMLEncodedSize, lpszMessageUTF, dwBuffLen, NULL, NULL);
- lpszBuff = (LPSTR)lpwszMessageXMLEncoded;
-
- 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);
- ProtoBroadcastAck(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);
- ProtoBroadcastAck(NULL, ICQACKTYPE_SMS, ACKRESULT_SUCCESS, (HANDLE)0, (LPARAM)lpszBuff);
- }
- }
- else dwRetErrorCode = GetLastError();
-
- mir_free(lpwszMessageXMLEncoded);
- mir_free(lpszMessageUTF);
+ if (MraAntiSpamReceivedMessageW(plpsFrom, dwFlags, wszMessage) != MESSAGE_NOT_SPAM)
+ return ERROR_ACCESS_DENIED;
+
+ if (dwFlags & (MESSAGE_FLAG_SMS | MESSAGE_SMS_DELIVERY_REPORT)) {// SMS //if (IsPhone(plpsFrom->lpszData, plpsFrom->dwSize))
+ INTERNET_TIME itTime;
+ InternetTimeGetCurrentTime(&itTime);
+ CMStringA szTime = InternetTimeGetString(&itTime);
+ CMStringA szPhone = CopyNumber(plpsFrom), szEmail;
+ mraGetStringA(NULL, "e-mail", szEmail);
+
+ CMStringW wszMessageXMLEncoded = EncodeXML(wszMessage);
+ ptrA lpszMessageUTF( mir_utf8encodeW(wszMessageXMLEncoded));
+
+ CMStringA szText;
+ if (dwFlags & MESSAGE_SMS_DELIVERY_REPORT) {
+ szText.Format("<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);
+ ProtoBroadcastAck(NULL, ICQACKTYPE_SMS, ACKRESULT_FAILED, 0, (LPARAM)szText.GetString());
}
- else {
- HANDLE hContact = MraHContactFromEmail(plpsFrom->lpszData, plpsFrom->dwSize, TRUE, TRUE, &bAdded);
- if (bAdded)
- MraUpdateContactInfo(hContact);
-
- // user typing
- if (dwFlags & MESSAGE_FLAG_NOTIFY)
- CallService(MS_PROTO_CONTACTISTYPING, (WPARAM)hContact, MAILRU_CONTACTISTYPING_TIMEOUT);
- else { // text/contact/auth // typing OFF
- CallService(MS_PROTO_CONTACTISTYPING, (WPARAM)hContact, PROTOTYPE_CONTACTTYPING_OFF);
-
- if (dwFlags & MESSAGE_FLAG_MULTICHAT) {
- LPBYTE lpbMultiChatData, lpbDataCurrent;
- size_t dwMultiChatDataSize;
- DWORD dwMultiChatEventType;
- MRA_LPS lpsEMailInMultiChat, lpsString, lpsMultichatName;
-
- lpbMultiChatData = (LPBYTE)plpsMultiChatData->lpszData;
- dwMultiChatDataSize = plpsMultiChatData->dwSize;
- lpbDataCurrent = lpbMultiChatData;
-
- dwMultiChatEventType = GetUL(&lpbDataCurrent);// type
- GetLPS(lpbMultiChatData, dwMultiChatDataSize, &lpbDataCurrent, &lpsMultichatName);// multichat_name
- GetLPS(lpbMultiChatData, dwMultiChatDataSize, &lpbDataCurrent, &lpsEMailInMultiChat);
-
- switch (dwMultiChatEventType) {
- case MULTICHAT_MESSAGE:
- MraChatSessionMessageAdd(hContact, lpsEMailInMultiChat.lpszData, lpsEMailInMultiChat.dwSize, lpwszMessage, dwMessageSize, dwTime);// LPS sender
- break;
- case MULTICHAT_ADD_MEMBERS:
- MraChatSessionMembersAdd(hContact, lpsEMailInMultiChat.lpszData, lpsEMailInMultiChat.dwSize, dwTime);// LPS sender
- GetLPS(lpbMultiChatData, dwMultiChatDataSize, &lpbDataCurrent, &lpsString);// CLPS members
- MraChatSessionSetIviter(hContact, lpsEMailInMultiChat.lpszData, lpsEMailInMultiChat.dwSize);
- case MULTICHAT_MEMBERS:
- {
- LPBYTE lpbMultiChatDataLocal, lpbDataCurrentLocal;
- size_t i, dwMultiChatMembersCount, dwMultiChatDataLocalSize;
-
- if (dwMultiChatEventType == MULTICHAT_MEMBERS) lpsString = lpsEMailInMultiChat;
-
- lpbMultiChatDataLocal = (LPBYTE)lpsString.lpszData;
- dwMultiChatDataLocalSize = lpsString.dwSize;
- lpbDataCurrentLocal = lpbMultiChatDataLocal;
-
- dwMultiChatMembersCount = GetUL(&lpbDataCurrentLocal);// count
- for (i = 0; i < dwMultiChatMembersCount; i++)
- if (GetLPS(lpbMultiChatDataLocal, dwMultiChatDataLocalSize, &lpbDataCurrentLocal, &lpsString) == NO_ERROR)
- MraChatSessionJoinUser(hContact, lpsString.lpszData, lpsString.dwSize, ((dwMultiChatEventType == MULTICHAT_MEMBERS)? 0:dwTime));
-
- if (dwMultiChatEventType == MULTICHAT_MEMBERS) {
- GetLPS(lpbMultiChatData, dwMultiChatDataSize, &lpbDataCurrent, &lpsEMailInMultiChat);// [ LPS owner ]
- MraChatSessionSetOwner(hContact, lpsEMailInMultiChat.lpszData, lpsEMailInMultiChat.dwSize);
- }
+ else { // new sms
+ szText.Format("<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);
+ ProtoBroadcastAck(NULL, ICQACKTYPE_SMS, ACKRESULT_SUCCESS, 0, (LPARAM)szText.GetString());
+ }
+ }
+ else {
+ BOOL bAdded;
+ HANDLE hContact = MraHContactFromEmail(plpsFrom, TRUE, TRUE, &bAdded);
+ if (bAdded)
+ MraUpdateContactInfo(hContact);
+
+ // user typing
+ if (dwFlags & MESSAGE_FLAG_NOTIFY)
+ CallService(MS_PROTO_CONTACTISTYPING, (WPARAM)hContact, MAILRU_CONTACTISTYPING_TIMEOUT);
+ else { // text/contact/auth // typing OFF
+ CallService(MS_PROTO_CONTACTISTYPING, (WPARAM)hContact, PROTOTYPE_CONTACTTYPING_OFF);
+
+ if (dwFlags & MESSAGE_FLAG_MULTICHAT) {
+ DWORD dwMultiChatEventType;
+ CMStringA lpsEMailInMultiChat, szString;
+ CMStringW lpsMultichatName;
+
+ BinBuffer buf((PBYTE)plpsMultiChatData.GetString(), plpsMultiChatData.GetLength());
+ buf >> dwMultiChatEventType >> lpsMultichatName >> lpsEMailInMultiChat;
+
+ switch (dwMultiChatEventType) {
+ case MULTICHAT_MESSAGE:
+ MraChatSessionMessageAdd(hContact, lpsEMailInMultiChat, wszMessage, dwTime);// LPS sender
+ break;
+ case MULTICHAT_ADD_MEMBERS:
+ MraChatSessionMembersAdd(hContact, lpsEMailInMultiChat, dwTime);// LPS sender
+ buf >> szString;// CLPS members
+ MraChatSessionSetIviter(hContact, lpsEMailInMultiChat);
+ case MULTICHAT_MEMBERS:
+ {
+ DWORD dwMultiChatMembersCount;
+ BinBuffer buf((PBYTE)lpsEMailInMultiChat.GetString(), lpsEMailInMultiChat.GetLength());
+ buf >> dwMultiChatMembersCount;// count
+ for (unsigned i = 0; i < dwMultiChatMembersCount && buf.m_len > 0; i++) {
+ buf >> szString;
+ MraChatSessionJoinUser(hContact, szString, ((dwMultiChatEventType == MULTICHAT_MEMBERS) ? 0 : dwTime));
+ }
+
+ if (dwMultiChatEventType == MULTICHAT_MEMBERS) {
+ buf >> szString; // [ LPS owner ]
+ MraChatSessionSetOwner(hContact, szString);
}
- break;
- case MULTICHAT_ATTACHED:
- MraChatSessionJoinUser(hContact, lpsEMailInMultiChat.lpszData, lpsEMailInMultiChat.dwSize, dwTime);// LPS member
- break;
- case MULTICHAT_DETACHED:
- MraChatSessionLeftUser(hContact, lpsEMailInMultiChat.lpszData, lpsEMailInMultiChat.dwSize, dwTime);// LPS member
- break;
- case MULTICHAT_INVITE:
- MraChatSessionInvite(hContact, lpsEMailInMultiChat.lpszData, lpsEMailInMultiChat.dwSize, dwTime);// LPS sender
- MraAddContactW(hContact, (CONTACT_FLAG_VISIBLE|CONTACT_FLAG_MULTICHAT|CONTACT_FLAG_UNICODE_NAME), -1, plpsFrom->lpszData, plpsFrom->dwSize, lpsMultichatName.lpwszData, (lpsMultichatName.dwSize/sizeof(WCHAR)), NULL, 0, NULL, 0, 0);
- break;
- default:
- DebugBreak();
- break;
}
+ break;
+ case MULTICHAT_ATTACHED:
+ MraChatSessionJoinUser(hContact, lpsEMailInMultiChat, dwTime);// LPS member
+ break;
+ case MULTICHAT_DETACHED:
+ MraChatSessionLeftUser(hContact, lpsEMailInMultiChat, dwTime);// LPS member
+ break;
+ case MULTICHAT_INVITE:
+ MraChatSessionInvite(hContact, lpsEMailInMultiChat, dwTime);// LPS sender
+ MraAddContactW(hContact, (CONTACT_FLAG_VISIBLE|CONTACT_FLAG_MULTICHAT|CONTACT_FLAG_UNICODE_NAME), -1, plpsFrom, lpsMultichatName, "", L"", 0);
+ break;
+ default:
+ DebugBreak();
+ break;
}
- else if (dwFlags & MESSAGE_FLAG_AUTHORIZE) { // auth request
- BYTE btBuff[BUFF_SIZE_BLOB];
- BOOL bAutoGrantAuth = FALSE;
+ }
+ else if (dwFlags & MESSAGE_FLAG_AUTHORIZE) { // auth request
+ BOOL bAutoGrantAuth = FALSE;
- if ( IsEMailChatAgent(plpsFrom->lpszData, plpsFrom->dwSize))
- bAutoGrantAuth = FALSE;
- else {
- // temporary contact
- if (db_get_b(hContact, "CList", "NotOnList", 0)) {
- if (getByte("AutoAuthGrandNewUsers", MRA_DEFAULT_AUTO_AUTH_GRAND_NEW_USERS))
- bAutoGrantAuth = TRUE;
- }
- else if (getByte("AutoAuthGrandUsersInCList", MRA_DEFAULT_AUTO_AUTH_GRAND_IN_CLIST))
+ if ( IsEMailChatAgent(plpsFrom))
+ bAutoGrantAuth = FALSE;
+ else {
+ // temporary contact
+ if (db_get_b(hContact, "CList", "NotOnList", 0)) {
+ if (getByte("AutoAuthGrandNewUsers", MRA_DEFAULT_AUTO_AUTH_GRAND_NEW_USERS))
bAutoGrantAuth = TRUE;
}
+ else if (getByte("AutoAuthGrandUsersInCList", MRA_DEFAULT_AUTO_AUTH_GRAND_IN_CLIST))
+ bAutoGrantAuth = TRUE;
+ }
+
+ if (bAdded)
+ db_set_b(hContact, "CList", "Hidden", 1);
+
+ CMStringA szBlob = CreateBlobFromContact(hContact, wszMessage);
+ if (bAutoGrantAuth) { // auto grant auth
+ DBEVENTINFO dbei = { sizeof(dbei) };
+ dbei.szModule = m_szModuleName;
+ dbei.timestamp = _time32(NULL);
+ dbei.flags = DBEF_READ;
+ dbei.eventType = EVENTTYPE_AUTHREQUEST;
+ dbei.pBlob = (PBYTE)szBlob.c_str();
+ dbei.cbBlob = szBlob.GetLength();
+ db_event_add(0, &dbei);
+ MraAuthorize(plpsFrom);
+ }
+ else {
+ pre.szMessage = (LPSTR)szBlob.GetString();
+ pre.lParam = szBlob.GetLength();
+ ProtoChainRecv(hContact, PSR_AUTH, 0, (LPARAM)&pre);
+ }
+ }
+ else {
+ db_unset(hContact, "CList", "Hidden");
+
+ if (dwFlags & MESSAGE_FLAG_CONTACT) { // contacts received
+ ptrA lpbBuffer( mir_u2a_cp(wszMessage, MRA_CODE_PAGE));
+ pre.flags = 0;
+ pre.szMessage = (LPSTR)lpbBuffer;
+ pre.lParam = strlen(lpbBuffer);
+
+ LPSTR lpbBufferCurPos = lpbBuffer;
+ while (TRUE) { // цикл замены ; на 0
+ LPSTR lpbBufferCurPos = (LPSTR)MemoryFindByte((lpbBufferCurPos-(LPSTR)lpbBuffer), lpbBuffer, pre.lParam, ';');
+ if (!lpbBufferCurPos)
+ break;
- if (bAdded)
- db_set_b(hContact, "CList", "Hidden", 1);
-
- if (bAutoGrantAuth) { // auto grant auth
- DBEVENTINFO dbei = { sizeof(dbei) };
- dbei.szModule = m_szModuleName;
- dbei.timestamp = _time32(NULL);
- dbei.flags = DBEF_READ;
- dbei.eventType = EVENTTYPE_AUTHREQUEST;
- dbei.pBlob = (PBYTE)btBuff;
- CreateBlobFromContact(hContact, lpwszMessage, dwMessageSize, btBuff, SIZEOF(btBuff), (size_t*)&dbei.cbBlob);
- db_event_add(0, &dbei);
- MraAuthorize(plpsFrom->lpszData, plpsFrom->dwSize);
+ // found
+ (*lpbBufferCurPos) = 0;
+ lpbBufferCurPos++;
}
+ ProtoChainRecv(hContact, PSR_CONTACTS, 0, (LPARAM)&pre);
+ }
+ else if (dwFlags & MESSAGE_FLAG_ALARM) { // alarm
+ if (m_heNudgeReceived)
+ NotifyEventHooks(m_heNudgeReceived, (WPARAM)hContact, NULL);
else {
- pre.szMessage = (LPSTR)btBuff;
- CreateBlobFromContact(hContact, lpwszMessage, dwMessageSize, btBuff, SIZEOF(btBuff), (size_t*)&pre.lParam);
- ProtoChainRecv(hContact, PSR_AUTH, 0, (LPARAM)&pre);
+ pre.flags = 0;
+ pre.szMessage = (LPSTR)TranslateTS(MRA_ALARM_MESSAGE);
+ ProtoChainRecvMsg(hContact, &pre);
}
}
- else {
- db_unset(hContact, "CList", "Hidden");
-
- if (dwFlags & MESSAGE_FLAG_CONTACT) { // contacts received
- LPBYTE lpbBuffer, lpbBufferCurPos;
-
- lpbBuffer = (LPBYTE)mir_calloc((dwMessageSize+MAX_PATH));
- if (lpbBuffer) {
- pre.flags = 0;
- pre.szMessage = (LPSTR)lpbBuffer;
- pre.lParam = WideCharToMultiByte(MRA_CODE_PAGE, 0, lpwszMessage, dwMessageSize, (LPSTR)lpbBuffer, (dwMessageSize+MAX_PATH), NULL, NULL);
-
- lpbBufferCurPos = lpbBuffer;
- while (TRUE) { // цикл замены ; на 0
- lpbBufferCurPos = (LPBYTE)MemoryFindByte((lpbBufferCurPos-lpbBuffer), lpbBuffer, pre.lParam, ';');
- if (!lpbBufferCurPos)
- break;
-
- // found
- (*lpbBufferCurPos) = 0;
- lpbBufferCurPos++;
- }
- ProtoChainRecv(hContact, PSR_CONTACTS, 0, (LPARAM)&pre);
- mir_free(lpbBuffer);
- }
- else dwRetErrorCode = GetLastError();
+ else { // standart message// flash animation
+ // пишем в ANSI, всё равно RTF
+ if ((dwFlags & MESSAGE_FLAG_RTF) && (dwFlags & MESSAGE_FLAG_FLASH) == 0 && !lpszMessageExt.IsEmpty() && getByte("RTFReceiveEnable", MRA_DEFAULT_RTF_RECEIVE_ENABLE)) {
+ pre.flags = 0;
+ pre.szMessage = (LPSTR)lpszMessageExt.GetString();
+ ProtoChainRecvMsg(hContact, &pre);
}
- else if (dwFlags & MESSAGE_FLAG_ALARM) { // alarm
- if (heNudgeReceived)
- NotifyEventHooks(heNudgeReceived, (WPARAM)hContact, NULL);
- else {
- pre.flags = 0;
- pre.szMessage = (LPSTR)TranslateTS(MRA_ALARM_MESSAGE);
- ProtoChainRecvMsg(hContact, &pre);
- }
+ else {
+ // some plugins can change pre.szMessage pointer and we failed to free it
+ ptrA lpszMessageUTF( mir_utf8encodeW(wszMessage));
+ pre.szMessage = lpszMessageUTF;
+ pre.flags = PREF_UTF;
+ ProtoChainRecvMsg(hContact, &pre);
}
- else { // standart message// flash animation
- // пишем в ANSI, всё равно RTF
- if ((dwFlags & MESSAGE_FLAG_RTF) && (dwFlags & MESSAGE_FLAG_FLASH) == 0 && lpszMessageExt && dwMessageExtSize && getByte("RTFReceiveEnable", MRA_DEFAULT_RTF_RECEIVE_ENABLE)) {
- pre.flags = 0;
- pre.szMessage = lpszMessageExt;
- ProtoChainRecvMsg(hContact, &pre);
- }
- else {
- // some plugins can change pre.szMessage pointer and we failed to free it
- LPSTR lpszMessageUTF = (LPSTR)mir_calloc(((dwMessageSize+MAX_PATH)*sizeof(WCHAR)));
- if (lpszMessageUTF) {
- pre.szMessage = lpszMessageUTF;
- pre.flags = PREF_UTF;
- WideCharToMultiByte(CP_UTF8, 0, lpwszMessage, dwMessageSize, lpszMessageUTF, ((dwMessageSize+MAX_PATH)*sizeof(WCHAR)), NULL, NULL);
- ProtoChainRecvMsg(hContact, &pre);
- mir_free(lpszMessageUTF);
- }
- else dwRetErrorCode = GetLastError();
- }
- if (dwFlags & MESSAGE_FLAG_SYSTEM)
- MraPopupShowW(hContact, MRA_POPUP_TYPE_INFORMATION, 0, TranslateW(L"Mail.ru System notify"), (LPWSTR)pre.szMessage);
- }
+ if (dwFlags & MESSAGE_FLAG_SYSTEM)
+ MraPopupShowW(hContact, MRA_POPUP_TYPE_INFORMATION, 0, TranslateW(L"Mail.ru System notify"), (LPWSTR)pre.szMessage);
}
}
}
}
- else dwRetErrorCode = ERROR_ACCESS_DENIED;
- if (lpwszMessage != plpsText->lpwszData && lpwszMessage != (LPWSTR)lpszMessageExt)
- mir_free(lpwszMessage);
- mir_free(lpszMessageExt);
-
- return dwRetErrorCode;
+ return NO_ERROR;
}
-DWORD GetMraXStatusIDFromMraUriStatus(LPSTR lpszStatusUri, size_t dwStatusUriSize)
+DWORD GetMraXStatusIDFromMraUriStatus(const char *szStatusUri)
{
- if (lpszStatusUri)
+ if (szStatusUri)
for (size_t i = 0; lpcszStatusUri[i]; i++)
- if ( !_strnicmp(lpcszStatusUri[i], lpszStatusUri, dwStatusUriSize))
+ if ( !_stricmp(lpcszStatusUri[i], szStatusUri))
return i;
return MRA_XSTATUS_UNKNOWN;
@@ -2141,7 +1936,6 @@ DWORD GetMraStatusFromMiradaStatus(DWORD dwMirandaStatus, DWORD dwXStatusMir, DW
return STATUS_OFFLINE;
}
-
DWORD GetMiradaStatusFromMraStatus(DWORD dwMraStatus, DWORD dwXStatusMra, DWORD *pdwXStatusMir)
{
if (pdwXStatusMir) *pdwXStatusMir = 0;
@@ -2169,43 +1963,64 @@ DWORD GetMiradaStatusFromMraStatus(DWORD dwMraStatus, DWORD dwXStatusMra, DWORD
return ID_STATUS_OFFLINE;
}
-DWORD GetUL(LPBYTE *plpData)
+/////////////////////////////////////////////////////////////////////////////////////////////////
+
+BinBuffer& operator >>(BinBuffer& buf, DWORD &ret)
{
- DWORD dwRet = *(DWORD*)(*plpData);
- plpData[0] += sizeof(DWORD);
- return dwRet;
+ if (buf.m_len >= sizeof(DWORD)) {
+ ret = *(DWORD*)buf.m_data;
+ buf.m_data += sizeof(DWORD);
+ buf.m_len -= sizeof(DWORD);
+ }
+ return buf;
}
-DWORDLONG GetUIDL(LPBYTE *plpData)
+BinBuffer& operator >>(BinBuffer& buf, DWORDLONG &ret)
{
- DWORDLONG dwRet = *(DWORDLONG*)(*plpData);
- plpData[0] += sizeof(DWORDLONG);
- return dwRet;
+ if (buf.m_len >= sizeof(DWORDLONG)) {
+ ret = *(DWORDLONG*)buf.m_data;
+ buf.m_data += sizeof(DWORDLONG);
+ buf.m_len -= sizeof(DWORDLONG);
+ }
+ return buf;
}
-MRA_GUID GetGUID(LPBYTE *plpData)
+BinBuffer& operator >>(BinBuffer& buf, MRA_GUID &ret)
{
- MRA_GUID guidRet = *(MRA_GUID*)(*plpData);
- plpData[0] += sizeof(MRA_GUID);
- return guidRet;
+ if (buf.m_len >= sizeof(MRA_GUID)) {
+ ret = *(MRA_GUID*)buf.m_data;
+ buf.m_data += sizeof(MRA_GUID);
+ buf.m_len -= sizeof(MRA_GUID);
+ }
+ return buf;
}
-DWORD GetLPS(LPBYTE lpbData, DWORD dwDataSize, LPBYTE *plpCurrentData, MRA_LPS *plpsString)
+BinBuffer& operator >>(BinBuffer& buf, CMStringA &ret)
{
- LPBYTE lpbDataEnd = (lpbData+dwDataSize);
-
- // хотябы длинна данных есть
- if (lpbDataEnd >= ((*plpCurrentData)+sizeof(DWORD))) {
- // все длинна данных в буфере равна или меньше размера буфера
- if (lpbDataEnd >= ((*plpCurrentData)+sizeof(DWORD)+(*(DWORD*)(*plpCurrentData)))) {
- plpsString->dwSize = (*(DWORD*)(*plpCurrentData));
- plpsString->lpszData = (LPSTR)((*plpCurrentData)+sizeof(DWORD));
- (*plpCurrentData) += (sizeof(DWORD)+plpsString->dwSize);
- return NO_ERROR;
+ if (buf.m_len >= sizeof(DWORD)) {
+ DWORD dwLen = *(DWORD*)buf.m_data;
+ buf.m_data += sizeof(DWORD);
+ buf.m_len -= sizeof(DWORD);
+ if (buf.m_len >= dwLen) {
+ ret = CMStringA((LPSTR)buf.m_data, dwLen);
+ buf.m_data += dwLen;
+ buf.m_len -= dwLen;
}
}
+ return buf;
+}
- plpsString->dwSize = 0;
- plpsString->lpszData = NULL;
- return ERROR_INVALID_USER_BUFFER;
+BinBuffer& operator >>(BinBuffer& buf, CMStringW &ret)
+{
+ if (buf.m_len >= sizeof(DWORD)) {
+ DWORD dwLen = *(DWORD*)buf.m_data;
+ buf.m_data += sizeof(DWORD);
+ buf.m_len -= sizeof(DWORD);
+ if (buf.m_len >= dwLen) {
+ ret = CMStringW((LPWSTR)buf.m_data, dwLen/2);
+ buf.m_data += dwLen;
+ buf.m_len -= dwLen;
+ }
+ }
+ return buf;
}
diff --git a/protocols/MRA/src/Mra_svcs.cpp b/protocols/MRA/src/Mra_svcs.cpp
index 992032963d..11b7f37b35 100644
--- a/protocols/MRA/src/Mra_svcs.cpp
+++ b/protocols/MRA/src/Mra_svcs.cpp
@@ -124,7 +124,7 @@ const LPWSTR lpcszXStatusNameDef[] =
void CMraProto::SetExtraIcons(HANDLE hContact)
{
DWORD dwID, dwGroupID, dwContactSeverFlags;
- if ( GetContactBasicInfoW(hContact, &dwID, &dwGroupID, NULL, &dwContactSeverFlags, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, NULL))
+ if ( GetContactBasicInfoW(hContact, &dwID, &dwGroupID, NULL, &dwContactSeverFlags, NULL, NULL, NULL, NULL))
return;
DWORD dwIconID = -1;
@@ -148,10 +148,10 @@ void CMraProto::SetExtraIcons(HANDLE hContact)
}
if (dwIconID == -1) {
- size_t dwBlogStatusMsgSize = 0;
-
- mraGetStaticStringW(hContact, DBSETTING_BLOGSTATUS, NULL, 0, &dwBlogStatusMsgSize);
- if (dwBlogStatusMsgSize) dwIconID = ADV_ICON_BLOGSTATUS;
+ CMStringW statusMsg;
+ mraGetStringW(hContact, DBSETTING_BLOGSTATUS, statusMsg);
+ if (statusMsg.GetLength())
+ dwIconID = ADV_ICON_BLOGSTATUS;
}
ExtraIcon_SetIcon(hExtraXstatusIcon, hContact,
@@ -168,13 +168,13 @@ INT_PTR CMraProto::MraXStatusMenu(WPARAM wParam, LPARAM lParam, LPARAM param)
INT_PTR CMraProto::MraGotoInbox(WPARAM wParam, LPARAM lParam)
{
- MraMPopSessionQueueAddUrl(hMPopSessionQueue, MRA_WIN_INBOX_URL, sizeof(MRA_WIN_INBOX_URL));
+ MraMPopSessionQueueAddUrl(hMPopSessionQueue, MRA_WIN_INBOX_URL);
return 0;
}
INT_PTR CMraProto::MraShowInboxStatus(WPARAM wParam, LPARAM lParam)
{
- MraUpdateEmailStatus(NULL, 0, NULL, 0, 0, 0);
+ MraUpdateEmailStatus("", "", 0, 0);
return 0;
}
@@ -184,27 +184,24 @@ INT_PTR CMraProto::MraSendSMS(WPARAM wParam, LPARAM lParam)
return 0;
ptrW lpwszMessageXMLEncoded( mir_utf8decodeW((LPSTR)lParam));
- size_t dwBuffLen = lstrlenA((LPSTR)lParam) + MAX_PATH;
- LPWSTR lpwszMessageXMLDecoded = (LPWSTR)mir_calloc((dwBuffLen*sizeof(WCHAR)));
- if (lpwszMessageXMLEncoded && lpwszMessageXMLDecoded) {
- size_t dwMessageXMLDecodedSize;
- DecodeXML(lpwszMessageXMLEncoded, lstrlen(lpwszMessageXMLEncoded), lpwszMessageXMLDecoded, dwBuffLen, &dwMessageXMLDecodedSize);
- if (dwMessageXMLDecodedSize)
- MraSMSW(NULL, (LPSTR)wParam , lstrlenA((LPSTR)wParam), lpwszMessageXMLDecoded, dwMessageXMLDecodedSize);
+ if (lpwszMessageXMLEncoded) {
+ CMStringW decoded = DecodeXML( CMStringW(lpwszMessageXMLEncoded));
+ if (decoded.GetLength())
+ MraSMSW(NULL, CMStringA((LPSTR)wParam), decoded);
}
- mir_free(lpwszMessageXMLDecoded);
+
return 0;
}
INT_PTR CMraProto::MraEditProfile(WPARAM wParam, LPARAM lParam)
{
- MraMPopSessionQueueAddUrl(hMPopSessionQueue, MRA_EDIT_PROFILE_URL, sizeof(MRA_EDIT_PROFILE_URL));
+ MraMPopSessionQueueAddUrl(hMPopSessionQueue, MRA_EDIT_PROFILE_URL);
return 0;
}
INT_PTR CMraProto::MraZhuki(WPARAM wParam, LPARAM lParam)
{
- MraMPopSessionQueueAddUrl(hMPopSessionQueue, MRA_ZHUKI_URL, sizeof(MRA_ZHUKI_URL));
+ MraMPopSessionQueueAddUrl(hMPopSessionQueue, MRA_ZHUKI_URL);
return 0;
}
@@ -218,10 +215,9 @@ INT_PTR CMraProto::MraUpdateAllUsersInfo(WPARAM wParam, LPARAM lParam)
{
if ( MessageBox(NULL, TranslateT("Are you sure?"), TranslateW(MRA_UPD_ALL_USERS_INFO_STR), MB_YESNO | MB_ICONQUESTION) == IDYES ) {
for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
- size_t dwEMailSize;
- CHAR szEMail[MAX_EMAIL_LEN];
- if ( mraGetStaticStringA(hContact, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize))
- MraWPRequestByEMail(hContact, ACKTYPE_GETINFO, szEMail, dwEMailSize);
+ CMStringA szEmail;
+ if ( mraGetStringA(hContact, "e-mail", szEmail))
+ MraWPRequestByEMail(hContact, ACKTYPE_GETINFO, szEmail);
}
}
return 0;
@@ -231,12 +227,10 @@ INT_PTR CMraProto::MraCheckUpdatesUsersAvt(WPARAM wParam, LPARAM lParam)
{
if ( MessageBox(NULL, TranslateT("Are you sure?"), TranslateW(MRA_CHK_USERS_AVATARS_STR), MB_YESNO | MB_ICONQUESTION) == IDYES) {
for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
- size_t dwEMailSize;
- CHAR szEMail[MAX_EMAIL_LEN];
-
- if (mraGetStaticStringA(hContact, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize))
- if (IsEMailChatAgent(szEMail, dwEMailSize) == FALSE)// только для оптимизации, MraAvatarsQueueGetAvatarSimple сама умеет фильтровать чатконтакты
- MraAvatarsQueueGetAvatarSimple(hAvatarsQueueHandle, 0/*GAIF_FORCE*/, hContact, 0);
+ CMStringA szEmail;
+ if (mraGetStringA(hContact, "e-mail", szEmail))
+ if ( !IsEMailChatAgent(szEmail))
+ MraAvatarsQueueGetAvatarSimple(hAvatarsQueueHandle, 0, hContact, 0);
}
}
return 0;
@@ -247,7 +241,7 @@ INT_PTR CMraProto::MraRequestAuthForAll(WPARAM wParam, LPARAM lParam)
if ( MessageBox(NULL, TranslateT("Are you sure?"), TranslateW(MRA_REQ_AUTH_FOR_ALL_STR), MB_YESNO | MB_ICONQUESTION) == IDYES) {
for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
DWORD dwContactSeverFlags;
- if (GetContactBasicInfoW(hContact, NULL, NULL, NULL, &dwContactSeverFlags, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, NULL) == NO_ERROR)
+ if (GetContactBasicInfoW(hContact, NULL, NULL, NULL, &dwContactSeverFlags, NULL, NULL, NULL, NULL) == NO_ERROR)
if (dwContactSeverFlags & CONTACT_INTFLAG_NOT_AUTHORIZED && dwContactSeverFlags != -1)
MraRequestAuthorization((WPARAM)hContact, 0);
}
@@ -257,31 +251,27 @@ INT_PTR CMraProto::MraRequestAuthForAll(WPARAM wParam, LPARAM lParam)
INT_PTR CMraProto::MraRequestAuthorization(WPARAM wParam, LPARAM lParam)
{
- if (wParam) {
- WCHAR wszAuthMessage[MAX_PATH];
-
- if (mraGetStaticStringW(NULL, "AuthMessage", wszAuthMessage, SIZEOF(wszAuthMessage), NULL) == FALSE)
- lstrcpynW(wszAuthMessage, TranslateW(MRA_DEFAULT_AUTH_MESSAGE), SIZEOF(wszAuthMessage));
+ HANDLE hContact = (HANDLE)wParam;
+ if (!hContact)
+ return 0;
- CHAR szEMail[MAX_EMAIL_LEN];
- size_t dwEMailSize, dwMessageSize;
+ CMStringW wszAuthMessage;
+ if ( !mraGetStringW(NULL, "AuthMessage", wszAuthMessage))
+ wszAuthMessage = TranslateW(MRA_DEFAULT_AUTH_MESSAGE);
- dwMessageSize = lstrlen(wszAuthMessage);
- if (dwMessageSize) {
- HANDLE hContact = (HANDLE)wParam;
- if ( mraGetStaticStringA(hContact, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize)) {
- BOOL bSlowSend = getByte("SlowSend", MRA_DEFAULT_SLOW_SEND);
- int iRet = MraMessageW(bSlowSend, hContact, ACKTYPE_AUTHREQ, MESSAGE_FLAG_AUTHORIZE, szEMail, dwEMailSize, wszAuthMessage, dwMessageSize, NULL, 0);
- if (bSlowSend == FALSE)
- ProtoBroadcastAck(hContact, ACKTYPE_AUTHREQ, ACKRESULT_SUCCESS, (HANDLE)iRet, 0);
+ if ( !wszAuthMessage.IsEmpty()) {
+ CMStringA szEmail;
+ if ( mraGetStringA(hContact, "e-mail", szEmail)) {
+ BOOL bSlowSend = getByte("SlowSend", MRA_DEFAULT_SLOW_SEND);
+ int iRet = MraMessageW(bSlowSend, hContact, ACKTYPE_AUTHREQ, MESSAGE_FLAG_AUTHORIZE, szEmail, wszAuthMessage, NULL, 0);
+ if (bSlowSend == FALSE)
+ ProtoBroadcastAck(hContact, ACKTYPE_AUTHREQ, ACKRESULT_SUCCESS, (HANDLE)iRet, 0);
- return 0;
- }
+ return 0;
}
-
- return 1;
}
- return 0;
+
+ return 1;
}
INT_PTR CMraProto::MraGrantAuthorization(WPARAM wParam, LPARAM lParam)
@@ -289,12 +279,10 @@ INT_PTR CMraProto::MraGrantAuthorization(WPARAM wParam, LPARAM lParam)
if (!m_bLoggedIn || !wParam)
return 0;
- CHAR szEMail[MAX_EMAIL_LEN];
- size_t dwEMailSize;
-
// send without reason, do we need any ?
- if (mraGetStaticStringA((HANDLE)wParam, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize))
- MraAuthorize(szEMail, dwEMailSize);
+ CMStringA szEmail;
+ if (mraGetStringA((HANDLE)wParam, "e-mail", szEmail))
+ MraAuthorize(szEmail);
return 0;
}
@@ -307,13 +295,11 @@ INT_PTR CMraProto::MraSendPostcard(WPARAM wParam, LPARAM lParam)
DWORD dwContactEMailCount = GetContactEMailCount((HANDLE)wParam, FALSE);
if (dwContactEMailCount) {
if (dwContactEMailCount == 1) {
- size_t dwUrlSize, dwEMailSize;
- CHAR szUrl[BUFF_SIZE_URL], szEMail[MAX_EMAIL_LEN];
-
- if ( GetContactFirstEMail((HANDLE)wParam, FALSE, szEMail, SIZEOF(szEMail), &dwEMailSize)) {
- BuffToLowerCase(szEMail, szEMail, dwEMailSize);
- dwUrlSize = mir_snprintf(szUrl, SIZEOF(szUrl), "http://cards.mail.ru/event.html?rcptname=%s&rcptemail=%s", GetContactNameA((HANDLE)wParam), szEMail);
- MraMPopSessionQueueAddUrl(hMPopSessionQueue, szUrl, dwUrlSize);
+ CMStringA szUrl, szEmail;
+ if ( GetContactFirstEMail((HANDLE)wParam, FALSE, szEmail)) {
+ szEmail.MakeLower();
+ szUrl.Format("http://cards.mail.ru/event.html?rcptname=%s&rcptemail=%s", GetContactNameA((HANDLE)wParam), szEmail);
+ MraMPopSessionQueueAddUrl(hMPopSessionQueue, szUrl);
}
}
else MraSelectEMailDlgShow((HANDLE)wParam, MRA_SELECT_EMAIL_TYPE_SEND_POSTCARD);
@@ -329,10 +315,9 @@ INT_PTR CMraProto::MraViewAlbum(WPARAM wParam, LPARAM lParam)
DWORD dwContactEMailMRCount = GetContactEMailCount((HANDLE)wParam, TRUE);
if (dwContactEMailMRCount) {
if (dwContactEMailMRCount == 1) {
- size_t dwEMailSize;
- CHAR szEMail[MAX_EMAIL_LEN];
- if (GetContactFirstEMail((HANDLE)wParam, TRUE, szEMail, SIZEOF(szEMail), &dwEMailSize))
- MraMPopSessionQueueAddUrlAndEMail(hMPopSessionQueue, MRA_FOTO_URL, sizeof(MRA_FOTO_URL), szEMail, dwEMailSize);
+ CMStringA szEmail;
+ if ( GetContactFirstEMail((HANDLE)wParam, TRUE, szEmail))
+ MraMPopSessionQueueAddUrlAndEMail(hMPopSessionQueue, MRA_FOTO_URL, szEmail);
}
else MraSelectEMailDlgShow((HANDLE)wParam, MRA_SELECT_EMAIL_TYPE_VIEW_ALBUM);
}
@@ -347,10 +332,9 @@ INT_PTR CMraProto::MraReadBlog(WPARAM wParam, LPARAM lParam)
DWORD dwContactEMailMRCount = GetContactEMailCount((HANDLE)wParam, TRUE);
if (dwContactEMailMRCount)
if (dwContactEMailMRCount == 1) {
- CHAR szEMail[MAX_EMAIL_LEN];
- size_t dwEMailSize;
- if (GetContactFirstEMail((HANDLE)wParam, TRUE, szEMail, SIZEOF(szEMail), &dwEMailSize))
- MraMPopSessionQueueAddUrlAndEMail(hMPopSessionQueue, MRA_BLOGS_URL, sizeof(MRA_BLOGS_URL), szEMail, dwEMailSize);
+ CMStringA szEmail;
+ if (GetContactFirstEMail((HANDLE)wParam, TRUE, szEmail))
+ MraMPopSessionQueueAddUrlAndEMail(hMPopSessionQueue, MRA_BLOGS_URL, szEmail);
}
else MraSelectEMailDlgShow((HANDLE)wParam, MRA_SELECT_EMAIL_TYPE_READ_BLOG);
@@ -362,9 +346,9 @@ INT_PTR CMraProto::MraReplyBlogStatus(WPARAM wParam, LPARAM lParam)
if (!m_bLoggedIn)
return 0;
- size_t dwBlogStatusMsgSize = 0;
- mraGetStaticStringW((HANDLE)wParam, DBSETTING_BLOGSTATUS, NULL, 0, &dwBlogStatusMsgSize);
- if (dwBlogStatusMsgSize || wParam == 0)
+ CMStringW blogStatusMsg;
+ mraGetStringW((HANDLE)wParam, DBSETTING_BLOGSTATUS, blogStatusMsg);
+ if (!blogStatusMsg.IsEmpty()|| wParam == 0)
MraSendReplyBlogStatus((HANDLE)wParam);
return 0;
@@ -378,10 +362,9 @@ INT_PTR CMraProto::MraViewVideo(WPARAM wParam, LPARAM lParam)
DWORD dwContactEMailMRCount = GetContactEMailCount((HANDLE)wParam, TRUE);
if (dwContactEMailMRCount) {
if (dwContactEMailMRCount == 1) {
- CHAR szEMail[MAX_EMAIL_LEN];
- size_t dwEMailSize;
- if (GetContactFirstEMail((HANDLE)wParam, TRUE, szEMail, SIZEOF(szEMail), &dwEMailSize))
- MraMPopSessionQueueAddUrlAndEMail(hMPopSessionQueue, MRA_VIDEO_URL, sizeof(MRA_VIDEO_URL), szEMail, dwEMailSize);
+ CMStringA szEmail;
+ if (GetContactFirstEMail((HANDLE)wParam, TRUE, szEmail))
+ MraMPopSessionQueueAddUrlAndEMail(hMPopSessionQueue, MRA_VIDEO_URL, szEmail);
}
else MraSelectEMailDlgShow((HANDLE)wParam, MRA_SELECT_EMAIL_TYPE_VIEW_VIDEO);
}
@@ -396,10 +379,9 @@ INT_PTR CMraProto::MraAnswers(WPARAM wParam, LPARAM lParam)
DWORD dwContactEMailMRCount = GetContactEMailCount((HANDLE)wParam, TRUE);
if (dwContactEMailMRCount) {
if (dwContactEMailMRCount == 1) {
- CHAR szEMail[MAX_EMAIL_LEN];
- size_t dwEMailSize;
- if (GetContactFirstEMail((HANDLE)wParam, TRUE, szEMail, SIZEOF(szEMail), &dwEMailSize))
- MraMPopSessionQueueAddUrlAndEMail(hMPopSessionQueue, MRA_ANSWERS_URL, sizeof(MRA_ANSWERS_URL), szEMail, dwEMailSize);
+ CMStringA szEmail;
+ if (GetContactFirstEMail((HANDLE)wParam, TRUE, szEmail))
+ MraMPopSessionQueueAddUrlAndEMail(hMPopSessionQueue, MRA_ANSWERS_URL, szEmail);
}
else MraSelectEMailDlgShow((HANDLE)wParam, MRA_SELECT_EMAIL_TYPE_ANSWERS);
}
@@ -414,10 +396,9 @@ INT_PTR CMraProto::MraWorld(WPARAM wParam, LPARAM lParam)
DWORD dwContactEMailMRCount = GetContactEMailCount((HANDLE)wParam, TRUE);
if (dwContactEMailMRCount) {
if (dwContactEMailMRCount == 1) {
- CHAR szEMail[MAX_EMAIL_LEN];
- size_t dwEMailSize;
- if (GetContactFirstEMail((HANDLE)wParam, TRUE, szEMail, SIZEOF(szEMail), &dwEMailSize))
- MraMPopSessionQueueAddUrlAndEMail(hMPopSessionQueue, MRA_WORLD_URL, sizeof(MRA_WORLD_URL), szEMail, dwEMailSize);
+ CMStringA szEmail;
+ if (GetContactFirstEMail((HANDLE)wParam, TRUE, szEmail))
+ MraMPopSessionQueueAddUrlAndEMail(hMPopSessionQueue, MRA_WORLD_URL, szEmail);
}
else MraSelectEMailDlgShow((HANDLE)wParam, MRA_SELECT_EMAIL_TYPE_WORLD);
}
@@ -433,14 +414,13 @@ int CMraProto::MraContactDeleted(WPARAM wParam, LPARAM lParam)
return 0;
if ( IsContactMra(hContact)) {
- CHAR szEMail[MAX_EMAIL_LEN];
+ CMStringA szEmail;
DWORD dwID, dwGroupID;
- size_t dwEMailSize;
- GetContactBasicInfoW(hContact, &dwID, &dwGroupID, NULL, NULL, NULL, szEMail, SIZEOF(szEMail), &dwEMailSize, NULL, 0, NULL, NULL, 0, NULL);
+ GetContactBasicInfoW(hContact, &dwID, &dwGroupID, NULL, NULL, NULL, &szEmail, NULL, NULL);
MraSetContactStatus(hContact, ID_STATUS_OFFLINE);
if ( !db_get_b(hContact, "CList", "NotOnList", 0) || dwID != -1)
- MraModifyContactW(hContact, dwID, CONTACT_FLAG_REMOVED, dwGroupID, szEMail, dwEMailSize, NULL, 0, NULL, 0);
+ MraModifyContactW(hContact, dwID, CONTACT_FLAG_REMOVED, dwGroupID, szEmail, L"", "");
MraAvatarsDeleteContactAvatarFile(hAvatarsQueueHandle, hContact);
}
return 0;
@@ -452,124 +432,99 @@ int CMraProto::MraDbSettingChanged(WPARAM wParam, LPARAM lParam)
return 0;
HANDLE hContact = (HANDLE)wParam;
+ if (hContact == NULL)
+ return 0;
+
DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING*)lParam;
- if (hContact) {
- // это наш контакт, он не временный (есть в списке на сервере) и его обновление разрешено
- if ( IsContactMra(hContact) && !db_get_b(hContact, "CList", "NotOnList", 0) && getDword(hContact, "HooksLocked", FALSE) == FALSE) {
- CHAR szEMail[MAX_EMAIL_LEN], szPhones[MAX_EMAIL_LEN];
- WCHAR wszNick[MAX_EMAIL_LEN];
- DWORD dwID, dwGroupID, dwContactFlag;
- size_t dwEMailSize, dwNickSize, dwPhonesSize;
-
- if ( CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szModule, -1, "CList", 5) == CSTR_EQUAL) {
- // MyHandle setting
- if (CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szSetting, -1, "MyHandle", 8) == CSTR_EQUAL) {
- LPWSTR lpwszNewNick;
-
- // allways store custom nick
- if (cws->value.type == DBVT_DELETED) {
- lstrcpynW(wszNick, GetContactNameW(hContact), SIZEOF(wszNick));
- lpwszNewNick = wszNick;
- dwNickSize = lstrlenW(lpwszNewNick);
- DB_SetStringExW(hContact, "CList", "MyHandle", lpwszNewNick, dwNickSize);
- }
- else if (cws->value.pszVal) {
- switch (cws->value.type) {
- case DBVT_WCHAR:
- lpwszNewNick = cws->value.pwszVal;
- dwNickSize = lstrlenW(lpwszNewNick);
- break;
- case DBVT_UTF8:
- lpwszNewNick = wszNick;
- dwNickSize = MultiByteToWideChar(CP_UTF8, 0, cws->value.pszVal, -1, wszNick, SIZEOF(wszNick));
- break;
- case DBVT_ASCIIZ:
- lpwszNewNick = wszNick;
- dwNickSize = MultiByteToWideChar(MRA_CODE_PAGE, 0, cws->value.pszVal, -1, wszNick, SIZEOF(wszNick));
- break;
- default:
- lpwszNewNick = NULL;
- dwNickSize = 0;
- break;
- }
- if (lpwszNewNick)
- if (GetContactBasicInfoW(hContact, &dwID, &dwGroupID, &dwContactFlag, NULL, NULL, szEMail, SIZEOF(szEMail), &dwEMailSize, NULL, 0, NULL, szPhones, SIZEOF(szPhones), &dwPhonesSize) == NO_ERROR)
- MraModifyContactW(hContact, dwID, dwContactFlag, dwGroupID, szEMail, dwEMailSize, lpwszNewNick, dwNickSize, szPhones, dwPhonesSize);
- }
+ // это наш контакт, он не временный (есть в списке на сервере) и его обновление разрешено
+ if ( IsContactMra(hContact) && !db_get_b(hContact, "CList", "NotOnList", 0) && getDword(hContact, "HooksLocked", FALSE) == FALSE) {
+ CMStringA szEmail, szPhones;
+ CMStringW wszNick;
+ DWORD dwID, dwGroupID, dwContactFlag;
+
+ if ( CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szModule, -1, "CList", 5) == CSTR_EQUAL) {
+ // MyHandle setting
+ if (CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szSetting, -1, "MyHandle", 8) == CSTR_EQUAL) {
+ // always store custom nick
+ if (cws->value.type == DBVT_DELETED) {
+ wszNick = GetContactNameW(hContact);
+ db_set_ws(hContact, "CList", "MyHandle", wszNick);
}
- // Group setting
- else if ( CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szSetting, -1, "Group", 5) == CSTR_EQUAL ) {
- // manage group on server
+ else if (cws->value.pszVal) {
switch (cws->value.type) {
+ case DBVT_WCHAR:
+ wszNick = cws->value.pwszVal;
+ break;
+ case DBVT_UTF8:
+ wszNick = ptrW( mir_utf8decodeW(cws->value.pszVal));
+ break;
case DBVT_ASCIIZ:
+ wszNick = ptrW( mir_a2u_cp(cws->value.pszVal, MRA_CODE_PAGE));
break;
- case DBVT_DELETED:
+ default:
break;
}
- }
- // NotOnList setting. Has a temporary contact just been added permanently?
- else if ( CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szSetting, -1, "NotOnList", 9) == CSTR_EQUAL) {
- if (cws->value.type == DBVT_DELETED || (cws->value.type == DBVT_BYTE && cws->value.bVal == 0)) {
- WCHAR wszAuthMessage[MAX_PATH];
- size_t dwAuthMessageSize;
- if ( mraGetStaticStringW(NULL, "AuthMessage", wszAuthMessage, SIZEOF(wszAuthMessage), &dwAuthMessageSize) == FALSE) {
- lstrcpynW(wszAuthMessage, TranslateW(MRA_DEFAULT_AUTH_MESSAGE), SIZEOF(wszAuthMessage));
- dwAuthMessageSize = lstrlenW(wszAuthMessage);
- }
-
- db_unset(hContact, "CList", "Hidden");
- GetContactBasicInfoW(hContact, NULL, &dwGroupID, &dwContactFlag, NULL, NULL, szEMail, SIZEOF(szEMail), &dwEMailSize, wszNick, SIZEOF(wszNick), &dwNickSize, szPhones, SIZEOF(szPhones), &dwPhonesSize);
- MraAddContactW(hContact, dwContactFlag, dwGroupID, szEMail, dwEMailSize, wszNick, dwNickSize, szPhones, dwPhonesSize, wszAuthMessage, dwAuthMessageSize, 0);
- }
- }
- // Hidden setting
- else if ( CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szSetting, -1, "Hidden" , 6) == CSTR_EQUAL) {
- GetContactBasicInfoW(hContact, &dwID, &dwGroupID, &dwContactFlag, NULL, NULL, szEMail, SIZEOF(szEMail), &dwEMailSize, wszNick, SIZEOF(wszNick), &dwNickSize, szPhones, SIZEOF(szPhones), &dwPhonesSize);
- if (cws->value.type == DBVT_DELETED || (cws->value.type == DBVT_BYTE && cws->value.bVal == 0))
- dwContactFlag &= ~CONTACT_FLAG_SHADOW;
- else
- dwContactFlag |= CONTACT_FLAG_SHADOW;
-
- MraModifyContactW(hContact, dwID, dwContactFlag, dwGroupID, szEMail, dwEMailSize, wszNick, dwNickSize, szPhones, dwPhonesSize);
+ if (wszNick.GetLength())
+ if (GetContactBasicInfoW(hContact, &dwID, &dwGroupID, &dwContactFlag, NULL, NULL, &szEmail, NULL, &szPhones) == NO_ERROR)
+ MraModifyContactW(hContact, dwID, dwContactFlag, dwGroupID, szEmail, wszNick, szPhones);
}
}
- // Ignore section
- else if ( CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szModule, -1, "Ignore", 6) == CSTR_EQUAL) {
- if ( CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szSetting, -1, "Mask1", 5) == CSTR_EQUAL) {
- GetContactBasicInfoW(hContact, &dwID, &dwGroupID, &dwContactFlag, NULL, NULL, szEMail, SIZEOF(szEMail), &dwEMailSize, wszNick, SIZEOF(wszNick), &dwNickSize, szPhones, SIZEOF(szPhones), &dwPhonesSize);
- if (cws->value.type == DBVT_DELETED || (cws->value.type == DBVT_DWORD && cws->value.dVal&IGNOREEVENT_MESSAGE) == 0)
- dwContactFlag &= ~CONTACT_FLAG_IGNORE;
- else
- dwContactFlag |= CONTACT_FLAG_IGNORE;
-
- MraModifyContactW(hContact, dwID, dwContactFlag, dwGroupID, szEMail, dwEMailSize, wszNick, dwNickSize, szPhones, dwPhonesSize);
+ // Group setting
+ else if ( CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szSetting, -1, "Group", 5) == CSTR_EQUAL ) {
+ // manage group on server
+ switch (cws->value.type) {
+ case DBVT_ASCIIZ:
+ break;
+ case DBVT_DELETED:
+ break;
}
}
- // User info section
- else if (CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szModule, -1, "UserInfo", 8) == CSTR_EQUAL) {
- if ( CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szSetting, -1, "MyPhone0", 8) == CSTR_EQUAL ||
- CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szSetting, -1, "MyPhone1", 8) == CSTR_EQUAL ||
- CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szSetting, -1, "MyPhone2", 8) == CSTR_EQUAL) {
- GetContactBasicInfoW(hContact, &dwID, &dwGroupID, &dwContactFlag, NULL, NULL, szEMail, SIZEOF(szEMail), &dwEMailSize, wszNick, SIZEOF(wszNick), &dwNickSize, szPhones, SIZEOF(szPhones), &dwPhonesSize);
- MraModifyContactW(hContact, dwID, dwContactFlag, dwGroupID, szEMail, dwEMailSize, wszNick, dwNickSize, szPhones, dwPhonesSize);
+ // NotOnList setting. Has a temporary contact just been added permanently?
+ else if ( CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szSetting, -1, "NotOnList", 9) == CSTR_EQUAL) {
+ if (cws->value.type == DBVT_DELETED || (cws->value.type == DBVT_BYTE && cws->value.bVal == 0)) {
+ CMStringW wszAuthMessage;
+ if ( !mraGetStringW(NULL, "AuthMessage", wszAuthMessage))
+ wszAuthMessage = TranslateW(MRA_DEFAULT_AUTH_MESSAGE);
+
+ db_unset(hContact, "CList", "Hidden");
+ GetContactBasicInfoW(hContact, NULL, &dwGroupID, &dwContactFlag, NULL, NULL, &szEmail, &wszNick, &szPhones);
+ MraAddContactW(hContact, dwContactFlag, dwGroupID, szEmail, wszNick, szPhones, wszAuthMessage, 0);
}
}
+ // Hidden setting
+ else if ( CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szSetting, -1, "Hidden" , 6) == CSTR_EQUAL) {
+ GetContactBasicInfoW(hContact, &dwID, &dwGroupID, &dwContactFlag, NULL, NULL, &szEmail, &wszNick, &szPhones);
+ if (cws->value.type == DBVT_DELETED || (cws->value.type == DBVT_BYTE && cws->value.bVal == 0))
+ dwContactFlag &= ~CONTACT_FLAG_SHADOW;
+ else
+ dwContactFlag |= CONTACT_FLAG_SHADOW;
+
+ MraModifyContactW(hContact, dwID, dwContactFlag, dwGroupID, szEmail, wszNick, szPhones);
+ }
}
- }
- // not contact
- else {
- if ( CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szModule, -1, "CListGroups", 11) == CSTR_EQUAL) {
- // manage group on server
- switch (cws->value.type) {
- case DBVT_ASCIIZ:
- break;
- case DBVT_DELETED:
- break;
+ // Ignore section
+ else if ( CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szModule, -1, "Ignore", 6) == CSTR_EQUAL) {
+ if ( CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szSetting, -1, "Mask1", 5) == CSTR_EQUAL) {
+ GetContactBasicInfoW(hContact, &dwID, &dwGroupID, &dwContactFlag, NULL, NULL, &szEmail, &wszNick, &szPhones);
+ if (cws->value.type == DBVT_DELETED || (cws->value.type == DBVT_DWORD && cws->value.dVal&IGNOREEVENT_MESSAGE) == 0)
+ dwContactFlag &= ~CONTACT_FLAG_IGNORE;
+ else
+ dwContactFlag |= CONTACT_FLAG_IGNORE;
+
+ MraModifyContactW(hContact, dwID, dwContactFlag, dwGroupID, szEmail, wszNick, szPhones);
+ }
+ }
+ // User info section
+ else if (CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szModule, -1, "UserInfo", 8) == CSTR_EQUAL) {
+ if ( CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szSetting, -1, "MyPhone0", 8) == CSTR_EQUAL ||
+ CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szSetting, -1, "MyPhone1", 8) == CSTR_EQUAL ||
+ CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szSetting, -1, "MyPhone2", 8) == CSTR_EQUAL) {
+ GetContactBasicInfoW(hContact, &dwID, &dwGroupID, &dwContactFlag, NULL, NULL, &szEmail, &wszNick, &szPhones);
+ MraModifyContactW(hContact, dwID, dwContactFlag, dwGroupID, szEmail, wszNick, szPhones);
}
}
}
-
return 0;
}
@@ -577,7 +532,7 @@ int CMraProto::MraRebuildContactMenu(WPARAM wParam, LPARAM lParam)
{
BOOL bIsContactMRA, bHasEMail, bHasEMailMR, bChatAgent;
DWORD dwContactSeverFlags = 0;
- size_t dwBlogStatusMsgSize = 0;
+ CMStringW blogStatusMsgSize;
HANDLE hContact = (HANDLE)wParam;
// proto own contact
@@ -586,8 +541,8 @@ int CMraProto::MraRebuildContactMenu(WPARAM wParam, LPARAM lParam)
bHasEMail = TRUE;
bHasEMailMR = TRUE;
bChatAgent = IsContactChatAgent(hContact);
- GetContactBasicInfoW(hContact, NULL, NULL, NULL, &dwContactSeverFlags, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, NULL);
- mraGetStaticStringW(hContact, DBSETTING_BLOGSTATUS, NULL, 0, &dwBlogStatusMsgSize);
+ GetContactBasicInfoW(hContact, NULL, NULL, NULL, &dwContactSeverFlags, NULL, NULL, NULL, NULL);
+ mraGetStringW(hContact, DBSETTING_BLOGSTATUS, blogStatusMsgSize);
}
// non proto contact
else bHasEMail = bHasEMailMR = bChatAgent = FALSE;
@@ -608,7 +563,7 @@ int CMraProto::MraRebuildContactMenu(WPARAM wParam, LPARAM lParam)
Menu_ShowItem(hContactMenuItems[4], (m_bLoggedIn && bHasEMailMR && bChatAgent == FALSE));
//"Reply Blog Status"
- Menu_ShowItem(hContactMenuItems[5], (m_bLoggedIn && dwBlogStatusMsgSize && bChatAgent == FALSE));
+ Menu_ShowItem(hContactMenuItems[5], (m_bLoggedIn && blogStatusMsgSize.GetLength() && bChatAgent == FALSE));
//"View Video"
Menu_ShowItem(hContactMenuItems[6], (m_bLoggedIn && bHasEMailMR && bChatAgent == FALSE));
@@ -620,7 +575,7 @@ int CMraProto::MraRebuildContactMenu(WPARAM wParam, LPARAM lParam)
Menu_ShowItem(hContactMenuItems[8], (m_bLoggedIn && bHasEMailMR && bChatAgent == FALSE));
//"Send &Nudge"
- Menu_ShowItem(hContactMenuItems[9], (!heNudgeReceived) ? (m_bLoggedIn && bIsContactMRA) : 0);
+ Menu_ShowItem(hContactMenuItems[9], (!m_heNudgeReceived) ? (m_bLoggedIn && bIsContactMRA) : 0);
return 0;
}
@@ -641,7 +596,7 @@ int CMraProto::MraRebuildStatusMenu(WPARAM wParam, LPARAM lParam)
strncpy(szServiceFunction, m_szModuleName, sizeof(szServiceFunction));
pszServiceFunctionName = szServiceFunction + strlen(m_szModuleName);
- WCHAR szItem[MAX_PATH+64], szStatusTitle[STATUS_TITLE_MAX+4];
+ WCHAR szItem[MAX_PATH+64];
mir_sntprintf(szItem, SIZEOF(szItem), L"%s Custom Status", m_tszUserName);
CLISTMENUITEM mi = { sizeof(mi) };
@@ -652,16 +607,16 @@ int CMraProto::MraRebuildStatusMenu(WPARAM wParam, LPARAM lParam)
mi.pszService = szServiceFunction;
mi.pszContactOwner = m_szModuleName;
+ CMStringW szStatusTitle;
for (size_t i = 0; i < MRA_XSTATUS_COUNT; i++) {
mir_snprintf(pszServiceFunctionName, 100, "/menuXStatus%ld", i);
mi.position++;
if (i) {
mir_snprintf(szValueName, SIZEOF(szValueName), "XStatus%ldName", i);
- if (mraGetStaticStringW(NULL, szValueName, szStatusTitle, (STATUS_TITLE_MAX+1), NULL)) {
- szStatusTitle[STATUS_TITLE_MAX] = 0;
- mi.ptszName = szStatusTitle;
- }
- else mi.ptszName = lpcszXStatusNameDef[i];
+ if ( mraGetStringW(NULL, szValueName, szStatusTitle))
+ mi.ptszName = (TCHAR*)szStatusTitle.c_str();
+ else
+ mi.ptszName = lpcszXStatusNameDef[i];
mi.icolibItem = hXStatusAdvancedStatusIcons[i];
}
@@ -680,28 +635,19 @@ INT_PTR CMraProto::MraSetListeningTo(WPARAM wParam, LPARAM lParam)
if (pliInfo == NULL || pliInfo->cbSize != sizeof(LISTENINGTOINFO))
{
- MraChangeUserBlogStatus(MRIM_BLOG_STATUS_MUSIC, NULL, 0, 0);
+ MraChangeUserBlogStatus(MRIM_BLOG_STATUS_MUSIC, L"", 0);
delSetting(DBSETTING_BLOGSTATUSMUSIC);
}
else if (pliInfo->dwFlags & LTI_UNICODE) {
- LPWSTR pwszListeningTo;
- WCHAR wszListeningTo[MICBLOG_STATUS_MAX+4];
- size_t dwListeningToSize;
-
- if ( ServiceExists(MS_LISTENINGTO_GETPARSEDTEXT)) {
- pwszListeningTo = (LPWSTR)CallService(MS_LISTENINGTO_GETPARSEDTEXT, (WPARAM)L"%track%. %title% - %artist% - %player%", (LPARAM)pliInfo);
- dwListeningToSize = lstrlenW(pwszListeningTo);
- }
- else {
- pwszListeningTo = wszListeningTo;
- dwListeningToSize = mir_sntprintf(pwszListeningTo, SIZEOF(wszListeningTo), L"%s. %s - %s - %s", pliInfo->ptszTrack?pliInfo->ptszTrack:L"", pliInfo->ptszTitle?pliInfo->ptszTitle:L"", pliInfo->ptszArtist?pliInfo->ptszArtist:L"", pliInfo->ptszPlayer?pliInfo->ptszPlayer:L"");
- }
+ CMStringW wszListeningTo;
- mraSetStringExW(NULL, DBSETTING_BLOGSTATUSMUSIC, pwszListeningTo, dwListeningToSize);
- MraChangeUserBlogStatus(MRIM_BLOG_STATUS_MUSIC, pwszListeningTo, dwListeningToSize, 0);
+ if ( ServiceExists(MS_LISTENINGTO_GETPARSEDTEXT))
+ wszListeningTo = ptrT((LPWSTR)CallService(MS_LISTENINGTO_GETPARSEDTEXT, (WPARAM)L"%track%. %title% - %artist% - %player%", (LPARAM)pliInfo));
+ else
+ wszListeningTo.Format(L"%s. %s - %s - %s", pliInfo->ptszTrack?pliInfo->ptszTrack:L"", pliInfo->ptszTitle?pliInfo->ptszTitle:L"", pliInfo->ptszArtist?pliInfo->ptszArtist:L"", pliInfo->ptszPlayer?pliInfo->ptszPlayer:L"");
- if (pwszListeningTo != wszListeningTo)
- mir_free(pwszListeningTo);
+ mraSetStringExW(NULL, DBSETTING_BLOGSTATUSMUSIC, wszListeningTo);
+ MraChangeUserBlogStatus(MRIM_BLOG_STATUS_MUSIC, wszListeningTo, 0);
}
return 0;
@@ -714,7 +660,7 @@ int CMraProto::MraMusicChanged(WPARAM wParam, LPARAM lParam)
// stopped
if (1 == lParam) {
delSetting(DBSETTING_BLOGSTATUSMUSIC);
- MraChangeUserBlogStatus(MRIM_BLOG_STATUS_MUSIC, NULL, 0, 0);
+ MraChangeUserBlogStatus(MRIM_BLOG_STATUS_MUSIC, L"", 0);
}
break;
@@ -722,12 +668,10 @@ int CMraProto::MraMusicChanged(WPARAM wParam, LPARAM lParam)
{
SONGINFO *psiSongInfo;
if (WAT_RES_OK == CallService(MS_WAT_GETMUSICINFO, WAT_INF_UNICODE, (LPARAM)&psiSongInfo)) {
- WCHAR wszMusic[MICBLOG_STATUS_MAX+4];
- size_t dwMusicSize;
-
- dwMusicSize = mir_sntprintf(wszMusic, SIZEOF(wszMusic), L"%ld. %s - %s - %s", psiSongInfo->track, psiSongInfo->artist, psiSongInfo->title, psiSongInfo->player);
- mraSetStringExW(NULL, DBSETTING_BLOGSTATUSMUSIC, wszMusic, dwMusicSize);
- MraChangeUserBlogStatus(MRIM_BLOG_STATUS_MUSIC, wszMusic, dwMusicSize, 0);
+ CMStringW wszMusic;
+ wszMusic.Format(L"%ld. %s - %s - %s", psiSongInfo->track, psiSongInfo->artist, psiSongInfo->title, psiSongInfo->player);
+ mraSetStringExW(NULL, DBSETTING_BLOGSTATUSMUSIC, wszMusic);
+ MraChangeUserBlogStatus(MRIM_BLOG_STATUS_MUSIC, wszMusic, 0);
}
}
break;
@@ -738,29 +682,22 @@ int CMraProto::MraMusicChanged(WPARAM wParam, LPARAM lParam)
DWORD CMraProto::MraSetXStatusInternal(DWORD dwXStatus)
{
- DWORD dwOldStatusMode;
-
if ( IsXStatusValid(dwXStatus)) {
- CHAR szValueName[MAX_PATH];
- WCHAR szBuff[4096];
- size_t dwBuffSize;
+ CMStringW szBuff;
// obsolete (TODO: remove in next version)
+ char szValueName[MAX_PATH];
mir_snprintf(szValueName, SIZEOF(szValueName), "XStatus%ldName", dwXStatus);
- if (mraGetStaticStringW(NULL, szValueName, szBuff, SIZEOF(szBuff), &dwBuffSize) == FALSE) {
- lstrcpynW(szBuff, lpcszXStatusNameDef[dwXStatus], SIZEOF(szBuff));
- dwBuffSize = lstrlenW(szBuff);
- }
- if (dwBuffSize>STATUS_TITLE_MAX) dwBuffSize = STATUS_TITLE_MAX;
- mraSetStringExW(NULL, DBSETTING_XSTATUSNAME, szBuff, dwBuffSize);
+ if ( !mraGetStringW(NULL, szValueName, szBuff))
+ szBuff = lpcszXStatusNameDef[dwXStatus];
+ mraSetStringExW(NULL, DBSETTING_XSTATUSNAME, szBuff);
// obsolete (TODO: remove in next version)
mir_snprintf(szValueName, SIZEOF(szValueName), "XStatus%ldMsg", dwXStatus);
- if (mraGetStaticStringW(NULL, szValueName, szBuff, SIZEOF(szBuff), &dwBuffSize)) {
- if (dwBuffSize>STATUS_DESC_MAX) dwBuffSize = STATUS_DESC_MAX;
- mraSetStringExW(NULL, DBSETTING_XSTATUSMSG, szBuff, dwBuffSize);
- }
- else delSetting(DBSETTING_XSTATUSMSG);
+ if (mraGetStringW(NULL, szValueName, szBuff))
+ mraSetStringExW(NULL, DBSETTING_XSTATUSMSG, szBuff);
+ else
+ delSetting(DBSETTING_XSTATUSMSG);
}
else {
delSetting(DBSETTING_XSTATUSNAME);
@@ -768,10 +705,10 @@ DWORD CMraProto::MraSetXStatusInternal(DWORD dwXStatus)
dwXStatus = MRA_MIR_XSTATUS_NONE;
}
- dwOldStatusMode = InterlockedExchange((volatile LONG*)&m_iXStatus, dwXStatus);
+ DWORD dwOldStatusMode = InterlockedExchange((volatile LONG*)&m_iXStatus, dwXStatus);
setByte(DBSETTING_XSTATUSID, (BYTE)dwXStatus);
- MraSendNewStatus(m_iStatus, dwXStatus, NULL, 0, NULL, 0);
+ MraSendNewStatus(m_iStatus, dwXStatus, L"", L"");
return dwOldStatusMode;
}
@@ -795,25 +732,17 @@ INT_PTR CMraProto::MraSetXStatusEx(WPARAM wParam, LPARAM lParam)
if (pData->flags & (CSSF_MASK_NAME|CSSF_MASK_MESSAGE) && iRet == 0) {
if ( IsXStatusValid(dwXStatus) || dwXStatus == MRA_MIR_XSTATUS_NONE) {
CHAR szValueName[MAX_PATH];
- size_t dwBuffSize;
// set custom status name
if (pData->flags & CSSF_MASK_NAME) {
mir_snprintf(szValueName, SIZEOF(szValueName), "XStatus%ldName", dwXStatus);
if (pData->flags & CSSF_UNICODE) {
- dwBuffSize = lstrlenW(pData->pwszName);
- if (dwBuffSize>STATUS_TITLE_MAX) dwBuffSize = STATUS_TITLE_MAX;
-
- mraSetStringExW(NULL, szValueName, pData->pwszName, dwBuffSize);
- mraSetStringExW(NULL, DBSETTING_XSTATUSNAME, pData->pwszName, dwBuffSize);
+ mraSetStringExW(NULL, szValueName, pData->pwszName);
+ mraSetStringExW(NULL, DBSETTING_XSTATUSNAME, pData->pwszName);
}
else {
- dwBuffSize = lstrlenA(pData->pszName);
- if (dwBuffSize > STATUS_TITLE_MAX)
- dwBuffSize = STATUS_TITLE_MAX;
-
- mraSetStringExA(NULL, szValueName, pData->pszName, dwBuffSize);
- mraSetStringExA(NULL, DBSETTING_XSTATUSNAME, pData->pszName, dwBuffSize);
+ mraSetStringExA(NULL, szValueName, pData->pszName);
+ mraSetStringExA(NULL, DBSETTING_XSTATUSNAME, pData->pszName);
}
}
@@ -821,18 +750,12 @@ INT_PTR CMraProto::MraSetXStatusEx(WPARAM wParam, LPARAM lParam)
if (pData->flags & CSSF_MASK_MESSAGE) {
mir_snprintf(szValueName, SIZEOF(szValueName), "XStatus%ldMsg", dwXStatus);
if (pData->flags & CSSF_UNICODE) {
- dwBuffSize = lstrlenW(pData->pwszMessage);
- if (dwBuffSize>STATUS_TITLE_MAX) dwBuffSize = STATUS_DESC_MAX;
-
- mraSetStringExW(NULL, szValueName, pData->pwszMessage, dwBuffSize);
- mraSetStringExW(NULL, DBSETTING_XSTATUSMSG, pData->pwszMessage, dwBuffSize);
+ mraSetStringExW(NULL, szValueName, pData->pwszMessage);
+ mraSetStringExW(NULL, DBSETTING_XSTATUSMSG, pData->pwszMessage);
}
else {
- dwBuffSize = lstrlenA(pData->pszMessage);
- if (dwBuffSize>STATUS_TITLE_MAX) dwBuffSize = STATUS_DESC_MAX;
-
- mraSetStringExA(NULL, szValueName, pData->pszMessage, dwBuffSize);
- mraSetStringExA(NULL, DBSETTING_XSTATUSMSG, pData->pszMessage, dwBuffSize);
+ mraSetStringExA(NULL, szValueName, pData->pszMessage);
+ mraSetStringExA(NULL, DBSETTING_XSTATUSMSG, pData->pszMessage);
}
}
}
@@ -926,62 +849,46 @@ INT_PTR CMraProto::MraGetXStatusIcon(WPARAM wParam, LPARAM lParam)
return (INT_PTR)IconLibGetIconEx(hXStatusAdvancedStatusIcons[wParam], lParam);
}
-DWORD CMraProto::MraSendNewStatus(DWORD dwStatusMir, DWORD dwXStatusMir, LPCWSTR lpwszStatusTitle, size_t dwStatusTitleSize, LPCWSTR lpwszStatusDesc, size_t dwStatusDescSize)
+DWORD CMraProto::MraSendNewStatus(DWORD dwStatusMir, DWORD dwXStatusMir, const CMStringW &pwszStatusTitle, const CMStringW &pwszStatusDesc)
{
if (!m_bLoggedIn)
return 0;
- CHAR szValueName[MAX_PATH];
- WCHAR wszStatusTitle[STATUS_TITLE_MAX+4], wszStatusDesc[STATUS_DESC_MAX+4];
- DWORD dwStatus, dwXStatus;
-
- dwStatus = GetMraStatusFromMiradaStatus(dwStatusMir, dwXStatusMir, &dwXStatus);
+ CMStringW wszStatusTitle, wszStatusDesc;
+ DWORD dwXStatus, dwStatus = GetMraStatusFromMiradaStatus(dwStatusMir, dwXStatusMir, &dwXStatus);
if ( IsXStatusValid(dwXStatusMir)) {
- if (lpwszStatusTitle == NULL || dwStatusTitleSize == 0) {
+ char szValueName[MAX_PATH];
+ if (pwszStatusTitle.IsEmpty()) {
mir_snprintf(szValueName, SIZEOF(szValueName), "XStatus%ldName", dwXStatusMir);
// custom xstatus name
- if (mraGetStaticStringW(NULL, szValueName, wszStatusTitle, (STATUS_TITLE_MAX+1), &dwStatusTitleSize))
- lpwszStatusTitle = wszStatusTitle;
- // default xstatus name
- else {
- lpwszStatusTitle = TranslateW(lpcszXStatusNameDef[dwXStatusMir]);
- dwStatusTitleSize = lstrlenW(lpwszStatusTitle);
- }
+ if ( !mraGetStringW(NULL, szValueName, wszStatusTitle))
+ wszStatusTitle = TranslateW(lpcszXStatusNameDef[dwXStatusMir]);
}
+ else wszStatusTitle = pwszStatusTitle;
- if (lpwszStatusDesc == NULL || dwStatusDescSize == 0) {
+ if (pwszStatusDesc.IsEmpty()) {
mir_snprintf(szValueName, SIZEOF(szValueName), "XStatus%ldMsg", dwXStatusMir);
// custom xstatus description
- if (mraGetStaticStringW(NULL, szValueName, wszStatusDesc, (STATUS_DESC_MAX+1), &dwStatusDescSize))
- lpwszStatusDesc = wszStatusDesc;
- // default xstatus description
- else {
- lpwszStatusDesc = NULL;
- dwStatusDescSize = 0;
- }
- }
- }
- else {
- if (lpwszStatusTitle == NULL || dwStatusTitleSize == 0) {
- lpwszStatusTitle = GetStatusModeDescriptionW(dwStatusMir);
- dwStatusTitleSize = lstrlenW(lpwszStatusTitle);
+ mraGetStringW(NULL, szValueName, wszStatusDesc);
}
+ else wszStatusDesc = pwszStatusDesc;
}
+ else if (pwszStatusTitle.IsEmpty())
+ wszStatusTitle = GetStatusModeDescriptionW(dwStatusMir);
- MraChangeStatusW(dwStatus, lpcszStatusUri[dwXStatus], lstrlenA(lpcszStatusUri[dwXStatus]), lpwszStatusTitle, dwStatusTitleSize, lpwszStatusDesc, dwStatusDescSize, ((getByte("RTFReceiveEnable", MRA_DEFAULT_RTF_RECEIVE_ENABLE)? FEATURE_FLAG_RTF_MESSAGE:0)|MRA_FEATURE_FLAGS));
+ MraChangeStatusW(dwStatus, lpcszStatusUri[dwXStatus], wszStatusTitle, wszStatusDesc, ((getByte("RTFReceiveEnable", MRA_DEFAULT_RTF_RECEIVE_ENABLE)? FEATURE_FLAG_RTF_MESSAGE:0)|MRA_FEATURE_FLAGS));
return 0;
}
INT_PTR CMraProto::MraSendNudge(WPARAM wParam, LPARAM lParam)
{
if (m_bLoggedIn && wParam) {
- CHAR szEMail[MAX_EMAIL_LEN];
LPWSTR lpwszAlarmMessage = TranslateW(MRA_ALARM_MESSAGE);
- size_t dwEMailSize;
HANDLE hContact = (HANDLE)wParam;
- if (mraGetStaticStringA(hContact, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize))
- if (MraMessageW(FALSE, hContact, 0, (MESSAGE_FLAG_RTF|MESSAGE_FLAG_ALARM), szEMail, dwEMailSize, lpwszAlarmMessage, lstrlenW(lpwszAlarmMessage), NULL, 0))
+ CMStringA szEmail;
+ if (mraGetStringA(hContact, "e-mail", szEmail))
+ if (MraMessageW(FALSE, hContact, 0, (MESSAGE_FLAG_RTF|MESSAGE_FLAG_ALARM), szEmail, lpwszAlarmMessage, NULL, 0))
return 0;
}
return 1;
@@ -1003,7 +910,7 @@ INT_PTR CMraProto::MraGetAvatarCaps(WPARAM wParam, LPARAM lParam)
return 0; // no formats to set
case AF_ENABLED:
- return 1; // allways on
+ return 1; // always on
case AF_DONTNEEDDELAYS:
return 0; // need delay
@@ -1031,8 +938,9 @@ INT_PTR CMraProto::MraGetAvatarInfo(WPARAM wParam, LPARAM lParam)
INT_PTR CMraProto::MraGetMyAvatar(WPARAM wParam, LPARAM lParam)
{
- if ( MraAvatarsGetFileName(hAvatarsQueueHandle, NULL, GetContactAvatarFormat(NULL, PA_FORMAT_DEFAULT), (LPTSTR)wParam, (size_t)lParam, NULL) == NO_ERROR) {
- LPSTR lpsz = (LPSTR)wParam;
+ CMStringW wszFileName;
+ if ( MraAvatarsGetFileName(hAvatarsQueueHandle, NULL, GetContactAvatarFormat(NULL, PA_FORMAT_DEFAULT), wszFileName) == NO_ERROR) {
+ lstrcpyn((LPTSTR)wParam, wszFileName, (size_t)lParam);
return 0;
}
return 1;
diff --git a/protocols/MRA/src/Sdk/InternetTime.h b/protocols/MRA/src/Sdk/InternetTime.h
index dae0ee0ce3..b226929299 100644
--- a/protocols/MRA/src/Sdk/InternetTime.h
+++ b/protocols/MRA/src/Sdk/InternetTime.h
@@ -282,61 +282,56 @@ __inline void InternetTimeGetCurrentTime(INTERNET_TIME *pitTime)
}
-__inline DWORD InternetTimeGetString(INTERNET_TIME *pitTime,LPSTR lpszBuff,size_t dwBuffSize,size_t *pdwBuffSizeRet)
+__inline CMStringA InternetTimeGetString(INTERNET_TIME *pitTime)
{// Переводит время из MAILTIME в строковое
DWORD dwRet=NO_ERROR;
- if (dwBuffSize>31)
- {
- LPSTR lpszCurPos=lpszBuff;
- size_t dwTimeLen=0,dwtm;
+ char lpszBuff[100];
+ LPSTR lpszCurPos = lpszBuff;
+ size_t dwTimeLen=0,dwtm;
- // day of weak// date of mounth// mounth name// year// hours // minutes// seconds
- dwtm=wsprintfA(lpszCurPos,"%s, %02lu %s %04lu %02lu:%02lu:%02lu ",lpcszenmDayOfWeakEnum[pitTime->stTime.wDayOfWeek],pitTime->stTime.wDay,lpcszenmMonthEnum[pitTime->stTime.wMonth],pitTime->stTime.wYear,pitTime->stTime.wHour,pitTime->stTime.wMinute,pitTime->stTime.wSecond);
- lpszCurPos+=dwtm;
- dwTimeLen+=dwtm;
+ // day of weak// date of mounth// mounth name// year// hours // minutes// seconds
+ dwtm=wsprintfA(lpszCurPos,"%s, %02lu %s %04lu %02lu:%02lu:%02lu ",lpcszenmDayOfWeakEnum[pitTime->stTime.wDayOfWeek],pitTime->stTime.wDay,lpcszenmMonthEnum[pitTime->stTime.wMonth],pitTime->stTime.wYear,pitTime->stTime.wHour,pitTime->stTime.wMinute,pitTime->stTime.wSecond);
+ lpszCurPos+=dwtm;
+ dwTimeLen+=dwtm;
- // time zone
- if (pitTime->lTimeZone)
- {
- if (pitTime->lTimeZone < 0)
- {// нужно добавить плюсик, минус добавляется автоматом
- (*((BYTE*)lpszCurPos))='+';
- lpszCurPos++;
- dwTimeLen++;
- }
-
- dwtm=wsprintfA(lpszCurPos,"%04ld",-(((pitTime->lTimeZone/60)*100)+pitTime->lTimeZone%60));
- lpszCurPos+=dwtm;
- dwTimeLen+=dwtm;
- }else{
- dwtm=wsprintfA(lpszCurPos,"GMT");
- lpszCurPos+=dwtm;
- dwTimeLen+=dwtm;
+ // time zone
+ if (pitTime->lTimeZone)
+ {
+ if (pitTime->lTimeZone < 0)
+ {// нужно добавить плюсик, минус добавляется автоматом
+ (*((BYTE*)lpszCurPos))='+';
+ lpszCurPos++;
+ dwTimeLen++;
}
- if (pdwBuffSizeRet) (*pdwBuffSizeRet)=dwTimeLen;
- }else{// переданный буффер слишком мал
- if (pdwBuffSizeRet) (*pdwBuffSizeRet)=32;
- dwRet=ERROR_INSUFFICIENT_BUFFER;
+ dwtm=wsprintfA(lpszCurPos,"%04ld",-(((pitTime->lTimeZone/60)*100)+pitTime->lTimeZone%60));
+ lpszCurPos+=dwtm;
+ dwTimeLen+=dwtm;
}
-return(dwRet);
+ else{
+ dwtm=wsprintfA(lpszCurPos,"GMT");
+ lpszCurPos+=dwtm;
+ dwTimeLen+=dwtm;
+ }
+
+ return lpszBuff;
}
-__inline DWORD InternetTimeGetTime(LPCSTR lpszTime,size_t dwTimeSize,INTERNET_TIME *pitTime)
+__inline DWORD InternetTimeGetTime(const CMStringA &lpszTime, INTERNET_TIME *pitTime)
{// Переводит время из строкового в INTERNET_TIME
DWORD dwRet=NO_ERROR;
- if (lpszTime && dwTimeSize && dwTimeSize<4097 && pitTime)
+ if (!lpszTime.IsEmpty() && pitTime)
{// = Thu, 21 May 1998 05:33:29 -0700 =
char sztmBuff[4096];
LPSTR lpszCurPos=sztmBuff,lpszTemp;
size_t i,dwCurSize=4096,dwTemp;
memset(pitTime, 0, sizeof(INTERNET_TIME));
- WSP2SP((LPSTR)lpszTime,dwTimeSize,lpszCurPos,&dwCurSize);
+ WSP2SP(lpszTime, lpszTime.GetLength(), lpszCurPos, &dwCurSize);
if (dwCurSize>3)
{// день недели
diff --git a/protocols/MRA/src/version.h b/protocols/MRA/src/version.h
index b7ce1137bf..8ec3205d42 100644
--- a/protocols/MRA/src/version.h
+++ b/protocols/MRA/src/version.h
@@ -1,6 +1,6 @@
-#define __FILEVERSION_STRING 2, 0, 0, 1
-#define __VERSION_STRING "2.0.0.1"
-#define __VERSION_DWORD PLUGIN_MAKE_VERSION(2, 0, 0, 1)
+#define __FILEVERSION_STRING 2, 1, 0, 1
+#define __VERSION_STRING "2.1.0.1"
+#define __VERSION_DWORD PLUGIN_MAKE_VERSION(2, 1, 0, 1)
#define PROTO_VERSION_MAJOR 1
#define PROTO_VERSION_MINOR 21