From 8c63b97ea59b9a9649f13ddc1392fbc45c3ab548 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 6 Apr 2013 19:40:26 +0000 Subject: memory corruption in the HTMLBuilder for Scriver git-svn-id: http://svn.miranda-ng.org/main/trunk@4348 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/IEView/src/HTMLBuilder.cpp | 135 +++++++++++++++--------------- plugins/IEView/src/ScriverHTMLBuilder.cpp | 134 ++++++++++++++--------------- 2 files changed, 133 insertions(+), 136 deletions(-) (limited to 'plugins') diff --git a/plugins/IEView/src/HTMLBuilder.cpp b/plugins/IEView/src/HTMLBuilder.cpp index bfee0b82b2..435c4cecf5 100644 --- a/plugins/IEView/src/HTMLBuilder.cpp +++ b/plugins/IEView/src/HTMLBuilder.cpp @@ -297,24 +297,25 @@ void HTMLBuilder::appendEventNew(IEView *view, IEVIEWEVENT *event) appendEvent(view, event); } -void HTMLBuilder::appendEventOld(IEView *view, IEVIEWEVENT *event) { - IEVIEWEVENT newEvent; +void HTMLBuilder::appendEventOld(IEView *view, IEVIEWEVENT *event) +{ IEVIEWEVENTDATA* eventData; IEVIEWEVENTDATA* prevEventData = NULL; - char *szProto = NULL; HANDLE hDbEvent = event->hDbEventFirst; event->hDbEventFirst = NULL; - newEvent.cbSize = sizeof (IEVIEWEVENT); + + IEVIEWEVENT newEvent = { sizeof (IEVIEWEVENT) }; newEvent.iType = IEE_LOG_MEM_EVENTS; newEvent.codepage = CP_ACP; - if (event->cbSize >= IEVIEWEVENT_SIZE_V2) { + if (event->cbSize >= IEVIEWEVENT_SIZE_V2) newEvent.codepage = event->codepage; - } - if (event->cbSize >= IEVIEWEVENT_SIZE_V3 && event->pszProto != NULL) { + + char *szProto; + if (event->cbSize >= IEVIEWEVENT_SIZE_V3 && event->pszProto != NULL) szProto = mir_strdup(event->pszProto); - } else { + else szProto = getProto(event->hContact); - } + newEvent.pszProto = szProto; newEvent.count = 0; newEvent.dwFlags = event->dwFlags; @@ -333,9 +334,10 @@ void HTMLBuilder::appendEventOld(IEView *view, IEVIEWEVENT *event) { if (!(dbei.flags & DBEF_SENT) && (dbei.eventType == EVENTTYPE_MESSAGE || dbei.eventType == EVENTTYPE_URL)) { db_event_markRead(event->hContact, hDbEvent); CallService(MS_CLIST_REMOVEEVENT, (WPARAM) event->hContact, (LPARAM) hDbEvent); - } else if (dbei.eventType == EVENTTYPE_STATUSCHANGE) { - db_event_markRead(event->hContact, hDbEvent); } + else if (dbei.eventType == EVENTTYPE_STATUSCHANGE) + db_event_markRead(event->hContact, hDbEvent); + if (!isDbEventShown(&dbei)) { free(dbei.pBlob); hDbEvent = db_event_next(hDbEvent); @@ -345,9 +347,9 @@ void HTMLBuilder::appendEventOld(IEView *view, IEVIEWEVENT *event) { eventData->cbSize = sizeof(IEVIEWEVENTDATA); eventData->dwFlags = IEEDF_UNICODE_TEXT | IEEDF_UNICODE_NICK | IEEDF_UNICODE_TEXT2 | (dbei.flags & DBEF_READ ? IEEDF_READ : 0) | (dbei.flags & DBEF_SENT ? IEEDF_SENT : 0) | (dbei.flags & DBEF_RTL ? IEEDF_RTL : 0); - if (event->dwFlags & IEEF_RTL) { - eventData->dwFlags |= IEEDF_RTL; - } + if (event->dwFlags & IEEF_RTL) + eventData->dwFlags |= IEEDF_RTL; + eventData->time = dbei.timestamp; eventData->pszNickW = NULL; eventData->pszTextW = NULL; @@ -355,7 +357,8 @@ void HTMLBuilder::appendEventOld(IEView *view, IEVIEWEVENT *event) { if (dbei.flags & DBEF_SENT) { eventData->pszNickW = getContactName(NULL, szProto); eventData->bIsMe = TRUE; - } else { + } + else { eventData->pszNickW = getContactName(event->hContact, szProto); eventData->bIsMe = FALSE; } @@ -364,14 +367,14 @@ void HTMLBuilder::appendEventOld(IEView *view, IEVIEWEVENT *event) { WCHAR* pwszEventText = (WCHAR*)CallService(MS_DB_EVENT_GETTEXT,0,(LPARAM)&temp); eventData->pszTextW = mir_tstrdup(pwszEventText); mir_free(pwszEventText); - if (dbei.eventType == EVENTTYPE_MESSAGE) { + if (dbei.eventType == EVENTTYPE_MESSAGE) eventData->iType = IEED_EVENT_MESSAGE; - } else if (dbei.eventType == EVENTTYPE_URL) { + else if (dbei.eventType == EVENTTYPE_URL) eventData->iType = IEED_EVENT_URL; - } else { + else eventData->iType = IEED_EVENT_STATUSCHANGE; - } - } else if (dbei.eventType == EVENTTYPE_FILE) { + } + else if (dbei.eventType == EVENTTYPE_FILE) { //blob is: sequenceid(DWORD),filename(ASCIIZ),description(ASCIIZ) char* filename = ((char *)dbei.pBlob) + sizeof(DWORD); char* descr = filename + lstrlenA(filename) + 1; @@ -384,14 +387,16 @@ void HTMLBuilder::appendEventOld(IEView *view, IEVIEWEVENT *event) { mir_free(tStr); } eventData->iType = IEED_EVENT_FILE; - } else if (dbei.eventType == EVENTTYPE_AUTHREQUEST) { + } + else if (dbei.eventType == EVENTTYPE_AUTHREQUEST) { //blob is: uin(DWORD), hContact(DWORD), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ) eventData->ptszText = mir_tstrdup(TranslateT(" requested authorisation")); TCHAR *tStr = DbGetEventStringT(&dbei, (char *)dbei.pBlob + 8); eventData->ptszNick = mir_tstrdup(tStr); mir_free(tStr); eventData->iType = IEED_EVENT_SYSTEM; - } else if (dbei.eventType == EVENTTYPE_ADDED) { + } + else if (dbei.eventType == EVENTTYPE_ADDED) { //blob is: uin(DWORD), hContact(DWORD), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ) eventData->ptszText = mir_tstrdup(TranslateT(" was added.")); TCHAR *tStr = DbGetEventStringT(&dbei, (char *)dbei.pBlob + 8); @@ -401,11 +406,11 @@ void HTMLBuilder::appendEventOld(IEView *view, IEVIEWEVENT *event) { } free(dbei.pBlob); eventData->next = NULL; - if (prevEventData != NULL) { + if (prevEventData != NULL) prevEventData->next = eventData; - } else { + else newEvent.eventData = eventData; - } + prevEventData = eventData; newEvent.count++; event->hDbEventFirst = hDbEvent; @@ -430,83 +435,81 @@ void HTMLBuilder::appendEventOld(IEView *view, IEVIEWEVENT *event) { } } -ProtocolSettings* HTMLBuilder::getSRMMProtocolSettings(const char *protocolName) { +ProtocolSettings* HTMLBuilder::getSRMMProtocolSettings(const char *protocolName) +{ ProtocolSettings *protoSettings = Options::getProtocolSettings(protocolName); - if (protoSettings == NULL || !protoSettings->isSRMMEnable()) { - protoSettings = Options::getProtocolSettings(); - } + if (protoSettings == NULL || !protoSettings->isSRMMEnable()) + protoSettings = Options::getProtocolSettings(); + return protoSettings; } -ProtocolSettings* HTMLBuilder::getSRMMProtocolSettings(HANDLE hContact) { - char *szRealProto = getRealProto(hContact); - ProtocolSettings *protoSettings = getSRMMProtocolSettings(szRealProto); - mir_free(szRealProto); - return protoSettings; +ProtocolSettings* HTMLBuilder::getSRMMProtocolSettings(HANDLE hContact) +{ + return getSRMMProtocolSettings( mir_ptr(getRealProto(hContact))); } -ProtocolSettings* HTMLBuilder::getHistoryProtocolSettings(const char *protocolName) { +ProtocolSettings* HTMLBuilder::getHistoryProtocolSettings(const char *protocolName) +{ ProtocolSettings *protoSettings = Options::getProtocolSettings(protocolName); - if (protoSettings == NULL || !protoSettings->isHistoryEnable()) { - protoSettings = Options::getProtocolSettings(); - } + if (protoSettings == NULL || !protoSettings->isHistoryEnable()) + protoSettings = Options::getProtocolSettings(); + return protoSettings; } -ProtocolSettings* HTMLBuilder::getHistoryProtocolSettings(HANDLE hContact) { - ProtocolSettings *protoSettings; - if (hContact != NULL) { - char *szRealProto = getRealProto(hContact); - protoSettings = getHistoryProtocolSettings(szRealProto); - delete szRealProto; - } else { - protoSettings = Options::getProtocolSettings(); - } - return protoSettings; +ProtocolSettings* HTMLBuilder::getHistoryProtocolSettings(HANDLE hContact) +{ + if (hContact != NULL) + return getHistoryProtocolSettings( mir_ptr(getRealProto(hContact))); + + return Options::getProtocolSettings(); } -ProtocolSettings* HTMLBuilder::getChatProtocolSettings(const char *protocolName) { +ProtocolSettings* HTMLBuilder::getChatProtocolSettings(const char *protocolName) +{ ProtocolSettings *protoSettings = Options::getProtocolSettings(protocolName); - if (protoSettings == NULL || !protoSettings->isChatEnable()) { - protoSettings = Options::getProtocolSettings(); - } + if (protoSettings == NULL || !protoSettings->isChatEnable()) + protoSettings = Options::getProtocolSettings(); + return protoSettings; } -ProtocolSettings* HTMLBuilder::getChatProtocolSettings(HANDLE hContact) { +ProtocolSettings* HTMLBuilder::getChatProtocolSettings(HANDLE hContact) +{ char *szRealProto = getRealProto(hContact); ProtocolSettings *protoSettings = getChatProtocolSettings(szRealProto); delete szRealProto; return protoSettings; } -void HTMLBuilder::setLastIEViewEvent(IEVIEWEVENT *event) { +void HTMLBuilder::setLastIEViewEvent(IEVIEWEVENT *event) +{ lastIEViewEvent.cbSize = sizeof (IEVIEWEVENT); lastIEViewEvent.iType = event->iType; lastIEViewEvent.codepage = CP_ACP; - if (event->cbSize >= IEVIEWEVENT_SIZE_V2) { + if (event->cbSize >= IEVIEWEVENT_SIZE_V2) lastIEViewEvent.codepage = event->codepage; - } + lastIEViewEvent.count = 0; lastIEViewEvent.dwFlags = event->dwFlags; lastIEViewEvent.hContact = event->hContact; lastIEViewEvent.hwnd = event->hwnd; lastIEViewEvent.eventData = NULL; - if (lastIEViewEvent.pszProto != NULL) { + if (lastIEViewEvent.pszProto != NULL) mir_free((void*)lastIEViewEvent.pszProto); - } - if (event->cbSize >= IEVIEWEVENT_SIZE_V3 && event->pszProto != NULL) { + + if (event->cbSize >= IEVIEWEVENT_SIZE_V3 && event->pszProto != NULL) lastIEViewEvent.pszProto = mir_strdup(event->pszProto); - } else { + else lastIEViewEvent.pszProto = getProto(event->hContact); - } } -void HTMLBuilder::clear(IEView *view, IEVIEWEVENT *event) { - if (event != NULL) { +void HTMLBuilder::clear(IEView *view, IEVIEWEVENT *event) +{ + if (event != NULL) setLastIEViewEvent(event); - } - if (lastIEViewEvent.pszProto != NULL || event->hContact == NULL) { + + if (lastIEViewEvent.pszProto != NULL || event->hContact == NULL) buildHead(view, &lastIEViewEvent); - } } diff --git a/plugins/IEView/src/ScriverHTMLBuilder.cpp b/plugins/IEView/src/ScriverHTMLBuilder.cpp index 666ea3fb74..6c11c4be51 100644 --- a/plugins/IEView/src/ScriverHTMLBuilder.cpp +++ b/plugins/IEView/src/ScriverHTMLBuilder.cpp @@ -282,7 +282,7 @@ void ScriverHTMLBuilder::appendEventNonTemplate(IEView *view, IEVIEWEVENT *event dwFlags |= db_get_b(NULL, SRMMMOD, SRMSGSET_MESSAGEONNEWLINE, 0) ? SMF_LOG_MSGONNEWLINE : 0; dwFlags |= db_get_b(NULL, SRMMMOD, SRMSGSET_DRAWLINES, 0) ? SMF_LOG_DRAWLINES : 0; - char *szRealProto = getRealProto(event->hContact); + mir_ptr szRealProto( getRealProto(event->hContact)); IEVIEWEVENTDATA* eventData = event->eventData; for (int eventIdx = 0; eventData!=NULL && (eventIdx < event->count || event->count==-1); eventData = eventData->next, eventIdx++) { const char *className = ""; @@ -292,53 +292,52 @@ void ScriverHTMLBuilder::appendEventNonTemplate(IEView *view, IEVIEWEVENT *event int isSent = eventData->dwFlags & IEEDF_SENT; int isRTL = eventData->dwFlags & IEEDF_RTL; showColon = false; - if (eventData->iType == IEED_EVENT_MESSAGE || eventData->iType == IEED_EVENT_STATUSCHANGE - || eventData->iType == IEED_EVENT_URL || eventData->iType == IEED_EVENT_FILE) { + if (eventData->iType == IEED_EVENT_MESSAGE || eventData->iType == IEED_EVENT_STATUSCHANGE || + eventData->iType == IEED_EVENT_URL || eventData->iType == IEED_EVENT_FILE) + { int isGroupBreak = TRUE; - if ((dwFlags & SMF_LOG_GROUPMESSAGES) && eventData->dwFlags == LOWORD(getLastEventType()) - && eventData->iType == IEED_EVENT_MESSAGE && HIWORD(getLastEventType()) == IEED_EVENT_MESSAGE - && (isSameDate(eventData->time, getLastEventTime())) - && (((eventData->time < startedTime) == (getLastEventTime() < startedTime)) || !(eventData->dwFlags & IEEDF_READ))) { + if ((dwFlags & SMF_LOG_GROUPMESSAGES) && eventData->dwFlags == LOWORD(getLastEventType()) && + eventData->iType == IEED_EVENT_MESSAGE && HIWORD(getLastEventType()) == IEED_EVENT_MESSAGE && + (isSameDate(eventData->time, getLastEventTime())) && + (((eventData->time < startedTime) == (getLastEventTime() < startedTime)) || !(eventData->dwFlags & IEEDF_READ))) { isGroupBreak = FALSE; } - char *szName = NULL; - char *szText = NULL; - if (eventData->dwFlags & IEEDF_UNICODE_NICK) { + char *szName = NULL, *szText = NULL; + if (eventData->dwFlags & IEEDF_UNICODE_NICK) szName = encodeUTF8(event->hContact, szRealProto, eventData->pszNickW, ENF_NAMESMILEYS, true); - } else { + else szName = encodeUTF8(event->hContact, szRealProto, eventData->pszNick, ENF_NAMESMILEYS, true); - } - if (eventData->dwFlags & IEEDF_UNICODE_TEXT) { + + if (eventData->dwFlags & IEEDF_UNICODE_TEXT) szText = encodeUTF8(event->hContact, szRealProto, eventData->pszTextW, eventData->iType == IEED_EVENT_MESSAGE ? ENF_ALL : 0, isSent); - } else { + else szText = encodeUTF8(event->hContact, szRealProto, eventData->pszText, event->codepage, eventData->iType == IEED_EVENT_MESSAGE ? ENF_ALL : 0, isSent); - } + /* Scriver-specific formatting */ - if ((dwFlags & SMF_LOG_DRAWLINES) && isGroupBreak && getLastEventType()!=-1) { - if (eventData->iType == IEED_EVENT_MESSAGE) { + if ((dwFlags & SMF_LOG_DRAWLINES) && isGroupBreak && getLastEventType() != -1) { + if (eventData->iType == IEED_EVENT_MESSAGE) className = isRTL ? isSent ? "divOutGridRTL" : "divInGridRTL" : isSent ? "divOutGrid" : "divInGrid"; - } else { + else className = isRTL ? isSent ? "divNoticeGridRTL" : "divNoticeGridRTL" : isSent ? "divNoticeGrid" : "divNoticeGrid"; - } - } else { - if (eventData->iType == IEED_EVENT_MESSAGE) { + } + else { + if (eventData->iType == IEED_EVENT_MESSAGE) className = isRTL ? isSent ? "divOutRTL" : "divInRTL" : isSent ? "divOut" : "divIn"; - } else { + else className = isRTL ? isSent ? "divNoticeRTL" : "divNoticeRTL" : isSent ? "divNotice" : "divNotice"; - } } Utils::appendText(&output, &outputSize, "
", className); if ((dwFlags & SMF_LOG_SHOWICONS) && isGroupBreak) { const char *iconFile = ""; - if (eventData->iType == IEED_EVENT_MESSAGE) { + if (eventData->iType == IEED_EVENT_MESSAGE) iconFile = isSent ? "message_out.gif" : "message_in.gif"; - } else if (eventData->iType == IEED_EVENT_FILE) { + else if (eventData->iType == IEED_EVENT_FILE) iconFile = "file.gif"; - } else if (eventData->iType == IEED_EVENT_URL) { + else if (eventData->iType == IEED_EVENT_URL) iconFile = "url.gif"; - } else if (eventData->iType == IEED_EVENT_STATUSCHANGE) { + else if (eventData->iType == IEED_EVENT_STATUSCHANGE) iconFile = "status.gif"; - } + Utils::appendIcon(&output, &outputSize, iconFile); } @@ -348,45 +347,43 @@ void ScriverHTMLBuilder::appendEventNonTemplate(IEView *view, IEVIEWEVENT *event char* timestampString = NULL; if (dwFlags & SMF_LOG_GROUPMESSAGES) { if (isGroupBreak) { - if (!(dwFlags & SMF_LOG_MARKFOLLOWUPS)) { + if (!(dwFlags & SMF_LOG_MARKFOLLOWUPS)) timestampString = timestampToString(dwFlags, eventData->time, 0); - } else if (dwFlags & SMF_LOG_SHOWDATE) + else if (dwFlags & SMF_LOG_SHOWDATE) timestampString = timestampToString(dwFlags, eventData->time, 1); - } else if (dwFlags & SMF_LOG_MARKFOLLOWUPS) { - timestampString = timestampToString(dwFlags, eventData->time, 2); } - } else - timestampString = timestampToString(dwFlags, eventData->time, 0); - if (timestampString != NULL) { - Utils::appendText(&output, &outputSize, "%s", - isSent ? "timeOut" : "timeIn", - timestampString); + else if (dwFlags & SMF_LOG_MARKFOLLOWUPS) + timestampString = timestampToString(dwFlags, eventData->time, 2); } - if (eventData->iType != IEED_EVENT_MESSAGE) { + else timestampString = timestampToString(dwFlags, eventData->time, 0); + + if (timestampString != NULL) + Utils::appendText(&output, &outputSize, "%s", + isSent ? "timeOut" : "timeIn", timestampString); + + if (eventData->iType != IEED_EVENT_MESSAGE) Utils::appendText(&output, &outputSize, ": ", isSent ? "colonOut" : "colonIn"); - } + showColon = true; } if ((dwFlags & SMF_LOG_SHOWNICK && eventData->iType == IEED_EVENT_MESSAGE && isGroupBreak) || eventData->iType == IEED_EVENT_STATUSCHANGE ) { if (eventData->iType == IEED_EVENT_MESSAGE) { - if (showColon) { + if (showColon) Utils::appendText(&output, &outputSize, " %s", isSent ? "nameOut" : "nameIn", szName); - } else { + else Utils::appendText(&output, &outputSize, "%s", - isSent ? "nameOut" : "nameIn", - szName); - } + isSent ? "nameOut" : "nameIn", szName); + showColon = true; if (dwFlags & SMF_LOG_GROUPMESSAGES) { Utils::appendText(&output, &outputSize, "
"); showColon = false; } - } else { - Utils::appendText(&output, &outputSize, "%s ", szName); } + else Utils::appendText(&output, &outputSize, "%s ", szName); } if (dwFlags & SMF_LOG_SHOWTIME && dwFlags & SMF_LOG_GROUPMESSAGES && dwFlags & SMF_LOG_MARKFOLLOWUPS && eventData->iType == IEED_EVENT_MESSAGE && isGroupBreak) { @@ -395,33 +392,32 @@ void ScriverHTMLBuilder::appendEventNonTemplate(IEView *view, IEVIEWEVENT *event timestampToString(dwFlags, eventData->time, 2)); showColon = true; } - if (showColon && eventData->iType == IEED_EVENT_MESSAGE) { + if (showColon && eventData->iType == IEED_EVENT_MESSAGE) Utils::appendText(&output, &outputSize, ": ", isSent ? "colonOut" : "colonIn"); - } + if (eventData->iType == IEED_EVENT_MESSAGE) { - if (dwFlags & SMF_LOG_MSGONNEWLINE && showColon) { + if (dwFlags & SMF_LOG_MSGONNEWLINE && showColon) Utils::appendText(&output, &outputSize, "
"); - } + className = isSent ? "messageOut" : "messageIn"; - } else { - className = "notices"; } + else className = "notices"; + if (eventData->iType == IEED_EVENT_FILE) { - if (isSent) { + if (isSent) Utils::appendText(&output, &outputSize, "%s: %s", className, Translate("File sent"), szText); - } else { + else Utils::appendText(&output, &outputSize, "%s: %s", className, Translate("File received"), szText); - } - } else if (eventData->iType == IEED_EVENT_URL) { - if (isSent) { + } + else if (eventData->iType == IEED_EVENT_URL) { + if (isSent) Utils::appendText(&output, &outputSize, "%s: %s", className, Translate("URL sent"), szText); - } else { + else Utils::appendText(&output, &outputSize, "%s: %s", className, Translate("URL received"), szText); - } - } else { - Utils::appendText(&output, &outputSize, "%s", className, szText); } + else Utils::appendText(&output, &outputSize, "%s", className, szText); + Utils::appendText(&output, &outputSize, "
\n"); setLastEventType(MAKELONG(eventData->dwFlags, eventData->iType)); setLastEventTime(eventData->time); @@ -433,19 +429,17 @@ void ScriverHTMLBuilder::appendEventNonTemplate(IEView *view, IEVIEWEVENT *event free(output); } } - if (szRealProto!=NULL) delete szRealProto; view->documentClose(); -// view->scrollToBottom(); } -void ScriverHTMLBuilder::appendEvent(IEView *view, IEVIEWEVENT *event) { +void ScriverHTMLBuilder::appendEvent(IEView *view, IEVIEWEVENT *event) +{ ProtocolSettings *protoSettings = getSRMMProtocolSettings(event->hContact); - if (protoSettings == NULL) { + if (protoSettings == NULL) return; - } - if (protoSettings->getSRMMMode() == Options::MODE_TEMPLATE) { + + if (protoSettings->getSRMMMode() == Options::MODE_TEMPLATE) appendEventTemplate(view, event, protoSettings); - } else { + else appendEventNonTemplate(view, event); - } } -- cgit v1.2.3