From ae1afa7d58e0ab42e8e93689c30f7d9084c926e4 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 6 Sep 2013 18:37:48 +0000 Subject: more cleaning for MRA git-svn-id: http://svn.miranda-ng.org/main/trunk@5978 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/MRA/src/Mra.h | 2 +- protocols/MRA/src/MraAvatars.cpp | 11 +- protocols/MRA/src/MraFilesQueue.cpp | 8 +- protocols/MRA/src/MraOfflineMsg.cpp | 233 ++++++++++++++++++----------------- protocols/MRA/src/Mra_functions.cpp | 36 +++--- protocols/MRA/src/Mra_svcs.cpp | 24 ++-- protocols/MRA/src/Sdk/InternetTime.h | 213 +++++++++++++++----------------- protocols/MRA/src/version.h | 6 +- 8 files changed, 254 insertions(+), 279 deletions(-) diff --git a/protocols/MRA/src/Mra.h b/protocols/MRA/src/Mra.h index 2e98bfd1ba..38e7276a76 100644 --- a/protocols/MRA/src/Mra.h +++ b/protocols/MRA/src/Mra.h @@ -136,7 +136,7 @@ public: void getStringA(CMStringA&); void getStringW(CMStringW&); - __forceinline bool eof() const { return m_len > 0; } + __forceinline bool eof() const { return m_len == 0; } }; __forceinline BinBuffer& operator >>(BinBuffer& buf, DWORD &dwVar) { dwVar = buf.getDword(); return buf; } diff --git a/protocols/MRA/src/MraAvatars.cpp b/protocols/MRA/src/MraAvatars.cpp index 3a6e37800a..371415862f 100644 --- a/protocols/MRA/src/MraAvatars.cpp +++ b/protocols/MRA/src/MraAvatars.cpp @@ -412,7 +412,7 @@ DWORD MraAvatarsHttpTransaction(HANDLE m_hConnection, DWORD dwRequestType, LPCST nlbhHeaders[2].szName = "Pragma"; nlbhHeaders[2].szValue = "no-cache"; nlbhHeaders[3].szName = "Connection"; nlbhHeaders[3].szValue = (bUseKeepAliveConn)? "keep-alive":"close"; - NETLIBHTTPREQUEST *pnlhr, nlhr = {0}; + NETLIBHTTPREQUEST nlhr = {0}; nlhr.cbSize = sizeof(nlhr); nlhr.requestType = dwRequestType; nlhr.flags = (NLHRF_GENERATEHOST|NLHRF_SMARTREMOVEHOST|NLHRF_SMARTAUTHHEADER); @@ -424,7 +424,7 @@ DWORD MraAvatarsHttpTransaction(HANDLE m_hConnection, DWORD dwRequestType, LPCST if (dwSent == SOCKET_ERROR || !dwSent) return GetLastError(); - pnlhr = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_RECVHTTPHEADERS, (WPARAM)m_hConnection, 0); + NETLIBHTTPREQUEST *pnlhr = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_RECVHTTPHEADERS, (WPARAM)m_hConnection, 0); if (!pnlhr) return GetLastError(); @@ -449,11 +449,12 @@ DWORD MraAvatarsHttpTransaction(HANDLE m_hConnection, DWORD dwRequestType, LPCST } else if ( !_strnicmp(pnlhr->headers[i].szName, "Last-Modified", 13)) { if (pitLastModifiedTime) - InternetTimeGetTime(pnlhr->headers[i].szValue, pitLastModifiedTime); + InternetTimeGetTime(pnlhr->headers[i].szValue, *pitLastModifiedTime); } } - if (pdwResultCode) (*pdwResultCode) = pnlhr->resultCode; + if (pdwResultCode) + *pdwResultCode = pnlhr->resultCode; CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)pnlhr); return 0; } @@ -464,7 +465,7 @@ bool CMraProto::MraAvatarsGetContactTime(HANDLE hContact, LPSTR lpszValueName, S INTERNET_TIME itAvatarLastModifiedTimeLocal; CMStringA szBuff; if (mraGetStringA(hContact, lpszValueName, szBuff)) - if (InternetTimeGetTime(szBuff, &itAvatarLastModifiedTimeLocal) == NO_ERROR) { + if (InternetTimeGetTime(szBuff, itAvatarLastModifiedTimeLocal) == NO_ERROR) { memmove(pstTime, &itAvatarLastModifiedTimeLocal.stTime, sizeof(SYSTEMTIME)); return TRUE; } diff --git a/protocols/MRA/src/MraFilesQueue.cpp b/protocols/MRA/src/MraFilesQueue.cpp index 3c3c6b9ce6..3eddf3dd21 100644 --- a/protocols/MRA/src/MraFilesQueue.cpp +++ b/protocols/MRA/src/MraFilesQueue.cpp @@ -412,7 +412,7 @@ bool CMraProto::MraFilesQueueHandCheck(HANDLE m_hConnection, MRA_FILES_QUEUE_ITE 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) + if ( !_memicmp(btBuff, btBuff+dwBuffSize, dwBuffSize)) return true; } } @@ -423,7 +423,7 @@ bool CMraProto::MraFilesQueueHandCheck(HANDLE m_hConnection, MRA_FILES_QUEUE_ITE // 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) { + if ( !_memicmp(btBuff, btBuff+dwBuffSize, dwBuffSize)) { // email verified dwBuffSize = (mir_snprintf((LPSTR)btBuff, SIZEOF(btBuff), "%s %s", MRA_FT_HELLO, szEmailMy.c_str())+1); if (dwBuffSize == Netlib_Send(m_hConnection, (LPSTR)btBuff, dwBuffSize, 0)) @@ -1063,14 +1063,14 @@ void CMraProto::MraFilesQueueSendThreadProc(LPVOID lpParameter) // ...received if (dwBuffSizeUsed > (sizeof(MRA_FT_GET_FILE)+1)) {// file name received - if (CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, (LPSTR)btBuff, (sizeof(MRA_FT_GET_FILE)-1), MRA_FT_GET_FILE, (sizeof(MRA_FT_GET_FILE)-1)) == CSTR_EQUAL) { + if ( !_memicmp(btBuff, MRA_FT_GET_FILE, sizeof(MRA_FT_GET_FILE)-1)) { // MRA_FT_GET_FILE verified bFailed = TRUE; for (j = 0;jdwFilesCount;j++) { lpwszFileName = GetFileNameFromFullPathW(dat->pmfqfFiles[j].lpwszName, dat->pmfqfFiles[j].dwNameLen); szFileName[WideCharToMultiByte(MRA_CODE_PAGE, 0, lpwszFileName, (dat->pmfqfFiles[j].dwNameLen-(lpwszFileName-dat->pmfqfFiles[j].lpwszName)), szFileName, SIZEOF(szFileName), NULL, NULL)] = 0; - if (CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, (((LPSTR)btBuff)+sizeof(MRA_FT_GET_FILE)), (dwBuffSizeUsed-(sizeof(MRA_FT_GET_FILE)+1)), szFileName, -1) == CSTR_EQUAL) { + if ( !_memicmp(btBuff+sizeof(MRA_FT_GET_FILE), szFileName, dwBuffSizeUsed-(sizeof(MRA_FT_GET_FILE)+1))) { bFailed = FALSE; break; } diff --git a/protocols/MRA/src/MraOfflineMsg.cpp b/protocols/MRA/src/MraOfflineMsg.cpp index 1c4e5c36d6..b94790afb9 100644 --- a/protocols/MRA/src/MraOfflineMsg.cpp +++ b/protocols/MRA/src/MraOfflineMsg.cpp @@ -75,27 +75,30 @@ static DWORD MraOfflineMessageGetHeaderValue(LPSTR lpszHeader, LPSTR lpszHeaderL if (lpszValue) { lpszValue += dwValueNameSize; 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); + 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) { lpszValue++; - plpszValue = CMStringA(lpszHeader+(lpszValue-lpszHeaderLow), (lpszValueEnd-lpszValue)); + size_t dwValueSize = lpszValueEnd - lpszValue; + lpszValue = lpszHeader + (lpszValue-lpszHeaderLow); + SkeepSPWSP(lpszValue, dwValueSize, &lpszValue, &dwValueSize); + plpszValue = CMStringA(lpszValue, dwValueSize); return NO_ERROR; } } return ERROR_NOT_FOUND; } -static DWORD MraOfflineMessageGetNextMIMEPart(LPSTR lpszBody, size_t dwBodySize, LPSTR lpszBoundary, size_t dwBoundarySize, LPSTR *plpszCurMIMEPos, LPSTR *plpszMIMEPart, size_t *pdwMIMEPartSize) +static DWORD MraOfflineMessageGetNextMIMEPart(LPSTR lpszBody, size_t dwBodySize, LPSTR lpszBoundary, size_t dwBoundarySize, LPSTR &plpszCurMIMEPos, LPSTR *plpszMIMEPart, size_t *pdwMIMEPartSize) { if (!lpszBody || !dwBodySize) return ERROR_INVALID_HANDLE; - LPSTR lpszCurMIMEPos; - if (plpszCurMIMEPos) - lpszCurMIMEPos = (*plpszCurMIMEPos); + LPSTR lpszCurMIMEPos = plpszCurMIMEPos; LPSTR lpszMIMEPart = (LPSTR)MemoryFind((lpszCurMIMEPos-lpszBody), lpszBody, dwBodySize, lpszBoundary, dwBoundarySize); if (lpszMIMEPart) {// первая миме часть @@ -126,7 +129,7 @@ static DWORD MraOfflineMessageGetNextMIMEPart(LPSTR lpszBody, size_t dwBodySize, if (plpszMIMEPart) (*plpszMIMEPart) = lpszMIMEPart; if (pdwMIMEPartSize) (*pdwMIMEPartSize) = dwMIMEPartSize; - if (plpszCurMIMEPos) (*plpszCurMIMEPos) = lpszTemp; + plpszCurMIMEPos = lpszTemp; return NO_ERROR; } } @@ -166,123 +169,121 @@ static DWORD PlainText2message(const CMStringA &szContentType, const CMStringA & DWORD MraOfflineMessageGet(CMStringA *plpsMsg, DWORD *pdwTime, DWORD *pdwFlags, CMStringA *plpsEMail, CMStringA *plpsText, CMStringA *plpsRTFText, CMStringA *plpsMultiChatData) { - DWORD dwRetErrorCode = ERROR_INVALID_HANDLE; - - if (plpsMsg) - if (!plpsMsg->IsEmpty()) { - LPSTR lpszHeader, lpszHeaderLow, lpszBody, lpszContentTypeLow; - size_t dwHeaderSize, dwBodySize, dwContentTypeSize; - DWORD dwMultichatType; - CMStringA szTemp; - - #ifdef _DEBUG - DebugPrintCRLFA(plpsMsg->GetString()); - #endif - - 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, szTemp) == NO_ERROR) { - INTERNET_TIME itTime; - InternetTimeGetTime(szTemp, &itTime); - (*pdwTime) = MraOfflineMessageConvertTime(&itTime); - } - else (*pdwTime) = 0; + if (plpsMsg == NULL || plpsMsg->IsEmpty()) + return ERROR_INVALID_HANDLE; - if (pdwFlags) - if (MraOfflineMessageGetHeaderValue(lpszHeader, lpszHeaderLow, dwHeaderSize, "x-mrim-flags", 12, szTemp) == NO_ERROR) - *pdwFlags = StrHexToUNum32(szTemp, szTemp.GetLength()); - else - *pdwFlags = 0; + LPSTR lpszHeader, lpszBody, lpszContentTypeLow; + size_t dwHeaderSize, dwBodySize, dwContentTypeSize; + DWORD dwMultichatType; + CMStringA szTemp; - 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) != NO_ERROR) - plpsEMail->Empty(); - - if (plpsText) - plpsText->Empty(); - - if (plpsRTFText) - plpsRTFText->Empty(); - - if (plpsMultiChatData) - plpsMultiChatData->Empty(); - - if (plpsText || plpsRTFText) - if (MraOfflineMessageGetHeaderValueLow(lpszHeaderLow, dwHeaderSize, "content-type", 12, &lpszContentTypeLow, &dwContentTypeSize) == NO_ERROR) { - if (MemoryFind(0, lpszContentTypeLow, dwContentTypeSize, "multipart/alternative", 21)) { - // Content-Type: multipart/alternative; boundary = 1217508709J3777283291217508709T31197726 - LPSTR lpszBoundary, lpszMIMEPart, lpszCurMIMEPos, lpszMIMEHeader, lpszMIMEHeaderLow, lpszMIMEBody, lpszMIMEContentType; - size_t i, dwBoundarySize, dwMIMEPartSize, dwMIMEHeaderSize, dwMIMEBodySize, dwMIMEContentTypeSize; - - lpszBoundary = (LPSTR)MemoryFind(0, lpszContentTypeLow, dwContentTypeSize, "boundary=", 9); - if (lpszBoundary) { - dwBoundarySize = ((dwContentTypeSize-(lpszBoundary-lpszContentTypeLow))-9); - lpszBoundary = (lpszHeader+((lpszBoundary+9)-lpszHeaderLow)); - - i = 0; - lpszCurMIMEPos = lpszBody; - while (MraOfflineMessageGetNextMIMEPart(lpszBody, dwBodySize, lpszBoundary, dwBoundarySize, &lpszCurMIMEPos, &lpszMIMEPart, &dwMIMEPartSize) == NO_ERROR) { - if (MraOfflineMessageGetMIMEHeadAndBody(lpszMIMEPart, dwMIMEPartSize, &lpszMIMEHeader, &dwMIMEHeaderSize, &lpszMIMEBody, &dwMIMEBodySize) == NO_ERROR) { - lpszMIMEHeaderLow = (LPSTR)mir_calloc(dwMIMEHeaderSize); - if (lpszMIMEHeaderLow) { - BuffToLowerCase(lpszMIMEHeaderLow, lpszMIMEHeader, dwMIMEHeaderSize); - if (MraOfflineMessageGetHeaderValueLow(lpszMIMEHeaderLow, dwMIMEHeaderSize, "content-type", 12, &lpszMIMEContentType, &dwMIMEContentTypeSize) == NO_ERROR) { - if (MemoryFind(0, lpszMIMEContentType, dwMIMEContentTypeSize, "text/plain", 10)) { - // this is simple text part: text/plain - if (plpsText) - dwRetErrorCode = PlainText2message( CMStringA(lpszMIMEContentType, dwMIMEContentTypeSize), CMStringA(lpszMIMEBody, dwMIMEBodySize), *plpsText, pdwFlags); - } - else if (MemoryFind(0, lpszMIMEContentType, dwMIMEContentTypeSize, "application/x-mrim-rtf", 22)) { - if (plpsRTFText) { - *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 = CMStringA(lpszMIMEBody, dwMIMEBodySize); - if (pdwFlags) - (*pdwFlags) |= MESSAGE_FLAG_MULTICHAT; // set MESSAGE_FLAG_MULTICHAT flag if not exist - dwRetErrorCode = NO_ERROR; - } - } - else DebugBreak(); - } - mir_free(lpszMIMEHeaderLow); - } + #ifdef _DEBUG + DebugPrintCRLFA(plpsMsg->GetString()); + #endif + + if ( MraOfflineMessageGetMIMEHeadAndBody(plpsMsg->GetString(), plpsMsg->GetLength(), &lpszHeader, &dwHeaderSize, &lpszBody, &dwBodySize) != NO_ERROR) + return ERROR_INVALID_HANDLE; + + ptrA lpszHeaderLow((LPSTR)mir_calloc(dwHeaderSize)); + if (lpszHeaderLow) + BuffToLowerCase(lpszHeaderLow, lpszHeader, dwHeaderSize); + + if (pdwTime) + if (MraOfflineMessageGetHeaderValue(lpszHeader, lpszHeaderLow, dwHeaderSize, "date", 4, szTemp) == NO_ERROR) { + INTERNET_TIME itTime; + InternetTimeGetTime(szTemp, itTime); + *pdwTime = MraOfflineMessageConvertTime(&itTime); + } + else *pdwTime = 0; + + if (pdwFlags) + if (MraOfflineMessageGetHeaderValue(lpszHeader, lpszHeaderLow, dwHeaderSize, "x-mrim-flags", 12, szTemp) == NO_ERROR) + *pdwFlags = StrHexToUNum32(szTemp, szTemp.GetLength()); + else + *pdwFlags = 0; + + 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) != NO_ERROR) + plpsEMail->Empty(); + + if (plpsText) + plpsText->Empty(); + + if (plpsRTFText) + plpsRTFText->Empty(); + + if (plpsMultiChatData) + plpsMultiChatData->Empty(); + + if (plpsText || plpsRTFText) + if (MraOfflineMessageGetHeaderValueLow(lpszHeaderLow, dwHeaderSize, "content-type", 12, &lpszContentTypeLow, &dwContentTypeSize) != NO_ERROR) + return ERROR_NOT_FOUND; + + if (MemoryFind(0, lpszContentTypeLow, dwContentTypeSize, "multipart/alternative", 21)) { + // Content-Type: multipart/alternative; boundary = 1217508709J3777283291217508709T31197726 + LPSTR lpszBoundary = (LPSTR)MemoryFind(0, lpszContentTypeLow, dwContentTypeSize, "boundary=", 9); + if (lpszBoundary) { + size_t dwBoundarySize = ((dwContentTypeSize-(lpszBoundary-lpszContentTypeLow))-9); + lpszBoundary = lpszHeader + (lpszBoundary + 9 - (LPSTR)lpszHeaderLow); + + int i = 0; + size_t dwMIMEPartSize, dwMIMEHeaderSize, dwMIMEBodySize, dwMIMEContentTypeSize; + LPSTR lpszCurMIMEPos = lpszBody, lpszMIMEPart, lpszMIMEHeader, lpszMIMEBody; + while (MraOfflineMessageGetNextMIMEPart(lpszBody, dwBodySize, lpszBoundary, dwBoundarySize, lpszCurMIMEPos, &lpszMIMEPart, &dwMIMEPartSize) == NO_ERROR) { + if (MraOfflineMessageGetMIMEHeadAndBody(lpszMIMEPart, dwMIMEPartSize, &lpszMIMEHeader, &dwMIMEHeaderSize, &lpszMIMEBody, &dwMIMEBodySize) == NO_ERROR) { + ptrA lpszMIMEHeaderLow((LPSTR)mir_calloc(dwMIMEHeaderSize)); + if (lpszMIMEHeaderLow == NULL) + return ERROR_OUTOFMEMORY; + + BuffToLowerCase(lpszMIMEHeaderLow, lpszMIMEHeader, dwMIMEHeaderSize); + + LPSTR lpszMIMEContentType; + if (MraOfflineMessageGetHeaderValueLow(lpszMIMEHeaderLow, dwMIMEHeaderSize, "content-type", 12, &lpszMIMEContentType, &dwMIMEContentTypeSize) == NO_ERROR) { + if (MemoryFind(0, lpszMIMEContentType, dwMIMEContentTypeSize, "text/plain", 10)) { + // this is simple text part: text/plain + if (plpsText) + return PlainText2message( CMStringA(lpszMIMEContentType, dwMIMEContentTypeSize), CMStringA(lpszMIMEBody, dwMIMEBodySize), *plpsText, pdwFlags); + } + else if (MemoryFind(0, lpszMIMEContentType, dwMIMEContentTypeSize, "application/x-mrim-rtf", 22)) { + if (plpsRTFText) { + *plpsRTFText = CMStringA(lpszMIMEBody, dwMIMEBodySize); + if (pdwFlags) + (*pdwFlags) |= MESSAGE_FLAG_RTF; // set RTF flag if not exist + return NO_ERROR; } - i++; } - - DebugBreakIf((i>3 || i == 0)); + else if (MemoryFind(0, lpszMIMEContentType, dwMIMEContentTypeSize, "application/x-mrim+xml", 22)) { + if (plpsMultiChatData) { + *plpsMultiChatData = CMStringA(lpszMIMEBody, dwMIMEBodySize); + if (pdwFlags) + (*pdwFlags) |= MESSAGE_FLAG_MULTICHAT; // set MESSAGE_FLAG_MULTICHAT flag if not exist + return NO_ERROR; + } + } + else DebugBreak(); } - else DebugBreak(); // boundary not found - } - else if (MemoryFind(0, lpszContentTypeLow, dwContentTypeSize, "text/plain", 10)) { - dwRetErrorCode = PlainText2message( CMStringA(lpszContentTypeLow, dwContentTypeSize), CMStringA(lpszBody, dwBodySize), *plpsText, pdwFlags); } - else if (MemoryFind(0, lpszContentTypeLow, dwContentTypeSize, "application/x-mrim-auth-req", 27)) { // Content-Type: application/x-mrim-auth-req - if (plpsText) - *plpsText = CMStringA(lpszBody, dwBodySize); - dwRetErrorCode = NO_ERROR; - } - else DebugBreak(); + i++; } - else DebugBreak(); - mir_free(lpszHeaderLow); + DebugBreakIf((i>3 || i == 0)); } + return ERROR_NOT_FOUND; + } + + if (MemoryFind(0, lpszContentTypeLow, dwContentTypeSize, "text/plain", 10)) + return PlainText2message( CMStringA(lpszContentTypeLow, dwContentTypeSize), CMStringA(lpszBody, dwBodySize), *plpsText, pdwFlags); + + if (MemoryFind(0, lpszContentTypeLow, dwContentTypeSize, "application/x-mrim-auth-req", 27)) { // Content-Type: application/x-mrim-auth-req + if (plpsText) + *plpsText = CMStringA(lpszBody, dwBodySize); + return NO_ERROR; } - return(dwRetErrorCode); + return ERROR_INVALID_HANDLE; } diff --git a/protocols/MRA/src/Mra_functions.cpp b/protocols/MRA/src/Mra_functions.cpp index 8e03a93c70..8d3c419bd8 100644 --- a/protocols/MRA/src/Mra_functions.cpp +++ b/protocols/MRA/src/Mra_functions.cpp @@ -466,8 +466,9 @@ HANDLE CMraProto::MraHContactFromEmail(const CMStringA& szEmail, BOOL bAddIfNeed 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"); + if (szEMailLocal == szEmail) { + if (bTemporary == FALSE) + db_unset(hContact, "CList", "NotOnList"); bFound = true; break; } @@ -489,7 +490,7 @@ HANDLE CMraProto::MraHContactFromEmail(const CMStringA& szEmail, BOOL bAddIfNeed 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) { + if (szEMailLocal == szEmail) { bChatAdded = TRUE; break; } @@ -555,16 +556,10 @@ DWORD CMraProto::MraSetContactStatus(HANDLE hContact, DWORD dwNewStatus) { DWORD dwOldStatus = MraGetContactStatus(hContact); - if (dwNewStatus != dwOldStatus) - { - BOOL bChatAgent; - - bChatAgent = IsContactChatAgent(hContact); - - if (dwNewStatus == ID_STATUS_OFFLINE) - { - if (hContact) - { + if (dwNewStatus != dwOldStatus) { + bool bChatAgent = IsContactChatAgent(hContact); + if (dwNewStatus == ID_STATUS_OFFLINE) { + if (hContact) { setByte(hContact, DBSETTING_XSTATUSID, MRA_MIR_XSTATUS_NONE); delSetting(hContact, DBSETTING_XSTATUSNAME); delSetting(hContact, DBSETTING_XSTATUSMSG); @@ -573,27 +568,28 @@ DWORD CMraProto::MraSetContactStatus(HANDLE hContact, DWORD dwNewStatus) delSetting(hContact, DBSETTING_BLOGSTATUS); delSetting(hContact, DBSETTING_BLOGSTATUSMUSIC); MraContactCapabilitiesSet(hContact, 0); - if (bChatAgent) MraChatSessionDestroy(hContact); + if (bChatAgent) + MraChatSessionDestroy(hContact); } setDword(hContact, "LogonTS", 0); delSetting(hContact, "IP"); delSetting(hContact, "RealIP"); - }else { - if (dwOldStatus == ID_STATUS_OFFLINE) - { + } + else { + if (dwOldStatus == ID_STATUS_OFFLINE) { DWORD dwTime = (DWORD)_time32(NULL); - setDword(hContact, "LogonTS", dwTime); setDword(hContact, "OldLogonTS", dwTime); - if (bChatAgent) MraChatSessionNew(hContact); + if (bChatAgent) + MraChatSessionNew(hContact); } MraAvatarsQueueGetAvatarSimple(hAvatarsQueueHandle, 0, hContact, 0); } setWord(hContact, "Status", (WORD)dwNewStatus); } - return(dwOldStatus); + return dwOldStatus; } void CMraProto::MraUpdateEmailStatus(const CMStringA &pszFrom, const CMStringA &pszSubject, DWORD dwDate, DWORD dwUIDL) diff --git a/protocols/MRA/src/Mra_svcs.cpp b/protocols/MRA/src/Mra_svcs.cpp index 11b7f37b35..2301c50c24 100644 --- a/protocols/MRA/src/Mra_svcs.cpp +++ b/protocols/MRA/src/Mra_svcs.cpp @@ -443,9 +443,9 @@ int CMraProto::MraDbSettingChanged(WPARAM wParam, LPARAM lParam) CMStringW wszNick; DWORD dwID, dwGroupID, dwContactFlag; - if ( CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szModule, -1, "CList", 5) == CSTR_EQUAL) { + if ( !strcmp(cws->szModule, "CList")) { // MyHandle setting - if (CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szSetting, -1, "MyHandle", 8) == CSTR_EQUAL) { + if ( !strcmp(cws->szSetting, "MyHandle")) { // always store custom nick if (cws->value.type == DBVT_DELETED) { wszNick = GetContactNameW(hContact); @@ -471,7 +471,7 @@ int CMraProto::MraDbSettingChanged(WPARAM wParam, LPARAM lParam) } } // Group setting - else if ( CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szSetting, -1, "Group", 5) == CSTR_EQUAL ) { + else if ( !strcmp(cws->szSetting, "Group")) { // manage group on server switch (cws->value.type) { case DBVT_ASCIIZ: @@ -481,7 +481,7 @@ int CMraProto::MraDbSettingChanged(WPARAM wParam, LPARAM lParam) } } // 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) { + else if ( !strcmp(cws->szSetting, "NotOnList")) { if (cws->value.type == DBVT_DELETED || (cws->value.type == DBVT_BYTE && cws->value.bVal == 0)) { CMStringW wszAuthMessage; if ( !mraGetStringW(NULL, "AuthMessage", wszAuthMessage)) @@ -493,7 +493,7 @@ int CMraProto::MraDbSettingChanged(WPARAM wParam, LPARAM lParam) } } // Hidden setting - else if ( CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, cws->szSetting, -1, "Hidden" , 6) == CSTR_EQUAL) { + else if ( !strcmp(cws->szSetting, "Hidden")) { 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; @@ -504,8 +504,8 @@ int CMraProto::MraDbSettingChanged(WPARAM wParam, LPARAM lParam) } } // 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) { + else if ( !strcmp(cws->szModule, "Ignore")) { + if ( !strcmp(cws->szSetting, "Mask1")) { 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; @@ -516,12 +516,10 @@ int CMraProto::MraDbSettingChanged(WPARAM wParam, LPARAM lParam) } } // 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); + else if ( !strcmp(cws->szModule, "UserInfo")) { + if ( !strcmp(cws->szSetting, "MyPhone0") || !strcmp(cws->szSetting, "MyPhone1") || !strcmp(cws->szSetting, "MyPhone2")) { + GetContactBasicInfoW(hContact, &dwID, &dwGroupID, &dwContactFlag, NULL, NULL, &szEmail, &wszNick, &szPhones); + MraModifyContactW(hContact, dwID, dwContactFlag, dwGroupID, szEmail, wszNick, szPhones); } } } diff --git a/protocols/MRA/src/Sdk/InternetTime.h b/protocols/MRA/src/Sdk/InternetTime.h index 683bae777f..0c7bde1f36 100644 --- a/protocols/MRA/src/Sdk/InternetTime.h +++ b/protocols/MRA/src/Sdk/InternetTime.h @@ -127,9 +127,9 @@ __inline void InternetTimeGetCurrentTime(INTERNET_TIME *pitTime) GetSystemTime(&pitTime->stTime); } - +// Переводит время из MAILTIME в строковое __inline CMStringA InternetTimeGetString(INTERNET_TIME *pitTime) -{// Переводит время из MAILTIME в строковое +{ DWORD dwRet=NO_ERROR; char lpszBuff[100]; @@ -164,135 +164,115 @@ __inline CMStringA InternetTimeGetString(INTERNET_TIME *pitTime) return lpszBuff; } - - -__inline DWORD InternetTimeGetTime(const CMStringA &lpszTime, INTERNET_TIME *pitTime) -{// Переводит время из строкового в INTERNET_TIME - DWORD dwRet=NO_ERROR; - - 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(lpszTime, lpszTime.GetLength(), lpszCurPos, &dwCurSize); - - if (dwCurSize>3) - {// день недели - if (lpszCurPos[3]==',') - { - for (i=0;i<8;i++) - { - if (CompareStringA(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),NORM_IGNORECASE,lpcszenmDayOfWeakEnum[i],3,lpszCurPos,3)==CSTR_EQUAL) - { - pitTime->stTime.wDayOfWeek=(unsigned short)i; - break; - } +// Переводит время из строкового в INTERNET_TIME +__inline DWORD InternetTimeGetTime(const CMStringA &lpszTime, INTERNET_TIME &pitTime) +{ + if (lpszTime.IsEmpty()) + return ERROR_INVALID_HANDLE; + + // = 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(lpszTime, lpszTime.GetLength(), lpszCurPos, &dwCurSize); + + if (dwCurSize > 3) { // день недели + if (lpszCurPos[3] == ',') { + for (i=0; i < 8; i++) { + if ( !_memicmp(lpcszenmDayOfWeakEnum[i], lpszCurPos, 3)) { + pitTime.stTime.wDayOfWeek=(unsigned short)i; + break; } - - lpszCurPos+=4; - dwCurSize-=4; } - if (dwCurSize>2) - {// день месяца - SkeepSPWSP(lpszCurPos,dwCurSize,&lpszCurPos,&dwCurSize); - if ((lpszTemp=(LPSTR)MemoryFindByte(0,lpszCurPos,dwCurSize,' '))) - { - dwTemp=(lpszTemp-lpszCurPos); - pitTime->stTime.wDay=(unsigned short)StrToUNum32(lpszCurPos,dwTemp); + lpszCurPos+=4; + dwCurSize-=4; + } - lpszCurPos=(lpszTemp+1); - dwCurSize-=(dwTemp+1); + if (dwCurSize>2) { // день месяца + SkeepSPWSP(lpszCurPos,dwCurSize,&lpszCurPos,&dwCurSize); + if ((lpszTemp = (LPSTR)MemoryFindByte(0, lpszCurPos, dwCurSize,' '))) { + dwTemp=(lpszTemp-lpszCurPos); + pitTime.stTime.wDay=(unsigned short)StrToUNum32(lpszCurPos,dwTemp); - if (dwCurSize>3) - {// месяц - SkeepSPWSP(lpszCurPos,dwCurSize,&lpszCurPos,&dwCurSize); + lpszCurPos=(lpszTemp+1); + dwCurSize-=(dwTemp+1); - for (i=1;i<14;i++) - { - if (CompareStringA(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),NORM_IGNORECASE,lpcszenmMonthEnum[i],3,lpszCurPos,3)==CSTR_EQUAL) - { - pitTime->stTime.wMonth=(unsigned short)i; - break; - } + if (dwCurSize > 3) { // месяц + SkeepSPWSP(lpszCurPos,dwCurSize,&lpszCurPos,&dwCurSize); + + for (i=1; i < 14; i++) + if ( !_memicmp(lpcszenmMonthEnum[i], lpszCurPos, 3)) { + pitTime.stTime.wMonth=(unsigned short)i; + break; } - lpszCurPos+=3; - dwCurSize-=3; - - - if (dwCurSize>3) - {// год - SkeepSPWSP(lpszCurPos,dwCurSize,&lpszCurPos,&dwCurSize); - if ((lpszTemp=(LPSTR)MemoryFindByte(0,lpszCurPos,dwCurSize,' '))) - { - dwTemp=(lpszTemp-lpszCurPos); - pitTime->stTime.wYear=(unsigned short)StrToUNum32(lpszCurPos,dwTemp); - - lpszCurPos=(lpszTemp+1); - dwCurSize-=(dwTemp+1); - - if (dwCurSize>2) - { // часы - SkeepSPWSP(lpszCurPos,dwCurSize,&lpszCurPos,&dwCurSize); - if ((lpszTemp=(LPSTR)MemoryFindByte(0,lpszCurPos,dwCurSize,':'))) - { - dwTemp=(lpszTemp-lpszCurPos); - pitTime->stTime.wHour=(unsigned short)StrToUNum32(lpszCurPos,dwTemp); - - lpszCurPos=(lpszTemp+1); - dwCurSize-=(dwTemp+1); - - if (dwCurSize>2) - {// минуты - SkeepSPWSP(lpszCurPos,dwCurSize,&lpszCurPos,&dwCurSize); - if ((lpszTemp=(LPSTR)MemoryFindByte(0,lpszCurPos,dwCurSize,':'))) - { - dwTemp=(lpszTemp-lpszCurPos); - pitTime->stTime.wMinute=(unsigned short)StrToUNum32(lpszCurPos,dwTemp); - - lpszCurPos=(lpszTemp+1); - dwCurSize-=(dwTemp+1); - - if (dwCurSize>2) - {// секунды, они есть - if ((lpszTemp=(LPSTR)MemoryFindByte(0,lpszCurPos,dwCurSize,' '))) - { - dwTemp=(lpszTemp-lpszCurPos); - pitTime->stTime.wSecond=(unsigned short)StrToUNum32(lpszCurPos,dwTemp); - - lpszCurPos=(lpszTemp+1); - dwCurSize-=(dwTemp+1); - } - }else{// зоны нет - if (dwCurSize) - { - pitTime->stTime.wSecond=(unsigned short)StrToUNum32(lpszCurPos,dwCurSize); - lpszCurPos+=dwCurSize; - dwCurSize=0; - } - } - }else{ - if ((lpszTemp=(LPSTR)MemoryFindByte(0,lpszCurPos,dwCurSize,' '))) - { + lpszCurPos += 3; + dwCurSize -= 3; + + if (dwCurSize > 3) { // год + SkeepSPWSP(lpszCurPos,dwCurSize,&lpszCurPos,&dwCurSize); + if ((lpszTemp = (LPSTR)MemoryFindByte(0,lpszCurPos,dwCurSize,' '))) { + dwTemp=(lpszTemp-lpszCurPos); + pitTime.stTime.wYear=(unsigned short)StrToUNum32(lpszCurPos,dwTemp); + + lpszCurPos=(lpszTemp+1); + dwCurSize-=(dwTemp+1); + + if (dwCurSize > 2) { // часы + SkeepSPWSP(lpszCurPos,dwCurSize,&lpszCurPos,&dwCurSize); + if ((lpszTemp = (LPSTR)MemoryFindByte(0,lpszCurPos,dwCurSize,':'))) { + dwTemp=(lpszTemp-lpszCurPos); + pitTime.stTime.wHour=(unsigned short)StrToUNum32(lpszCurPos,dwTemp); + + lpszCurPos=(lpszTemp+1); + dwCurSize-=(dwTemp+1); + + if (dwCurSize > 2) { // минуты + SkeepSPWSP(lpszCurPos,dwCurSize,&lpszCurPos,&dwCurSize); + if ((lpszTemp=(LPSTR)MemoryFindByte(0,lpszCurPos,dwCurSize,':'))) + { + dwTemp=(lpszTemp-lpszCurPos); + pitTime.stTime.wMinute=(unsigned short)StrToUNum32(lpszCurPos,dwTemp); + + lpszCurPos = (lpszTemp+1); + dwCurSize -= (dwTemp+1); + + if (dwCurSize > 2) { // секунды, они есть + if ((lpszTemp = (LPSTR)MemoryFindByte(0,lpszCurPos,dwCurSize,' '))) { dwTemp=(lpszTemp-lpszCurPos); - pitTime->stTime.wMinute=(unsigned short)StrToUNum32(lpszCurPos,dwTemp); + pitTime.stTime.wSecond=(unsigned short)StrToUNum32(lpszCurPos,dwTemp); lpszCurPos=(lpszTemp+1); dwCurSize-=(dwTemp+1); } } + else {// зоны нет + if (dwCurSize) { + pitTime.stTime.wSecond=(unsigned short)StrToUNum32(lpszCurPos,dwCurSize); + lpszCurPos+=dwCurSize; + dwCurSize=0; + } + } + } + else { + if ((lpszTemp = (LPSTR)MemoryFindByte(0,lpszCurPos,dwCurSize,' '))) { + dwTemp = (lpszTemp-lpszCurPos); + pitTime.stTime.wMinute = (unsigned short)StrToUNum32(lpszCurPos,dwTemp); - if (dwCurSize) - {// часовой пояс - SkeepSPWSP(lpszCurPos,dwCurSize,&lpszCurPos,&dwCurSize); - pitTime->lTimeZone=(LONG)StrToNum(lpszCurPos,dwCurSize); - if (pitTime->lTimeZone>1300 || pitTime->lTimeZone<-1200) pitTime->lTimeZone=2400; + lpszCurPos = (lpszTemp+1); + dwCurSize -= (dwTemp+1); } } + + if (dwCurSize) { // часовой пояс + SkeepSPWSP(lpszCurPos, dwCurSize, &lpszCurPos, &dwCurSize); + pitTime.lTimeZone = (LONG)StrToNum(lpszCurPos, dwCurSize); + if (pitTime.lTimeZone > 1300 || pitTime.lTimeZone < -1200) + pitTime.lTimeZone = 2400; + } } } } @@ -301,10 +281,9 @@ __inline DWORD InternetTimeGetTime(const CMStringA &lpszTime, INTERNET_TIME *pit } } } - }else{ - dwRet=ERROR_INVALID_HANDLE; } -return(dwRet); + + return NO_ERROR; } diff --git a/protocols/MRA/src/version.h b/protocols/MRA/src/version.h index 8ec3205d42..f8c4fb2be7 100644 --- a/protocols/MRA/src/version.h +++ b/protocols/MRA/src/version.h @@ -1,6 +1,6 @@ -#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 __FILEVERSION_STRING 2, 1, 0, 2 +#define __VERSION_STRING "2.1.0.2" +#define __VERSION_DWORD PLUGIN_MAKE_VERSION(2, 1, 0, 2) #define PROTO_VERSION_MAJOR 1 #define PROTO_VERSION_MINOR 21 -- cgit v1.2.3