From 37f0dfdfac4dc0af578769b02e29efb9926415bb Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 6 Apr 2013 21:07:53 +0000 Subject: postfix to the standard functions patch by Mataes git-svn-id: http://svn.miranda-ng.org/main/trunk@4351 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/IEView/src/TemplateHTMLBuilder.cpp | 392 ++++++++++++++--------------- 1 file changed, 192 insertions(+), 200 deletions(-) (limited to 'plugins/IEView/src/TemplateHTMLBuilder.cpp') diff --git a/plugins/IEView/src/TemplateHTMLBuilder.cpp b/plugins/IEView/src/TemplateHTMLBuilder.cpp index 32ba30ee62..05d7faf1d6 100644 --- a/plugins/IEView/src/TemplateHTMLBuilder.cpp +++ b/plugins/IEView/src/TemplateHTMLBuilder.cpp @@ -23,7 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define EVENTTYPE_STATUSCHANGE 25368 -TemplateHTMLBuilder::TemplateHTMLBuilder() { +TemplateHTMLBuilder::TemplateHTMLBuilder() +{ iLastEventType = -1; startedTime = time(NULL); lastEventTime = time(NULL); @@ -34,15 +35,15 @@ TemplateHTMLBuilder::TemplateHTMLBuilder() { flashAvatars[1] = NULL; } -TemplateHTMLBuilder::~TemplateHTMLBuilder() { - for (int i = 0; i < 2; i++) { - if (flashAvatars[i] != NULL) { - mir_free(flashAvatars[i]); - } - } +TemplateHTMLBuilder::~TemplateHTMLBuilder() +{ + for (int i = 0; i < 2; i++) + if (flashAvatars[i] != NULL) + mir_free(flashAvatars[i]); } -char *TemplateHTMLBuilder::getAvatar(HANDLE hContact, const char * szProto) { +char *TemplateHTMLBuilder::getAvatar(HANDLE hContact, const char* szProto) +{ DBVARIANT dbv; TCHAR tmpPath[MAX_PATH]; TCHAR *result = NULL; @@ -87,7 +88,8 @@ char *TemplateHTMLBuilder::getAvatar(HANDLE hContact, const char * szProto) { return res; } -const char *TemplateHTMLBuilder::getFlashAvatar(const TCHAR *file, int index) { +const char *TemplateHTMLBuilder::getFlashAvatar(const TCHAR *file, int index) +{ if (time(NULL) - flashAvatarsTime[index] > 600 || flashAvatars[index] == NULL) { if (flashAvatars[index] != NULL) { mir_free(flashAvatars[index]); @@ -109,15 +111,18 @@ const char *TemplateHTMLBuilder::getFlashAvatar(const TCHAR *file, int index) { return flashAvatars[index]; } -TemplateMap *TemplateHTMLBuilder::getTemplateMap(ProtocolSettings * protoSettings) { +TemplateMap *TemplateHTMLBuilder::getTemplateMap(ProtocolSettings * protoSettings) +{ return TemplateMap::getTemplateMap(protoSettings->getSRMMTemplateFilename()); } -int TemplateHTMLBuilder::getFlags(ProtocolSettings * protoSettings) { +int TemplateHTMLBuilder::getFlags(ProtocolSettings * protoSettings) +{ return protoSettings->getSRMMFlags(); } -char *TemplateHTMLBuilder::timestampToString(DWORD dwFlags, time_t check, int mode) { +char *TemplateHTMLBuilder::timestampToString(DWORD dwFlags, time_t check, int mode) +{ static char szResult[512]; TCHAR str[300]; DBTIMETOSTRINGT dbtts; @@ -145,13 +150,13 @@ char *TemplateHTMLBuilder::timestampToString(DWORD dwFlags, time_t check, int mo CallService(MS_DB_TIME_TIMESTAMPTOSTRINGT, check, (LPARAM) & dbtts); } } - char *tmp = mir_utf8encodeT(str); - lstrcpynA(szResult, tmp, 500); - mir_free(tmp); + + lstrcpynA(szResult, mir_ptr(mir_utf8encodeT(str)), 500); return szResult; } -void TemplateHTMLBuilder::buildHeadTemplate(IEView *view, IEVIEWEVENT *event, ProtocolSettings *protoSettings) { +void TemplateHTMLBuilder::buildHeadTemplate(IEView *view, IEVIEWEVENT *event, ProtocolSettings *protoSettings) +{ DBVARIANT dbv; CONTACTINFO ci; char tempBase[1024]; @@ -291,13 +296,10 @@ void TemplateHTMLBuilder::buildHeadTemplate(IEView *view, IEVIEWEVENT *event, Pr break; } if (tokenVal != NULL) { - if (token->getEscape()) { - char *escapedToken = Utils::escapeString(tokenVal); - Utils::appendText(&output, &outputSize, "%s", escapedToken); - delete escapedToken; - } else { + if (token->getEscape()) + Utils::appendText(&output, &outputSize, "%s", mir_ptr(Utils::escapeString(tokenVal))); + else Utils::appendText(&output, &outputSize, "%s", tokenVal); - } } } } @@ -305,25 +307,26 @@ void TemplateHTMLBuilder::buildHeadTemplate(IEView *view, IEVIEWEVENT *event, Pr view->write(output); free(output); } - if (szBase!=NULL) mir_free(szBase); - if (szRealProto!=NULL) mir_free(szRealProto); - if (szProto!=NULL) mir_free(szProto); - if (szUINIn!=NULL) mir_free(szUINIn); - if (szUINOut!=NULL) mir_free(szUINOut); - if (szNoAvatar!=NULL) mir_free(szNoAvatar); - if (szAvatarIn!=NULL) mir_free(szAvatarIn); - if (szAvatarOut!=NULL) mir_free(szAvatarOut); - if (szNameIn!=NULL) mir_free(szNameIn); - if (szNameOut!=NULL) mir_free(szNameOut); - if (szNickIn!=NULL) mir_free(szNickIn); - if (szNickOut!=NULL) mir_free(szNickOut); - if (szStatusMsg!=NULL) mir_free(szStatusMsg); - //view->scrollToBottom(); + mir_free(szBase); + mir_free(szRealProto); + mir_free(szProto); + mir_free(szUINIn); + mir_free(szUINOut); + mir_free(szNoAvatar); + mir_free(szAvatarIn); + mir_free(szAvatarOut); + mir_free(szNameIn); + mir_free(szNameOut); + mir_free(szNickIn); + mir_free(szNickOut); + mir_free(szStatusMsg); + groupTemplate = NULL; iLastEventType = -1; } -void TemplateHTMLBuilder::appendEventTemplate(IEView *view, IEVIEWEVENT *event, ProtocolSettings* protoSettings) { +void TemplateHTMLBuilder::appendEventTemplate(IEView *view, IEVIEWEVENT *event, ProtocolSettings* protoSettings) +{ DBVARIANT dbv; CONTACTINFO ci; HANDLE hRealContact; @@ -350,8 +353,6 @@ void TemplateHTMLBuilder::appendEventTemplate(IEView *view, IEVIEWEVENT *event, char *szFileDesc = NULL; const char *tmpltName[2]; bool isGrouping = false; -// DWORD today = (DWORD)time(NULL); -// today = today - today % 86400; if (protoSettings == NULL) return; @@ -371,14 +372,14 @@ void TemplateHTMLBuilder::appendEventTemplate(IEView *view, IEVIEWEVENT *event, } szBase = mir_utf8encode(tempBase); - if (event->hContact != NULL) { + if (event->hContact != NULL) getUINs(event->hContact, szUINIn, szUINOut); - } if (event->hContact != NULL) { szNameOut = getEncodedContactName(NULL, szProto, szRealProto); szNameIn = getEncodedContactName(event->hContact, szProto, szRealProto); - } else { + } + else { szNameOut = mir_strdup(" "); szNameIn = mir_strdup(" "); } @@ -393,21 +394,20 @@ void TemplateHTMLBuilder::appendEventTemplate(IEView *view, IEVIEWEVENT *event, else sprintf(tempStr, "%snoavatar.png", tempBase); szNoAvatar = mir_utf8encode(tempStr); - if(event->hContact != NULL) { + if(event->hContact != NULL) szAvatarIn = getAvatar(event->hContact, szRealProto); - } - if (szAvatarIn == NULL) { + + if (szAvatarIn == NULL) szAvatarIn = mir_strdup(szNoAvatar); - } + szAvatarOut = getAvatar(NULL, szRealProto); - if (szAvatarOut == NULL) { + if (szAvatarOut == NULL) szAvatarOut = mir_strdup(szNoAvatar); - } + if(event->hContact != NULL) { if (!db_get(event->hContact, "CList", "StatusMsg",&dbv)) { - if (strlen(dbv.pszVal) > 0) { + if (strlen(dbv.pszVal) > 0) szStatusMsg = mir_utf8encode(dbv.pszVal); - } db_free(&dbv); } } @@ -416,39 +416,39 @@ void TemplateHTMLBuilder::appendEventTemplate(IEView *view, IEVIEWEVENT *event, ci.hContact = event->hContact; ci.szProto = szProto; ci.dwFlag = CNF_NICK | CNF_TCHAR; - if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) & ci)) { + if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) & ci)) szNickIn = encodeUTF8(event->hContact, szRealProto, ci.pszVal, ENF_NAMESMILEYS, true); - } + ZeroMemory(&ci, sizeof(ci)); ci.cbSize = sizeof(ci); ci.hContact = NULL; ci.szProto = szProto; ci.dwFlag = CNF_NICK | CNF_TCHAR; - if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) & ci)) { + if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) & ci)) szNickOut = encodeUTF8(event->hContact, szRealProto, ci.pszVal, ENF_NAMESMILEYS, true); - } + IEVIEWEVENTDATA* eventData = event->eventData; for (int eventIdx = 0; eventData!=NULL && (eventIdx < event->count || event->count==-1); eventData = eventData->next, eventIdx++) { int outputSize; - char *output; - output = NULL; + char *output = NULL; if (eventData->iType == IEED_EVENT_MESSAGE || eventData->iType == IEED_EVENT_STATUSCHANGE || eventData->iType == IEED_EVENT_FILE || eventData->iType == IEED_EVENT_URL || eventData->iType == IEED_EVENT_SYSTEM) { bool isSent = (eventData->dwFlags & IEEDF_SENT) != 0; bool isRTL = (eventData->dwFlags & IEEDF_RTL) && tmpm->isRTL(); bool isHistory = (eventData->time < (DWORD)getStartedTime() && (eventData->dwFlags & IEEDF_READ || eventData->dwFlags & IEEDF_SENT)); bool isGroupBreak = TRUE; - if ((getFlags(protoSettings) & Options::LOG_GROUP_MESSAGES) && eventData->dwFlags == LOWORD(getLastEventType()) - && eventData->iType == IEED_EVENT_MESSAGE && HIWORD(getLastEventType()) == IEED_EVENT_MESSAGE - && (isSameDate(eventData->time, getLastEventTime())) -// && ((eventData->time < today) == (getLastEventTime() < today)) - && (((eventData->time < (DWORD)startedTime) == (getLastEventTime() < (DWORD)startedTime)) || !(eventData->dwFlags & IEEDF_READ))) { + if ((getFlags(protoSettings) & Options::LOG_GROUP_MESSAGES) && eventData->dwFlags == LOWORD(getLastEventType()) && + eventData->iType == IEED_EVENT_MESSAGE && HIWORD(getLastEventType()) == IEED_EVENT_MESSAGE && + (isSameDate(eventData->time, getLastEventTime())) && + (((eventData->time < (DWORD)startedTime) == (getLastEventTime() < (DWORD)startedTime)) || !(eventData->dwFlags & IEEDF_READ))) + { isGroupBreak = FALSE; } if (isSent) { szAvatar = szAvatarOut; szUIN = szUINOut; sprintf(szCID, "%d", 0); - } else { + } + else { szAvatar = szAvatarIn; szUIN = szUINIn; sprintf(szCID, "%d", (int)event->hContact); @@ -459,60 +459,60 @@ void TemplateHTMLBuilder::appendEventTemplate(IEView *view, IEVIEWEVENT *event, szName = NULL; szText = NULL; szFileDesc = NULL; - if (event->eventData->dwFlags & IEEDF_UNICODE_NICK) { + if (event->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); - } - if (eventData->dwFlags & IEEDF_UNICODE_TEXT2) { + + if (eventData->dwFlags & IEEDF_UNICODE_TEXT2) szFileDesc = encodeUTF8(event->hContact, szRealProto, eventData->pszText2W, 0, isSent); - } else { + else szFileDesc = encodeUTF8(event->hContact, szRealProto, eventData->pszText2, event->codepage, 0, isSent); - } + if ((eventData->iType == IEED_EVENT_MESSAGE)) { if (!isRTL) { if (isGrouping && (getFlags(protoSettings) & Options::LOG_GROUP_MESSAGES)) { - if (isGroupBreak) { + if (isGroupBreak) tmpltName[1] = isHistory ? isSent ? "hMessageOutGroupStart" : "hMessageInGroupStart" : isSent ? "MessageOutGroupStart" : "MessageInGroupStart"; - } else { + else tmpltName[0] = isHistory ? isSent ? "hMessageOutGroupInner" : "hMessageInGroupInner" : isSent ? "MessageOutGroupInner" : "MessageInGroupInner"; - } + groupTemplate = isHistory ? isSent ? "hMessageOutGroupEnd" : "hMessageInGroupEnd" : isSent ? "MessageOutGroupEnd" : "MessageInGroupEnd"; - } else { - tmpltName[1] = isHistory ? isSent ? "hMessageOut" : "hMessageIn" : isSent ? "MessageOut" : "MessageIn"; } - } else { + else tmpltName[1] = isHistory ? isSent ? "hMessageOut" : "hMessageIn" : isSent ? "MessageOut" : "MessageIn"; + } + else { if (isGrouping && (getFlags(protoSettings) & Options::LOG_GROUP_MESSAGES)) { - if (isGroupBreak) { + if (isGroupBreak) tmpltName[1] = isHistory ? isSent ? "hMessageOutGroupStartRTL" : "hMessageInGroupStartRTL" : isSent ? "MessageOutGroupStartRTL" : "MessageInGroupStartRTL"; - } else { + else tmpltName[0] = isHistory ? isSent ? "hMessageOutGroupInnerRTL" : "hMessageInGroupInnerRTL" : isSent ? "MessageOutGroupInnerRTL" : "MessageInGroupInnerRTL"; - } + groupTemplate = isHistory ? isSent ? "hMessageOutGroupEndRTL" : "hMessageInGroupEndRTL" : isSent ? "MessageOutGroupEndRTL" : "MessageInGroupEndRTL"; - } else { - tmpltName[1] = isHistory ? isSent ? "hMessageOutRTL" : "hMessageInRTL" : isSent ? "MessageOutRTL" : "MessageInRTL"; } + else tmpltName[1] = isHistory ? isSent ? "hMessageOutRTL" : "hMessageInRTL" : isSent ? "MessageOutRTL" : "MessageInRTL"; } - } else if (eventData->iType == IEED_EVENT_FILE) { + } + else if (eventData->iType == IEED_EVENT_FILE) { tmpltName[1] = isHistory ? isSent ? "hFileOut" : "hFileIn" : isSent ? "FileOut" : "FileIn"; Template *tmplt = (tmpm == NULL) ? NULL : tmpm->getTemplate(tmpltName[1]); - if (tmplt == NULL) { + if (tmplt == NULL) tmpltName[1] = isHistory ? "hFile" : "File"; - } - } else if (eventData->iType == IEED_EVENT_URL) { + } + else if (eventData->iType == IEED_EVENT_URL) { tmpltName[1] = isHistory ? isSent ? "hURLOut" : "hURLIn" : isSent ? "URLOut" : "URLIn"; Template *tmplt = (tmpm == NULL) ? NULL : tmpm->getTemplate(tmpltName[1]); - if (tmplt == NULL) { + if (tmplt == NULL) tmpltName[1] = isHistory ? "hURL" : "URL"; - } - } else if (eventData->iType == IEED_EVENT_STATUSCHANGE || (eventData->iType == IEED_EVENT_SYSTEM)) { - tmpltName[1] = isHistory ? "hStatus" : "Status"; } + else if (eventData->iType == IEED_EVENT_STATUSCHANGE || (eventData->iType == IEED_EVENT_SYSTEM)) + tmpltName[1] = isHistory ? "hStatus" : "Status"; + /* template-specific formatting */ for (int i=0;i<2;i++) { if (tmpltName[i] == NULL || tmpm == NULL) continue; @@ -522,133 +522,125 @@ void TemplateHTMLBuilder::appendEventTemplate(IEView *view, IEVIEWEVENT *event, const char *tokenVal; tokenVal = NULL; switch (token->getType()) { - case Token::PLAIN: - tokenVal = token->getText(); - break; - case Token::INAME: - if (getFlags(protoSettings) & Options::LOG_SHOW_NICKNAMES) { + case Token::PLAIN: + tokenVal = token->getText(); + break; + case Token::INAME: + if (getFlags(protoSettings) & Options::LOG_SHOW_NICKNAMES) + tokenVal = szName; + else + tokenVal = " "; + break; + case Token::TIME: + if (getFlags(protoSettings) & Options::LOG_SHOW_TIME) + tokenVal = timestampToString(getFlags(protoSettings), eventData->time, 1); + else + tokenVal = " "; + break; + case Token::DATE: + if (getFlags(protoSettings) & Options::LOG_SHOW_DATE) + tokenVal = timestampToString(getFlags(protoSettings), eventData->time, 0); + else + tokenVal = " "; + break; + case Token::TEXT: + tokenVal = szText; + break; + case Token::AVATAR: + tokenVal = szAvatar; + break; + case Token::CID: + tokenVal = szCID; + break; + case Token::BASE: + tokenVal = szBase; + break; + case Token::NAMEIN: + if (getFlags(protoSettings) & Options::LOG_SHOW_NICKNAMES) { + if (event->hContact != NULL) + tokenVal = szNameIn; + else + tokenVal = szName; + } + else tokenVal = " "; + break; + case Token::NAMEOUT: + if (getFlags(protoSettings) & Options::LOG_SHOW_NICKNAMES) { + if (event->hContact != NULL) + tokenVal = szNameOut; + else tokenVal = szName; - } else { - tokenVal = " "; - } - break; - case Token::TIME: - if (getFlags(protoSettings) & Options::LOG_SHOW_TIME) { - tokenVal = timestampToString(getFlags(protoSettings), eventData->time, 1); - } else { - tokenVal = " "; - } - break; - case Token::DATE: - if (getFlags(protoSettings) & Options::LOG_SHOW_DATE) { - tokenVal = timestampToString(getFlags(protoSettings), eventData->time, 0); - } else { - tokenVal = " "; - } - break; - case Token::TEXT: - tokenVal = szText; - break; - case Token::AVATAR: - tokenVal = szAvatar; - break; - case Token::CID: - tokenVal = szCID; - break; - case Token::BASE: - tokenVal = szBase; - break; - case Token::NAMEIN: - if (getFlags(protoSettings) & Options::LOG_SHOW_NICKNAMES) { - if (event->hContact != NULL) { - tokenVal = szNameIn; - } else { - tokenVal = szName; - } - } else { - tokenVal = " "; - } - break; - case Token::NAMEOUT: - if (getFlags(protoSettings) & Options::LOG_SHOW_NICKNAMES) { - if (event->hContact != NULL) { - tokenVal = szNameOut; - } else { - tokenVal = szName; - } - } else { - tokenVal = " "; - } - break; - case Token::AVATARIN: - tokenVal = szAvatarIn; - break; - case Token::AVATAROUT: - tokenVal = szAvatarOut; - break; - case Token::PROTO: - tokenVal = szRealProto; - break; - case Token::UIN: - tokenVal = szUIN; - break; - case Token::UININ: - tokenVal = szUINIn; - break; - case Token::UINOUT: - tokenVal = szUINOut; - break; - case Token::STATUSMSG: - tokenVal = szStatusMsg; - break; - case Token::NICKIN: - tokenVal = szNickIn; - break; - case Token::NICKOUT: - tokenVal = szNickOut; - break; - case Token::FILEDESC: - tokenVal = szFileDesc; - break; + } + else tokenVal = " "; + break; + case Token::AVATARIN: + tokenVal = szAvatarIn; + break; + case Token::AVATAROUT: + tokenVal = szAvatarOut; + break; + case Token::PROTO: + tokenVal = szRealProto; + break; + case Token::UIN: + tokenVal = szUIN; + break; + case Token::UININ: + tokenVal = szUINIn; + break; + case Token::UINOUT: + tokenVal = szUINOut; + break; + case Token::STATUSMSG: + tokenVal = szStatusMsg; + break; + case Token::NICKIN: + tokenVal = szNickIn; + break; + case Token::NICKOUT: + tokenVal = szNickOut; + break; + case Token::FILEDESC: + tokenVal = szFileDesc; + break; } if (tokenVal != NULL) { - if (token->getEscape()) { - char *escapedToken = Utils::escapeString(tokenVal); - Utils::appendText(&output, &outputSize, "%s", escapedToken); - delete escapedToken; - } else { + if (token->getEscape()) + Utils::appendText(&output, &outputSize, "%s", mir_ptr(Utils::escapeString(tokenVal))); + else Utils::appendText(&output, &outputSize, "%s", tokenVal); - } } } } setLastEventType(MAKELONG(eventData->dwFlags, eventData->iType)); setLastEventTime(eventData->time); - if (szName!=NULL) mir_free(szName); - if (szText!=NULL) mir_free(szText); - if (szFileDesc!=NULL) mir_free(szFileDesc); + + mir_free(szName); + mir_free(szText); + mir_free(szFileDesc); } if (output != NULL) { view->write(output); free(output); } } - if (szBase!=NULL) mir_free(szBase); - if (szRealProto!=NULL) mir_free(szRealProto); - if (szProto!=NULL) mir_free(szProto); - if (szUINIn!=NULL) mir_free(szUINIn); - if (szUINOut!=NULL) mir_free(szUINOut); - if (szNoAvatar!=NULL) mir_free(szNoAvatar); - if (szAvatarIn!=NULL) mir_free(szAvatarIn); - if (szAvatarOut!=NULL) mir_free(szAvatarOut); - if (szNameIn!=NULL) mir_free(szNameIn); - if (szNameOut!=NULL) mir_free(szNameOut); - if (szNickIn!=NULL) mir_free(szNickIn); - if (szNickOut!=NULL) mir_free(szNickOut); - if (szStatusMsg!=NULL) mir_free(szStatusMsg); + mir_free(szBase); + mir_free(szRealProto); + mir_free(szProto); + mir_free(szUINIn); + mir_free(szUINOut); + mir_free(szNoAvatar); + mir_free(szAvatarIn); + mir_free(szAvatarOut); + mir_free(szNameIn); + mir_free(szNameOut); + mir_free(szNickIn); + mir_free(szNickOut); + mir_free(szStatusMsg); view->documentClose(); } -time_t TemplateHTMLBuilder::getStartedTime() { +time_t TemplateHTMLBuilder::getStartedTime() +{ return startedTime; } \ No newline at end of file -- cgit v1.2.3