From d5baf212f45c3926ffec3bccad77ca4dd0751d23 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Thu, 21 Oct 2010 05:34:01 +0300 Subject: using utf8<->utf16 on poor c++ instead of miranda api (can solve some issues with badly encoded messages, testing needed) --- messages.cpp | 57 +++++++++++++++------------------------------------------ 1 file changed, 15 insertions(+), 42 deletions(-) (limited to 'messages.cpp') diff --git a/messages.cpp b/messages.cpp index 3479f7e..8df3a2b 100644 --- a/messages.cpp +++ b/messages.cpp @@ -40,11 +40,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) { //check for gpg related data - wchar_t *tmp = mir_utf8decodeW(msg); - if(!tmp) - tmp = mir_a2t(msg); - wstring str = tmp; - mir_free(tmp); + wstring str = toUTF16(msg); wstring::size_type s1 = wstring::npos, s2 = wstring::npos; if((str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")) != wstring::npos) && (str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")) != wstring::npos)) @@ -311,16 +307,9 @@ int RecvMsgSvc(WPARAM w, LPARAM l) f.seekg(0, std::ios::beg); f.read(tmp, size); tmp[size] = '\0'; - TCHAR *tmp2 = mir_utf8decodeW(tmp); - if(!tmp2) - { - str.append(_T("Miranda failed to decode this utf8 message, showing it as is:\n")); - tmp2 = mir_a2t(tmp); - str.append(tmp2); - } + toUTF16(tmp); + str.append(toUTF16(tmp)); delete [] tmp; - str.append(tmp2); - mir_free(tmp2); f.close(); DeleteFile(path.c_str()); } @@ -341,10 +330,10 @@ int RecvMsgSvc(WPARAM w, LPARAM l) str.insert(0, inopentag); str.append(inclosetag); } - pre->szMessage = mir_utf8encodeW(str.c_str()); + pre->szMessage = mir_strdup(toUTF8(str).c_str()); if(metaIsSubcontact(hContact)) { - char *msg = mir_utf8encodeW(str.c_str()); + char *msg = mir_strdup(toUTF8(str).c_str()); HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, DBEF_UTF); mir_free(msg); return 1; @@ -363,11 +352,9 @@ int RecvMsgSvc(WPARAM w, LPARAM l) mir_free(msg); return 1; } - wchar_t *tmp = mir_utf8decodeW(msg); - wstring str = tmp; - mir_free(tmp); + wstring str = toUTF16(msg); mir_free((void**)pre->szMessage); - pre->szMessage = mir_utf8encodeW(str.c_str()); + pre->szMessage = mir_strdup(toUTF8(str).c_str()); return CallService(MS_PROTO_CHAINRECV, w, (LPARAM)ccs); } return CallService(MS_PROTO_CHAINRECV, w, l); @@ -405,11 +392,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) { //encrypt data here - TCHAR *tmp = mir_utf8decodeW(msg); - if(!tmp) - tmp = mir_a2t(msg); - wstring str = tmp; - mir_free(tmp); + wstring str = toUTF16(msg); { //not xmpp, just replace whole message string out; DWORD code; @@ -442,7 +425,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) cmd += _T("\""); { char *tmp; - tmp = mir_utf8encodeW(str.c_str()); + tmp = mir_strdup(toUTF8(str).c_str()); fstream f(path.c_str(), std::ios::out); f<lParam = (LPARAM)mir_utf8encodeW(str.c_str()); + ccs->lParam = (LPARAM)mir_strdup(toUTF8(str).c_str()); if(bAppendTags) DBWriteContactSettingByte(hContact, szGPGModuleName, "MsgsForTagging", DBGetContactSettingByte(hContact, szGPGModuleName, "MsgsForTagging", 0) + 1); } @@ -596,14 +573,10 @@ int HookSendMsg(WPARAM w, LPARAM l) if((dbei->eventType == EVENTTYPE_MESSAGE) && (dbei->flags & DBEF_SENT)) { char *msg = (char*)dbei->pBlob; - TCHAR *tmp = mir_utf8decodeW(msg); - if(!tmp) - tmp = mir_a2t(msg); - wstring str = tmp; - mir_free(tmp); + wstring str = toUTF16(msg); str.insert(0, outopentag); str.append(outclosetag); - char *msg2 = mir_utf8encodeW(str.c_str()); + char *msg2 = mir_strdup(toUTF8(str).c_str()); mir_free(dbei->pBlob); dbei->pBlob = (PBYTE)msg2; dbei->cbBlob = strlen(msg2)+1; -- cgit v1.2.3