diff options
author | Piotr Piastucki <leech.miranda@gmail.com> | 2015-05-14 15:24:53 +0000 |
---|---|---|
committer | Piotr Piastucki <leech.miranda@gmail.com> | 2015-05-14 15:24:53 +0000 |
commit | b7a1174511c3b7fad5b81a54bb4647662d94031c (patch) | |
tree | 91b3f36fd78ae9b481cb11d8602e61a79c388d04 /protocols/MSN/src/msn_threads.cpp | |
parent | 01b66588ca510b49be5a06d2bfb5bd28b4416030 (diff) |
Updated for partial MSNP24 protocol support, for detailed changes see MSNP24 branch.
git-svn-id: http://svn.miranda-ng.org/main/trunk@13589 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/MSN/src/msn_threads.cpp')
-rw-r--r-- | protocols/MSN/src/msn_threads.cpp | 91 |
1 files changed, 57 insertions, 34 deletions
diff --git a/protocols/MSN/src/msn_threads.cpp b/protocols/MSN/src/msn_threads.cpp index 5878171337..34c446d3e6 100644 --- a/protocols/MSN/src/msn_threads.cpp +++ b/protocols/MSN/src/msn_threads.cpp @@ -42,7 +42,7 @@ void __cdecl CMsnProto::msn_keepAliveThread(void*) msnPingTimeout = 45;
else {
msnPingTimeout = 20;
- keepFlag = keepFlag && msnNsThread->send("PNG\r\n", 5);
+ keepFlag = keepFlag && msnNsThread->sendPacket("PNG", "CON 0");
}
p2p_clearDormantSessions();
if (hHttpsConnection && (clock() - mHttpsTS) > 60 * CLOCKS_PER_SEC) {
@@ -72,6 +72,18 @@ void __cdecl CMsnProto::msn_keepAliveThread(void*) /////////////////////////////////////////////////////////////////////////////////////////
// MSN server thread - read and process commands from a server
+static bool ReallocInfoBuffer(ThreadData *info, int mDataSize)
+{
+ char *mData = (char*)mir_realloc(info->mData, mDataSize+1);
+ if (mData) {
+ info->mData = mData;
+ info->mDataSize = mDataSize;
+ ZeroMemory(&mData[info->mBytesInData], info->mDataSize-info->mBytesInData+1);
+ return true;
+ }
+ return false;
+}
+
void __cdecl CMsnProto::MSNServerThread(void* arg)
{
@@ -120,6 +132,7 @@ void __cdecl CMsnProto::MSNServerThread(void* arg) tConn.wPort = MSN_DEFAULT_GATEWAY_PORT;
}
else {
+ tConn.flags = NLOCF_SSL;
tConn.szHost = info->mServer;
tConn.wPort = MSN_DEFAULT_PORT;
}
@@ -149,9 +162,9 @@ void __cdecl CMsnProto::MSNServerThread(void* arg) debugLogA("Connected with handle=%08X", info->s);
- if (info->mType == SERVER_NOTIFICATION) {
- info->sendPacket("VER", "MSNP18 MSNP17 CVR0");
- }
+ if (info->mType == SERVER_NOTIFICATION)
+ info->sendPacketPayload("CNT", "CON", "<connect>%s%s%s<ver>2</ver><agent><os>winnt</os><osVer>5.2</osVer><proc>x86</proc><lcid>en-us</lcid></agent></connect>\r\n",
+ *info->mState?"<xfr><state>":"", *info->mState?info->mState:"", *info->mState?"</state></xfr>":"");
else if (info->mType == SERVER_SWITCHBOARD) {
info->sendPacket(info->mCaller ? "USR" : "ANS", "%s;%s %s", MyOptions.szEmail, MyOptions.szMachineGuid, info->mCookie);
}
@@ -166,7 +179,7 @@ void __cdecl CMsnProto::MSNServerThread(void* arg) debugLogA("Entering main recv loop");
info->mBytesInData = 0;
for (;;) {
- int recvResult = info->recv(info->mData + info->mBytesInData, sizeof(info->mData) - info->mBytesInData);
+ int recvResult = info->recv(info->mData + info->mBytesInData, info->mDataSize - info->mBytesInData);
if (recvResult == SOCKET_ERROR) {
debugLogA("Connection %08p [%08X] was abortively closed", info->s, GetCurrentThreadId());
break;
@@ -192,7 +205,7 @@ void __cdecl CMsnProto::MSNServerThread(void* arg) if (info->mBytesInData < peol - info->mData + 2)
break; //wait for full line end
- char msg[sizeof(info->mData)];
+ char msg[1024];
memcpy(msg, info->mData, peol - info->mData); msg[peol - info->mData] = 0;
if (*++peol != '\n')
@@ -227,9 +240,11 @@ void __cdecl CMsnProto::MSNServerThread(void* arg) }
}
- if (info->mBytesInData == sizeof(info->mData)) {
- debugLogA("sizeof(data) is too small: the longest line won't fit");
- break;
+ if (info->mBytesInData == info->mDataSize) {
+ if (!ReallocInfoBuffer(info, info->mDataSize*2)) {
+ debugLogA("sizeof(data) is too small: the longest line won't fit");
+ break;
+ }
}
}
@@ -340,27 +355,14 @@ ThreadData* CMsnProto::MSN_GetThreadByContact(const char* wlid, TInfoType type) return NULL;
}
-ThreadData* CMsnProto::MSN_GetThreadByChatId(const TCHAR* chatId)
-{
- mir_cslock lck(m_csThreads);
-
- for (int i = 0; i < m_arThreads.getCount(); i++) {
- ThreadData &T = m_arThreads[i];
- if (_tcsicmp(T.mChatID, chatId) == 0)
- return &T;
- }
-
- return NULL;
-}
-
-ThreadData* CMsnProto::MSN_GetThreadByTimer(UINT timerId)
+GCThreadData* CMsnProto::MSN_GetThreadByChatId(const TCHAR* chatId)
{
mir_cslock lck(m_csThreads);
- for (int i = 0; i < m_arThreads.getCount(); i++) {
- ThreadData &T = m_arThreads[i];
- if (T.mType == SERVER_SWITCHBOARD && T.mTimerId == timerId)
- return &T;
+ for (int i = 0; i < m_arGCThreads.getCount(); i++) {
+ GCThreadData *T = m_arGCThreads[i];
+ if (_tcsicmp(T->mChatID, chatId) == 0)
+ return T;
}
return NULL;
@@ -517,6 +519,7 @@ ThreadData::ThreadData() mGatewayTimeout = 2;
resetTimeout();
hWaitEvent = CreateSemaphore(NULL, 0, MSN_PACKETS_COMBINE, NULL);
+ mData = (char*)mir_calloc((mDataSize=8192)+1);
}
ThreadData::~ThreadData()
@@ -567,6 +570,8 @@ ThreadData::~ThreadData() proto->MSN_GetUnconnectedThread(wlid) == NULL) {
proto->MsgQueue_Clear(wlid, true);
}
+
+ mir_free(mData);
}
void ThreadData::applyGatewayData(HANDLE hConn, bool isPoll)
@@ -677,9 +682,7 @@ HReadBuffer::~HReadBuffer() BYTE* HReadBuffer::surelyRead(size_t parBytes)
{
- const size_t bufferSize = sizeof(owner->mData);
-
- if ((startOffset + parBytes) > bufferSize) {
+ if ((startOffset + parBytes) > owner->mDataSize) {
if (totalDataSize > startOffset)
memmove(buffer, buffer + startOffset, (totalDataSize -= startOffset));
else
@@ -687,14 +690,19 @@ BYTE* HReadBuffer::surelyRead(size_t parBytes) startOffset = 0;
- if (parBytes > bufferSize) {
- owner->proto->debugLogA("HReadBuffer::surelyRead: not enough memory, %d %d %d", parBytes, bufferSize, startOffset);
- return NULL;
+ if (parBytes > owner->mDataSize) {
+ size_t mDataSize = owner->mDataSize;
+ while (parBytes > mDataSize) mDataSize*=2;
+ if (!ReallocInfoBuffer(owner, mDataSize)) {
+ owner->proto->debugLogA("HReadBuffer::surelyRead: not enough memory, %d %d %d", parBytes, owner->mDataSize, startOffset);
+ return NULL;
+ }
+ buffer = (BYTE*)owner->mData;
}
}
while ((startOffset + parBytes) > totalDataSize) {
- int recvResult = owner->recv((char*)buffer + totalDataSize, bufferSize - totalDataSize);
+ int recvResult = owner->recv((char*)buffer + totalDataSize, owner->mDataSize - totalDataSize);
if (recvResult <= 0)
return NULL;
@@ -703,5 +711,20 @@ BYTE* HReadBuffer::surelyRead(size_t parBytes) }
BYTE *result = buffer + startOffset; startOffset += parBytes;
+ buffer[totalDataSize] = 0;
return result;
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// class GCThreadData members
+
+GCThreadData::GCThreadData() :
+mJoinedContacts(10, PtrKeySortT)
+{
+ memset(&mCreator, 0, sizeof(GCThreadData) - sizeof(mJoinedContacts));
+}
+
+GCThreadData::~GCThreadData()
+{
+}
+
|