summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsje <sje@4f64403b-2f21-0410-a795-97e2b3489a10>2007-06-27 06:20:33 +0000
committersje <sje@4f64403b-2f21-0410-a795-97e2b3489a10>2007-06-27 06:20:33 +0000
commit564ca85d661ac802458d1975995da8ed266ba2e1 (patch)
tree3e79a09ee10886dc05576e04535287213dd8b795
parent2b8de7f0339506e75c47ffb0e14ee2e527ab1353 (diff)
fixes for miranda utf8 messages
git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@211 4f64403b-2f21-0410-a795-97e2b3489a10
-rw-r--r--otr/dllmain.cpp51
-rw-r--r--otr/otr.mdsp7
-rw-r--r--otr/otr_private.h2
3 files changed, 40 insertions, 20 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);
diff --git a/otr/otr.mdsp b/otr/otr.mdsp
index f3f5385..31982d6 100644
--- a/otr/otr.mdsp
+++ b/otr/otr.mdsp
@@ -127,6 +127,11 @@ extraResourceOptions=
28=..\..\include\m_popup.h
29=..\..\include\m_metacontacts.h
30=..\..\include\m_updater.h
+31=..\..\include\m_database.h
[History]
-dllmain.cpp,37791
+dllmain.cpp,30085
+..\..\include\m_database.h,16859
+..\..\include\m_protomod.h,0
+..\..\include\m_protocols.h,0
+..\..\include\m_protosvc.h,21718
otr_private.h,171
diff --git a/otr/otr_private.h b/otr/otr_private.h
index cc6d768..2bb2dd1 100644
--- a/otr/otr_private.h
+++ b/otr/otr_private.h
@@ -5,7 +5,7 @@
#define VER_MAJOR 0
#define VER_MINOR 5
#define VER_RELEASE 4
-#define VER_BUILD 4
+#define VER_BUILD 5
#define __STRINGIZE(x) #x
#define VER_STRING __STRINGIZE( VER_MAJOR.VER_MINOR.VER_RELEASE.VER_BUILD )