diff options
Diffstat (limited to 'protocols/MRA/src/MraOfflineMsg.cpp')
-rw-r--r-- | protocols/MRA/src/MraOfflineMsg.cpp | 233 |
1 files changed, 117 insertions, 116 deletions
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;
}
|