summaryrefslogtreecommitdiff
path: root/protocols/MRA/MraSendCommand.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-09-11 19:28:53 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-09-11 19:28:53 +0000
commit274cffbbffa950ddf286092b52f03f76ec61a301 (patch)
tree5aeb062d27c79d1fbc15eaf033da943630bcbf84 /protocols/MRA/MraSendCommand.cpp
parent482be69d327aef60a9a654b8cc6a5e6646d095de (diff)
slightly refactored MRA
git-svn-id: http://svn.miranda-ng.org/main/trunk@1564 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/MRA/MraSendCommand.cpp')
-rw-r--r--protocols/MRA/MraSendCommand.cpp1267
1 files changed, 540 insertions, 727 deletions
diff --git a/protocols/MRA/MraSendCommand.cpp b/protocols/MRA/MraSendCommand.cpp
index f27ef57860..f192afe889 100644
--- a/protocols/MRA/MraSendCommand.cpp
+++ b/protocols/MRA/MraSendCommand.cpp
@@ -3,876 +3,689 @@
#include "MraRTFMsg.h"
#include "proto.h"
+static void SetUL(LPBYTE *plpBuff, DWORD dwData)
+{
+ (*(DWORD*)(*plpBuff)) = dwData;
+ (*plpBuff) += sizeof(DWORD);
+}
+static void SetUIDL(LPBYTE *plpBuff, DWORDLONG dwData)
+{
+ (*(DWORDLONG*)(*plpBuff)) = dwData;
+ (*plpBuff) += sizeof(DWORDLONG);
+}
+static void SetGUID(LPBYTE *plpBuff, MRA_GUID guidData)
+{
+ (*(MRA_GUID*)(*plpBuff)) = guidData;
+ (*plpBuff) += sizeof(MRA_GUID);
+}
+static void SetLPS(LPBYTE *plpBuff, LPCSTR lpszData, DWORD dwSize)
+{
+ (*(DWORD*)(*plpBuff)) = dwSize;
+ (*plpBuff) += sizeof(DWORD);
+ memmove((*plpBuff), lpszData, dwSize);
+ (*plpBuff) += dwSize;
+}
-void SetUL (LPBYTE *plpBuff,DWORD dwData);
-void SetUIDL (LPBYTE *plpBuff,DWORDLONG dwData);
-void SetGUID (LPBYTE *plpBuff,MRA_GUID guidData);
-void SetLPS (LPBYTE *plpBuff,LPSTR lpszData,DWORD dwSize);
-void SetLPSW (LPBYTE *plpBuff,LPWSTR lpwszData,DWORD dwSize);
-void SetLPSWtoA (LPBYTE *plpBuff,LPWSTR lpwszData,DWORD dwSize);
-void SetLPSLowerCase (LPBYTE *plpBuff,LPSTR lpszData,DWORD dwSize);
-void SetLPSLowerCaseW (LPBYTE *plpBuff,LPWSTR lpwszData,DWORD dwSize);
-
-
+static void SetLPSW(LPBYTE *plpBuff, LPCWSTR lpwszData, DWORD dwSize)
+{
+ dwSize *= sizeof(WCHAR);
+ (*(DWORD*)(*plpBuff)) = dwSize;
+ (*plpBuff) += sizeof(DWORD);
+ memmove((*plpBuff), lpwszData, dwSize);
+ (*plpBuff) += dwSize;
+}
+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);
+}
+static void SetLPSLowerCase(LPBYTE *plpBuff, LPCSTR lpszData, DWORD dwSize)
+{
+ (*(DWORD*)(*plpBuff)) = dwSize;
+ (*plpBuff) += sizeof(DWORD);
+ BuffToLowerCase((*plpBuff), lpszData, dwSize);
+ (*plpBuff) += dwSize;
+}
+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;
+}
-DWORD MraSendCommand_MessageW(BOOL bAddToQueue,HANDLE hContact,DWORD dwAckType,DWORD dwFlags,LPSTR lpszEMail,SIZE_T dwEMailSize,LPWSTR lpwszMessage,SIZE_T dwMessageSize,LPBYTE lpbMultiChatData,SIZE_T dwMultiChatDataSize)
-{// Сообщение
- DWORD dwRet=0;
- LPBYTE lpbData,lpbDataCurrent;
- LPSTR lpszMessageConverted=(LPSTR)lpwszMessage;
- LPSTR lpszMessageRTF=NULL;
- SIZE_T dwMessageConvertedSize=(dwMessageSize*sizeof(WCHAR)),dwMessageRTFSize=0;
+/////////////////////////////////////////////////////////////////////////////////////////
+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 dwRet = 0;
+ LPBYTE lpbData, lpbDataCurrent;
+ LPSTR lpszMessageConverted = (LPSTR)lpwszMessage;
+ LPSTR lpszMessageRTF = NULL;
+ size_t dwMessageConvertedSize = (dwMessageSize*sizeof(WCHAR)), dwMessageRTFSize = 0;
- if (MraIsMessageFlashAnimation(lpwszMessage,dwMessageSize)) dwFlags|=MESSAGE_FLAG_FLASH;
+ if ( MraIsMessageFlashAnimation(lpwszMessage, dwMessageSize))
+ dwFlags |= MESSAGE_FLAG_FLASH;
- if (dwFlags&MESSAGE_FLAG_AUTHORIZE)
- {// pack auth message
+ // pack auth message
+ if (dwFlags & MESSAGE_FLAG_AUTHORIZE) {
LPBYTE lpbAuthMsgBuff;
- SIZE_T dwMessageConvertedBuffSize=(((((dwMessageSize*sizeof(WCHAR))+1024)+2)/3)*4);
+ size_t dwMessageConvertedBuffSize = (((((dwMessageSize*sizeof(WCHAR))+1024)+2)/3)*4);
- lpszMessageConverted=(LPSTR)MEMALLOC(dwMessageConvertedBuffSize);
- lpbAuthMsgBuff=(LPBYTE)MEMALLOC(((dwMessageSize*sizeof(WCHAR))+1024));
- if (lpszMessageConverted && lpbAuthMsgBuff)
- {
- lpbDataCurrent=lpbAuthMsgBuff;
- SetUL(&lpbDataCurrent,2);
- SetLPSW(&lpbDataCurrent,NULL,0);//***deb possible nick here
- SetLPSW(&lpbDataCurrent,lpwszMessage,dwMessageSize);
-
- BASE64EncodeUnSafe(lpbAuthMsgBuff,(lpbDataCurrent-lpbAuthMsgBuff),lpszMessageConverted,dwMessageConvertedBuffSize,&dwMessageConvertedSize);
- }else{
- MEMFREE(lpszMessageConverted);
- lpszMessageConverted=(LPSTR)lpwszMessage;
+ lpszMessageConverted = (LPSTR)mir_calloc(dwMessageConvertedBuffSize);
+ lpbAuthMsgBuff = (LPBYTE)mir_calloc(((dwMessageSize*sizeof(WCHAR))+1024));
+ if (lpszMessageConverted && lpbAuthMsgBuff) {
+ lpbDataCurrent = lpbAuthMsgBuff;
+ SetUL(&lpbDataCurrent, 2);
+ SetLPSW(&lpbDataCurrent, NULL, 0);//***deb possible nick here
+ SetLPSW(&lpbDataCurrent, (LPWSTR)lpwszMessage, dwMessageSize);
+
+ BASE64EncodeUnSafe(lpbAuthMsgBuff, (lpbDataCurrent-lpbAuthMsgBuff), lpszMessageConverted, dwMessageConvertedBuffSize, &dwMessageConvertedSize);
}
- MEMFREE(lpbAuthMsgBuff);
- }else
- if (dwFlags&MESSAGE_FLAG_FLASH)
- {// особая упаковка для флеша
- if (masMraSettings.lpfnCompress2)// only if func exist
- {
- SIZE_T dwRFTBuffSize=(((dwMessageSize*sizeof(WCHAR))*4)+8192),dwRTFDataSize;
+ else {
+ mir_free(lpszMessageConverted);
+ lpszMessageConverted = (LPSTR)lpwszMessage;
+ }
+ mir_free(lpbAuthMsgBuff);
+ }
+ // messages with Flash
+ else if (dwFlags & MESSAGE_FLAG_FLASH) {
+ if (masMraSettings.lpfnCompress2) { // only if func exist
+ size_t dwRFTBuffSize = (((dwMessageSize*sizeof(WCHAR))*4)+8192), dwRTFDataSize;
LPBYTE lpbRTFData;
- dwFlags|=MESSAGE_FLAG_RTF;
- lpszMessageRTF=(LPSTR)MEMALLOC(dwRFTBuffSize);
- lpbRTFData=(LPBYTE)MEMALLOC(dwRFTBuffSize);
- if (lpszMessageRTF && lpbRTFData)
- {
- DWORD dwBackColour;
+ dwFlags |= MESSAGE_FLAG_RTF;
+ lpszMessageRTF = (LPSTR)mir_calloc(dwRFTBuffSize);
+ lpbRTFData = (LPBYTE)mir_calloc(dwRFTBuffSize);
+ if (lpszMessageRTF && lpbRTFData) {
+ DWORD dwBackColour = mraGetDword(NULL, "RTFBackgroundColour", MRA_DEFAULT_RTF_BACKGROUND_COLOUR);
+ lpbDataCurrent = (LPBYTE)lpszMessageRTF;
- dwBackColour=DB_Mra_GetDword(NULL,"RTFBackgroundColour",MRA_DEFAULT_RTF_BACKGROUND_COLOUR);
- lpbDataCurrent=(LPBYTE)lpszMessageRTF;
+ WideCharToMultiByte(MRA_CODE_PAGE, 0, lpwszMessage, dwMessageSize, (LPSTR)lpbRTFData, dwRFTBuffSize, NULL, NULL);
- 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
- 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 ((PCOMPRESS2(masMraSettings.lpfnCompress2))(lpbRTFData,(DWORD*)&dwRTFDataSize,(LPBYTE)lpszMessageRTF,(lpbDataCurrent-(LPBYTE)lpszMessageRTF),Z_BEST_COMPRESSION)==Z_OK)
- {
- BASE64EncodeUnSafe(lpbRTFData,dwRTFDataSize,lpszMessageRTF,dwRFTBuffSize,&dwMessageRTFSize);
- }
+ dwRTFDataSize = dwRFTBuffSize;
+ if ((PCOMPRESS2(masMraSettings.lpfnCompress2))(lpbRTFData, (DWORD*)&dwRTFDataSize, (LPBYTE)lpszMessageRTF, (lpbDataCurrent-(LPBYTE)lpszMessageRTF), Z_BEST_COMPRESSION) == Z_OK)
+ BASE64EncodeUnSafe(lpbRTFData, dwRTFDataSize, lpszMessageRTF, dwRFTBuffSize, &dwMessageRTFSize);
}
- MEMFREE(lpbRTFData);
+ mir_free(lpbRTFData);
}
- }else// standart message
- 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
- if (masMraSettings.lpfnCompress2)// only if func exist
- {// обычный ртф
- SIZE_T dwRFTBuffSize=(((dwMessageSize*sizeof(WCHAR))*16)+8192),dwRTFDataSize;
+ }
+ // 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
+ if (masMraSettings.lpfnCompress2) { // обычный ртф
+ size_t dwRFTBuffSize = (((dwMessageSize*sizeof(WCHAR))*16)+8192), dwRTFDataSize;
LPBYTE lpbRTFData;
- lpszMessageRTF=(LPSTR)MEMALLOC(dwRFTBuffSize);
- lpbRTFData=(LPBYTE)MEMALLOC(dwRFTBuffSize);
- if (lpszMessageRTF && lpbRTFData)
- {
- if (MraConvertToRTFW(lpwszMessage,dwMessageSize,(LPSTR)lpbRTFData,dwRFTBuffSize,&dwRTFDataSize)==NO_ERROR)
- {
- DWORD dwBackColour;
-
- dwBackColour=DB_Mra_GetDword(NULL,"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 ((PCOMPRESS2(masMraSettings.lpfnCompress2))(lpbRTFData,(DWORD*)&dwRTFDataSize,(LPBYTE)lpszMessageRTF,(lpbDataCurrent-(LPBYTE)lpszMessageRTF),Z_BEST_COMPRESSION)==Z_OK)
- {
- BASE64EncodeUnSafe(lpbRTFData,dwRTFDataSize,lpszMessageRTF,dwRFTBuffSize,&dwMessageRTFSize);
- }
+ lpszMessageRTF = (LPSTR)mir_calloc(dwRFTBuffSize);
+ lpbRTFData = (LPBYTE)mir_calloc(dwRFTBuffSize);
+ if (lpszMessageRTF && lpbRTFData) {
+ if ( !MraConvertToRTFW(lpwszMessage, dwMessageSize, (LPSTR)lpbRTFData, dwRFTBuffSize, &dwRTFDataSize)) {
+ DWORD dwBackColour = mraGetDword(NULL, "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 ((PCOMPRESS2(masMraSettings.lpfnCompress2))(lpbRTFData, (DWORD*)&dwRTFDataSize, (LPBYTE)lpszMessageRTF, (lpbDataCurrent-(LPBYTE)lpszMessageRTF), Z_BEST_COMPRESSION) == Z_OK)
+ BASE64EncodeUnSafe(lpbRTFData, dwRTFDataSize, lpszMessageRTF, dwRFTBuffSize, &dwMessageRTFSize);
}
}
- MEMFREE(lpbRTFData);
+ mir_free(lpbRTFData);
}
- }//*/
- if (lpszMessageRTF==NULL || dwMessageRTFSize==0) dwFlags&=~(MESSAGE_FLAG_RTF|MESSAGE_FLAG_FLASH);
- if (lpbMultiChatData==NULL || dwMultiChatDataSize==0) dwFlags&=~MESSAGE_FLAG_MULTICHAT;
-
- lpbData=(LPBYTE)MEMALLOC((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 (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(masMraSettings.hSendQueueHandle,0,hContact,dwAckType,(LPBYTE)lpwszMessage,(dwMessageSize*sizeof(WCHAR)),MRIM_CS_MESSAGE,lpbData,(lpbDataCurrent-lpbData));
- }else{
- dwRet=MraSendCMD(MRIM_CS_MESSAGE,lpbData,(lpbDataCurrent-lpbData));
- }
- MEMFREE(lpbData);
+ 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);
}
- if (lpszMessageConverted!=(LPSTR)lpwszMessage) MEMFREE(lpszMessageConverted);
- MEMFREE(lpszMessageRTF);
-
-return(dwRet);
-}
-
-DWORD MraSendCommand_MessageAskW(DWORD dwMsgID,DWORD dwFlags,LPSTR lpszEMail,SIZE_T dwEMailSize,LPWSTR lpwszMessage,SIZE_T dwMessageSize,LPSTR lpwszMessageRTF,SIZE_T dwMessageRTFSize)
-{// Подтверждение получения сообщения
- DWORD dwRet=0;
+ if (lpszMessageConverted != (LPSTR)lpwszMessage)
+ mir_free(lpszMessageConverted);
+ mir_free(lpszMessageRTF);
- if (lpszEMail && dwEMailSize>4 && lpwszMessage && dwMessageSize)
- {
- LPBYTE lpbData,lpbDataCurrent;
+ return dwRet;
+}
- lpbData=(LPBYTE)MEMALLOC((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
+// 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 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
+ SetLPS(&lpbDataCurrent, (LPSTR)lpwszMessageRTF, dwMessageRTFSize);// LPS //rtf-formatted message ( >= 1.1) - MESSAGE_FLAG_RTF
- dwRet=MraSendCMD(MRIM_CS_MESSAGE_ACK,lpbData,(lpbDataCurrent-lpbData));
- //dwRet=MraSendCMD(MRIM_CS_MESSAGE,lpbData,(lpbDataCurrent-lpbData));
- MEMFREE(lpbData);
+ dwRet = MraSendCMD(MRIM_CS_MESSAGE_ACK, lpbData, (lpbDataCurrent-lpbData));
+ mir_free(lpbData);
}
- }else{
- DebugBreak();
}
-return(dwRet);
-}
-
-DWORD MraSendCommand_MessageRecv(LPSTR lpszFrom,SIZE_T dwFromSize,DWORD dwMsgID)
-{// Подтверждение получения сообщения
- DWORD dwRet=0;
-
- if (lpszFrom && dwFromSize>4)
- {
- LPBYTE lpbData,lpbDataCurrent;
-
- lpbData=(LPBYTE)MEMALLOC((dwFromSize+sizeof(DWORD)+32));
- if (lpbData)
- {
- lpbDataCurrent=lpbData;
- SetLPSLowerCase(&lpbDataCurrent,lpszFrom,dwFromSize);
- SetUL(&lpbDataCurrent,dwMsgID);
+ return dwRet;
+}
- dwRet=MraSendCMD(MRIM_CS_MESSAGE_RECV,lpbData,(lpbDataCurrent-lpbData));
- MEMFREE(lpbData);
+DWORD CMraProto::MraMessageRecv(LPSTR lpszFrom, size_t dwFromSize, DWORD dwMsgID)
+{
+ DWORD dwRet = 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);
}
- }else{
- DebugBreak();
}
-return(dwRet);
+ return dwRet;
}
-
-DWORD MraSendCommand_AddContactW(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 dwRet=0;
-
- if (lpszEMail && dwEMailSize>4)
- {
- LPBYTE lpbData,lpbDataCurrent;
-
- lpbData=(LPBYTE)MEMALLOC((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;
-
- 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,lpbAuthMessageConverted,lpbAuthDataCurrent;
- SIZE_T dwAuthMessageConvertedBuffSize=(((((dwAuthMessageSize*sizeof(WCHAR))+1024)+2)/3)*4),dwAuthMessageConvertedSize=0;
+// 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 dwRet = 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, lpbAuthMessageConverted, lpbAuthDataCurrent;
+ size_t dwAuthMessageConvertedBuffSize = (((((dwAuthMessageSize*sizeof(WCHAR))+1024)+2)/3)*4), dwAuthMessageConvertedSize = 0;
- lpbAuthMessageConverted=(LPBYTE)MEMALLOC(dwAuthMessageConvertedBuffSize);
- lpbAuthMsgBuff=(LPBYTE)MEMALLOC(((dwAuthMessageSize*sizeof(WCHAR))+1024));
- if (lpbAuthMessageConverted && lpbAuthMsgBuff)
- {
- lpbAuthDataCurrent=lpbAuthMsgBuff;
- SetUL(&lpbAuthDataCurrent,2);
- SetLPSW(&lpbAuthDataCurrent,NULL,0);//***deb possible nick here
- SetLPSW(&lpbAuthDataCurrent,lpwszAuthMessage,dwAuthMessageSize);
-
- BASE64EncodeUnSafe(lpbAuthMsgBuff,(lpbAuthDataCurrent-lpbAuthMsgBuff),lpbAuthMessageConverted,dwAuthMessageConvertedBuffSize,&dwAuthMessageConvertedSize);
- }
- SetLPS(&lpbDataCurrent,(LPSTR)lpbAuthMessageConverted,dwAuthMessageConvertedSize);
- MEMFREE(lpbAuthMsgBuff);
- MEMFREE(lpbAuthMessageConverted);
+ lpbAuthMessageConverted = (LPBYTE)mir_calloc(dwAuthMessageConvertedBuffSize);
+ lpbAuthMsgBuff = (LPBYTE)mir_calloc(((dwAuthMessageSize*sizeof(WCHAR))+1024));
+ if (lpbAuthMessageConverted && lpbAuthMsgBuff) {
+ lpbAuthDataCurrent = lpbAuthMsgBuff;
+ SetUL(&lpbAuthDataCurrent, 2);
+ SetLPSW(&lpbAuthDataCurrent, NULL, 0);//***deb possible nick here
+ SetLPSW(&lpbAuthDataCurrent, lpwszAuthMessage, dwAuthMessageSize);
+
+ BASE64EncodeUnSafe(lpbAuthMsgBuff, (lpbAuthDataCurrent-lpbAuthMsgBuff), lpbAuthMessageConverted, dwAuthMessageConvertedBuffSize, &dwAuthMessageConvertedSize);
}
- SetUL(&lpbDataCurrent,dwActions);
+ SetLPS(&lpbDataCurrent, (LPSTR)lpbAuthMessageConverted, dwAuthMessageConvertedSize);
+ mir_free(lpbAuthMsgBuff);
+ mir_free(lpbAuthMessageConverted);
+
+ SetUL(&lpbDataCurrent, dwActions);
- dwRet=MraSendQueueCMD(masMraSettings.hSendQueueHandle,0,hContact,ACKTYPE_ADDED,NULL,0,MRIM_CS_ADD_CONTACT,lpbData,(lpbDataCurrent-lpbData));
- MEMFREE(lpbData);
+ dwRet = MraSendQueueCMD(hSendQueueHandle, 0, hContact, ACKTYPE_ADDED, NULL, 0, MRIM_CS_ADD_CONTACT, lpbData, (lpbDataCurrent-lpbData));
+ mir_free(lpbData);
}
- }else{
- //DebugBreak();
}
-return(dwRet);
+ return dwRet;
}
-
-DWORD MraSendCommand_ModifyContactW(HANDLE hContact,DWORD dwID,DWORD dwContactFlag,DWORD dwGroupID,LPSTR lpszEMail,SIZE_T dwEMailSize,LPWSTR lpwszCustomName,SIZE_T dwCustomNameSize,LPSTR lpszPhones,SIZE_T dwPhonesSize)
-{// Изменение контакта
- DWORD dwRet=0;
-
- LPBYTE lpbData,lpbDataCurrent;
-
- if (dwID!=-1)
- {
- lpbData=(LPBYTE)MEMALLOC((sizeof(DWORD)+sizeof(DWORD)+sizeof(DWORD)+dwEMailSize+(dwCustomNameSize*sizeof(WCHAR))+dwPhonesSize+32));
+// 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 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;
-
- 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(masMraSettings.hSendQueueHandle,0,hContact,ACKTYPE_ADDED,NULL,0,MRIM_CS_MODIFY_CONTACT,lpbData,(lpbDataCurrent-lpbData));
- MEMFREE(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);
}
- }else{
- DebugBreak();
}
-return(dwRet);
+ return dwRet;
}
-
-DWORD MraSendCommand_OfflineMessageDel(DWORDLONG dwMsgUIDL)
-{// Удаление сохраненного сообщения
-return(MraSendCMD(MRIM_CS_DELETE_OFFLINE_MESSAGE,&dwMsgUIDL,sizeof(DWORDLONG)));
+// remove stored message
+DWORD CMraProto::MraOfflineMessageDel(DWORDLONG dwMsgUIDL)
+{
+ return MraSendCMD(MRIM_CS_DELETE_OFFLINE_MESSAGE, &dwMsgUIDL, sizeof(DWORDLONG));
}
-
-DWORD MraSendCommand_Authorize(LPSTR lpszEMail,SIZE_T dwEMailSize)
-{// Авторизация пользователя на добавление в контакт-лист
- DWORD dwRet=0;
-
- if (lpszEMail && dwEMailSize>4)
- {
- LPBYTE lpbData,lpbDataCurrent;
-
- lpbData=(LPBYTE)MEMALLOC((dwEMailSize+32));
- if (lpbData)
- {
- lpbDataCurrent=lpbData;
- SetLPSLowerCase(&lpbDataCurrent,lpszEMail,dwEMailSize);
-
- dwRet=MraSendCMD(MRIM_CS_AUTHORIZE,lpbData,(lpbDataCurrent-lpbData));
- MEMFREE(lpbData);
+// autorize a user & add him to a roster
+DWORD CMraProto::MraAuthorize(LPSTR lpszEMail, size_t dwEMailSize)
+{
+ DWORD dwRet = 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);
}
- }else{
- DebugBreak();
}
-return(dwRet);
+ return dwRet;
}
-
-DWORD MraSendCommand_ChangeStatusW(DWORD dwStatus,LPSTR lpszStatusUri,SIZE_T dwStatusUriSize,LPWSTR lpwszStatusTitle,SIZE_T dwStatusTitleSize,LPWSTR lpwszStatusDesc,SIZE_T dwStatusDescSize,DWORD dwFutureFlags)
-{// Изменение статуса
- DWORD dwRet=0;
- LPBYTE lpbData,lpbDataCurrent;
-
- 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;
-
- lpbData=(LPBYTE)MEMALLOC((sizeof(DWORD)+dwStatusUriSize+(dwStatusTitleSize*sizeof(WCHAR))+(dwStatusDescSize*sizeof(WCHAR))+sizeof(DWORD)+32));
- if (lpbData)
- {
- 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));
- MEMFREE(lpbData);
+// 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 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);
+ return dwRet;
}
+// Отправка файлов
+DWORD CMraProto::MraFileTransfer(LPSTR lpszEMail, size_t dwEMailSize, DWORD dwIDRequest, DWORD dwFilesTotalSize, LPWSTR lpwszFiles, size_t dwFilesSize, LPSTR lpszAddreses, size_t dwAddresesSize)
+{
+ DWORD dwRet = 0;
-DWORD MraSendCommand_FileTransfer(LPSTR lpszEMail,SIZE_T dwEMailSize,DWORD dwIDRequest,DWORD dwFilesTotalSize,LPWSTR lpwszFiles,SIZE_T dwFilesSize,LPSTR lpszAddreses,SIZE_T dwAddresesSize)
-{// Отправка файлов
- DWORD dwRet=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))+dwAddresesSize+MAX_PATH));
+ if (lpbData) {
+ LPBYTE lpbDataCurrent = lpbData;
+ SetLPSLowerCase(&lpbDataCurrent, lpszEMail, dwEMailSize);
+ SetUL(&lpbDataCurrent, dwIDRequest);
+ SetUL(&lpbDataCurrent, dwFilesTotalSize);
+ SetUL(&lpbDataCurrent, (sizeof(DWORD)+dwFilesSizeA + sizeof(DWORD)+(sizeof(DWORD)+sizeof(DWORD)+(dwFilesSize*sizeof(WCHAR))) + sizeof(DWORD)+(DWORD)dwAddresesSize));
- if (lpszEMail && dwEMailSize>4)
- {
- SIZE_T dwFilesSizeA;
- LPBYTE lpbData,lpbDataCurrent;
+ SetLPSWtoA(&lpbDataCurrent, lpwszFiles, dwFilesSize);
+ SetUL(&lpbDataCurrent, (sizeof(DWORD)+sizeof(DWORD)+(dwFilesSize*sizeof(WCHAR))));
- dwFilesSizeA=WideCharToMultiByte(MRA_CODE_PAGE,0,lpwszFiles,dwFilesSize,NULL,0,NULL,NULL);
- lpbData=(LPBYTE)MEMALLOC((dwEMailSize+dwFilesSizeA+(dwFilesSize*sizeof(WCHAR))+dwAddresesSize+MAX_PATH));
- if (lpbData)
- {
- lpbDataCurrent=lpbData;
- SetLPSLowerCase(&lpbDataCurrent,lpszEMail,dwEMailSize);
- SetUL(&lpbDataCurrent,dwIDRequest);
- SetUL(&lpbDataCurrent,dwFilesTotalSize);
- SetUL(&lpbDataCurrent,(sizeof(DWORD)+dwFilesSizeA + sizeof(DWORD)+(sizeof(DWORD)+sizeof(DWORD)+(dwFilesSize*sizeof(WCHAR))) + sizeof(DWORD)+dwAddresesSize));//SetLPS(&lpbDataCurrent,(LPSTR)lpbDataEx,dwDataExSize);
- {
- SetLPSWtoA(&lpbDataCurrent,lpwszFiles,dwFilesSize);
- SetUL(&lpbDataCurrent,(sizeof(DWORD)+sizeof(DWORD)+(dwFilesSize*sizeof(WCHAR))));//SetLPS(&lpbDataCurrent,lpbDescription,dwDescriptionSize);
- {
- SetUL(&lpbDataCurrent,1);
- SetLPSW(&lpbDataCurrent,lpwszFiles,dwFilesSize);
- }
- SetLPS(&lpbDataCurrent,lpszAddreses,dwAddresesSize);
- }
+ SetUL(&lpbDataCurrent, 1);
+ SetLPSW(&lpbDataCurrent, lpwszFiles, dwFilesSize);
+
+ SetLPS(&lpbDataCurrent, lpszAddreses, dwAddresesSize);
- dwRet=MraSendCMD(MRIM_CS_FILE_TRANSFER,lpbData,(lpbDataCurrent-lpbData));
- MEMFREE(lpbData);
+ dwRet = MraSendCMD(MRIM_CS_FILE_TRANSFER, lpbData, lpbDataCurrent-lpbData);
+ mir_free(lpbData);
}
- }else{
- DebugBreak();
}
-return(dwRet);
+ return dwRet;
}
-
-DWORD MraSendCommand_FileTransferAck(DWORD dwStatus,LPSTR lpszEMail,SIZE_T dwEMailSize,DWORD dwIDRequest,LPBYTE lpbDescription,SIZE_T dwDescriptionSize)
-{// Ответ на отправку файлов
- DWORD dwRet=0;
-
- if (lpszEMail && dwEMailSize>4)
- {
- LPBYTE lpbData,lpbDataCurrent;
-
- lpbData=(LPBYTE)MEMALLOC((dwEMailSize+dwDescriptionSize+32));
- if (lpbData)
- {
- 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));
- MEMFREE(lpbData);
+// Ответ на отправку файлов
+DWORD CMraProto::MraFileTransferAck(DWORD dwStatus, LPSTR lpszEMail, size_t dwEMailSize, 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);
}
- }else{
- DebugBreak();
}
-return(dwRet);
+ return dwRet;
}
-
-/*DWORD MraSendCommand_WPRequestA(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)
-{// Поиск контакта
- //WCHAR wszUser[MAX_PATH],wszDomain[MAX_PATH];
- WCHAR wszNickName[MAX_PATH],wszFirstName[MAX_PATH],wszLastName[MAX_PATH];
-
- //if (lpszUser && dwUserSize) dwUserSize=MultiByteToWideChar(MRA_CODE_PAGE,0,lpszUser,dwUserSize,wszUser,SIZEOF(wszUser));
- //if (lpszDomain && dwDomainSize) dwDomainSize=MultiByteToWideChar(MRA_CODE_PAGE,0,lpszDomain,dwDomainSize,wszDomain,SIZEOF(wszDomain));
- if (lpszNickName && dwNickNameSize) dwNickNameSize=MultiByteToWideChar(MRA_CODE_PAGE,0,lpszNickName,dwNickNameSize,wszNickName,SIZEOF(wszNickName));
- if (lpszFirstName && dwFirstNameSize) dwFirstNameSize=MultiByteToWideChar(MRA_CODE_PAGE,0,lpszFirstName,dwFirstNameSize,wszFirstName,SIZEOF(wszFirstName));
- if (lpszLastName && dwLastNameSize) dwLastNameSize=MultiByteToWideChar(MRA_CODE_PAGE,0,lpszLastName,dwLastNameSize,wszLastName,SIZEOF(wszLastName));
-
-return(MraSendCommand_WPRequestW(hContact,dwAckType,dwRequestFlags,lpszUser,dwUserSize,lpszDomain,dwDomainSize,wszNickName,dwNickNameSize,wszFirstName,dwFirstNameSize,wszLastName,dwLastNameSize,dwSex,dwDate1,dwDate2,dwCityID,dwZodiak,dwBirthdayMonth,dwBirthdayDay,dwCountryID,dwOnline));
-}//*/
-
-DWORD MraSendCommand_WPRequestW(HANDLE hContact,DWORD dwAckType,DWORD dwRequestFlags,LPSTR lpszUser,SIZE_T dwUserSize,LPSTR lpszDomain,SIZE_T dwDomainSize,LPWSTR lpwszNickName,SIZE_T dwNickNameSize,LPWSTR lpwszFirstName,SIZE_T dwFirstNameSize,LPWSTR lpwszLastName,SIZE_T dwLastNameSize,DWORD dwSex,DWORD dwDate1,DWORD dwDate2,DWORD dwCityID,DWORD dwZodiak,DWORD dwBirthdayMonth,DWORD dwBirthdayDay,DWORD dwCountryID,DWORD dwOnline)
-{// Поиск контакта
- DWORD dwRet=0;
- LPBYTE lpbData,lpbDataCurrent;
-
- lpbData=(LPBYTE)MEMALLOC(((dwUserSize+dwDomainSize+dwNickNameSize+dwFirstNameSize+dwLastNameSize)*sizeof(WCHAR))+4096);
- if (lpbData)
- {
+// Поиск контакта
+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)
+{
+ 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;
+ size_t dwBuffSize;
- lpbDataCurrent=lpbData;
+ 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_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_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_BIRTHDAY))
- {
- dwBuffSize=mir_snprintf(szBuff,SIZEOF(szBuff),"%lu",dwSex);
- SetUL(&lpbDataCurrent,MRIM_CS_WP_REQUEST_PARAM_BIRTHDAY);
- 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);
+ 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);
}
- 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_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_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_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_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_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_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_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_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_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_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_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_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_ONLINE)) {
+ dwBuffSize = mir_snprintf(szBuff, SIZEOF(szBuff), "%lu", dwOnline);
+ SetUL(&lpbDataCurrent, MRIM_CS_WP_REQUEST_PARAM_ONLINE);
+ SetLPS(&lpbDataCurrent, szBuff, dwBuffSize);
}
- dwRet=MraSendQueueCMD(masMraSettings.hSendQueueHandle,0,hContact,dwAckType,NULL,0,MRIM_CS_WP_REQUEST,lpbData,(lpbDataCurrent-lpbData));
- MEMFREE(lpbData);
+ dwRet = MraSendQueueCMD(hSendQueueHandle, 0, hContact, dwAckType, NULL, 0, MRIM_CS_WP_REQUEST, lpbData, (lpbDataCurrent-lpbData));
+ mir_free(lpbData);
}
-return(dwRet);
+ return (HANDLE)dwRet;
}
-
-DWORD MraSendCommand_WPRequestByEMail(HANDLE hContact,DWORD dwAckType,LPSTR lpszEMail,SIZE_T dwEMailSize)
-{// Поиск контакта по EMail
- DWORD dwRet=0,dwRequestFlags=0;
+// Поиск контакта по EMail
+HANDLE CMraProto::MraWPRequestByEMail(HANDLE hContact, DWORD dwAckType, LPCSTR lpszEMail, size_t dwEMailSize)
+{
+ HANDLE dwRet = 0;
- if (lpszEMail && dwEMailSize>4)
- {
- LPSTR lpszUser,lpszDomain;
- SIZE_T dwUserSize,dwDomainSize;
-
- lpszDomain=(LPSTR)MemoryFindByte(0,lpszEMail,dwEMailSize,'@');
- if (lpszDomain)
- {
- lpszUser=lpszEMail;
- dwUserSize=(lpszDomain-lpszEMail);
+ 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));
+ dwDomainSize = (dwEMailSize-(dwUserSize+1));
- SetBit(dwRequestFlags,MRIM_CS_WP_REQUEST_PARAM_USER);
- SetBit(dwRequestFlags,MRIM_CS_WP_REQUEST_PARAM_DOMAIN);
+ DWORD dwRequestFlags = 0;
+ SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_USER);
+ SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_DOMAIN);
- dwRet=MraSendCommand_WPRequestW(hContact,dwAckType,dwRequestFlags,lpszUser,dwUserSize,lpszDomain,dwDomainSize,NULL,0,NULL,0,NULL,0,0,0,0,0,0,0,0,0,0);
+ 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);
+ return dwRet;
}
-
-DWORD MraSendCommand_Game(LPSTR lpszEMail,SIZE_T dwEMailSize,DWORD dwGameSessionID,DWORD dwGameMsg,DWORD dwGameMsgID,LPSTR lpszData,SIZE_T dwDataSize)
-{// Отправка файлов
- DWORD dwRet=0;
-
- if (lpszEMail && dwEMailSize>4)
- {
- LPBYTE lpbData,lpbDataCurrent;
-
- lpbData=(LPBYTE)MEMALLOC((dwEMailSize+(sizeof(DWORD)*4)+dwDataSize+32));
- if (lpbData)
- {
- 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));
- MEMFREE(lpbData);
+// Отправка файлов
+DWORD CMraProto::MraGame(LPSTR lpszEMail, size_t dwEMailSize, DWORD dwGameSessionID, DWORD dwGameMsg, DWORD dwGameMsgID, LPSTR lpszData, size_t dwDataSize)
+{
+ 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);
}
- }else{
- DebugBreak();
}
-return(dwRet);
+ return dwRet;
}
-
-DWORD MraSendCommand_Login2W(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 lpszUserAgentFormated,SIZE_T dwUserAgentFormatedSize,LPSTR lpszUserAgent,SIZE_T dwUserAgentSize)
-{// Авторизация
- DWORD dwRet=0;
- LPBYTE lpbData,lpbDataCurrent;
-
- 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 (dwUserAgentFormatedSize>USER_AGENT_MAX) dwUserAgentFormatedSize=USER_AGENT_MAX;
- if (dwUserAgentSize>MAX_CLIENT_DESCRIPTION) dwUserAgentSize=MAX_CLIENT_DESCRIPTION;
-
- lpbData=(LPBYTE)MEMALLOC((dwLoginSize+dwPasswordSize+sizeof(DWORD)+dwStatusUriSize+(dwStatusTitleSize*sizeof(WCHAR))+(dwStatusDescSize*sizeof(WCHAR))+2+sizeof(DWORD)+(sizeof(DWORD)*2)+dwUserAgentFormatedSize+dwUserAgentSize+32));
- if (lpbData)
- {
- 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,lpszUserAgentFormated,dwUserAgentFormatedSize);
- 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));
- MEMFREE(lpbData);
+// Авторизация
+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 lpszUserAgentFormated, size_t dwUserAgentFormatedSize, LPSTR lpszUserAgent, size_t dwUserAgentSize)
+{
+ 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 (dwUserAgentFormatedSize>USER_AGENT_MAX) dwUserAgentFormatedSize = 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)+dwUserAgentFormatedSize+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, lpszUserAgentFormated, dwUserAgentFormatedSize);
+ 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);
+ return dwRet;
}
-
-DWORD MraSendCommand_SMSW(HANDLE hContact,LPSTR lpszPhone,SIZE_T dwPhoneSize,LPWSTR lpwszMessage,SIZE_T dwMessageSize)
-{// Отправка SMS
- DWORD dwRet=0;
- LPBYTE lpbData,lpbDataCurrent,lpbDataQueue;
- LPSTR lpszPhoneLocal;
-
- lpbData=(LPBYTE)MEMALLOC((dwPhoneSize+(dwMessageSize*sizeof(WCHAR))+32));
- lpbDataQueue=(LPBYTE)MEMALLOC((dwPhoneSize+(dwMessageSize*sizeof(WCHAR))+32));
- lpszPhoneLocal=(LPSTR)MEMALLOC((dwPhoneSize+32));
- if (lpbData && lpbDataQueue && lpszPhoneLocal)
- {
- lpszPhoneLocal[0]='+';
- dwPhoneSize=1+CopyNumber((lpszPhoneLocal+1),lpszPhone,dwPhoneSize);
-
- 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(masMraSettings.hSendQueueHandle,0,hContact,ICQACKTYPE_SMS,lpbDataQueue,(dwPhoneSize+(dwMessageSize*sizeof(WCHAR))+sizeof(DWORD)+2),MRIM_CS_SMS,lpbData,(lpbDataCurrent-lpbData));
- MEMFREE(lpbData);
- MEMFREE(lpszPhoneLocal);
- }else{
- MEMFREE(lpbData);
- MEMFREE(lpbDataQueue);
- MEMFREE(lpszPhoneLocal);
+// Отправка SMS
+DWORD CMraProto::MraSMSW(HANDLE hContact, LPSTR lpszPhone, size_t dwPhoneSize, LPWSTR lpwszMessage, size_t dwMessageSize)
+{
+ 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);
}
-return(dwRet);
-}
-
-
-
-DWORD MraSendCommand_Proxy(LPSTR lpszEMail,SIZE_T dwEMailSize,DWORD dwIDRequest,DWORD dwDataType,LPSTR lpszData,SIZE_T dwDataSize,LPSTR lpszAddreses,SIZE_T dwAddresesSize,MRA_GUID mguidSessionID)
-{// Соединение с прокси
- DWORD dwRet=0;
-
- if (lpszEMail && dwEMailSize>4)
- {
- LPBYTE lpbData,lpbDataCurrent;
-
- lpbData=(LPBYTE)MEMALLOC((dwEMailSize+(sizeof(DWORD)*2)+dwDataSize+dwAddresesSize+sizeof(MRA_GUID)+32));
- if (lpbData)
- {
- lpbDataCurrent=lpbData;
- SetLPSLowerCase(&lpbDataCurrent,lpszEMail,dwEMailSize);
- SetUL(&lpbDataCurrent,dwIDRequest);
- SetUL(&lpbDataCurrent,dwDataType);
- SetLPS(&lpbDataCurrent,lpszData,dwDataSize);
- SetLPS(&lpbDataCurrent,lpszAddreses,dwAddresesSize);
- SetGUID(&lpbDataCurrent,mguidSessionID);
-
- dwRet=MraSendCMD(MRIM_CS_PROXY,lpbData,(lpbDataCurrent-lpbData));
- MEMFREE(lpbData);
- }
- }else{
- DebugBreak();
+ else {
+ mir_free(lpbData);
+ mir_free(lpbDataQueue);
+ mir_free(lpszPhoneLocal);
}
-return(dwRet);
+ return dwRet;
}
-
-DWORD MraSendCommand_ProxyAck(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 dwRet=0;
-
- if (lpszEMail && dwEMailSize>4)
- {
- LPBYTE lpbData,lpbDataCurrent;
-
- lpbData=(LPBYTE)MEMALLOC((dwEMailSize+(sizeof(DWORD)*3)+dwDataSize+dwAddresesSize+sizeof(MRA_GUID)+32));
- if (lpbData)
- {
- lpbDataCurrent=lpbData;
- SetUL(&lpbDataCurrent,dwStatus);
- SetLPSLowerCase(&lpbDataCurrent,lpszEMail,dwEMailSize);
- SetUL(&lpbDataCurrent,dwIDRequest);
- SetUL(&lpbDataCurrent,dwDataType);
- SetLPS(&lpbDataCurrent,lpszData,dwDataSize);
- SetLPS(&lpbDataCurrent,lpszAddreses,dwAddresesSize);
- SetGUID(&lpbDataCurrent,mguidSessionID);
-
- dwRet=MraSendCMD(MRIM_CS_PROXY_ACK,lpbData,(lpbDataCurrent-lpbData));
- MEMFREE(lpbData);
+// Соединение с прокси
+DWORD CMraProto::MraProxy(LPSTR lpszEMail, size_t dwEMailSize, DWORD dwIDRequest, DWORD dwDataType, LPSTR lpszData, size_t dwDataSize, LPSTR lpszAddreses, size_t dwAddresesSize, MRA_GUID mguidSessionID)
+{
+ DWORD dwRet = 0;
+
+ if (lpszEMail && dwEMailSize>4) {
+ LPBYTE lpbData = (LPBYTE)mir_calloc((dwEMailSize+(sizeof(DWORD)*2)+dwDataSize+dwAddresesSize+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, dwAddresesSize);
+ SetGUID(&lpbDataCurrent, mguidSessionID);
+
+ dwRet = MraSendCMD(MRIM_CS_PROXY, lpbData, (lpbDataCurrent-lpbData));
+ mir_free(lpbData);
}
- }else{
- DebugBreak();
}
-return(dwRet);
+ return dwRet;
}
-
-DWORD MraSendCommand_ChangeUserBlogStatus(DWORD dwFlags,LPWSTR lpwszText,SIZE_T dwTextSize,DWORDLONG dwBlogStatusID)
-{// Отправка сообщения в микроблог
- DWORD dwRet=0;
- LPBYTE lpbData,lpbDataCurrent;
-
- if (dwTextSize>MICBLOG_STATUS_MAX) dwTextSize=MICBLOG_STATUS_MAX;
-
- lpbData=(LPBYTE)MEMALLOC((sizeof(DWORD)+(dwTextSize*sizeof(WCHAR))+sizeof(DWORDLONG)+32));
- if (lpbData)
- {
- lpbDataCurrent=lpbData;
- SetUL(&lpbDataCurrent,dwFlags);
- SetLPSW(&lpbDataCurrent,lpwszText,dwTextSize);
- SetUIDL(&lpbDataCurrent,dwBlogStatusID);
-
- dwRet=MraSendCMD(MRIM_CS_CHANGE_USER_BLOG_STATUS,lpbData,(lpbDataCurrent-lpbData));
- MEMFREE(lpbData);
- }
-
-return(dwRet);
-}
-
-
-void SetUL(LPBYTE *plpBuff,DWORD dwData)
+// Ответ на соединение с прокси
+DWORD CMraProto::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*)(*plpBuff))=dwData;
- (*plpBuff)+=sizeof(DWORD);
-}
-
-
-void SetUIDL(LPBYTE *plpBuff,DWORDLONG dwData)
-{
- (*(DWORDLONG*)(*plpBuff))=dwData;
- (*plpBuff)+=sizeof(DWORDLONG);
-}
-
-
-void SetGUID(LPBYTE *plpBuff,MRA_GUID guidData)
-{
- (*(MRA_GUID*)(*plpBuff))=guidData;
- (*plpBuff)+=sizeof(MRA_GUID);
-}
-
-
-void SetLPS(LPBYTE *plpBuff,LPSTR lpszData,DWORD dwSize)
-{
- (*(DWORD*)(*plpBuff))=dwSize;
- (*plpBuff)+=sizeof(DWORD);
- memmove((*plpBuff),lpszData,dwSize);
- (*plpBuff)+=dwSize;
-}
-
-
-void SetLPSW(LPBYTE *plpBuff,LPWSTR lpwszData,DWORD dwSize)
-{
- dwSize*=sizeof(WCHAR);
- (*(DWORD*)(*plpBuff))=dwSize;
- (*plpBuff)+=sizeof(DWORD);
- memmove((*plpBuff),lpwszData,dwSize);
- (*plpBuff)+=dwSize;
-}
-
-
-void SetLPSWtoA(LPBYTE *plpBuff,LPWSTR 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);
+ DWORD dwRet = 0;
+
+ if (lpszEMail && dwEMailSize>4) {
+ LPBYTE lpbData = (LPBYTE)mir_calloc((dwEMailSize+(sizeof(DWORD)*3)+dwDataSize+dwAddresesSize+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, dwAddresesSize);
+ SetGUID(&lpbDataCurrent, mguidSessionID);
+
+ dwRet = MraSendCMD(MRIM_CS_PROXY_ACK, lpbData, (lpbDataCurrent-lpbData));
+ mir_free(lpbData);
+ }
+ }
+ return dwRet;
}
-
-
-void SetLPSLowerCase(LPBYTE *plpBuff,LPSTR lpszData,DWORD dwSize)
+// Отправка сообщения в микроблог
+DWORD CMraProto::MraChangeUserBlogStatus(DWORD dwFlags, LPWSTR lpwszText, size_t dwTextSize, DWORDLONG dwBlogStatusID)
{
- (*(DWORD*)(*plpBuff))=dwSize;
- (*plpBuff)+=sizeof(DWORD);
- BuffToLowerCase((*plpBuff),lpszData,dwSize);
- (*plpBuff)+=dwSize;
-}
-
+ 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);
+ }
-void SetLPSLowerCaseW(LPBYTE *plpBuff,LPWSTR lpwszData,DWORD dwSize)
-{
- dwSize*=sizeof(WCHAR);
- (*(DWORD*)(*plpBuff))=dwSize;
- (*plpBuff)+=sizeof(DWORD);
- memmove((*plpBuff),lpwszData,dwSize);
- CharLowerBuff((LPWSTR)(*plpBuff),(dwSize/sizeof(WCHAR)));
- (*plpBuff)+=dwSize;
+ return dwRet;
}
-
-DWORD MraSendPacket(HANDLE hConnection,DWORD dwCMDNum,DWORD dwType,LPVOID lpData,SIZE_T dwDataSize)
+DWORD CMraProto::MraSendPacket(HANDLE hConnection, DWORD dwCMDNum, DWORD dwType, LPVOID lpData, size_t dwDataSize)
{
DWORD dwRet;
- LPBYTE lpbData;
- mrim_packet_header_t *pmaHeader;
-
- lpbData=(LPBYTE)MEMALLOC((dwDataSize+sizeof(mrim_packet_header_t)));
- if (lpbData)
- {
- pmaHeader=(mrim_packet_header_t*)lpbData;
- pmaHeader->magic=CS_MAGIC;
- pmaHeader->proto=PROTO_VERSION;// Версия протокола
- pmaHeader->seq=dwCMDNum;// Sequence
- pmaHeader->msg=dwType;// Тип пакета
- pmaHeader->dlen=dwDataSize;// Длина данных
- //bzero(&maHeader->reserved[0],24);// Зарезервировано
-
- memmove((lpbData+sizeof(mrim_packet_header_t)),lpData,dwDataSize);
- dwRet=Netlib_Send(hConnection,(LPSTR)lpbData,(dwDataSize+sizeof(mrim_packet_header_t)),0);
-
- /*if (dwType==MRIM_CS_ADD_CONTACT)
- {
- {
- char sztm[100];
-
- SHA1GetStringDigestA((LPSTR)lpbData,(dwDataSize+sizeof(mrim_packet_header_t)),sztm);
- OutputDebugStringA((sztm));
- OutputDebugStringA("\r\n");
- }
-
- {
- DWORD dwTemp;
- HANDLE hFile=CreateFileW(L"C:\\Documents and Settings\\rozhuk_im\\Рабочий стол\\AddContact.txt",GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
-
- if (hFile!=INVALID_HANDLE_VALUE)
- {
- WriteFile(hFile,lpbData,(dwDataSize+sizeof(mrim_packet_header_t)),&dwTemp,NULL);
- CloseHandle(hFile);
- }
- }
- }//*/
- MEMFREE(lpbData);
+ 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;// Длина данных
+
+ 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);
+ return dwRet;
}
-
-DWORD MraSendCMD(DWORD dwType,LPVOID lpData,SIZE_T dwDataSize)
+DWORD CMraProto::MraSendCMD(DWORD dwType, LPVOID lpData, size_t dwDataSize)
{
- DWORD dwRet;
+ DWORD dwRet = InterlockedIncrement((LONG volatile*)&dwCMDNum);
- dwRet=InterlockedIncrement((LONG volatile*)&masMraSettings.dwCMDNum);
- EnterCriticalSection(&masMraSettings.csCriticalSectionSend);// guarding winsock internal buffers
- if (MraSendPacket(masMraSettings.hConnection,dwRet,dwType,lpData,dwDataSize)==0)
- {// err on send
- dwRet=0;
- }
- LeaveCriticalSection(&masMraSettings.csCriticalSectionSend);
-return(dwRet);
+ mir_cslock l(csCriticalSectionSend); // guarding winsock internal buffers
+ return !MraSendPacket(hConnection, dwRet, dwType, lpData, dwDataSize) ? 0 : dwRet;
}
-DWORD MraSendQueueCMD(HANDLE hSendQueueHandle,DWORD dwFlags,HANDLE hContact,DWORD dwAckType,LPBYTE lpbDataQueue,SIZE_T dwDataQueueSize,DWORD dwType,LPVOID lpData,SIZE_T dwDataSize)
+DWORD CMraProto::MraSendQueueCMD(HANDLE hSendQueueHandle, DWORD dwFlags, HANDLE hContact, DWORD dwAckType, LPBYTE lpbDataQueue, size_t dwDataQueueSize, DWORD dwType, LPVOID lpData, size_t dwDataSize)
{
- DWORD dwRet;
-
- dwRet=InterlockedIncrement((LONG volatile*)&masMraSettings.dwCMDNum);
- if (MraSendQueueAdd(hSendQueueHandle,dwRet,dwFlags,hContact,dwAckType,lpbDataQueue,dwDataQueueSize)==NO_ERROR)
- {
- EnterCriticalSection(&masMraSettings.csCriticalSectionSend);// guarding winsock internal buffers
- if (MraSendPacket(masMraSettings.hConnection,dwRet,dwType,lpData,dwDataSize)==0)
- {
- MraSendQueueFree(hSendQueueHandle,dwRet);
- dwRet=0;
+ 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)) {
+ MraSendQueueFree(hSendQueueHandle, dwRet);
+ dwRet = 0;
}
- LeaveCriticalSection(&masMraSettings.csCriticalSectionSend);
}
-return(dwRet);
+ return dwRet;
}
-
-
-