summaryrefslogtreecommitdiff
path: root/otr/dllmain.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'otr/dllmain.cpp')
-rw-r--r--otr/dllmain.cpp51
1 files changed, 33 insertions, 18 deletions
diff --git a/otr/dllmain.cpp b/otr/dllmain.cpp
index bddefee..26300bb 100644
--- a/otr/dllmain.cpp
+++ b/otr/dllmain.cpp
@@ -788,26 +788,33 @@ int RecvMessage(WPARAM wParam,LPARAM lParam){
// convert oldmessage to utf-8
if(ccs->wParam & PREF_UNICODE) {
int size = WideCharToMultiByte(CP_UTF8, 0, (wchar_t *)&oldmessage[strlen(oldmessage)+1], -1, 0, 0, 0, 0);
- oldmessage_utf = (char *)malloc(size * sizeof(char));
+ oldmessage_utf = (char *)malloc(size);
if(!oldmessage_utf) return 1;
WideCharToMultiByte(CP_UTF8, 0, (wchar_t *)&oldmessage[strlen(oldmessage)+1], -1, oldmessage_utf, size, 0, 0);
} else {
- wchar_t *temp = 0;
- int size_temp, size;
- size_temp = MultiByteToWideChar(code_page, 0, oldmessage, -1, 0, 0);
- temp = (wchar_t *)malloc(size_temp * sizeof(wchar_t));
- if(!temp) return 1;
- MultiByteToWideChar(code_page, 0, oldmessage, -1, temp, size_temp);
-
- size = WideCharToMultiByte(CP_UTF8, 0, temp, -1, 0, 0, 0, 0);
- oldmessage_utf = (char *)malloc(size * sizeof(char));
- if(!oldmessage_utf) {
+ if(ccs->wParam & PREF_UTF) {
+ int size = strlen(oldmessage);
+ oldmessage_utf = (char *)malloc(size + 1);
+ if(!oldmessage_utf) return 1;
+ mir_snprintf(oldmessage_utf, size + 1, "%s", oldmessage);
+ } else {
+ wchar_t *temp = 0;
+ int size_temp, size;
+ size_temp = MultiByteToWideChar(code_page, 0, oldmessage, -1, 0, 0);
+ temp = (wchar_t *)malloc(size_temp * sizeof(wchar_t));
+ if(!temp) return 1;
+ MultiByteToWideChar(code_page, 0, oldmessage, -1, temp, size_temp);
+
+ size = WideCharToMultiByte(CP_UTF8, 0, temp, -1, 0, 0, 0, 0);
+ oldmessage_utf = (char *)malloc(size * sizeof(char));
+ if(!oldmessage_utf) {
+ free(temp);
+ return 1;
+ }
+ WideCharToMultiByte(CP_UTF8, 0, temp, -1, oldmessage_utf, size, 0, 0);
+
free(temp);
- return 1;
}
- WideCharToMultiByte(CP_UTF8, 0, temp, -1, oldmessage_utf, size, 0, 0);
-
- free(temp);
}
lib_cs_lock();
@@ -907,6 +914,7 @@ int RecvMessage(WPARAM wParam,LPARAM lParam){
free(tMsgBuf);
// restore old message, so it can be freed etc
+ pre->flags &= ~(PREF_UTF);
pre->flags = old_flags;
pre->szMessage = oldmessage;
@@ -980,9 +988,15 @@ int OnDatabaseEventPreAdd(WPARAM wParam, LPARAM lParam) {
msgw = (wchar_t *)&msg[msglen];
} else {
// no, convert to unciode (allocate stack memory);
- int size = MultiByteToWideChar(code_page, 0, (char *) msg, -1, 0, 0);
- msgw = (wchar_t *) _alloca(sizeof(wchar_t) * size);
- MultiByteToWideChar(code_page, 0, msg, -1, msgw, size);
+ if(dbei->flags && DBEF_UTF) {
+ int size = MultiByteToWideChar(CP_UTF8, 0, (char *) msg, -1, 0, 0);
+ msgw = (wchar_t *) _alloca(sizeof(wchar_t) * size);
+ MultiByteToWideChar(CP_UTF8, 0, msg, -1, msgw, size);
+ } else {
+ int size = MultiByteToWideChar(code_page, 0, (char *) msg, -1, 0, 0);
+ msgw = (wchar_t *) _alloca(sizeof(wchar_t) * size);
+ MultiByteToWideChar(code_page, 0, msg, -1, msgw, size);
+ }
}
int tMsgBodyLen = strlen(msg) + strlen(MESSAGE_PREFIX);
@@ -1004,6 +1018,7 @@ int OnDatabaseEventPreAdd(WPARAM wParam, LPARAM lParam) {
my_dbei.pBlob = (BYTE *)tMsgBuf;
my_dbei.cbBlob = tMsgBufLen;
+ my_dbei.flags &= ~(DBEF_UTF);
CallService(MS_DB_EVENT_ADD, (WPARAM)hContact, (LPARAM)&my_dbei);