summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--otr/dllmain.cpp307
-rw-r--r--otr/otr.mdsp3
-rw-r--r--otr/otr_private.h4
3 files changed, 171 insertions, 143 deletions
diff --git a/otr/dllmain.cpp b/otr/dllmain.cpp
index 57c42df..cd99563 100644
--- a/otr/dllmain.cpp
+++ b/otr/dllmain.cpp
@@ -1,4 +1,5 @@
/* Replace "dll.h" with the name of your header */
+/* Replace "dll.h" with the name of your header */
#include "common.h"
#include "dll.h"
@@ -31,7 +32,8 @@ char private_key_filename[MAX_PATH];
OtrlUserState otr_user_state = 0;
-#define TIMER_ID_CLEAR_FINISHED 0x101
+UINT_PTR TIMER_ID_CLEAR_FINISHED = 0;
+
// plugin stuff
PLUGININFOEX pluginInfo={
sizeof(PLUGININFOEX),
@@ -162,7 +164,7 @@ void SetEncryptionStatus(HANDLE hContact, bool encrypted) {
if(!chat_room && ServiceExists(MS_MC_GETMETACONTACT)) {
HANDLE hMeta = (HANDLE)CallService(MS_MC_GETMETACONTACT, (WPARAM)hContact, 0);
- if(hContact == (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hMeta, 0)) {
+ if(hMeta && hContact == (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hMeta, 0)) {
//strcat(dbg_msg, "\nrecursing for meta");
SetEncryptionStatus(hMeta, encrypted);
}
@@ -494,21 +496,28 @@ void Disconnect(ConnContext *context) {
void CALLBACK ClearFinishedSessions(HWND, UINT, UINT, DWORD) {
KillTimer(0, TIMER_ID_CLEAR_FINISHED);
+ //PUShowMessage("Clearing finished sessions", SM_NOTIFY);
HANDLE hContact;
ConnContext *context = otr_user_state->context_root;
while(context) {
if(context->msgstate == OTRL_MSGSTATE_FINISHED) {
- hContact = context->app_data;
+ //hContact = context->app_data; // why is this broken?
+ hContact = get_contact(context->protocol, context->username);
+ SetEncryptionStatus(hContact, false);
+ //PUShowMessage("Cleared a finished session", SM_NOTIFY);
+
+ lib_cs_lock();
otrl_context_force_plaintext(context);
- SetEncryptionStatus(hContact, false);
+ lib_cs_unlock();
}
context = context->next;
}
}
void ResetFinishedTimer() {
- KillTimer(0, TIMER_ID_CLEAR_FINISHED);
- SetTimer(0, TIMER_ID_CLEAR_FINISHED, DBGetContactSettingDword(0, MODULE, "SessionTimeout", 10000), ClearFinishedSessions);
+ //PUShowMessage("ResetFinishedTimer", SM_NOTIFY);
+ if(TIMER_ID_CLEAR_FINISHED) KillTimer(0, TIMER_ID_CLEAR_FINISHED);
+ TIMER_ID_CLEAR_FINISHED = SetTimer(0, 0, DBGetContactSettingDword(0, MODULE, "SessionTimeout", 10000), ClearFinishedSessions);
}
// if it's a protocol going offline, attempt to send terminate session to all contacts of that protocol
@@ -679,61 +688,67 @@ int OTRSendMessage(WPARAM wParam,LPARAM lParam){
}
if(newmessage) {
- //MessageBox(0, "Send message - message encoded - decoding UTF-8", "msg", MB_OK);
- // decode utf8 into unicode message
- wchar_t *temp;
- char *text;
-
- // forward message
- int size = MultiByteToWideChar(CP_UTF8, 0, (const char *)newmessage, -1, 0, 0);
- temp = (wchar_t *)malloc(size * sizeof(wchar_t));
- if(!temp) return 1;
- MultiByteToWideChar(CP_UTF8, 0, (const char *)newmessage, -1, temp, size);
-
- size = WideCharToMultiByte(code_page, 0, temp, -1, 0, 0, 0, 0);
- text = (char *)malloc(size);
- if(!text) {
- free(temp);
- return 1;
- }
- WideCharToMultiByte(code_page, 0, temp, -1, text, size, 0, 0);
-
- lib_cs_lock();
- otrl_message_free(newmessage);
- lib_cs_unlock();
-
- int tMsgBodyLen = strlen(text);
- int tRealBodyLen = wcslen(temp);
+ int ret;
+ if(ccs->wParam & PREF_UTF) {
+ ccs->lParam = (LPARAM)newmessage;
+ ret = CallService(MS_PROTO_CHAINSEND, wParam, lParam);
+ } else {
+ //MessageBox(0, "Send message - message encoded - decoding UTF-8", "msg", MB_OK);
+ // decode utf8 into unicode message
+ wchar_t *temp;
+ char *text;
- int tMsgBufLen = (tMsgBodyLen+1) * sizeof(char) + (tRealBodyLen+1)*sizeof( wchar_t );
- char* tMsgBuf = ( char* )malloc( tMsgBufLen );
- if(!tMsgBuf) {
- free(temp);
- free(text);
- return 1;
- }
-
- char* p = tMsgBuf;
+ // forward message
+ int size = MultiByteToWideChar(CP_UTF8, 0, (const char *)newmessage, -1, 0, 0);
+ temp = (wchar_t *)malloc(size * sizeof(wchar_t));
+ if(!temp) return 1;
+ MultiByteToWideChar(CP_UTF8, 0, (const char *)newmessage, -1, temp, size);
- strcpy(p, text);
- p += (tMsgBodyLen+1);
- free(text);
+ size = WideCharToMultiByte(code_page, 0, temp, -1, 0, 0, 0, 0);
+ text = (char *)malloc(size);
+ if(!text) {
+ free(temp);
+ return 1;
+ }
+ WideCharToMultiByte(code_page, 0, temp, -1, text, size, 0, 0);
+
+ lib_cs_lock();
+ otrl_message_free(newmessage);
+ lib_cs_unlock();
- WPARAM old_flags = ccs->wParam;
- if ( tRealBodyLen != 0 ) {
- wcscpy((wchar_t *)p, temp);
- ccs->wParam |= PREF_UNICODE;
+ int tMsgBodyLen = strlen(text);
+ int tRealBodyLen = wcslen(temp);
+
+ int tMsgBufLen = (tMsgBodyLen+1) * sizeof(char) + (tRealBodyLen+1)*sizeof( wchar_t );
+ char* tMsgBuf = ( char* )malloc( tMsgBufLen );
+ if(!tMsgBuf) {
+ free(temp);
+ free(text);
+ return 1;
+ }
+
+ char* p = tMsgBuf;
+
+ strcpy(p, text);
+ p += (tMsgBodyLen+1);
+ free(text);
+
+ WPARAM old_flags = ccs->wParam;
+ if ( tRealBodyLen != 0 ) {
+ wcscpy((wchar_t *)p, temp);
+ ccs->wParam |= PREF_UNICODE;
+ }
+ free(temp);
+ //MessageBox(0, "Send message - forwarding message", "msg", MB_OK);
+ // forward new message
+ ccs->lParam = (LPARAM)tMsgBuf;
+ ret = CallService(MS_PROTO_CHAINSEND, wParam, lParam);
+ // free decrypted message and conversion buffer
+ free(tMsgBuf);
+
+ // restore state of chain message, for freeing, db, etc etc.
+ ccs->wParam = old_flags;
}
- free(temp);
- //MessageBox(0, "Send message - forwarding message", "msg", MB_OK);
- // forward new message
- ccs->lParam = (LPARAM)tMsgBuf;
- int ret = CallService(MS_PROTO_CHAINSEND, wParam, lParam);
- // free decrypted message and conversion buffer
- free(tMsgBuf);
-
- // restore state of chain message, for freeing, db, etc etc.
- ccs->wParam = old_flags;
//ccs->szProtoService=PSS_MESSAGE"W";
ccs->lParam = (LPARAM)oldmessage;
@@ -788,37 +803,31 @@ int RecvMessage(WPARAM wParam,LPARAM lParam){
if(!proto || !uname) return 1; // error
// convert oldmessage to utf-8
- if(ccs->wParam & PREF_UTF) {
+ if(pre->flags & PREF_UTF) {
oldmessage_utf = strdup(oldmessage);
- } else if(ccs->wParam & PREF_UNICODE) {
+ if(!oldmessage_utf) return 1;
+ } else if(pre->flags & PREF_UNICODE) {
int size = WideCharToMultiByte(CP_UTF8, 0, (wchar_t *)&oldmessage[strlen(oldmessage)+1], -1, 0, 0, 0, 0);
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 {
- 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);
-
+ 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);
}
lib_cs_lock();
@@ -848,78 +857,96 @@ int RecvMessage(WPARAM wParam,LPARAM lParam){
return 1;
if(newmessage) {
+ int ret;
// user should receive newmessage instead of message
-
- // decode utf8 into unicode message
- wchar_t *temp;
- char *text;
-
- int size = MultiByteToWideChar(CP_UTF8, 0, (const char *)newmessage, -1, 0, 0);
- temp = (wchar_t *)malloc(size * sizeof(wchar_t));
- if(!temp) return 1;
- MultiByteToWideChar(CP_UTF8, 0, (const char *)newmessage, -1, temp, size);
-
- size = WideCharToMultiByte(code_page, 0, temp, -1, 0, 0, 0, 0);
- text = (char *)malloc(size);
- if(!text) {
- free(temp);
- return 1;
- }
- WideCharToMultiByte(code_page, 0, temp, -1, text, size, 0, 0);
-
- lib_cs_lock();
- otrl_message_free(newmessage);
- lib_cs_unlock();
- int tMsgBodyLen = strlen(text);
- int tRealBodyLen = wcslen(temp);
-
// it may not be encrypted however (e.g. tagged plaintext with tags stripped)
ConnContext *context = otrl_context_find(otr_user_state, uname, MODULE, proto, FALSE, 0, 0, 0);
bool encrypted = context && context->msgstate != OTRL_MSGSTATE_PLAINTEXT;
-
- if(options.prefix_messages && encrypted) {
- tMsgBodyLen += strlen(MESSAGE_PREFIX);
- tRealBodyLen += wcslen(MESSAGE_PREFIXW);
- }
-
- int tMsgBufLen = (tMsgBodyLen+1) * sizeof(char) + (tRealBodyLen+1)*sizeof( wchar_t );
- char* tMsgBuf = ( char* )malloc( tMsgBufLen );
- if(!tMsgBuf) {
+
+ if(pre->flags & PREF_UTF) {
+ char *temp;
+ if(options.prefix_messages && encrypted) {
+ int len = strlen(MESSAGE_PREFIX) + strlen(newmessage) + 1;
+ temp = (char *)malloc(len);
+ mir_snprintf(temp, len, "%s%s", MESSAGE_PREFIX, newmessage);
+ } else
+ temp = strdup(newmessage);
+
+ pre->szMessage = temp;
+ ret = CallService(MS_PROTO_CHAINRECV, wParam, lParam);
free(temp);
- free(text);
- return 1;
- }
-
- char* p = tMsgBuf;
-
- if(options.prefix_messages && encrypted) {
- strcpy(p, MESSAGE_PREFIX);
- strcat(p + strlen(MESSAGE_PREFIX), text);
- } else
- strcpy(p, text);
- p += (tMsgBodyLen+1);
- free(text);
+ } else {
+ // decode utf8 into unicode message
+ wchar_t *temp;
+ char *text;
+
+ int size = MultiByteToWideChar(CP_UTF8, 0, (const char *)newmessage, -1, 0, 0);
+ temp = (wchar_t *)malloc(size * sizeof(wchar_t));
+ if(!temp) return 1;
+ MultiByteToWideChar(CP_UTF8, 0, (const char *)newmessage, -1, temp, size);
+
+ size = WideCharToMultiByte(code_page, 0, temp, -1, 0, 0, 0, 0);
+ text = (char *)malloc(size);
+ if(!text) {
+ free(temp);
+ return 1;
+ }
+ WideCharToMultiByte(code_page, 0, temp, -1, text, size, 0, 0);
+
+ int tMsgBodyLen = strlen(text);
+ int tRealBodyLen = wcslen(temp);
+
+ // it may not be encrypted however (e.g. tagged plaintext with tags stripped)
+ ConnContext *context = otrl_context_find(otr_user_state, uname, MODULE, proto, FALSE, 0, 0, 0);
+ bool encrypted = context && context->msgstate != OTRL_MSGSTATE_PLAINTEXT;
- WPARAM old_flags = pre->flags;
- if ( tRealBodyLen != 0 ) {
if(options.prefix_messages && encrypted) {
- wcscpy((wchar_t *)p, MESSAGE_PREFIXW);
- wcscat((wchar_t *)p + wcslen(MESSAGE_PREFIXW), temp );
+ tMsgBodyLen += strlen(MESSAGE_PREFIX);
+ tRealBodyLen += wcslen(MESSAGE_PREFIXW);
+ }
+
+ int tMsgBufLen = (tMsgBodyLen+1) * sizeof(char) + (tRealBodyLen+1)*sizeof( wchar_t );
+ char* tMsgBuf = ( char* )malloc( tMsgBufLen );
+ if(!tMsgBuf) {
+ free(temp);
+ free(text);
+ return 1;
+ }
+
+ char* p = tMsgBuf;
+
+ if(options.prefix_messages && encrypted) {
+ strcpy(p, MESSAGE_PREFIX);
+ strcat(p + strlen(MESSAGE_PREFIX), text);
} else
- wcscpy((wchar_t *)p, temp);
- pre->flags |= PREF_UNICODE;
+ strcpy(p, text);
+ p += (tMsgBodyLen+1);
+ free(text);
+
+ WPARAM old_flags = pre->flags;
+ if ( tRealBodyLen != 0 ) {
+ if(options.prefix_messages && encrypted) {
+ wcscpy((wchar_t *)p, MESSAGE_PREFIXW);
+ wcscat((wchar_t *)p + wcslen(MESSAGE_PREFIXW), temp );
+ } else
+ wcscpy((wchar_t *)p, temp);
+ pre->flags |= PREF_UNICODE;
+ }
+ free(temp);
+
+ pre->szMessage = tMsgBuf;
+ ret = CallService(MS_PROTO_CHAINRECV, wParam, lParam);
+ // free decrypted message and conversion buffer
+ free(tMsgBuf);
+ pre->flags = old_flags;
}
- free(temp);
-
- pre->szMessage = tMsgBuf;
- int ret = CallService(MS_PROTO_CHAINRECV, wParam, lParam);
- // free decrypted message and conversion buffer
- free(tMsgBuf);
+ lib_cs_lock();
+ otrl_message_free(newmessage);
+ lib_cs_unlock();
+
// restore old message, so it can be freed etc
- pre->flags &= ~(PREF_UTF);
- pre->flags = old_flags;
pre->szMessage = oldmessage;
return ret;
diff --git a/otr/otr.mdsp b/otr/otr.mdsp
index d4b77ec..6254430 100644
--- a/otr/otr.mdsp
+++ b/otr/otr.mdsp
@@ -129,4 +129,5 @@ extraResourceOptions=
30=..\..\include\m_updater.h
31=..\..\include\m_database.h
[History]
-otr_private.h,534
+otr_private.h,171
+dllmain.cpp,41536
diff --git a/otr/otr_private.h b/otr/otr_private.h
index 9d306d5..d67e25b 100644
--- a/otr/otr_private.h
+++ b/otr/otr_private.h
@@ -4,8 +4,8 @@
/* VERSION DEFINITIONS */
#define VER_MAJOR 0
#define VER_MINOR 5
-#define VER_RELEASE 7
-#define VER_BUILD 1
+#define VER_RELEASE 8
+#define VER_BUILD 0
#define __STRINGIZE(x) #x
#define VER_STRING __STRINGIZE( VER_MAJOR.VER_MINOR.VER_RELEASE.VER_BUILD )