From aaf5653fc14543047663f0e1171cef6716689378 Mon Sep 17 00:00:00 2001 From: Kirill Volinsky Date: Sun, 14 Oct 2012 14:01:42 +0000 Subject: MirOTR: folders restructurization git-svn-id: http://svn.miranda-ng.org/main/trunk@1926 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirOTR/MirOTR/MirOTR.vcxproj | 68 +- plugins/MirOTR/MirOTR/MirOTR.vcxproj.filters | 68 +- plugins/MirOTR/MirOTR/dbfilter.cpp | 349 ---------- plugins/MirOTR/MirOTR/dbfilter.h | 4 - plugins/MirOTR/MirOTR/dialogs.cpp | 756 -------------------- plugins/MirOTR/MirOTR/dialogs.h | 8 - plugins/MirOTR/MirOTR/dllmain.cpp | 153 ----- plugins/MirOTR/MirOTR/dllmain.h | 8 - plugins/MirOTR/MirOTR/entities.cpp | 430 ------------ plugins/MirOTR/MirOTR/entities.h | 26 - plugins/MirOTR/MirOTR/icons.cpp | 62 -- plugins/MirOTR/MirOTR/icons.h | 13 - plugins/MirOTR/MirOTR/language.h | 122 ---- plugins/MirOTR/MirOTR/mirotrmenu.cpp | 294 -------- plugins/MirOTR/MirOTR/mirotrmenu.h | 45 -- plugins/MirOTR/MirOTR/options.cpp | 911 ------------------------- plugins/MirOTR/MirOTR/options.h | 75 -- plugins/MirOTR/MirOTR/otr.cpp | 401 ----------- plugins/MirOTR/MirOTR/otr.h | 53 -- plugins/MirOTR/MirOTR/res/finished.ico | Bin 0 -> 2550 bytes plugins/MirOTR/MirOTR/res/insecure.ico | Bin 0 -> 2550 bytes plugins/MirOTR/MirOTR/res/otr.ico | Bin 0 -> 17542 bytes plugins/MirOTR/MirOTR/res/private.ico | Bin 0 -> 2550 bytes plugins/MirOTR/MirOTR/res/refresh.ico | Bin 0 -> 7886 bytes plugins/MirOTR/MirOTR/res/resource.rc | 134 ++++ plugins/MirOTR/MirOTR/res/unverified.ico | Bin 0 -> 2550 bytes plugins/MirOTR/MirOTR/res/version.rc | 42 ++ plugins/MirOTR/MirOTR/resource.h | 104 --- plugins/MirOTR/MirOTR/resources/finished.ico | Bin 2550 -> 0 bytes plugins/MirOTR/MirOTR/resources/insecure.ico | Bin 2550 -> 0 bytes plugins/MirOTR/MirOTR/resources/otr.ico | Bin 17542 -> 0 bytes plugins/MirOTR/MirOTR/resources/private.ico | Bin 2550 -> 0 bytes plugins/MirOTR/MirOTR/resources/refresh.ico | Bin 7886 -> 0 bytes plugins/MirOTR/MirOTR/resources/resource.rc | 134 ---- plugins/MirOTR/MirOTR/resources/unverified.ico | Bin 2550 -> 0 bytes plugins/MirOTR/MirOTR/resources/version.rc | 42 -- plugins/MirOTR/MirOTR/src/dbfilter.cpp | 349 ++++++++++ plugins/MirOTR/MirOTR/src/dbfilter.h | 4 + plugins/MirOTR/MirOTR/src/dialogs.cpp | 756 ++++++++++++++++++++ plugins/MirOTR/MirOTR/src/dialogs.h | 8 + plugins/MirOTR/MirOTR/src/dllmain.cpp | 153 +++++ plugins/MirOTR/MirOTR/src/dllmain.h | 8 + plugins/MirOTR/MirOTR/src/entities.cpp | 430 ++++++++++++ plugins/MirOTR/MirOTR/src/entities.h | 26 + plugins/MirOTR/MirOTR/src/icons.cpp | 62 ++ plugins/MirOTR/MirOTR/src/icons.h | 13 + plugins/MirOTR/MirOTR/src/language.h | 122 ++++ plugins/MirOTR/MirOTR/src/mirotrmenu.cpp | 294 ++++++++ plugins/MirOTR/MirOTR/src/mirotrmenu.h | 45 ++ plugins/MirOTR/MirOTR/src/options.cpp | 911 +++++++++++++++++++++++++ plugins/MirOTR/MirOTR/src/options.h | 75 ++ plugins/MirOTR/MirOTR/src/otr.cpp | 401 +++++++++++ plugins/MirOTR/MirOTR/src/otr.h | 53 ++ plugins/MirOTR/MirOTR/src/resource.h | 104 +++ plugins/MirOTR/MirOTR/src/stdafx.cpp | 8 + plugins/MirOTR/MirOTR/src/stdafx.h | 87 +++ plugins/MirOTR/MirOTR/src/striphtml.cpp | 127 ++++ plugins/MirOTR/MirOTR/src/striphtml.h | 11 + plugins/MirOTR/MirOTR/src/svcs_menu.cpp | 211 ++++++ plugins/MirOTR/MirOTR/src/svcs_menu.h | 14 + plugins/MirOTR/MirOTR/src/svcs_proto.cpp | 406 +++++++++++ plugins/MirOTR/MirOTR/src/svcs_proto.h | 13 + plugins/MirOTR/MirOTR/src/svcs_srmm.cpp | 292 ++++++++ plugins/MirOTR/MirOTR/src/svcs_srmm.h | 7 + plugins/MirOTR/MirOTR/src/targetver.h | 21 + plugins/MirOTR/MirOTR/src/utils.cpp | 417 +++++++++++ plugins/MirOTR/MirOTR/src/utils.h | 49 ++ plugins/MirOTR/MirOTR/src/version.h | 37 + plugins/MirOTR/MirOTR/stdafx.cpp | 8 - plugins/MirOTR/MirOTR/stdafx.h | 87 --- plugins/MirOTR/MirOTR/striphtml.cpp | 127 ---- plugins/MirOTR/MirOTR/striphtml.h | 11 - plugins/MirOTR/MirOTR/svcs_menu.cpp | 211 ------ plugins/MirOTR/MirOTR/svcs_menu.h | 14 - plugins/MirOTR/MirOTR/svcs_proto.cpp | 406 ----------- plugins/MirOTR/MirOTR/svcs_proto.h | 13 - plugins/MirOTR/MirOTR/svcs_srmm.cpp | 292 -------- plugins/MirOTR/MirOTR/svcs_srmm.h | 7 - plugins/MirOTR/MirOTR/targetver.h | 21 - plugins/MirOTR/MirOTR/utils.cpp | 417 ----------- plugins/MirOTR/MirOTR/utils.h | 49 -- plugins/MirOTR/MirOTR/version.h | 37 - 82 files changed, 5758 insertions(+), 5758 deletions(-) delete mode 100644 plugins/MirOTR/MirOTR/dbfilter.cpp delete mode 100644 plugins/MirOTR/MirOTR/dbfilter.h delete mode 100644 plugins/MirOTR/MirOTR/dialogs.cpp delete mode 100644 plugins/MirOTR/MirOTR/dialogs.h delete mode 100644 plugins/MirOTR/MirOTR/dllmain.cpp delete mode 100644 plugins/MirOTR/MirOTR/dllmain.h delete mode 100644 plugins/MirOTR/MirOTR/entities.cpp delete mode 100644 plugins/MirOTR/MirOTR/entities.h delete mode 100644 plugins/MirOTR/MirOTR/icons.cpp delete mode 100644 plugins/MirOTR/MirOTR/icons.h delete mode 100644 plugins/MirOTR/MirOTR/language.h delete mode 100644 plugins/MirOTR/MirOTR/mirotrmenu.cpp delete mode 100644 plugins/MirOTR/MirOTR/mirotrmenu.h delete mode 100644 plugins/MirOTR/MirOTR/options.cpp delete mode 100644 plugins/MirOTR/MirOTR/options.h delete mode 100644 plugins/MirOTR/MirOTR/otr.cpp delete mode 100644 plugins/MirOTR/MirOTR/otr.h create mode 100644 plugins/MirOTR/MirOTR/res/finished.ico create mode 100644 plugins/MirOTR/MirOTR/res/insecure.ico create mode 100644 plugins/MirOTR/MirOTR/res/otr.ico create mode 100644 plugins/MirOTR/MirOTR/res/private.ico create mode 100644 plugins/MirOTR/MirOTR/res/refresh.ico create mode 100644 plugins/MirOTR/MirOTR/res/resource.rc create mode 100644 plugins/MirOTR/MirOTR/res/unverified.ico create mode 100644 plugins/MirOTR/MirOTR/res/version.rc delete mode 100644 plugins/MirOTR/MirOTR/resource.h delete mode 100644 plugins/MirOTR/MirOTR/resources/finished.ico delete mode 100644 plugins/MirOTR/MirOTR/resources/insecure.ico delete mode 100644 plugins/MirOTR/MirOTR/resources/otr.ico delete mode 100644 plugins/MirOTR/MirOTR/resources/private.ico delete mode 100644 plugins/MirOTR/MirOTR/resources/refresh.ico delete mode 100644 plugins/MirOTR/MirOTR/resources/resource.rc delete mode 100644 plugins/MirOTR/MirOTR/resources/unverified.ico delete mode 100644 plugins/MirOTR/MirOTR/resources/version.rc create mode 100644 plugins/MirOTR/MirOTR/src/dbfilter.cpp create mode 100644 plugins/MirOTR/MirOTR/src/dbfilter.h create mode 100644 plugins/MirOTR/MirOTR/src/dialogs.cpp create mode 100644 plugins/MirOTR/MirOTR/src/dialogs.h create mode 100644 plugins/MirOTR/MirOTR/src/dllmain.cpp create mode 100644 plugins/MirOTR/MirOTR/src/dllmain.h create mode 100644 plugins/MirOTR/MirOTR/src/entities.cpp create mode 100644 plugins/MirOTR/MirOTR/src/entities.h create mode 100644 plugins/MirOTR/MirOTR/src/icons.cpp create mode 100644 plugins/MirOTR/MirOTR/src/icons.h create mode 100644 plugins/MirOTR/MirOTR/src/language.h create mode 100644 plugins/MirOTR/MirOTR/src/mirotrmenu.cpp create mode 100644 plugins/MirOTR/MirOTR/src/mirotrmenu.h create mode 100644 plugins/MirOTR/MirOTR/src/options.cpp create mode 100644 plugins/MirOTR/MirOTR/src/options.h create mode 100644 plugins/MirOTR/MirOTR/src/otr.cpp create mode 100644 plugins/MirOTR/MirOTR/src/otr.h create mode 100644 plugins/MirOTR/MirOTR/src/resource.h create mode 100644 plugins/MirOTR/MirOTR/src/stdafx.cpp create mode 100644 plugins/MirOTR/MirOTR/src/stdafx.h create mode 100644 plugins/MirOTR/MirOTR/src/striphtml.cpp create mode 100644 plugins/MirOTR/MirOTR/src/striphtml.h create mode 100644 plugins/MirOTR/MirOTR/src/svcs_menu.cpp create mode 100644 plugins/MirOTR/MirOTR/src/svcs_menu.h create mode 100644 plugins/MirOTR/MirOTR/src/svcs_proto.cpp create mode 100644 plugins/MirOTR/MirOTR/src/svcs_proto.h create mode 100644 plugins/MirOTR/MirOTR/src/svcs_srmm.cpp create mode 100644 plugins/MirOTR/MirOTR/src/svcs_srmm.h create mode 100644 plugins/MirOTR/MirOTR/src/targetver.h create mode 100644 plugins/MirOTR/MirOTR/src/utils.cpp create mode 100644 plugins/MirOTR/MirOTR/src/utils.h create mode 100644 plugins/MirOTR/MirOTR/src/version.h delete mode 100644 plugins/MirOTR/MirOTR/stdafx.cpp delete mode 100644 plugins/MirOTR/MirOTR/stdafx.h delete mode 100644 plugins/MirOTR/MirOTR/striphtml.cpp delete mode 100644 plugins/MirOTR/MirOTR/striphtml.h delete mode 100644 plugins/MirOTR/MirOTR/svcs_menu.cpp delete mode 100644 plugins/MirOTR/MirOTR/svcs_menu.h delete mode 100644 plugins/MirOTR/MirOTR/svcs_proto.cpp delete mode 100644 plugins/MirOTR/MirOTR/svcs_proto.h delete mode 100644 plugins/MirOTR/MirOTR/svcs_srmm.cpp delete mode 100644 plugins/MirOTR/MirOTR/svcs_srmm.h delete mode 100644 plugins/MirOTR/MirOTR/targetver.h delete mode 100644 plugins/MirOTR/MirOTR/utils.cpp delete mode 100644 plugins/MirOTR/MirOTR/utils.h delete mode 100644 plugins/MirOTR/MirOTR/version.h diff --git a/plugins/MirOTR/MirOTR/MirOTR.vcxproj b/plugins/MirOTR/MirOTR/MirOTR.vcxproj index 7b11394cfd..a365292a94 100644 --- a/plugins/MirOTR/MirOTR/MirOTR.vcxproj +++ b/plugins/MirOTR/MirOTR/MirOTR.vcxproj @@ -194,46 +194,46 @@ - - - - - - - - - + + + + + + + + + Create - - - - - + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - + + diff --git a/plugins/MirOTR/MirOTR/MirOTR.vcxproj.filters b/plugins/MirOTR/MirOTR/MirOTR.vcxproj.filters index 278ee9f9a4..33f67678dc 100644 --- a/plugins/MirOTR/MirOTR/MirOTR.vcxproj.filters +++ b/plugins/MirOTR/MirOTR/MirOTR.vcxproj.filters @@ -15,110 +15,110 @@ - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Resource Files - + Resource Files diff --git a/plugins/MirOTR/MirOTR/dbfilter.cpp b/plugins/MirOTR/MirOTR/dbfilter.cpp deleted file mode 100644 index aab60e18e5..0000000000 --- a/plugins/MirOTR/MirOTR/dbfilter.cpp +++ /dev/null @@ -1,349 +0,0 @@ -#include "stdafx.h" -#include "dbfilter.h" -static HANDLE hDBEventPreAdd, hDBEventAdded, hContactSettingChanged; -static CRITICAL_SECTION RemoveChainCS={0}, *lpRemoveChainCS = &RemoveChainCS; -static UINT_PTR timerId = 0; - -struct DeleteEventNode { - DeleteEventNode *next; - time_t timestamp; - HANDLE hContact; - HANDLE hDbEvent; -}; -struct DeleteEventHead { - DeleteEventNode *first; - DeleteEventNode *last; -}; -static DeleteEventHead DeleteEvents = {0,0}; - -VOID CALLBACK DeleteTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) { - if (!DeleteEvents.first) return; - EnterCriticalSection(lpRemoveChainCS); - DeleteEventNode *prev =0, *current, *next; - DBEVENTINFO info = {0}; - info.cbSize = sizeof(info); - next = DeleteEvents.first; - while (current = next) { - if (difftime(time(0), current->timestamp) < 1) break; - if (!CallService(MS_DB_EVENT_GET, (WPARAM)current->hDbEvent, (LPARAM)&info)) // && info.flags&DBEF_READ) - { - CallService(MS_DB_EVENT_DELETE, (WPARAM)current->hContact, (LPARAM)current->hDbEvent); - next = current->next; - if (prev) prev->next = next; - else if (DeleteEvents.first == current) DeleteEvents.first = next; - delete current; - } else { - prev = current; - next = current->next; - } - } - if (!DeleteEvents.first) DeleteEvents.last = 0; - LeaveCriticalSection(lpRemoveChainCS); -} - - -// add prefix to sent messages -int OnDatabaseEventPreAdd(WPARAM wParam, LPARAM lParam) { - if (!options.prefix_messages || !lParam) return 0; - HANDLE hContact = (HANDLE)wParam; - DBEVENTINFO *dbei = (DBEVENTINFO *)lParam; - if ((dbei->eventType != EVENTTYPE_MESSAGE) || !(dbei->flags & DBEF_SENT) || (dbei->flags & DBEF_OTR_PREFIXED)) - return 0; - if(dbei->cbBlob == 0 || dbei->pBlob == 0) - return 0; // just to be safe - - const char *proto = contact_get_proto(hContact); - if (!proto ) return 0; - if (DBGetContactSettingByte(hContact, proto, "ChatRoom", 0) == 1) - return 0; - - if(g_metaproto && strcmp(proto, g_metaproto) == 0) { - hContact = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0); - if (!hContact) return 0; - proto = contact_get_proto(hContact); - if (!proto ) return 0; - } - - - ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact); - bool encrypted = otr_context_get_trust(context) != TRUST_NOT_PRIVATE; - if (!encrypted) return 0; - - DBEVENTINFO my_dbei = *dbei; // copy the other event - - char *msg = (char *)dbei->pBlob; - char *newmsg = 0; - DWORD alloclen = 0; - DWORD msglen = strlen(msg); - if (dbei->flags & DBEF_UTF) { - int prefixlen = strnlen(options.prefix, 64); - if (strncmp(msg, options.prefix, prefixlen) == 0) return 0; - alloclen = (msglen+prefixlen+1)*sizeof(char); - - // get additional data - DWORD len2 = alloclen- prefixlen*sizeof(char); - int datalen = dbei->cbBlob - len2; - if (datalen < 0) datalen = 0; - - newmsg = (char*)mir_alloc(alloclen); - memset(newmsg, 0, alloclen+datalen); - strncpy(newmsg, options.prefix, prefixlen); - strncat(newmsg, msg, msglen); - // append additional data - if (datalen) { - memcpy(newmsg+alloclen, msg+len2, datalen); - alloclen += datalen; - } - } else { - bool dz = false; - if(msglen < dbei->cbBlob) { - for(unsigned int i = msglen; i < dbei->cbBlob; i++) { - if(msg[i] == 0 && msg[i - 1] == 0) { - dz = true; - break; - } - } - } - if(dz) { - // yes, unicode - wchar_t* msgw = (wchar_t *)&msg[msglen]; - wchar_t *prefixw = mir_utf8decodeW(options.prefix); - int prefixlenw = wcslen(prefixw); - if (wcsncmp(msgw, prefixw, prefixlenw) == 0) { - mir_free(prefixw); - return 0; - } - int msglenw = wcslen(msgw); - - char *prefix = mir_utf8decodeA(options.prefix); - int prefixlen = strlen(prefix); - - alloclen = (msglen+prefixlen+1)* sizeof(char) + (msglenw + prefixlenw +1) * sizeof(wchar_t); - // get additional data - DWORD len2 = (msglen+1)* sizeof(char) + (msglenw+1) * sizeof(wchar_t); - int datalen = dbei->cbBlob - len2; - if (datalen < 0) datalen = 0; - - newmsg = (char*)mir_alloc(alloclen+datalen); - memset(newmsg, 0, alloclen+datalen); - strncpy(newmsg, prefix, prefixlen); - strncat(newmsg, msg, msglen); - wchar_t *p = (wchar_t*) newmsg + (msglen + prefixlen + 1) * sizeof(char); - wcsncpy(p, prefixw, prefixlenw); - wcsncat(p, msgw, msglenw); - mir_free(prefix); - mir_free(prefixw); - // append additional data - if (datalen) { - memcpy(newmsg+alloclen, msg+len2, datalen); - alloclen += datalen; - } - - } else { - char *prefix = mir_utf8decodeA(options.prefix); - int prefixlen = strlen(prefix); - if (strncmp(msg, prefix, prefixlen) == 0) { - mir_free(prefix); - return 0; - } - alloclen = msglen+prefixlen+sizeof(char); - // get additional data - DWORD len2 = alloclen-prefixlen; - int datalen = dbei->cbBlob - len2; - if (datalen < 0) datalen = 0; - - newmsg = (char*)mir_alloc(alloclen+datalen); - memset(newmsg, 0, alloclen+datalen); - strncpy(newmsg, prefix, prefixlen); - strncat(newmsg, msg, msglen); - mir_free(prefix); - // append additional data - if (datalen) { - memcpy(newmsg+alloclen, msg+len2, datalen); - alloclen += datalen; - } - } - - } - - my_dbei.pBlob = (BYTE *)newmsg; - my_dbei.cbBlob = alloclen; - my_dbei.flags |= DBEF_OTR_PREFIXED; - - CallService(MS_DB_EVENT_ADD, wParam, (LPARAM)&my_dbei); - if (newmsg) mir_free(newmsg); - - // stop original event from being added - return 1; -} - - int OnDatabaseEventAdded(WPARAM wParam, LPARAM lParam) { - if (!options.delete_history) return 0; - - DBEVENTINFO info = {0}; - info.cbSize = sizeof(info); - - static char* prefixutf = mir_utf8encodeT(TranslateT(LANG_INLINE_PREFIX)); - static char* prefix = Translate(LANG_INLINE_PREFIX); - static DWORD lenutf = strlen(prefixutf); - static DWORD len = strlen(prefix); - info.cbBlob = lenutf*2; - info.pBlob = (PBYTE)mir_alloc(info.cbBlob); - if (!CallService(MS_DB_EVENT_GET, (WPARAM)lParam, (LPARAM)&info)) { - if(info.eventType == EVENTTYPE_MESSAGE) { - HANDLE hContact = (HANDLE)wParam, hSub; - if(options.bHaveMetaContacts && (hSub = (HANDLE)CallService - (MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0)) != 0) { - hContact = hSub; - } - ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact); - if (context && otr_context_get_trust(context) != TRUST_NOT_PRIVATE ) { - // only delete encrypted messages that are no OTR system messages - if ( options.delete_systeminfo || - ((info.flags&DBEF_UTF && !(info.cbBlob >lenutf && 0==strncmp((char*)info.pBlob, prefixutf, lenutf))) - || (!(info.flags&DBEF_UTF) && !(info.cbBlob >len && 0==strncmp((char*)info.pBlob, prefix, len))) - ) - ) - { - DeleteEventNode *node = new DeleteEventNode(); - node->hContact = hContact; - node->hDbEvent = (HANDLE) lParam; - node->timestamp = time(0); - node->next = 0; - EnterCriticalSection(lpRemoveChainCS); - if (DeleteEvents.last) - DeleteEvents.last->next = node; - else - DeleteEvents.first = node; - DeleteEvents.last = node; - LeaveCriticalSection(lpRemoveChainCS); - } - } - } - } - mir_free(prefixutf); - mir_free(info.pBlob); - return 0; -} - -void FinishSession(HANDLE hContact) { - if (!hContact) return; - ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact); - TrustLevel level = otr_context_get_trust(context); - if (level == TRUST_UNVERIFIED || level == TRUST_PRIVATE) { - otrl_context_force_finished(context); - //SetEncryptionStatus(hContact, TRUST_FINISHED); - otr_gui_gone_insecure(context->app_data, context); - //otrl_message_disconnect(otr_user_state, &ops, hContact, context->accountname, context->protocol, context->username); - //SetEncryptionStatus(hContact, TRUST_NOT_PRIVATE); - } - return; -} - -int WindowEvent(WPARAM wParam, LPARAM lParam) { - MessageWindowEventData *mwd = (MessageWindowEventData *)lParam; - - if(mwd->uType == MSG_WINDOW_EVT_CLOSE && options.end_window_close) { - FinishSession(mwd->hContact); - return 0; - } - - if(mwd->uType != MSG_WINDOW_EVT_OPEN) return 0; - if (!options.bHaveSRMMIcons) return 0; - - HANDLE hContact = mwd->hContact, hTemp; - if(options.bHaveMetaContacts && (hTemp = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0)) != 0) - hContact = hTemp; - - if (!CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)MODULENAME)) - return 0; - - lib_cs_lock(); - ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact); - lib_cs_unlock(); - - SetEncryptionStatus(hContact, otr_context_get_trust(context)); - - return 0; -} - -// if it's a protocol going offline, attempt to send terminate session to all contacts of that protocol -// (this would be hooked as the ME_CLIST_STATUSMODECHANGE handler except that event is sent *after* the proto goes offline) -int StatusModeChange(WPARAM wParam, LPARAM lParam) { - int status = (int)wParam; - - if(status != ID_STATUS_OFFLINE ) return 0; - - const char *proto = (char *)lParam; - HANDLE hContact; - - lib_cs_lock(); - - ConnContext *context = otr_user_state->context_root; - while(context) { - if(context->msgstate == OTRL_MSGSTATE_ENCRYPTED && (proto == 0 || strcmp(proto, context->protocol) == 0)) { - hContact = context->app_data; - - if(hContact) { - otrl_message_disconnect(otr_user_state, &ops, hContact, context->accountname, context->protocol, context->username); - SetEncryptionStatus(hContact, TRUST_NOT_PRIVATE); - } - - } - context = context->next; - } - lib_cs_unlock(); - - return 0; -} - -int OnContactSettingChanged(WPARAM wParam, LPARAM lParam) { - DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *)lParam; - if (!lParam || strcmp(cws->szSetting, "Status") != 0) return 0; - HANDLE hContact = (HANDLE)wParam; - int status=0; - switch (cws->value.type){ - case DBVT_WORD: - status = cws->value.wVal; - break; - case DBVT_BYTE: - status = cws->value.bVal; - break; - case DBVT_DWORD: - status = cws->value.dVal; - break; - } - if (status == ID_STATUS_OFFLINE) { - if (!hContact) { - // Protocol is going offline - // Terminate sessions with all contacts of that proto - StatusModeChange((WPARAM) ID_STATUS_OFFLINE, (LPARAM)cws->szModule); - return 0; - }else if(CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)MODULENAME)) { - // only care about contacts to which this filter is attached - FinishSession(hContact); - } - } - - - return 0; -} - -void InitDBFilter() { - InitializeCriticalSectionAndSpinCount(lpRemoveChainCS, 500); - hDBEventPreAdd = HookEvent(ME_DB_EVENT_FILTER_ADD, OnDatabaseEventPreAdd); - hDBEventAdded = HookEvent(ME_DB_EVENT_ADDED, OnDatabaseEventAdded); - hContactSettingChanged = HookEvent(ME_DB_CONTACT_SETTINGCHANGED, OnContactSettingChanged); - timerId = SetTimer(0, 0, 1000, DeleteTimerProc); -} -void DeinitDBFilter() { - UnhookEvent(hDBEventPreAdd); - hDBEventPreAdd = 0; - UnhookEvent(hDBEventAdded); - hDBEventAdded = 0; - UnhookEvent(hContactSettingChanged); - hContactSettingChanged=0; - if (timerId) KillTimer(0, timerId); - DeleteTimerProc(0,0,0,0); - DeleteCriticalSection(lpRemoveChainCS); -} \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/dbfilter.h b/plugins/MirOTR/MirOTR/dbfilter.h deleted file mode 100644 index 99a6d50428..0000000000 --- a/plugins/MirOTR/MirOTR/dbfilter.h +++ /dev/null @@ -1,4 +0,0 @@ -#define DBEF_OTR_PREFIXED 0x8000 - -void InitDBFilter(); -void DeinitDBFilter(); \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/dialogs.cpp b/plugins/MirOTR/MirOTR/dialogs.cpp deleted file mode 100644 index 3335935282..0000000000 --- a/plugins/MirOTR/MirOTR/dialogs.cpp +++ /dev/null @@ -1,756 +0,0 @@ -#include "stdafx.h" -#include "dialogs.h" -#include -#include -#include - -struct SmpData { - HWND dialog; - TrustLevel oldlevel; - ConnContext *context; - bool responder; - TCHAR *question; -}; -typedef std::map SmpForContactMap; -SmpForContactMap smp_for_contact; - - -INT_PTR CALLBACK DlgSMPUpdateProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch ( msg ) { - case WM_INITDIALOG: - { - if (!lParam) { - EndDialog(hwndDlg, IDCANCEL); - return FALSE; - } - TranslateDialogDefault( hwndDlg ); - - SmpData *data = (SmpData*)lParam; - ConnContext *context = data->context; - data->dialog = hwndDlg; - //smp_for_contact.insert(SmpForContactMap::value_type(context->app_data, *data)); - if (smp_for_contact[context->app_data].dialog) SendMessage(smp_for_contact[context->app_data].dialog, WMU_REFRESHSMP, 0, 0); - smp_for_contact[context->app_data].context = data->context; - smp_for_contact[context->app_data].dialog = hwndDlg; - smp_for_contact[context->app_data].oldlevel = data->oldlevel; - smp_for_contact[context->app_data].responder = data->responder; - mir_free(data); - - TCHAR title[512], *proto = mir_a2t(contact_get_proto((HANDLE)context->app_data)); - const TCHAR *name =contact_get_nameT((HANDLE)context->app_data); - mir_sntprintf(title, 512, TranslateT(LANG_SMP_PROGRESS_TITLE), name, proto); - SendMessage(hwndDlg, WM_SETTEXT, 0, (LPARAM)title); - mir_sntprintf(title, 512, TranslateT(LANG_SMP_PROGRESS_DESC), name, proto); - mir_free(proto); - SetDlgItemText(hwndDlg, IDC_STC_SMP_HEADPRO, title); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)context); - - // Move window to screen center - // Get the owner window and dialog box rectangles. - HWND hwndOwner; RECT rcOwner, rcDlg, rc; - if ((hwndOwner = GetParent(hwndDlg)) == NULL) - { - hwndOwner = GetDesktopWindow(); - } - - GetWindowRect(hwndOwner, &rcOwner); - GetWindowRect(hwndDlg, &rcDlg); - CopyRect(&rc, &rcOwner); - - // Offset the owner and dialog box rectangles so that right and bottom - // values represent the width and height, and then offset the owner again - // to discard space taken up by the dialog box. - - OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); - OffsetRect(&rc, -rc.left, -rc.top); - OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); - - // The new position is the sum of half the remaining space and the owner's - // original position. - - SetWindowPos(hwndDlg, - HWND_TOP, - rcOwner.left + (rc.right / 2), - rcOwner.top + (rc.bottom / 2), - 0, 0, // Ignores size arguments. - SWP_NOSIZE); - - // end center dialog - - SendDlgItemMessage(hwndDlg, IDC_PGB_SMP, PBM_SETRANGE, 0, MAKELONG(0, 100)); - SendDlgItemMessage(hwndDlg, IDC_PGB_SMP, PBM_SETPOS, 10, 0); - - EnableWindow(GetDlgItem(hwndDlg, IDCANCEL), true); - EnableWindow(GetDlgItem(hwndDlg, IDOK), false); - - return TRUE; - } - - case WMU_REFRESHSMP: - { - ConnContext *context = (ConnContext*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - SendDlgItemMessage(hwndDlg, IDC_PGB_SMP, PBM_SETPOS, wParam, 0); - switch (wParam) { - case 0: - EnableWindow(GetDlgItem(hwndDlg, IDCANCEL), false); - EnableWindow(GetDlgItem(hwndDlg, IDOK), true); - SetDlgItemText(hwndDlg, IDC_STC_SMP_PROGRESS, TranslateT(LANG_SMP_ERROR)); - smp_for_contact.erase(context->app_data); - break; - case 100: - { - EnableWindow(GetDlgItem(hwndDlg, IDCANCEL), false); - EnableWindow(GetDlgItem(hwndDlg, IDOK), true); - smp_for_contact.erase(context->app_data); - if (context->smstate->sm_prog_state == OTRL_SMP_PROG_SUCCEEDED) { - if (context->active_fingerprint->trust && - context->active_fingerprint->trust[0]) { - SetDlgItemText(hwndDlg, IDC_STC_SMP_PROGRESS, TranslateT(LANG_SMP_SUCCESS)); - } else { - SetDlgItemText(hwndDlg, IDC_STC_SMP_PROGRESS, TranslateT(LANG_SMP_SUCCESS_VERIFY)); - } - } else { - SetDlgItemText(hwndDlg, IDC_STC_SMP_PROGRESS, TranslateT(LANG_SMP_FAILED)); - } - } - break; - default: - SetDlgItemText(hwndDlg, IDC_STC_SMP_PROGRESS, _T("")); - } - } - - case WM_COMMAND: - switch ( HIWORD( wParam )) { - case BN_CLICKED: - { - ConnContext *context = (ConnContext*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - switch ( LOWORD( wParam )) { - case IDCANCEL: - otr_abort_smp(context); - //break; - case IDOK: - smp_for_contact.erase(context->app_data); - EndDialog(hwndDlg, LOWORD( wParam )); - break; - } - }break; - } - - } - - return FALSE; -} - -void SMPInitUpdateDialog(ConnContext *context, bool responder) { - if (!context) return; - SmpData *data = (SmpData*)mir_calloc(sizeof(SmpData)); - data->context = context; - data->oldlevel = otr_context_get_trust(context); - data->responder = responder; - CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_SMP_PROGRESS), 0, DlgSMPUpdateProc, (LPARAM) data); -} - -INT_PTR CALLBACK DlgSMPResponseProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch ( msg ) { - case WM_INITDIALOG: - { - if (!lParam) { - EndDialog(hwndDlg, IDCANCEL); - return FALSE; - } - TranslateDialogDefault( hwndDlg ); - - SmpData *data = (SmpData*)lParam; - ConnContext *context = data->context; - data->dialog = hwndDlg; - //smp_for_contact.insert(SmpForContactMap::value_type(context->app_data, *data)); - if (smp_for_contact[context->app_data].dialog) SendMessage(smp_for_contact[context->app_data].dialog, WMU_REFRESHSMP, 0, 0); - smp_for_contact[context->app_data].context = data->context; - smp_for_contact[context->app_data].dialog = hwndDlg; - smp_for_contact[context->app_data].oldlevel = data->oldlevel; - smp_for_contact[context->app_data].responder = data->responder; - - TCHAR buff[512], *proto=mir_a2t(contact_get_proto(context->app_data)); - mir_sntprintf(buff, 512, TranslateT(LANG_SMP_VERIFY_TITLE), contact_get_nameT(context->app_data), proto); - mir_free(proto); - SendMessage(hwndDlg, WM_SETTEXT, 0, (LPARAM)buff); - SetDlgItemText(hwndDlg, IDC_STC_SMP_HEAD, buff); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)context); - - if (data->question) { - mir_sntprintf(buff, 512, TranslateT(LANG_OTR_SMPQUESTION_RESPOND_DESC), contact_get_nameT(context->app_data)); - - SetDlgItemText(hwndDlg, IDC_STC_SMP_INFO, buff); - - SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, data->question); - SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, TRUE, 0); - SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, TranslateT(LANG_SMP_QUESTION)); - - SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, _T("")); - SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, EM_SETREADONLY, FALSE, 0); - SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD2, TranslateT(LANG_SMP_ANSWER)); - - - ShowWindow(GetDlgItem(hwndDlg, IDOK), SW_SHOWNA); - ShowWindow(GetDlgItem(hwndDlg, IDYES), SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDNO), SW_HIDE); - - mir_free(data->question); - } else { - mir_sntprintf(buff, 512, TranslateT(LANG_OTR_SMPPASSWORD_RESPOND_DESC), contact_get_nameT((HANDLE)context->app_data)); - - SetDlgItemText(hwndDlg, IDC_STC_SMP_INFO, buff); - - SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, _T("")); - SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, TRUE, 0); - SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, _T("")); - - SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, _T("")); - SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, EM_SETREADONLY, FALSE, 0); - SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD2, TranslateT(LANG_SMP_PASSWORD)); - - - ShowWindow(GetDlgItem(hwndDlg, IDOK), SW_SHOWNA); - ShowWindow(GetDlgItem(hwndDlg, IDYES), SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDNO), SW_HIDE); - } - mir_free(data); - - // Move window to screen center - // Get the owner window and dialog box rectangles. - HWND hwndOwner; RECT rcOwner, rcDlg, rc; - if ((hwndOwner = GetParent(hwndDlg)) == NULL) - { - hwndOwner = GetDesktopWindow(); - } - - GetWindowRect(hwndOwner, &rcOwner); - GetWindowRect(hwndDlg, &rcDlg); - CopyRect(&rc, &rcOwner); - - // Offset the owner and dialog box rectangles so that right and bottom - // values represent the width and height, and then offset the owner again - // to discard space taken up by the dialog box. - - OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); - OffsetRect(&rc, -rc.left, -rc.top); - OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); - - // The new position is the sum of half the remaining space and the owner's - // original position. - - SetWindowPos(hwndDlg, - HWND_TOP, - rcOwner.left + (rc.right / 2), - rcOwner.top + (rc.bottom / 2), - 0, 0, // Ignores size arguments. - SWP_NOSIZE); - - // end center dialog - - - - return TRUE; - } - - case WM_COMMAND: - switch ( HIWORD( wParam )) { - case BN_CLICKED: - { - ConnContext *context = (ConnContext *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - switch ( LOWORD( wParam )) { - case IDOK: - { - SMPInitUpdateDialog(context, true); - - int len = SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, WM_GETTEXTLENGTH, 0, 0); - TCHAR *answer = new TCHAR[len+1]; - GetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, answer, len+1); - char *ans = mir_utf8encodeT(answer); - delete answer; - - otr_continue_smp(context, (const unsigned char *)ans, strlen(ans)); - mir_free(ans); - - EndDialog(hwndDlg, LOWORD( wParam )); - }break; - case IDCANCEL: - smp_for_contact.erase(context->app_data); - EndDialog(hwndDlg, LOWORD( wParam )); - break; - } - } - } - break; - - } - - return FALSE; -} - -/* -void SMPInitResponseDialog(ConnContext *context, const TCHAR *question) { - if (!context) return; - SmpData *data = (SmpData*)mir_calloc(sizeof(SmpData)); - data->context = context; - data->oldlevel = TRUST_NOT_PRIVATE; - data->responder = true; - data->question = (question) ? mir_tstrdup(question) : NULL; - CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_SMP_INPUT), 0, DlgSMPResponseProc, (LPARAM) data); -} -*/ - -INT_PTR CALLBACK DlgProcSMPInitProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch ( msg ) { - case WM_INITDIALOG: - { - if (!lParam) { - EndDialog(hwndDlg, IDCANCEL); - return FALSE; - } - TranslateDialogDefault( hwndDlg ); - - ConnContext *context = (ConnContext*)lParam; - if (smp_for_contact.find(context->app_data) != smp_for_contact.end()) { - EndDialog(hwndDlg, IDCANCEL); - return FALSE; - } - - TCHAR title[512], *proto = mir_a2t(contact_get_proto((HANDLE)context->app_data)); - mir_sntprintf(title, 512, TranslateT(LANG_SMP_VERIFY_TITLE), contact_get_nameT((HANDLE)context->app_data), proto); - mir_free(proto); - SendMessage(hwndDlg, WM_SETTEXT, 0, (LPARAM)title); - SetDlgItemText(hwndDlg, IDC_STC_SMP_HEAD, title); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); - - // Move window to screen center - // Get the owner window and dialog box rectangles. - HWND hwndOwner; RECT rcOwner, rcDlg, rc; - if ((hwndOwner = GetParent(hwndDlg)) == NULL) - { - hwndOwner = GetDesktopWindow(); - } - - GetWindowRect(hwndOwner, &rcOwner); - GetWindowRect(hwndDlg, &rcDlg); - CopyRect(&rc, &rcOwner); - - // Offset the owner and dialog box rectangles so that right and bottom - // values represent the width and height, and then offset the owner again - // to discard space taken up by the dialog box. - - OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); - OffsetRect(&rc, -rc.left, -rc.top); - OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); - - // The new position is the sum of half the remaining space and the owner's - // original position. - - SetWindowPos(hwndDlg, - HWND_TOP, - rcOwner.left + (rc.right / 2), - rcOwner.top + (rc.bottom / 2), - 0, 0, // Ignores size arguments. - SWP_NOSIZE); - - // end center dialog - - - HWND cmb = GetDlgItem(hwndDlg, IDC_CBO_SMP_CHOOSE); - SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_SMPTYPE_QUESTION)); - SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_SMPTYPE_PASSWORD)); - SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_SMPTYPE_FINGERPRINT)); - SendMessage(cmb, CB_SELECTSTRING, -1, (WPARAM)TranslateT(LANG_SMPTYPE_QUESTION)); - EnableWindow(GetDlgItem(hwndDlg, IDC_CBO_SMP_CHOOSE), TRUE); - - - Fingerprint *fp = context->active_fingerprint; - if (!fp) { - EndDialog(hwndDlg, IDCANCEL); - return FALSE; - } - TCHAR buff[1024]; - if (!fp->trust || fp->trust[0] == '\0') - mir_sntprintf(buff, 512, TranslateT(LANG_OTR_SMPQUESTION_VERIFY_DESC), contact_get_nameT((HANDLE)context->app_data)); - else - mir_sntprintf(buff, 512, TranslateT(LANG_OTR_SMPQUESTION_VERIFIED_DESC), contact_get_nameT((HANDLE)context->app_data)); - - SetDlgItemText(hwndDlg, IDC_STC_SMP_INFO, buff); - - SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, _T("")); - SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, FALSE, 0); - SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, TranslateT(LANG_SMP_QUESTION)); - - SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, _T("")); - SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, EM_SETREADONLY, FALSE, 0); - SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD2, TranslateT(LANG_SMP_ANSWER)); - - - ShowWindow(GetDlgItem(hwndDlg, IDOK), SW_SHOWNA); - ShowWindow(GetDlgItem(hwndDlg, IDYES), SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDNO), SW_HIDE); - SetFocus(GetDlgItem(hwndDlg, IDC_CBO_SMP_CHOOSE)); - - return FALSE; - } - - case WM_COMMAND: - switch ( HIWORD( wParam )) { - case BN_CLICKED: - { - ConnContext* context = (ConnContext*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - TCHAR msg[1024]; - switch ( LOWORD( wParam )) { - case IDCANCEL: - EndDialog(hwndDlg, LOWORD( wParam )); - break; - case IDOK: - GetDlgItemText(hwndDlg, IDC_CBO_SMP_CHOOSE, msg, 255); - if (_tcsncmp(msg, TranslateT(LANG_SMPTYPE_QUESTION), 255)==0) { - if (smp_for_contact.find(context->app_data) != smp_for_contact.end()) { - TCHAR msg[512]; - mir_sntprintf(msg, 512, TranslateT(LANG_SMP_IN_PROGRESS), contact_get_nameT((HANDLE)context->app_data)); - ShowError(msg); - }else { - int len = SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, WM_GETTEXTLENGTH, 0, 0); - TCHAR *question = new TCHAR[len+1]; - GetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, question, len+1); - char *quest = mir_utf8encodeT(question); - delete question; - - len = SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, WM_GETTEXTLENGTH, 0, 0); - TCHAR *answer = new TCHAR[len+1]; - GetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, answer, len+1); - char *ans = mir_utf8encodeT(answer); - delete answer; - - SMPInitUpdateDialog(context, false); - otr_start_smp(context, quest, (const unsigned char*)ans, strlen(ans)); - mir_free(quest); - mir_free(ans); - } - - }else if (_tcsncmp(msg, TranslateT(LANG_SMPTYPE_PASSWORD), 255)==0) { - if (smp_for_contact.find(context->app_data) != smp_for_contact.end()) { - TCHAR msg[512]; - mir_sntprintf(msg, 512, TranslateT(LANG_SMP_IN_PROGRESS), contact_get_nameT((HANDLE)context->app_data)); - ShowError(msg); - }else { - int len = SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, WM_GETTEXTLENGTH, 0, 0); - TCHAR *answer = new TCHAR[len+1]; - GetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, answer, len+1); - char *ans = mir_utf8encodeT(answer); - delete answer; - - SMPInitUpdateDialog(context, false); - otr_start_smp(context, NULL, (const unsigned char*)ans, strlen(ans)); - mir_free(ans); - } - - }else break; - EndDialog(hwndDlg, LOWORD( wParam )); - break; - case IDYES: - VerifyFingerprint(context, true); - EndDialog(hwndDlg, LOWORD( wParam )); - break; - case IDNO: - VerifyFingerprint(context, false); - EndDialog(hwndDlg, LOWORD( wParam )); - break; - } - } - break; - case CBN_SELCHANGE: - switch ( LOWORD( wParam )) { - case IDC_CBO_SMP_CHOOSE: - { - ConnContext* context = (ConnContext*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - Fingerprint *fp = context->active_fingerprint; - if (!fp) { - EndDialog(hwndDlg, IDCANCEL); - return TRUE; - } - BOOL trusted = false; - if (fp->trust && fp->trust[0] != '\0') trusted = true; - - TCHAR buff[512]; - GetDlgItemText(hwndDlg, IDC_CBO_SMP_CHOOSE, buff, 255); - if (_tcsncmp(buff, TranslateT(LANG_SMPTYPE_QUESTION), 255)==0) { - if (trusted) - mir_sntprintf(buff, 512, TranslateT(LANG_OTR_SMPQUESTION_VERIFIED_DESC), contact_get_nameT((HANDLE)context->app_data)); - else - mir_sntprintf(buff, 512, TranslateT(LANG_OTR_SMPQUESTION_VERIFY_DESC), contact_get_nameT((HANDLE)context->app_data)); - - SetDlgItemText(hwndDlg, IDC_STC_SMP_INFO, buff); - - SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, _T("")); - SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, FALSE, 0); - SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, TranslateT(LANG_SMP_QUESTION)); - - SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, _T("")); - SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, EM_SETREADONLY, FALSE, 0); - SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD2, TranslateT(LANG_SMP_ANSWER)); - - - ShowWindow(GetDlgItem(hwndDlg, IDOK), SW_SHOWNA); - ShowWindow(GetDlgItem(hwndDlg, IDYES), SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDNO), SW_HIDE); - } else if (_tcsncmp(buff, TranslateT(LANG_SMPTYPE_PASSWORD), 255)==0) { - if (trusted) - mir_sntprintf(buff, 512, TranslateT(LANG_OTR_SMPPASSWORD_VERIFIED_DESC), contact_get_nameT((HANDLE)context->app_data)); - else - mir_sntprintf(buff, 512, TranslateT(LANG_OTR_SMPPASSWORD_VERIFY_DESC), contact_get_nameT((HANDLE)context->app_data)); - - SetDlgItemText(hwndDlg, IDC_STC_SMP_INFO, buff); - - SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, _T("")); - SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, TRUE, 0); - SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, _T("")); - - SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, _T("")); - SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, EM_SETREADONLY, FALSE, 0); - SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD2, TranslateT(LANG_SMP_PASSWORD)); - - - ShowWindow(GetDlgItem(hwndDlg, IDOK), SW_SHOWNA); - ShowWindow(GetDlgItem(hwndDlg, IDYES), SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDNO), SW_HIDE); - } else if (_tcsncmp(buff, TranslateT(LANG_SMPTYPE_FINGERPRINT), 255)==0) { - if (trusted) - mir_sntprintf(buff, 512, TranslateT(LANG_OTR_FPVERIFIED_DESC), contact_get_nameT((HANDLE)context->app_data)); - else - mir_sntprintf(buff, 512, TranslateT(LANG_OTR_FPVERIFY_DESC), contact_get_nameT((HANDLE)context->app_data)); - - SetDlgItemText(hwndDlg, IDC_STC_SMP_INFO, buff); - - unsigned char hash[20]; - lib_cs_lock(); - if (!otrl_privkey_fingerprint_raw(otr_user_state, hash, context->accountname, context->protocol)) { - lib_cs_unlock(); - EndDialog(hwndDlg, IDCANCEL); - return FALSE; - } - otrl_privkey_hash_to_humanT(buff, hash); - lib_cs_unlock(); - SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, buff); - SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, TRUE, 0); - SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, TranslateT(LANG_YOUR_PRIVKEY)); - - otrl_privkey_hash_to_humanT(buff, fp->fingerprint); - SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, buff); - SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, EM_SETREADONLY, TRUE, 0); - SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD2, TranslateT(LANG_CONTACT_FINGERPRINT)); - - ShowWindow(GetDlgItem(hwndDlg, IDOK), SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDYES), SW_SHOWNA); - ShowWindow(GetDlgItem(hwndDlg, IDNO), SW_SHOWNA); - - } - }break; - } - } - break; - - } - - return FALSE; -} -void SMPInitDialog(ConnContext* context) { - if (!context) return; - CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_SMP_INPUT), 0, DlgProcSMPInitProc, (LPARAM) context); -} - -void SMPDialogUpdate(ConnContext *context, int percent) { - if (!context) return; - SmpForContactMap::iterator it = smp_for_contact.find(context->app_data); - if (it == smp_for_contact.end()) return; - if (it->second.dialog) PostMessage(it->second.dialog, WMU_REFRESHSMP, percent, 0); - TrustLevel level = otr_context_get_trust(context); - if (!it->second.responder && it->second.oldlevel != level) { - if (level == TRUST_PRIVATE) - VerifyFingerprintMessage(context, true); - else if (level == TRUST_UNVERIFIED) - VerifyFingerprintMessage(context, false); - } - //if (percent == 100) - /* - switch (percent){ - case 0: - VerifyFingerprint(context, false); - ShowWarning(_T("SMP failed")); - break; - case 100: - VerifyFingerprint(context, true); - ShowWarning(_T("SMP successful")); - break; - default: - ShowWarning(_T("Received an SMP update")); - } - */ -} -void SMPDialogReply(ConnContext *context, const char* question){ - SmpData *data = (SmpData*)mir_calloc(sizeof(SmpData)); - data->context = context; - data->oldlevel = TRUST_NOT_PRIVATE; - data->responder = true; - data->question = (question) ? mir_utf8decodeT(question) : NULL; - CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_SMP_INPUT), 0, DlgSMPResponseProc, (LPARAM) data); - /* - ShowError(_T("SMP requires user password (NOT IMPL YET)")); - otr_abort_smp(context); - */ - //otr_continue_smp(context, pass, strlen(pass)); -} - -unsigned int CALLBACK verify_context_thread(void *param); -void VerifyContextDialog(ConnContext* context) { - if (!context) return; - CloseHandle((HANDLE)_beginthreadex(0, 0, verify_context_thread, context, 0, 0)); -} - -INT_PTR CALLBACK DlgProcVerifyContext(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch ( msg ) { - case WM_INITDIALOG: - { - if (!lParam) { - EndDialog(hwndDlg, IDCANCEL); - return FALSE; - } - SendMessage(hwndDlg, WM_SETTEXT, 0, (LPARAM)_T(LANG_OTR_FPVERIFY_TITLE)); - SetDlgItemText(hwndDlg, IDC_STC_SMP_HEAD, _T(LANG_OTR_FPVERIFY_TITLE)); - TranslateDialogDefault( hwndDlg ); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); - - // Move window to screen center - // Get the owner window and dialog box rectangles. - HWND hwndOwner; RECT rcOwner, rcDlg, rc; - if ((hwndOwner = GetParent(hwndDlg)) == NULL) - { - hwndOwner = GetDesktopWindow(); - } - - GetWindowRect(hwndOwner, &rcOwner); - GetWindowRect(hwndDlg, &rcDlg); - CopyRect(&rc, &rcOwner); - - // Offset the owner and dialog box rectangles so that right and bottom - // values represent the width and height, and then offset the owner again - // to discard space taken up by the dialog box. - - OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); - OffsetRect(&rc, -rc.left, -rc.top); - OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); - - // The new position is the sum of half the remaining space and the owner's - // original position. - - SetWindowPos(hwndDlg, - HWND_TOP, - rcOwner.left + (rc.right / 2), - rcOwner.top + (rc.bottom / 2), - 0, 0, // Ignores size arguments. - SWP_NOSIZE); - - // end center dialog - - ConnContext *context = (ConnContext*)lParam; - Fingerprint *fp = context->active_fingerprint; - if (!fp) { - EndDialog(hwndDlg, IDCANCEL); - return FALSE; - } - TCHAR buff[512]; - if (!fp->trust || fp->trust[0] == '\0') - mir_sntprintf(buff, 512, TranslateT(LANG_OTR_FPVERIFY_DESC), contact_get_nameT((HANDLE)context->app_data)); - else - mir_sntprintf(buff, 512, TranslateT(LANG_OTR_FPVERIFIED_DESC), contact_get_nameT((HANDLE)context->app_data)); - - SetDlgItemText(hwndDlg, IDC_STC_SMP_INFO, buff); - - unsigned char hash[20]; - lib_cs_lock(); - if (!otrl_privkey_fingerprint_raw(otr_user_state, hash, context->accountname, context->protocol)) { - lib_cs_unlock(); - EndDialog(hwndDlg, IDCANCEL); - return FALSE; - } - otrl_privkey_hash_to_humanT(buff, hash); - lib_cs_unlock(); - SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, buff); - SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, TRUE, 0); - SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, TranslateT(LANG_YOUR_PRIVKEY)); - - otrl_privkey_hash_to_humanT(buff, fp->fingerprint); - SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, buff); - SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, EM_SETREADONLY, TRUE, 0); - SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD2, TranslateT(LANG_CONTACT_FINGERPRINT)); - - EnableWindow(GetDlgItem(hwndDlg, IDC_CBO_SMP_CHOOSE), FALSE); - - ShowWindow(GetDlgItem(hwndDlg, IDOK), SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDYES), SW_SHOWNA); - ShowWindow(GetDlgItem(hwndDlg, IDNO), SW_SHOWNA); - SetFocus(GetDlgItem(hwndDlg, IDCANCEL)); - - return FALSE; - } - - case WM_COMMAND: - switch ( HIWORD( wParam )) { - case BN_CLICKED: - switch ( LOWORD( wParam )) { - case IDYES: - case IDNO: - case IDCANCEL: - case IDOK: - EndDialog(hwndDlg, LOWORD( wParam )); - break; - } - } - break; - - } - - return FALSE; -} - -unsigned int CALLBACK verify_context_thread(void *param) -{ - Thread_Push( 0 ); - - if (param) { - ConnContext *context = (ConnContext *)param; - TCHAR msg[1024]; - switch ( DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SMP_INPUT), 0, DlgProcVerifyContext, (LPARAM)param) ) { - case IDOK: - case IDYES: - lib_cs_lock(); - otrl_context_set_trust(context->active_fingerprint, "verified"); - otrl_privkey_write_fingerprints(otr_user_state, g_fingerprint_store_filename); - lib_cs_unlock(); - mir_sntprintf(msg, 1024, TranslateT(LANG_FINGERPRINT_VERIFIED), contact_get_nameT((HANDLE)context->app_data)); - msg[1023] = '\0'; - ShowMessage((HANDLE)context->app_data, msg); - SetEncryptionStatus(context->app_data, otr_context_get_trust(context)); - break; - case IDNO: - lib_cs_lock(); - otrl_context_set_trust(context->active_fingerprint, NULL); - otrl_privkey_write_fingerprints(otr_user_state, g_fingerprint_store_filename); - lib_cs_unlock(); - mir_sntprintf(msg, 1024, TranslateT(LANG_FINGERPRINT_NOT_VERIFIED), contact_get_nameT((HANDLE)context->app_data)); - msg[1023] = '\0'; - ShowMessage((HANDLE)context->app_data, msg); - SetEncryptionStatus(context->app_data, otr_context_get_trust(context)); - break; - } - } - - Thread_Pop(); - return 0; -} \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/dialogs.h b/plugins/MirOTR/MirOTR/dialogs.h deleted file mode 100644 index 0422dc3095..0000000000 --- a/plugins/MirOTR/MirOTR/dialogs.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once -void VerifyContextDialog(ConnContext* context); -void SMPInitDialog(ConnContext* context); -INT_PTR CALLBACK DlgProcVerifyContext(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); -void SMPDialogUpdate(ConnContext *context, int percent); -void SMPDialogReply(ConnContext *context, const char* question); - -#define WMU_REFRESHSMP (WM_USER + 245) \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/dllmain.cpp b/plugins/MirOTR/MirOTR/dllmain.cpp deleted file mode 100644 index 80833c9b2e..0000000000 --- a/plugins/MirOTR/MirOTR/dllmain.cpp +++ /dev/null @@ -1,153 +0,0 @@ -// dllmain.cpp : Definiert den Einstiegspunkt für die DLL-Anwendung. -#include "stdafx.h" -#include "dllmain.h" -#include "otr.h" -#include "dbfilter.h" -#include - -HANDLE hEventWindow; -HINSTANCE hInst; - -int hLangpack; -char* g_metaproto; - - -PLUGININFOEX pluginInfo={ - sizeof(PLUGININFOEX), - SHORT_NAME_STRING, - PLUGIN_MAKE_VERSION(VER_MAJOR,VER_MINOR,VER_RELEASE,VER_BUILD), - LONGDESC_STRING, - AUTHOR, - AUTHOR_MAIL, - LEGAL_COPYRIGHT_LONG, - HOMEPAGE, - UNICODE_AWARE, - MIID_OTRPLUGIN // ANSI and Unicode have different IDs -}; - -BOOL APIENTRY DllMain( HMODULE hModule, - DWORD ul_reason_for_call, - LPVOID lpReserved - ) -{ - if (ul_reason_for_call == DLL_PROCESS_ATTACH) { - hInst=hModule; - OTRL_INIT; - INITCOMMONCONTROLSEX icce = {0}; - icce.dwSize = sizeof(icce); - icce.dwICC = ICC_LISTVIEW_CLASSES|ICC_PROGRESS_CLASS; - InitCommonControlsEx(&icce); - } - return TRUE; -} - -DLLFUNC PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) -{ - return &pluginInfo; -} - -int ModulesLoaded(WPARAM wParam, LPARAM lParam) { - if(ServiceExists(MS_MC_GETPROTOCOLNAME)) - g_metaproto = (char *)CallService(MS_MC_GETPROTOCOLNAME, 0, 0); - - InitUtils(); - - lib_cs_lock(); - otr_user_state = otrl_userstate_create(); - lib_cs_unlock(); - - // this calls ReadPrivkeyFiles (above) to set filename values (also called on ME_FOLDERS_PATH_CHANGED) - InitOptions(); - - InitDBFilter(); - InitIcons(); - InitMenu(); - - InitSRMM(); - - hEventWindow = HookEvent(ME_MSG_WINDOWEVENT, WindowEvent); - - if (options.bHaveSecureIM && !db_get_b(0, MODULENAME, "sim_warned", 0)) { - db_set_b(0, MODULENAME, "sim_warned", 1); - options.default_policy = OTRL_POLICY_MANUAL_MOD; - SaveOptions(); - MessageBox(0, TranslateT(LANG_OTR_SECUREIM_TEXT), TranslateT(LANG_OTR_SECUREIM_TITLE), 0x30); - } - if (!options.bHaveSRMMIcons) { - MessageBox(0, _T("OTR Info"), _T("Your SRMM plugin does not support status icons. Not all OTR-functions are available!"), 0x30); - } - - // HookEvent(ME_OPT_INITIALISE, OptInit); - - // hook setting changed to monitor status - //hSettingChanged = HookEvent(ME_DB_CONTACT_SETTINGCHANGED, SettingChanged); - - // hook status mode changes to terminate sessions when we go offline - // (this would be hooked as the ME_CLIST_STATUSMODECHANGE handler except that event is sent *after* the proto goes offline) - // (instead, it's called from the SettingChanged handler for protocol status db setting changes) - //HookEvent(ME_CLIST_STATUSMODECHANGE, StatusModeChange); - - return 0; -} - -DLLFUNC int Load(void) -{ - DEBUGOUT_T("LOAD MIROTR") - - mir_getLP( &pluginInfo ); - /* for timezones - mir_getTMI(&tmi); */ - - CallService(MS_DB_SETSETTINGRESIDENT, TRUE, (LPARAM)(MODULENAME "/TrustLevel")); - - ///////////// - ////// init plugin - PROTOCOLDESCRIPTOR pd = {0}; - pd.cbSize = sizeof(pd); - pd.szName = MODULENAME; - pd.type = PROTOTYPE_ENCRYPTION; - CallService(MS_PROTO_REGISTERMODULE,0,(LPARAM)&pd); - - // remove us as a filter to all contacts - fix filter type problem - if(DBGetContactSettingByte(0, MODULENAME, "FilterOrderFix", 0) != 2) { - HANDLE hContact = db_find_first(); - while ( hContact != NULL ) { - CallService( MS_PROTO_REMOVEFROMCONTACT, ( WPARAM )hContact, ( LPARAM )MODULENAME ); - hContact = db_find_next(hContact); - } - DBWriteContactSettingByte(0, MODULENAME, "FilterOrderFix", 2); - } - - // create our services - CreateProtoServiceFunction(MODULENAME, PSS_MESSAGE, SVC_OTRSendMessage); - CreateProtoServiceFunction(MODULENAME, PSS_MESSAGE"W", SVC_OTRSendMessageW); - CreateProtoServiceFunction(MODULENAME, PSR_MESSAGE, SVC_OTRRecvMessage); - - - // hook modules loaded for updater support - HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded); - - return 0; -} - -DLLFUNC int Unload(void) -{ - //UnhookEvent(hSettingChanged); - UnhookEvent(hEventWindow); - //UnhookEvent(hEventDbEventAddedFilter); - //UnhookEvent(hEventDbEventAdded); - DEBUGOUT_T("UNLOAD MIROTR") - DeinitSRMM(); - DeinitOptions(); - DeinitMenu(); - DeinitDBFilter(); - - lib_cs_lock(); - otrl_userstate_free(otr_user_state); - lib_cs_unlock(); - - DeinitIcons(); - DeinitUtils(); - - return 0; -} \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/dllmain.h b/plugins/MirOTR/MirOTR/dllmain.h deleted file mode 100644 index b2346859f6..0000000000 --- a/plugins/MirOTR/MirOTR/dllmain.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include "stdafx.h" -#include "version.h" - -#define DLLFUNC extern "C" __declspec(dllexport) - -extern HINSTANCE hInst; diff --git a/plugins/MirOTR/MirOTR/entities.cpp b/plugins/MirOTR/MirOTR/entities.cpp deleted file mode 100644 index ae2335bc01..0000000000 --- a/plugins/MirOTR/MirOTR/entities.cpp +++ /dev/null @@ -1,430 +0,0 @@ -// (C) of entities.cpp: Christoph -// http://mercurial.intuxication.org/hg/cstuff/raw-file/tip/entities.c -// http://stackoverflow.com/questions/1082162/how-to-unescape-html-in-c/1082191#1082191 -// modified by ProgAndy - -#include "stdafx.h" -#include "entities.h" - -#include -#include -#include -using namespace std; - -#define UNICODE_MAX 0x10FFFFul - - -static const char *named_entities[][2] = -{ - { "AElig;", "Æ" }, - { "Aacute;", "Ã" }, - { "Acirc;", "Â" }, - { "Agrave;", "À" }, - { "Alpha;", "Α" }, - { "Aring;", "Ã…" }, - { "Atilde;", "Ã" }, - { "Auml;", "Ä" }, - { "Beta;", "Î’" }, - { "Ccedil;", "Ç" }, - { "Chi;", "Χ" }, - { "Dagger;", "‡" }, - { "Delta;", "Δ" }, - { "ETH;", "Ã" }, - { "Eacute;", "É" }, - { "Ecirc;", "Ê" }, - { "Egrave;", "È" }, - { "Epsilon;", "Ε" }, - { "Eta;", "Η" }, - { "Euml;", "Ë" }, - { "Gamma;", "Γ" }, - { "Iacute;", "Ã" }, - { "Icirc;", "ÃŽ" }, - { "Igrave;", "ÃŒ" }, - { "Iota;", "Ι" }, - { "Iuml;", "Ã" }, - { "Kappa;", "Κ" }, - { "Lambda;", "Λ" }, - { "Mu;", "Îœ" }, - { "Ntilde;", "Ñ" }, - { "Nu;", "Î" }, - { "OElig;", "Å’" }, - { "Oacute;", "Ó" }, - { "Ocirc;", "Ô" }, - { "Ograve;", "Ã’" }, - { "Omega;", "Ω" }, - { "Omicron;", "Ο" }, - { "Oslash;", "Ø" }, - { "Otilde;", "Õ" }, - { "Ouml;", "Ö" }, - { "Phi;", "Φ" }, - { "Pi;", "Π" }, - { "Prime;", "″" }, - { "Psi;", "Ψ" }, - { "Rho;", "Ρ" }, - { "Scaron;", "Å " }, - { "Sigma;", "Σ" }, - { "THORN;", "Þ" }, - { "Tau;", "Τ" }, - { "Theta;", "Θ" }, - { "Uacute;", "Ú" }, - { "Ucirc;", "Û" }, - { "Ugrave;", "Ù" }, - { "Upsilon;", "Î¥" }, - { "Uuml;", "Ãœ" }, - { "Xi;", "Ξ" }, - { "Yacute;", "Ã" }, - { "Yuml;", "Ÿ" }, - { "Zeta;", "Ζ" }, - { "aacute;", "á" }, - { "acirc;", "â" }, - { "acute;", "´" }, - { "aelig;", "æ" }, - { "agrave;", "à" }, - { "alefsym;", "ℵ" }, - { "alpha;", "α" }, - { "amp;", "&" }, - { "and;", "∧" }, - { "ang;", "∠" }, - { "apos;", "'" }, - { "aring;", "Ã¥" }, - { "asymp;", "≈" }, - { "atilde;", "ã" }, - { "auml;", "ä" }, - { "bdquo;", "„" }, - { "beta;", "β" }, - { "brvbar;", "¦" }, - { "bull;", "•" }, - { "cap;", "∩" }, - { "ccedil;", "ç" }, - { "cedil;", "¸" }, - { "cent;", "¢" }, - { "chi;", "χ" }, - { "circ;", "ˆ" }, - { "clubs;", "♣" }, - { "cong;", "≅" }, - { "copy;", "©" }, - { "crarr;", "↵" }, - { "cup;", "∪" }, - { "curren;", "¤" }, - { "dArr;", "⇓" }, - { "dagger;", "†" }, - { "darr;", "↓" }, - { "deg;", "°" }, - { "delta;", "δ" }, - { "diams;", "♦" }, - { "divide;", "÷" }, - { "eacute;", "é" }, - { "ecirc;", "ê" }, - { "egrave;", "è" }, - { "empty;", "∅" }, - { "emsp;", " " }, - { "ensp;", " " }, - { "epsilon;", "ε" }, - { "equiv;", "≡" }, - { "eta;", "η" }, - { "eth;", "ð" }, - { "euml;", "ë" }, - { "euro;", "€" }, - { "exist;", "∃" }, - { "fnof;", "Æ’" }, - { "forall;", "∀" }, - { "frac12;", "½" }, - { "frac14;", "¼" }, - { "frac34;", "¾" }, - { "frasl;", "â„" }, - { "gamma;", "γ" }, - { "ge;", "≥" }, - { "gt;", ">" }, - { "hArr;", "⇔" }, - { "harr;", "↔" }, - { "hearts;", "♥" }, - { "hellip;", "…" }, - { "iacute;", "í" }, - { "icirc;", "î" }, - { "iexcl;", "¡" }, - { "igrave;", "ì" }, - { "image;", "â„‘" }, - { "infin;", "∞" }, - { "int;", "∫" }, - { "iota;", "ι" }, - { "iquest;", "¿" }, - { "isin;", "∈" }, - { "iuml;", "ï" }, - { "kappa;", "κ" }, - { "lArr;", "â‡" }, - { "lambda;", "λ" }, - { "lang;", "〈" }, - { "laquo;", "«" }, - { "larr;", "â†" }, - { "lceil;", "⌈" }, - { "ldquo;", "“" }, - { "le;", "≤" }, - { "lfloor;", "⌊" }, - { "lowast;", "∗" }, - { "loz;", "â—Š" }, - { "lrm;", "\xE2\x80\x8E" }, - { "lsaquo;", "‹" }, - { "lsquo;", "‘" }, - { "lt;", "<" }, - { "macr;", "¯" }, - { "mdash;", "—" }, - { "micro;", "µ" }, - { "middot;", "·" }, - { "minus;", "−" }, - { "mu;", "μ" }, - { "nabla;", "∇" }, - { "nbsp;", " " }, - { "ndash;", "–" }, - { "ne;", "≠" }, - { "ni;", "∋" }, - { "not;", "¬" }, - { "notin;", "∉" }, - { "nsub;", "⊄" }, - { "ntilde;", "ñ" }, - { "nu;", "ν" }, - { "oacute;", "ó" }, - { "ocirc;", "ô" }, - { "oelig;", "Å“" }, - { "ograve;", "ò" }, - { "oline;", "‾" }, - { "omega;", "ω" }, - { "omicron;", "ο" }, - { "oplus;", "⊕" }, - { "or;", "∨" }, - { "ordf;", "ª" }, - { "ordm;", "º" }, - { "oslash;", "ø" }, - { "otilde;", "õ" }, - { "otimes;", "⊗" }, - { "ouml;", "ö" }, - { "para;", "¶" }, - { "part;", "∂" }, - { "permil;", "‰" }, - { "perp;", "⊥" }, - { "phi;", "φ" }, - { "pi;", "Ï€" }, - { "piv;", "Ï–" }, - { "plusmn;", "±" }, - { "pound;", "£" }, - { "prime;", "′" }, - { "prod;", "âˆ" }, - { "prop;", "âˆ" }, - { "psi;", "ψ" }, - { "quot;", "\"" }, - { "rArr;", "⇒" }, - { "radic;", "√" }, - { "rang;", "〉" }, - { "raquo;", "»" }, - { "rarr;", "→" }, - { "rceil;", "⌉" }, - { "rdquo;", "â€" }, - { "real;", "â„œ" }, - { "reg;", "®" }, - { "rfloor;", "⌋" }, - { "rho;", "Ï" }, - { "rlm;", "\xE2\x80\x8F" }, - { "rsaquo;", "›" }, - { "rsquo;", "’" }, - { "sbquo;", "‚" }, - { "scaron;", "Å¡" }, - { "sdot;", "â‹…" }, - { "sect;", "§" }, - { "shy;", "\xC2\xAD" }, - { "sigma;", "σ" }, - { "sigmaf;", "Ï‚" }, - { "sim;", "∼" }, - { "spades;", "â™ " }, - { "sub;", "⊂" }, - { "sube;", "⊆" }, - { "sum;", "∑" }, - { "sup;", "⊃" }, - { "sup1;", "¹" }, - { "sup2;", "²" }, - { "sup3;", "³" }, - { "supe;", "⊇" }, - { "szlig;", "ß" }, - { "tau;", "Ï„" }, - { "there4;", "∴" }, - { "theta;", "θ" }, - { "thetasym;", "Ï‘" }, - { "thinsp;", " " }, - { "thorn;", "þ" }, - { "tilde;", "Ëœ" }, - { "times;", "×" }, - { "trade;", "â„¢" }, - { "uArr;", "⇑" }, - { "uacute;", "ú" }, - { "uarr;", "↑" }, - { "ucirc;", "û" }, - { "ugrave;", "ù" }, - { "uml;", "¨" }, - { "upsih;", "Ï’" }, - { "upsilon;", "Ï…" }, - { "uuml;", "ü" }, - { "weierp;", "℘" }, - { "xi;", "ξ" }, - { "yacute;", "ý" }, - { "yen;", "Â¥" }, - { "yuml;", "ÿ" }, - { "zeta;", "ζ" }, - { "zwj;", "\xE2\x80\x8D" }, - { "zwnj;", "\xE2\x80\x8C" } -}; - -static int cmp(const void *key, const void *element) -{ - return strncmp((const char *)key, *(const char **)element, - strlen(*(const char **)element)); -} - -static const char *get_named_entity(const char *name) -{ - const char **entity = (const char **)bsearch(name, named_entities, - sizeof(named_entities) / sizeof(*named_entities), - sizeof(*named_entities), cmp); - - return entity ? entity[1] : NULL; -} - -static size_t putc_utf8(unsigned long cp, char *buffer) -{ - unsigned char *bytes = (unsigned char *)buffer; - - if(cp <= 0x007Ful) - { - bytes[0] = (unsigned char)cp; - return 1; - } - - if(cp <= 0x07FFul) - { - bytes[1] = (unsigned char)((2u << 6) | (cp & 0x3Fu)); - bytes[0] = (unsigned char)((6u << 5) | (cp >> 6)); - return 2; - } - - if(cp <= 0xFFFFul) - { - bytes[2] = (unsigned char)(( 2u << 6) | ( cp & 0x3Fu)); - bytes[1] = (unsigned char)(( 2u << 6) | ((cp >> 6) & 0x3Fu)); - bytes[0] = (unsigned char)((14u << 4) | (cp >> 12)); - return 3; - } - - if(cp <= 0x10FFFFul) - { - bytes[3] = (unsigned char)(( 2u << 6) | ( cp & 0x3Fu)); - bytes[2] = (unsigned char)(( 2u << 6) | ((cp >> 6) & 0x3Fu)); - bytes[1] = (unsigned char)(( 2u << 6) | ((cp >> 12) & 0x3Fu)); - bytes[0] = (unsigned char)((30u << 3) | (cp >> 18)); - return 4; - } - - return 0; -} - -static _Bool parse_entity(const char *current, char **to, - const char **from, size_t maxlen) -{ - const char *end = (const char *)memchr(current, ';', maxlen); - if (!end) return 0; - - if(current[1] == '#') - { - char *tail = NULL; - errno = 0; - - _Bool hex = current[2] == 'x' || current[2] == 'X'; - - unsigned long cp = strtoul( - current + (hex ? 3 : 2), &tail, hex ? 16 : 10); - - if(tail == end && !errno && cp <= UNICODE_MAX) - { - *to += putc_utf8(cp, *to); - *from = end + 1; - - return 1; - } - } - else - { - const char *entity = get_named_entity(¤t[1]); - if(entity) - { - size_t len = strlen(entity); - memcpy(*to, entity, len); - - *to += len; - *from = end + 1; - - return 1; - } - } - - return 0; -} - -size_t decode_html_entities_utf8(char *dest, const char *src, size_t len) -{ - if (!src) src = dest; - - char *to = dest; - const char *from = src; - - const char *current; - if (!len) len = strlen(src); - size_t remain = len; - while((current = (const char*)memchr(from, '&', len-(from-src)))) - { - memcpy(to, from, (size_t)(current - from)); - to += current - from; - //remain = len-(current-src); - - if(parse_entity(current, &to, &from, len-(current-src))) - continue; - - from = current; - *to++ = *from++; - } - - remain = strnlen(from, len-(from-src)); - - memcpy(to, from, remain); - to += remain; - - if (src!=dest || (size_t)(to-dest) < len ) *to = 0; - return (size_t)(to - dest); -} - -char * encode_html_entities_utf8(const char *src) { - const char *pos, *start=src; - std::string buf; - if (! (pos = strpbrk(start, "&<>\"\r")) ) return NULL; - while (pos) { - buf.append(start, pos-start); - start = pos+1; - switch (*pos) { - case '"': - buf.append("""); - break; - case '<': - buf.append("<"); - break; - case '>': - buf.append(">"); - break; - case '&': - buf.append("&"); - break; - case '\r': - buf.append("
\r"); - break; - } - pos = strpbrk(start, "&<>\"\r"); - } - if (strlen(start)) buf.append(start); - pos = mir_strdup(buf.c_str()); - buf.clear(); - return (char*)pos; -} \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/entities.h b/plugins/MirOTR/MirOTR/entities.h deleted file mode 100644 index e4121dc5da..0000000000 --- a/plugins/MirOTR/MirOTR/entities.h +++ /dev/null @@ -1,26 +0,0 @@ -// (C) of entities.h: Christoph -// http://mercurial.intuxication.org/hg/cstuff/raw-file/tip/entities.h -// http://stackoverflow.com/questions/1082162/how-to-unescape-html-in-c/1082191#1082191 -// modified by ProgAndy - -#ifndef DECODE_HTML_ENTITIES_UTF8 -#define DECODE_HTML_ENTITIES_UTF8 - -#include - -extern size_t decode_html_entities_utf8(char *dest, const char *src, size_t len); -/* if `src` is `NULL`, input will be taken from `dest`, decoding - the entities in-place - - otherwise, the output will be placed in `dest`, which should point - to a buffer big enough to hold `strlen(src) + 1` characters, while - `src` remains unchanged - if `len` is given, `dest` must be at least big enough - to hold `len + 1` characters. - - the function returns the length of the decoded string -*/ - -extern char * encode_html_entities_utf8(const char *src); - -#endif diff --git a/plugins/MirOTR/MirOTR/icons.cpp b/plugins/MirOTR/MirOTR/icons.cpp deleted file mode 100644 index c9dd1a10db..0000000000 --- a/plugins/MirOTR/MirOTR/icons.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "stdafx.h" -#include "icons.h" -TCHAR g_dllpath[1024]; - -struct -{ - const TCHAR* stzDescr; - const char* szName; - int defIconID; -} -static iconList[] = { - { _T(LANG_ICON_OTR), ICON_OTR, IDI_OTR }, - { _T(LANG_ICON_PRIVATE), ICON_PRIVATE, IDI_PRIVATE }, - { _T(LANG_ICON_UNVERIFIED), ICON_UNVERIFIED, IDI_UNVERIFIED }, - { _T(LANG_ICON_FINISHED), ICON_FINISHED, IDI_FINISHED }, - { _T(LANG_ICON_NOT_PRIVATE), ICON_NOT_PRIVATE, IDI_INSECURE } - -}; - -HANDLE hIconLibItem[SIZEOF(iconList)]; - -void InitIcons() { - TCHAR szFile[MAX_PATH+500]; - - GetModuleFileName(hInst, szFile, SIZEOF(szFile)); - - SKINICONDESC sid = {0}; - sid.cbSize = sizeof(SKINICONDESC); - sid.ptszDefaultFile = szFile; - sid.ptszSection = _T(MODULENAME); - sid.flags = SIDF_ALL_TCHAR; - - for ( int i = 0; i < SIZEOF(iconList); i++ ) { - sid.pszName = (char*)iconList[i].szName; - sid.ptszDescription = (TCHAR*)iconList[i].stzDescr; - sid.iDefaultIndex = -iconList[i].defIconID; - hIconLibItem[i] = Skin_AddIcon(&sid); - } - -} - -void DeinitIcons() { - for ( int i = 0; i < SIZEOF(iconList); i++ ) { - (HANDLE)CallService(MS_SKIN2_REMOVEICON, 0, (LPARAM)iconList[i].szName); - hIconLibItem[i] = NULL; - } -} - -HICON LoadIcon(const char* name, int big) { - return ( HICON )CallService( MS_SKIN2_GETICON, big, (LPARAM)name ); -} - -HANDLE GetIconHandle(const char* name) { - return ( HANDLE )CallService( MS_SKIN2_GETICONHANDLE, 0, (LPARAM)name ); -} - -void ReleaseIcon(const char* name, int big) { - CallService( big ? MS_SKIN2_RELEASEICONBIG : MS_SKIN2_RELEASEICON, 0, (LPARAM)name ); -} -void ReleaseIcon(HICON handle, int big) { - CallService( big ? MS_SKIN2_RELEASEICONBIG : MS_SKIN2_RELEASEICON, (WPARAM)handle, 0 ); -} diff --git a/plugins/MirOTR/MirOTR/icons.h b/plugins/MirOTR/MirOTR/icons.h deleted file mode 100644 index 0983cc147c..0000000000 --- a/plugins/MirOTR/MirOTR/icons.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#define ICON_FINISHED (MODULENAME"_finished") -#define ICON_UNVERIFIED (MODULENAME"_unverified") -#define ICON_PRIVATE (MODULENAME"_private") -#define ICON_NOT_PRIVATE (MODULENAME"_not_private") -#define ICON_OTR (MODULENAME"_otr") - -void InitIcons(); -void DeinitIcons(); -HICON LoadIcon(const char* name, int big); -HANDLE GetIconHandle(const char* name); -void ReleaseIcon(const char* name, int big); -void ReleaseIcon(HICON handle, int big); \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/language.h b/plugins/MirOTR/MirOTR/language.h deleted file mode 100644 index 8934405608..0000000000 --- a/plugins/MirOTR/MirOTR/language.h +++ /dev/null @@ -1,122 +0,0 @@ -#pragma once - -#include "m_langpack.h" - -#define LANG_START_OTR LPGEN("Start OTR") -#define LANG_STOP_OTR LPGEN("Stop OTR") - -#define LANG_YES LPGEN("Yes") -#define LANG_NO LPGEN("No") - -#define LANG_OTR_TOOLTIP LPGEN("OTR status (Click for more options)") -#define LANG_STATUS_DISABLED LPGEN("OTR Encryption: Disabled") -#define LANG_STATUS_UNVERIFIED LPGEN("OTR Encryption: UNVERIFIED") -#define LANG_STATUS_PRIVATE LPGEN("OTR Encryption: Private") -#define LANG_STATUS_FINISHED LPGEN("OTR Encryption: Finished") - -#define LANG_MENU_START LPGEN("&Start OTR session") -#define LANG_MENU_REFRESH LPGEN("&Refresh OTR session") -#define LANG_MENU_STOP LPGEN("Sto&p OTR session") -#define LANG_MENU_VERIFY LPGEN("&Verify Fingerprint") -#define LANG_MENU_TOGGLEHTML LPGEN("&Convert HTML (for Pidgin)") - -#define LANG_SESSION_TERMINATED_OTR LPGEN("OTR encrypted session with '%s' has been terminated") -#define LANG_SESSION_REQUEST_OTR LPGEN("Requesting OTR encrypted session with '%s'") -#define LANG_SESSION_START_OTR LPGEN("Beginning OTR encrypted session with '%s'") -#define LANG_SESSION_START_OTR_VERIFY LPGEN("Beginning OTR encrypted session with '%s' (NOT VERIFIED)") -#define LANG_SESSION_TRY_CONTINUE_OTR LPGEN("Trying to refresh OTR encrypted session with '%s'") -#define LANG_SESSION_HAS_CONTINUE_OTR LPGEN("OTR encrypted session was refreshed by '%s'") -#define LANG_SESSION_HAS_CONTINUE_OTR_VERIFY LPGEN("OTR encrypted session was refreshed by '%s' (NOT VERIFIED)") -#define LANG_SESSION_REQUEST_CONTINUE_OTR LPGEN("OTR encrypted session with '%s' sucessfully refreshed") -#define LANG_SESSION_CONTINUE_OTR LPGEN("OTR encrypted session with '%s' sucessfully refreshed") -#define LANG_SESSION_CONTINUE_OTR_VERIFY LPGEN("OTR encrypted session with '%s' sucessfully refreshed (NOT VERIFIED)") -#define LANG_SESSION_TERMINATED_BY_OTR LPGEN("OTR encrypted session has been terminated by '%s'. You should do that, too!") -#define LANG_SESSION_NOT_STARTED_OTR LPGEN("OTR encrypted session with '%s' could not be started") - -#define LANG_ENCRYPTION_ERROR LPGEN("OTR could not encrypt when sending message") - -#define LANG_OTR_INFO LPGEN("OTR Information") -#define LANG_INLINE_PREFIX LPGEN("[OTR INFO] ") - -#define LANG_SMP_AUTH_FROM LPGEN("Authentication from %s") -#define LANG_SMP_AUTH LPGEN("Authenticae %s") - -#define LANG_UNKNOWN LPGEN("Unknown") -#define LANG_OTR_USERMESSAGE LPGEN("OTR: %s (%s)") -#define LANG_OTR_NOTIFY LPGEN("OTR %s (%s)") - -//#define LANG_FINGERPRINT_CAPTION LPGEN("OTR New Fingerprint") -//#define LANG_FINGERPRINT_ASK_VERIFY LPGEN("OTR encrypted session with '%s'.\n\nFingerprint is UNVERIFIED.\n\n%s\n\nVerify?") -//#define LANG_FINGERPRINT_ASK_NEW LPGEN("A new fingerprint has been recieved from '%s'\n\n%s\n\nDo you trust it?") -#define LANG_FINGERPRINT_VERIFIED LPGEN("OTR encrypted session with '%s' is now using a VERIFIED fingerprint") -#define LANG_FINGERPRINT_NOT_VERIFIED LPGEN("OTR encrypted session with '%s' is now using a NOT VERIFIED fingerprint") - -#define LANG_ICON_UNVERIFIED LPGEN("OTR unverified") -#define LANG_ICON_FINISHED LPGEN("OTR finished") -#define LANG_ICON_PRIVATE LPGEN("OTR private") -#define LANG_ICON_NOT_PRIVATE LPGEN("OTR not secure") -#define LANG_ICON_OTR LPGEN("OTR") - -#define LANG_GENERATE_KEY LPGEN("Generating new private key for protocol '%s'.\nPlease Wait...") - -#define LANG_OPT_GENERAL LPGEN("General") -#define LANG_OPT_PROTO LPGEN("Protocols") -#define LANG_OPT_CONTACTS LPGEN("Contacts") -#define LANG_OPT_FINGER LPGEN("Fingerprints") - -#define LANG_CONTACT LPGEN("Contact") -#define LANG_PROTO LPGEN("Protocol") -#define LANG_POLICY LPGEN("Policy") -#define LANG_VERIFIED LPGEN("Verified") -#define LANG_ACTIVE LPGEN("Active") -#define LANG_FINGERPRINT LPGEN("Fingerprint") -#define LANG_HTMLCONV LPGEN("Conv. HTML") - -#define LANG_POLICY_DEFAULT LPGEN("Default") -#define LANG_POLICY_ALWAYS LPGEN("Always") -#define LANG_POLICY_OPP LPGEN("Opportunistic") -#define LANG_POLICY_MANUAL LPGEN("Manual") -#define LANG_POLICY_NEVER LPGEN("Never") - -#define LANG_OTR_ASK_NEWKEY LPGEN("Generating new key for '%s'. Continue?") -#define LANG_OTR_ASK_REMOVEKEY LPGEN("Removing key for '%s'. Continue?") - -#define LANG_OTR_FPVERIFY_TITLE LPGEN("OTR Fingerprint Verification") -#define LANG_OTR_FPVERIFY_DESC LPGEN("OTR encrypted session with '%s'.\nThe OTR fingerprint used by your contact is NOT VERIFIED.\nDo you trust it?") -#define LANG_OTR_FPVERIFIED_DESC LPGEN("OTR encrypted session with '%s'.\nThe OTR fingerprint used by your contact is already verified.\nDo you still trust it?") -#define LANG_YOUR_PRIVKEY LPGEN("Your Fingerprint to tell your contact (use a trusted channel!)") -#define LANG_CONTACT_FINGERPRINT LPGEN("VERIFY: Fingerprint from contact") - -#define LANG_SMP_VERIFY_TITLE LPGEN("OTR Authenticate: %s (%s)") -#define LANG_SMPTYPE_QUESTION LPGEN("Challenge Question") -#define LANG_SMPTYPE_PASSWORD LPGEN("Known Password") -#define LANG_SMPTYPE_FINGERPRINT LPGEN("Manual fingerprint comparison") -#define LANG_SMP_ANSWER LPGEN("Secret Answer") -#define LANG_SMP_QUESTION LPGEN("Question") -#define LANG_SMP_PASSWORD LPGEN("Password") - -#define LANG_SMP_SUCCESS LPGEN("Authentication sucessful.") -#define LANG_SMP_SUCCESS_VERIFY LPGEN("You contact authenticated you sucessful. You can send your own request to authenticate him.") -#define LANG_SMP_ERROR LPGEN("Error during authentication.") -#define LANG_SMP_FAILED LPGEN("Authentication failed") -#define LANG_SMP_IN_PROGRESS LPGEN("Authentication for '%s' is already in progress.") - -#define LANG_SMP_PROGRESS_TITLE LPGEN("OTR Authenticating: %s (%s)") -#define LANG_SMP_PROGRESS_DESC LPGEN("Authenticating contact:\n%s (%s)") - -#define LANG_OTR_SMPQUESTION_VERIFY_DESC LPGEN("OTR encrypted session with '%s' (UNVERIFIED).\nUse a question only your partner can answer.") -#define LANG_OTR_SMPQUESTION_VERIFIED_DESC LPGEN("OTR encrypted session with '%s' (VERIFIED).\nVerify the session again using a question only your partner can answer.") - -#define LANG_OTR_SMPPASSWORD_VERIFY_DESC LPGEN("OTR encrypted session with '%s' (UNVERIFIED).\nUse a known password.") -#define LANG_OTR_SMPPASSWORD_VERIFIED_DESC LPGEN("OTR encrypted session with '%s' (VERIFIED).\nVerify the session again using a known password.") - -#define LANG_OTR_SMPQUESTION_RESPOND_DESC LPGEN("Your contact '%s' wants to verify your identity with a question only you can answer.") - -#define LANG_OTR_SMPPASSWORD_RESPOND_DESC LPGEN("Your contact '%s' wants to verify your identity with a secret password you should know.") - -#define LANG_FINGERPRINT_STILL_IN_USE LPGEN("Fingerprint '%s' still in use in conversation with '%s' (%s). You cannot delete it!") -#define LANG_FINGERPRINT_NOT_DELETED LPGEN("Fingerprint '%s' in use in conversation with '%s' (%s). It could not be deleted!") - -#define LANG_OTR_SECUREIM_STARTED LPGEN("Cannot start OTR for '%s'. SecureIM is already running") -#define LANG_OTR_SECUREIM_TITLE LPGEN("OTR: SecureIM installed") -#define LANG_OTR_SECUREIM_TEXT LPGEN("You are using SecureIM. MirOTR will only work for contacts with SecureIM disabled") \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/mirotrmenu.cpp b/plugins/MirOTR/MirOTR/mirotrmenu.cpp deleted file mode 100644 index 07a874c425..0000000000 --- a/plugins/MirOTR/MirOTR/mirotrmenu.cpp +++ /dev/null @@ -1,294 +0,0 @@ -#include "stdafx.h" -#include "m_genmenu.h" -#include "mirotrmenu.h" -static HANDLE hMirOTRMenuObject; -static HGENMENU hStatusInfoItem, hHTMLConvMenuItem; -HWND hDummyPaintWin; - -//contactmenu exec param(ownerdata) -//also used in checkservice -typedef struct -{ - char *szServiceName; -} -MirOTRMenuExecParam,*lpMirOTRMenuExecParam; - -//////////////////////////////////////////// -// MirOTR MENU -/////////////////////////////////////////// -static INT_PTR RemoveMirOTRMenuItem(WPARAM wParam, LPARAM) -{ - CallService(MO_REMOVEMENUITEM,wParam,0); - return 0; -} - -static INT_PTR AddMirOTRMenuItem(WPARAM, LPARAM lParam) -{ - MIROTRMENUITEM *mi=(MIROTRMENUITEM*)lParam; - if ( mi->cbSize != sizeof( MIROTRMENUITEM )) - return 0; - - TMO_MenuItem tmi = { 0 }; - tmi.cbSize = sizeof(tmi); - tmi.flags = mi->flags; - tmi.hIcon = mi->hIcon; - tmi.hIcolibItem = mi->icolibItem; - tmi.hotKey = mi->hotKey; - tmi.position = mi->position; - tmi.ptszName = mi->ptszName; - tmi.root = mi->root; - - //owner data - lpMirOTRMenuExecParam cmep = ( lpMirOTRMenuExecParam )mir_calloc(sizeof(MirOTRMenuExecParam)); - cmep->szServiceName = mir_strdup( mi->pszService ); - tmi.ownerdata = cmep; - - INT_PTR menuHandle = CallService(MO_ADDNEWMENUITEM, (WPARAM) hMirOTRMenuObject, (LPARAM)&tmi ); - - return menuHandle; -} - -static INT_PTR BuildMirOTRMenu(WPARAM wParam, LPARAM) -{ - HANDLE hContact = ( HANDLE )wParam; - //NotifyEventHooks(hPreBuildMirOTRMenuEvent,(WPARAM)hMirOTR,0); - - - ListParam param = { 0 }; - param.MenuObjectHandle = hMirOTRMenuObject; - param.wParam = (WPARAM)hContact; - HMENU hMenu = CreatePopupMenu(); - CallService(MO_BUILDMENU,(WPARAM)hMenu,(LPARAM)¶m); - - return (INT_PTR)hMenu; -} - -//called with: -//wparam - ownerdata -//lparam - lparam from winproc -INT_PTR MirOTRMenuExecService(WPARAM wParam,LPARAM lParam) -{ - if (wParam!=0) { - lpMirOTRMenuExecParam cmep=(lpMirOTRMenuExecParam)wParam; - //call with wParam=(WPARAM)(HANDLE)hContact - CallService(cmep->szServiceName,lParam,0); - } - return 0; -} - -//true - ok,false ignore -INT_PTR MirOTRMenuCheckService(WPARAM wParam,LPARAM) -{ - PCheckProcParam pcpp = ( PCheckProcParam )wParam; - lpMirOTRMenuExecParam cmep=NULL; - TMO_MenuItem mi; - - if ( pcpp == NULL ) - return FALSE; - - cmep = ( lpMirOTRMenuExecParam )pcpp->MenuItemOwnerData; - if ( cmep == NULL ) //this is rootsection...build it - return TRUE; - - HANDLE hContact = (HANDLE)pcpp->wParam, hSub; - if(options.bHaveMetaContacts && (hSub = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0)) != 0) { - hContact = hSub; - } - - TrustLevel level = ( TrustLevel )otr_context_get_trust(otrl_context_find_miranda(otr_user_state, hContact)); - - mi.cbSize = sizeof(mi); - if ( CallService(MO_GETMENUITEM, ( WPARAM )pcpp->MenuItemHandle, ( LPARAM )&mi ) == 0 ) { - - if ( mi.flags & CMIF_HIDDEN ) return FALSE; - if ( mi.flags & CMIF_NOTPRIVATE && level==TRUST_PRIVATE ) return FALSE; - if ( mi.flags & CMIF_NOTFINISHED && level==TRUST_FINISHED ) return FALSE; - if ( mi.flags & CMIF_NOTUNVERIFIED && level==TRUST_UNVERIFIED ) return FALSE; - if ( mi.flags & CMIF_NOTNOTPRIVATE && level==TRUST_NOT_PRIVATE ) return FALSE; - - if (pcpp->MenuItemHandle == hStatusInfoItem) { - mi.flags = CMIM_NAME | CMIM_ICON | CMIF_ICONFROMICOLIB | CMIF_TCHAR; - switch (level) { - case TRUST_PRIVATE: - mi.hIcolibItem = GetIconHandle(ICON_PRIVATE); - mi.ptszName = TranslateT(LANG_STATUS_PRIVATE); - break; - case TRUST_UNVERIFIED: - mi.hIcolibItem = GetIconHandle(ICON_UNVERIFIED); - mi.ptszName = TranslateT(LANG_STATUS_UNVERIFIED); - break; - case TRUST_FINISHED: - mi.hIcolibItem = GetIconHandle(ICON_FINISHED); - mi.ptszName = TranslateT(LANG_STATUS_FINISHED); - break; - default: - mi.hIcolibItem = GetIconHandle(ICON_NOT_PRIVATE); - mi.ptszName = TranslateT(LANG_STATUS_DISABLED); - } - CallService(MO_MODIFYMENUITEM, (WPARAM)hStatusInfoItem, (LPARAM)&mi); - } else if (pcpp->MenuItemHandle == hHTMLConvMenuItem) { - if (db_get_b(hContact, MODULENAME, "HTMLConv", 0) ) - mi.flags |= CMIM_FLAGS|CMIF_CHECKED; - else - mi.flags = CMIM_FLAGS|(mi.flags &~CMIF_CHECKED); - CallService(MO_MODIFYMENUITEM, (WPARAM)hHTMLConvMenuItem, (LPARAM)&mi); - } - } - return TRUE; -} - -INT_PTR FreeOwnerDataMirOTRMenu (WPARAM, LPARAM lParam) -{ - lpMirOTRMenuExecParam cmep = ( lpMirOTRMenuExecParam )lParam; - if ( cmep != NULL ) { - if (cmep->szServiceName) mir_free(cmep->szServiceName); - mir_free(cmep); - } - return 0; -} - -INT_PTR OnAddMenuItemMirOTRMenu (WPARAM wParam, LPARAM lParam) -{ - - MENUITEMINFO *mii = (MENUITEMINFO*)wParam; - if (!mii || mii->cbSize != sizeof(MENUITEMINFO)) return 0; - - TMO_MenuItem mi; - mi.cbSize = sizeof(mi); - if ( CallService(MO_GETMENUITEM, ( WPARAM )lParam, ( LPARAM )&mi ) == 0 ) { - if (mi.flags & CMIF_DISABLED) { - mii->fMask |= MIIM_STATE; - mii->fState |= MF_DISABLED; - } - } - return 1; -} - - -LRESULT CALLBACK PopupMenuWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - switch (message) - { - case WM_MEASUREITEM: - if (CallService(MS_CLIST_MENUMEASUREITEM, wParam, lParam)) return TRUE; - break; - case WM_DRAWITEM: - if (CallService(MS_CLIST_MENUDRAWITEM, wParam, lParam)) return TRUE; - break; - case WM_COMMAND: - if (CallService(MO_PROCESSCOMMANDBYMENUIDENT, wParam, GetWindowLongPtr(hwnd, GWLP_USERDATA))) return TRUE; - break; - } - return DefWindowProc(hwnd, message, wParam, lParam); -} - -void ShowOTRMenu(HANDLE hContact, POINT pt){ - HMENU menu = (HMENU) CallService(MS_MIROTR_MENUBUILDMIROTR, (WPARAM)hContact, 0); - SetWindowLongPtr(hDummyPaintWin, GWLP_USERDATA, (LONG_PTR)hContact); - TrackPopupMenu(menu, 0, pt.x, pt.y, 0, hDummyPaintWin, 0); - DestroyMenu(menu); -} - -void InitMirOTRMenu(void) -{ - - WNDCLASS wc = {0}; - wc.hInstance = hInst; - wc.lpfnWndProc = PopupMenuWndProc; - wc.lpszClassName = _T("MirOTRPopUpMenuProcessor"); - RegisterClass(&wc); - hDummyPaintWin = CreateWindowEx(0, _T("MirOTRPopUpMenuProcessor"), NULL, 0, 0, 0, 1, 1, 0, 0, hInst, 0); - - CreateServiceFunction("MirOTRMenuExecService",MirOTRMenuExecService); - CreateServiceFunction("MirOTRMenuCheckService",MirOTRMenuCheckService); - - //free services - CreateServiceFunction("MIROTRMENUS/FreeOwnerDataMirOTRMenu",FreeOwnerDataMirOTRMenu); - CreateServiceFunction("MIROTRMENUS/OnAddMenuItemMirOTRMenu",OnAddMenuItemMirOTRMenu); - - - CreateServiceFunction(MS_MIROTR_ADDMIROTRMENUITEM,AddMirOTRMenuItem); - CreateServiceFunction(MS_MIROTR_MENUBUILDMIROTR,BuildMirOTRMenu); - CreateServiceFunction(MS_MIROTR_REMOVEMIROTRMENUITEM,RemoveMirOTRMenuItem); - - //hPreBuildMirOTRMenuEvent=CreateHookableEvent(ME_CLIST_PREBUILDMirOTRMENU); - - //MirOTR menu - { - TMenuParam tmp = { 0 }; - tmp.cbSize=sizeof(tmp); - tmp.CheckService="MirOTRMenuCheckService"; - tmp.ExecService="MirOTRMenuExecService"; - tmp.name="MirOTRMenu"; - hMirOTRMenuObject=(HANDLE)CallService(MO_CREATENEWMENUOBJECT,(WPARAM)0,(LPARAM)&tmp); - } - - OptParam params; - params.Handle = hMirOTRMenuObject; - params.Setting = OPT_USERDEFINEDITEMS; - params.Value = FALSE; - CallService(MO_SETOPTIONSMENUOBJECT, 0, (LPARAM)¶ms); - - params.Setting = OPT_MENUOBJECT_SET_FREE_SERVICE; - params.Value = (INT_PTR)"MIROTRMENUS/FreeOwnerDataMirOTRMenu"; - CallService(MO_SETOPTIONSMENUOBJECT, 0, (LPARAM)¶ms); - - params.Setting = OPT_MENUOBJECT_SET_ONADD_SERVICE; - params.Value = (INT_PTR)"MIROTRMENUS/OnAddMenuItemMirOTRMenu"; - CallService(MO_SETOPTIONSMENUOBJECT, 0, (LPARAM)¶ms); - - - MIROTRMENUITEM mi = {0}; - mi.cbSize = sizeof(mi); - - mi.flags = CMIF_DISABLED|CMIF_TCHAR|CMIF_ICONFROMICOLIB; - mi.ptszName = _T("OTR Status"); - mi.position = 0; - hStatusInfoItem = (HGENMENU) AddMirOTRMenuItem(0, (LPARAM) &mi); - - mi.flags = CMIF_TCHAR|CMIF_ICONFROMICOLIB|CMIF_NOTPRIVATE|CMIF_NOTUNVERIFIED; - mi.ptszName = _T(LANG_MENU_START); - mi.position = 100001; - mi.pszService = MS_OTR_MENUSTART; - mi.icolibItem = GetIconHandle(ICON_UNVERIFIED); - AddMirOTRMenuItem(0, (LPARAM) &mi); - - mi.flags = CMIF_TCHAR|CMIF_ICONFROMICOLIB|CMIF_NOTNOTPRIVATE|CMIF_NOTFINISHED; - mi.ptszName = _T(LANG_MENU_REFRESH); - mi.position = 100002; - mi.pszService = MS_OTR_MENUREFRESH; - mi.icolibItem = GetIconHandle(ICON_FINISHED); - AddMirOTRMenuItem(0, (LPARAM) &mi); - - mi.flags = CMIF_TCHAR|CMIF_ICONFROMICOLIB|CMIF_NOTNOTPRIVATE; - mi.ptszName = _T(LANG_MENU_STOP); - mi.position = 100003; - mi.pszService = MS_OTR_MENUSTOP; - mi.icolibItem = GetIconHandle(ICON_NOT_PRIVATE); - AddMirOTRMenuItem(0, (LPARAM) &mi); - - mi.flags = CMIF_TCHAR|CMIF_ICONFROMICOLIB|CMIF_NOTNOTPRIVATE|CMIF_NOTFINISHED; - mi.ptszName = _T(LANG_MENU_VERIFY); - mi.position = 200001; - mi.pszService = MS_OTR_MENUVERIFY; - mi.icolibItem = GetIconHandle(ICON_PRIVATE); - AddMirOTRMenuItem(0, (LPARAM) &mi); - - mi.flags = CMIF_TCHAR|CMIF_CHECKED; - mi.ptszName = _T(LANG_MENU_TOGGLEHTML); - mi.position = 300001; - mi.pszService = MS_OTR_MENUTOGGLEHTML; - hHTMLConvMenuItem = (HGENMENU) AddMirOTRMenuItem(0, (LPARAM) &mi); - - - -} - -void UninitMirOTRMenu(void) -{ - DestroyWindow(hDummyPaintWin); - hDummyPaintWin = 0; - UnregisterClass(_T("MirOTRPopUpMenuProcessor"), hInst); - if ( hMirOTRMenuObject ) CallService( MO_REMOVEMENUOBJECT, (WPARAM)hMirOTRMenuObject, 0 ); - hMirOTRMenuObject = 0; -} \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/mirotrmenu.h b/plugins/MirOTR/MirOTR/mirotrmenu.h deleted file mode 100644 index fe070f0ba8..0000000000 --- a/plugins/MirOTR/MirOTR/mirotrmenu.h +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once -#define MS_MIROTR_ADDMIROTRMENUITEM MODULENAME"/AddMirOTRMenuItem" -#define MS_MIROTR_MENUBUILDMIROTR MODULENAME"/MenuBuildMirOTR" -#define MS_MIROTR_REMOVEMIROTRMENUITEM MODULENAME"/RemoveMirOTRMenuItem" - -#define CMIF_NOTNOTPRIVATE CMIF_NOTOFFLINE -#define CMIF_NOTUNVERIFIED CMIF_NOTONLINE -#define CMIF_NOTPRIVATE CMIF_NOTONLIST -#define CMIF_NOTFINISHED CMIF_NOTOFFLIST -#define CMIF_DISABLED 0x8000 - -//add a new item to the MirOTR Menu -//wParam=0 -//lParam=(LPARAM)(CLISTMENUITEM*)&mi -//returns a handle to the new item, or NULL on failure -//the service that is called when the item is clicked is called with -//wParam=0, lParam=hContact -//dividers are inserted every 100000 positions -//pszContactOwner is ignored for this service. -// -// WARNING: do not use Translate(TS) for p(t)szName or p(t)szPopupName as they -// are translated by the core, which may lead to double translation. -// Use LPGEN instead which are just dummy wrappers/markers for "lpgen.pl". -typedef struct { - int cbSize; //size in bytes of this structure - union { - char* pszName; //[TRANSLATED-BY-CORE] text of the menu item - TCHAR* ptszName; //Unicode text of the menu item - }; - int position; //approx position on the menu. lower numbers go nearer the top - HGENMENU root; //submenu where the item will be added, NULL for root - DWORD flags; //set of MOMIF_* flags - union { - HICON hIcon; //icon to put by the item. If this was not loaded from - //a resource, you can delete it straight after the call - HANDLE icolibItem; //set CMIF_ICONFROMICOLIB to pass this value - }; - DWORD hotKey; //keyboard accelerator, same as lParam of WM_HOTKEY,0 for none - char* pszService; //name of service to call when the item gets selected -} MIROTRMENUITEM; - -void InitMirOTRMenu(void); -void UninitMirOTRMenu(void); - -void ShowOTRMenu(HANDLE hContact, POINT pt); \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/options.cpp b/plugins/MirOTR/MirOTR/options.cpp deleted file mode 100644 index 8af221d5da..0000000000 --- a/plugins/MirOTR/MirOTR/options.cpp +++ /dev/null @@ -1,911 +0,0 @@ -#include "stdafx.h" -#include "options.h" -#include "utils.h" -#include "m_options.h" -#include -#include -#include - -char g_fingerprint_store_filename[MAX_PATH]; -char g_private_key_filename[MAX_PATH]; -HANDLE hPATH_MIROTR; -Options options; -#define DATA_DIRECTORY MIRANDA_USERDATA "\\" MODULENAME -HANDLE hHookOptions; -struct PROTOREGENKEYOPTIONS { - HWND refresh; - TCHAR proto[129]; -}; - -void SetFilenames(const char *path) { - if (!path || !path[0]) return; - CallService(MS_UTILS_CREATEDIRTREE, 0, (LPARAM) path); - strcpy(g_fingerprint_store_filename, path); - strcpy(g_private_key_filename, path); - strcat(g_fingerprint_store_filename, ("\\")); - strcat(g_private_key_filename, ("\\")); - - strcat(g_fingerprint_store_filename, FINGERPRINT_STORE_FILENAME); - strcat(g_private_key_filename, PRIVATE_KEY_FILENAME); -} - -int FoldersChanged(WPARAM wParam, LPARAM lParam) { - char path[MAX_PATH]; - - FOLDERSGETDATA fgd = {0}; - fgd.cbSize = sizeof(FOLDERSGETDATA); - fgd.nMaxPathSize = MAX_PATH; - fgd.szPath = path; - if (CallService(MS_FOLDERS_GET_PATH, (LPARAM)hPATH_MIROTR, (LPARAM)&fgd)) { - char *mypath = Utils_ReplaceVars(DATA_DIRECTORY); - SetFilenames(mypath); - mir_free(mypath); - } else - SetFilenames(path); - - ReadPrivkeyFiles(); - return 0; -} - -void LoadFilenames() { - if(ServiceExists(MS_FOLDERS_REGISTER_PATH)) { - hPATH_MIROTR = FoldersRegisterCustomPath(MODULENAME, "Private Data", DATA_DIRECTORY); - HookEvent(ME_FOLDERS_PATH_CHANGED, FoldersChanged); - - // get the path - above are only defaults - there may be a different value in the db - FoldersChanged(0, 0); - } else { - char *path = Utils_ReplaceVars(DATA_DIRECTORY); - SetFilenames(path); - mir_free(path); - ReadPrivkeyFiles(); - } -} - -void LoadOptions() { - options.default_policy = DBGetContactSettingWord(0, MODULENAME, "DefaultPolicy", OTRL_POLICY_OPPORTUNISTIC); - // deal with changed flags in proto.h and new interpretation of 'manual' mode (see common.h) - switch(options.default_policy) { - case OTRL_POLICY_MANUAL: - options.default_policy = OTRL_POLICY_MANUAL_MOD; - break; - case OTRL_POLICY_OPPORTUNISTIC: - case OTRL_POLICY_MANUAL_MOD: - case OTRL_POLICY_ALWAYS: - case OTRL_POLICY_NEVER: - break; - default: - options.default_policy = OTRL_POLICY_OPPORTUNISTIC; - break; - } - options.err_method = (ErrorDisplay)DBGetContactSettingWord(0, MODULENAME, "ErrorDisplay", ED_POP); - options.prefix_messages = (DBGetContactSettingByte(0, MODULENAME, "PrefixMessages", 0) == 1); - options.msg_inline = (DBGetContactSettingByte(0, MODULENAME, "MsgInline", 0) == 1); - options.msg_popup = (DBGetContactSettingByte(0, MODULENAME, "MsgPopup", 1) == 1); - options.delete_history = (DBGetContactSettingByte(0, MODULENAME, "NoHistory", 0) == 1); - options.delete_systeminfo = (DBGetContactSettingByte(0, MODULENAME, "NoSystemHistory", 0) == 1); - options.autoshow_verify = (DBGetContactSettingByte(0, MODULENAME, "AutoShowVerify", 1) == 1); - - DBVARIANT dbv; - if (!DBGetContactSettingUTF8String(0, MODULENAME, "Prefix", &dbv)) { - strncpy(options.prefix, dbv.pszVal, OPTIONS_PREFIXLEN); - options.prefix[OPTIONS_PREFIXLEN-1] = 0; - DBFreeVariant(&dbv); - } else - strcpy(options.prefix, ("OTR: ")); - - options.timeout_finished = (DBGetContactSettingByte(0, MODULENAME, "TimeoutFinished", 0) == 1); - - options.end_offline = (DBGetContactSettingByte(0, MODULENAME, "EndOffline", 1) == 1); - options.end_window_close = (DBGetContactSettingByte(0, MODULENAME, "EndWindowClose", 0) == 1); - - options.bHaveMetaContacts = 0!=ServiceExists(MS_MC_GETMETACONTACT); - options.bHavePopups = 0!=ServiceExists(MS_POPUP_ADDPOPUPT) && ServiceExists(MS_POPUP_SHOWMESSAGE); - options.bHaveSRMMIcons = 0!=ServiceExists(MS_MSG_MODIFYICON); - options.bHaveSecureIM = 0!=ServiceExists("SecureIM/IsContactSecured"); - options.bHaveButtonsBar = 0!=ServiceExists(MS_BB_ADDBUTTON); - - LoadFilenames(); -} - -extern "C" int OpenOptions(WPARAM wParam, LPARAM lParam) -{ - OPTIONSDIALOGPAGE odp = { 0 }; - - odp.cbSize = sizeof(odp); - odp.position = 100; - odp.hInstance = hInst; - odp.ptszGroup = LPGENT("Plugins"); //"Plugins" - odp.ptszTitle = _T(MODULENAME); - odp.flags = ODPF_BOLDGROUPS|ODPF_TCHAR; - - odp.ptszTab = _T(LANG_OPT_GENERAL); - odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_GENERAL); - odp.pfnDlgProc = DlgProcMirOTROpts; - Options_AddPage(wParam, &odp); - - odp.ptszTab = _T(LANG_OPT_PROTO); - odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_PROTO); - odp.pfnDlgProc = DlgProcMirOTROptsProto; - Options_AddPage(wParam, &odp); - - odp.ptszTab = _T(LANG_OPT_CONTACTS); - odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_CONTACTS); - odp.pfnDlgProc = DlgProcMirOTROptsContacts; - Options_AddPage(wParam, &odp); - - odp.ptszTab = _T(LANG_OPT_FINGER); - odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_FINGER); - odp.pfnDlgProc = DlgProcMirOTROptsFinger; - Options_AddPage(wParam, &odp); - - return 0; -} - -void InitOptions() { - LoadOptions(); - hHookOptions = HookEvent(ME_OPT_INITIALISE, OpenOptions); -} - -void DeinitOptions() { - UnhookEvent(hHookOptions); -} - -void SaveOptions() { - DBWriteContactSettingWord(0, MODULENAME, "DefaultPolicy", options.default_policy); - DBWriteContactSettingWord(0, MODULENAME, "ErrorDisplay", (int)options.err_method); - DBWriteContactSettingByte(0, MODULENAME, "PrefixMessages", options.prefix_messages ? 1 : 0); - DBWriteContactSettingByte(0, MODULENAME, "MsgInline", options.msg_inline ? 1 : 0); - DBWriteContactSettingByte(0, MODULENAME, "MsgPopup", options.msg_popup ? 1 : 0); - - DBWriteContactSettingByte(0, MODULENAME, "NoHistory", options.delete_history ? 1 : 0); - DBWriteContactSettingByte(0, MODULENAME, "NoSystemHistory", options.delete_systeminfo ? 1 : 0); - DBWriteContactSettingByte(0, MODULENAME, "AutoShowVerify", options.autoshow_verify ? 1 : 0); - - /* - if (contact_policies) { - for(ContactPolicyMap::iterator i = contact_policies->begin(); i != contact_policies->end(); i++) { - DBWriteContactSettingWord(i->first, MODULENAME, "Policy", i->second); - } - } - */ - - DBWriteContactSettingStringUtf(0, MODULENAME, "Prefix", options.prefix); - - DBWriteContactSettingByte(0, MODULENAME, "TimeoutFinished", options.timeout_finished ? 1 : 0); - - DBWriteContactSettingByte(0, MODULENAME, "EndOffline", options.end_offline ? 1 : 0); - DBWriteContactSettingByte(0, MODULENAME, "EndWindowClose", options.end_window_close ? 1 : 0); -} - -extern "C" void set_context_contact(void *data, ConnContext *context) { - HANDLE hContact = find_contact(context->username, context->protocol); - context->app_data = hContact; - } - -void ReadPrivkeyFiles() { - DEBUGOUT_T("READ privkey"); - lib_cs_lock(); - otrl_privkey_read(otr_user_state, g_private_key_filename); - otrl_privkey_read_fingerprints(otr_user_state, g_fingerprint_store_filename, set_context_contact, 0); - lib_cs_unlock(); -} - -static INT_PTR CALLBACK DlgProcMirOTROpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - TCHAR *prefix; char* prefix_utf; - switch ( msg ) { - case WM_INITDIALOG: - TranslateDialogDefault( hwndDlg ); - - // set default policy radio - switch(options.default_policy) { - case OTRL_POLICY_OPPORTUNISTIC: - CheckDlgButton(hwndDlg, IDC_RAD_OPP, TRUE); - break; - case OTRL_POLICY_MANUAL_MOD: - CheckDlgButton(hwndDlg, IDC_RAD_MANUAL, TRUE); - break; - case OTRL_POLICY_ALWAYS: - CheckDlgButton(hwndDlg, IDC_RAD_ALWAYS, TRUE); - break; - case OTRL_POLICY_NEVER: - CheckDlgButton(hwndDlg, IDC_RAD_NEVER, TRUE); - break; - } - - CheckDlgButton(hwndDlg, IDC_CHK_PREFIX, options.prefix_messages ? TRUE : FALSE); - CheckDlgButton(hwndDlg, IDC_CHK_MSGINLINE, options.msg_inline ? TRUE : FALSE); - CheckDlgButton(hwndDlg, IDC_CHK_MSGPOPUP, options.msg_popup ? TRUE : FALSE); - CheckDlgButton(hwndDlg, IDC_CHK_TIMEFINISH, options.timeout_finished ? TRUE : FALSE); - CheckDlgButton(hwndDlg, IDC_CHK_PREVENTSAVE, options.delete_history ? TRUE : FALSE); - CheckDlgButton(hwndDlg, IDC_CHK_PREVENTSYSSAVE, options.delete_systeminfo ? TRUE : FALSE); - CheckDlgButton(hwndDlg, IDC_CHK_AUTOSHOW_VERIFY, options.autoshow_verify ? TRUE : FALSE); - CheckDlgButton(hwndDlg, IDC_CHK_ENDOFFLINE, options.end_offline ? TRUE : FALSE); - CheckDlgButton(hwndDlg, IDC_CHK_ENDCLOSE, options.end_window_close ? TRUE : FALSE); - - prefix = mir_utf8decodeT(options.prefix); - SetDlgItemText(hwndDlg, IDC_ED_PREFIX, prefix); - mir_free(prefix); - - return TRUE; - break; - - case WM_COMMAND: - switch ( HIWORD( wParam )) { - case BN_CLICKED: - switch ( LOWORD( wParam )) { - case IDC_RAD_OPP: - case IDC_RAD_MANUAL: - case IDC_RAD_ALWAYS: - case IDC_RAD_NEVER: - case IDC_CHK_PREFIX: - case IDC_CHK_MSGINLINE: - case IDC_CHK_MSGPOPUP: - case IDC_CHK_TIMEFINISH: - case IDC_CHK_PREVENTSAVE: - case IDC_CHK_AUTOSHOW_VERIFY: - case IDC_CHK_ENDOFFLINE: - case IDC_CHK_ENDCLOSE: - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - break; - } - case EN_CHANGE: - if (LOWORD( wParam ) == IDC_ED_PREFIX && ( HWND )lParam == GetFocus()) - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - break; - } - break; - - case WM_NOTIFY: - - if (((LPNMHDR)lParam)->code == (UINT) PSN_APPLY ) { - // handle apply - - if (IsDlgButtonChecked(hwndDlg, IDC_RAD_OPP)) - options.default_policy = OTRL_POLICY_OPPORTUNISTIC; - else if (IsDlgButtonChecked(hwndDlg, IDC_RAD_MANUAL)) - options.default_policy = OTRL_POLICY_MANUAL_MOD; - else if (IsDlgButtonChecked(hwndDlg, IDC_RAD_ALWAYS)) - options.default_policy = OTRL_POLICY_ALWAYS; - else - options.default_policy = OTRL_POLICY_NEVER; - - options.prefix_messages = (TRUE==IsDlgButtonChecked(hwndDlg, IDC_CHK_PREFIX)); - options.msg_inline = (TRUE==IsDlgButtonChecked(hwndDlg, IDC_CHK_MSGINLINE)); - options.msg_popup = (TRUE==IsDlgButtonChecked(hwndDlg, IDC_CHK_MSGPOPUP)); - options.timeout_finished = (TRUE==IsDlgButtonChecked(hwndDlg, IDC_CHK_TIMEFINISH)); - options.delete_history = (TRUE==IsDlgButtonChecked(hwndDlg, IDC_CHK_PREVENTSAVE)); - options.delete_systeminfo = (TRUE==IsDlgButtonChecked(hwndDlg, IDC_CHK_PREVENTSYSSAVE)); - options.autoshow_verify = (TRUE==IsDlgButtonChecked(hwndDlg, IDC_CHK_AUTOSHOW_VERIFY)); - options.end_offline = (TRUE==IsDlgButtonChecked(hwndDlg, IDC_CHK_ENDOFFLINE)); - options.end_window_close = (TRUE==IsDlgButtonChecked(hwndDlg, IDC_CHK_ENDCLOSE)); - - prefix = (TCHAR*)mir_alloc(sizeof(TCHAR)*OPTIONS_PREFIXLEN); - GetDlgItemText(hwndDlg, IDC_ED_PREFIX, prefix, OPTIONS_PREFIXLEN); - prefix_utf = mir_utf8encodeT(prefix); - mir_free(prefix); - strncpy(options.prefix, prefix_utf, OPTIONS_PREFIXLEN); - mir_free(prefix_utf); - - SaveOptions(); - - return TRUE; - } - - break; - } - return FALSE; -} - -static unsigned int CALLBACK regen_key_thread(void* param) -{ - Thread_Push(0); - PROTOREGENKEYOPTIONS *opts = (PROTOREGENKEYOPTIONS *)param; - TCHAR *buff = (TCHAR*) mir_alloc(512*sizeof(TCHAR)); - mir_sntprintf(buff, 512, TranslateT(LANG_OTR_ASK_NEWKEY), opts->proto); - EnableWindow(opts->refresh, FALSE); - if (IDYES == MessageBox(opts->refresh, buff, TranslateT(LANG_OTR_INFO), MB_ICONQUESTION|MB_YESNO)) - { - mir_free(buff); - - char* proto = mir_t2a(opts->proto); - otr_gui_create_privkey(0, proto, proto); - SendMessage(opts->refresh, WMU_REFRESHPROTOLIST, 0, 0); - /* - char *fp = (char*)mir_alloc(20); - otrl_privkey_fingerprint(otr_user_state, fp, proto, proto); - TCHAR *fpt = mir_a2t(fp); - mir_free(fp); - ListView_SetItemText(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS), sel, 2, fpt); - mir_free(fpt); - mir_free(proto); - */ - } else { - mir_free(buff); - } - EnableWindow(opts->refresh, TRUE); - delete opts; - Thread_Pop(); - return 0; -} - -static INT_PTR CALLBACK DlgProcMirOTROptsProto(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - HWND lv; - switch ( msg ) { - case WM_INITDIALOG: - TranslateDialogDefault( hwndDlg ); - lv = GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS); - - { - HWND cmb = GetDlgItem(hwndDlg, IDC_CMB_PROTO_POLICY); - SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_DEFAULT)); - SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_ALWAYS)); - SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_OPP)); - SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_MANUAL)); - SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_NEVER)); - SendMessage(GetDlgItem(hwndDlg, IDC_CMB_PROTO_POLICY), CB_SETCURSEL, (LPARAM)-1, 0); - EnableWindow(GetDlgItem(hwndDlg, IDC_CMB_PROTO_POLICY), FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_NEWKEY), FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_FORGET), FALSE); - } - - SendMessage(lv,LVM_SETEXTENDEDLISTVIEWSTYLE, 0,LVS_EX_FULLROWSELECT);// | LVS_EX_CHECKBOXES); - { - // add list columns - LVCOLUMN lvc; - // Initialize the LVCOLUMN structure. - // The mask specifies that the format, width, text, and - // subitem members of the structure are valid. - lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; - lvc.fmt = LVCFMT_LEFT; - - lvc.iSubItem = 0; - lvc.pszText = TranslateT(LANG_PROTO); - lvc.cx = 85; // width of column in pixels - ListView_InsertColumn(lv, 0, &lvc); - - lvc.iSubItem = 1; - lvc.pszText = TranslateT(LANG_POLICY); - lvc.cx = 80; // width of column in pixels - ListView_InsertColumn(lv, 1, &lvc); - - lvc.iSubItem = 2; - lvc.pszText = TranslateT(LANG_FINGERPRINT); - lvc.cx = 275; // width of column in pixels - ListView_InsertColumn(lv, 2, &lvc); - } - PostMessage(hwndDlg, WMU_REFRESHPROTOLIST, 0, 0); - - return TRUE; - case WMU_REFRESHPROTOLIST: - { - lv = GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS); - ListView_DeleteAllItems(lv); - int num_protocols; - PROTOACCOUNT **pppDesc; - int ilvItem; - LV_ITEM item = {0}; - char fprint[45]; - TCHAR* temp; - //BOOL unicode = ListView_GetUnicodeFormat(lv); - - ProtoEnumAccounts(&num_protocols, &pppDesc); - for(int i = 0; i < num_protocols; i++) { - if((!g_metaproto || strcmp(pppDesc[i]->szModuleName, g_metaproto) != 0) - && (CallProtoService(pppDesc[i]->szModuleName, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IM) == PF1_IM) - { - //if (unicode) { - item.mask = LVIF_TEXT; - temp = mir_a2t(pppDesc[i]->szModuleName); - item.pszText = temp; - ilvItem = ListView_InsertItem(lv, &item); - mir_free(temp); - - - ListView_SetItemText(lv, ilvItem, 1, (TCHAR*)policy_to_string(db_get_dw(0,MODULENAME"_ProtoPol", pppDesc[i]->szModuleName, CONTACT_DEFAULT_POLICY)) ); - if(otrl_privkey_fingerprint(otr_user_state, fprint, pppDesc[i]->szModuleName, pppDesc[i]->szModuleName)) { - temp = mir_a2t(fprint); - ListView_SetItemText(lv, ilvItem, 2, temp); - mir_free(temp); - } - } - } - } - return TRUE; - case WM_COMMAND: - switch ( HIWORD( wParam )) { - case BN_CLICKED: - switch ( LOWORD( wParam )) { - case IDC_BTN_PROTO_NEWKEY: - { - int sel = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS)); - if (sel != -1) { - PROTOREGENKEYOPTIONS *opts = new PROTOREGENKEYOPTIONS(); - opts->refresh = hwndDlg; - ListView_GetItemText(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS), sel, 0, opts->proto, 128); - CloseHandle((HANDLE)_beginthreadex(0, 0, regen_key_thread, opts, 0, 0)); - } - }break; - case IDC_BTN_PROTO_FORGET: - { - int sel = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS)); - if (sel != -1) { - TCHAR buff_proto[128]; - ListView_GetItemText(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS), sel, 0, buff_proto, 128); - TCHAR buff[512]; - mir_sntprintf(buff, 512, TranslateT(LANG_OTR_ASK_REMOVEKEY), buff_proto); - if (IDYES == MessageBox(hwndDlg, buff, TranslateT(LANG_OTR_INFO), MB_ICONQUESTION|MB_YESNO)) - { - char* proto = mir_t2a(buff_proto); - OtrlPrivKey *key = otrl_privkey_find(otr_user_state, proto, proto); - mir_free(proto); - if (key) { - otrl_privkey_forget(key); - otrl_privkey_write(otr_user_state, g_private_key_filename); - ListView_SetItemText(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS), sel, 2, _T("")); - } - } - } - }break; - } - case CBN_SELCHANGE: - switch ( LOWORD( wParam )) { - case IDC_CMB_PROTO_POLICY: - { - int proto = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS)); - if (proto == -1) break; - int sel = SendDlgItemMessage(hwndDlg, IDC_CMB_PROTO_POLICY, CB_GETCURSEL, 0, 0); - if (sel==CB_ERR) break; - int len = SendDlgItemMessage(hwndDlg, IDC_CMB_PROTO_POLICY, CB_GETLBTEXTLEN, sel, 0); - if (len < 0) break; - TCHAR *text = new TCHAR[len+1]; - SendDlgItemMessage(hwndDlg, IDC_CMB_PROTO_POLICY, CB_GETLBTEXT, sel, (LPARAM)text); - ListView_SetItemText(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS), proto, 1, text); - delete text; - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - }break; - } - break; - } - break; - - case WM_NOTIFY: - if (((LPNMHDR) lParam)->code == (UINT) LVN_ITEMCHANGED && ((LPNMHDR) lParam)->hwndFrom == GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS) - && (((LPNMLISTVIEW)lParam)->uNewState & LVIS_SELECTED )) { - int sel = ListView_GetSelectionMark(((LPNMHDR) lParam)->hwndFrom); - if (sel == -1) { - SendMessage(GetDlgItem(hwndDlg, IDC_CMB_PROTO_POLICY), CB_SETCURSEL, (LPARAM)-1, 0); - EnableWindow(GetDlgItem(hwndDlg, IDC_CMB_PROTO_POLICY), FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_NEWKEY), FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_FORGET), FALSE); - } else { - EnableWindow(GetDlgItem(hwndDlg, IDC_CMB_PROTO_POLICY), TRUE); - EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_NEWKEY), TRUE); - EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_FORGET), TRUE); - TCHAR buff[50]; - ListView_GetItemText(((LPNMHDR)lParam)->hwndFrom, sel, 1, buff, 50); - SendMessage(GetDlgItem(hwndDlg, IDC_CMB_PROTO_POLICY), CB_SELECTSTRING, (LPARAM)-1, (WPARAM)buff); - } - - } else if (((LPNMHDR)lParam)->code == (UINT) PSN_APPLY ) { - lv = GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS); - int cnt = ListView_GetItemCount(lv); - TCHAR proto_t[128], policy[64]; - char* proto; - for (int i = 0; i < cnt; ++i) { - ListView_GetItemText(lv, i, 0, proto_t, 128); - ListView_GetItemText(lv, i, 1, policy, 64); - proto = mir_t2a(proto_t); - db_set_dw(0, MODULENAME"_ProtoPol", proto, policy_from_string(policy)); - mir_free(proto); - } - // handle apply - return TRUE; - } - break; - } - return FALSE; -} - -static INT_PTR CALLBACK DlgProcMirOTROptsContacts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch ( msg ) { - case WM_INITDIALOG: - { - TranslateDialogDefault( hwndDlg ); - - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (ULONG_PTR) new ContactPolicyMap()); - - HWND cmb = GetDlgItem(hwndDlg, IDC_CMB_CONT_POLICY); - SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_DEFAULT)); - SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_ALWAYS)); - SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_OPP)); - SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_MANUAL)); - SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_NEVER)); - EnableWindow(GetDlgItem(hwndDlg, IDC_CMB_CONT_POLICY), FALSE); - - SendDlgItemMessage(hwndDlg, IDC_LV_CONT_CONTACTS ,LVM_SETEXTENDEDLISTVIEWSTYLE, 0,LVS_EX_FULLROWSELECT);// | LVS_EX_CHECKBOXES); - - - HWND lv = GetDlgItem(hwndDlg, IDC_LV_CONT_CONTACTS); - - - // add list columns - LVCOLUMN lvc; - // Initialize the LVCOLUMN structure. - // The mask specifies that the format, width, text, and - // subitem members of the structure are valid. - lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; - lvc.fmt = LVCFMT_LEFT; - - lvc.iSubItem = 0; - lvc.pszText = TranslateT(LANG_CONTACT); - lvc.cx = 150; // width of column in pixels - ListView_InsertColumn(lv, 0, &lvc); - - lvc.iSubItem = 1; - lvc.pszText = TranslateT(LANG_PROTO); - lvc.cx = 100; // width of column in pixels - ListView_InsertColumn(lv, 1, &lvc); - - lvc.iSubItem = 2; - lvc.pszText = TranslateT(LANG_POLICY); - lvc.cx = 90; // width of column in pixels - ListView_InsertColumn(lv, 2, &lvc); - - lvc.iSubItem = 3; - lvc.pszText = TranslateT(LANG_HTMLCONV); - lvc.cx = 80; // width of column in pixels - ListView_InsertColumn(lv, 3, &lvc); - } - SendMessage(hwndDlg, WMU_REFRESHLIST, 0, 0); - - return TRUE; - case WMU_REFRESHLIST: - { - HWND lv = GetDlgItem(hwndDlg, IDC_LV_CONT_CONTACTS); - - ListView_DeleteAllItems(lv); - - LVITEM lvI = {0}; - - // Some code to create the list-view control. - // Initialize LVITEM members that are common to all - // items. - lvI.mask = LVIF_TEXT | LVIF_PARAM;// | LVIF_NORECOMPUTE;// | LVIF_IMAGE; - - const char *proto; - TCHAR *proto_t; - HANDLE hContact = db_find_first(); - while ( hContact != NULL ) - { - proto = contact_get_proto(hContact); - if(proto && db_get_b(hContact, proto, "ChatRoom", 0) == 0 && CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)MODULENAME) // ignore chatrooms - && (g_metaproto == 0 || strcmp(proto, g_metaproto) != 0)) // and MetaContacts - { - lvI.iItem = 0; - lvI.iSubItem = 0; - lvI.lParam = (LPARAM)hContact; - lvI.pszText = (TCHAR*)contact_get_nameT(hContact); - lvI.iItem = ListView_InsertItem(lv , &lvI); - - proto_t = mir_a2t(proto); - ListView_SetItemText(lv, lvI.iItem, 1, proto_t); - mir_free(proto_t); - - ListView_SetItemText(lv, lvI.iItem, 2, (TCHAR*)policy_to_string((OtrlPolicy)db_get_dw(hContact, MODULENAME, "Policy", CONTACT_DEFAULT_POLICY)) ); - ListView_SetItemText(lv, lvI.iItem, 3, (db_get_b(hContact, MODULENAME, "HTMLConv", 0))?TranslateT(LANG_YES):TranslateT(LANG_NO) ); - } - - - hContact = db_find_next(hContact); - } - } - return TRUE; - break; - case WM_COMMAND: - switch ( HIWORD( wParam )) { - case CBN_SELCHANGE: - switch ( LOWORD( wParam )) { - case IDC_CMB_CONT_POLICY: - { - HANDLE hContact = 0; - int iUser = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_CONT_CONTACTS)); - if (iUser == -1) break; - int sel = SendDlgItemMessage(hwndDlg, IDC_CMB_CONT_POLICY, CB_GETCURSEL, 0, 0); - if (sel==CB_ERR) break; - int len = SendDlgItemMessage(hwndDlg, IDC_CMB_CONT_POLICY, CB_GETLBTEXTLEN, sel, 0); - if (len < 0) break; - TCHAR *text = new TCHAR[len+1]; - SendDlgItemMessage(hwndDlg, IDC_CMB_CONT_POLICY, CB_GETLBTEXT, sel, (LPARAM)text); - ListView_SetItemText(GetDlgItem(hwndDlg, IDC_LV_CONT_CONTACTS), iUser, 2, text); - OtrlPolicy policy = policy_from_string(text); - delete text; - LVITEM lvi = {0}; - lvi.mask = LVIF_PARAM; - lvi.iItem = iUser; - lvi.iSubItem = 0; - ListView_GetItem(GetDlgItem(hwndDlg, IDC_LV_CONT_CONTACTS), &lvi); - ContactPolicyMap* cpm = (ContactPolicyMap*) GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - hContact = (HANDLE)lvi.lParam; - (*cpm)[hContact].policy = policy; - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - }break; - } - break; - } - break; - - case WM_NOTIFY: - { - UINT code = ((LPNMHDR) lParam)->code; - if (code == (UINT) PSN_APPLY ) { - // handle apply - - ContactPolicyMap *cpm = (ContactPolicyMap*) GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - // Iterate over the map and print out all key/value pairs. - // Using a const_iterator since we are not going to change the values. - for(ContactPolicyMap::const_iterator it = cpm->begin(); it != cpm->end(); ++it) - { - if (!it->first) continue; - if (it->second.policy) DBWriteContactSettingDword(it->first, MODULENAME, "Policy", (DWORD)it->second.policy); - if (it->second.htmlconv) db_set_b(it->first, MODULENAME, "HTMLConv", it->second.htmlconv-1); - } - return TRUE; - } else if (((LPNMHDR) lParam)->hwndFrom == GetDlgItem(hwndDlg, IDC_LV_CONT_CONTACTS)) { - if (code == (UINT) LVN_ITEMCHANGED && (((LPNMLISTVIEW)lParam)->uNewState & LVIS_SELECTED )) { - int sel = ListView_GetSelectionMark(((LPNMHDR) lParam)->hwndFrom); - if (sel == -1) { - SendMessage(GetDlgItem(hwndDlg, IDC_CMB_CONT_POLICY), CB_SETCURSEL, (LPARAM)-1, 0); - EnableWindow(GetDlgItem(hwndDlg, IDC_CMB_CONT_POLICY), FALSE); - } else { - EnableWindow(GetDlgItem(hwndDlg, IDC_CMB_CONT_POLICY), TRUE); - TCHAR buff[50]; - ListView_GetItemText(((LPNMHDR)lParam)->hwndFrom, sel, 2, buff, 50); - SendMessage(GetDlgItem(hwndDlg, IDC_CMB_CONT_POLICY), CB_SELECTSTRING, (LPARAM)-1, (WPARAM)buff); - } - } else if (code == (UINT) NM_CLICK) { - if (((LPNMLISTVIEW)lParam)->iSubItem == 3) { - LVITEM lvi; - lvi.mask = LVIF_PARAM; - lvi.iItem = ((LPNMLISTVIEW)lParam)->iItem; - if (lvi.iItem < 0) return FALSE; - lvi.iSubItem = 0; - SendDlgItemMessage(hwndDlg, IDC_LV_CONT_CONTACTS, LVM_GETITEM, 0, (LPARAM)&lvi); - - HANDLE hContact = (HANDLE)lvi.lParam; - ContactPolicyMap *cp = (ContactPolicyMap *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - TCHAR buff[50]; - ListView_GetItemText(((LPNMHDR)lParam)->hwndFrom, lvi.iItem, 3, buff, 50); - if (_tcsncmp(buff, TranslateT(LANG_YES), 50)==0){ - (*cp)[hContact].htmlconv = HTMLCONV_DISABLE; - ListView_SetItemText(((LPNMHDR)lParam)->hwndFrom, lvi.iItem, 3, TranslateT(LANG_NO)); - }else { - (*cp)[hContact].htmlconv = HTMLCONV_ENABLE; - ListView_SetItemText(((LPNMHDR)lParam)->hwndFrom, lvi.iItem, 3, TranslateT(LANG_YES)); - } - (*cp)[hContact].htmlconv += 1; - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - } - - - } - } - }break; - case WM_DESTROY: - ContactPolicyMap *cpm = (ContactPolicyMap*) GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - cpm->clear(); - delete cpm; - break; - } - return FALSE; -} - -static INT_PTR CALLBACK DlgProcMirOTROptsFinger(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch ( msg ) { - case WM_INITDIALOG: - TranslateDialogDefault( hwndDlg ); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (ULONG_PTR) new FPModifyMap()); - - SendDlgItemMessage(hwndDlg, IDC_LV_FINGER_LIST ,LVM_SETEXTENDEDLISTVIEWSTYLE, 0,LVS_EX_FULLROWSELECT);// | LVS_EX_CHECKBOXES); - - { - HWND lv = GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST); - // add list columns - LVCOLUMN lvc; - // Initialize the LVCOLUMN structure. - // The mask specifies that the format, width, text, and - // subitem members of the structure are valid. - lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; - lvc.fmt = LVCFMT_LEFT; - - lvc.iSubItem = 0; - lvc.pszText = TranslateT(LANG_CONTACT); - lvc.cx = 100; // width of column in pixels - ListView_InsertColumn(lv, 0, &lvc); - - lvc.iSubItem = 1; - lvc.pszText = TranslateT(LANG_PROTO); - lvc.cx = 90; // width of column in pixels - ListView_InsertColumn(lv, 1, &lvc); - - lvc.iSubItem = 2; - lvc.pszText = TranslateT(LANG_ACTIVE); - lvc.cx = 50; // width of column in pixels - ListView_InsertColumn(lv, 2, &lvc); - - lvc.iSubItem = 3; - lvc.pszText = TranslateT(LANG_VERIFIED); - lvc.cx = 50; // width of column in pixels - ListView_InsertColumn(lv, 3, &lvc); - - lvc.iSubItem = 4; - lvc.pszText = TranslateT(LANG_FINGERPRINT); - lvc.cx = 300; // width of column in pixels - ListView_InsertColumn(lv, 4, &lvc); - } - SendMessage(hwndDlg, WMU_REFRESHLIST, 0, 0); - - return TRUE; - - case WMU_REFRESHLIST: - //enumerate contacts, fill in list - { - HWND lv = GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST); - ListView_DeleteAllItems(lv); - - LVITEM lvI = {0}; - - // Some code to create the list-view control. - // Initialize LVITEM members that are common to all - // items. - lvI.mask = LVIF_TEXT | LVIF_PARAM;// | LVIF_NORECOMPUTE;// | LVIF_IMAGE; - ConnContext * context = otr_user_state->context_root; - TCHAR *proto, *user, hash[45] = {0}; - Fingerprint *fp; - while (context) { - if (context->app_data) { - user = (TCHAR*)contact_get_nameT((HANDLE)context->app_data); - if (user) { - proto = mir_a2t(context->protocol); - fp = context->fingerprint_root.next; - while(fp) { - otrl_privkey_hash_to_humanT(hash, fp->fingerprint); - if (hash) { - lvI.iSubItem = 0; - lvI.lParam = (LPARAM)fp; - lvI.pszText = user; - int d = ListView_InsertItem(lv, &lvI); - - ListView_SetItemText(lv,d, 1, proto); - ListView_SetItemText(lv,d, 2, (context->active_fingerprint == fp)? TranslateT(LANG_YES) : TranslateT(LANG_NO)); - ListView_SetItemText(lv,d, 3, (fp->trust && fp->trust != '\0')? TranslateT(LANG_YES) : TranslateT(LANG_NO)); - ListView_SetItemText(lv,d, 4, hash ); - } - fp = fp->next; - } - mir_free(proto); - } - } - context = context->next; - } - } - - return TRUE; - case WM_COMMAND: - switch ( HIWORD( wParam )) { - case BN_CLICKED: - switch ( LOWORD( wParam )) { - case IDC_BTN_FINGER_DONTTRUST: - { - int sel = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST)); - if (sel != -1) { - LVITEM lvi = {0}; - lvi.mask = LVIF_PARAM; - lvi.iItem = sel; - Fingerprint *fp = NULL; - ListView_GetItem(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST), &lvi); - fp = (Fingerprint*) lvi.lParam; - FPModifyMap* fpm = (FPModifyMap*) GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - (*fpm)[fp] = FPM_NOTRUST; - ListView_SetItemText(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST), sel, 3, TranslateT(LANG_NO)); - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - } - }break; - case IDC_BTN_FINGER_TRUST: - { - int sel = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST)); - if (sel != -1) { - LVITEM lvi = {0}; - lvi.mask = LVIF_PARAM; - lvi.iItem = sel; - Fingerprint *fp = NULL; - ListView_GetItem(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST), &lvi); - fp = (Fingerprint*) lvi.lParam; - FPModifyMap* fpm = (FPModifyMap*) GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - (*fpm)[fp] = FPM_VERIFY; - ListView_SetItemText(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST), sel, 3, TranslateT(LANG_YES)); - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - } - }break; - case IDC_BTN_FINGER_FORGET: - { - int sel = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST)); - if (sel != -1) { - LVITEM lvi = {0}; - lvi.mask = LVIF_PARAM; - lvi.iItem = sel; - Fingerprint *fp = NULL; - ListView_GetItem(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST), &lvi); - fp = (Fingerprint*) lvi.lParam; - if (fp->context->active_fingerprint == fp) { - TCHAR buff[1024], hash[45]; - otrl_privkey_hash_to_humanT(hash, fp->fingerprint); - mir_sntprintf(buff, 1024, TranslateT(LANG_FINGERPRINT_STILL_IN_USE), hash, contact_get_nameT((HANDLE)fp->context->app_data)); - ShowError(buff); - } else { - FPModifyMap* fpm = (FPModifyMap*) GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - (*fpm)[fp] = FPM_DELETE; - ListView_DeleteItem(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST), sel); - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - } - } - }break; - } - } - break; - - case WM_NOTIFY: - if (((LPNMHDR)lParam)->code == (UINT) PSN_APPLY ) { - // handle apply - - FPModifyMap *fpm = (FPModifyMap*) GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - // Iterate over the map and print out all key/value pairs. - // Using a const_iterator since we are not going to change the values. - for(FPModifyMap::const_iterator it = fpm->begin(); it != fpm->end(); ++it) - { - if (!it->first) continue; - switch (it->second) { - case FPM_DELETE: - if (it->first->context->active_fingerprint == it->first) { - TCHAR buff[1024], hash[45]; - otrl_privkey_hash_to_humanT(hash, it->first->fingerprint); - mir_sntprintf(buff, 1024, TranslateT(LANG_FINGERPRINT_NOT_DELETED), hash, contact_get_nameT((HANDLE)it->first->context->app_data)); - ShowError(buff); - } else { - otrl_context_forget_fingerprint(it->first, 1); - } - break; - case FPM_VERIFY: - otrl_context_set_trust(it->first, "verified"); - if (it->first == it->first->context->active_fingerprint) - VerifyFingerprint(it->first->context, true); - //SetEncryptionStatus((HANDLE)it->first->context->app_data, otr_context_get_trust(it->first->context)); - break; - case FPM_NOTRUST: - otrl_context_set_trust(it->first, NULL); - if (it->first == it->first->context->active_fingerprint) - VerifyFingerprint(it->first->context, false); - //SetEncryptionStatus((HANDLE)it->first->context->app_data, otr_context_get_trust(it->first->context)); - break; - } - } - if (!fpm->empty()) otr_gui_write_fingerprints(0); - fpm->clear(); - SendMessage(hwndDlg, WMU_REFRESHLIST, 0, 0); - - return TRUE; - } - break; - case WM_DESTROY: - FPModifyMap *fpm = (FPModifyMap*) GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - fpm->clear(); - delete fpm; - break; - } - - return FALSE; -} \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/options.h b/plugins/MirOTR/MirOTR/options.h deleted file mode 100644 index b66125d473..0000000000 --- a/plugins/MirOTR/MirOTR/options.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef _OPTIONS_INC -#define _OPTIONS_INC - -//#include "stdafx.h" - -extern char* g_metaproto; - -#define PRIVATE_KEY_FILENAME "otr.private_key" -#define FINGERPRINT_STORE_FILENAME "otr.fingerprints" - -extern char g_fingerprint_store_filename[MAX_PATH]; -extern char g_private_key_filename[MAX_PATH]; - -#define CONTACT_DEFAULT_POLICY 0xFFFF - -typedef enum {ED_POP, ED_BAL, ED_MB} ErrorDisplay; - -#define OPTIONS_PREFIXLEN 64 - -typedef struct { - OtrlPolicy default_policy; - ErrorDisplay err_method; - bool prefix_messages; - bool msg_inline; - bool msg_popup; - char prefix[OPTIONS_PREFIXLEN]; - - bool timeout_finished; - - bool delete_history; - bool delete_systeminfo; - bool autoshow_verify; - - bool end_offline, end_window_close; - - // temporary options - bool bHaveMetaContacts, bHavePopups, bHaveSRMMIcons, bHaveSecureIM, bHaveButtonsBar; - -} Options; - -extern Options options; - -#define WMU_REFRESHLIST (WM_USER + 241) -#define WMU_REFRESHPROTOLIST (WM_USER + 242) -#define CONTACT_DEFAULT_POLICY 0xFFFF - -#include -enum HTMLConvSetting { - HTMLCONV_DISABLE, - HTMLCONV_ENABLE -}; -struct CONTACT_DATA { - OtrlPolicy policy; - int htmlconv; -}; -typedef std::map ContactPolicyMap; -typedef enum {FPM_VERIFY, FPM_NOTRUST, FPM_DELETE } FPModify; -typedef std::map FPModifyMap; - -int OptInit(WPARAM wParam, LPARAM lParam); - -void LoadOptions(); -void SaveOptions(); -extern "C" int OpenOptions(WPARAM wParam, LPARAM lParam); -void InitOptions(); -void DeinitOptions(); - -void ReadPrivkeyFiles(); - -static INT_PTR CALLBACK DlgProcMirOTROpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); -static INT_PTR CALLBACK DlgProcMirOTROptsProto(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); -static INT_PTR CALLBACK DlgProcMirOTROptsContacts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); -static INT_PTR CALLBACK DlgProcMirOTROptsFinger(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); - -#endif diff --git a/plugins/MirOTR/MirOTR/otr.cpp b/plugins/MirOTR/MirOTR/otr.cpp deleted file mode 100644 index ee6e3e0e12..0000000000 --- a/plugins/MirOTR/MirOTR/otr.cpp +++ /dev/null @@ -1,401 +0,0 @@ -#include -#include "otr.h" -#include - -OtrlUserState otr_user_state; -#define WMU_ENDDIALOG (WM_USER+244) - -OtrlMessageAppOps ops = { - otr_gui_policy, - otr_gui_create_privkey, - otr_gui_is_logged_in, - otr_gui_inject_message, - otr_gui_notify, - otr_gui_display_otr_message, - otr_gui_update_context_list, - otr_gui_protocol_name, - otr_gui_protocol_name_free, - otr_gui_new_fingerprint, - otr_gui_write_fingerprints, - otr_gui_gone_secure, - otr_gui_gone_insecure, - otr_gui_still_secure, - otr_gui_log_message, - max_message_size, - account_name, - account_name_free -}; - -struct GenKeyData{ - HWND dialog; - const char *proto; -}; - -static unsigned int CALLBACK generate_key_thread(void* param) -{ - Thread_Push(0); - GenKeyData *data = (GenKeyData *)param; - //lib_cs_lock(); - otrl_privkey_generate(otr_user_state, g_private_key_filename, data->proto, data->proto); - //lib_cs_unlock(); - PostMessage(data->dialog, WMU_ENDDIALOG, 0, 0); - mir_free(data); - Thread_Pop(); - return 0; -} - -INT_PTR CALLBACK GenKeyDlgFunc(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - switch(msg) { - case WM_INITDIALOG: - { - if (!lParam) { - EndDialog(hWndDlg, 0); - return 0; - } - TranslateDialogDefault(hWndDlg); - SetClassLongPtr(hWndDlg, GCLP_HICON, (LONG_PTR)LoadIcon(ICON_OTR,1) ); - TCHAR buff[256]; - TCHAR *proto = mir_a2t((char*)lParam); - mir_sntprintf(buff, 256, TranslateT(LANG_GENERATE_KEY), proto); - mir_free(proto); - SetDlgItemText(hWndDlg, IDC_GENERATE, buff); - GenKeyData *data = (GenKeyData *)mir_calloc(sizeof(GenKeyData)); - data->dialog = hWndDlg; - data->proto = (char*)lParam; - CloseHandle((HANDLE)_beginthreadex(0, 0, generate_key_thread, (void*)data, 0, 0)); - }break; - case WMU_ENDDIALOG: - EndDialog(hWndDlg, 0); - return TRUE; - case WM_DESTROY: - SetClassLongPtr(hWndDlg, GCLP_HICON, 0); - ReleaseIcon(ICON_OTR,1); - } - return FALSE; -} - -extern "C" { - /* Return the OTR policy for the given context. */ - OtrlPolicy otr_gui_policy(void *opdata, ConnContext *context) { - DEBUGOUT_T("OTR_GUI_POLICY") - HANDLE hContact = (HANDLE)opdata; - DWORD pol; - if(hContact) { - pol = DBGetContactSettingDword(hContact, MODULENAME, "Policy", CONTACT_DEFAULT_POLICY); - if (options.bHaveSecureIM && pol != OTRL_POLICY_MANUAL_MOD && pol != OTRL_POLICY_NEVER && db_get_b(hContact, "SecureIM" , "StatusID", 0)) { - // if SecureIM is not disabled for this contact, MirOTR will be set to manual - db_set_dw(hContact, MODULENAME, "Policy", OTRL_POLICY_MANUAL_MOD); - return OTRL_POLICY_MANUAL_MOD; - } - if(pol != CONTACT_DEFAULT_POLICY) return pol ; - } - if(context->protocol) { - pol = db_get_dw(0,MODULENAME"_ProtoPol", context->protocol, CONTACT_DEFAULT_POLICY); - if(pol != CONTACT_DEFAULT_POLICY) return pol ; - } - - return options.default_policy ; - } - - /* Create a private key for the given accountname/protocol if - * desired. */ - void otr_gui_create_privkey(void *opdata, const char *account_name, const char *protocol) { - DEBUGOUT_T("OTR_GUI_CREATE_PRIVKEY") - //if(MessageBox(0, Translate("Would you like to generate a new private key for this protocol?"), Translate("OTR"), MB_YESNO) == IDYES) - //if(options.err_method == ED_POP) - //ShowPopup(Translate("Generating new private key."), 0 /*Translate("Please wait.")*/, 5); - - //NewKeyData *nkd = (NewKeyData *)malloc(sizeof(NewKeyData)); - //nkd->account_name = strdup(account_name); - //nkd->protocol = strdup(protocol); - - //DWORD tid; - //CloseHandle(CreateThread(0, 0, newKeyThread, (VOID *)nkd, 0, &tid)); - //QueueUserAPC(newKeyAPC, Global::mainThread, (DWORD)nkd); - if (opdata) protocol = contact_get_proto((HANDLE)opdata); - if (!protocol) return; - DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_GENKEYNOTIFY), 0, GenKeyDlgFunc, (LPARAM)protocol ); - - } - - /* Report whether you think the given user is online. Return 1 if - * you think he is, 0 if you think he isn't, -1 if you're not sure. - * - * If you return 1, messages such as heartbeats or other - * notifications may be sent to the user, which could result in "not - * logged in" errors if you're wrong. */ - int otr_gui_is_logged_in(void *opdata, const char *accountname, const char *protocol, const char *recipient) { - DEBUGOUT_T("OTR_GUI_IS_LOGGED_IN") - HANDLE hContact = (HANDLE)opdata; - if(hContact) { - WORD status = DBGetContactSettingWord(hContact, contact_get_proto(hContact), "Status", ID_STATUS_OFFLINE); - if(status == ID_STATUS_OFFLINE) return 0; - else return 1; - } - - return -1; - } - - /* Send the given IM to the given recipient from the given - * accountname/protocol. */ - void otr_gui_inject_message(void *opdata, const char *accountname, const char *protocol, const char *recipient, const char *message) { - DEBUGOUT_T("OTR_GUI_INJECT_MESSAGE") - //MessageBox(0, message, "OTR Inject", MB_OK); - HANDLE hContact = (HANDLE)opdata; - - if(protocol && DBGetContactSettingWord(hContact, protocol, "Status", ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) { - /* this would be with translation - TCHAR *decode = mir_utf8decodeT(message); - TCHAR *encode = mir_utf8encodeT(TranslateT(decide)); - mir_free(decode); - CallContactService(hContact, PSS_MESSAGE, PREF_UTF|PREF_BYPASS_OTR, (LPARAM)encode); - mir_free(encode); - */ - CallContactService(hContact, PSS_MESSAGE, PREF_UTF|PREF_BYPASS_OTR, (LPARAM)message); - //DEBUGOUT_T("INJECT") - } - } - - /* Display a notification message for a particular accountname / - * protocol / username conversation. */ - void otr_gui_notify(void *opdata, OtrlNotifyLevel level, const char *accountname, const char *protocol, const char *username, const char *title, const char *primary, const char *secondary) { - DEBUGOUT_T("OTR_GUI_NOTIFY") - const TCHAR* uname = contact_get_nameT((HANDLE)opdata); - TCHAR* title_t = mir_utf8decodeT(title); - TCHAR *notify = TranslateT(LANG_OTR_NOTIFY); - - size_t len = _tcslen(uname) + _tcslen(title_t) + _tcslen(notify); - TCHAR *buff1 = new TCHAR[len]; - mir_sntprintf(buff1, len, notify, TranslateTS(title_t), uname); - mir_free(title_t); - - len = strlen(primary) + strlen(secondary) + 5; - char *buff2 = new char[len]; - mir_snprintf(buff2, len, "%s\n%s", Translate(primary), Translate(secondary)); - TCHAR* buff2_t = mir_utf8decodeT(buff2); - delete buff2; - - DEBUGOUT_T("OTR_GUI_NOTIFY") - - ShowPopup(buff1, buff2_t, 0); - mir_free(buff2_t); - delete buff1; - } - - /* Display an OTR control message for a particular accountname / - * protocol / username conversation. Return 0 if you are able to - * successfully display it. If you return non-0 (or if this - * function is NULL), the control message will be displayed inline, - * as a received message, or else by using the above notify() - * callback. */ - int otr_gui_display_otr_message(void *opdata, const char *accountname, const char *protocol, const char *username, const char *msg) { - DEBUGOUT_T("OTR_GUI_DISPLAY_OTR_MESSAGE") - if(options.msg_inline) - ShowMessageInlineUtf((HANDLE)opdata, Translate(msg)); - if(options.msg_popup) { - TCHAR buff[512]; - TCHAR* proto = mir_a2t(protocol); - mir_sntprintf(buff, 512, TranslateT(LANG_OTR_USERMESSAGE), contact_get_nameT((HANDLE)opdata), proto); - mir_free(proto); - TCHAR *msg_t = mir_utf8decodeT(msg); - ShowPopup(buff, TranslateTS(msg_t), 0); - mir_free(msg_t); - } - return 0; - } - - /* When the list of ConnContexts changes (including a change in - * state), this is called so the UI can be updated. */ - void otr_gui_update_context_list(void *opdata) { - //MessageBox(0, "Update Context List", "OTR Callback", MB_OK); - DEBUGOUT_T("OTR: Update Context List"); - } - - /* Return a newly-allocated string containing a human-friendly name - * for the given protocol id */ - const char *otr_gui_protocol_name(void *opdata, const char *protocol) { - //return strdup(protocol); - DEBUGOUT_T("OTR_GUI_PROTOCOL_NAME") - return protocol; - } - - /* Deallocate a string allocated by protocol_name */ - void otr_gui_protocol_name_free(void *opdata, const char *protocol_name) { - //free((void *)protocol_name); - } - - /* A new fingerprint for the given user has been received. */ - void otr_gui_new_fingerprint(void *opdata, OtrlUserState us, const char *accountname, const char *protocol, const char *username, unsigned char fingerprint[20]) { - DEBUGOUT_T("OTR_GUI_NEW_FUNGERPRINT") - ConnContext *context = otrl_context_find(us, username, accountname, protocol, TRUE, 0, add_appdata, opdata); - Fingerprint *fp = otrl_context_find_fingerprint(context, fingerprint, TRUE, 0); - - //CloseHandle((HANDLE)_beginthreadex(0, 0, trust_fp_thread, (void *)fp, 0, 0)); - - otrl_context_set_trust(fp, NULL); - otrl_privkey_write_fingerprints(otr_user_state, g_fingerprint_store_filename); - } - - /* The list of known fingerprints has changed. Write them to disk. */ - void otr_gui_write_fingerprints(void *opdata) { - DEBUGOUT_T("OTR_GUI_WRITE_FINGERPRINTS") - //if(MessageBox(0, Translate("Would you like to save the current fingerprint list?"), Translate(MODULE), MB_YESNO) == IDYES) - otrl_privkey_write_fingerprints(otr_user_state, g_fingerprint_store_filename); - } - - /* A ConnContext has entered a secure state. */ - void otr_gui_gone_secure(void *opdata, ConnContext *context) { - DEBUGOUT_T("OTR_GUI_GONE_SECURE") - TrustLevel trusted = otr_context_get_trust(context); - // opdata is hContact - SetEncryptionStatus((HANDLE)opdata, trusted); - TCHAR buff[1024]; - if(trusted == TRUST_PRIVATE) { - mir_sntprintf(buff, 1024, TranslateT(LANG_SESSION_START_OTR), contact_get_nameT((HANDLE)opdata)); - } else if (trusted == TRUST_UNVERIFIED) { - if (options.autoshow_verify) SMPInitDialog(context); //VerifyContextDialog(context); - mir_sntprintf(buff, 1024, TranslateT(LANG_SESSION_START_OTR_VERIFY), contact_get_nameT((HANDLE)opdata)); - } else { // should never happen - mir_sntprintf(buff, 1024, TranslateT(LANG_SESSION_NOT_STARTED_OTR), contact_get_nameT((HANDLE)opdata)); - } - // opdata is hContact - ShowMessage((HANDLE)opdata, buff); - - } - - /* A ConnContext has left a secure state. */ - void otr_gui_gone_insecure(void *opdata, ConnContext *context) { - DEBUGOUT_T("OTR_GUI_GONE_INSECURE") - TCHAR buff[512]; - mir_sntprintf(buff, 512, TranslateT(LANG_SESSION_TERMINATED_BY_OTR), contact_get_nameT((HANDLE)opdata)); - //MessageBox(0, buff, Translate("OTR Information"), MB_OK); - if (!Miranda_Terminated()) { - ShowMessage((HANDLE)opdata, buff); - } - - // opdata is hContact - SetEncryptionStatus((HANDLE)opdata, otr_context_get_trust(context)); - } - - /* We have completed an authentication, using the D-H keys we - * already knew. is_reply indicates whether we initiated the AKE. */ - void otr_gui_still_secure(void *opdata, ConnContext *context, int is_reply) { - DEBUGOUT_T("OTR_GUI_STILL_SECURE") - TrustLevel trusted = otr_context_get_trust(context); - SetEncryptionStatus((HANDLE)opdata, trusted); - TCHAR buff[1024]; - if (!is_reply) { - if(trusted == TRUST_PRIVATE) { - mir_sntprintf(buff, 1024, TranslateT(LANG_SESSION_CONTINUE_OTR), contact_get_nameT((HANDLE)opdata)); - } else if (trusted == TRUST_UNVERIFIED) { - if (options.autoshow_verify) SMPInitDialog(context); //VerifyContextDialog(context); - mir_sntprintf(buff, 1024, TranslateT(LANG_SESSION_CONTINUE_OTR_VERIFY), contact_get_nameT((HANDLE)opdata)); - } else { // should never happen - mir_sntprintf(buff, 1024, TranslateT(LANG_SESSION_NOT_STARTED_OTR), contact_get_nameT((HANDLE)opdata)); - } - // opdata is hContact - ShowMessage((HANDLE)opdata, buff); - } else { - if(trusted == TRUST_PRIVATE) { - mir_sntprintf(buff, 1024, TranslateT(LANG_SESSION_HAS_CONTINUE_OTR), contact_get_nameT((HANDLE)opdata)); - } else if (trusted == TRUST_UNVERIFIED) { - mir_sntprintf(buff, 1024, TranslateT(LANG_SESSION_HAS_CONTINUE_OTR_VERIFY), contact_get_nameT((HANDLE)opdata)); - } else { // should never happen - mir_sntprintf(buff, 1024, TranslateT(LANG_SESSION_NOT_STARTED_OTR), contact_get_nameT((HANDLE)opdata)); - } - - } - SetEncryptionStatus((HANDLE)opdata, trusted); - } - - /* Log a message. The passed message will end in "\n". */ - void otr_gui_log_message(void *opdata, const char *message) { - //MessageBox(0, message, Translate("OTR Log Message"), MB_OK); - //ShowMessageInline((HANDLE)opdata, message); -#ifdef _DEBUG - char* msg = strcpy((char*)mir_alloc(strlen(message)+15), "OTR message: "); - strcat(msg, message); - DEBUGOUTA(msg) - mir_free(msg); -#endif - } - - int max_message_size(void *opdata, ConnContext *context) { - const char *proto; - if (context && context->protocol) - proto = context->protocol; - else - proto = contact_get_proto(opdata); - // ugly wokaround for ICQ. ICQ protocol reports more than 7k, but in SMP this is too long. - // possibly ICQ doesn't allow single words without spaces to become longer than ~2340? - if (strcmp("ICQ", proto)==0 || strncmp("ICQ_", proto, 4)==0) - return 2340; - return CallProtoService(proto, PS_GETCAPS, PFLAG_MAXLENOFMESSAGE, (LPARAM)opdata); - } - - const char *account_name(void *opdata, const char *account, const char *protocol) { - return account; - } - - void account_name_free(void *opdata, const char *account_name) { - } - - void add_appdata(void *data, ConnContext *context) { - if(context) context->app_data = data; - } -} - -// Forward decl -gcry_error_t otrl_privkey_write_FILEp(OtrlUserState us, FILE *privf); -/* Generate a private DSA key for a given account, storing it into a -* file on disk, and loading it into the given OtrlUserState. Overwrite any -* previously generated keys for that account in that OtrlUserState. */ - gcry_error_t otrl_privkey_write(OtrlUserState us, const char *filename) - { - gcry_error_t err; - FILE *privf; - #ifndef WIN32 - mode_t oldmask; - #endif - - #ifndef WIN32 - oldmask = umask(077); - #endif - privf = fopen(filename, "w+b"); - if (!privf) { - #ifndef WIN32 - umask(oldmask); - #endif - err = gcry_error_from_errno(errno); - return err; - } - - err = otrl_privkey_write_FILEp(us, privf); - - fclose(privf); - #ifndef WIN32 - umask(oldmask); - #endif - return err; - } - -/* Just store the private keys of an OtrlUserState. - * The FILE* must be open for reading and writing. */ - gcry_error_t otrl_privkey_write_FILEp(OtrlUserState us, FILE *privf) - { - OtrlPrivKey *p; - - if (!privf) return gcry_error(GPG_ERR_NO_ERROR); - - - - /* Output the other keys we know */ - fprintf(privf, "(privkeys\n"); - for (p=us->privkey_root; p; p=p->next) { - otrl_account_write(privf, p->accountname, p->protocol, p->privkey); - } - if ( fprintf(privf, ")\n") < 0 ) - return gcry_error_from_errno(errno); - return gcry_error(GPG_ERR_NO_ERROR); - -} \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/otr.h b/plugins/MirOTR/MirOTR/otr.h deleted file mode 100644 index 110bcd9485..0000000000 --- a/plugins/MirOTR/MirOTR/otr.h +++ /dev/null @@ -1,53 +0,0 @@ -#pragma once - -#include "stdafx.h" - -extern OtrlUserState otr_user_state; -extern OtrlMessageAppOps ops; - -extern "C" { - - /* Return the OTR policy for the given context. */ - OtrlPolicy otr_gui_policy(void *opdata, ConnContext *context); - - /* Create a private key for the given accountname/protocol if - * desired. */ - void otr_gui_create_privkey(void *opdata, const char *account_name, const char *protocol); - - int otr_gui_is_logged_in(void *opdata, const char *accountname, const char *protocol, const char *recipient); - - void otr_gui_inject_message(void *opdata, const char *accountname, const char *protocol, const char *recipient, const char *message); - - void otr_gui_notify(void *opdata, OtrlNotifyLevel level, const char *accountname, const char *protocol, const char *username, const char *title, const char *primary, const char *secondary); - - int otr_gui_display_otr_message(void *opdata, const char *accountname, const char *protocol, const char *username, const char *msg); - - void otr_gui_update_context_list(void *opdata); - - const char *otr_gui_protocol_name(void *opdata, const char *protocol); - - void otr_gui_protocol_name_free(void *opdata, const char *protocol_name); - - void otr_gui_new_fingerprint(void *opdata, OtrlUserState us, const char *accountname, const char *protocol, const char *username, unsigned char fingerprint[20]); - - void otr_gui_write_fingerprints(void *opdata); - - void otr_gui_gone_secure(void *opdata, ConnContext *context); - - void otr_gui_gone_insecure(void *opdata, ConnContext *context); - - void otr_gui_still_secure(void *opdata, ConnContext *context, int is_reply); - - void otr_gui_log_message(void *opdata, const char *message); - - int max_message_size(void *opdata, ConnContext *context); - - const char *account_name(void *opdata, const char *account, const char *protocol); - - void account_name_free(void *opdata, const char *account_name); - - void add_appdata(void *data, ConnContext *context); - -} - -gcry_error_t otrl_privkey_write(OtrlUserState us, const char *filename); \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/res/finished.ico b/plugins/MirOTR/MirOTR/res/finished.ico new file mode 100644 index 0000000000..870cd0a216 Binary files /dev/null and b/plugins/MirOTR/MirOTR/res/finished.ico differ diff --git a/plugins/MirOTR/MirOTR/res/insecure.ico b/plugins/MirOTR/MirOTR/res/insecure.ico new file mode 100644 index 0000000000..4a72fe3ff4 Binary files /dev/null and b/plugins/MirOTR/MirOTR/res/insecure.ico differ diff --git a/plugins/MirOTR/MirOTR/res/otr.ico b/plugins/MirOTR/MirOTR/res/otr.ico new file mode 100644 index 0000000000..298a3baf2e Binary files /dev/null and b/plugins/MirOTR/MirOTR/res/otr.ico differ diff --git a/plugins/MirOTR/MirOTR/res/private.ico b/plugins/MirOTR/MirOTR/res/private.ico new file mode 100644 index 0000000000..b7c8585b88 Binary files /dev/null and b/plugins/MirOTR/MirOTR/res/private.ico differ diff --git a/plugins/MirOTR/MirOTR/res/refresh.ico b/plugins/MirOTR/MirOTR/res/refresh.ico new file mode 100644 index 0000000000..45fbbf2e7c Binary files /dev/null and b/plugins/MirOTR/MirOTR/res/refresh.ico differ diff --git a/plugins/MirOTR/MirOTR/res/resource.rc b/plugins/MirOTR/MirOTR/res/resource.rc new file mode 100644 index 0000000000..da2a1cb26d --- /dev/null +++ b/plugins/MirOTR/MirOTR/res/resource.rc @@ -0,0 +1,134 @@ +#ifndef IDCANCEL + #define IDCANCEL 2 +#endif +#ifndef IDOK + #define IDOK 1 +#endif + +#include "windows.h" +#include "..\src\resource.h" + +LANGUAGE 9,0 + +IDI_OTR ICON DISCARDABLE "otr.ico" +IDI_REFRESH ICON DISCARDABLE "refresh.ico" +IDI_INSECURE ICON DISCARDABLE "insecure.ico" +IDI_UNVERIFIED ICON DISCARDABLE "unverified.ico" +IDI_PRIVATE ICON DISCARDABLE "private.ico" +IDI_FINISHED ICON DISCARDABLE "finished.ico" + +IDD_GENKEYNOTIFY DIALOGEX 0,0,270,33 +CAPTION "OTR Generating Private Key" +FONT 8,"MS Shell Dlg",0,0,0 +STYLE WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|DS_CENTER|DS_SETFOREGROUND|DS_MODALFRAME|DS_SETFONT|0xC0000000 +BEGIN + CONTROL "Generating new private key - please wait.",IDC_GENERATE,"Static",WS_CHILDWINDOW|WS_VISIBLE|WS_GROUP|SS_CENTER,33,3,201,27 + CONTROL IDI_OTR,IDC_ICOOTR,"Static",WS_CHILDWINDOW|WS_VISIBLE|SS_CENTERIMAGE|SS_ICON,0,0,32,32 + CONTROL IDI_REFRESH,IDC_ICOREFRESH,"Static",WS_CHILDWINDOW|WS_VISIBLE|SS_CENTERIMAGE|SS_ICON,237,0,32,32 +END + +IDD_OPT_GENERAL DIALOGEX 0,0,296,220 +FONT 8,"MS Shell Dlg",0,0,1 +STYLE WS_CHILDWINDOW|WS_VISIBLE|DS_SHELLFONT +EXSTYLE WS_EX_CONTROLPARENT +BEGIN + CONTROL "",IDC_STATIC,"Static",WS_VISIBLE|WS_TABSTOP,0,0,1,1 + CONTROL "Default Policy",IDC_GRP_POLICY,"Button",WS_CHILDWINDOW|WS_VISIBLE|BS_GROUPBOX,5,3,139,60 + CONTROL "Always",IDC_RAD_ALWAYS,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTORADIOBUTTON,12,12,126,10 + CONTROL "Opportunistic",IDC_RAD_OPP,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTORADIOBUTTON,12,24,126,10 + CONTROL "Manual",IDC_RAD_MANUAL,"Button",WS_VISIBLE|WS_GROUP|WS_TABSTOP|BS_AUTORADIOBUTTON,12,36,126,10 + CONTROL "Never",IDC_RAD_NEVER,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTORADIOBUTTON,12,48,126,10 + CONTROL "End sessions on window close",IDC_CHK_ENDCLOSE,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,12,70,265,10 + CONTROL "End sessions when contacts go offline",IDC_CHK_ENDOFFLINE,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,12,82,265,10 + CONTROL "Prefix encrypted IMs:",IDC_CHK_PREFIX,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,12,94,108,10 + CONTROL "",IDC_ED_PREFIX,"Edit",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|ES_AUTOHSCROLL,120,93,159,12,WS_EX_CLIENTEDGE + CONTROL "Don't add encrypted messages to the history",IDC_CHK_PREVENTSAVE,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,12,106,265,10 + CONTROL "Also remove OTR system messages",IDC_CHK_PREVENTSYSSAVE,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,12,117,245,10 + CONTROL "Show OTR system messages inline",IDC_CHK_MSGINLINE,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,12,130,265,10 + CONTROL "Show OTR system messages as popup",IDC_CHK_MSGPOPUP,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,12,142,265,10 + CONTROL "Timeout FINISHED sessions back to PLAINTEXT (TAKE CARE!)",IDC_CHK_TIMEFINISH,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,12,154,265,10 + CONTROL "Show verification dialog when receiving unverified fingerprint",IDC_CHK_AUTOSHOW_VERIFY,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,12,166,265,10 +END + +IDD_OPT_PROTO DIALOGEX 0,0,296,220 +FONT 8,"MS Shell Dlg",0,0,1 +STYLE WS_CHILDWINDOW|WS_VISIBLE|DS_SHELLFONT +EXSTYLE WS_EX_CONTROLPARENT +BEGIN + CONTROL "Set OTR policy per protocol",IDC_STC_PROTO1,"Static",WS_CHILDWINDOW|WS_VISIBLE|SS_NOPREFIX,3,3,291,12 + CONTROL "",IDC_LV_PROTO_PROTOS,"SysListView32",WS_VISIBLE|WS_BORDER|WS_TABSTOP|LVS_SORTASCENDING|LVS_SHOWSELALWAYS|LVS_SINGLESEL|LVS_REPORT,0,18,296,165 + CONTROL "Current policy:",IDC_STC_PROTO2,"Static",WS_CHILDWINDOW|WS_VISIBLE|SS_NOPREFIX,3,189,138,9 + CONTROL "",IDC_CMB_PROTO_POLICY,"ComboBox",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|CBS_HASSTRINGS|CBS_DROPDOWNLIST,3,201,138,12 + CONTROL "Generate new private key",IDC_BTN_PROTO_NEWKEY,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,162,186,123,18 + CONTROL "Forget private key",IDC_BTN_PROTO_FORGET,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,162,207,123,12 +END + +IDD_OPT_CONTACTS DIALOGEX 0,0,296,220 +FONT 8,"MS Shell Dlg",0,0,1 +STYLE WS_CHILDWINDOW|WS_VISIBLE|DS_SHELLFONT +EXSTYLE WS_EX_CONTROLPARENT +BEGIN + CONTROL "Set OTR policy per contact",IDC_STC_CONT1,"Static",WS_CHILDWINDOW|WS_VISIBLE|SS_NOPREFIX,3,3,291,12 + CONTROL "",IDC_LV_CONT_CONTACTS,"SysListView32",WS_VISIBLE|WS_BORDER|WS_TABSTOP|LVS_SORTASCENDING|LVS_SHOWSELALWAYS|LVS_SINGLESEL|LVS_REPORT,0,18,296,180 + CONTROL "Current policy:",IDC_STC_CONT2,"Static",WS_CHILDWINDOW|WS_VISIBLE|SS_NOPREFIX,3,204,129,9 + CONTROL "",IDC_CMB_CONT_POLICY,"ComboBox",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|CBS_HASSTRINGS|CBS_DROPDOWNLIST,138,201,153,12 +END + +IDD_OPT_FINGER DIALOGEX 0,0,296,220 +FONT 8,"MS Shell Dlg",0,0,1 +STYLE WS_CHILDWINDOW|WS_VISIBLE|DS_SHELLFONT +EXSTYLE WS_EX_CONTROLPARENT +BEGIN + CONTROL "View & Modify status of known fingerprints",IDC_STC_FINGER1,"Static",WS_CHILDWINDOW|WS_VISIBLE|SS_NOPREFIX,3,3,291,12 + CONTROL "",IDC_LV_FINGER_LIST,"SysListView32",WS_VISIBLE|WS_BORDER|WS_TABSTOP|LVS_SORTASCENDING|LVS_SHOWSELALWAYS|LVS_SINGLESEL|LVS_REPORT,0,18,296,171 + CONTROL "Set verified",IDC_BTN_FINGER_TRUST,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,3,195,66,18 + CONTROL "Set unknown",IDC_BTN_FINGER_DONTTRUST,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,72,195,66,18 + CONTROL "Forget",IDC_BTN_FINGER_FORGET,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,225,195,66,18 +END + +IDR_CONTEXT MENU +BEGIN + POPUP "MirOTR" + BEGIN + MENUITEM "OTR status",IDM_OTR_STATUS,GRAYED + MENUITEM SEPARATOR + MENUITEM "&Start OTR session",IDM_OTR_START + MENUITEM "&Refresh OTR session",IDM_OTR_REFRESH + MENUITEM "Sto&p OTR session",IDM_OTR_STOP + MENUITEM SEPARATOR + MENUITEM "&Verify Fingerprint",IDM_OTR_VERIFY + END +END + +IDD_SMP_PROGRESS DIALOGEX 10,10,200,100 +CAPTION "Socialist Millionaires Protocol" +FONT 8,"MS Sans Serif",0,0,0 +STYLE WS_POPUP|WS_VISIBLE|WS_CAPTION|DS_CENTER|DS_SETFOREGROUND|DS_MODALFRAME +BEGIN + CONTROL IDI_OTR,IDC_ICO_SMP,"Static",WS_CHILDWINDOW|WS_VISIBLE|SS_CENTERIMAGE|SS_ICON,3,3,32,32 + CONTROL "Socialist Millionaires Protocol\r\nVerification progress",IDC_STC_SMP_HEADPRO,"Static",WS_CHILDWINDOW|WS_VISIBLE|SS_NOPREFIX,39,9,156,21 + CONTROL "",IDC_PGB_SMP,"msctls_progress32",WS_CHILDWINDOW|WS_VISIBLE|PBS_SMOOTH,3,36,194,18 + CONTROL "",IDC_STC_SMP_PROGRESS,"Static",WS_CHILDWINDOW|WS_VISIBLE,3,57,194,20 + CONTROL "&Cancel",IDCANCEL,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,70,80,60,16 + CONTROL "&OK",IDOK,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,135,80,60,16 +END + +IDD_SMP_INPUT DIALOGEX 10,10,200,200 +CAPTION "Socialist Millionaires Protocol" +FONT 8,"MS Sans Serif",0,0,0 +STYLE WS_VISIBLE|WS_CAPTION|WS_SYSMENU|DS_SETFOREGROUND|DS_MODALFRAME +BEGIN + CONTROL IDI_OTR,IDC_ICO_SMP,"Static",WS_CHILDWINDOW|WS_VISIBLE|SS_CENTERIMAGE|SS_ICON,3,3,32,32 + CONTROL "Socialist Millionaires Protocol\r\nVerification",IDC_STC_SMP_HEAD,"Static",WS_CHILDWINDOW|WS_VISIBLE|SS_NOPREFIX,39,9,156,21 + CONTROL "",IDC_CBO_SMP_CHOOSE,"ComboBox",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|CBS_HASSTRINGS|CBS_DROPDOWNLIST,3,36,194,60 + CONTROL "",IDC_STC_SMP_INFO,"Static",WS_CHILDWINDOW|WS_VISIBLE,3,60,194,35 + CONTROL "",IDC_STC_SMP_FIELD1,"Static",WS_CHILDWINDOW|WS_VISIBLE,3,105,194,10 + CONTROL "",IDC_EDT_SMP_FIELD1,"Edit",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,3,117,194,13,WS_EX_CLIENTEDGE + CONTROL "",IDC_STC_SMP_FIELD2,"Static",WS_CHILDWINDOW|WS_VISIBLE,3,141,194,10 + CONTROL "",IDC_EDT_SMP_FIELD2,"Edit",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,3,153,194,13,WS_EX_CLIENTEDGE + CONTROL "&Cancel",IDCANCEL,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,3,180,60,16 + CONTROL "&OK",IDOK,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,135,180,60,16 + CONTROL "&No",IDNO,"Button",NOT WS_VISIBLE|WS_CHILDWINDOW|WS_TABSTOP,70,180,60,16 + CONTROL "&Yes",IDYES,"Button",NOT WS_VISIBLE|WS_CHILDWINDOW|WS_TABSTOP,135,180,60,16 +END + diff --git a/plugins/MirOTR/MirOTR/res/unverified.ico b/plugins/MirOTR/MirOTR/res/unverified.ico new file mode 100644 index 0000000000..95cc6629fa Binary files /dev/null and b/plugins/MirOTR/MirOTR/res/unverified.ico differ diff --git a/plugins/MirOTR/MirOTR/res/version.rc b/plugins/MirOTR/MirOTR/res/version.rc new file mode 100644 index 0000000000..232f2dc04c --- /dev/null +++ b/plugins/MirOTR/MirOTR/res/version.rc @@ -0,0 +1,42 @@ +// Microsoft Visual C++ generated resource script. +// +#ifdef APSTUDIO_INVOKED +#error this file is not editable by Microsoft Visual C++ +#endif //APSTUDIO_INVOKED + +#include "afxres.h" +#include "..\src\version.h" + +#ifdef _WIN32 +LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL +#endif //_WIN32 + +VS_VERSION_INFO VERSIONINFO + FILEVERSION VER_MAJOR,VER_MINOR,VER_RELEASE,VER_BUILD + PRODUCTVERSION VER_MAJOR,VER_MINOR,VER_RELEASE,VER_BUILD + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x0L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000004b0" + BEGIN + VALUE "FileDescription", FILE_DESCRIPTION + VALUE "InternalName", INTERNAL_NAME + VALUE "LegalCopyright", LEGAL_COPYRIGHT + VALUE "OriginalFilename", ORIGINAL_FILENAME + VALUE "ProductName", PRODUCT_NAME + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0, 1200 + END +END diff --git a/plugins/MirOTR/MirOTR/resource.h b/plugins/MirOTR/MirOTR/resource.h deleted file mode 100644 index b861799546..0000000000 --- a/plugins/MirOTR/MirOTR/resource.h +++ /dev/null @@ -1,104 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by resource.rc -// -#ifndef IDOK - #define IDOK 1 -#endif -#ifndef IDCANCEL - #define IDCANCEL 2 -#endif -#define IDD_GENKEYNOTIFY 101 -#define IDD_OPT_GENERAL 102 -#define IDD_OPT_PROTO 103 -#define IDD_OPT_CONTACTS 104 -#define IDD_OPT_FINGER 105 -#define IDD_SMP_INPUT 106 -#define IDD_SMP_PROGRESS 107 - -// General Options -#define IDC_GRP_POLICY 1051 -#define IDC_RAD_ALWAYS 1052 -#define IDC_RAD_OPP 1053 -#define IDC_RAD_MANUAL 1054 -#define IDC_RAD_NEVER 1055 - -#define IDC_CHK_PREFIX 1056 -#define IDC_ED_PREFIX 1057 -#define IDC_CHK_MSGINLINE 1058 -#define IDC_CHK_MSGPOPUP 1059 -#define IDC_CHK_PREVENTSAVE 1060 -#define IDC_CHK_AUTOSHOW_VERIFY 1061 -#define IDC_CHK_TIMEFINISH 1062 -#define IDC_CHK_ENDOFFLINE 1063 -#define IDC_CHK_ENDCLOSE 1064 -#define IDC_CHK_PREVENTSYSSAVE 1065 - -// Proto policy & keys -#define IDC_LV_PROTO_PROTOS 1101 -#define IDC_BTN_PROTO_NEWKEY 1102 -#define IDC_CMB_PROTO_POLICY 1103 -#define IDC_BTN_PROTO_FORGET 1104 -#define IDC_STC_PROTO1 1151 -#define IDC_STC_PROTO2 1152 - -// User policy -#define IDC_LV_CONT_CONTACTS 1201 -#define IDC_CMB_CONT_POLICY 1202 -#define IDC_STC_CONT1 1251 -#define IDC_STC_CONT2 1252 - -// User fingerprints -#define IDC_LV_FINGER_LIST 1301 -#define IDC_BTN_FINGER_FORGET 1302 -#define IDC_BTN_FINGER_TRUST 1303 -#define IDC_BTN_FINGER_DONTTRUST 1304 -#define IDC_STC_FINGER1 1351 - -// Generate dialog -#define IDC_GENERATE 1401 -#define IDC_ICOOTR 1402 -#define IDC_ICOREFRESH 1403 - -// SMP Progress -#define IDC_PGB_SMP 1501 -#define IDC_STC_SMP_HEADPRO 1502 -#define IDC_ICO_SMP 1503 -#define IDC_STC_SMP_PROGRESS 1504 - -// SMP Dialog -#define IDC_STC_SMP_HEAD 1602 -#define IDC_CBO_SMP_CHOOSE 1603 -#define IDC_STC_SMP_INFO 1604 -#define IDC_STC_SMP_FIELD1 1605 -#define IDC_EDT_SMP_FIELD1 1606 -#define IDC_STC_SMP_FIELD2 1607 -#define IDC_EDT_SMP_FIELD2 1608 - -#define IDI_OTR 2000 -#define IDI_REFRESH 2001 -#define IDI_INSECURE 2002 -#define IDI_UNVERIFIED 2003 -#define IDI_PRIVATE 2004 -#define IDI_FINISHED 2005 - -#define IDC_STATIC -1 - -#define IDM_OTR_MENU 10001 -#define IDR_CONTEXT 10000 -#define IDM_OTR_STATUS 10001 -#define IDM_OTR_START 10002 -#define IDM_OTR_REFRESH 10003 -#define IDM_OTR_STOP 10004 -#define IDM_OTR_VERIFY 10005 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 101 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1001 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/plugins/MirOTR/MirOTR/resources/finished.ico b/plugins/MirOTR/MirOTR/resources/finished.ico deleted file mode 100644 index 870cd0a216..0000000000 Binary files a/plugins/MirOTR/MirOTR/resources/finished.ico and /dev/null differ diff --git a/plugins/MirOTR/MirOTR/resources/insecure.ico b/plugins/MirOTR/MirOTR/resources/insecure.ico deleted file mode 100644 index 4a72fe3ff4..0000000000 Binary files a/plugins/MirOTR/MirOTR/resources/insecure.ico and /dev/null differ diff --git a/plugins/MirOTR/MirOTR/resources/otr.ico b/plugins/MirOTR/MirOTR/resources/otr.ico deleted file mode 100644 index 298a3baf2e..0000000000 Binary files a/plugins/MirOTR/MirOTR/resources/otr.ico and /dev/null differ diff --git a/plugins/MirOTR/MirOTR/resources/private.ico b/plugins/MirOTR/MirOTR/resources/private.ico deleted file mode 100644 index b7c8585b88..0000000000 Binary files a/plugins/MirOTR/MirOTR/resources/private.ico and /dev/null differ diff --git a/plugins/MirOTR/MirOTR/resources/refresh.ico b/plugins/MirOTR/MirOTR/resources/refresh.ico deleted file mode 100644 index 45fbbf2e7c..0000000000 Binary files a/plugins/MirOTR/MirOTR/resources/refresh.ico and /dev/null differ diff --git a/plugins/MirOTR/MirOTR/resources/resource.rc b/plugins/MirOTR/MirOTR/resources/resource.rc deleted file mode 100644 index edb1e714c4..0000000000 --- a/plugins/MirOTR/MirOTR/resources/resource.rc +++ /dev/null @@ -1,134 +0,0 @@ -#ifndef IDCANCEL - #define IDCANCEL 2 -#endif -#ifndef IDOK - #define IDOK 1 -#endif - -#include "windows.h" -#include "../resource.h" - -LANGUAGE 9,0 - -IDI_OTR ICON DISCARDABLE "otr.ico" -IDI_REFRESH ICON DISCARDABLE "refresh.ico" -IDI_INSECURE ICON DISCARDABLE "insecure.ico" -IDI_UNVERIFIED ICON DISCARDABLE "unverified.ico" -IDI_PRIVATE ICON DISCARDABLE "private.ico" -IDI_FINISHED ICON DISCARDABLE "finished.ico" - -IDD_GENKEYNOTIFY DIALOGEX 0,0,270,33 -CAPTION "OTR Generating Private Key" -FONT 8,"MS Shell Dlg",0,0,0 -STYLE WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|DS_CENTER|DS_SETFOREGROUND|DS_MODALFRAME|DS_SETFONT|0xC0000000 -BEGIN - CONTROL "Generating new private key - please wait.",IDC_GENERATE,"Static",WS_CHILDWINDOW|WS_VISIBLE|WS_GROUP|SS_CENTER,33,3,201,27 - CONTROL IDI_OTR,IDC_ICOOTR,"Static",WS_CHILDWINDOW|WS_VISIBLE|SS_CENTERIMAGE|SS_ICON,0,0,32,32 - CONTROL IDI_REFRESH,IDC_ICOREFRESH,"Static",WS_CHILDWINDOW|WS_VISIBLE|SS_CENTERIMAGE|SS_ICON,237,0,32,32 -END - -IDD_OPT_GENERAL DIALOGEX 0,0,296,220 -FONT 8,"MS Shell Dlg",0,0,1 -STYLE WS_CHILDWINDOW|WS_VISIBLE|DS_SHELLFONT -EXSTYLE WS_EX_CONTROLPARENT -BEGIN - CONTROL "",IDC_STATIC,"Static",WS_VISIBLE|WS_TABSTOP,0,0,1,1 - CONTROL "Default Policy",IDC_GRP_POLICY,"Button",WS_CHILDWINDOW|WS_VISIBLE|BS_GROUPBOX,5,3,139,60 - CONTROL "Always",IDC_RAD_ALWAYS,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTORADIOBUTTON,12,12,126,10 - CONTROL "Opportunistic",IDC_RAD_OPP,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTORADIOBUTTON,12,24,126,10 - CONTROL "Manual",IDC_RAD_MANUAL,"Button",WS_VISIBLE|WS_GROUP|WS_TABSTOP|BS_AUTORADIOBUTTON,12,36,126,10 - CONTROL "Never",IDC_RAD_NEVER,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTORADIOBUTTON,12,48,126,10 - CONTROL "End sessions on window close",IDC_CHK_ENDCLOSE,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,12,70,265,10 - CONTROL "End sessions when contacts go offline",IDC_CHK_ENDOFFLINE,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,12,82,265,10 - CONTROL "Prefix encrypted IMs:",IDC_CHK_PREFIX,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,12,94,108,10 - CONTROL "",IDC_ED_PREFIX,"Edit",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|ES_AUTOHSCROLL,120,93,159,12,WS_EX_CLIENTEDGE - CONTROL "Don't add encrypted messages to the history",IDC_CHK_PREVENTSAVE,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,12,106,265,10 - CONTROL "Also remove OTR system messages",IDC_CHK_PREVENTSYSSAVE,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,12,117,245,10 - CONTROL "Show OTR system messages inline",IDC_CHK_MSGINLINE,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,12,130,265,10 - CONTROL "Show OTR system messages as popup",IDC_CHK_MSGPOPUP,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,12,142,265,10 - CONTROL "Timeout FINISHED sessions back to PLAINTEXT (TAKE CARE!)",IDC_CHK_TIMEFINISH,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,12,154,265,10 - CONTROL "Show verification dialog when receiving unverified fingerprint",IDC_CHK_AUTOSHOW_VERIFY,"Button",WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,12,166,265,10 -END - -IDD_OPT_PROTO DIALOGEX 0,0,296,220 -FONT 8,"MS Shell Dlg",0,0,1 -STYLE WS_CHILDWINDOW|WS_VISIBLE|DS_SHELLFONT -EXSTYLE WS_EX_CONTROLPARENT -BEGIN - CONTROL "Set OTR policy per protocol",IDC_STC_PROTO1,"Static",WS_CHILDWINDOW|WS_VISIBLE|SS_NOPREFIX,3,3,291,12 - CONTROL "",IDC_LV_PROTO_PROTOS,"SysListView32",WS_VISIBLE|WS_BORDER|WS_TABSTOP|LVS_SORTASCENDING|LVS_SHOWSELALWAYS|LVS_SINGLESEL|LVS_REPORT,0,18,296,165 - CONTROL "Current policy:",IDC_STC_PROTO2,"Static",WS_CHILDWINDOW|WS_VISIBLE|SS_NOPREFIX,3,189,138,9 - CONTROL "",IDC_CMB_PROTO_POLICY,"ComboBox",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|CBS_HASSTRINGS|CBS_DROPDOWNLIST,3,201,138,12 - CONTROL "Generate new private key",IDC_BTN_PROTO_NEWKEY,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,162,186,123,18 - CONTROL "Forget private key",IDC_BTN_PROTO_FORGET,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,162,207,123,12 -END - -IDD_OPT_CONTACTS DIALOGEX 0,0,296,220 -FONT 8,"MS Shell Dlg",0,0,1 -STYLE WS_CHILDWINDOW|WS_VISIBLE|DS_SHELLFONT -EXSTYLE WS_EX_CONTROLPARENT -BEGIN - CONTROL "Set OTR policy per contact",IDC_STC_CONT1,"Static",WS_CHILDWINDOW|WS_VISIBLE|SS_NOPREFIX,3,3,291,12 - CONTROL "",IDC_LV_CONT_CONTACTS,"SysListView32",WS_VISIBLE|WS_BORDER|WS_TABSTOP|LVS_SORTASCENDING|LVS_SHOWSELALWAYS|LVS_SINGLESEL|LVS_REPORT,0,18,296,180 - CONTROL "Current policy:",IDC_STC_CONT2,"Static",WS_CHILDWINDOW|WS_VISIBLE|SS_NOPREFIX,3,204,129,9 - CONTROL "",IDC_CMB_CONT_POLICY,"ComboBox",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|CBS_HASSTRINGS|CBS_DROPDOWNLIST,138,201,153,12 -END - -IDD_OPT_FINGER DIALOGEX 0,0,296,220 -FONT 8,"MS Shell Dlg",0,0,1 -STYLE WS_CHILDWINDOW|WS_VISIBLE|DS_SHELLFONT -EXSTYLE WS_EX_CONTROLPARENT -BEGIN - CONTROL "View & Modify status of known fingerprints",IDC_STC_FINGER1,"Static",WS_CHILDWINDOW|WS_VISIBLE|SS_NOPREFIX,3,3,291,12 - CONTROL "",IDC_LV_FINGER_LIST,"SysListView32",WS_VISIBLE|WS_BORDER|WS_TABSTOP|LVS_SORTASCENDING|LVS_SHOWSELALWAYS|LVS_SINGLESEL|LVS_REPORT,0,18,296,171 - CONTROL "Set verified",IDC_BTN_FINGER_TRUST,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,3,195,66,18 - CONTROL "Set unknown",IDC_BTN_FINGER_DONTTRUST,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,72,195,66,18 - CONTROL "Forget",IDC_BTN_FINGER_FORGET,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,225,195,66,18 -END - -IDR_CONTEXT MENU -BEGIN - POPUP "MirOTR" - BEGIN - MENUITEM "OTR status",IDM_OTR_STATUS,GRAYED - MENUITEM SEPARATOR - MENUITEM "&Start OTR session",IDM_OTR_START - MENUITEM "&Refresh OTR session",IDM_OTR_REFRESH - MENUITEM "Sto&p OTR session",IDM_OTR_STOP - MENUITEM SEPARATOR - MENUITEM "&Verify Fingerprint",IDM_OTR_VERIFY - END -END - -IDD_SMP_PROGRESS DIALOGEX 10,10,200,100 -CAPTION "Socialist Millionaires Protocol" -FONT 8,"MS Sans Serif",0,0,0 -STYLE WS_POPUP|WS_VISIBLE|WS_CAPTION|DS_CENTER|DS_SETFOREGROUND|DS_MODALFRAME -BEGIN - CONTROL IDI_OTR,IDC_ICO_SMP,"Static",WS_CHILDWINDOW|WS_VISIBLE|SS_CENTERIMAGE|SS_ICON,3,3,32,32 - CONTROL "Socialist Millionaires Protocol\r\nVerification progress",IDC_STC_SMP_HEADPRO,"Static",WS_CHILDWINDOW|WS_VISIBLE|SS_NOPREFIX,39,9,156,21 - CONTROL "",IDC_PGB_SMP,"msctls_progress32",WS_CHILDWINDOW|WS_VISIBLE|PBS_SMOOTH,3,36,194,18 - CONTROL "",IDC_STC_SMP_PROGRESS,"Static",WS_CHILDWINDOW|WS_VISIBLE,3,57,194,20 - CONTROL "&Cancel",IDCANCEL,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,70,80,60,16 - CONTROL "&OK",IDOK,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,135,80,60,16 -END - -IDD_SMP_INPUT DIALOGEX 10,10,200,200 -CAPTION "Socialist Millionaires Protocol" -FONT 8,"MS Sans Serif",0,0,0 -STYLE WS_VISIBLE|WS_CAPTION|WS_SYSMENU|DS_SETFOREGROUND|DS_MODALFRAME -BEGIN - CONTROL IDI_OTR,IDC_ICO_SMP,"Static",WS_CHILDWINDOW|WS_VISIBLE|SS_CENTERIMAGE|SS_ICON,3,3,32,32 - CONTROL "Socialist Millionaires Protocol\r\nVerification",IDC_STC_SMP_HEAD,"Static",WS_CHILDWINDOW|WS_VISIBLE|SS_NOPREFIX,39,9,156,21 - CONTROL "",IDC_CBO_SMP_CHOOSE,"ComboBox",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|CBS_HASSTRINGS|CBS_DROPDOWNLIST,3,36,194,60 - CONTROL "",IDC_STC_SMP_INFO,"Static",WS_CHILDWINDOW|WS_VISIBLE,3,60,194,35 - CONTROL "",IDC_STC_SMP_FIELD1,"Static",WS_CHILDWINDOW|WS_VISIBLE,3,105,194,10 - CONTROL "",IDC_EDT_SMP_FIELD1,"Edit",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,3,117,194,13,WS_EX_CLIENTEDGE - CONTROL "",IDC_STC_SMP_FIELD2,"Static",WS_CHILDWINDOW|WS_VISIBLE,3,141,194,10 - CONTROL "",IDC_EDT_SMP_FIELD2,"Edit",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,3,153,194,13,WS_EX_CLIENTEDGE - CONTROL "&Cancel",IDCANCEL,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,3,180,60,16 - CONTROL "&OK",IDOK,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,135,180,60,16 - CONTROL "&No",IDNO,"Button",NOT WS_VISIBLE|WS_CHILDWINDOW|WS_TABSTOP,70,180,60,16 - CONTROL "&Yes",IDYES,"Button",NOT WS_VISIBLE|WS_CHILDWINDOW|WS_TABSTOP,135,180,60,16 -END - diff --git a/plugins/MirOTR/MirOTR/resources/unverified.ico b/plugins/MirOTR/MirOTR/resources/unverified.ico deleted file mode 100644 index 95cc6629fa..0000000000 Binary files a/plugins/MirOTR/MirOTR/resources/unverified.ico and /dev/null differ diff --git a/plugins/MirOTR/MirOTR/resources/version.rc b/plugins/MirOTR/MirOTR/resources/version.rc deleted file mode 100644 index da4afefd9f..0000000000 --- a/plugins/MirOTR/MirOTR/resources/version.rc +++ /dev/null @@ -1,42 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#ifdef APSTUDIO_INVOKED -#error this file is not editable by Microsoft Visual C++ -#endif //APSTUDIO_INVOKED - -#include "afxres.h" -#include "version.h" - -#ifdef _WIN32 -LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL -#endif //_WIN32 - -VS_VERSION_INFO VERSIONINFO - FILEVERSION VER_MAJOR,VER_MINOR,VER_RELEASE,VER_BUILD - PRODUCTVERSION VER_MAJOR,VER_MINOR,VER_RELEASE,VER_BUILD - FILEFLAGSMASK 0x17L -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x4L - FILETYPE 0x0L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "000004b0" - BEGIN - VALUE "FileDescription", FILE_DESCRIPTION - VALUE "InternalName", INTERNAL_NAME - VALUE "LegalCopyright", LEGAL_COPYRIGHT - VALUE "OriginalFilename", ORIGINAL_FILENAME - VALUE "ProductName", PRODUCT_NAME - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x0, 1200 - END -END diff --git a/plugins/MirOTR/MirOTR/src/dbfilter.cpp b/plugins/MirOTR/MirOTR/src/dbfilter.cpp new file mode 100644 index 0000000000..aab60e18e5 --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/dbfilter.cpp @@ -0,0 +1,349 @@ +#include "stdafx.h" +#include "dbfilter.h" +static HANDLE hDBEventPreAdd, hDBEventAdded, hContactSettingChanged; +static CRITICAL_SECTION RemoveChainCS={0}, *lpRemoveChainCS = &RemoveChainCS; +static UINT_PTR timerId = 0; + +struct DeleteEventNode { + DeleteEventNode *next; + time_t timestamp; + HANDLE hContact; + HANDLE hDbEvent; +}; +struct DeleteEventHead { + DeleteEventNode *first; + DeleteEventNode *last; +}; +static DeleteEventHead DeleteEvents = {0,0}; + +VOID CALLBACK DeleteTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) { + if (!DeleteEvents.first) return; + EnterCriticalSection(lpRemoveChainCS); + DeleteEventNode *prev =0, *current, *next; + DBEVENTINFO info = {0}; + info.cbSize = sizeof(info); + next = DeleteEvents.first; + while (current = next) { + if (difftime(time(0), current->timestamp) < 1) break; + if (!CallService(MS_DB_EVENT_GET, (WPARAM)current->hDbEvent, (LPARAM)&info)) // && info.flags&DBEF_READ) + { + CallService(MS_DB_EVENT_DELETE, (WPARAM)current->hContact, (LPARAM)current->hDbEvent); + next = current->next; + if (prev) prev->next = next; + else if (DeleteEvents.first == current) DeleteEvents.first = next; + delete current; + } else { + prev = current; + next = current->next; + } + } + if (!DeleteEvents.first) DeleteEvents.last = 0; + LeaveCriticalSection(lpRemoveChainCS); +} + + +// add prefix to sent messages +int OnDatabaseEventPreAdd(WPARAM wParam, LPARAM lParam) { + if (!options.prefix_messages || !lParam) return 0; + HANDLE hContact = (HANDLE)wParam; + DBEVENTINFO *dbei = (DBEVENTINFO *)lParam; + if ((dbei->eventType != EVENTTYPE_MESSAGE) || !(dbei->flags & DBEF_SENT) || (dbei->flags & DBEF_OTR_PREFIXED)) + return 0; + if(dbei->cbBlob == 0 || dbei->pBlob == 0) + return 0; // just to be safe + + const char *proto = contact_get_proto(hContact); + if (!proto ) return 0; + if (DBGetContactSettingByte(hContact, proto, "ChatRoom", 0) == 1) + return 0; + + if(g_metaproto && strcmp(proto, g_metaproto) == 0) { + hContact = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0); + if (!hContact) return 0; + proto = contact_get_proto(hContact); + if (!proto ) return 0; + } + + + ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact); + bool encrypted = otr_context_get_trust(context) != TRUST_NOT_PRIVATE; + if (!encrypted) return 0; + + DBEVENTINFO my_dbei = *dbei; // copy the other event + + char *msg = (char *)dbei->pBlob; + char *newmsg = 0; + DWORD alloclen = 0; + DWORD msglen = strlen(msg); + if (dbei->flags & DBEF_UTF) { + int prefixlen = strnlen(options.prefix, 64); + if (strncmp(msg, options.prefix, prefixlen) == 0) return 0; + alloclen = (msglen+prefixlen+1)*sizeof(char); + + // get additional data + DWORD len2 = alloclen- prefixlen*sizeof(char); + int datalen = dbei->cbBlob - len2; + if (datalen < 0) datalen = 0; + + newmsg = (char*)mir_alloc(alloclen); + memset(newmsg, 0, alloclen+datalen); + strncpy(newmsg, options.prefix, prefixlen); + strncat(newmsg, msg, msglen); + // append additional data + if (datalen) { + memcpy(newmsg+alloclen, msg+len2, datalen); + alloclen += datalen; + } + } else { + bool dz = false; + if(msglen < dbei->cbBlob) { + for(unsigned int i = msglen; i < dbei->cbBlob; i++) { + if(msg[i] == 0 && msg[i - 1] == 0) { + dz = true; + break; + } + } + } + if(dz) { + // yes, unicode + wchar_t* msgw = (wchar_t *)&msg[msglen]; + wchar_t *prefixw = mir_utf8decodeW(options.prefix); + int prefixlenw = wcslen(prefixw); + if (wcsncmp(msgw, prefixw, prefixlenw) == 0) { + mir_free(prefixw); + return 0; + } + int msglenw = wcslen(msgw); + + char *prefix = mir_utf8decodeA(options.prefix); + int prefixlen = strlen(prefix); + + alloclen = (msglen+prefixlen+1)* sizeof(char) + (msglenw + prefixlenw +1) * sizeof(wchar_t); + // get additional data + DWORD len2 = (msglen+1)* sizeof(char) + (msglenw+1) * sizeof(wchar_t); + int datalen = dbei->cbBlob - len2; + if (datalen < 0) datalen = 0; + + newmsg = (char*)mir_alloc(alloclen+datalen); + memset(newmsg, 0, alloclen+datalen); + strncpy(newmsg, prefix, prefixlen); + strncat(newmsg, msg, msglen); + wchar_t *p = (wchar_t*) newmsg + (msglen + prefixlen + 1) * sizeof(char); + wcsncpy(p, prefixw, prefixlenw); + wcsncat(p, msgw, msglenw); + mir_free(prefix); + mir_free(prefixw); + // append additional data + if (datalen) { + memcpy(newmsg+alloclen, msg+len2, datalen); + alloclen += datalen; + } + + } else { + char *prefix = mir_utf8decodeA(options.prefix); + int prefixlen = strlen(prefix); + if (strncmp(msg, prefix, prefixlen) == 0) { + mir_free(prefix); + return 0; + } + alloclen = msglen+prefixlen+sizeof(char); + // get additional data + DWORD len2 = alloclen-prefixlen; + int datalen = dbei->cbBlob - len2; + if (datalen < 0) datalen = 0; + + newmsg = (char*)mir_alloc(alloclen+datalen); + memset(newmsg, 0, alloclen+datalen); + strncpy(newmsg, prefix, prefixlen); + strncat(newmsg, msg, msglen); + mir_free(prefix); + // append additional data + if (datalen) { + memcpy(newmsg+alloclen, msg+len2, datalen); + alloclen += datalen; + } + } + + } + + my_dbei.pBlob = (BYTE *)newmsg; + my_dbei.cbBlob = alloclen; + my_dbei.flags |= DBEF_OTR_PREFIXED; + + CallService(MS_DB_EVENT_ADD, wParam, (LPARAM)&my_dbei); + if (newmsg) mir_free(newmsg); + + // stop original event from being added + return 1; +} + + int OnDatabaseEventAdded(WPARAM wParam, LPARAM lParam) { + if (!options.delete_history) return 0; + + DBEVENTINFO info = {0}; + info.cbSize = sizeof(info); + + static char* prefixutf = mir_utf8encodeT(TranslateT(LANG_INLINE_PREFIX)); + static char* prefix = Translate(LANG_INLINE_PREFIX); + static DWORD lenutf = strlen(prefixutf); + static DWORD len = strlen(prefix); + info.cbBlob = lenutf*2; + info.pBlob = (PBYTE)mir_alloc(info.cbBlob); + if (!CallService(MS_DB_EVENT_GET, (WPARAM)lParam, (LPARAM)&info)) { + if(info.eventType == EVENTTYPE_MESSAGE) { + HANDLE hContact = (HANDLE)wParam, hSub; + if(options.bHaveMetaContacts && (hSub = (HANDLE)CallService + (MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0)) != 0) { + hContact = hSub; + } + ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact); + if (context && otr_context_get_trust(context) != TRUST_NOT_PRIVATE ) { + // only delete encrypted messages that are no OTR system messages + if ( options.delete_systeminfo || + ((info.flags&DBEF_UTF && !(info.cbBlob >lenutf && 0==strncmp((char*)info.pBlob, prefixutf, lenutf))) + || (!(info.flags&DBEF_UTF) && !(info.cbBlob >len && 0==strncmp((char*)info.pBlob, prefix, len))) + ) + ) + { + DeleteEventNode *node = new DeleteEventNode(); + node->hContact = hContact; + node->hDbEvent = (HANDLE) lParam; + node->timestamp = time(0); + node->next = 0; + EnterCriticalSection(lpRemoveChainCS); + if (DeleteEvents.last) + DeleteEvents.last->next = node; + else + DeleteEvents.first = node; + DeleteEvents.last = node; + LeaveCriticalSection(lpRemoveChainCS); + } + } + } + } + mir_free(prefixutf); + mir_free(info.pBlob); + return 0; +} + +void FinishSession(HANDLE hContact) { + if (!hContact) return; + ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact); + TrustLevel level = otr_context_get_trust(context); + if (level == TRUST_UNVERIFIED || level == TRUST_PRIVATE) { + otrl_context_force_finished(context); + //SetEncryptionStatus(hContact, TRUST_FINISHED); + otr_gui_gone_insecure(context->app_data, context); + //otrl_message_disconnect(otr_user_state, &ops, hContact, context->accountname, context->protocol, context->username); + //SetEncryptionStatus(hContact, TRUST_NOT_PRIVATE); + } + return; +} + +int WindowEvent(WPARAM wParam, LPARAM lParam) { + MessageWindowEventData *mwd = (MessageWindowEventData *)lParam; + + if(mwd->uType == MSG_WINDOW_EVT_CLOSE && options.end_window_close) { + FinishSession(mwd->hContact); + return 0; + } + + if(mwd->uType != MSG_WINDOW_EVT_OPEN) return 0; + if (!options.bHaveSRMMIcons) return 0; + + HANDLE hContact = mwd->hContact, hTemp; + if(options.bHaveMetaContacts && (hTemp = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0)) != 0) + hContact = hTemp; + + if (!CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)MODULENAME)) + return 0; + + lib_cs_lock(); + ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact); + lib_cs_unlock(); + + SetEncryptionStatus(hContact, otr_context_get_trust(context)); + + return 0; +} + +// if it's a protocol going offline, attempt to send terminate session to all contacts of that protocol +// (this would be hooked as the ME_CLIST_STATUSMODECHANGE handler except that event is sent *after* the proto goes offline) +int StatusModeChange(WPARAM wParam, LPARAM lParam) { + int status = (int)wParam; + + if(status != ID_STATUS_OFFLINE ) return 0; + + const char *proto = (char *)lParam; + HANDLE hContact; + + lib_cs_lock(); + + ConnContext *context = otr_user_state->context_root; + while(context) { + if(context->msgstate == OTRL_MSGSTATE_ENCRYPTED && (proto == 0 || strcmp(proto, context->protocol) == 0)) { + hContact = context->app_data; + + if(hContact) { + otrl_message_disconnect(otr_user_state, &ops, hContact, context->accountname, context->protocol, context->username); + SetEncryptionStatus(hContact, TRUST_NOT_PRIVATE); + } + + } + context = context->next; + } + lib_cs_unlock(); + + return 0; +} + +int OnContactSettingChanged(WPARAM wParam, LPARAM lParam) { + DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *)lParam; + if (!lParam || strcmp(cws->szSetting, "Status") != 0) return 0; + HANDLE hContact = (HANDLE)wParam; + int status=0; + switch (cws->value.type){ + case DBVT_WORD: + status = cws->value.wVal; + break; + case DBVT_BYTE: + status = cws->value.bVal; + break; + case DBVT_DWORD: + status = cws->value.dVal; + break; + } + if (status == ID_STATUS_OFFLINE) { + if (!hContact) { + // Protocol is going offline + // Terminate sessions with all contacts of that proto + StatusModeChange((WPARAM) ID_STATUS_OFFLINE, (LPARAM)cws->szModule); + return 0; + }else if(CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)MODULENAME)) { + // only care about contacts to which this filter is attached + FinishSession(hContact); + } + } + + + return 0; +} + +void InitDBFilter() { + InitializeCriticalSectionAndSpinCount(lpRemoveChainCS, 500); + hDBEventPreAdd = HookEvent(ME_DB_EVENT_FILTER_ADD, OnDatabaseEventPreAdd); + hDBEventAdded = HookEvent(ME_DB_EVENT_ADDED, OnDatabaseEventAdded); + hContactSettingChanged = HookEvent(ME_DB_CONTACT_SETTINGCHANGED, OnContactSettingChanged); + timerId = SetTimer(0, 0, 1000, DeleteTimerProc); +} +void DeinitDBFilter() { + UnhookEvent(hDBEventPreAdd); + hDBEventPreAdd = 0; + UnhookEvent(hDBEventAdded); + hDBEventAdded = 0; + UnhookEvent(hContactSettingChanged); + hContactSettingChanged=0; + if (timerId) KillTimer(0, timerId); + DeleteTimerProc(0,0,0,0); + DeleteCriticalSection(lpRemoveChainCS); +} \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/src/dbfilter.h b/plugins/MirOTR/MirOTR/src/dbfilter.h new file mode 100644 index 0000000000..99a6d50428 --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/dbfilter.h @@ -0,0 +1,4 @@ +#define DBEF_OTR_PREFIXED 0x8000 + +void InitDBFilter(); +void DeinitDBFilter(); \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/src/dialogs.cpp b/plugins/MirOTR/MirOTR/src/dialogs.cpp new file mode 100644 index 0000000000..3335935282 --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/dialogs.cpp @@ -0,0 +1,756 @@ +#include "stdafx.h" +#include "dialogs.h" +#include +#include +#include + +struct SmpData { + HWND dialog; + TrustLevel oldlevel; + ConnContext *context; + bool responder; + TCHAR *question; +}; +typedef std::map SmpForContactMap; +SmpForContactMap smp_for_contact; + + +INT_PTR CALLBACK DlgSMPUpdateProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch ( msg ) { + case WM_INITDIALOG: + { + if (!lParam) { + EndDialog(hwndDlg, IDCANCEL); + return FALSE; + } + TranslateDialogDefault( hwndDlg ); + + SmpData *data = (SmpData*)lParam; + ConnContext *context = data->context; + data->dialog = hwndDlg; + //smp_for_contact.insert(SmpForContactMap::value_type(context->app_data, *data)); + if (smp_for_contact[context->app_data].dialog) SendMessage(smp_for_contact[context->app_data].dialog, WMU_REFRESHSMP, 0, 0); + smp_for_contact[context->app_data].context = data->context; + smp_for_contact[context->app_data].dialog = hwndDlg; + smp_for_contact[context->app_data].oldlevel = data->oldlevel; + smp_for_contact[context->app_data].responder = data->responder; + mir_free(data); + + TCHAR title[512], *proto = mir_a2t(contact_get_proto((HANDLE)context->app_data)); + const TCHAR *name =contact_get_nameT((HANDLE)context->app_data); + mir_sntprintf(title, 512, TranslateT(LANG_SMP_PROGRESS_TITLE), name, proto); + SendMessage(hwndDlg, WM_SETTEXT, 0, (LPARAM)title); + mir_sntprintf(title, 512, TranslateT(LANG_SMP_PROGRESS_DESC), name, proto); + mir_free(proto); + SetDlgItemText(hwndDlg, IDC_STC_SMP_HEADPRO, title); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)context); + + // Move window to screen center + // Get the owner window and dialog box rectangles. + HWND hwndOwner; RECT rcOwner, rcDlg, rc; + if ((hwndOwner = GetParent(hwndDlg)) == NULL) + { + hwndOwner = GetDesktopWindow(); + } + + GetWindowRect(hwndOwner, &rcOwner); + GetWindowRect(hwndDlg, &rcDlg); + CopyRect(&rc, &rcOwner); + + // Offset the owner and dialog box rectangles so that right and bottom + // values represent the width and height, and then offset the owner again + // to discard space taken up by the dialog box. + + OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); + OffsetRect(&rc, -rc.left, -rc.top); + OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); + + // The new position is the sum of half the remaining space and the owner's + // original position. + + SetWindowPos(hwndDlg, + HWND_TOP, + rcOwner.left + (rc.right / 2), + rcOwner.top + (rc.bottom / 2), + 0, 0, // Ignores size arguments. + SWP_NOSIZE); + + // end center dialog + + SendDlgItemMessage(hwndDlg, IDC_PGB_SMP, PBM_SETRANGE, 0, MAKELONG(0, 100)); + SendDlgItemMessage(hwndDlg, IDC_PGB_SMP, PBM_SETPOS, 10, 0); + + EnableWindow(GetDlgItem(hwndDlg, IDCANCEL), true); + EnableWindow(GetDlgItem(hwndDlg, IDOK), false); + + return TRUE; + } + + case WMU_REFRESHSMP: + { + ConnContext *context = (ConnContext*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + SendDlgItemMessage(hwndDlg, IDC_PGB_SMP, PBM_SETPOS, wParam, 0); + switch (wParam) { + case 0: + EnableWindow(GetDlgItem(hwndDlg, IDCANCEL), false); + EnableWindow(GetDlgItem(hwndDlg, IDOK), true); + SetDlgItemText(hwndDlg, IDC_STC_SMP_PROGRESS, TranslateT(LANG_SMP_ERROR)); + smp_for_contact.erase(context->app_data); + break; + case 100: + { + EnableWindow(GetDlgItem(hwndDlg, IDCANCEL), false); + EnableWindow(GetDlgItem(hwndDlg, IDOK), true); + smp_for_contact.erase(context->app_data); + if (context->smstate->sm_prog_state == OTRL_SMP_PROG_SUCCEEDED) { + if (context->active_fingerprint->trust && + context->active_fingerprint->trust[0]) { + SetDlgItemText(hwndDlg, IDC_STC_SMP_PROGRESS, TranslateT(LANG_SMP_SUCCESS)); + } else { + SetDlgItemText(hwndDlg, IDC_STC_SMP_PROGRESS, TranslateT(LANG_SMP_SUCCESS_VERIFY)); + } + } else { + SetDlgItemText(hwndDlg, IDC_STC_SMP_PROGRESS, TranslateT(LANG_SMP_FAILED)); + } + } + break; + default: + SetDlgItemText(hwndDlg, IDC_STC_SMP_PROGRESS, _T("")); + } + } + + case WM_COMMAND: + switch ( HIWORD( wParam )) { + case BN_CLICKED: + { + ConnContext *context = (ConnContext*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + switch ( LOWORD( wParam )) { + case IDCANCEL: + otr_abort_smp(context); + //break; + case IDOK: + smp_for_contact.erase(context->app_data); + EndDialog(hwndDlg, LOWORD( wParam )); + break; + } + }break; + } + + } + + return FALSE; +} + +void SMPInitUpdateDialog(ConnContext *context, bool responder) { + if (!context) return; + SmpData *data = (SmpData*)mir_calloc(sizeof(SmpData)); + data->context = context; + data->oldlevel = otr_context_get_trust(context); + data->responder = responder; + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_SMP_PROGRESS), 0, DlgSMPUpdateProc, (LPARAM) data); +} + +INT_PTR CALLBACK DlgSMPResponseProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch ( msg ) { + case WM_INITDIALOG: + { + if (!lParam) { + EndDialog(hwndDlg, IDCANCEL); + return FALSE; + } + TranslateDialogDefault( hwndDlg ); + + SmpData *data = (SmpData*)lParam; + ConnContext *context = data->context; + data->dialog = hwndDlg; + //smp_for_contact.insert(SmpForContactMap::value_type(context->app_data, *data)); + if (smp_for_contact[context->app_data].dialog) SendMessage(smp_for_contact[context->app_data].dialog, WMU_REFRESHSMP, 0, 0); + smp_for_contact[context->app_data].context = data->context; + smp_for_contact[context->app_data].dialog = hwndDlg; + smp_for_contact[context->app_data].oldlevel = data->oldlevel; + smp_for_contact[context->app_data].responder = data->responder; + + TCHAR buff[512], *proto=mir_a2t(contact_get_proto(context->app_data)); + mir_sntprintf(buff, 512, TranslateT(LANG_SMP_VERIFY_TITLE), contact_get_nameT(context->app_data), proto); + mir_free(proto); + SendMessage(hwndDlg, WM_SETTEXT, 0, (LPARAM)buff); + SetDlgItemText(hwndDlg, IDC_STC_SMP_HEAD, buff); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)context); + + if (data->question) { + mir_sntprintf(buff, 512, TranslateT(LANG_OTR_SMPQUESTION_RESPOND_DESC), contact_get_nameT(context->app_data)); + + SetDlgItemText(hwndDlg, IDC_STC_SMP_INFO, buff); + + SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, data->question); + SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, TRUE, 0); + SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, TranslateT(LANG_SMP_QUESTION)); + + SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, _T("")); + SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, EM_SETREADONLY, FALSE, 0); + SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD2, TranslateT(LANG_SMP_ANSWER)); + + + ShowWindow(GetDlgItem(hwndDlg, IDOK), SW_SHOWNA); + ShowWindow(GetDlgItem(hwndDlg, IDYES), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDNO), SW_HIDE); + + mir_free(data->question); + } else { + mir_sntprintf(buff, 512, TranslateT(LANG_OTR_SMPPASSWORD_RESPOND_DESC), contact_get_nameT((HANDLE)context->app_data)); + + SetDlgItemText(hwndDlg, IDC_STC_SMP_INFO, buff); + + SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, _T("")); + SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, TRUE, 0); + SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, _T("")); + + SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, _T("")); + SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, EM_SETREADONLY, FALSE, 0); + SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD2, TranslateT(LANG_SMP_PASSWORD)); + + + ShowWindow(GetDlgItem(hwndDlg, IDOK), SW_SHOWNA); + ShowWindow(GetDlgItem(hwndDlg, IDYES), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDNO), SW_HIDE); + } + mir_free(data); + + // Move window to screen center + // Get the owner window and dialog box rectangles. + HWND hwndOwner; RECT rcOwner, rcDlg, rc; + if ((hwndOwner = GetParent(hwndDlg)) == NULL) + { + hwndOwner = GetDesktopWindow(); + } + + GetWindowRect(hwndOwner, &rcOwner); + GetWindowRect(hwndDlg, &rcDlg); + CopyRect(&rc, &rcOwner); + + // Offset the owner and dialog box rectangles so that right and bottom + // values represent the width and height, and then offset the owner again + // to discard space taken up by the dialog box. + + OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); + OffsetRect(&rc, -rc.left, -rc.top); + OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); + + // The new position is the sum of half the remaining space and the owner's + // original position. + + SetWindowPos(hwndDlg, + HWND_TOP, + rcOwner.left + (rc.right / 2), + rcOwner.top + (rc.bottom / 2), + 0, 0, // Ignores size arguments. + SWP_NOSIZE); + + // end center dialog + + + + return TRUE; + } + + case WM_COMMAND: + switch ( HIWORD( wParam )) { + case BN_CLICKED: + { + ConnContext *context = (ConnContext *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + switch ( LOWORD( wParam )) { + case IDOK: + { + SMPInitUpdateDialog(context, true); + + int len = SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, WM_GETTEXTLENGTH, 0, 0); + TCHAR *answer = new TCHAR[len+1]; + GetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, answer, len+1); + char *ans = mir_utf8encodeT(answer); + delete answer; + + otr_continue_smp(context, (const unsigned char *)ans, strlen(ans)); + mir_free(ans); + + EndDialog(hwndDlg, LOWORD( wParam )); + }break; + case IDCANCEL: + smp_for_contact.erase(context->app_data); + EndDialog(hwndDlg, LOWORD( wParam )); + break; + } + } + } + break; + + } + + return FALSE; +} + +/* +void SMPInitResponseDialog(ConnContext *context, const TCHAR *question) { + if (!context) return; + SmpData *data = (SmpData*)mir_calloc(sizeof(SmpData)); + data->context = context; + data->oldlevel = TRUST_NOT_PRIVATE; + data->responder = true; + data->question = (question) ? mir_tstrdup(question) : NULL; + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_SMP_INPUT), 0, DlgSMPResponseProc, (LPARAM) data); +} +*/ + +INT_PTR CALLBACK DlgProcSMPInitProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch ( msg ) { + case WM_INITDIALOG: + { + if (!lParam) { + EndDialog(hwndDlg, IDCANCEL); + return FALSE; + } + TranslateDialogDefault( hwndDlg ); + + ConnContext *context = (ConnContext*)lParam; + if (smp_for_contact.find(context->app_data) != smp_for_contact.end()) { + EndDialog(hwndDlg, IDCANCEL); + return FALSE; + } + + TCHAR title[512], *proto = mir_a2t(contact_get_proto((HANDLE)context->app_data)); + mir_sntprintf(title, 512, TranslateT(LANG_SMP_VERIFY_TITLE), contact_get_nameT((HANDLE)context->app_data), proto); + mir_free(proto); + SendMessage(hwndDlg, WM_SETTEXT, 0, (LPARAM)title); + SetDlgItemText(hwndDlg, IDC_STC_SMP_HEAD, title); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); + + // Move window to screen center + // Get the owner window and dialog box rectangles. + HWND hwndOwner; RECT rcOwner, rcDlg, rc; + if ((hwndOwner = GetParent(hwndDlg)) == NULL) + { + hwndOwner = GetDesktopWindow(); + } + + GetWindowRect(hwndOwner, &rcOwner); + GetWindowRect(hwndDlg, &rcDlg); + CopyRect(&rc, &rcOwner); + + // Offset the owner and dialog box rectangles so that right and bottom + // values represent the width and height, and then offset the owner again + // to discard space taken up by the dialog box. + + OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); + OffsetRect(&rc, -rc.left, -rc.top); + OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); + + // The new position is the sum of half the remaining space and the owner's + // original position. + + SetWindowPos(hwndDlg, + HWND_TOP, + rcOwner.left + (rc.right / 2), + rcOwner.top + (rc.bottom / 2), + 0, 0, // Ignores size arguments. + SWP_NOSIZE); + + // end center dialog + + + HWND cmb = GetDlgItem(hwndDlg, IDC_CBO_SMP_CHOOSE); + SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_SMPTYPE_QUESTION)); + SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_SMPTYPE_PASSWORD)); + SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_SMPTYPE_FINGERPRINT)); + SendMessage(cmb, CB_SELECTSTRING, -1, (WPARAM)TranslateT(LANG_SMPTYPE_QUESTION)); + EnableWindow(GetDlgItem(hwndDlg, IDC_CBO_SMP_CHOOSE), TRUE); + + + Fingerprint *fp = context->active_fingerprint; + if (!fp) { + EndDialog(hwndDlg, IDCANCEL); + return FALSE; + } + TCHAR buff[1024]; + if (!fp->trust || fp->trust[0] == '\0') + mir_sntprintf(buff, 512, TranslateT(LANG_OTR_SMPQUESTION_VERIFY_DESC), contact_get_nameT((HANDLE)context->app_data)); + else + mir_sntprintf(buff, 512, TranslateT(LANG_OTR_SMPQUESTION_VERIFIED_DESC), contact_get_nameT((HANDLE)context->app_data)); + + SetDlgItemText(hwndDlg, IDC_STC_SMP_INFO, buff); + + SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, _T("")); + SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, FALSE, 0); + SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, TranslateT(LANG_SMP_QUESTION)); + + SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, _T("")); + SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, EM_SETREADONLY, FALSE, 0); + SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD2, TranslateT(LANG_SMP_ANSWER)); + + + ShowWindow(GetDlgItem(hwndDlg, IDOK), SW_SHOWNA); + ShowWindow(GetDlgItem(hwndDlg, IDYES), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDNO), SW_HIDE); + SetFocus(GetDlgItem(hwndDlg, IDC_CBO_SMP_CHOOSE)); + + return FALSE; + } + + case WM_COMMAND: + switch ( HIWORD( wParam )) { + case BN_CLICKED: + { + ConnContext* context = (ConnContext*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + TCHAR msg[1024]; + switch ( LOWORD( wParam )) { + case IDCANCEL: + EndDialog(hwndDlg, LOWORD( wParam )); + break; + case IDOK: + GetDlgItemText(hwndDlg, IDC_CBO_SMP_CHOOSE, msg, 255); + if (_tcsncmp(msg, TranslateT(LANG_SMPTYPE_QUESTION), 255)==0) { + if (smp_for_contact.find(context->app_data) != smp_for_contact.end()) { + TCHAR msg[512]; + mir_sntprintf(msg, 512, TranslateT(LANG_SMP_IN_PROGRESS), contact_get_nameT((HANDLE)context->app_data)); + ShowError(msg); + }else { + int len = SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, WM_GETTEXTLENGTH, 0, 0); + TCHAR *question = new TCHAR[len+1]; + GetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, question, len+1); + char *quest = mir_utf8encodeT(question); + delete question; + + len = SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, WM_GETTEXTLENGTH, 0, 0); + TCHAR *answer = new TCHAR[len+1]; + GetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, answer, len+1); + char *ans = mir_utf8encodeT(answer); + delete answer; + + SMPInitUpdateDialog(context, false); + otr_start_smp(context, quest, (const unsigned char*)ans, strlen(ans)); + mir_free(quest); + mir_free(ans); + } + + }else if (_tcsncmp(msg, TranslateT(LANG_SMPTYPE_PASSWORD), 255)==0) { + if (smp_for_contact.find(context->app_data) != smp_for_contact.end()) { + TCHAR msg[512]; + mir_sntprintf(msg, 512, TranslateT(LANG_SMP_IN_PROGRESS), contact_get_nameT((HANDLE)context->app_data)); + ShowError(msg); + }else { + int len = SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, WM_GETTEXTLENGTH, 0, 0); + TCHAR *answer = new TCHAR[len+1]; + GetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, answer, len+1); + char *ans = mir_utf8encodeT(answer); + delete answer; + + SMPInitUpdateDialog(context, false); + otr_start_smp(context, NULL, (const unsigned char*)ans, strlen(ans)); + mir_free(ans); + } + + }else break; + EndDialog(hwndDlg, LOWORD( wParam )); + break; + case IDYES: + VerifyFingerprint(context, true); + EndDialog(hwndDlg, LOWORD( wParam )); + break; + case IDNO: + VerifyFingerprint(context, false); + EndDialog(hwndDlg, LOWORD( wParam )); + break; + } + } + break; + case CBN_SELCHANGE: + switch ( LOWORD( wParam )) { + case IDC_CBO_SMP_CHOOSE: + { + ConnContext* context = (ConnContext*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + Fingerprint *fp = context->active_fingerprint; + if (!fp) { + EndDialog(hwndDlg, IDCANCEL); + return TRUE; + } + BOOL trusted = false; + if (fp->trust && fp->trust[0] != '\0') trusted = true; + + TCHAR buff[512]; + GetDlgItemText(hwndDlg, IDC_CBO_SMP_CHOOSE, buff, 255); + if (_tcsncmp(buff, TranslateT(LANG_SMPTYPE_QUESTION), 255)==0) { + if (trusted) + mir_sntprintf(buff, 512, TranslateT(LANG_OTR_SMPQUESTION_VERIFIED_DESC), contact_get_nameT((HANDLE)context->app_data)); + else + mir_sntprintf(buff, 512, TranslateT(LANG_OTR_SMPQUESTION_VERIFY_DESC), contact_get_nameT((HANDLE)context->app_data)); + + SetDlgItemText(hwndDlg, IDC_STC_SMP_INFO, buff); + + SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, _T("")); + SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, FALSE, 0); + SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, TranslateT(LANG_SMP_QUESTION)); + + SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, _T("")); + SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, EM_SETREADONLY, FALSE, 0); + SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD2, TranslateT(LANG_SMP_ANSWER)); + + + ShowWindow(GetDlgItem(hwndDlg, IDOK), SW_SHOWNA); + ShowWindow(GetDlgItem(hwndDlg, IDYES), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDNO), SW_HIDE); + } else if (_tcsncmp(buff, TranslateT(LANG_SMPTYPE_PASSWORD), 255)==0) { + if (trusted) + mir_sntprintf(buff, 512, TranslateT(LANG_OTR_SMPPASSWORD_VERIFIED_DESC), contact_get_nameT((HANDLE)context->app_data)); + else + mir_sntprintf(buff, 512, TranslateT(LANG_OTR_SMPPASSWORD_VERIFY_DESC), contact_get_nameT((HANDLE)context->app_data)); + + SetDlgItemText(hwndDlg, IDC_STC_SMP_INFO, buff); + + SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, _T("")); + SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, TRUE, 0); + SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, _T("")); + + SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, _T("")); + SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, EM_SETREADONLY, FALSE, 0); + SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD2, TranslateT(LANG_SMP_PASSWORD)); + + + ShowWindow(GetDlgItem(hwndDlg, IDOK), SW_SHOWNA); + ShowWindow(GetDlgItem(hwndDlg, IDYES), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDNO), SW_HIDE); + } else if (_tcsncmp(buff, TranslateT(LANG_SMPTYPE_FINGERPRINT), 255)==0) { + if (trusted) + mir_sntprintf(buff, 512, TranslateT(LANG_OTR_FPVERIFIED_DESC), contact_get_nameT((HANDLE)context->app_data)); + else + mir_sntprintf(buff, 512, TranslateT(LANG_OTR_FPVERIFY_DESC), contact_get_nameT((HANDLE)context->app_data)); + + SetDlgItemText(hwndDlg, IDC_STC_SMP_INFO, buff); + + unsigned char hash[20]; + lib_cs_lock(); + if (!otrl_privkey_fingerprint_raw(otr_user_state, hash, context->accountname, context->protocol)) { + lib_cs_unlock(); + EndDialog(hwndDlg, IDCANCEL); + return FALSE; + } + otrl_privkey_hash_to_humanT(buff, hash); + lib_cs_unlock(); + SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, buff); + SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, TRUE, 0); + SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, TranslateT(LANG_YOUR_PRIVKEY)); + + otrl_privkey_hash_to_humanT(buff, fp->fingerprint); + SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, buff); + SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, EM_SETREADONLY, TRUE, 0); + SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD2, TranslateT(LANG_CONTACT_FINGERPRINT)); + + ShowWindow(GetDlgItem(hwndDlg, IDOK), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDYES), SW_SHOWNA); + ShowWindow(GetDlgItem(hwndDlg, IDNO), SW_SHOWNA); + + } + }break; + } + } + break; + + } + + return FALSE; +} +void SMPInitDialog(ConnContext* context) { + if (!context) return; + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_SMP_INPUT), 0, DlgProcSMPInitProc, (LPARAM) context); +} + +void SMPDialogUpdate(ConnContext *context, int percent) { + if (!context) return; + SmpForContactMap::iterator it = smp_for_contact.find(context->app_data); + if (it == smp_for_contact.end()) return; + if (it->second.dialog) PostMessage(it->second.dialog, WMU_REFRESHSMP, percent, 0); + TrustLevel level = otr_context_get_trust(context); + if (!it->second.responder && it->second.oldlevel != level) { + if (level == TRUST_PRIVATE) + VerifyFingerprintMessage(context, true); + else if (level == TRUST_UNVERIFIED) + VerifyFingerprintMessage(context, false); + } + //if (percent == 100) + /* + switch (percent){ + case 0: + VerifyFingerprint(context, false); + ShowWarning(_T("SMP failed")); + break; + case 100: + VerifyFingerprint(context, true); + ShowWarning(_T("SMP successful")); + break; + default: + ShowWarning(_T("Received an SMP update")); + } + */ +} +void SMPDialogReply(ConnContext *context, const char* question){ + SmpData *data = (SmpData*)mir_calloc(sizeof(SmpData)); + data->context = context; + data->oldlevel = TRUST_NOT_PRIVATE; + data->responder = true; + data->question = (question) ? mir_utf8decodeT(question) : NULL; + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_SMP_INPUT), 0, DlgSMPResponseProc, (LPARAM) data); + /* + ShowError(_T("SMP requires user password (NOT IMPL YET)")); + otr_abort_smp(context); + */ + //otr_continue_smp(context, pass, strlen(pass)); +} + +unsigned int CALLBACK verify_context_thread(void *param); +void VerifyContextDialog(ConnContext* context) { + if (!context) return; + CloseHandle((HANDLE)_beginthreadex(0, 0, verify_context_thread, context, 0, 0)); +} + +INT_PTR CALLBACK DlgProcVerifyContext(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch ( msg ) { + case WM_INITDIALOG: + { + if (!lParam) { + EndDialog(hwndDlg, IDCANCEL); + return FALSE; + } + SendMessage(hwndDlg, WM_SETTEXT, 0, (LPARAM)_T(LANG_OTR_FPVERIFY_TITLE)); + SetDlgItemText(hwndDlg, IDC_STC_SMP_HEAD, _T(LANG_OTR_FPVERIFY_TITLE)); + TranslateDialogDefault( hwndDlg ); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); + + // Move window to screen center + // Get the owner window and dialog box rectangles. + HWND hwndOwner; RECT rcOwner, rcDlg, rc; + if ((hwndOwner = GetParent(hwndDlg)) == NULL) + { + hwndOwner = GetDesktopWindow(); + } + + GetWindowRect(hwndOwner, &rcOwner); + GetWindowRect(hwndDlg, &rcDlg); + CopyRect(&rc, &rcOwner); + + // Offset the owner and dialog box rectangles so that right and bottom + // values represent the width and height, and then offset the owner again + // to discard space taken up by the dialog box. + + OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); + OffsetRect(&rc, -rc.left, -rc.top); + OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); + + // The new position is the sum of half the remaining space and the owner's + // original position. + + SetWindowPos(hwndDlg, + HWND_TOP, + rcOwner.left + (rc.right / 2), + rcOwner.top + (rc.bottom / 2), + 0, 0, // Ignores size arguments. + SWP_NOSIZE); + + // end center dialog + + ConnContext *context = (ConnContext*)lParam; + Fingerprint *fp = context->active_fingerprint; + if (!fp) { + EndDialog(hwndDlg, IDCANCEL); + return FALSE; + } + TCHAR buff[512]; + if (!fp->trust || fp->trust[0] == '\0') + mir_sntprintf(buff, 512, TranslateT(LANG_OTR_FPVERIFY_DESC), contact_get_nameT((HANDLE)context->app_data)); + else + mir_sntprintf(buff, 512, TranslateT(LANG_OTR_FPVERIFIED_DESC), contact_get_nameT((HANDLE)context->app_data)); + + SetDlgItemText(hwndDlg, IDC_STC_SMP_INFO, buff); + + unsigned char hash[20]; + lib_cs_lock(); + if (!otrl_privkey_fingerprint_raw(otr_user_state, hash, context->accountname, context->protocol)) { + lib_cs_unlock(); + EndDialog(hwndDlg, IDCANCEL); + return FALSE; + } + otrl_privkey_hash_to_humanT(buff, hash); + lib_cs_unlock(); + SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, buff); + SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, TRUE, 0); + SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, TranslateT(LANG_YOUR_PRIVKEY)); + + otrl_privkey_hash_to_humanT(buff, fp->fingerprint); + SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, buff); + SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, EM_SETREADONLY, TRUE, 0); + SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD2, TranslateT(LANG_CONTACT_FINGERPRINT)); + + EnableWindow(GetDlgItem(hwndDlg, IDC_CBO_SMP_CHOOSE), FALSE); + + ShowWindow(GetDlgItem(hwndDlg, IDOK), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDYES), SW_SHOWNA); + ShowWindow(GetDlgItem(hwndDlg, IDNO), SW_SHOWNA); + SetFocus(GetDlgItem(hwndDlg, IDCANCEL)); + + return FALSE; + } + + case WM_COMMAND: + switch ( HIWORD( wParam )) { + case BN_CLICKED: + switch ( LOWORD( wParam )) { + case IDYES: + case IDNO: + case IDCANCEL: + case IDOK: + EndDialog(hwndDlg, LOWORD( wParam )); + break; + } + } + break; + + } + + return FALSE; +} + +unsigned int CALLBACK verify_context_thread(void *param) +{ + Thread_Push( 0 ); + + if (param) { + ConnContext *context = (ConnContext *)param; + TCHAR msg[1024]; + switch ( DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SMP_INPUT), 0, DlgProcVerifyContext, (LPARAM)param) ) { + case IDOK: + case IDYES: + lib_cs_lock(); + otrl_context_set_trust(context->active_fingerprint, "verified"); + otrl_privkey_write_fingerprints(otr_user_state, g_fingerprint_store_filename); + lib_cs_unlock(); + mir_sntprintf(msg, 1024, TranslateT(LANG_FINGERPRINT_VERIFIED), contact_get_nameT((HANDLE)context->app_data)); + msg[1023] = '\0'; + ShowMessage((HANDLE)context->app_data, msg); + SetEncryptionStatus(context->app_data, otr_context_get_trust(context)); + break; + case IDNO: + lib_cs_lock(); + otrl_context_set_trust(context->active_fingerprint, NULL); + otrl_privkey_write_fingerprints(otr_user_state, g_fingerprint_store_filename); + lib_cs_unlock(); + mir_sntprintf(msg, 1024, TranslateT(LANG_FINGERPRINT_NOT_VERIFIED), contact_get_nameT((HANDLE)context->app_data)); + msg[1023] = '\0'; + ShowMessage((HANDLE)context->app_data, msg); + SetEncryptionStatus(context->app_data, otr_context_get_trust(context)); + break; + } + } + + Thread_Pop(); + return 0; +} \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/src/dialogs.h b/plugins/MirOTR/MirOTR/src/dialogs.h new file mode 100644 index 0000000000..0422dc3095 --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/dialogs.h @@ -0,0 +1,8 @@ +#pragma once +void VerifyContextDialog(ConnContext* context); +void SMPInitDialog(ConnContext* context); +INT_PTR CALLBACK DlgProcVerifyContext(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); +void SMPDialogUpdate(ConnContext *context, int percent); +void SMPDialogReply(ConnContext *context, const char* question); + +#define WMU_REFRESHSMP (WM_USER + 245) \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/src/dllmain.cpp b/plugins/MirOTR/MirOTR/src/dllmain.cpp new file mode 100644 index 0000000000..80833c9b2e --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/dllmain.cpp @@ -0,0 +1,153 @@ +// dllmain.cpp : Definiert den Einstiegspunkt für die DLL-Anwendung. +#include "stdafx.h" +#include "dllmain.h" +#include "otr.h" +#include "dbfilter.h" +#include + +HANDLE hEventWindow; +HINSTANCE hInst; + +int hLangpack; +char* g_metaproto; + + +PLUGININFOEX pluginInfo={ + sizeof(PLUGININFOEX), + SHORT_NAME_STRING, + PLUGIN_MAKE_VERSION(VER_MAJOR,VER_MINOR,VER_RELEASE,VER_BUILD), + LONGDESC_STRING, + AUTHOR, + AUTHOR_MAIL, + LEGAL_COPYRIGHT_LONG, + HOMEPAGE, + UNICODE_AWARE, + MIID_OTRPLUGIN // ANSI and Unicode have different IDs +}; + +BOOL APIENTRY DllMain( HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + if (ul_reason_for_call == DLL_PROCESS_ATTACH) { + hInst=hModule; + OTRL_INIT; + INITCOMMONCONTROLSEX icce = {0}; + icce.dwSize = sizeof(icce); + icce.dwICC = ICC_LISTVIEW_CLASSES|ICC_PROGRESS_CLASS; + InitCommonControlsEx(&icce); + } + return TRUE; +} + +DLLFUNC PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) +{ + return &pluginInfo; +} + +int ModulesLoaded(WPARAM wParam, LPARAM lParam) { + if(ServiceExists(MS_MC_GETPROTOCOLNAME)) + g_metaproto = (char *)CallService(MS_MC_GETPROTOCOLNAME, 0, 0); + + InitUtils(); + + lib_cs_lock(); + otr_user_state = otrl_userstate_create(); + lib_cs_unlock(); + + // this calls ReadPrivkeyFiles (above) to set filename values (also called on ME_FOLDERS_PATH_CHANGED) + InitOptions(); + + InitDBFilter(); + InitIcons(); + InitMenu(); + + InitSRMM(); + + hEventWindow = HookEvent(ME_MSG_WINDOWEVENT, WindowEvent); + + if (options.bHaveSecureIM && !db_get_b(0, MODULENAME, "sim_warned", 0)) { + db_set_b(0, MODULENAME, "sim_warned", 1); + options.default_policy = OTRL_POLICY_MANUAL_MOD; + SaveOptions(); + MessageBox(0, TranslateT(LANG_OTR_SECUREIM_TEXT), TranslateT(LANG_OTR_SECUREIM_TITLE), 0x30); + } + if (!options.bHaveSRMMIcons) { + MessageBox(0, _T("OTR Info"), _T("Your SRMM plugin does not support status icons. Not all OTR-functions are available!"), 0x30); + } + + // HookEvent(ME_OPT_INITIALISE, OptInit); + + // hook setting changed to monitor status + //hSettingChanged = HookEvent(ME_DB_CONTACT_SETTINGCHANGED, SettingChanged); + + // hook status mode changes to terminate sessions when we go offline + // (this would be hooked as the ME_CLIST_STATUSMODECHANGE handler except that event is sent *after* the proto goes offline) + // (instead, it's called from the SettingChanged handler for protocol status db setting changes) + //HookEvent(ME_CLIST_STATUSMODECHANGE, StatusModeChange); + + return 0; +} + +DLLFUNC int Load(void) +{ + DEBUGOUT_T("LOAD MIROTR") + + mir_getLP( &pluginInfo ); + /* for timezones + mir_getTMI(&tmi); */ + + CallService(MS_DB_SETSETTINGRESIDENT, TRUE, (LPARAM)(MODULENAME "/TrustLevel")); + + ///////////// + ////// init plugin + PROTOCOLDESCRIPTOR pd = {0}; + pd.cbSize = sizeof(pd); + pd.szName = MODULENAME; + pd.type = PROTOTYPE_ENCRYPTION; + CallService(MS_PROTO_REGISTERMODULE,0,(LPARAM)&pd); + + // remove us as a filter to all contacts - fix filter type problem + if(DBGetContactSettingByte(0, MODULENAME, "FilterOrderFix", 0) != 2) { + HANDLE hContact = db_find_first(); + while ( hContact != NULL ) { + CallService( MS_PROTO_REMOVEFROMCONTACT, ( WPARAM )hContact, ( LPARAM )MODULENAME ); + hContact = db_find_next(hContact); + } + DBWriteContactSettingByte(0, MODULENAME, "FilterOrderFix", 2); + } + + // create our services + CreateProtoServiceFunction(MODULENAME, PSS_MESSAGE, SVC_OTRSendMessage); + CreateProtoServiceFunction(MODULENAME, PSS_MESSAGE"W", SVC_OTRSendMessageW); + CreateProtoServiceFunction(MODULENAME, PSR_MESSAGE, SVC_OTRRecvMessage); + + + // hook modules loaded for updater support + HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded); + + return 0; +} + +DLLFUNC int Unload(void) +{ + //UnhookEvent(hSettingChanged); + UnhookEvent(hEventWindow); + //UnhookEvent(hEventDbEventAddedFilter); + //UnhookEvent(hEventDbEventAdded); + DEBUGOUT_T("UNLOAD MIROTR") + DeinitSRMM(); + DeinitOptions(); + DeinitMenu(); + DeinitDBFilter(); + + lib_cs_lock(); + otrl_userstate_free(otr_user_state); + lib_cs_unlock(); + + DeinitIcons(); + DeinitUtils(); + + return 0; +} \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/src/dllmain.h b/plugins/MirOTR/MirOTR/src/dllmain.h new file mode 100644 index 0000000000..b2346859f6 --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/dllmain.h @@ -0,0 +1,8 @@ +#pragma once + +#include "stdafx.h" +#include "version.h" + +#define DLLFUNC extern "C" __declspec(dllexport) + +extern HINSTANCE hInst; diff --git a/plugins/MirOTR/MirOTR/src/entities.cpp b/plugins/MirOTR/MirOTR/src/entities.cpp new file mode 100644 index 0000000000..ae2335bc01 --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/entities.cpp @@ -0,0 +1,430 @@ +// (C) of entities.cpp: Christoph +// http://mercurial.intuxication.org/hg/cstuff/raw-file/tip/entities.c +// http://stackoverflow.com/questions/1082162/how-to-unescape-html-in-c/1082191#1082191 +// modified by ProgAndy + +#include "stdafx.h" +#include "entities.h" + +#include +#include +#include +using namespace std; + +#define UNICODE_MAX 0x10FFFFul + + +static const char *named_entities[][2] = +{ + { "AElig;", "Æ" }, + { "Aacute;", "Ã" }, + { "Acirc;", "Â" }, + { "Agrave;", "À" }, + { "Alpha;", "Α" }, + { "Aring;", "Ã…" }, + { "Atilde;", "Ã" }, + { "Auml;", "Ä" }, + { "Beta;", "Î’" }, + { "Ccedil;", "Ç" }, + { "Chi;", "Χ" }, + { "Dagger;", "‡" }, + { "Delta;", "Δ" }, + { "ETH;", "Ã" }, + { "Eacute;", "É" }, + { "Ecirc;", "Ê" }, + { "Egrave;", "È" }, + { "Epsilon;", "Ε" }, + { "Eta;", "Η" }, + { "Euml;", "Ë" }, + { "Gamma;", "Γ" }, + { "Iacute;", "Ã" }, + { "Icirc;", "ÃŽ" }, + { "Igrave;", "ÃŒ" }, + { "Iota;", "Ι" }, + { "Iuml;", "Ã" }, + { "Kappa;", "Κ" }, + { "Lambda;", "Λ" }, + { "Mu;", "Îœ" }, + { "Ntilde;", "Ñ" }, + { "Nu;", "Î" }, + { "OElig;", "Å’" }, + { "Oacute;", "Ó" }, + { "Ocirc;", "Ô" }, + { "Ograve;", "Ã’" }, + { "Omega;", "Ω" }, + { "Omicron;", "Ο" }, + { "Oslash;", "Ø" }, + { "Otilde;", "Õ" }, + { "Ouml;", "Ö" }, + { "Phi;", "Φ" }, + { "Pi;", "Π" }, + { "Prime;", "″" }, + { "Psi;", "Ψ" }, + { "Rho;", "Ρ" }, + { "Scaron;", "Å " }, + { "Sigma;", "Σ" }, + { "THORN;", "Þ" }, + { "Tau;", "Τ" }, + { "Theta;", "Θ" }, + { "Uacute;", "Ú" }, + { "Ucirc;", "Û" }, + { "Ugrave;", "Ù" }, + { "Upsilon;", "Î¥" }, + { "Uuml;", "Ãœ" }, + { "Xi;", "Ξ" }, + { "Yacute;", "Ã" }, + { "Yuml;", "Ÿ" }, + { "Zeta;", "Ζ" }, + { "aacute;", "á" }, + { "acirc;", "â" }, + { "acute;", "´" }, + { "aelig;", "æ" }, + { "agrave;", "à" }, + { "alefsym;", "ℵ" }, + { "alpha;", "α" }, + { "amp;", "&" }, + { "and;", "∧" }, + { "ang;", "∠" }, + { "apos;", "'" }, + { "aring;", "Ã¥" }, + { "asymp;", "≈" }, + { "atilde;", "ã" }, + { "auml;", "ä" }, + { "bdquo;", "„" }, + { "beta;", "β" }, + { "brvbar;", "¦" }, + { "bull;", "•" }, + { "cap;", "∩" }, + { "ccedil;", "ç" }, + { "cedil;", "¸" }, + { "cent;", "¢" }, + { "chi;", "χ" }, + { "circ;", "ˆ" }, + { "clubs;", "♣" }, + { "cong;", "≅" }, + { "copy;", "©" }, + { "crarr;", "↵" }, + { "cup;", "∪" }, + { "curren;", "¤" }, + { "dArr;", "⇓" }, + { "dagger;", "†" }, + { "darr;", "↓" }, + { "deg;", "°" }, + { "delta;", "δ" }, + { "diams;", "♦" }, + { "divide;", "÷" }, + { "eacute;", "é" }, + { "ecirc;", "ê" }, + { "egrave;", "è" }, + { "empty;", "∅" }, + { "emsp;", " " }, + { "ensp;", " " }, + { "epsilon;", "ε" }, + { "equiv;", "≡" }, + { "eta;", "η" }, + { "eth;", "ð" }, + { "euml;", "ë" }, + { "euro;", "€" }, + { "exist;", "∃" }, + { "fnof;", "Æ’" }, + { "forall;", "∀" }, + { "frac12;", "½" }, + { "frac14;", "¼" }, + { "frac34;", "¾" }, + { "frasl;", "â„" }, + { "gamma;", "γ" }, + { "ge;", "≥" }, + { "gt;", ">" }, + { "hArr;", "⇔" }, + { "harr;", "↔" }, + { "hearts;", "♥" }, + { "hellip;", "…" }, + { "iacute;", "í" }, + { "icirc;", "î" }, + { "iexcl;", "¡" }, + { "igrave;", "ì" }, + { "image;", "â„‘" }, + { "infin;", "∞" }, + { "int;", "∫" }, + { "iota;", "ι" }, + { "iquest;", "¿" }, + { "isin;", "∈" }, + { "iuml;", "ï" }, + { "kappa;", "κ" }, + { "lArr;", "â‡" }, + { "lambda;", "λ" }, + { "lang;", "〈" }, + { "laquo;", "«" }, + { "larr;", "â†" }, + { "lceil;", "⌈" }, + { "ldquo;", "“" }, + { "le;", "≤" }, + { "lfloor;", "⌊" }, + { "lowast;", "∗" }, + { "loz;", "â—Š" }, + { "lrm;", "\xE2\x80\x8E" }, + { "lsaquo;", "‹" }, + { "lsquo;", "‘" }, + { "lt;", "<" }, + { "macr;", "¯" }, + { "mdash;", "—" }, + { "micro;", "µ" }, + { "middot;", "·" }, + { "minus;", "−" }, + { "mu;", "μ" }, + { "nabla;", "∇" }, + { "nbsp;", " " }, + { "ndash;", "–" }, + { "ne;", "≠" }, + { "ni;", "∋" }, + { "not;", "¬" }, + { "notin;", "∉" }, + { "nsub;", "⊄" }, + { "ntilde;", "ñ" }, + { "nu;", "ν" }, + { "oacute;", "ó" }, + { "ocirc;", "ô" }, + { "oelig;", "Å“" }, + { "ograve;", "ò" }, + { "oline;", "‾" }, + { "omega;", "ω" }, + { "omicron;", "ο" }, + { "oplus;", "⊕" }, + { "or;", "∨" }, + { "ordf;", "ª" }, + { "ordm;", "º" }, + { "oslash;", "ø" }, + { "otilde;", "õ" }, + { "otimes;", "⊗" }, + { "ouml;", "ö" }, + { "para;", "¶" }, + { "part;", "∂" }, + { "permil;", "‰" }, + { "perp;", "⊥" }, + { "phi;", "φ" }, + { "pi;", "Ï€" }, + { "piv;", "Ï–" }, + { "plusmn;", "±" }, + { "pound;", "£" }, + { "prime;", "′" }, + { "prod;", "âˆ" }, + { "prop;", "âˆ" }, + { "psi;", "ψ" }, + { "quot;", "\"" }, + { "rArr;", "⇒" }, + { "radic;", "√" }, + { "rang;", "〉" }, + { "raquo;", "»" }, + { "rarr;", "→" }, + { "rceil;", "⌉" }, + { "rdquo;", "â€" }, + { "real;", "â„œ" }, + { "reg;", "®" }, + { "rfloor;", "⌋" }, + { "rho;", "Ï" }, + { "rlm;", "\xE2\x80\x8F" }, + { "rsaquo;", "›" }, + { "rsquo;", "’" }, + { "sbquo;", "‚" }, + { "scaron;", "Å¡" }, + { "sdot;", "â‹…" }, + { "sect;", "§" }, + { "shy;", "\xC2\xAD" }, + { "sigma;", "σ" }, + { "sigmaf;", "Ï‚" }, + { "sim;", "∼" }, + { "spades;", "â™ " }, + { "sub;", "⊂" }, + { "sube;", "⊆" }, + { "sum;", "∑" }, + { "sup;", "⊃" }, + { "sup1;", "¹" }, + { "sup2;", "²" }, + { "sup3;", "³" }, + { "supe;", "⊇" }, + { "szlig;", "ß" }, + { "tau;", "Ï„" }, + { "there4;", "∴" }, + { "theta;", "θ" }, + { "thetasym;", "Ï‘" }, + { "thinsp;", " " }, + { "thorn;", "þ" }, + { "tilde;", "Ëœ" }, + { "times;", "×" }, + { "trade;", "â„¢" }, + { "uArr;", "⇑" }, + { "uacute;", "ú" }, + { "uarr;", "↑" }, + { "ucirc;", "û" }, + { "ugrave;", "ù" }, + { "uml;", "¨" }, + { "upsih;", "Ï’" }, + { "upsilon;", "Ï…" }, + { "uuml;", "ü" }, + { "weierp;", "℘" }, + { "xi;", "ξ" }, + { "yacute;", "ý" }, + { "yen;", "Â¥" }, + { "yuml;", "ÿ" }, + { "zeta;", "ζ" }, + { "zwj;", "\xE2\x80\x8D" }, + { "zwnj;", "\xE2\x80\x8C" } +}; + +static int cmp(const void *key, const void *element) +{ + return strncmp((const char *)key, *(const char **)element, + strlen(*(const char **)element)); +} + +static const char *get_named_entity(const char *name) +{ + const char **entity = (const char **)bsearch(name, named_entities, + sizeof(named_entities) / sizeof(*named_entities), + sizeof(*named_entities), cmp); + + return entity ? entity[1] : NULL; +} + +static size_t putc_utf8(unsigned long cp, char *buffer) +{ + unsigned char *bytes = (unsigned char *)buffer; + + if(cp <= 0x007Ful) + { + bytes[0] = (unsigned char)cp; + return 1; + } + + if(cp <= 0x07FFul) + { + bytes[1] = (unsigned char)((2u << 6) | (cp & 0x3Fu)); + bytes[0] = (unsigned char)((6u << 5) | (cp >> 6)); + return 2; + } + + if(cp <= 0xFFFFul) + { + bytes[2] = (unsigned char)(( 2u << 6) | ( cp & 0x3Fu)); + bytes[1] = (unsigned char)(( 2u << 6) | ((cp >> 6) & 0x3Fu)); + bytes[0] = (unsigned char)((14u << 4) | (cp >> 12)); + return 3; + } + + if(cp <= 0x10FFFFul) + { + bytes[3] = (unsigned char)(( 2u << 6) | ( cp & 0x3Fu)); + bytes[2] = (unsigned char)(( 2u << 6) | ((cp >> 6) & 0x3Fu)); + bytes[1] = (unsigned char)(( 2u << 6) | ((cp >> 12) & 0x3Fu)); + bytes[0] = (unsigned char)((30u << 3) | (cp >> 18)); + return 4; + } + + return 0; +} + +static _Bool parse_entity(const char *current, char **to, + const char **from, size_t maxlen) +{ + const char *end = (const char *)memchr(current, ';', maxlen); + if (!end) return 0; + + if(current[1] == '#') + { + char *tail = NULL; + errno = 0; + + _Bool hex = current[2] == 'x' || current[2] == 'X'; + + unsigned long cp = strtoul( + current + (hex ? 3 : 2), &tail, hex ? 16 : 10); + + if(tail == end && !errno && cp <= UNICODE_MAX) + { + *to += putc_utf8(cp, *to); + *from = end + 1; + + return 1; + } + } + else + { + const char *entity = get_named_entity(¤t[1]); + if(entity) + { + size_t len = strlen(entity); + memcpy(*to, entity, len); + + *to += len; + *from = end + 1; + + return 1; + } + } + + return 0; +} + +size_t decode_html_entities_utf8(char *dest, const char *src, size_t len) +{ + if (!src) src = dest; + + char *to = dest; + const char *from = src; + + const char *current; + if (!len) len = strlen(src); + size_t remain = len; + while((current = (const char*)memchr(from, '&', len-(from-src)))) + { + memcpy(to, from, (size_t)(current - from)); + to += current - from; + //remain = len-(current-src); + + if(parse_entity(current, &to, &from, len-(current-src))) + continue; + + from = current; + *to++ = *from++; + } + + remain = strnlen(from, len-(from-src)); + + memcpy(to, from, remain); + to += remain; + + if (src!=dest || (size_t)(to-dest) < len ) *to = 0; + return (size_t)(to - dest); +} + +char * encode_html_entities_utf8(const char *src) { + const char *pos, *start=src; + std::string buf; + if (! (pos = strpbrk(start, "&<>\"\r")) ) return NULL; + while (pos) { + buf.append(start, pos-start); + start = pos+1; + switch (*pos) { + case '"': + buf.append("""); + break; + case '<': + buf.append("<"); + break; + case '>': + buf.append(">"); + break; + case '&': + buf.append("&"); + break; + case '\r': + buf.append("
\r"); + break; + } + pos = strpbrk(start, "&<>\"\r"); + } + if (strlen(start)) buf.append(start); + pos = mir_strdup(buf.c_str()); + buf.clear(); + return (char*)pos; +} \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/src/entities.h b/plugins/MirOTR/MirOTR/src/entities.h new file mode 100644 index 0000000000..e4121dc5da --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/entities.h @@ -0,0 +1,26 @@ +// (C) of entities.h: Christoph +// http://mercurial.intuxication.org/hg/cstuff/raw-file/tip/entities.h +// http://stackoverflow.com/questions/1082162/how-to-unescape-html-in-c/1082191#1082191 +// modified by ProgAndy + +#ifndef DECODE_HTML_ENTITIES_UTF8 +#define DECODE_HTML_ENTITIES_UTF8 + +#include + +extern size_t decode_html_entities_utf8(char *dest, const char *src, size_t len); +/* if `src` is `NULL`, input will be taken from `dest`, decoding + the entities in-place + + otherwise, the output will be placed in `dest`, which should point + to a buffer big enough to hold `strlen(src) + 1` characters, while + `src` remains unchanged + if `len` is given, `dest` must be at least big enough + to hold `len + 1` characters. + + the function returns the length of the decoded string +*/ + +extern char * encode_html_entities_utf8(const char *src); + +#endif diff --git a/plugins/MirOTR/MirOTR/src/icons.cpp b/plugins/MirOTR/MirOTR/src/icons.cpp new file mode 100644 index 0000000000..c9dd1a10db --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/icons.cpp @@ -0,0 +1,62 @@ +#include "stdafx.h" +#include "icons.h" +TCHAR g_dllpath[1024]; + +struct +{ + const TCHAR* stzDescr; + const char* szName; + int defIconID; +} +static iconList[] = { + { _T(LANG_ICON_OTR), ICON_OTR, IDI_OTR }, + { _T(LANG_ICON_PRIVATE), ICON_PRIVATE, IDI_PRIVATE }, + { _T(LANG_ICON_UNVERIFIED), ICON_UNVERIFIED, IDI_UNVERIFIED }, + { _T(LANG_ICON_FINISHED), ICON_FINISHED, IDI_FINISHED }, + { _T(LANG_ICON_NOT_PRIVATE), ICON_NOT_PRIVATE, IDI_INSECURE } + +}; + +HANDLE hIconLibItem[SIZEOF(iconList)]; + +void InitIcons() { + TCHAR szFile[MAX_PATH+500]; + + GetModuleFileName(hInst, szFile, SIZEOF(szFile)); + + SKINICONDESC sid = {0}; + sid.cbSize = sizeof(SKINICONDESC); + sid.ptszDefaultFile = szFile; + sid.ptszSection = _T(MODULENAME); + sid.flags = SIDF_ALL_TCHAR; + + for ( int i = 0; i < SIZEOF(iconList); i++ ) { + sid.pszName = (char*)iconList[i].szName; + sid.ptszDescription = (TCHAR*)iconList[i].stzDescr; + sid.iDefaultIndex = -iconList[i].defIconID; + hIconLibItem[i] = Skin_AddIcon(&sid); + } + +} + +void DeinitIcons() { + for ( int i = 0; i < SIZEOF(iconList); i++ ) { + (HANDLE)CallService(MS_SKIN2_REMOVEICON, 0, (LPARAM)iconList[i].szName); + hIconLibItem[i] = NULL; + } +} + +HICON LoadIcon(const char* name, int big) { + return ( HICON )CallService( MS_SKIN2_GETICON, big, (LPARAM)name ); +} + +HANDLE GetIconHandle(const char* name) { + return ( HANDLE )CallService( MS_SKIN2_GETICONHANDLE, 0, (LPARAM)name ); +} + +void ReleaseIcon(const char* name, int big) { + CallService( big ? MS_SKIN2_RELEASEICONBIG : MS_SKIN2_RELEASEICON, 0, (LPARAM)name ); +} +void ReleaseIcon(HICON handle, int big) { + CallService( big ? MS_SKIN2_RELEASEICONBIG : MS_SKIN2_RELEASEICON, (WPARAM)handle, 0 ); +} diff --git a/plugins/MirOTR/MirOTR/src/icons.h b/plugins/MirOTR/MirOTR/src/icons.h new file mode 100644 index 0000000000..0983cc147c --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/icons.h @@ -0,0 +1,13 @@ +#pragma once +#define ICON_FINISHED (MODULENAME"_finished") +#define ICON_UNVERIFIED (MODULENAME"_unverified") +#define ICON_PRIVATE (MODULENAME"_private") +#define ICON_NOT_PRIVATE (MODULENAME"_not_private") +#define ICON_OTR (MODULENAME"_otr") + +void InitIcons(); +void DeinitIcons(); +HICON LoadIcon(const char* name, int big); +HANDLE GetIconHandle(const char* name); +void ReleaseIcon(const char* name, int big); +void ReleaseIcon(HICON handle, int big); \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/src/language.h b/plugins/MirOTR/MirOTR/src/language.h new file mode 100644 index 0000000000..8934405608 --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/language.h @@ -0,0 +1,122 @@ +#pragma once + +#include "m_langpack.h" + +#define LANG_START_OTR LPGEN("Start OTR") +#define LANG_STOP_OTR LPGEN("Stop OTR") + +#define LANG_YES LPGEN("Yes") +#define LANG_NO LPGEN("No") + +#define LANG_OTR_TOOLTIP LPGEN("OTR status (Click for more options)") +#define LANG_STATUS_DISABLED LPGEN("OTR Encryption: Disabled") +#define LANG_STATUS_UNVERIFIED LPGEN("OTR Encryption: UNVERIFIED") +#define LANG_STATUS_PRIVATE LPGEN("OTR Encryption: Private") +#define LANG_STATUS_FINISHED LPGEN("OTR Encryption: Finished") + +#define LANG_MENU_START LPGEN("&Start OTR session") +#define LANG_MENU_REFRESH LPGEN("&Refresh OTR session") +#define LANG_MENU_STOP LPGEN("Sto&p OTR session") +#define LANG_MENU_VERIFY LPGEN("&Verify Fingerprint") +#define LANG_MENU_TOGGLEHTML LPGEN("&Convert HTML (for Pidgin)") + +#define LANG_SESSION_TERMINATED_OTR LPGEN("OTR encrypted session with '%s' has been terminated") +#define LANG_SESSION_REQUEST_OTR LPGEN("Requesting OTR encrypted session with '%s'") +#define LANG_SESSION_START_OTR LPGEN("Beginning OTR encrypted session with '%s'") +#define LANG_SESSION_START_OTR_VERIFY LPGEN("Beginning OTR encrypted session with '%s' (NOT VERIFIED)") +#define LANG_SESSION_TRY_CONTINUE_OTR LPGEN("Trying to refresh OTR encrypted session with '%s'") +#define LANG_SESSION_HAS_CONTINUE_OTR LPGEN("OTR encrypted session was refreshed by '%s'") +#define LANG_SESSION_HAS_CONTINUE_OTR_VERIFY LPGEN("OTR encrypted session was refreshed by '%s' (NOT VERIFIED)") +#define LANG_SESSION_REQUEST_CONTINUE_OTR LPGEN("OTR encrypted session with '%s' sucessfully refreshed") +#define LANG_SESSION_CONTINUE_OTR LPGEN("OTR encrypted session with '%s' sucessfully refreshed") +#define LANG_SESSION_CONTINUE_OTR_VERIFY LPGEN("OTR encrypted session with '%s' sucessfully refreshed (NOT VERIFIED)") +#define LANG_SESSION_TERMINATED_BY_OTR LPGEN("OTR encrypted session has been terminated by '%s'. You should do that, too!") +#define LANG_SESSION_NOT_STARTED_OTR LPGEN("OTR encrypted session with '%s' could not be started") + +#define LANG_ENCRYPTION_ERROR LPGEN("OTR could not encrypt when sending message") + +#define LANG_OTR_INFO LPGEN("OTR Information") +#define LANG_INLINE_PREFIX LPGEN("[OTR INFO] ") + +#define LANG_SMP_AUTH_FROM LPGEN("Authentication from %s") +#define LANG_SMP_AUTH LPGEN("Authenticae %s") + +#define LANG_UNKNOWN LPGEN("Unknown") +#define LANG_OTR_USERMESSAGE LPGEN("OTR: %s (%s)") +#define LANG_OTR_NOTIFY LPGEN("OTR %s (%s)") + +//#define LANG_FINGERPRINT_CAPTION LPGEN("OTR New Fingerprint") +//#define LANG_FINGERPRINT_ASK_VERIFY LPGEN("OTR encrypted session with '%s'.\n\nFingerprint is UNVERIFIED.\n\n%s\n\nVerify?") +//#define LANG_FINGERPRINT_ASK_NEW LPGEN("A new fingerprint has been recieved from '%s'\n\n%s\n\nDo you trust it?") +#define LANG_FINGERPRINT_VERIFIED LPGEN("OTR encrypted session with '%s' is now using a VERIFIED fingerprint") +#define LANG_FINGERPRINT_NOT_VERIFIED LPGEN("OTR encrypted session with '%s' is now using a NOT VERIFIED fingerprint") + +#define LANG_ICON_UNVERIFIED LPGEN("OTR unverified") +#define LANG_ICON_FINISHED LPGEN("OTR finished") +#define LANG_ICON_PRIVATE LPGEN("OTR private") +#define LANG_ICON_NOT_PRIVATE LPGEN("OTR not secure") +#define LANG_ICON_OTR LPGEN("OTR") + +#define LANG_GENERATE_KEY LPGEN("Generating new private key for protocol '%s'.\nPlease Wait...") + +#define LANG_OPT_GENERAL LPGEN("General") +#define LANG_OPT_PROTO LPGEN("Protocols") +#define LANG_OPT_CONTACTS LPGEN("Contacts") +#define LANG_OPT_FINGER LPGEN("Fingerprints") + +#define LANG_CONTACT LPGEN("Contact") +#define LANG_PROTO LPGEN("Protocol") +#define LANG_POLICY LPGEN("Policy") +#define LANG_VERIFIED LPGEN("Verified") +#define LANG_ACTIVE LPGEN("Active") +#define LANG_FINGERPRINT LPGEN("Fingerprint") +#define LANG_HTMLCONV LPGEN("Conv. HTML") + +#define LANG_POLICY_DEFAULT LPGEN("Default") +#define LANG_POLICY_ALWAYS LPGEN("Always") +#define LANG_POLICY_OPP LPGEN("Opportunistic") +#define LANG_POLICY_MANUAL LPGEN("Manual") +#define LANG_POLICY_NEVER LPGEN("Never") + +#define LANG_OTR_ASK_NEWKEY LPGEN("Generating new key for '%s'. Continue?") +#define LANG_OTR_ASK_REMOVEKEY LPGEN("Removing key for '%s'. Continue?") + +#define LANG_OTR_FPVERIFY_TITLE LPGEN("OTR Fingerprint Verification") +#define LANG_OTR_FPVERIFY_DESC LPGEN("OTR encrypted session with '%s'.\nThe OTR fingerprint used by your contact is NOT VERIFIED.\nDo you trust it?") +#define LANG_OTR_FPVERIFIED_DESC LPGEN("OTR encrypted session with '%s'.\nThe OTR fingerprint used by your contact is already verified.\nDo you still trust it?") +#define LANG_YOUR_PRIVKEY LPGEN("Your Fingerprint to tell your contact (use a trusted channel!)") +#define LANG_CONTACT_FINGERPRINT LPGEN("VERIFY: Fingerprint from contact") + +#define LANG_SMP_VERIFY_TITLE LPGEN("OTR Authenticate: %s (%s)") +#define LANG_SMPTYPE_QUESTION LPGEN("Challenge Question") +#define LANG_SMPTYPE_PASSWORD LPGEN("Known Password") +#define LANG_SMPTYPE_FINGERPRINT LPGEN("Manual fingerprint comparison") +#define LANG_SMP_ANSWER LPGEN("Secret Answer") +#define LANG_SMP_QUESTION LPGEN("Question") +#define LANG_SMP_PASSWORD LPGEN("Password") + +#define LANG_SMP_SUCCESS LPGEN("Authentication sucessful.") +#define LANG_SMP_SUCCESS_VERIFY LPGEN("You contact authenticated you sucessful. You can send your own request to authenticate him.") +#define LANG_SMP_ERROR LPGEN("Error during authentication.") +#define LANG_SMP_FAILED LPGEN("Authentication failed") +#define LANG_SMP_IN_PROGRESS LPGEN("Authentication for '%s' is already in progress.") + +#define LANG_SMP_PROGRESS_TITLE LPGEN("OTR Authenticating: %s (%s)") +#define LANG_SMP_PROGRESS_DESC LPGEN("Authenticating contact:\n%s (%s)") + +#define LANG_OTR_SMPQUESTION_VERIFY_DESC LPGEN("OTR encrypted session with '%s' (UNVERIFIED).\nUse a question only your partner can answer.") +#define LANG_OTR_SMPQUESTION_VERIFIED_DESC LPGEN("OTR encrypted session with '%s' (VERIFIED).\nVerify the session again using a question only your partner can answer.") + +#define LANG_OTR_SMPPASSWORD_VERIFY_DESC LPGEN("OTR encrypted session with '%s' (UNVERIFIED).\nUse a known password.") +#define LANG_OTR_SMPPASSWORD_VERIFIED_DESC LPGEN("OTR encrypted session with '%s' (VERIFIED).\nVerify the session again using a known password.") + +#define LANG_OTR_SMPQUESTION_RESPOND_DESC LPGEN("Your contact '%s' wants to verify your identity with a question only you can answer.") + +#define LANG_OTR_SMPPASSWORD_RESPOND_DESC LPGEN("Your contact '%s' wants to verify your identity with a secret password you should know.") + +#define LANG_FINGERPRINT_STILL_IN_USE LPGEN("Fingerprint '%s' still in use in conversation with '%s' (%s). You cannot delete it!") +#define LANG_FINGERPRINT_NOT_DELETED LPGEN("Fingerprint '%s' in use in conversation with '%s' (%s). It could not be deleted!") + +#define LANG_OTR_SECUREIM_STARTED LPGEN("Cannot start OTR for '%s'. SecureIM is already running") +#define LANG_OTR_SECUREIM_TITLE LPGEN("OTR: SecureIM installed") +#define LANG_OTR_SECUREIM_TEXT LPGEN("You are using SecureIM. MirOTR will only work for contacts with SecureIM disabled") \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/src/mirotrmenu.cpp b/plugins/MirOTR/MirOTR/src/mirotrmenu.cpp new file mode 100644 index 0000000000..07a874c425 --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/mirotrmenu.cpp @@ -0,0 +1,294 @@ +#include "stdafx.h" +#include "m_genmenu.h" +#include "mirotrmenu.h" +static HANDLE hMirOTRMenuObject; +static HGENMENU hStatusInfoItem, hHTMLConvMenuItem; +HWND hDummyPaintWin; + +//contactmenu exec param(ownerdata) +//also used in checkservice +typedef struct +{ + char *szServiceName; +} +MirOTRMenuExecParam,*lpMirOTRMenuExecParam; + +//////////////////////////////////////////// +// MirOTR MENU +/////////////////////////////////////////// +static INT_PTR RemoveMirOTRMenuItem(WPARAM wParam, LPARAM) +{ + CallService(MO_REMOVEMENUITEM,wParam,0); + return 0; +} + +static INT_PTR AddMirOTRMenuItem(WPARAM, LPARAM lParam) +{ + MIROTRMENUITEM *mi=(MIROTRMENUITEM*)lParam; + if ( mi->cbSize != sizeof( MIROTRMENUITEM )) + return 0; + + TMO_MenuItem tmi = { 0 }; + tmi.cbSize = sizeof(tmi); + tmi.flags = mi->flags; + tmi.hIcon = mi->hIcon; + tmi.hIcolibItem = mi->icolibItem; + tmi.hotKey = mi->hotKey; + tmi.position = mi->position; + tmi.ptszName = mi->ptszName; + tmi.root = mi->root; + + //owner data + lpMirOTRMenuExecParam cmep = ( lpMirOTRMenuExecParam )mir_calloc(sizeof(MirOTRMenuExecParam)); + cmep->szServiceName = mir_strdup( mi->pszService ); + tmi.ownerdata = cmep; + + INT_PTR menuHandle = CallService(MO_ADDNEWMENUITEM, (WPARAM) hMirOTRMenuObject, (LPARAM)&tmi ); + + return menuHandle; +} + +static INT_PTR BuildMirOTRMenu(WPARAM wParam, LPARAM) +{ + HANDLE hContact = ( HANDLE )wParam; + //NotifyEventHooks(hPreBuildMirOTRMenuEvent,(WPARAM)hMirOTR,0); + + + ListParam param = { 0 }; + param.MenuObjectHandle = hMirOTRMenuObject; + param.wParam = (WPARAM)hContact; + HMENU hMenu = CreatePopupMenu(); + CallService(MO_BUILDMENU,(WPARAM)hMenu,(LPARAM)¶m); + + return (INT_PTR)hMenu; +} + +//called with: +//wparam - ownerdata +//lparam - lparam from winproc +INT_PTR MirOTRMenuExecService(WPARAM wParam,LPARAM lParam) +{ + if (wParam!=0) { + lpMirOTRMenuExecParam cmep=(lpMirOTRMenuExecParam)wParam; + //call with wParam=(WPARAM)(HANDLE)hContact + CallService(cmep->szServiceName,lParam,0); + } + return 0; +} + +//true - ok,false ignore +INT_PTR MirOTRMenuCheckService(WPARAM wParam,LPARAM) +{ + PCheckProcParam pcpp = ( PCheckProcParam )wParam; + lpMirOTRMenuExecParam cmep=NULL; + TMO_MenuItem mi; + + if ( pcpp == NULL ) + return FALSE; + + cmep = ( lpMirOTRMenuExecParam )pcpp->MenuItemOwnerData; + if ( cmep == NULL ) //this is rootsection...build it + return TRUE; + + HANDLE hContact = (HANDLE)pcpp->wParam, hSub; + if(options.bHaveMetaContacts && (hSub = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0)) != 0) { + hContact = hSub; + } + + TrustLevel level = ( TrustLevel )otr_context_get_trust(otrl_context_find_miranda(otr_user_state, hContact)); + + mi.cbSize = sizeof(mi); + if ( CallService(MO_GETMENUITEM, ( WPARAM )pcpp->MenuItemHandle, ( LPARAM )&mi ) == 0 ) { + + if ( mi.flags & CMIF_HIDDEN ) return FALSE; + if ( mi.flags & CMIF_NOTPRIVATE && level==TRUST_PRIVATE ) return FALSE; + if ( mi.flags & CMIF_NOTFINISHED && level==TRUST_FINISHED ) return FALSE; + if ( mi.flags & CMIF_NOTUNVERIFIED && level==TRUST_UNVERIFIED ) return FALSE; + if ( mi.flags & CMIF_NOTNOTPRIVATE && level==TRUST_NOT_PRIVATE ) return FALSE; + + if (pcpp->MenuItemHandle == hStatusInfoItem) { + mi.flags = CMIM_NAME | CMIM_ICON | CMIF_ICONFROMICOLIB | CMIF_TCHAR; + switch (level) { + case TRUST_PRIVATE: + mi.hIcolibItem = GetIconHandle(ICON_PRIVATE); + mi.ptszName = TranslateT(LANG_STATUS_PRIVATE); + break; + case TRUST_UNVERIFIED: + mi.hIcolibItem = GetIconHandle(ICON_UNVERIFIED); + mi.ptszName = TranslateT(LANG_STATUS_UNVERIFIED); + break; + case TRUST_FINISHED: + mi.hIcolibItem = GetIconHandle(ICON_FINISHED); + mi.ptszName = TranslateT(LANG_STATUS_FINISHED); + break; + default: + mi.hIcolibItem = GetIconHandle(ICON_NOT_PRIVATE); + mi.ptszName = TranslateT(LANG_STATUS_DISABLED); + } + CallService(MO_MODIFYMENUITEM, (WPARAM)hStatusInfoItem, (LPARAM)&mi); + } else if (pcpp->MenuItemHandle == hHTMLConvMenuItem) { + if (db_get_b(hContact, MODULENAME, "HTMLConv", 0) ) + mi.flags |= CMIM_FLAGS|CMIF_CHECKED; + else + mi.flags = CMIM_FLAGS|(mi.flags &~CMIF_CHECKED); + CallService(MO_MODIFYMENUITEM, (WPARAM)hHTMLConvMenuItem, (LPARAM)&mi); + } + } + return TRUE; +} + +INT_PTR FreeOwnerDataMirOTRMenu (WPARAM, LPARAM lParam) +{ + lpMirOTRMenuExecParam cmep = ( lpMirOTRMenuExecParam )lParam; + if ( cmep != NULL ) { + if (cmep->szServiceName) mir_free(cmep->szServiceName); + mir_free(cmep); + } + return 0; +} + +INT_PTR OnAddMenuItemMirOTRMenu (WPARAM wParam, LPARAM lParam) +{ + + MENUITEMINFO *mii = (MENUITEMINFO*)wParam; + if (!mii || mii->cbSize != sizeof(MENUITEMINFO)) return 0; + + TMO_MenuItem mi; + mi.cbSize = sizeof(mi); + if ( CallService(MO_GETMENUITEM, ( WPARAM )lParam, ( LPARAM )&mi ) == 0 ) { + if (mi.flags & CMIF_DISABLED) { + mii->fMask |= MIIM_STATE; + mii->fState |= MF_DISABLED; + } + } + return 1; +} + + +LRESULT CALLBACK PopupMenuWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_MEASUREITEM: + if (CallService(MS_CLIST_MENUMEASUREITEM, wParam, lParam)) return TRUE; + break; + case WM_DRAWITEM: + if (CallService(MS_CLIST_MENUDRAWITEM, wParam, lParam)) return TRUE; + break; + case WM_COMMAND: + if (CallService(MO_PROCESSCOMMANDBYMENUIDENT, wParam, GetWindowLongPtr(hwnd, GWLP_USERDATA))) return TRUE; + break; + } + return DefWindowProc(hwnd, message, wParam, lParam); +} + +void ShowOTRMenu(HANDLE hContact, POINT pt){ + HMENU menu = (HMENU) CallService(MS_MIROTR_MENUBUILDMIROTR, (WPARAM)hContact, 0); + SetWindowLongPtr(hDummyPaintWin, GWLP_USERDATA, (LONG_PTR)hContact); + TrackPopupMenu(menu, 0, pt.x, pt.y, 0, hDummyPaintWin, 0); + DestroyMenu(menu); +} + +void InitMirOTRMenu(void) +{ + + WNDCLASS wc = {0}; + wc.hInstance = hInst; + wc.lpfnWndProc = PopupMenuWndProc; + wc.lpszClassName = _T("MirOTRPopUpMenuProcessor"); + RegisterClass(&wc); + hDummyPaintWin = CreateWindowEx(0, _T("MirOTRPopUpMenuProcessor"), NULL, 0, 0, 0, 1, 1, 0, 0, hInst, 0); + + CreateServiceFunction("MirOTRMenuExecService",MirOTRMenuExecService); + CreateServiceFunction("MirOTRMenuCheckService",MirOTRMenuCheckService); + + //free services + CreateServiceFunction("MIROTRMENUS/FreeOwnerDataMirOTRMenu",FreeOwnerDataMirOTRMenu); + CreateServiceFunction("MIROTRMENUS/OnAddMenuItemMirOTRMenu",OnAddMenuItemMirOTRMenu); + + + CreateServiceFunction(MS_MIROTR_ADDMIROTRMENUITEM,AddMirOTRMenuItem); + CreateServiceFunction(MS_MIROTR_MENUBUILDMIROTR,BuildMirOTRMenu); + CreateServiceFunction(MS_MIROTR_REMOVEMIROTRMENUITEM,RemoveMirOTRMenuItem); + + //hPreBuildMirOTRMenuEvent=CreateHookableEvent(ME_CLIST_PREBUILDMirOTRMENU); + + //MirOTR menu + { + TMenuParam tmp = { 0 }; + tmp.cbSize=sizeof(tmp); + tmp.CheckService="MirOTRMenuCheckService"; + tmp.ExecService="MirOTRMenuExecService"; + tmp.name="MirOTRMenu"; + hMirOTRMenuObject=(HANDLE)CallService(MO_CREATENEWMENUOBJECT,(WPARAM)0,(LPARAM)&tmp); + } + + OptParam params; + params.Handle = hMirOTRMenuObject; + params.Setting = OPT_USERDEFINEDITEMS; + params.Value = FALSE; + CallService(MO_SETOPTIONSMENUOBJECT, 0, (LPARAM)¶ms); + + params.Setting = OPT_MENUOBJECT_SET_FREE_SERVICE; + params.Value = (INT_PTR)"MIROTRMENUS/FreeOwnerDataMirOTRMenu"; + CallService(MO_SETOPTIONSMENUOBJECT, 0, (LPARAM)¶ms); + + params.Setting = OPT_MENUOBJECT_SET_ONADD_SERVICE; + params.Value = (INT_PTR)"MIROTRMENUS/OnAddMenuItemMirOTRMenu"; + CallService(MO_SETOPTIONSMENUOBJECT, 0, (LPARAM)¶ms); + + + MIROTRMENUITEM mi = {0}; + mi.cbSize = sizeof(mi); + + mi.flags = CMIF_DISABLED|CMIF_TCHAR|CMIF_ICONFROMICOLIB; + mi.ptszName = _T("OTR Status"); + mi.position = 0; + hStatusInfoItem = (HGENMENU) AddMirOTRMenuItem(0, (LPARAM) &mi); + + mi.flags = CMIF_TCHAR|CMIF_ICONFROMICOLIB|CMIF_NOTPRIVATE|CMIF_NOTUNVERIFIED; + mi.ptszName = _T(LANG_MENU_START); + mi.position = 100001; + mi.pszService = MS_OTR_MENUSTART; + mi.icolibItem = GetIconHandle(ICON_UNVERIFIED); + AddMirOTRMenuItem(0, (LPARAM) &mi); + + mi.flags = CMIF_TCHAR|CMIF_ICONFROMICOLIB|CMIF_NOTNOTPRIVATE|CMIF_NOTFINISHED; + mi.ptszName = _T(LANG_MENU_REFRESH); + mi.position = 100002; + mi.pszService = MS_OTR_MENUREFRESH; + mi.icolibItem = GetIconHandle(ICON_FINISHED); + AddMirOTRMenuItem(0, (LPARAM) &mi); + + mi.flags = CMIF_TCHAR|CMIF_ICONFROMICOLIB|CMIF_NOTNOTPRIVATE; + mi.ptszName = _T(LANG_MENU_STOP); + mi.position = 100003; + mi.pszService = MS_OTR_MENUSTOP; + mi.icolibItem = GetIconHandle(ICON_NOT_PRIVATE); + AddMirOTRMenuItem(0, (LPARAM) &mi); + + mi.flags = CMIF_TCHAR|CMIF_ICONFROMICOLIB|CMIF_NOTNOTPRIVATE|CMIF_NOTFINISHED; + mi.ptszName = _T(LANG_MENU_VERIFY); + mi.position = 200001; + mi.pszService = MS_OTR_MENUVERIFY; + mi.icolibItem = GetIconHandle(ICON_PRIVATE); + AddMirOTRMenuItem(0, (LPARAM) &mi); + + mi.flags = CMIF_TCHAR|CMIF_CHECKED; + mi.ptszName = _T(LANG_MENU_TOGGLEHTML); + mi.position = 300001; + mi.pszService = MS_OTR_MENUTOGGLEHTML; + hHTMLConvMenuItem = (HGENMENU) AddMirOTRMenuItem(0, (LPARAM) &mi); + + + +} + +void UninitMirOTRMenu(void) +{ + DestroyWindow(hDummyPaintWin); + hDummyPaintWin = 0; + UnregisterClass(_T("MirOTRPopUpMenuProcessor"), hInst); + if ( hMirOTRMenuObject ) CallService( MO_REMOVEMENUOBJECT, (WPARAM)hMirOTRMenuObject, 0 ); + hMirOTRMenuObject = 0; +} \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/src/mirotrmenu.h b/plugins/MirOTR/MirOTR/src/mirotrmenu.h new file mode 100644 index 0000000000..fe070f0ba8 --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/mirotrmenu.h @@ -0,0 +1,45 @@ +#pragma once +#define MS_MIROTR_ADDMIROTRMENUITEM MODULENAME"/AddMirOTRMenuItem" +#define MS_MIROTR_MENUBUILDMIROTR MODULENAME"/MenuBuildMirOTR" +#define MS_MIROTR_REMOVEMIROTRMENUITEM MODULENAME"/RemoveMirOTRMenuItem" + +#define CMIF_NOTNOTPRIVATE CMIF_NOTOFFLINE +#define CMIF_NOTUNVERIFIED CMIF_NOTONLINE +#define CMIF_NOTPRIVATE CMIF_NOTONLIST +#define CMIF_NOTFINISHED CMIF_NOTOFFLIST +#define CMIF_DISABLED 0x8000 + +//add a new item to the MirOTR Menu +//wParam=0 +//lParam=(LPARAM)(CLISTMENUITEM*)&mi +//returns a handle to the new item, or NULL on failure +//the service that is called when the item is clicked is called with +//wParam=0, lParam=hContact +//dividers are inserted every 100000 positions +//pszContactOwner is ignored for this service. +// +// WARNING: do not use Translate(TS) for p(t)szName or p(t)szPopupName as they +// are translated by the core, which may lead to double translation. +// Use LPGEN instead which are just dummy wrappers/markers for "lpgen.pl". +typedef struct { + int cbSize; //size in bytes of this structure + union { + char* pszName; //[TRANSLATED-BY-CORE] text of the menu item + TCHAR* ptszName; //Unicode text of the menu item + }; + int position; //approx position on the menu. lower numbers go nearer the top + HGENMENU root; //submenu where the item will be added, NULL for root + DWORD flags; //set of MOMIF_* flags + union { + HICON hIcon; //icon to put by the item. If this was not loaded from + //a resource, you can delete it straight after the call + HANDLE icolibItem; //set CMIF_ICONFROMICOLIB to pass this value + }; + DWORD hotKey; //keyboard accelerator, same as lParam of WM_HOTKEY,0 for none + char* pszService; //name of service to call when the item gets selected +} MIROTRMENUITEM; + +void InitMirOTRMenu(void); +void UninitMirOTRMenu(void); + +void ShowOTRMenu(HANDLE hContact, POINT pt); \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/src/options.cpp b/plugins/MirOTR/MirOTR/src/options.cpp new file mode 100644 index 0000000000..8af221d5da --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/options.cpp @@ -0,0 +1,911 @@ +#include "stdafx.h" +#include "options.h" +#include "utils.h" +#include "m_options.h" +#include +#include +#include + +char g_fingerprint_store_filename[MAX_PATH]; +char g_private_key_filename[MAX_PATH]; +HANDLE hPATH_MIROTR; +Options options; +#define DATA_DIRECTORY MIRANDA_USERDATA "\\" MODULENAME +HANDLE hHookOptions; +struct PROTOREGENKEYOPTIONS { + HWND refresh; + TCHAR proto[129]; +}; + +void SetFilenames(const char *path) { + if (!path || !path[0]) return; + CallService(MS_UTILS_CREATEDIRTREE, 0, (LPARAM) path); + strcpy(g_fingerprint_store_filename, path); + strcpy(g_private_key_filename, path); + strcat(g_fingerprint_store_filename, ("\\")); + strcat(g_private_key_filename, ("\\")); + + strcat(g_fingerprint_store_filename, FINGERPRINT_STORE_FILENAME); + strcat(g_private_key_filename, PRIVATE_KEY_FILENAME); +} + +int FoldersChanged(WPARAM wParam, LPARAM lParam) { + char path[MAX_PATH]; + + FOLDERSGETDATA fgd = {0}; + fgd.cbSize = sizeof(FOLDERSGETDATA); + fgd.nMaxPathSize = MAX_PATH; + fgd.szPath = path; + if (CallService(MS_FOLDERS_GET_PATH, (LPARAM)hPATH_MIROTR, (LPARAM)&fgd)) { + char *mypath = Utils_ReplaceVars(DATA_DIRECTORY); + SetFilenames(mypath); + mir_free(mypath); + } else + SetFilenames(path); + + ReadPrivkeyFiles(); + return 0; +} + +void LoadFilenames() { + if(ServiceExists(MS_FOLDERS_REGISTER_PATH)) { + hPATH_MIROTR = FoldersRegisterCustomPath(MODULENAME, "Private Data", DATA_DIRECTORY); + HookEvent(ME_FOLDERS_PATH_CHANGED, FoldersChanged); + + // get the path - above are only defaults - there may be a different value in the db + FoldersChanged(0, 0); + } else { + char *path = Utils_ReplaceVars(DATA_DIRECTORY); + SetFilenames(path); + mir_free(path); + ReadPrivkeyFiles(); + } +} + +void LoadOptions() { + options.default_policy = DBGetContactSettingWord(0, MODULENAME, "DefaultPolicy", OTRL_POLICY_OPPORTUNISTIC); + // deal with changed flags in proto.h and new interpretation of 'manual' mode (see common.h) + switch(options.default_policy) { + case OTRL_POLICY_MANUAL: + options.default_policy = OTRL_POLICY_MANUAL_MOD; + break; + case OTRL_POLICY_OPPORTUNISTIC: + case OTRL_POLICY_MANUAL_MOD: + case OTRL_POLICY_ALWAYS: + case OTRL_POLICY_NEVER: + break; + default: + options.default_policy = OTRL_POLICY_OPPORTUNISTIC; + break; + } + options.err_method = (ErrorDisplay)DBGetContactSettingWord(0, MODULENAME, "ErrorDisplay", ED_POP); + options.prefix_messages = (DBGetContactSettingByte(0, MODULENAME, "PrefixMessages", 0) == 1); + options.msg_inline = (DBGetContactSettingByte(0, MODULENAME, "MsgInline", 0) == 1); + options.msg_popup = (DBGetContactSettingByte(0, MODULENAME, "MsgPopup", 1) == 1); + options.delete_history = (DBGetContactSettingByte(0, MODULENAME, "NoHistory", 0) == 1); + options.delete_systeminfo = (DBGetContactSettingByte(0, MODULENAME, "NoSystemHistory", 0) == 1); + options.autoshow_verify = (DBGetContactSettingByte(0, MODULENAME, "AutoShowVerify", 1) == 1); + + DBVARIANT dbv; + if (!DBGetContactSettingUTF8String(0, MODULENAME, "Prefix", &dbv)) { + strncpy(options.prefix, dbv.pszVal, OPTIONS_PREFIXLEN); + options.prefix[OPTIONS_PREFIXLEN-1] = 0; + DBFreeVariant(&dbv); + } else + strcpy(options.prefix, ("OTR: ")); + + options.timeout_finished = (DBGetContactSettingByte(0, MODULENAME, "TimeoutFinished", 0) == 1); + + options.end_offline = (DBGetContactSettingByte(0, MODULENAME, "EndOffline", 1) == 1); + options.end_window_close = (DBGetContactSettingByte(0, MODULENAME, "EndWindowClose", 0) == 1); + + options.bHaveMetaContacts = 0!=ServiceExists(MS_MC_GETMETACONTACT); + options.bHavePopups = 0!=ServiceExists(MS_POPUP_ADDPOPUPT) && ServiceExists(MS_POPUP_SHOWMESSAGE); + options.bHaveSRMMIcons = 0!=ServiceExists(MS_MSG_MODIFYICON); + options.bHaveSecureIM = 0!=ServiceExists("SecureIM/IsContactSecured"); + options.bHaveButtonsBar = 0!=ServiceExists(MS_BB_ADDBUTTON); + + LoadFilenames(); +} + +extern "C" int OpenOptions(WPARAM wParam, LPARAM lParam) +{ + OPTIONSDIALOGPAGE odp = { 0 }; + + odp.cbSize = sizeof(odp); + odp.position = 100; + odp.hInstance = hInst; + odp.ptszGroup = LPGENT("Plugins"); //"Plugins" + odp.ptszTitle = _T(MODULENAME); + odp.flags = ODPF_BOLDGROUPS|ODPF_TCHAR; + + odp.ptszTab = _T(LANG_OPT_GENERAL); + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_GENERAL); + odp.pfnDlgProc = DlgProcMirOTROpts; + Options_AddPage(wParam, &odp); + + odp.ptszTab = _T(LANG_OPT_PROTO); + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_PROTO); + odp.pfnDlgProc = DlgProcMirOTROptsProto; + Options_AddPage(wParam, &odp); + + odp.ptszTab = _T(LANG_OPT_CONTACTS); + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_CONTACTS); + odp.pfnDlgProc = DlgProcMirOTROptsContacts; + Options_AddPage(wParam, &odp); + + odp.ptszTab = _T(LANG_OPT_FINGER); + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_FINGER); + odp.pfnDlgProc = DlgProcMirOTROptsFinger; + Options_AddPage(wParam, &odp); + + return 0; +} + +void InitOptions() { + LoadOptions(); + hHookOptions = HookEvent(ME_OPT_INITIALISE, OpenOptions); +} + +void DeinitOptions() { + UnhookEvent(hHookOptions); +} + +void SaveOptions() { + DBWriteContactSettingWord(0, MODULENAME, "DefaultPolicy", options.default_policy); + DBWriteContactSettingWord(0, MODULENAME, "ErrorDisplay", (int)options.err_method); + DBWriteContactSettingByte(0, MODULENAME, "PrefixMessages", options.prefix_messages ? 1 : 0); + DBWriteContactSettingByte(0, MODULENAME, "MsgInline", options.msg_inline ? 1 : 0); + DBWriteContactSettingByte(0, MODULENAME, "MsgPopup", options.msg_popup ? 1 : 0); + + DBWriteContactSettingByte(0, MODULENAME, "NoHistory", options.delete_history ? 1 : 0); + DBWriteContactSettingByte(0, MODULENAME, "NoSystemHistory", options.delete_systeminfo ? 1 : 0); + DBWriteContactSettingByte(0, MODULENAME, "AutoShowVerify", options.autoshow_verify ? 1 : 0); + + /* + if (contact_policies) { + for(ContactPolicyMap::iterator i = contact_policies->begin(); i != contact_policies->end(); i++) { + DBWriteContactSettingWord(i->first, MODULENAME, "Policy", i->second); + } + } + */ + + DBWriteContactSettingStringUtf(0, MODULENAME, "Prefix", options.prefix); + + DBWriteContactSettingByte(0, MODULENAME, "TimeoutFinished", options.timeout_finished ? 1 : 0); + + DBWriteContactSettingByte(0, MODULENAME, "EndOffline", options.end_offline ? 1 : 0); + DBWriteContactSettingByte(0, MODULENAME, "EndWindowClose", options.end_window_close ? 1 : 0); +} + +extern "C" void set_context_contact(void *data, ConnContext *context) { + HANDLE hContact = find_contact(context->username, context->protocol); + context->app_data = hContact; + } + +void ReadPrivkeyFiles() { + DEBUGOUT_T("READ privkey"); + lib_cs_lock(); + otrl_privkey_read(otr_user_state, g_private_key_filename); + otrl_privkey_read_fingerprints(otr_user_state, g_fingerprint_store_filename, set_context_contact, 0); + lib_cs_unlock(); +} + +static INT_PTR CALLBACK DlgProcMirOTROpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + TCHAR *prefix; char* prefix_utf; + switch ( msg ) { + case WM_INITDIALOG: + TranslateDialogDefault( hwndDlg ); + + // set default policy radio + switch(options.default_policy) { + case OTRL_POLICY_OPPORTUNISTIC: + CheckDlgButton(hwndDlg, IDC_RAD_OPP, TRUE); + break; + case OTRL_POLICY_MANUAL_MOD: + CheckDlgButton(hwndDlg, IDC_RAD_MANUAL, TRUE); + break; + case OTRL_POLICY_ALWAYS: + CheckDlgButton(hwndDlg, IDC_RAD_ALWAYS, TRUE); + break; + case OTRL_POLICY_NEVER: + CheckDlgButton(hwndDlg, IDC_RAD_NEVER, TRUE); + break; + } + + CheckDlgButton(hwndDlg, IDC_CHK_PREFIX, options.prefix_messages ? TRUE : FALSE); + CheckDlgButton(hwndDlg, IDC_CHK_MSGINLINE, options.msg_inline ? TRUE : FALSE); + CheckDlgButton(hwndDlg, IDC_CHK_MSGPOPUP, options.msg_popup ? TRUE : FALSE); + CheckDlgButton(hwndDlg, IDC_CHK_TIMEFINISH, options.timeout_finished ? TRUE : FALSE); + CheckDlgButton(hwndDlg, IDC_CHK_PREVENTSAVE, options.delete_history ? TRUE : FALSE); + CheckDlgButton(hwndDlg, IDC_CHK_PREVENTSYSSAVE, options.delete_systeminfo ? TRUE : FALSE); + CheckDlgButton(hwndDlg, IDC_CHK_AUTOSHOW_VERIFY, options.autoshow_verify ? TRUE : FALSE); + CheckDlgButton(hwndDlg, IDC_CHK_ENDOFFLINE, options.end_offline ? TRUE : FALSE); + CheckDlgButton(hwndDlg, IDC_CHK_ENDCLOSE, options.end_window_close ? TRUE : FALSE); + + prefix = mir_utf8decodeT(options.prefix); + SetDlgItemText(hwndDlg, IDC_ED_PREFIX, prefix); + mir_free(prefix); + + return TRUE; + break; + + case WM_COMMAND: + switch ( HIWORD( wParam )) { + case BN_CLICKED: + switch ( LOWORD( wParam )) { + case IDC_RAD_OPP: + case IDC_RAD_MANUAL: + case IDC_RAD_ALWAYS: + case IDC_RAD_NEVER: + case IDC_CHK_PREFIX: + case IDC_CHK_MSGINLINE: + case IDC_CHK_MSGPOPUP: + case IDC_CHK_TIMEFINISH: + case IDC_CHK_PREVENTSAVE: + case IDC_CHK_AUTOSHOW_VERIFY: + case IDC_CHK_ENDOFFLINE: + case IDC_CHK_ENDCLOSE: + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + } + case EN_CHANGE: + if (LOWORD( wParam ) == IDC_ED_PREFIX && ( HWND )lParam == GetFocus()) + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + } + break; + + case WM_NOTIFY: + + if (((LPNMHDR)lParam)->code == (UINT) PSN_APPLY ) { + // handle apply + + if (IsDlgButtonChecked(hwndDlg, IDC_RAD_OPP)) + options.default_policy = OTRL_POLICY_OPPORTUNISTIC; + else if (IsDlgButtonChecked(hwndDlg, IDC_RAD_MANUAL)) + options.default_policy = OTRL_POLICY_MANUAL_MOD; + else if (IsDlgButtonChecked(hwndDlg, IDC_RAD_ALWAYS)) + options.default_policy = OTRL_POLICY_ALWAYS; + else + options.default_policy = OTRL_POLICY_NEVER; + + options.prefix_messages = (TRUE==IsDlgButtonChecked(hwndDlg, IDC_CHK_PREFIX)); + options.msg_inline = (TRUE==IsDlgButtonChecked(hwndDlg, IDC_CHK_MSGINLINE)); + options.msg_popup = (TRUE==IsDlgButtonChecked(hwndDlg, IDC_CHK_MSGPOPUP)); + options.timeout_finished = (TRUE==IsDlgButtonChecked(hwndDlg, IDC_CHK_TIMEFINISH)); + options.delete_history = (TRUE==IsDlgButtonChecked(hwndDlg, IDC_CHK_PREVENTSAVE)); + options.delete_systeminfo = (TRUE==IsDlgButtonChecked(hwndDlg, IDC_CHK_PREVENTSYSSAVE)); + options.autoshow_verify = (TRUE==IsDlgButtonChecked(hwndDlg, IDC_CHK_AUTOSHOW_VERIFY)); + options.end_offline = (TRUE==IsDlgButtonChecked(hwndDlg, IDC_CHK_ENDOFFLINE)); + options.end_window_close = (TRUE==IsDlgButtonChecked(hwndDlg, IDC_CHK_ENDCLOSE)); + + prefix = (TCHAR*)mir_alloc(sizeof(TCHAR)*OPTIONS_PREFIXLEN); + GetDlgItemText(hwndDlg, IDC_ED_PREFIX, prefix, OPTIONS_PREFIXLEN); + prefix_utf = mir_utf8encodeT(prefix); + mir_free(prefix); + strncpy(options.prefix, prefix_utf, OPTIONS_PREFIXLEN); + mir_free(prefix_utf); + + SaveOptions(); + + return TRUE; + } + + break; + } + return FALSE; +} + +static unsigned int CALLBACK regen_key_thread(void* param) +{ + Thread_Push(0); + PROTOREGENKEYOPTIONS *opts = (PROTOREGENKEYOPTIONS *)param; + TCHAR *buff = (TCHAR*) mir_alloc(512*sizeof(TCHAR)); + mir_sntprintf(buff, 512, TranslateT(LANG_OTR_ASK_NEWKEY), opts->proto); + EnableWindow(opts->refresh, FALSE); + if (IDYES == MessageBox(opts->refresh, buff, TranslateT(LANG_OTR_INFO), MB_ICONQUESTION|MB_YESNO)) + { + mir_free(buff); + + char* proto = mir_t2a(opts->proto); + otr_gui_create_privkey(0, proto, proto); + SendMessage(opts->refresh, WMU_REFRESHPROTOLIST, 0, 0); + /* + char *fp = (char*)mir_alloc(20); + otrl_privkey_fingerprint(otr_user_state, fp, proto, proto); + TCHAR *fpt = mir_a2t(fp); + mir_free(fp); + ListView_SetItemText(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS), sel, 2, fpt); + mir_free(fpt); + mir_free(proto); + */ + } else { + mir_free(buff); + } + EnableWindow(opts->refresh, TRUE); + delete opts; + Thread_Pop(); + return 0; +} + +static INT_PTR CALLBACK DlgProcMirOTROptsProto(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + HWND lv; + switch ( msg ) { + case WM_INITDIALOG: + TranslateDialogDefault( hwndDlg ); + lv = GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS); + + { + HWND cmb = GetDlgItem(hwndDlg, IDC_CMB_PROTO_POLICY); + SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_DEFAULT)); + SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_ALWAYS)); + SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_OPP)); + SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_MANUAL)); + SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_NEVER)); + SendMessage(GetDlgItem(hwndDlg, IDC_CMB_PROTO_POLICY), CB_SETCURSEL, (LPARAM)-1, 0); + EnableWindow(GetDlgItem(hwndDlg, IDC_CMB_PROTO_POLICY), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_NEWKEY), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_FORGET), FALSE); + } + + SendMessage(lv,LVM_SETEXTENDEDLISTVIEWSTYLE, 0,LVS_EX_FULLROWSELECT);// | LVS_EX_CHECKBOXES); + { + // add list columns + LVCOLUMN lvc; + // Initialize the LVCOLUMN structure. + // The mask specifies that the format, width, text, and + // subitem members of the structure are valid. + lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; + lvc.fmt = LVCFMT_LEFT; + + lvc.iSubItem = 0; + lvc.pszText = TranslateT(LANG_PROTO); + lvc.cx = 85; // width of column in pixels + ListView_InsertColumn(lv, 0, &lvc); + + lvc.iSubItem = 1; + lvc.pszText = TranslateT(LANG_POLICY); + lvc.cx = 80; // width of column in pixels + ListView_InsertColumn(lv, 1, &lvc); + + lvc.iSubItem = 2; + lvc.pszText = TranslateT(LANG_FINGERPRINT); + lvc.cx = 275; // width of column in pixels + ListView_InsertColumn(lv, 2, &lvc); + } + PostMessage(hwndDlg, WMU_REFRESHPROTOLIST, 0, 0); + + return TRUE; + case WMU_REFRESHPROTOLIST: + { + lv = GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS); + ListView_DeleteAllItems(lv); + int num_protocols; + PROTOACCOUNT **pppDesc; + int ilvItem; + LV_ITEM item = {0}; + char fprint[45]; + TCHAR* temp; + //BOOL unicode = ListView_GetUnicodeFormat(lv); + + ProtoEnumAccounts(&num_protocols, &pppDesc); + for(int i = 0; i < num_protocols; i++) { + if((!g_metaproto || strcmp(pppDesc[i]->szModuleName, g_metaproto) != 0) + && (CallProtoService(pppDesc[i]->szModuleName, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IM) == PF1_IM) + { + //if (unicode) { + item.mask = LVIF_TEXT; + temp = mir_a2t(pppDesc[i]->szModuleName); + item.pszText = temp; + ilvItem = ListView_InsertItem(lv, &item); + mir_free(temp); + + + ListView_SetItemText(lv, ilvItem, 1, (TCHAR*)policy_to_string(db_get_dw(0,MODULENAME"_ProtoPol", pppDesc[i]->szModuleName, CONTACT_DEFAULT_POLICY)) ); + if(otrl_privkey_fingerprint(otr_user_state, fprint, pppDesc[i]->szModuleName, pppDesc[i]->szModuleName)) { + temp = mir_a2t(fprint); + ListView_SetItemText(lv, ilvItem, 2, temp); + mir_free(temp); + } + } + } + } + return TRUE; + case WM_COMMAND: + switch ( HIWORD( wParam )) { + case BN_CLICKED: + switch ( LOWORD( wParam )) { + case IDC_BTN_PROTO_NEWKEY: + { + int sel = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS)); + if (sel != -1) { + PROTOREGENKEYOPTIONS *opts = new PROTOREGENKEYOPTIONS(); + opts->refresh = hwndDlg; + ListView_GetItemText(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS), sel, 0, opts->proto, 128); + CloseHandle((HANDLE)_beginthreadex(0, 0, regen_key_thread, opts, 0, 0)); + } + }break; + case IDC_BTN_PROTO_FORGET: + { + int sel = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS)); + if (sel != -1) { + TCHAR buff_proto[128]; + ListView_GetItemText(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS), sel, 0, buff_proto, 128); + TCHAR buff[512]; + mir_sntprintf(buff, 512, TranslateT(LANG_OTR_ASK_REMOVEKEY), buff_proto); + if (IDYES == MessageBox(hwndDlg, buff, TranslateT(LANG_OTR_INFO), MB_ICONQUESTION|MB_YESNO)) + { + char* proto = mir_t2a(buff_proto); + OtrlPrivKey *key = otrl_privkey_find(otr_user_state, proto, proto); + mir_free(proto); + if (key) { + otrl_privkey_forget(key); + otrl_privkey_write(otr_user_state, g_private_key_filename); + ListView_SetItemText(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS), sel, 2, _T("")); + } + } + } + }break; + } + case CBN_SELCHANGE: + switch ( LOWORD( wParam )) { + case IDC_CMB_PROTO_POLICY: + { + int proto = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS)); + if (proto == -1) break; + int sel = SendDlgItemMessage(hwndDlg, IDC_CMB_PROTO_POLICY, CB_GETCURSEL, 0, 0); + if (sel==CB_ERR) break; + int len = SendDlgItemMessage(hwndDlg, IDC_CMB_PROTO_POLICY, CB_GETLBTEXTLEN, sel, 0); + if (len < 0) break; + TCHAR *text = new TCHAR[len+1]; + SendDlgItemMessage(hwndDlg, IDC_CMB_PROTO_POLICY, CB_GETLBTEXT, sel, (LPARAM)text); + ListView_SetItemText(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS), proto, 1, text); + delete text; + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + }break; + } + break; + } + break; + + case WM_NOTIFY: + if (((LPNMHDR) lParam)->code == (UINT) LVN_ITEMCHANGED && ((LPNMHDR) lParam)->hwndFrom == GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS) + && (((LPNMLISTVIEW)lParam)->uNewState & LVIS_SELECTED )) { + int sel = ListView_GetSelectionMark(((LPNMHDR) lParam)->hwndFrom); + if (sel == -1) { + SendMessage(GetDlgItem(hwndDlg, IDC_CMB_PROTO_POLICY), CB_SETCURSEL, (LPARAM)-1, 0); + EnableWindow(GetDlgItem(hwndDlg, IDC_CMB_PROTO_POLICY), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_NEWKEY), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_FORGET), FALSE); + } else { + EnableWindow(GetDlgItem(hwndDlg, IDC_CMB_PROTO_POLICY), TRUE); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_NEWKEY), TRUE); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_FORGET), TRUE); + TCHAR buff[50]; + ListView_GetItemText(((LPNMHDR)lParam)->hwndFrom, sel, 1, buff, 50); + SendMessage(GetDlgItem(hwndDlg, IDC_CMB_PROTO_POLICY), CB_SELECTSTRING, (LPARAM)-1, (WPARAM)buff); + } + + } else if (((LPNMHDR)lParam)->code == (UINT) PSN_APPLY ) { + lv = GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS); + int cnt = ListView_GetItemCount(lv); + TCHAR proto_t[128], policy[64]; + char* proto; + for (int i = 0; i < cnt; ++i) { + ListView_GetItemText(lv, i, 0, proto_t, 128); + ListView_GetItemText(lv, i, 1, policy, 64); + proto = mir_t2a(proto_t); + db_set_dw(0, MODULENAME"_ProtoPol", proto, policy_from_string(policy)); + mir_free(proto); + } + // handle apply + return TRUE; + } + break; + } + return FALSE; +} + +static INT_PTR CALLBACK DlgProcMirOTROptsContacts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch ( msg ) { + case WM_INITDIALOG: + { + TranslateDialogDefault( hwndDlg ); + + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (ULONG_PTR) new ContactPolicyMap()); + + HWND cmb = GetDlgItem(hwndDlg, IDC_CMB_CONT_POLICY); + SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_DEFAULT)); + SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_ALWAYS)); + SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_OPP)); + SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_MANUAL)); + SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_NEVER)); + EnableWindow(GetDlgItem(hwndDlg, IDC_CMB_CONT_POLICY), FALSE); + + SendDlgItemMessage(hwndDlg, IDC_LV_CONT_CONTACTS ,LVM_SETEXTENDEDLISTVIEWSTYLE, 0,LVS_EX_FULLROWSELECT);// | LVS_EX_CHECKBOXES); + + + HWND lv = GetDlgItem(hwndDlg, IDC_LV_CONT_CONTACTS); + + + // add list columns + LVCOLUMN lvc; + // Initialize the LVCOLUMN structure. + // The mask specifies that the format, width, text, and + // subitem members of the structure are valid. + lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; + lvc.fmt = LVCFMT_LEFT; + + lvc.iSubItem = 0; + lvc.pszText = TranslateT(LANG_CONTACT); + lvc.cx = 150; // width of column in pixels + ListView_InsertColumn(lv, 0, &lvc); + + lvc.iSubItem = 1; + lvc.pszText = TranslateT(LANG_PROTO); + lvc.cx = 100; // width of column in pixels + ListView_InsertColumn(lv, 1, &lvc); + + lvc.iSubItem = 2; + lvc.pszText = TranslateT(LANG_POLICY); + lvc.cx = 90; // width of column in pixels + ListView_InsertColumn(lv, 2, &lvc); + + lvc.iSubItem = 3; + lvc.pszText = TranslateT(LANG_HTMLCONV); + lvc.cx = 80; // width of column in pixels + ListView_InsertColumn(lv, 3, &lvc); + } + SendMessage(hwndDlg, WMU_REFRESHLIST, 0, 0); + + return TRUE; + case WMU_REFRESHLIST: + { + HWND lv = GetDlgItem(hwndDlg, IDC_LV_CONT_CONTACTS); + + ListView_DeleteAllItems(lv); + + LVITEM lvI = {0}; + + // Some code to create the list-view control. + // Initialize LVITEM members that are common to all + // items. + lvI.mask = LVIF_TEXT | LVIF_PARAM;// | LVIF_NORECOMPUTE;// | LVIF_IMAGE; + + const char *proto; + TCHAR *proto_t; + HANDLE hContact = db_find_first(); + while ( hContact != NULL ) + { + proto = contact_get_proto(hContact); + if(proto && db_get_b(hContact, proto, "ChatRoom", 0) == 0 && CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)MODULENAME) // ignore chatrooms + && (g_metaproto == 0 || strcmp(proto, g_metaproto) != 0)) // and MetaContacts + { + lvI.iItem = 0; + lvI.iSubItem = 0; + lvI.lParam = (LPARAM)hContact; + lvI.pszText = (TCHAR*)contact_get_nameT(hContact); + lvI.iItem = ListView_InsertItem(lv , &lvI); + + proto_t = mir_a2t(proto); + ListView_SetItemText(lv, lvI.iItem, 1, proto_t); + mir_free(proto_t); + + ListView_SetItemText(lv, lvI.iItem, 2, (TCHAR*)policy_to_string((OtrlPolicy)db_get_dw(hContact, MODULENAME, "Policy", CONTACT_DEFAULT_POLICY)) ); + ListView_SetItemText(lv, lvI.iItem, 3, (db_get_b(hContact, MODULENAME, "HTMLConv", 0))?TranslateT(LANG_YES):TranslateT(LANG_NO) ); + } + + + hContact = db_find_next(hContact); + } + } + return TRUE; + break; + case WM_COMMAND: + switch ( HIWORD( wParam )) { + case CBN_SELCHANGE: + switch ( LOWORD( wParam )) { + case IDC_CMB_CONT_POLICY: + { + HANDLE hContact = 0; + int iUser = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_CONT_CONTACTS)); + if (iUser == -1) break; + int sel = SendDlgItemMessage(hwndDlg, IDC_CMB_CONT_POLICY, CB_GETCURSEL, 0, 0); + if (sel==CB_ERR) break; + int len = SendDlgItemMessage(hwndDlg, IDC_CMB_CONT_POLICY, CB_GETLBTEXTLEN, sel, 0); + if (len < 0) break; + TCHAR *text = new TCHAR[len+1]; + SendDlgItemMessage(hwndDlg, IDC_CMB_CONT_POLICY, CB_GETLBTEXT, sel, (LPARAM)text); + ListView_SetItemText(GetDlgItem(hwndDlg, IDC_LV_CONT_CONTACTS), iUser, 2, text); + OtrlPolicy policy = policy_from_string(text); + delete text; + LVITEM lvi = {0}; + lvi.mask = LVIF_PARAM; + lvi.iItem = iUser; + lvi.iSubItem = 0; + ListView_GetItem(GetDlgItem(hwndDlg, IDC_LV_CONT_CONTACTS), &lvi); + ContactPolicyMap* cpm = (ContactPolicyMap*) GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + hContact = (HANDLE)lvi.lParam; + (*cpm)[hContact].policy = policy; + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + }break; + } + break; + } + break; + + case WM_NOTIFY: + { + UINT code = ((LPNMHDR) lParam)->code; + if (code == (UINT) PSN_APPLY ) { + // handle apply + + ContactPolicyMap *cpm = (ContactPolicyMap*) GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + // Iterate over the map and print out all key/value pairs. + // Using a const_iterator since we are not going to change the values. + for(ContactPolicyMap::const_iterator it = cpm->begin(); it != cpm->end(); ++it) + { + if (!it->first) continue; + if (it->second.policy) DBWriteContactSettingDword(it->first, MODULENAME, "Policy", (DWORD)it->second.policy); + if (it->second.htmlconv) db_set_b(it->first, MODULENAME, "HTMLConv", it->second.htmlconv-1); + } + return TRUE; + } else if (((LPNMHDR) lParam)->hwndFrom == GetDlgItem(hwndDlg, IDC_LV_CONT_CONTACTS)) { + if (code == (UINT) LVN_ITEMCHANGED && (((LPNMLISTVIEW)lParam)->uNewState & LVIS_SELECTED )) { + int sel = ListView_GetSelectionMark(((LPNMHDR) lParam)->hwndFrom); + if (sel == -1) { + SendMessage(GetDlgItem(hwndDlg, IDC_CMB_CONT_POLICY), CB_SETCURSEL, (LPARAM)-1, 0); + EnableWindow(GetDlgItem(hwndDlg, IDC_CMB_CONT_POLICY), FALSE); + } else { + EnableWindow(GetDlgItem(hwndDlg, IDC_CMB_CONT_POLICY), TRUE); + TCHAR buff[50]; + ListView_GetItemText(((LPNMHDR)lParam)->hwndFrom, sel, 2, buff, 50); + SendMessage(GetDlgItem(hwndDlg, IDC_CMB_CONT_POLICY), CB_SELECTSTRING, (LPARAM)-1, (WPARAM)buff); + } + } else if (code == (UINT) NM_CLICK) { + if (((LPNMLISTVIEW)lParam)->iSubItem == 3) { + LVITEM lvi; + lvi.mask = LVIF_PARAM; + lvi.iItem = ((LPNMLISTVIEW)lParam)->iItem; + if (lvi.iItem < 0) return FALSE; + lvi.iSubItem = 0; + SendDlgItemMessage(hwndDlg, IDC_LV_CONT_CONTACTS, LVM_GETITEM, 0, (LPARAM)&lvi); + + HANDLE hContact = (HANDLE)lvi.lParam; + ContactPolicyMap *cp = (ContactPolicyMap *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + TCHAR buff[50]; + ListView_GetItemText(((LPNMHDR)lParam)->hwndFrom, lvi.iItem, 3, buff, 50); + if (_tcsncmp(buff, TranslateT(LANG_YES), 50)==0){ + (*cp)[hContact].htmlconv = HTMLCONV_DISABLE; + ListView_SetItemText(((LPNMHDR)lParam)->hwndFrom, lvi.iItem, 3, TranslateT(LANG_NO)); + }else { + (*cp)[hContact].htmlconv = HTMLCONV_ENABLE; + ListView_SetItemText(((LPNMHDR)lParam)->hwndFrom, lvi.iItem, 3, TranslateT(LANG_YES)); + } + (*cp)[hContact].htmlconv += 1; + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + } + + + } + } + }break; + case WM_DESTROY: + ContactPolicyMap *cpm = (ContactPolicyMap*) GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + cpm->clear(); + delete cpm; + break; + } + return FALSE; +} + +static INT_PTR CALLBACK DlgProcMirOTROptsFinger(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch ( msg ) { + case WM_INITDIALOG: + TranslateDialogDefault( hwndDlg ); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (ULONG_PTR) new FPModifyMap()); + + SendDlgItemMessage(hwndDlg, IDC_LV_FINGER_LIST ,LVM_SETEXTENDEDLISTVIEWSTYLE, 0,LVS_EX_FULLROWSELECT);// | LVS_EX_CHECKBOXES); + + { + HWND lv = GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST); + // add list columns + LVCOLUMN lvc; + // Initialize the LVCOLUMN structure. + // The mask specifies that the format, width, text, and + // subitem members of the structure are valid. + lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; + lvc.fmt = LVCFMT_LEFT; + + lvc.iSubItem = 0; + lvc.pszText = TranslateT(LANG_CONTACT); + lvc.cx = 100; // width of column in pixels + ListView_InsertColumn(lv, 0, &lvc); + + lvc.iSubItem = 1; + lvc.pszText = TranslateT(LANG_PROTO); + lvc.cx = 90; // width of column in pixels + ListView_InsertColumn(lv, 1, &lvc); + + lvc.iSubItem = 2; + lvc.pszText = TranslateT(LANG_ACTIVE); + lvc.cx = 50; // width of column in pixels + ListView_InsertColumn(lv, 2, &lvc); + + lvc.iSubItem = 3; + lvc.pszText = TranslateT(LANG_VERIFIED); + lvc.cx = 50; // width of column in pixels + ListView_InsertColumn(lv, 3, &lvc); + + lvc.iSubItem = 4; + lvc.pszText = TranslateT(LANG_FINGERPRINT); + lvc.cx = 300; // width of column in pixels + ListView_InsertColumn(lv, 4, &lvc); + } + SendMessage(hwndDlg, WMU_REFRESHLIST, 0, 0); + + return TRUE; + + case WMU_REFRESHLIST: + //enumerate contacts, fill in list + { + HWND lv = GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST); + ListView_DeleteAllItems(lv); + + LVITEM lvI = {0}; + + // Some code to create the list-view control. + // Initialize LVITEM members that are common to all + // items. + lvI.mask = LVIF_TEXT | LVIF_PARAM;// | LVIF_NORECOMPUTE;// | LVIF_IMAGE; + ConnContext * context = otr_user_state->context_root; + TCHAR *proto, *user, hash[45] = {0}; + Fingerprint *fp; + while (context) { + if (context->app_data) { + user = (TCHAR*)contact_get_nameT((HANDLE)context->app_data); + if (user) { + proto = mir_a2t(context->protocol); + fp = context->fingerprint_root.next; + while(fp) { + otrl_privkey_hash_to_humanT(hash, fp->fingerprint); + if (hash) { + lvI.iSubItem = 0; + lvI.lParam = (LPARAM)fp; + lvI.pszText = user; + int d = ListView_InsertItem(lv, &lvI); + + ListView_SetItemText(lv,d, 1, proto); + ListView_SetItemText(lv,d, 2, (context->active_fingerprint == fp)? TranslateT(LANG_YES) : TranslateT(LANG_NO)); + ListView_SetItemText(lv,d, 3, (fp->trust && fp->trust != '\0')? TranslateT(LANG_YES) : TranslateT(LANG_NO)); + ListView_SetItemText(lv,d, 4, hash ); + } + fp = fp->next; + } + mir_free(proto); + } + } + context = context->next; + } + } + + return TRUE; + case WM_COMMAND: + switch ( HIWORD( wParam )) { + case BN_CLICKED: + switch ( LOWORD( wParam )) { + case IDC_BTN_FINGER_DONTTRUST: + { + int sel = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST)); + if (sel != -1) { + LVITEM lvi = {0}; + lvi.mask = LVIF_PARAM; + lvi.iItem = sel; + Fingerprint *fp = NULL; + ListView_GetItem(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST), &lvi); + fp = (Fingerprint*) lvi.lParam; + FPModifyMap* fpm = (FPModifyMap*) GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + (*fpm)[fp] = FPM_NOTRUST; + ListView_SetItemText(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST), sel, 3, TranslateT(LANG_NO)); + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + } + }break; + case IDC_BTN_FINGER_TRUST: + { + int sel = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST)); + if (sel != -1) { + LVITEM lvi = {0}; + lvi.mask = LVIF_PARAM; + lvi.iItem = sel; + Fingerprint *fp = NULL; + ListView_GetItem(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST), &lvi); + fp = (Fingerprint*) lvi.lParam; + FPModifyMap* fpm = (FPModifyMap*) GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + (*fpm)[fp] = FPM_VERIFY; + ListView_SetItemText(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST), sel, 3, TranslateT(LANG_YES)); + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + } + }break; + case IDC_BTN_FINGER_FORGET: + { + int sel = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST)); + if (sel != -1) { + LVITEM lvi = {0}; + lvi.mask = LVIF_PARAM; + lvi.iItem = sel; + Fingerprint *fp = NULL; + ListView_GetItem(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST), &lvi); + fp = (Fingerprint*) lvi.lParam; + if (fp->context->active_fingerprint == fp) { + TCHAR buff[1024], hash[45]; + otrl_privkey_hash_to_humanT(hash, fp->fingerprint); + mir_sntprintf(buff, 1024, TranslateT(LANG_FINGERPRINT_STILL_IN_USE), hash, contact_get_nameT((HANDLE)fp->context->app_data)); + ShowError(buff); + } else { + FPModifyMap* fpm = (FPModifyMap*) GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + (*fpm)[fp] = FPM_DELETE; + ListView_DeleteItem(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST), sel); + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + } + } + }break; + } + } + break; + + case WM_NOTIFY: + if (((LPNMHDR)lParam)->code == (UINT) PSN_APPLY ) { + // handle apply + + FPModifyMap *fpm = (FPModifyMap*) GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + // Iterate over the map and print out all key/value pairs. + // Using a const_iterator since we are not going to change the values. + for(FPModifyMap::const_iterator it = fpm->begin(); it != fpm->end(); ++it) + { + if (!it->first) continue; + switch (it->second) { + case FPM_DELETE: + if (it->first->context->active_fingerprint == it->first) { + TCHAR buff[1024], hash[45]; + otrl_privkey_hash_to_humanT(hash, it->first->fingerprint); + mir_sntprintf(buff, 1024, TranslateT(LANG_FINGERPRINT_NOT_DELETED), hash, contact_get_nameT((HANDLE)it->first->context->app_data)); + ShowError(buff); + } else { + otrl_context_forget_fingerprint(it->first, 1); + } + break; + case FPM_VERIFY: + otrl_context_set_trust(it->first, "verified"); + if (it->first == it->first->context->active_fingerprint) + VerifyFingerprint(it->first->context, true); + //SetEncryptionStatus((HANDLE)it->first->context->app_data, otr_context_get_trust(it->first->context)); + break; + case FPM_NOTRUST: + otrl_context_set_trust(it->first, NULL); + if (it->first == it->first->context->active_fingerprint) + VerifyFingerprint(it->first->context, false); + //SetEncryptionStatus((HANDLE)it->first->context->app_data, otr_context_get_trust(it->first->context)); + break; + } + } + if (!fpm->empty()) otr_gui_write_fingerprints(0); + fpm->clear(); + SendMessage(hwndDlg, WMU_REFRESHLIST, 0, 0); + + return TRUE; + } + break; + case WM_DESTROY: + FPModifyMap *fpm = (FPModifyMap*) GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + fpm->clear(); + delete fpm; + break; + } + + return FALSE; +} \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/src/options.h b/plugins/MirOTR/MirOTR/src/options.h new file mode 100644 index 0000000000..b66125d473 --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/options.h @@ -0,0 +1,75 @@ +#ifndef _OPTIONS_INC +#define _OPTIONS_INC + +//#include "stdafx.h" + +extern char* g_metaproto; + +#define PRIVATE_KEY_FILENAME "otr.private_key" +#define FINGERPRINT_STORE_FILENAME "otr.fingerprints" + +extern char g_fingerprint_store_filename[MAX_PATH]; +extern char g_private_key_filename[MAX_PATH]; + +#define CONTACT_DEFAULT_POLICY 0xFFFF + +typedef enum {ED_POP, ED_BAL, ED_MB} ErrorDisplay; + +#define OPTIONS_PREFIXLEN 64 + +typedef struct { + OtrlPolicy default_policy; + ErrorDisplay err_method; + bool prefix_messages; + bool msg_inline; + bool msg_popup; + char prefix[OPTIONS_PREFIXLEN]; + + bool timeout_finished; + + bool delete_history; + bool delete_systeminfo; + bool autoshow_verify; + + bool end_offline, end_window_close; + + // temporary options + bool bHaveMetaContacts, bHavePopups, bHaveSRMMIcons, bHaveSecureIM, bHaveButtonsBar; + +} Options; + +extern Options options; + +#define WMU_REFRESHLIST (WM_USER + 241) +#define WMU_REFRESHPROTOLIST (WM_USER + 242) +#define CONTACT_DEFAULT_POLICY 0xFFFF + +#include +enum HTMLConvSetting { + HTMLCONV_DISABLE, + HTMLCONV_ENABLE +}; +struct CONTACT_DATA { + OtrlPolicy policy; + int htmlconv; +}; +typedef std::map ContactPolicyMap; +typedef enum {FPM_VERIFY, FPM_NOTRUST, FPM_DELETE } FPModify; +typedef std::map FPModifyMap; + +int OptInit(WPARAM wParam, LPARAM lParam); + +void LoadOptions(); +void SaveOptions(); +extern "C" int OpenOptions(WPARAM wParam, LPARAM lParam); +void InitOptions(); +void DeinitOptions(); + +void ReadPrivkeyFiles(); + +static INT_PTR CALLBACK DlgProcMirOTROpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); +static INT_PTR CALLBACK DlgProcMirOTROptsProto(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); +static INT_PTR CALLBACK DlgProcMirOTROptsContacts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); +static INT_PTR CALLBACK DlgProcMirOTROptsFinger(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); + +#endif diff --git a/plugins/MirOTR/MirOTR/src/otr.cpp b/plugins/MirOTR/MirOTR/src/otr.cpp new file mode 100644 index 0000000000..ee6e3e0e12 --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/otr.cpp @@ -0,0 +1,401 @@ +#include +#include "otr.h" +#include + +OtrlUserState otr_user_state; +#define WMU_ENDDIALOG (WM_USER+244) + +OtrlMessageAppOps ops = { + otr_gui_policy, + otr_gui_create_privkey, + otr_gui_is_logged_in, + otr_gui_inject_message, + otr_gui_notify, + otr_gui_display_otr_message, + otr_gui_update_context_list, + otr_gui_protocol_name, + otr_gui_protocol_name_free, + otr_gui_new_fingerprint, + otr_gui_write_fingerprints, + otr_gui_gone_secure, + otr_gui_gone_insecure, + otr_gui_still_secure, + otr_gui_log_message, + max_message_size, + account_name, + account_name_free +}; + +struct GenKeyData{ + HWND dialog; + const char *proto; +}; + +static unsigned int CALLBACK generate_key_thread(void* param) +{ + Thread_Push(0); + GenKeyData *data = (GenKeyData *)param; + //lib_cs_lock(); + otrl_privkey_generate(otr_user_state, g_private_key_filename, data->proto, data->proto); + //lib_cs_unlock(); + PostMessage(data->dialog, WMU_ENDDIALOG, 0, 0); + mir_free(data); + Thread_Pop(); + return 0; +} + +INT_PTR CALLBACK GenKeyDlgFunc(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { + switch(msg) { + case WM_INITDIALOG: + { + if (!lParam) { + EndDialog(hWndDlg, 0); + return 0; + } + TranslateDialogDefault(hWndDlg); + SetClassLongPtr(hWndDlg, GCLP_HICON, (LONG_PTR)LoadIcon(ICON_OTR,1) ); + TCHAR buff[256]; + TCHAR *proto = mir_a2t((char*)lParam); + mir_sntprintf(buff, 256, TranslateT(LANG_GENERATE_KEY), proto); + mir_free(proto); + SetDlgItemText(hWndDlg, IDC_GENERATE, buff); + GenKeyData *data = (GenKeyData *)mir_calloc(sizeof(GenKeyData)); + data->dialog = hWndDlg; + data->proto = (char*)lParam; + CloseHandle((HANDLE)_beginthreadex(0, 0, generate_key_thread, (void*)data, 0, 0)); + }break; + case WMU_ENDDIALOG: + EndDialog(hWndDlg, 0); + return TRUE; + case WM_DESTROY: + SetClassLongPtr(hWndDlg, GCLP_HICON, 0); + ReleaseIcon(ICON_OTR,1); + } + return FALSE; +} + +extern "C" { + /* Return the OTR policy for the given context. */ + OtrlPolicy otr_gui_policy(void *opdata, ConnContext *context) { + DEBUGOUT_T("OTR_GUI_POLICY") + HANDLE hContact = (HANDLE)opdata; + DWORD pol; + if(hContact) { + pol = DBGetContactSettingDword(hContact, MODULENAME, "Policy", CONTACT_DEFAULT_POLICY); + if (options.bHaveSecureIM && pol != OTRL_POLICY_MANUAL_MOD && pol != OTRL_POLICY_NEVER && db_get_b(hContact, "SecureIM" , "StatusID", 0)) { + // if SecureIM is not disabled for this contact, MirOTR will be set to manual + db_set_dw(hContact, MODULENAME, "Policy", OTRL_POLICY_MANUAL_MOD); + return OTRL_POLICY_MANUAL_MOD; + } + if(pol != CONTACT_DEFAULT_POLICY) return pol ; + } + if(context->protocol) { + pol = db_get_dw(0,MODULENAME"_ProtoPol", context->protocol, CONTACT_DEFAULT_POLICY); + if(pol != CONTACT_DEFAULT_POLICY) return pol ; + } + + return options.default_policy ; + } + + /* Create a private key for the given accountname/protocol if + * desired. */ + void otr_gui_create_privkey(void *opdata, const char *account_name, const char *protocol) { + DEBUGOUT_T("OTR_GUI_CREATE_PRIVKEY") + //if(MessageBox(0, Translate("Would you like to generate a new private key for this protocol?"), Translate("OTR"), MB_YESNO) == IDYES) + //if(options.err_method == ED_POP) + //ShowPopup(Translate("Generating new private key."), 0 /*Translate("Please wait.")*/, 5); + + //NewKeyData *nkd = (NewKeyData *)malloc(sizeof(NewKeyData)); + //nkd->account_name = strdup(account_name); + //nkd->protocol = strdup(protocol); + + //DWORD tid; + //CloseHandle(CreateThread(0, 0, newKeyThread, (VOID *)nkd, 0, &tid)); + //QueueUserAPC(newKeyAPC, Global::mainThread, (DWORD)nkd); + if (opdata) protocol = contact_get_proto((HANDLE)opdata); + if (!protocol) return; + DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_GENKEYNOTIFY), 0, GenKeyDlgFunc, (LPARAM)protocol ); + + } + + /* Report whether you think the given user is online. Return 1 if + * you think he is, 0 if you think he isn't, -1 if you're not sure. + * + * If you return 1, messages such as heartbeats or other + * notifications may be sent to the user, which could result in "not + * logged in" errors if you're wrong. */ + int otr_gui_is_logged_in(void *opdata, const char *accountname, const char *protocol, const char *recipient) { + DEBUGOUT_T("OTR_GUI_IS_LOGGED_IN") + HANDLE hContact = (HANDLE)opdata; + if(hContact) { + WORD status = DBGetContactSettingWord(hContact, contact_get_proto(hContact), "Status", ID_STATUS_OFFLINE); + if(status == ID_STATUS_OFFLINE) return 0; + else return 1; + } + + return -1; + } + + /* Send the given IM to the given recipient from the given + * accountname/protocol. */ + void otr_gui_inject_message(void *opdata, const char *accountname, const char *protocol, const char *recipient, const char *message) { + DEBUGOUT_T("OTR_GUI_INJECT_MESSAGE") + //MessageBox(0, message, "OTR Inject", MB_OK); + HANDLE hContact = (HANDLE)opdata; + + if(protocol && DBGetContactSettingWord(hContact, protocol, "Status", ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) { + /* this would be with translation + TCHAR *decode = mir_utf8decodeT(message); + TCHAR *encode = mir_utf8encodeT(TranslateT(decide)); + mir_free(decode); + CallContactService(hContact, PSS_MESSAGE, PREF_UTF|PREF_BYPASS_OTR, (LPARAM)encode); + mir_free(encode); + */ + CallContactService(hContact, PSS_MESSAGE, PREF_UTF|PREF_BYPASS_OTR, (LPARAM)message); + //DEBUGOUT_T("INJECT") + } + } + + /* Display a notification message for a particular accountname / + * protocol / username conversation. */ + void otr_gui_notify(void *opdata, OtrlNotifyLevel level, const char *accountname, const char *protocol, const char *username, const char *title, const char *primary, const char *secondary) { + DEBUGOUT_T("OTR_GUI_NOTIFY") + const TCHAR* uname = contact_get_nameT((HANDLE)opdata); + TCHAR* title_t = mir_utf8decodeT(title); + TCHAR *notify = TranslateT(LANG_OTR_NOTIFY); + + size_t len = _tcslen(uname) + _tcslen(title_t) + _tcslen(notify); + TCHAR *buff1 = new TCHAR[len]; + mir_sntprintf(buff1, len, notify, TranslateTS(title_t), uname); + mir_free(title_t); + + len = strlen(primary) + strlen(secondary) + 5; + char *buff2 = new char[len]; + mir_snprintf(buff2, len, "%s\n%s", Translate(primary), Translate(secondary)); + TCHAR* buff2_t = mir_utf8decodeT(buff2); + delete buff2; + + DEBUGOUT_T("OTR_GUI_NOTIFY") + + ShowPopup(buff1, buff2_t, 0); + mir_free(buff2_t); + delete buff1; + } + + /* Display an OTR control message for a particular accountname / + * protocol / username conversation. Return 0 if you are able to + * successfully display it. If you return non-0 (or if this + * function is NULL), the control message will be displayed inline, + * as a received message, or else by using the above notify() + * callback. */ + int otr_gui_display_otr_message(void *opdata, const char *accountname, const char *protocol, const char *username, const char *msg) { + DEBUGOUT_T("OTR_GUI_DISPLAY_OTR_MESSAGE") + if(options.msg_inline) + ShowMessageInlineUtf((HANDLE)opdata, Translate(msg)); + if(options.msg_popup) { + TCHAR buff[512]; + TCHAR* proto = mir_a2t(protocol); + mir_sntprintf(buff, 512, TranslateT(LANG_OTR_USERMESSAGE), contact_get_nameT((HANDLE)opdata), proto); + mir_free(proto); + TCHAR *msg_t = mir_utf8decodeT(msg); + ShowPopup(buff, TranslateTS(msg_t), 0); + mir_free(msg_t); + } + return 0; + } + + /* When the list of ConnContexts changes (including a change in + * state), this is called so the UI can be updated. */ + void otr_gui_update_context_list(void *opdata) { + //MessageBox(0, "Update Context List", "OTR Callback", MB_OK); + DEBUGOUT_T("OTR: Update Context List"); + } + + /* Return a newly-allocated string containing a human-friendly name + * for the given protocol id */ + const char *otr_gui_protocol_name(void *opdata, const char *protocol) { + //return strdup(protocol); + DEBUGOUT_T("OTR_GUI_PROTOCOL_NAME") + return protocol; + } + + /* Deallocate a string allocated by protocol_name */ + void otr_gui_protocol_name_free(void *opdata, const char *protocol_name) { + //free((void *)protocol_name); + } + + /* A new fingerprint for the given user has been received. */ + void otr_gui_new_fingerprint(void *opdata, OtrlUserState us, const char *accountname, const char *protocol, const char *username, unsigned char fingerprint[20]) { + DEBUGOUT_T("OTR_GUI_NEW_FUNGERPRINT") + ConnContext *context = otrl_context_find(us, username, accountname, protocol, TRUE, 0, add_appdata, opdata); + Fingerprint *fp = otrl_context_find_fingerprint(context, fingerprint, TRUE, 0); + + //CloseHandle((HANDLE)_beginthreadex(0, 0, trust_fp_thread, (void *)fp, 0, 0)); + + otrl_context_set_trust(fp, NULL); + otrl_privkey_write_fingerprints(otr_user_state, g_fingerprint_store_filename); + } + + /* The list of known fingerprints has changed. Write them to disk. */ + void otr_gui_write_fingerprints(void *opdata) { + DEBUGOUT_T("OTR_GUI_WRITE_FINGERPRINTS") + //if(MessageBox(0, Translate("Would you like to save the current fingerprint list?"), Translate(MODULE), MB_YESNO) == IDYES) + otrl_privkey_write_fingerprints(otr_user_state, g_fingerprint_store_filename); + } + + /* A ConnContext has entered a secure state. */ + void otr_gui_gone_secure(void *opdata, ConnContext *context) { + DEBUGOUT_T("OTR_GUI_GONE_SECURE") + TrustLevel trusted = otr_context_get_trust(context); + // opdata is hContact + SetEncryptionStatus((HANDLE)opdata, trusted); + TCHAR buff[1024]; + if(trusted == TRUST_PRIVATE) { + mir_sntprintf(buff, 1024, TranslateT(LANG_SESSION_START_OTR), contact_get_nameT((HANDLE)opdata)); + } else if (trusted == TRUST_UNVERIFIED) { + if (options.autoshow_verify) SMPInitDialog(context); //VerifyContextDialog(context); + mir_sntprintf(buff, 1024, TranslateT(LANG_SESSION_START_OTR_VERIFY), contact_get_nameT((HANDLE)opdata)); + } else { // should never happen + mir_sntprintf(buff, 1024, TranslateT(LANG_SESSION_NOT_STARTED_OTR), contact_get_nameT((HANDLE)opdata)); + } + // opdata is hContact + ShowMessage((HANDLE)opdata, buff); + + } + + /* A ConnContext has left a secure state. */ + void otr_gui_gone_insecure(void *opdata, ConnContext *context) { + DEBUGOUT_T("OTR_GUI_GONE_INSECURE") + TCHAR buff[512]; + mir_sntprintf(buff, 512, TranslateT(LANG_SESSION_TERMINATED_BY_OTR), contact_get_nameT((HANDLE)opdata)); + //MessageBox(0, buff, Translate("OTR Information"), MB_OK); + if (!Miranda_Terminated()) { + ShowMessage((HANDLE)opdata, buff); + } + + // opdata is hContact + SetEncryptionStatus((HANDLE)opdata, otr_context_get_trust(context)); + } + + /* We have completed an authentication, using the D-H keys we + * already knew. is_reply indicates whether we initiated the AKE. */ + void otr_gui_still_secure(void *opdata, ConnContext *context, int is_reply) { + DEBUGOUT_T("OTR_GUI_STILL_SECURE") + TrustLevel trusted = otr_context_get_trust(context); + SetEncryptionStatus((HANDLE)opdata, trusted); + TCHAR buff[1024]; + if (!is_reply) { + if(trusted == TRUST_PRIVATE) { + mir_sntprintf(buff, 1024, TranslateT(LANG_SESSION_CONTINUE_OTR), contact_get_nameT((HANDLE)opdata)); + } else if (trusted == TRUST_UNVERIFIED) { + if (options.autoshow_verify) SMPInitDialog(context); //VerifyContextDialog(context); + mir_sntprintf(buff, 1024, TranslateT(LANG_SESSION_CONTINUE_OTR_VERIFY), contact_get_nameT((HANDLE)opdata)); + } else { // should never happen + mir_sntprintf(buff, 1024, TranslateT(LANG_SESSION_NOT_STARTED_OTR), contact_get_nameT((HANDLE)opdata)); + } + // opdata is hContact + ShowMessage((HANDLE)opdata, buff); + } else { + if(trusted == TRUST_PRIVATE) { + mir_sntprintf(buff, 1024, TranslateT(LANG_SESSION_HAS_CONTINUE_OTR), contact_get_nameT((HANDLE)opdata)); + } else if (trusted == TRUST_UNVERIFIED) { + mir_sntprintf(buff, 1024, TranslateT(LANG_SESSION_HAS_CONTINUE_OTR_VERIFY), contact_get_nameT((HANDLE)opdata)); + } else { // should never happen + mir_sntprintf(buff, 1024, TranslateT(LANG_SESSION_NOT_STARTED_OTR), contact_get_nameT((HANDLE)opdata)); + } + + } + SetEncryptionStatus((HANDLE)opdata, trusted); + } + + /* Log a message. The passed message will end in "\n". */ + void otr_gui_log_message(void *opdata, const char *message) { + //MessageBox(0, message, Translate("OTR Log Message"), MB_OK); + //ShowMessageInline((HANDLE)opdata, message); +#ifdef _DEBUG + char* msg = strcpy((char*)mir_alloc(strlen(message)+15), "OTR message: "); + strcat(msg, message); + DEBUGOUTA(msg) + mir_free(msg); +#endif + } + + int max_message_size(void *opdata, ConnContext *context) { + const char *proto; + if (context && context->protocol) + proto = context->protocol; + else + proto = contact_get_proto(opdata); + // ugly wokaround for ICQ. ICQ protocol reports more than 7k, but in SMP this is too long. + // possibly ICQ doesn't allow single words without spaces to become longer than ~2340? + if (strcmp("ICQ", proto)==0 || strncmp("ICQ_", proto, 4)==0) + return 2340; + return CallProtoService(proto, PS_GETCAPS, PFLAG_MAXLENOFMESSAGE, (LPARAM)opdata); + } + + const char *account_name(void *opdata, const char *account, const char *protocol) { + return account; + } + + void account_name_free(void *opdata, const char *account_name) { + } + + void add_appdata(void *data, ConnContext *context) { + if(context) context->app_data = data; + } +} + +// Forward decl +gcry_error_t otrl_privkey_write_FILEp(OtrlUserState us, FILE *privf); +/* Generate a private DSA key for a given account, storing it into a +* file on disk, and loading it into the given OtrlUserState. Overwrite any +* previously generated keys for that account in that OtrlUserState. */ + gcry_error_t otrl_privkey_write(OtrlUserState us, const char *filename) + { + gcry_error_t err; + FILE *privf; + #ifndef WIN32 + mode_t oldmask; + #endif + + #ifndef WIN32 + oldmask = umask(077); + #endif + privf = fopen(filename, "w+b"); + if (!privf) { + #ifndef WIN32 + umask(oldmask); + #endif + err = gcry_error_from_errno(errno); + return err; + } + + err = otrl_privkey_write_FILEp(us, privf); + + fclose(privf); + #ifndef WIN32 + umask(oldmask); + #endif + return err; + } + +/* Just store the private keys of an OtrlUserState. + * The FILE* must be open for reading and writing. */ + gcry_error_t otrl_privkey_write_FILEp(OtrlUserState us, FILE *privf) + { + OtrlPrivKey *p; + + if (!privf) return gcry_error(GPG_ERR_NO_ERROR); + + + + /* Output the other keys we know */ + fprintf(privf, "(privkeys\n"); + for (p=us->privkey_root; p; p=p->next) { + otrl_account_write(privf, p->accountname, p->protocol, p->privkey); + } + if ( fprintf(privf, ")\n") < 0 ) + return gcry_error_from_errno(errno); + return gcry_error(GPG_ERR_NO_ERROR); + +} \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/src/otr.h b/plugins/MirOTR/MirOTR/src/otr.h new file mode 100644 index 0000000000..110bcd9485 --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/otr.h @@ -0,0 +1,53 @@ +#pragma once + +#include "stdafx.h" + +extern OtrlUserState otr_user_state; +extern OtrlMessageAppOps ops; + +extern "C" { + + /* Return the OTR policy for the given context. */ + OtrlPolicy otr_gui_policy(void *opdata, ConnContext *context); + + /* Create a private key for the given accountname/protocol if + * desired. */ + void otr_gui_create_privkey(void *opdata, const char *account_name, const char *protocol); + + int otr_gui_is_logged_in(void *opdata, const char *accountname, const char *protocol, const char *recipient); + + void otr_gui_inject_message(void *opdata, const char *accountname, const char *protocol, const char *recipient, const char *message); + + void otr_gui_notify(void *opdata, OtrlNotifyLevel level, const char *accountname, const char *protocol, const char *username, const char *title, const char *primary, const char *secondary); + + int otr_gui_display_otr_message(void *opdata, const char *accountname, const char *protocol, const char *username, const char *msg); + + void otr_gui_update_context_list(void *opdata); + + const char *otr_gui_protocol_name(void *opdata, const char *protocol); + + void otr_gui_protocol_name_free(void *opdata, const char *protocol_name); + + void otr_gui_new_fingerprint(void *opdata, OtrlUserState us, const char *accountname, const char *protocol, const char *username, unsigned char fingerprint[20]); + + void otr_gui_write_fingerprints(void *opdata); + + void otr_gui_gone_secure(void *opdata, ConnContext *context); + + void otr_gui_gone_insecure(void *opdata, ConnContext *context); + + void otr_gui_still_secure(void *opdata, ConnContext *context, int is_reply); + + void otr_gui_log_message(void *opdata, const char *message); + + int max_message_size(void *opdata, ConnContext *context); + + const char *account_name(void *opdata, const char *account, const char *protocol); + + void account_name_free(void *opdata, const char *account_name); + + void add_appdata(void *data, ConnContext *context); + +} + +gcry_error_t otrl_privkey_write(OtrlUserState us, const char *filename); \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/src/resource.h b/plugins/MirOTR/MirOTR/src/resource.h new file mode 100644 index 0000000000..b861799546 --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/resource.h @@ -0,0 +1,104 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by resource.rc +// +#ifndef IDOK + #define IDOK 1 +#endif +#ifndef IDCANCEL + #define IDCANCEL 2 +#endif +#define IDD_GENKEYNOTIFY 101 +#define IDD_OPT_GENERAL 102 +#define IDD_OPT_PROTO 103 +#define IDD_OPT_CONTACTS 104 +#define IDD_OPT_FINGER 105 +#define IDD_SMP_INPUT 106 +#define IDD_SMP_PROGRESS 107 + +// General Options +#define IDC_GRP_POLICY 1051 +#define IDC_RAD_ALWAYS 1052 +#define IDC_RAD_OPP 1053 +#define IDC_RAD_MANUAL 1054 +#define IDC_RAD_NEVER 1055 + +#define IDC_CHK_PREFIX 1056 +#define IDC_ED_PREFIX 1057 +#define IDC_CHK_MSGINLINE 1058 +#define IDC_CHK_MSGPOPUP 1059 +#define IDC_CHK_PREVENTSAVE 1060 +#define IDC_CHK_AUTOSHOW_VERIFY 1061 +#define IDC_CHK_TIMEFINISH 1062 +#define IDC_CHK_ENDOFFLINE 1063 +#define IDC_CHK_ENDCLOSE 1064 +#define IDC_CHK_PREVENTSYSSAVE 1065 + +// Proto policy & keys +#define IDC_LV_PROTO_PROTOS 1101 +#define IDC_BTN_PROTO_NEWKEY 1102 +#define IDC_CMB_PROTO_POLICY 1103 +#define IDC_BTN_PROTO_FORGET 1104 +#define IDC_STC_PROTO1 1151 +#define IDC_STC_PROTO2 1152 + +// User policy +#define IDC_LV_CONT_CONTACTS 1201 +#define IDC_CMB_CONT_POLICY 1202 +#define IDC_STC_CONT1 1251 +#define IDC_STC_CONT2 1252 + +// User fingerprints +#define IDC_LV_FINGER_LIST 1301 +#define IDC_BTN_FINGER_FORGET 1302 +#define IDC_BTN_FINGER_TRUST 1303 +#define IDC_BTN_FINGER_DONTTRUST 1304 +#define IDC_STC_FINGER1 1351 + +// Generate dialog +#define IDC_GENERATE 1401 +#define IDC_ICOOTR 1402 +#define IDC_ICOREFRESH 1403 + +// SMP Progress +#define IDC_PGB_SMP 1501 +#define IDC_STC_SMP_HEADPRO 1502 +#define IDC_ICO_SMP 1503 +#define IDC_STC_SMP_PROGRESS 1504 + +// SMP Dialog +#define IDC_STC_SMP_HEAD 1602 +#define IDC_CBO_SMP_CHOOSE 1603 +#define IDC_STC_SMP_INFO 1604 +#define IDC_STC_SMP_FIELD1 1605 +#define IDC_EDT_SMP_FIELD1 1606 +#define IDC_STC_SMP_FIELD2 1607 +#define IDC_EDT_SMP_FIELD2 1608 + +#define IDI_OTR 2000 +#define IDI_REFRESH 2001 +#define IDI_INSECURE 2002 +#define IDI_UNVERIFIED 2003 +#define IDI_PRIVATE 2004 +#define IDI_FINISHED 2005 + +#define IDC_STATIC -1 + +#define IDM_OTR_MENU 10001 +#define IDR_CONTEXT 10000 +#define IDM_OTR_STATUS 10001 +#define IDM_OTR_START 10002 +#define IDM_OTR_REFRESH 10003 +#define IDM_OTR_STOP 10004 +#define IDM_OTR_VERIFY 10005 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/plugins/MirOTR/MirOTR/src/stdafx.cpp b/plugins/MirOTR/MirOTR/src/stdafx.cpp new file mode 100644 index 0000000000..98540cbccf --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : Quelldatei, die nur die Standard-Includes einbindet. +// MirOTR.pch ist der vorkompilierte Header. +// stdafx.obj enthält die vorkompilierten Typinformationen. + +#include "stdafx.h" + +// TODO: Auf zusätzliche Header verweisen, die in STDAFX.H +// und nicht in dieser Datei erforderlich sind. diff --git a/plugins/MirOTR/MirOTR/src/stdafx.h b/plugins/MirOTR/MirOTR/src/stdafx.h new file mode 100644 index 0000000000..ec471e83bd --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/stdafx.h @@ -0,0 +1,87 @@ +// stdafx.h : Includedatei für Standardsystem-Includedateien +// oder häufig verwendete projektspezifische Includedateien, +// die nur in unregelmäßigen Abständen geändert werden. +// + +#pragma once + +#include "targetver.h" + +#define _CRT_NON_CONFORMING_SWPRINTFS +#define WIN32_LEAN_AND_MEAN // Selten verwendete Teile der Windows-Header nicht einbinden. + +// Windows-Headerdateien: +#include +#include +#include + +#ifdef _DEBUG + #define DEBUGOUTA(x) OutputDebugStringA(x); + #define DEBUGOUT(x) OutputDebugString(x); + #define DEBUGOUT_T(x) OutputDebugString(__T(x)); +#else + #define DEBUGOUTA(x); + #define DEBUGOUT(x) + #define DEBUGOUT_T(x) +#endif +#define MIRANDA_VER 0x0900 +#define MIRANDA_CUSTOM_LP + +//include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//ExternalAPI +#include +#include +#include + +#include +extern "C" { + #include + #include + #include + #include + #include +} + +#include "dllmain.h" +#include "language.h" +#include "options.h" +#include "utils.h" +#include "svcs_menu.h" +#include "svcs_proto.h" +#include "svcs_srmm.h" +#include "resource.h" +#include "otr.h" +#include "icons.h" +#include "dialogs.h" + +// modified manual policy - so that users set to 'opportunistic' will automatically start OTR with users set to 'manual' +#define OTRL_POLICY_MANUAL_MOD (OTRL_POLICY_MANUAL | OTRL_POLICY_WHITESPACE_START_AKE | OTRL_POLICY_ERROR_START_AKE) + +// {12D8FAAD-78AB-4e3c-9854-320E9EA5CC9F} +static const MUUID MIID_OTRPLUGIN = { 0x12d8faad, 0x78ab, 0x4e3c, { 0x98, 0x54, 0x32, 0xe, 0x9e, 0xa5, 0xcc, 0x9f } }; + +#define MODULENAME "MirOTR" + +#define PREF_BYPASS_OTR 0x8000 +#define PREF_NO_HISTORY 0x10000 + +#define SIZEOF(X) (sizeof(X)/sizeof(X[0])) + +// TODO: Hier auf zusätzliche Header, die das Programm erfordert, verweisen. diff --git a/plugins/MirOTR/MirOTR/src/striphtml.cpp b/plugins/MirOTR/MirOTR/src/striphtml.cpp new file mode 100644 index 0000000000..c76b0f7d80 --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/striphtml.cpp @@ -0,0 +1,127 @@ +#include "stdafx.h" +#include "striphtml.h" +#include "ekhtml.h" +#include "entities.h" + +void starttag_cb (void *cbdata, ekhtml_string_t *tag, ekhtml_attr_t *attrs) { + STRIPHTML_DATA *data = (STRIPHTML_DATA *)cbdata; + switch (tag->len) { + case 1: + switch (*(tag->str)) { + case 'a': + case 'A': + { + ekhtml_attr_t *attr = attrs; + while (attr) { + if (_strnicmp(attr->name.str, "href", attr->name.len)==0) { + data->stack.push(strncpy((char*)mir_calloc(attr->val.len+1), attr->val.str, attr->val.len)); + break; + } + } + }break; + case 'i': + case 'I': + data->buffer.append(" *"); + break; + case 'b': + case 'B': + data->buffer.append(" _"); + break; + } + case 2: + if (toupper(tag->str[0]) == 'B' && toupper(tag->str[1]) == 'R') + data->buffer.append("\r\n"); + break; + case 3: + if (_strnicmp(tag->str, "img", 3) == 0) { + ekhtml_attr_t *attr = attrs; + data->buffer.append("IMAGE [ "); + while (attr) { + if (_strnicmp(attr->name.str, "src", attr->name.len)==0) { + data->buffer.append(attr->val.str, attr->val.len); + break; + } + } + data->buffer.append(" ] "); + } + break; + } +} + +void endtag_cb (void *cbdata, ekhtml_string_t *tag) { + STRIPHTML_DATA *data = (STRIPHTML_DATA *)cbdata; + switch (tag->len) { + case 1: + switch (*(tag->str)) { + case 'a': + case 'A': + if (data->stack.empty()) break; + data->buffer.append(" [ "); + data->buffer.append(data->stack.top()); + mir_free(data->stack.top()); + data->stack.pop(); + data->buffer.append(" ] "); + break; + case 'i': + case 'I': + data->buffer.append("* "); + break; + case 'b': + case 'B': + data->buffer.append("_ "); + break; + } + } + +} + +void data_cb (void *cbdata, ekhtml_string_t *text) { + STRIPHTML_DATA *data = (STRIPHTML_DATA *)cbdata; + if(text->len <= 0) + return; + char* s = (char*) mir_calloc(text->len+1); + decode_html_entities_utf8(s, text->str, text->len); + + if (!data->stack.empty()) { + char *top = data->stack.top(); + if (_stricmp(s, top)==0) { + mir_free(top); + data->stack.pop(); + } + } + + + data->buffer.append(s); + mir_free(s); +} + +char * striphtml(char *html) { + STRIPHTML_DATA data; + ekhtml_string_t ekstring; + + ekstring.len = strlen(html); + ekstring.str = html; + + data.buffer.clear(); + data.buffer.reserve(ekstring.len); + + ekhtml_parser_t *parser = ekhtml_parser_new(&data); + ekhtml_parser_datacb_set(parser, &data_cb); + ekhtml_parser_startcb_add(parser, NULL, &starttag_cb); + ekhtml_parser_endcb_add(parser, NULL, &endtag_cb); + + ekhtml_parser_feed(parser, &ekstring); + ekhtml_parser_flush(parser, 1); + + while (!data.stack.empty()) { + mir_free(data.stack.top()); + data.stack.pop(); + } + + ekhtml_parser_destroy(parser); + + char *s = mir_strdup(data.buffer.c_str()); + data.buffer.erase(); + return s; + //ekhtml_parser_create( +} diff --git a/plugins/MirOTR/MirOTR/src/striphtml.h b/plugins/MirOTR/MirOTR/src/striphtml.h new file mode 100644 index 0000000000..7cffc41f22 --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/striphtml.h @@ -0,0 +1,11 @@ +#pragma once + +#include "stack" +#include "string" + +struct STRIPHTML_DATA { + std::stack stack; + std::string buffer; +}; + +char * striphtml(char *html); \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/src/svcs_menu.cpp b/plugins/MirOTR/MirOTR/src/svcs_menu.cpp new file mode 100644 index 0000000000..17c2d9a4b0 --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/svcs_menu.cpp @@ -0,0 +1,211 @@ +#include "stdafx.h" +#include "otr.h" + +HANDLE hMenuBuildEvent, hStopItem, hStartItem; + +//////////////////////////////// +///////// Menu Services //////// +/////////////////////////////// +int StartOTR(HANDLE hContact) { + + const char *proto = contact_get_proto(hContact); + if (!proto) return 1; // error + char *uname = contact_get_id(hContact); + if (!uname) return 1; // error + DWORD pol = DBGetContactSettingDword(hContact, MODULENAME, "Policy", CONTACT_DEFAULT_POLICY); + if(pol == CONTACT_DEFAULT_POLICY) pol = options.default_policy; + + lib_cs_lock(); + char *msg = otrl_proto_default_query_msg(MODULENAME, pol); + otr_gui_inject_message(hContact, proto, proto, uname, msg ? msg : "?OTRv2?"); + lib_cs_unlock(); + otrl_message_free(msg); + mir_free(uname); + return 0; +} +INT_PTR SVC_StartOTR(WPARAM wParam, LPARAM lParam) { + HANDLE hContact = (HANDLE)wParam, hSub; + if(options.bHaveMetaContacts && (hSub = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0)) != 0) { + hContact = hSub; + } + + if ( options.bHaveSecureIM && CallService("SecureIM/IsContactSecured", (WPARAM)hContact, 0) != 0 ) { + TCHAR msg[512]; + mir_sntprintf(msg, 512, TranslateT(LANG_OTR_SECUREIM_STARTED), contact_get_nameT(hContact)); + ShowError(msg); + return 0; + } + + TCHAR buff[512]; + mir_sntprintf(buff, 512, TranslateT(LANG_SESSION_REQUEST_OTR), contact_get_nameT(hContact)); + ShowMessage(hContact, buff); + + int res = StartOTR(hContact); + if (res) return res; + + return 0; +} +INT_PTR SVC_RefreshOTR(WPARAM wParam, LPARAM lParam) { + HANDLE hContact = (HANDLE)wParam, hSub; + if(options.bHaveMetaContacts && (hSub = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0)) != 0) { + hContact = hSub; + } + + if ( options.bHaveSecureIM && CallService("SecureIM/IsContactSecured", (WPARAM)hContact, 0) != 0 ) { + TCHAR msg[512]; + mir_sntprintf(msg, 512, TranslateT(LANG_OTR_SECUREIM_STARTED), contact_get_nameT(hContact)); + ShowError(msg); + return 0; + } + + TCHAR buff[512]; + mir_sntprintf(buff, 512, TranslateT(LANG_SESSION_TRY_CONTINUE_OTR), contact_get_nameT(hContact)); + ShowMessage(hContact, buff); + + int res = StartOTR(hContact); + if (res) return res; + + return 0; +} +int otr_disconnect_contact(HANDLE hContact) { + HANDLE hSub; + if(ServiceExists(MS_MC_GETMOSTONLINECONTACT) && (hSub = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0)) != 0) { + hContact = hSub; + } + + const char *proto = contact_get_proto(hContact); + if (!proto) return 1; // error + char *uname = contact_get_id(hContact); + if (!uname) return 1; // error + + lib_cs_lock(); + otrl_message_disconnect(otr_user_state, &ops, hContact, proto, proto, uname); + lib_cs_unlock(); + mir_free(uname); + return 0; +} + +INT_PTR SVC_StopOTR(WPARAM wParam, LPARAM lParam) { + HANDLE hContact = (HANDLE)wParam; + + // prevent this filter from acting on injeceted messages for metas, when they are passed though the subcontact's proto send chain + if (otr_disconnect_contact(hContact)) return 0; + + SetEncryptionStatus(hContact, TRUST_NOT_PRIVATE); + + TCHAR buff[512]; + mir_sntprintf(buff, 512, TranslateT(LANG_SESSION_TERMINATED_OTR), contact_get_nameT(hContact)); + ShowMessage(hContact, buff); + + return 0; +} + +INT_PTR SVC_VerifyOTR(WPARAM wParam, LPARAM lParam) { + HANDLE hContact = (HANDLE)wParam, hSub; + if(options.bHaveMetaContacts && (hSub = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0)) != 0) { + hContact = hSub; + } + ConnContext *context = otrl_context_find_miranda(otr_user_state, (HANDLE)wParam); + if (!context) return 1; + //VerifyContextDialog(context); + SMPInitDialog(context); + return 0; +} + +INT_PTR SVC_ToggleHTMLOTR(WPARAM wParam, LPARAM lParam) { + HANDLE hContact = (HANDLE)wParam; + if (db_get_b(hContact, MODULENAME, "HTMLConv", 0)) + db_set_b(hContact, MODULENAME, "HTMLConv", 0); + else + db_set_b(hContact, MODULENAME, "HTMLConv", 1); + + return 0; +} + +void InitMenu() { + CreateServiceFunction(MS_OTR_MENUSTART, SVC_StartOTR); + CreateServiceFunction(MS_OTR_MENUSTOP, SVC_StopOTR); + CreateServiceFunction(MS_OTR_MENUREFRESH, SVC_RefreshOTR); + CreateServiceFunction(MS_OTR_MENUVERIFY, SVC_VerifyOTR); + CreateServiceFunction(MS_OTR_MENUTOGGLEHTML, SVC_ToggleHTMLOTR); + + CLISTMENUITEM mi = {0}; + mi.cbSize = sizeof(mi); + mi.flags = CMIF_NOTOFFLINE | CMIF_TCHAR | CMIF_ICONFROMICOLIB; + mi.position = -400000; + + mi.ptszName = _T(LANG_STOP_OTR); + mi.pszService = MS_OTR_MENUSTOP; + mi.icolibItem = GetIconHandle(ICON_PRIVATE); + + hStopItem = Menu_AddContactMenuItem(&mi); + + mi.ptszName = _T(LANG_START_OTR); + mi.pszService = MS_OTR_MENUSTART; + mi.icolibItem = GetIconHandle(ICON_NOT_PRIVATE); + + hStartItem = Menu_AddContactMenuItem(&mi); + + hMenuBuildEvent = HookEvent(ME_CLIST_PREBUILDCONTACTMENU, SVC_PrebuildContactMenu); + +} + +void DeinitMenu() { + UnhookEvent(hMenuBuildEvent); +} + +int SVC_PrebuildContactMenu(WPARAM wParam, LPARAM lParam) { + HANDLE hContact = (HANDLE)wParam; + + CLISTMENUITEM mi = {0}; + mi.cbSize = sizeof(mi); + mi.flags = CMIM_FLAGS | CMIF_NOTOFFLINE | CMIF_TCHAR | CMIF_ICONFROMICOLIB; + + const char *proto = contact_get_proto(hContact); + DWORD pol = CONTACT_DEFAULT_POLICY; + + if (!proto || DBGetContactSettingByte(hContact, proto, "ChatRoom", 0) == 1) { + goto hide_all; + } + + if(proto && g_metaproto && strcmp(proto, g_metaproto) == 0) { + // make menu act as per most online subcontact + hContact = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0); + if (!hContact) + goto hide_all; + proto = contact_get_proto(hContact); + } + + pol = DBGetContactSettingDword(hContact, MODULENAME, "Policy", CONTACT_DEFAULT_POLICY); + if(pol == CONTACT_DEFAULT_POLICY) pol = options.default_policy; + + if(pol == OTRL_POLICY_NEVER || pol == OTRL_POLICY_ALWAYS) { + goto hide_all; + } + + { + ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact); + TrustLevel encrypted = otr_context_get_trust(context); + if(encrypted != TRUST_NOT_PRIVATE) { + CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hStopItem, (LPARAM)&mi); + mi.flags |= CMIF_HIDDEN; + CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hStartItem, (LPARAM)&mi); + } else { + //if(pol == OTRL_POLICY_MANUAL_MOD) { + CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hStartItem, (LPARAM)&mi); + mi.flags |= CMIF_HIDDEN; + CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hStopItem, (LPARAM)&mi); + //} else { // should only be 'opportunistic' + // goto hide_all; + //} + } + } + + return 0; + +hide_all: + mi.flags |= CMIF_HIDDEN; + CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hStopItem, (LPARAM)&mi); + CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hStartItem, (LPARAM)&mi); + return 0; +} \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/src/svcs_menu.h b/plugins/MirOTR/MirOTR/src/svcs_menu.h new file mode 100644 index 0000000000..7dfc11a9ea --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/svcs_menu.h @@ -0,0 +1,14 @@ +#pragma once +INT_PTR SVC_StartOTR(WPARAM wParam, LPARAM lParam); +INT_PTR SVC_RefreshOTR(WPARAM wParam, LPARAM lParam); +INT_PTR SVC_StopOTR(WPARAM wParam, LPARAM lParam); +INT_PTR SVC_VerifyOTR(WPARAM wParam, LPARAM lParam); +int SVC_PrebuildContactMenu(WPARAM wParam, LPARAM lParam); +void InitMenu(); +void DeinitMenu(); + +#define MS_OTR_MENUSTART MODULENAME"/Start" +#define MS_OTR_MENUSTOP MODULENAME"/Stop" +#define MS_OTR_MENUREFRESH MODULENAME"/Refresh" +#define MS_OTR_MENUVERIFY MODULENAME"/Verify" +#define MS_OTR_MENUTOGGLEHTML MODULENAME"/ToggleHTML" \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/src/svcs_proto.cpp b/plugins/MirOTR/MirOTR/src/svcs_proto.cpp new file mode 100644 index 0000000000..618034cc10 --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/svcs_proto.cpp @@ -0,0 +1,406 @@ +#include "stdafx.h" +#include "svcs_proto.h" +#include "striphtml.h" +#include "entities.h" +#include +#include +#include +#include + +//TODO: Social-Millionaire-Dialoge +INT_PTR SVC_OTRSendMessage(WPARAM wParam,LPARAM lParam){ + if (!lParam) return 0; + + CCSDATA *ccs = (CCSDATA *) lParam; + + DEBUGOUT_T("SENDING") + + if (ccs->wParam & PREF_BYPASS_OTR) // bypass for OTR-messages + return CallService(MS_PROTO_CHAINSEND, wParam, lParam); + + char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)ccs->hContact, 0); + if(proto && g_metaproto && strcmp(proto, g_metaproto) == 0) // bypass for metacontacts + return CallService(MS_PROTO_CHAINSEND, wParam, lParam); + if (!proto || !ccs->hContact) return 1; // error + + gcry_error_t err; + char *newmessage = 0; + char *oldmessage = (char *)ccs->lParam; + char *oldmessage_utf = 0; + + //MessageBox(0, "Send message - converting to UTF-8", "msg", MB_OK); + + if(ccs->wParam & PREF_UTF) { + oldmessage_utf = oldmessage; + } else if(ccs->wParam & PREF_UNICODE) { + //TODO: check if this is correct or oldmessage[strlen(oldmessage)+1] is needed + //oldmessage_utf = mir_utf8encodeW((wchar_t*)oldmessage); + //should be the thing with strlen + oldmessage_utf = mir_utf8encodeW((wchar_t*)&oldmessage[strlen(oldmessage)+1]); + } else { + oldmessage_utf = mir_utf8encode(oldmessage); + } + if (!oldmessage_utf) return 1; + + // don't filter OTR messages being sent (OTR messages should only happen *after* the otrl_message_sending call below) + if(strncmp(oldmessage_utf, "?OTR", 4) == 0) { + DEBUGOUT_T("OTR message without PREF_BYPASS_OTR") + if (!(ccs->wParam & PREF_UTF)) mir_free(oldmessage_utf); + return CallService(MS_PROTO_CHAINSEND, wParam, lParam); + } + + char *tmpencode = NULL; + ConnContext *context = otrl_context_find_miranda(otr_user_state, (void*)ccs->hContact); + if (db_get_b(ccs->hContact, MODULENAME, "HTMLConv", 0) && otr_context_get_trust(context) >= TRUST_UNVERIFIED) { + char *tmpencode = encode_html_entities_utf8(oldmessage_utf); + if (tmpencode != NULL) { + if (!(ccs->wParam & PREF_UTF)) mir_free(oldmessage_utf); + oldmessage_utf = tmpencode; + } + } + + char *username = contact_get_id(ccs->hContact); + err = otrl_message_sending(otr_user_state, &ops, (void*)ccs->hContact, + proto, proto, username, oldmessage_utf, NULL, &newmessage, + add_appdata, (void*)ccs->hContact); + if (tmpencode!= NULL || !(ccs->wParam & PREF_UTF)) mir_free(oldmessage_utf); + oldmessage_utf = NULL; + mir_free(username); + + if (err && newmessage == NULL) { + /* Be *sure* not to send out plaintext */ + ShowError(TranslateT(LANG_ENCRYPTION_ERROR)); + /* should not be needed + char t[3] = {0, 0, 0}; + if(ccs->wParam & PREF_UNICODE) { //TODO!! lstrlen(pre->szMessage)+1 ?? + if (strlen(oldmessage)) memcpy(oldmessage, t,3 ); + } else { + if (strlen(oldmessage)) memcpy(oldmessage, t, 1); + } + */ + return 1; + } else if (newmessage) { + /* Fragment the message if necessary, and send all but the last + * fragment over the network. We will send the last segment later */ + + // oldmessage_utf is not used anymore, so use it as buffer + err = otrl_message_fragment_and_send(&ops, (void*)ccs->hContact, context, + newmessage, OTRL_FRAGMENT_SEND_ALL_BUT_LAST, &oldmessage_utf); + // newmessage is not needed anymore + otrl_message_free(newmessage); + // move the last fragment to newmessage, oldmessage_utf will be buffer later + newmessage = oldmessage_utf; + + WPARAM oldflags = ccs->wParam; + if(ccs->wParam & PREF_UTF) { + ccs->lParam = (LPARAM)newmessage; + } else if(ccs->wParam & PREF_UNICODE) { + // just send UTF, hope that proto supports it. + // don't want to create the Unicode-Format + // oldmessage_utf = (char*)mir_utf8decodeW(newmessage); + ccs->lParam = (LPARAM)newmessage; + ccs->wParam &= ~PREF_UNICODE; + ccs->wParam |= PREF_UTF; + } else { + mir_utf8decode(newmessage, NULL); + ccs->lParam = (LPARAM)newmessage; + } + if (otr_context_get_trust(context) >= TRUST_UNVERIFIED) ccs->wParam; + INT_PTR ret = CallService(MS_PROTO_CHAINSEND, wParam, lParam); + +#ifdef _DEBUG + if(ccs->wParam & PREF_UNICODE) + { + TCHAR *mes = mir_a2t((const char *)ccs->lParam); + MessageBox(0, mes, _T("OTR - sending raw message"), MB_OK); + mir_free(mes); + } + else + MessageBoxA(0, (char *)ccs->lParam, ("OTR - sending raw message"), MB_OK); + #endif + + // reset to original values + + ccs->lParam = (LPARAM)oldmessage; + ccs->wParam = oldflags; + otrl_message_free(newmessage); + return ret; + + } + + return CallService(MS_PROTO_CHAINSEND, wParam, lParam); +} + +INT_PTR SVC_OTRSendMessageW(WPARAM wParam, LPARAM lParam){ + if (!lParam) return 0; + + CCSDATA *ccs = (CCSDATA *) lParam; + if (!(ccs->wParam & PREF_UTF)) ccs->wParam |= PREF_UNICODE; + + return SVC_OTRSendMessage(wParam, lParam); +} + +/* +#define MESSAGE_PREFIX "(OTR) " +#define MESSAGE_PREFIXW L"(OTR) " +#define MESSAGE_PREFIX_LEN 6 +*/ + +INT_PTR SVC_OTRRecvMessage(WPARAM wParam,LPARAM lParam){ + //PUShowMessage("OTR Recv Message", SM_NOTIFY); + CCSDATA *ccs = (CCSDATA *) lParam; + PROTORECVEVENT *pre = (PROTORECVEVENT *) ccs->lParam; + +#ifdef _DEBUG + if(pre->flags & PREF_UNICODE) + { + TCHAR *mes = mir_a2t(pre->szMessage); + MessageBox(0, mes, _T("OTR - receiving message"), MB_OK); + mir_free(mes); + } + else + MessageBoxA(0, (char *)pre->szMessage, ("OTR - receiving message"), MB_OK); +#endif + + if (pre->flags & PREF_BYPASS_OTR) { // bypass for our inline messages + return CallService(MS_PROTO_CHAINRECV, wParam, lParam); + } + + char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)ccs->hContact, 0); + if (!proto) + return 1; //error + else if(proto && g_metaproto && strcmp(proto, g_metaproto) == 0) // bypass for metacontacts + return CallService(MS_PROTO_CHAINRECV, wParam, lParam); + + if (!ccs->hContact) return 1; //error + + char *oldmessage = pre->szMessage; + char *oldmessage_utf = NULL; + // convert oldmessage to utf-8 + if(pre->flags & PREF_UTF) { + oldmessage_utf = oldmessage; + } else if(pre->flags & PREF_UNICODE) { //UNSURE!! + oldmessage_utf = mir_utf8encodeW((wchar_t*)(&oldmessage[strlen(oldmessage)+1])); + } else { + oldmessage_utf = mir_utf8encode(oldmessage); + } + if (!oldmessage_utf) return 1; + + + char *newmessage = NULL; + OtrlTLV *tlvs = NULL; + OtrlTLV *tlv = NULL; + BOOL ignore_msg; + ConnContext *context; + //NextExpectedSMP nextMsg; + + char *uname = contact_get_id(ccs->hContact); + lib_cs_lock(); + ignore_msg = otrl_message_receiving(otr_user_state, &ops, (void*)ccs->hContact, + proto, proto, uname, oldmessage_utf, + &newmessage, &tlvs, add_appdata, (void*)ccs->hContact); + lib_cs_unlock(); + mir_free(uname); + + if ( !(pre->flags & PREF_UTF)) mir_free(oldmessage_utf); + oldmessage_utf = NULL; + + + tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED); + if (tlv && !Miranda_Terminated()) { + /* Notify the user that the other side disconnected. */ + TCHAR buff[256]; + mir_sntprintf(buff, 256, TranslateT(LANG_SESSION_TERMINATED_BY_OTR), contact_get_nameT(ccs->hContact)); + //MessageBox(0, buff, Translate("OTR Information"), MB_OK); + ShowMessage((HANDLE)ccs->hContact, buff); + + //if(options.timeout_finished) ResetFinishedTimer(); + } + + lib_cs_lock(); + context = otrl_context_find_miranda(otr_user_state, ccs->hContact); + lib_cs_unlock(); + /* Keep track of our current progress in the Socialist Millionaires' + * Protocol. */ + + /* + if (context && ( (context->smstate->sm_prog_state == OTRL_SMP_PROG_CHEATED) || + otrl_tlv_find(tlvs, OTRL_TLV_SMP1Q) || + otrl_tlv_find(tlvs, OTRL_TLV_SMP1) || + otrl_tlv_find(tlvs, OTRL_TLV_SMP2) || + otrl_tlv_find(tlvs, OTRL_TLV_SMP3) || + otrl_tlv_find(tlvs, OTRL_TLV_SMP4) ) + ) + { + otr_abort_smp(context); // we do not support it (yet), notify partner to shorten wait time + } + */ + + + if (context) { + NextExpectedSMP nextMsg = context->smstate->nextExpected; + + if (context->smstate->sm_prog_state == OTRL_SMP_PROG_CHEATED) { + otr_abort_smp(context); + //otrg_dialog_update_smp(context, 0.0); + SMPDialogUpdate(context, 0); + context->smstate->nextExpected = OTRL_SMP_EXPECT1; + context->smstate->sm_prog_state = OTRL_SMP_PROG_OK; + } else { + + tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1Q); + if (tlv) { + if (nextMsg != OTRL_SMP_EXPECT1) + otr_abort_smp(context); + else { + char *question = (char *)tlv->data; + char *eoq = (char*)memchr(question, '\0', tlv->len); + if (eoq) { + SMPDialogReply(context, question); + } + } + } + tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1); + if (tlv) { + if (nextMsg != OTRL_SMP_EXPECT1) + otr_abort_smp(context); + else { + SMPDialogReply(context, NULL); + } + } + tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP2); + if (tlv) { + if (nextMsg != OTRL_SMP_EXPECT2) + otr_abort_smp(context); + else { + context->smstate->nextExpected = OTRL_SMP_EXPECT4; + SMPDialogUpdate(context, 60); + } + } + tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP3); + if (tlv) { + if (nextMsg != OTRL_SMP_EXPECT3) + otr_abort_smp(context); + else { + context->smstate->nextExpected = OTRL_SMP_EXPECT1; + SMPDialogUpdate(context, 100); + //otrg_dialog_update_smp(context, 1.0); + } + } + tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP4); + if (tlv) { + if (nextMsg != OTRL_SMP_EXPECT4) + otr_abort_smp(context); + else { + SMPDialogUpdate(context, 100); + //otrg_dialog_update_smp(context, 1.0); + context->smstate->nextExpected = OTRL_SMP_EXPECT1; + } + } + tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP_ABORT); + if (tlv) { + SMPDialogUpdate(context, 0); + context->smstate->nextExpected = OTRL_SMP_EXPECT1; + } + } + } + otrl_tlv_free(tlvs); + + /* If we're supposed to ignore this incoming message (because it's a + * protocol message), set it to NULL, so that other plugins that + * catch receiving-im-msg don't return 0, and cause it to be + * displayed anyway. */ + if (ignore_msg) { + /* should not be required ;) + char t[3] = {0, 0, 0}; + char t[3] = {0, 0, 0}; + if(pre->flags & PREF_UNICODE) { //TODO!! lstrlen(pre->szMessage)+1 ?? + if (pre->szMessage && strlen(pre->szMessage)) memcpy(pre->szMessage, t,3 ); + } else { + if (pre->szMessage && strlen(pre->szMessage)) memcpy(pre->szMessage, t, 1); + } + */ + if (newmessage) otrl_message_free(newmessage); + return 1; + } else if (newmessage) { + //bool free=false; + DWORD flags = pre->flags; + /* if(pre->flags & PREF_UTF) { + oldmessage_utf = newmessage; + } else if(pre->flags & PREF_UNICODE) { //TODO!! lstrlen(pre->szMessage)+1 ?? + oldmessage_utf = (char*)mir_utf8decodeW(newmessage); + free = true; + } else { + mir_utf8decode(newmessage, NULL); + oldmessage_utf = newmessage; + } */ + + //pre->szMessage = oldmessage_utf; + pre->flags &= ~PREF_UNICODE; + pre->flags |= PREF_UTF; // just use UTF, so we do not have to recode the message + + bool is_miralloc = false; + if (context) { + TrustLevel level = otr_context_get_trust(context); + if (level >= TRUST_UNVERIFIED) { + char* premsg; + if (db_get_b(ccs->hContact, MODULENAME, "HTMLConv", 0)) { + premsg = striphtml(newmessage); + otrl_message_free(newmessage); + newmessage = premsg; + is_miralloc = true; + } + + if (options.prefix_messages) { + size_t len = (strlen(options.prefix)+strlen(newmessage)+1)*sizeof(char); + premsg = (char*)mir_alloc( len ); + memset(premsg, 0, len); + strcpy(premsg, options.prefix); + strcat(premsg, newmessage); + (is_miralloc) ? mir_free(newmessage) : otrl_message_free(newmessage); + newmessage = premsg; + is_miralloc = true; + } + } + } + pre->szMessage = newmessage; + BOOL ret = CallService(MS_PROTO_CHAINRECV, wParam, lParam); + pre->flags = flags; + pre->szMessage = oldmessage; + if (is_miralloc) + mir_free(newmessage); + else + otrl_message_free(newmessage); + + // if (free) mir_free(oldmessage_utf); + return ret; + } + return CallService(MS_PROTO_CHAINRECV, wParam, lParam); + +} + +/* Abort the SMP protocol. Used when malformed or unexpected messages + * are received. */ +void otr_abort_smp(ConnContext *context) +{ + otrl_message_abort_smp(otr_user_state, &ops, context->app_data, context); +} + +/* Start the Socialist Millionaires' Protocol over the current connection, + * using the given initial secret, and optionally a question to pass to + * the buddy. */ +void otr_start_smp(ConnContext *context, const char *question, + const unsigned char *secret, size_t secretlen) +{ + otrl_message_initiate_smp_q(otr_user_state, &ops, context->app_data, + context, question, secret, secretlen); +} + +/* Continue the Socialist Millionaires' Protocol over the current connection, + * using the given initial secret (ie finish step 2). */ +void otr_continue_smp(ConnContext *context, + const unsigned char *secret, size_t secretlen) +{ + otrl_message_respond_smp(otr_user_state, &ops, context->app_data, + context, secret, secretlen); +} \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/src/svcs_proto.h b/plugins/MirOTR/MirOTR/src/svcs_proto.h new file mode 100644 index 0000000000..fe0db53a4e --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/svcs_proto.h @@ -0,0 +1,13 @@ +#pragma once + +INT_PTR SVC_OTRSendMessage(WPARAM wParam,LPARAM lParam); +INT_PTR SVC_OTRSendMessageW(WPARAM wParam, LPARAM lParam); +INT_PTR SVC_OTRRecvMessage(WPARAM wParam,LPARAM lParam); + +void otr_abort_smp(ConnContext *context); + +void otr_start_smp(ConnContext *context, const char *question, + const unsigned char *secret, size_t secretlen); + +void otr_continue_smp(ConnContext *context, + const unsigned char *secret, size_t secretlen); \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/src/svcs_srmm.cpp b/plugins/MirOTR/MirOTR/src/svcs_srmm.cpp new file mode 100644 index 0000000000..707eb0a020 --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/svcs_srmm.cpp @@ -0,0 +1,292 @@ +#include "stdafx.h" +#include "mirotrmenu.h" +HANDLE hEventIconPressed; +HICON hIconNotSecure, hIconFinished, hIconPrivate, hIconUnverified; +BBButton OTRButton; + +/* Plugin init and deinit */ +// int WindowEvent(WPARAM wParam, LPARAM lParam) { +// MessageWindowEventData *mwd = (MessageWindowEventData *)lParam; +// +// if(mwd->uType == MSG_WINDOW_EVT_CLOSE && options.end_window_close) { +// FinishSession(mwd->hContact); +// return 0; +// } +// +// if(mwd->uType != MSG_WINDOW_EVT_OPEN) return 0; +// if (!options.bHaveSRMMIcons) return 0; +// +// HANDLE hContact = mwd->hContact, hTemp; +// if(options.bHaveMetaContacts && (hTemp = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0)) != 0) +// hContact = hTemp; +// +// if (!CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)MODULENAME)) +// return 0; +// +// lib_cs_lock(); +// ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact); +// lib_cs_unlock(); +// +// SetEncryptionStatus(hContact, otr_context_get_trust(context)); +// +// return 0; +// } + +int SVC_IconPressed(WPARAM wParam, LPARAM lParam) { + HANDLE hContact = (HANDLE)wParam; + StatusIconClickData *sicd = (StatusIconClickData *)lParam; + if(sicd->cbSize < (int)sizeof(StatusIconClickData)) + return 0; + + if(strcmp(sicd->szModule, MODULENAME) == 0) { + char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); + if(proto && DBGetContactSettingByte(hContact, proto, "ChatRoom", 0)) + return 0; + ShowOTRMenu(hContact, sicd->clickLocation); + /* + HMENU hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_CONTEXT)); + CallService(MS_LANGPACK_TRANSLATEMENU, (WPARAM)hMenu, 0); + TrustLevel level = (TrustLevel) db_get_dw(hContact, MODULENAME, "TrustLevel", TRUST_NOT_PRIVATE); + MENUITEMINFO minfo = {0}; + minfo.cbSize = sizeof(MENUITEMINFO); + minfo.fMask = MIIM_STRING|MIIM_STATE|MIIM_BITMAP; + minfo.fState = MF_DISABLED; + + HWND wnd = GetFocus(); + HDC dc = GetDC(wnd), hdc = CreateCompatibleDC(dc); + HBITMAP bmpIconPrivate = CreateCompatibleBitmap(dc, 16, 16); + HGDIOBJ old = SelectObject(hdc, bmpIconPrivate); + DrawIconEx(hdc, 0, 0, hIconPrivate,16, 16, 0, GetSysColorBrush(COLOR_MENU), DI_NORMAL); + + HBITMAP bmpIconUnverified = CreateCompatibleBitmap(dc, 16, 16); + SelectObject(hdc, bmpIconUnverified); + DrawIconEx(hdc, 0, 0, hIconUnverified,16, 16, 0, GetSysColorBrush(COLOR_MENU), DI_NORMAL); + + HBITMAP bmpIconFinished = CreateCompatibleBitmap(dc, 16, 16); + SelectObject(hdc, bmpIconFinished); + DrawIconEx(hdc, 0, 0, hIconFinished,16, 16, 0, GetSysColorBrush(COLOR_MENU), DI_NORMAL); + + HBITMAP bmpIconNotSecure = CreateCompatibleBitmap(dc, 16, 16); + SelectObject(hdc, bmpIconNotSecure); + DrawIconEx(hdc, 0, 0, hIconNotSecure,16, 16, 0, GetSysColorBrush(COLOR_MENU), DI_NORMAL); + + switch (level) { + case TRUST_PRIVATE: + minfo.hbmpItem = bmpIconPrivate; + minfo.dwTypeData = TranslateT(LANG_STATUS_PRIVATE); + break; + case TRUST_UNVERIFIED: + minfo.hbmpItem = bmpIconUnverified; + minfo.dwTypeData = TranslateT(LANG_STATUS_UNVERIFIED); + break; + case TRUST_FINISHED: + minfo.hbmpItem = bmpIconFinished; + minfo.dwTypeData = TranslateT(LANG_STATUS_FINISHED); + break; + default: + minfo.hbmpItem = bmpIconNotSecure; + minfo.dwTypeData = TranslateT(LANG_STATUS_DISABLED); + } + + SelectObject(hdc, old); + DeleteDC(hdc); + ReleaseDC(wnd, dc); + + SetMenuItemInfo(hMenu, IDM_OTR_STATUS, FALSE, &minfo); + + minfo.fMask = MIIM_STATE|MIIM_BITMAP; + minfo.fState = (level==TRUST_NOT_PRIVATE)?MF_ENABLED:MF_GRAYED; + minfo.hbmpItem = bmpIconUnverified; + SetMenuItemInfo(hMenu, IDM_OTR_START, FALSE, &minfo); + + minfo.fState = (level==TRUST_NOT_PRIVATE)?MF_GRAYED:MF_ENABLED; + minfo.hbmpItem = bmpIconNotSecure; + SetMenuItemInfo(hMenu, IDM_OTR_STOP, FALSE, &minfo); + + minfo.fState = (level==TRUST_NOT_PRIVATE)?MF_GRAYED:MF_ENABLED; + minfo.hbmpItem = bmpIconFinished; + SetMenuItemInfo(hMenu, IDM_OTR_REFRESH, FALSE, &minfo); + + minfo.fState = (level==TRUST_NOT_PRIVATE||level==TRUST_FINISHED)?MF_GRAYED:MF_ENABLED; + minfo.hbmpItem = bmpIconPrivate; + SetMenuItemInfo(hMenu, IDM_OTR_VERIFY, FALSE, &minfo); + + switch ( (DWORD) TrackPopupMenu(GetSubMenu(hMenu, 0), TPM_NONOTIFY|TPM_RETURNCMD, sicd->clickLocation.x, sicd->clickLocation.y, 0, GetFocus(), 0) ) + { + case IDM_OTR_START: + SVC_StartOTR(wParam, 0); + break; + case IDM_OTR_REFRESH: + SVC_RefreshOTR(wParam, 0); + break; + case IDM_OTR_STOP: + SVC_StopOTR(wParam, 0); + break; + case IDM_OTR_VERIFY: + ConnContext *context = otrl_context_find_miranda(otr_user_state, (HANDLE)wParam); + if (context) VerifyContextDialog(context); + break; + } + DeleteObject(bmpIconPrivate); + DeleteObject(bmpIconFinished); + DeleteObject(bmpIconNotSecure); + DeleteObject(bmpIconUnverified); + */ + } + + return 0; +} + +// set SRMM icon status, if applicable +void SetEncryptionStatus(HANDLE hContact, TrustLevel level) { + //char dbg_msg[2048]; + //dbg_msg[0] = 0; + + //strcat(dbg_msg, "Set encyption status: "); + //strcat(dbg_msg, (encrypted ? "true" : "false")); + + char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); + bool chat_room = (proto && DBGetContactSettingByte(hContact, proto, "ChatRoom", 0)); + + // if (!chat_room) DBWriteContactSettingByte(hContact, MODULENAME, "Encrypted", (encrypted ? 1 : 0)); + + if(options.bHaveSRMMIcons || options.bHaveButtonsBar) { + //strcat(dbg_msg, "\nchanging icon"); + BBButton button = OTRButton; + StatusIconData sid = {0}, sid2={0}; + sid.cbSize = sizeof(sid); + sid.szModule = MODULENAME; + sid.dwId = 0; + sid.flags = MBF_HIDDEN; + + sid2.cbSize = sid.cbSize; + sid2.szModule = MODULENAME; + sid2.dwId = 1; + sid2.flags = MBF_HIDDEN; + if (!chat_room) { + switch (level) { + case TRUST_FINISHED: + sid.flags = 0; + button.ptszTooltip = TranslateT(LANG_STATUS_FINISHED); + button.hIcon = GetIconHandle(ICON_FINISHED); + break; + case TRUST_UNVERIFIED: + sid2.flags = MBF_DISABLED; + button.ptszTooltip = TranslateT(LANG_STATUS_UNVERIFIED); + button.hIcon = GetIconHandle(ICON_UNVERIFIED); + break; + case TRUST_PRIVATE: + sid2.flags = 0; + button.ptszTooltip = TranslateT(LANG_STATUS_PRIVATE); + button.hIcon = GetIconHandle(ICON_PRIVATE); + break; + default: + sid.flags = MBF_DISABLED; + button.ptszTooltip = TranslateT(LANG_STATUS_DISABLED); + button.hIcon = GetIconHandle(ICON_NOT_PRIVATE); + break; + } + button.bbbFlags = 0; + } else { + button.bbbFlags = BBSF_HIDDEN; + } + if (options.bHaveSRMMIcons) { + CallService(MS_MSG_MODIFYICON, (WPARAM)hContact, (LPARAM)&sid); + CallService(MS_MSG_MODIFYICON, (WPARAM)hContact, (LPARAM)&sid2); + } + if (options.bHaveButtonsBar) CallService(MS_BB_SETBUTTONSTATE, (WPARAM)hContact, (LPARAM)&button); + db_set_dw(hContact, MODULENAME, "TrustLevel", level); + + if (!chat_room && options.bHaveMetaContacts) { + HANDLE hMeta = (HANDLE)CallService(MS_MC_GETMETACONTACT, (WPARAM)hContact, 0); + HANDLE hMostOnline = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hMeta, 0); + if(hMeta && hContact == hMostOnline) { + //strcat(dbg_msg, "\nrecursing for meta"); + SetEncryptionStatus(hMeta, level); + } + else if(hMeta) { + /* in case the new most online contact has changed + (e.g. when the otr subcontact goes offline) */ + ConnContext *context = otrl_context_find_miranda(otr_user_state, hMostOnline); + TrustLevel encrypted = otr_context_get_trust(context); + SetEncryptionStatus(hMeta, encrypted); + } + } + } + //PUShowMessage(dbg_msg, SM_NOTIFY); +} + +int SVC_ButtonsBarLoaded(WPARAM, LPARAM) { + CallService(MS_BB_ADDBUTTON, 0, (LPARAM)&OTRButton); + return 0; +} +int SVC_ButtonsBarPressed(WPARAM w, LPARAM l) { + CustomButtonClickData* cbcd = (CustomButtonClickData *)l; + if (cbcd->cbSize == (int)sizeof(CustomButtonClickData) && cbcd->dwButtonId == 0 && strcmp(cbcd->pszModule, MODULENAME)==0) { + HANDLE hContact = (HANDLE)w; + + char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); + if(proto && DBGetContactSettingByte(hContact, proto, "ChatRoom", 0)) + return 0; + ShowOTRMenu(hContact, cbcd->pt); + + } + return 0; +} + +void InitSRMM() { + // add icon to srmm status icons + InitMirOTRMenu(); + if(options.bHaveSRMMIcons) { + hIconNotSecure = LoadIcon(ICON_NOT_PRIVATE, 0); + hIconFinished = LoadIcon(ICON_FINISHED, 0); + hIconPrivate = LoadIcon(ICON_PRIVATE, 0); + hIconUnverified = LoadIcon(ICON_UNVERIFIED, 0); + + StatusIconData sid = {0}; + sid.cbSize = sizeof(sid); + sid.szModule = MODULENAME; + sid.dwId = 0; + sid.hIcon = hIconFinished; + sid.hIconDisabled = hIconNotSecure; + sid.flags = MBF_DISABLED | MBF_HIDDEN; + sid.szTooltip = Translate(LANG_OTR_TOOLTIP); + CallService(MS_MSG_ADDICON, 0, (LPARAM)&sid); + + sid.dwId = 1; + sid.hIcon = hIconPrivate; + sid.hIconDisabled = hIconUnverified; + CallService(MS_MSG_ADDICON, 0, (LPARAM)&sid); + + // hook the window events so that we can can change the status of the icon + + hEventIconPressed = HookEvent(ME_MSG_ICONPRESSED, SVC_IconPressed); + } + if (options.bHaveButtonsBar) { + ZeroMemory(&OTRButton, sizeof(OTRButton)); + OTRButton.cbSize = sizeof(OTRButton); + OTRButton.dwButtonID = 0; + OTRButton.pszModuleName = MODULENAME; + OTRButton.dwDefPos = 200; +#ifdef _UNICODE + OTRButton.bbbFlags = BBBF_ISRSIDEBUTTON|BBBF_CANBEHIDDEN|BBBF_ISIMBUTTON; +#else + OTRButton.bbbFlags = BBBF_ISRSIDEBUTTON|BBBF_CANBEHIDDEN|BBBF_ISIMBUTTON|BBBF_ANSITOOLTIP; +#endif + OTRButton.ptszTooltip = TranslateT(LANG_OTR_TOOLTIP); + OTRButton.hIcon = GetIconHandle(ICON_NOT_PRIVATE); + HookEvent(ME_MSG_TOOLBARLOADED, SVC_ButtonsBarLoaded); + HookEvent(ME_MSG_BUTTONPRESSED, SVC_ButtonsBarPressed); + } +} +void DeinitSRMM() { + if(options.bHaveSRMMIcons) { + UnhookEvent(hEventIconPressed); + ReleaseIcon(ICON_NOT_PRIVATE, 0); + ReleaseIcon(ICON_FINISHED, 0); + ReleaseIcon(ICON_PRIVATE, 0); + ReleaseIcon(ICON_UNVERIFIED, 0); + hIconNotSecure = hIconFinished = hIconPrivate = hIconUnverified =0; + } + UninitMirOTRMenu(); +} \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/src/svcs_srmm.h b/plugins/MirOTR/MirOTR/src/svcs_srmm.h new file mode 100644 index 0000000000..4bc204656d --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/svcs_srmm.h @@ -0,0 +1,7 @@ +#pragma once + +int WindowEvent(WPARAM wParam, LPARAM lParam); +int SVC_IconPressed(WPARAM wParam, LPARAM lParam); +void SetEncryptionStatus(HANDLE hContact, TrustLevel level); +void InitSRMM(); +void DeinitSRMM(); \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/src/targetver.h b/plugins/MirOTR/MirOTR/src/targetver.h new file mode 100644 index 0000000000..4b435d653b --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/targetver.h @@ -0,0 +1,21 @@ +#pragma once + +// Die folgenden Makros definieren die mindestens erforderliche Plattform. Die mindestens erforderliche Plattform +// ist die früheste Windows-, Internet Explorer-Version usw., die über die erforderlichen Features zur Ausführung +// Ihrer Anwendung verfügt. Die Makros aktivieren alle Funktionen, die auf den Plattformversionen bis +// einschließlich der angegebenen Version verfügbar sind. + +// Ändern Sie folgende Definitionen für Plattformen, die älter als die unten angegebenen sind. +// Unter MSDN finden Sie die neuesten Informationen über die entsprechenden Werte für die unterschiedlichen Plattformen. + +#ifndef WINVER // Gibt an, dass Windows 2000 die mindestens erforderliche Plattform ist. +#define WINVER 0x0500 // Ändern Sie den entsprechenden Wert, um auf andere Versionen von Windows abzuzielen. +#endif + +#ifndef _WIN32_WINNT // Gibt an, dass Windows 2000 die mindestens erforderliche Plattform ist. +#define _WIN32_WINNT 0x0500 // Ändern Sie den entsprechenden Wert, um auf andere Versionen von Windows abzuzielen. +#endif + +#ifndef _WIN32_IE // Gibt an, dass Internet Explorer 7.0 die mindestens erforderliche Plattform ist. +#define _WIN32_IE 0x0700 // Ändern Sie den entsprechenden Wert, um auf andere Versionen von IE abzuzielen. +#endif diff --git a/plugins/MirOTR/MirOTR/src/utils.cpp b/plugins/MirOTR/MirOTR/src/utils.cpp new file mode 100644 index 0000000000..ce2bbc5b9a --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/utils.cpp @@ -0,0 +1,417 @@ +#include "stdafx.h" +#include "utils.h" + +CRITICAL_SECTION lib_cs; + +void InitUtils() { + InitializeCriticalSection(&lib_cs); +} +void DeinitUtils() { + DeleteCriticalSection(&lib_cs); +} + +void lib_cs_lock() { + EnterCriticalSection(&lib_cs); +} + +void lib_cs_unlock() { + LeaveCriticalSection(&lib_cs); +} + +HANDLE find_contact(const char* userid, const char* protocol) { + HANDLE hContact = db_find_first(); + while ( hContact != NULL ) + { + const char *proto = contact_get_proto(hContact); + if(proto && strcmp(proto, protocol) == 0) { + char *name = contact_get_id(hContact); + if(name && strcmp(name, userid) == 0) { + mir_free(name); + return hContact; + } + mir_free(name); + } + hContact = db_find_next(hContact); + } + + return 0; +} + +/* Look up a connection context by hContact from the given +* OtrlUserState. If add_if_missing is true, allocate and return a new +* context if one does not currently exist. In that event, call +* add_app_data(data, context) so that app_data and app_data_free can be +* filled in by the application, and set *addedp to 1. */ +ConnContext * otrl_context_find_miranda(OtrlUserState us, HANDLE hContact) +{ + ConnContext ** curp; + if (!hContact) return NULL; + for (curp = &(us->context_root); *curp; curp = &((*curp)->next)) { + if ((*curp)->app_data == hContact ) return *curp; + } + return NULL; +} + +/* What level of trust do we have in the privacy of this ConnContext? */ +TrustLevel otr_context_get_trust(ConnContext *context) +{ + TrustLevel level = TRUST_NOT_PRIVATE; + + if (context && context->msgstate == OTRL_MSGSTATE_ENCRYPTED) { + if (context->active_fingerprint->trust && + context->active_fingerprint->trust[0] != '\0') { + level = TRUST_PRIVATE; + } else { + level = TRUST_UNVERIFIED; + } + } else if (context && context->msgstate == OTRL_MSGSTATE_FINISHED) { + level = TRUST_FINISHED; + } + + return level; +} + +/* Set verification of fingerprint */ +void VerifyFingerprint(ConnContext *context, bool verify) { + lib_cs_lock(); + otrl_context_set_trust(context->active_fingerprint, (verify)?"verified":NULL); + otrl_privkey_write_fingerprints(otr_user_state, g_fingerprint_store_filename); + lib_cs_unlock(); + VerifyFingerprintMessage(context, verify); +} + +void VerifyFingerprintMessage(ConnContext *context, bool verify) { + TCHAR msg[1024]; + mir_sntprintf(msg, 1024, (verify)?TranslateT(LANG_FINGERPRINT_VERIFIED):TranslateT(LANG_FINGERPRINT_NOT_VERIFIED), contact_get_nameT((HANDLE)context->app_data)); + msg[1023] = '\0'; + ShowMessage((HANDLE)context->app_data, msg); + SetEncryptionStatus(context->app_data, otr_context_get_trust(context)); +} + +/* Convert a 20-byte hash value to a 45-byte human-readable value */ +void otrl_privkey_hash_to_humanT(TCHAR human[45], const unsigned char hash[20]) +{ + int word, byte; + TCHAR *p = human; + + for(word=0; word<5; ++word) { + for(byte=0; byte<4; ++byte) { + _stprintf(p, _T("%02X"), hash[word*4+byte]); + p += 2; + } + *(p++) = ' '; + } + /* Change that last ' ' to a '\0' */ + --p; + *p = '\0'; +} + +char* contact_get_id(HANDLE hContact, bool bNameOnError) { + char* pszUniqueID = NULL; + CONTACTINFO ci; + ZeroMemory(&ci, sizeof(ci)); + ci.cbSize = sizeof(ci); + ci.hContact = hContact; + ci.dwFlag = CNF_UNIQUEID; + + if (CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci) == 0) + { + if (ci.type == CNFT_ASCIIZ) { + pszUniqueID = (char*)ci.pszVal; // MS_CONTACT_GETCONTACTINFO uses mir_alloc + } else if (ci.type == CNFT_DWORD) { + pszUniqueID = (char*)mir_alloc(15); + if (pszUniqueID) + mir_snprintf(pszUniqueID, 15, ("%u"), ci.dVal); + } else if (ci.type == CNFT_WORD) { + pszUniqueID = (char*)mir_alloc(15); + if (pszUniqueID) + mir_snprintf(pszUniqueID, 15, ("%u"), ci.wVal); + } else if (ci.type == CNFT_BYTE) { + pszUniqueID = (char*)mir_alloc(15); + if (pszUniqueID) + mir_snprintf(pszUniqueID, 15, ("%u"), ci.bVal); + } + } + if (!pszUniqueID && bNameOnError) { + char *name = (char *)CallService( MS_CLIST_GETCONTACTDISPLAYNAME, ( WPARAM )hContact, 0 ); + if (name) pszUniqueID = mir_strdup(name); + } + return pszUniqueID; +} + +__inline const TCHAR* contact_get_nameT(HANDLE hContact) { + return (TCHAR*)CallService( MS_CLIST_GETCONTACTDISPLAYNAME, ( WPARAM )hContact, GCDNF_TCHAR ); +} + +__inline const char* contact_get_proto(HANDLE hContact) { + char *uproto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); + return uproto; +} + +__inline const char* contact_get_account(HANDLE hContact) { + char *uacc = (char *)CallService(MS_PROTO_GETCONTACTBASEACCOUNT, (WPARAM)hContact, 0); + return uacc; +} + +void ShowPopup(const TCHAR* line1, const TCHAR* line2, int timeout, const HANDLE hContact) { + if(CallService(MS_SYSTEM_TERMINATED, 0, 0)) return; + + if ( !options.bHavePopups) { + TCHAR title[256]; + _stprintf(title, _T("%s Message"), _T(MODULENAME)); + + if(line1 && line2) { + TCHAR *message = new TCHAR[_tcslen(line1) + _tcslen(line2) + 3]; // newline and null terminator + _stprintf(message, _T("%s\r\n%s"), line1, line2); + MessageBox( NULL, message, title, MB_OK | MB_ICONINFORMATION ); + delete message; + } else if(line1) { + MessageBox( NULL, line1, title, MB_OK | MB_ICONINFORMATION ); + } else if(line2) { + MessageBox( NULL, line2, title, MB_OK | MB_ICONINFORMATION ); + } + return; + } + + POPUPDATAT ppd = {0}; + //memset((void *)&ppd, 0, sizeof(POPUPDATAT)); + + ppd.lchContact = hContact; + ppd.lchIcon = NULL; + + if(line1 && line2) { + _tcsncpy( ppd.lptzContactName, line1, MAX_CONTACTNAME-1 ); + _tcsncpy( ppd.lptzText, line2, MAX_SECONDLINE-1 ); + } else if(line1) { + if (PUIsSecondLineShown()) _tcsncpy( ppd.lptzText, line1, MAX_SECONDLINE-1 ); + else _tcsncpy( ppd.lptzContactName, line1, MAX_CONTACTNAME-1 ); + } + else if(line2) { + if (PUIsSecondLineShown()) _tcsncpy( ppd.lptzText, line2, MAX_SECONDLINE-1 ); + else _tcsncpy( ppd.lptzContactName, line2, MAX_CONTACTNAME-1 ); + } + + ppd.iSeconds = timeout; + + ppd.PluginWindowProc = NULL; + ppd.PluginData = NULL; + + PUAddPopUpT(&ppd); + +} + +void ShowWarning(TCHAR *msg) { + TCHAR buffer[512]; + ErrorDisplay disp = options.err_method; + // funny logic :) ... try to avoid message boxes + // if want baloons but no balloons, try popups + // if want popups but no popups, try baloons + // if, after that, you want balloons but no balloons, revert to message boxes + if(disp == ED_BAL && !ServiceExists(MS_CLIST_SYSTRAY_NOTIFY)) disp = ED_POP; + if(disp == ED_POP && !options.bHavePopups) disp = ED_BAL; + if(disp == ED_BAL && !ServiceExists(MS_CLIST_SYSTRAY_NOTIFY)) disp = ED_MB; + + _stprintf(buffer, _T("%s Warning"), _T(MODULENAME)); + + TCHAR *message; + switch(disp) { + case ED_POP: + message = new TCHAR[_tcslen(msg) + 515]; // newline and null terminator + _stprintf(message, _T("%s\r\n%s"), buffer, msg); + PUShowMessageT(message, SM_WARNING); + delete message; + break; + case ED_MB: + MessageBox(0, msg, buffer, MB_OK | MB_ICONWARNING); + break; + case ED_BAL: + { + MIRANDASYSTRAYNOTIFY sn = {0}; + sn.cbSize = sizeof(sn); + sn.szProto= MODULENAME; + sn.tszInfoTitle = buffer; + sn.tszInfo = msg; +#ifdef _UNICODE + sn.dwInfoFlags = NIIF_WARNING | NIIF_INTERN_UNICODE; +#else + sn.dwInfoFlags = NIIF_WARNING; +#endif + sn.uTimeout = 10; + + CallService(MS_CLIST_SYSTRAY_NOTIFY, 0, (LPARAM)&sn); + } + + break; + } +} + +void ShowError(TCHAR *msg) { + TCHAR buffer[512]; + ErrorDisplay disp = options.err_method; + // funny logic :) ... try to avoid message boxes + // if want baloons but no balloons, try popups + // if want popups but no popups, try baloons + // if, after that, you want balloons but no balloons, revert to message boxes + if(disp == ED_BAL && !ServiceExists(MS_CLIST_SYSTRAY_NOTIFY)) disp = ED_POP; + if(disp == ED_POP && !options.bHavePopups) disp = ED_BAL; + if(disp == ED_BAL && !ServiceExists(MS_CLIST_SYSTRAY_NOTIFY)) disp = ED_MB; + + _stprintf(buffer, _T("%s Error"), _T(MODULENAME)); + + + TCHAR *message; + switch(disp) { + case ED_POP: + message = new TCHAR[_tcslen(msg) + 515]; // newline and null terminator + _stprintf(message, _T("%s\r\n%s"), buffer, msg); + PUShowMessageT(message, SM_WARNING); + delete message; + break; + case ED_MB: + MessageBox(0, msg, buffer, MB_OK | MB_ICONERROR); + break; + case ED_BAL: + { + MIRANDASYSTRAYNOTIFY sn = {0}; + sn.cbSize = sizeof(sn); + sn.szProto = MODULENAME; + sn.tszInfoTitle = buffer; + sn.tszInfo = msg; +#ifdef _UNICODE + sn.dwInfoFlags = NIIF_ERROR | NIIF_INTERN_UNICODE; +#else + sn.dwInfoFlags = NIIF_ERROR; +#endif + sn.uTimeout = 10; + + CallService(MS_CLIST_SYSTRAY_NOTIFY, 0, (LPARAM)&sn); + } + + break; + } +} + + +void ShowPopupUtf(const char* line1, const char* line2, int timeout, const HANDLE hContact) { + TCHAR* l1 = (line1) ? mir_utf8decodeT(line1) : NULL; + TCHAR* l2 = (line2) ? mir_utf8decodeT(line2) : NULL; + ShowPopup(l1, l2, timeout, hContact); + if (l1) mir_free(l1); + if (l2) mir_free(l2); +} + +void ShowWarningUtf(char* msg) { + TCHAR* m = (msg) ? mir_utf8decodeT(msg) : NULL; + ShowWarning(m); + if (m) mir_free(m); +} +void ShowErrorUtf(char* msg) { + TCHAR* m = (msg) ? mir_utf8decodeT(msg) : NULL; + ShowError(m); + if (m) mir_free(m); +} + +void ShowMessageInline(const HANDLE hContact, const TCHAR *msg) { + TCHAR buff[1024]; + mir_sntprintf(buff, 1024, _T("%s%s"), TranslateT(LANG_INLINE_PREFIX), msg); + + PROTORECVEVENT pre = {0}; + pre.timestamp = time(0); + char *utf = mir_utf8encodeT(buff); + pre.szMessage = utf; + pre.flags = PREF_UTF|PREF_BYPASS_OTR; + //CallContactService(hContact, PSR_MESSAGE, 0, (LPARAM)&pre); + + CCSDATA ccs = {0}; + ccs.hContact = hContact; + ccs.szProtoService = PSR_MESSAGE; + ccs.lParam = (LPARAM)⪯ + + CallService(MS_PROTO_CHAINRECV, 0, (LPARAM)&ccs); + mir_free(utf); +} + +void ShowMessageInlineUtf(const HANDLE hContact, const char *msg) { + char buff[1024]; + mir_snprintf(buff, 1024, "%s%s", Translate(LANG_INLINE_PREFIX), msg); + + PROTORECVEVENT pre = {0}; + pre.timestamp = time(0); + pre.szMessage = buff; + pre.flags = PREF_UTF|PREF_BYPASS_OTR; + //CallContactService(hContact, PSR_MESSAGE, 0, (LPARAM)&pre); + + CCSDATA ccs = {0}; + ccs.hContact = hContact; + ccs.szProtoService = PSR_MESSAGE; + ccs.lParam = (LPARAM)⪯ + + CallService(MS_PROTO_CHAINRECV, 0, (LPARAM)&ccs); +} + + +void ShowMessageUtf(const HANDLE hContact, const char *msg) { + if(options.msg_inline) + ShowMessageInlineUtf(hContact, msg); + if(options.msg_popup) + ShowPopupUtf(Translate(LANG_OTR_INFO), msg, 0, hContact); +} + +void ShowMessage(const HANDLE hContact, const TCHAR *msg) { + if(options.msg_inline) + ShowMessageInline(hContact, msg); + if(options.msg_popup) + ShowPopup(TranslateT(LANG_OTR_INFO), msg, 0, hContact); +} + + +/* +bool GetEncryptionStatus(HANDLE hContact) { + char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); + bool chat_room = (proto && DBGetContactSettingByte(hContact, proto, "ChatRoom", 0)); + + if (!chat_room) { + if (options.bHaveMetaContacts) { + HANDLE hMeta = (HANDLE)CallService(MS_MC_GETMETACONTACT, (WPARAM)hContact, 0); + if(hMeta && hContact == (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hMeta, 0)) { + //strcat(dbg_msg, "\nrecursing for meta"); + return GetEncryptionStatus(hMeta); + } + return 0!=DBGetContactSettingByte(hContact, MODULENAME, "Encrypted", 0 ); + } + } + return 0; +} +*/ + +const TCHAR *policy_to_string(OtrlPolicy policy) { + switch (policy) { + case OTRL_POLICY_NEVER: + return TranslateT(LANG_POLICY_NEVER); + break; + case OTRL_POLICY_OPPORTUNISTIC: + return TranslateT(LANG_POLICY_OPP); + break; + case OTRL_POLICY_MANUAL: + case OTRL_POLICY_MANUAL_MOD: + return TranslateT(LANG_POLICY_MANUAL); + break; + case OTRL_POLICY_ALWAYS: + return TranslateT(LANG_POLICY_ALWAYS); + break; + } + return TranslateT(LANG_POLICY_DEFAULT); +} + +OtrlPolicy policy_from_string(const TCHAR *polstring) { + if (_tcscmp(polstring, TranslateT(LANG_POLICY_NEVER)) == 0) + return OTRL_POLICY_NEVER; + else if (_tcscmp(polstring, TranslateT(LANG_POLICY_OPP)) == 0) + return OTRL_POLICY_OPPORTUNISTIC; + else if (_tcscmp(polstring, TranslateT(LANG_POLICY_MANUAL)) == 0) + return OTRL_POLICY_MANUAL_MOD; + else if (_tcscmp(polstring, TranslateT(LANG_POLICY_ALWAYS)) == 0) + return OTRL_POLICY_ALWAYS; + else + return CONTACT_DEFAULT_POLICY; +} \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/src/utils.h b/plugins/MirOTR/MirOTR/src/utils.h new file mode 100644 index 0000000000..01c1b44f69 --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/utils.h @@ -0,0 +1,49 @@ +#pragma once +#ifndef __HEADER_UTILS_H +#define __HEADER_UTILS_H +#include "stdafx.h" + + +void lib_cs_lock(); +void lib_cs_unlock(); + +HANDLE find_contact(const char* userid, const char* protocol); +ConnContext * otrl_context_find_miranda(OtrlUserState us, HANDLE hContact); + +typedef enum { + TRUST_NOT_PRIVATE, + TRUST_FINISHED, + TRUST_UNVERIFIED, + TRUST_PRIVATE +} TrustLevel; +TrustLevel otr_context_get_trust(ConnContext *context); +void VerifyFingerprint(ConnContext *context, bool verify); +void VerifyFingerprintMessage(ConnContext *context, bool verify); + +void otrl_privkey_hash_to_humanT(TCHAR human[45], const unsigned char hash[20]); + +char* contact_get_id(HANDLE hContact, bool bNameOnError=true); +__inline const char* contact_get_proto(HANDLE hContact); +__inline const char* contact_get_account(HANDLE hContact); +extern __inline const TCHAR* contact_get_nameT(HANDLE hContact); + +void ShowPopup(const TCHAR* line1, const TCHAR* line2, int timeout, const HANDLE hContact = NULL); +void ShowWarning(TCHAR* msg); +void ShowError(TCHAR* msg); +void ShowPopupUtf(const char* line1, const char* line2, int timeout, const HANDLE hContact = NULL); +void ShowWarningUtf(char* msg); +void ShowErrorUtf(char* msg); + +void ShowMessageInline(const HANDLE hContact, const TCHAR *msg); +void ShowMessageInlineUtf(const HANDLE hContact, const char *msg); + +void ShowMessage(const HANDLE hContact, const TCHAR *msg); +void ShowMessageUtf(const HANDLE hContact, const char *msg); + +void InitUtils(); +void DeinitUtils(); + +const TCHAR *policy_to_string(OtrlPolicy policy); +OtrlPolicy policy_from_string(const TCHAR *polstring); + +#endif \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/src/version.h b/plugins/MirOTR/MirOTR/src/version.h new file mode 100644 index 0000000000..2bd9618de7 --- /dev/null +++ b/plugins/MirOTR/MirOTR/src/version.h @@ -0,0 +1,37 @@ +#ifndef OTR_PRIVATE_H +#define OTR_PRIVATE_H + +/* VERSION DEFINITIONS */ +#define VER_MAJOR 0 +#define VER_MINOR 11 +#define VER_RELEASE 0 +#define VER_BUILD 4 + +#define __STRINGIZE(x) #x +#define VER_STRING "0.11.0.4" + +#ifdef _UNICODE + #define SHORT_NAME_STRING "Miranda OTR" + #define DESC_STRING "OTR (Off-the-Record) plugin for Miranda NG" +#else + #define SHORT_NAME_STRING "Miranda OTR (x64)" + #define DESC_STRING "OTR (Off-the-Record) plugin for Miranda NG (64Bit)" +#endif +#define LONGDESC_STRING DESC_STRING "\r\n(using some code and ideas from SecureIM, Pidgin-OTR and old Miranda OTR (by SJE))." +#define COMPANY_NAME "" +#define FILE_VERSION VER_STRING +#define FILE_DESCRIPTION DESC_STRING +#define INTERNAL_NAME "" +#define LEGAL_COPYRIGHT "© ProgAndy & CHEF-KOCH" +#define LEGAL_COPYRIGHT_LONG "© ProgAndy & CHEF-KOCH" +#define LEGAL_TRADEMARKS "" +#define ORIGINAL_FILENAME "mirotr.dll" +#define PRODUCT_NAME DESC_STRING +#define PRODUCT_VERSION VER_STRING + + +#define AUTHOR "ProgAndy & CHEF-KOCH" +#define AUTHOR_MAIL "" +#define HOMEPAGE "http://miranda-ng.org/" + +#endif /*OTR_PRIVATE_H*/ diff --git a/plugins/MirOTR/MirOTR/stdafx.cpp b/plugins/MirOTR/MirOTR/stdafx.cpp deleted file mode 100644 index 98540cbccf..0000000000 --- a/plugins/MirOTR/MirOTR/stdafx.cpp +++ /dev/null @@ -1,8 +0,0 @@ -// stdafx.cpp : Quelldatei, die nur die Standard-Includes einbindet. -// MirOTR.pch ist der vorkompilierte Header. -// stdafx.obj enthält die vorkompilierten Typinformationen. - -#include "stdafx.h" - -// TODO: Auf zusätzliche Header verweisen, die in STDAFX.H -// und nicht in dieser Datei erforderlich sind. diff --git a/plugins/MirOTR/MirOTR/stdafx.h b/plugins/MirOTR/MirOTR/stdafx.h deleted file mode 100644 index ec471e83bd..0000000000 --- a/plugins/MirOTR/MirOTR/stdafx.h +++ /dev/null @@ -1,87 +0,0 @@ -// stdafx.h : Includedatei für Standardsystem-Includedateien -// oder häufig verwendete projektspezifische Includedateien, -// die nur in unregelmäßigen Abständen geändert werden. -// - -#pragma once - -#include "targetver.h" - -#define _CRT_NON_CONFORMING_SWPRINTFS -#define WIN32_LEAN_AND_MEAN // Selten verwendete Teile der Windows-Header nicht einbinden. - -// Windows-Headerdateien: -#include -#include -#include - -#ifdef _DEBUG - #define DEBUGOUTA(x) OutputDebugStringA(x); - #define DEBUGOUT(x) OutputDebugString(x); - #define DEBUGOUT_T(x) OutputDebugString(__T(x)); -#else - #define DEBUGOUTA(x); - #define DEBUGOUT(x) - #define DEBUGOUT_T(x) -#endif -#define MIRANDA_VER 0x0900 -#define MIRANDA_CUSTOM_LP - -//include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//ExternalAPI -#include -#include -#include - -#include -extern "C" { - #include - #include - #include - #include - #include -} - -#include "dllmain.h" -#include "language.h" -#include "options.h" -#include "utils.h" -#include "svcs_menu.h" -#include "svcs_proto.h" -#include "svcs_srmm.h" -#include "resource.h" -#include "otr.h" -#include "icons.h" -#include "dialogs.h" - -// modified manual policy - so that users set to 'opportunistic' will automatically start OTR with users set to 'manual' -#define OTRL_POLICY_MANUAL_MOD (OTRL_POLICY_MANUAL | OTRL_POLICY_WHITESPACE_START_AKE | OTRL_POLICY_ERROR_START_AKE) - -// {12D8FAAD-78AB-4e3c-9854-320E9EA5CC9F} -static const MUUID MIID_OTRPLUGIN = { 0x12d8faad, 0x78ab, 0x4e3c, { 0x98, 0x54, 0x32, 0xe, 0x9e, 0xa5, 0xcc, 0x9f } }; - -#define MODULENAME "MirOTR" - -#define PREF_BYPASS_OTR 0x8000 -#define PREF_NO_HISTORY 0x10000 - -#define SIZEOF(X) (sizeof(X)/sizeof(X[0])) - -// TODO: Hier auf zusätzliche Header, die das Programm erfordert, verweisen. diff --git a/plugins/MirOTR/MirOTR/striphtml.cpp b/plugins/MirOTR/MirOTR/striphtml.cpp deleted file mode 100644 index c76b0f7d80..0000000000 --- a/plugins/MirOTR/MirOTR/striphtml.cpp +++ /dev/null @@ -1,127 +0,0 @@ -#include "stdafx.h" -#include "striphtml.h" -#include "ekhtml.h" -#include "entities.h" - -void starttag_cb (void *cbdata, ekhtml_string_t *tag, ekhtml_attr_t *attrs) { - STRIPHTML_DATA *data = (STRIPHTML_DATA *)cbdata; - switch (tag->len) { - case 1: - switch (*(tag->str)) { - case 'a': - case 'A': - { - ekhtml_attr_t *attr = attrs; - while (attr) { - if (_strnicmp(attr->name.str, "href", attr->name.len)==0) { - data->stack.push(strncpy((char*)mir_calloc(attr->val.len+1), attr->val.str, attr->val.len)); - break; - } - } - }break; - case 'i': - case 'I': - data->buffer.append(" *"); - break; - case 'b': - case 'B': - data->buffer.append(" _"); - break; - } - case 2: - if (toupper(tag->str[0]) == 'B' && toupper(tag->str[1]) == 'R') - data->buffer.append("\r\n"); - break; - case 3: - if (_strnicmp(tag->str, "img", 3) == 0) { - ekhtml_attr_t *attr = attrs; - data->buffer.append("IMAGE [ "); - while (attr) { - if (_strnicmp(attr->name.str, "src", attr->name.len)==0) { - data->buffer.append(attr->val.str, attr->val.len); - break; - } - } - data->buffer.append(" ] "); - } - break; - } -} - -void endtag_cb (void *cbdata, ekhtml_string_t *tag) { - STRIPHTML_DATA *data = (STRIPHTML_DATA *)cbdata; - switch (tag->len) { - case 1: - switch (*(tag->str)) { - case 'a': - case 'A': - if (data->stack.empty()) break; - data->buffer.append(" [ "); - data->buffer.append(data->stack.top()); - mir_free(data->stack.top()); - data->stack.pop(); - data->buffer.append(" ] "); - break; - case 'i': - case 'I': - data->buffer.append("* "); - break; - case 'b': - case 'B': - data->buffer.append("_ "); - break; - } - } - -} - -void data_cb (void *cbdata, ekhtml_string_t *text) { - STRIPHTML_DATA *data = (STRIPHTML_DATA *)cbdata; - if(text->len <= 0) - return; - char* s = (char*) mir_calloc(text->len+1); - decode_html_entities_utf8(s, text->str, text->len); - - if (!data->stack.empty()) { - char *top = data->stack.top(); - if (_stricmp(s, top)==0) { - mir_free(top); - data->stack.pop(); - } - } - - - data->buffer.append(s); - mir_free(s); -} - -char * striphtml(char *html) { - STRIPHTML_DATA data; - ekhtml_string_t ekstring; - - ekstring.len = strlen(html); - ekstring.str = html; - - data.buffer.clear(); - data.buffer.reserve(ekstring.len); - - ekhtml_parser_t *parser = ekhtml_parser_new(&data); - ekhtml_parser_datacb_set(parser, &data_cb); - ekhtml_parser_startcb_add(parser, NULL, &starttag_cb); - ekhtml_parser_endcb_add(parser, NULL, &endtag_cb); - - ekhtml_parser_feed(parser, &ekstring); - ekhtml_parser_flush(parser, 1); - - while (!data.stack.empty()) { - mir_free(data.stack.top()); - data.stack.pop(); - } - - ekhtml_parser_destroy(parser); - - char *s = mir_strdup(data.buffer.c_str()); - data.buffer.erase(); - return s; - //ekhtml_parser_create( -} diff --git a/plugins/MirOTR/MirOTR/striphtml.h b/plugins/MirOTR/MirOTR/striphtml.h deleted file mode 100644 index 7cffc41f22..0000000000 --- a/plugins/MirOTR/MirOTR/striphtml.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include "stack" -#include "string" - -struct STRIPHTML_DATA { - std::stack stack; - std::string buffer; -}; - -char * striphtml(char *html); \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/svcs_menu.cpp b/plugins/MirOTR/MirOTR/svcs_menu.cpp deleted file mode 100644 index 17c2d9a4b0..0000000000 --- a/plugins/MirOTR/MirOTR/svcs_menu.cpp +++ /dev/null @@ -1,211 +0,0 @@ -#include "stdafx.h" -#include "otr.h" - -HANDLE hMenuBuildEvent, hStopItem, hStartItem; - -//////////////////////////////// -///////// Menu Services //////// -/////////////////////////////// -int StartOTR(HANDLE hContact) { - - const char *proto = contact_get_proto(hContact); - if (!proto) return 1; // error - char *uname = contact_get_id(hContact); - if (!uname) return 1; // error - DWORD pol = DBGetContactSettingDword(hContact, MODULENAME, "Policy", CONTACT_DEFAULT_POLICY); - if(pol == CONTACT_DEFAULT_POLICY) pol = options.default_policy; - - lib_cs_lock(); - char *msg = otrl_proto_default_query_msg(MODULENAME, pol); - otr_gui_inject_message(hContact, proto, proto, uname, msg ? msg : "?OTRv2?"); - lib_cs_unlock(); - otrl_message_free(msg); - mir_free(uname); - return 0; -} -INT_PTR SVC_StartOTR(WPARAM wParam, LPARAM lParam) { - HANDLE hContact = (HANDLE)wParam, hSub; - if(options.bHaveMetaContacts && (hSub = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0)) != 0) { - hContact = hSub; - } - - if ( options.bHaveSecureIM && CallService("SecureIM/IsContactSecured", (WPARAM)hContact, 0) != 0 ) { - TCHAR msg[512]; - mir_sntprintf(msg, 512, TranslateT(LANG_OTR_SECUREIM_STARTED), contact_get_nameT(hContact)); - ShowError(msg); - return 0; - } - - TCHAR buff[512]; - mir_sntprintf(buff, 512, TranslateT(LANG_SESSION_REQUEST_OTR), contact_get_nameT(hContact)); - ShowMessage(hContact, buff); - - int res = StartOTR(hContact); - if (res) return res; - - return 0; -} -INT_PTR SVC_RefreshOTR(WPARAM wParam, LPARAM lParam) { - HANDLE hContact = (HANDLE)wParam, hSub; - if(options.bHaveMetaContacts && (hSub = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0)) != 0) { - hContact = hSub; - } - - if ( options.bHaveSecureIM && CallService("SecureIM/IsContactSecured", (WPARAM)hContact, 0) != 0 ) { - TCHAR msg[512]; - mir_sntprintf(msg, 512, TranslateT(LANG_OTR_SECUREIM_STARTED), contact_get_nameT(hContact)); - ShowError(msg); - return 0; - } - - TCHAR buff[512]; - mir_sntprintf(buff, 512, TranslateT(LANG_SESSION_TRY_CONTINUE_OTR), contact_get_nameT(hContact)); - ShowMessage(hContact, buff); - - int res = StartOTR(hContact); - if (res) return res; - - return 0; -} -int otr_disconnect_contact(HANDLE hContact) { - HANDLE hSub; - if(ServiceExists(MS_MC_GETMOSTONLINECONTACT) && (hSub = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0)) != 0) { - hContact = hSub; - } - - const char *proto = contact_get_proto(hContact); - if (!proto) return 1; // error - char *uname = contact_get_id(hContact); - if (!uname) return 1; // error - - lib_cs_lock(); - otrl_message_disconnect(otr_user_state, &ops, hContact, proto, proto, uname); - lib_cs_unlock(); - mir_free(uname); - return 0; -} - -INT_PTR SVC_StopOTR(WPARAM wParam, LPARAM lParam) { - HANDLE hContact = (HANDLE)wParam; - - // prevent this filter from acting on injeceted messages for metas, when they are passed though the subcontact's proto send chain - if (otr_disconnect_contact(hContact)) return 0; - - SetEncryptionStatus(hContact, TRUST_NOT_PRIVATE); - - TCHAR buff[512]; - mir_sntprintf(buff, 512, TranslateT(LANG_SESSION_TERMINATED_OTR), contact_get_nameT(hContact)); - ShowMessage(hContact, buff); - - return 0; -} - -INT_PTR SVC_VerifyOTR(WPARAM wParam, LPARAM lParam) { - HANDLE hContact = (HANDLE)wParam, hSub; - if(options.bHaveMetaContacts && (hSub = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0)) != 0) { - hContact = hSub; - } - ConnContext *context = otrl_context_find_miranda(otr_user_state, (HANDLE)wParam); - if (!context) return 1; - //VerifyContextDialog(context); - SMPInitDialog(context); - return 0; -} - -INT_PTR SVC_ToggleHTMLOTR(WPARAM wParam, LPARAM lParam) { - HANDLE hContact = (HANDLE)wParam; - if (db_get_b(hContact, MODULENAME, "HTMLConv", 0)) - db_set_b(hContact, MODULENAME, "HTMLConv", 0); - else - db_set_b(hContact, MODULENAME, "HTMLConv", 1); - - return 0; -} - -void InitMenu() { - CreateServiceFunction(MS_OTR_MENUSTART, SVC_StartOTR); - CreateServiceFunction(MS_OTR_MENUSTOP, SVC_StopOTR); - CreateServiceFunction(MS_OTR_MENUREFRESH, SVC_RefreshOTR); - CreateServiceFunction(MS_OTR_MENUVERIFY, SVC_VerifyOTR); - CreateServiceFunction(MS_OTR_MENUTOGGLEHTML, SVC_ToggleHTMLOTR); - - CLISTMENUITEM mi = {0}; - mi.cbSize = sizeof(mi); - mi.flags = CMIF_NOTOFFLINE | CMIF_TCHAR | CMIF_ICONFROMICOLIB; - mi.position = -400000; - - mi.ptszName = _T(LANG_STOP_OTR); - mi.pszService = MS_OTR_MENUSTOP; - mi.icolibItem = GetIconHandle(ICON_PRIVATE); - - hStopItem = Menu_AddContactMenuItem(&mi); - - mi.ptszName = _T(LANG_START_OTR); - mi.pszService = MS_OTR_MENUSTART; - mi.icolibItem = GetIconHandle(ICON_NOT_PRIVATE); - - hStartItem = Menu_AddContactMenuItem(&mi); - - hMenuBuildEvent = HookEvent(ME_CLIST_PREBUILDCONTACTMENU, SVC_PrebuildContactMenu); - -} - -void DeinitMenu() { - UnhookEvent(hMenuBuildEvent); -} - -int SVC_PrebuildContactMenu(WPARAM wParam, LPARAM lParam) { - HANDLE hContact = (HANDLE)wParam; - - CLISTMENUITEM mi = {0}; - mi.cbSize = sizeof(mi); - mi.flags = CMIM_FLAGS | CMIF_NOTOFFLINE | CMIF_TCHAR | CMIF_ICONFROMICOLIB; - - const char *proto = contact_get_proto(hContact); - DWORD pol = CONTACT_DEFAULT_POLICY; - - if (!proto || DBGetContactSettingByte(hContact, proto, "ChatRoom", 0) == 1) { - goto hide_all; - } - - if(proto && g_metaproto && strcmp(proto, g_metaproto) == 0) { - // make menu act as per most online subcontact - hContact = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0); - if (!hContact) - goto hide_all; - proto = contact_get_proto(hContact); - } - - pol = DBGetContactSettingDword(hContact, MODULENAME, "Policy", CONTACT_DEFAULT_POLICY); - if(pol == CONTACT_DEFAULT_POLICY) pol = options.default_policy; - - if(pol == OTRL_POLICY_NEVER || pol == OTRL_POLICY_ALWAYS) { - goto hide_all; - } - - { - ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact); - TrustLevel encrypted = otr_context_get_trust(context); - if(encrypted != TRUST_NOT_PRIVATE) { - CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hStopItem, (LPARAM)&mi); - mi.flags |= CMIF_HIDDEN; - CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hStartItem, (LPARAM)&mi); - } else { - //if(pol == OTRL_POLICY_MANUAL_MOD) { - CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hStartItem, (LPARAM)&mi); - mi.flags |= CMIF_HIDDEN; - CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hStopItem, (LPARAM)&mi); - //} else { // should only be 'opportunistic' - // goto hide_all; - //} - } - } - - return 0; - -hide_all: - mi.flags |= CMIF_HIDDEN; - CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hStopItem, (LPARAM)&mi); - CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hStartItem, (LPARAM)&mi); - return 0; -} \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/svcs_menu.h b/plugins/MirOTR/MirOTR/svcs_menu.h deleted file mode 100644 index 7dfc11a9ea..0000000000 --- a/plugins/MirOTR/MirOTR/svcs_menu.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -INT_PTR SVC_StartOTR(WPARAM wParam, LPARAM lParam); -INT_PTR SVC_RefreshOTR(WPARAM wParam, LPARAM lParam); -INT_PTR SVC_StopOTR(WPARAM wParam, LPARAM lParam); -INT_PTR SVC_VerifyOTR(WPARAM wParam, LPARAM lParam); -int SVC_PrebuildContactMenu(WPARAM wParam, LPARAM lParam); -void InitMenu(); -void DeinitMenu(); - -#define MS_OTR_MENUSTART MODULENAME"/Start" -#define MS_OTR_MENUSTOP MODULENAME"/Stop" -#define MS_OTR_MENUREFRESH MODULENAME"/Refresh" -#define MS_OTR_MENUVERIFY MODULENAME"/Verify" -#define MS_OTR_MENUTOGGLEHTML MODULENAME"/ToggleHTML" \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/svcs_proto.cpp b/plugins/MirOTR/MirOTR/svcs_proto.cpp deleted file mode 100644 index 618034cc10..0000000000 --- a/plugins/MirOTR/MirOTR/svcs_proto.cpp +++ /dev/null @@ -1,406 +0,0 @@ -#include "stdafx.h" -#include "svcs_proto.h" -#include "striphtml.h" -#include "entities.h" -#include -#include -#include -#include - -//TODO: Social-Millionaire-Dialoge -INT_PTR SVC_OTRSendMessage(WPARAM wParam,LPARAM lParam){ - if (!lParam) return 0; - - CCSDATA *ccs = (CCSDATA *) lParam; - - DEBUGOUT_T("SENDING") - - if (ccs->wParam & PREF_BYPASS_OTR) // bypass for OTR-messages - return CallService(MS_PROTO_CHAINSEND, wParam, lParam); - - char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)ccs->hContact, 0); - if(proto && g_metaproto && strcmp(proto, g_metaproto) == 0) // bypass for metacontacts - return CallService(MS_PROTO_CHAINSEND, wParam, lParam); - if (!proto || !ccs->hContact) return 1; // error - - gcry_error_t err; - char *newmessage = 0; - char *oldmessage = (char *)ccs->lParam; - char *oldmessage_utf = 0; - - //MessageBox(0, "Send message - converting to UTF-8", "msg", MB_OK); - - if(ccs->wParam & PREF_UTF) { - oldmessage_utf = oldmessage; - } else if(ccs->wParam & PREF_UNICODE) { - //TODO: check if this is correct or oldmessage[strlen(oldmessage)+1] is needed - //oldmessage_utf = mir_utf8encodeW((wchar_t*)oldmessage); - //should be the thing with strlen - oldmessage_utf = mir_utf8encodeW((wchar_t*)&oldmessage[strlen(oldmessage)+1]); - } else { - oldmessage_utf = mir_utf8encode(oldmessage); - } - if (!oldmessage_utf) return 1; - - // don't filter OTR messages being sent (OTR messages should only happen *after* the otrl_message_sending call below) - if(strncmp(oldmessage_utf, "?OTR", 4) == 0) { - DEBUGOUT_T("OTR message without PREF_BYPASS_OTR") - if (!(ccs->wParam & PREF_UTF)) mir_free(oldmessage_utf); - return CallService(MS_PROTO_CHAINSEND, wParam, lParam); - } - - char *tmpencode = NULL; - ConnContext *context = otrl_context_find_miranda(otr_user_state, (void*)ccs->hContact); - if (db_get_b(ccs->hContact, MODULENAME, "HTMLConv", 0) && otr_context_get_trust(context) >= TRUST_UNVERIFIED) { - char *tmpencode = encode_html_entities_utf8(oldmessage_utf); - if (tmpencode != NULL) { - if (!(ccs->wParam & PREF_UTF)) mir_free(oldmessage_utf); - oldmessage_utf = tmpencode; - } - } - - char *username = contact_get_id(ccs->hContact); - err = otrl_message_sending(otr_user_state, &ops, (void*)ccs->hContact, - proto, proto, username, oldmessage_utf, NULL, &newmessage, - add_appdata, (void*)ccs->hContact); - if (tmpencode!= NULL || !(ccs->wParam & PREF_UTF)) mir_free(oldmessage_utf); - oldmessage_utf = NULL; - mir_free(username); - - if (err && newmessage == NULL) { - /* Be *sure* not to send out plaintext */ - ShowError(TranslateT(LANG_ENCRYPTION_ERROR)); - /* should not be needed - char t[3] = {0, 0, 0}; - if(ccs->wParam & PREF_UNICODE) { //TODO!! lstrlen(pre->szMessage)+1 ?? - if (strlen(oldmessage)) memcpy(oldmessage, t,3 ); - } else { - if (strlen(oldmessage)) memcpy(oldmessage, t, 1); - } - */ - return 1; - } else if (newmessage) { - /* Fragment the message if necessary, and send all but the last - * fragment over the network. We will send the last segment later */ - - // oldmessage_utf is not used anymore, so use it as buffer - err = otrl_message_fragment_and_send(&ops, (void*)ccs->hContact, context, - newmessage, OTRL_FRAGMENT_SEND_ALL_BUT_LAST, &oldmessage_utf); - // newmessage is not needed anymore - otrl_message_free(newmessage); - // move the last fragment to newmessage, oldmessage_utf will be buffer later - newmessage = oldmessage_utf; - - WPARAM oldflags = ccs->wParam; - if(ccs->wParam & PREF_UTF) { - ccs->lParam = (LPARAM)newmessage; - } else if(ccs->wParam & PREF_UNICODE) { - // just send UTF, hope that proto supports it. - // don't want to create the Unicode-Format - // oldmessage_utf = (char*)mir_utf8decodeW(newmessage); - ccs->lParam = (LPARAM)newmessage; - ccs->wParam &= ~PREF_UNICODE; - ccs->wParam |= PREF_UTF; - } else { - mir_utf8decode(newmessage, NULL); - ccs->lParam = (LPARAM)newmessage; - } - if (otr_context_get_trust(context) >= TRUST_UNVERIFIED) ccs->wParam; - INT_PTR ret = CallService(MS_PROTO_CHAINSEND, wParam, lParam); - -#ifdef _DEBUG - if(ccs->wParam & PREF_UNICODE) - { - TCHAR *mes = mir_a2t((const char *)ccs->lParam); - MessageBox(0, mes, _T("OTR - sending raw message"), MB_OK); - mir_free(mes); - } - else - MessageBoxA(0, (char *)ccs->lParam, ("OTR - sending raw message"), MB_OK); - #endif - - // reset to original values - - ccs->lParam = (LPARAM)oldmessage; - ccs->wParam = oldflags; - otrl_message_free(newmessage); - return ret; - - } - - return CallService(MS_PROTO_CHAINSEND, wParam, lParam); -} - -INT_PTR SVC_OTRSendMessageW(WPARAM wParam, LPARAM lParam){ - if (!lParam) return 0; - - CCSDATA *ccs = (CCSDATA *) lParam; - if (!(ccs->wParam & PREF_UTF)) ccs->wParam |= PREF_UNICODE; - - return SVC_OTRSendMessage(wParam, lParam); -} - -/* -#define MESSAGE_PREFIX "(OTR) " -#define MESSAGE_PREFIXW L"(OTR) " -#define MESSAGE_PREFIX_LEN 6 -*/ - -INT_PTR SVC_OTRRecvMessage(WPARAM wParam,LPARAM lParam){ - //PUShowMessage("OTR Recv Message", SM_NOTIFY); - CCSDATA *ccs = (CCSDATA *) lParam; - PROTORECVEVENT *pre = (PROTORECVEVENT *) ccs->lParam; - -#ifdef _DEBUG - if(pre->flags & PREF_UNICODE) - { - TCHAR *mes = mir_a2t(pre->szMessage); - MessageBox(0, mes, _T("OTR - receiving message"), MB_OK); - mir_free(mes); - } - else - MessageBoxA(0, (char *)pre->szMessage, ("OTR - receiving message"), MB_OK); -#endif - - if (pre->flags & PREF_BYPASS_OTR) { // bypass for our inline messages - return CallService(MS_PROTO_CHAINRECV, wParam, lParam); - } - - char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)ccs->hContact, 0); - if (!proto) - return 1; //error - else if(proto && g_metaproto && strcmp(proto, g_metaproto) == 0) // bypass for metacontacts - return CallService(MS_PROTO_CHAINRECV, wParam, lParam); - - if (!ccs->hContact) return 1; //error - - char *oldmessage = pre->szMessage; - char *oldmessage_utf = NULL; - // convert oldmessage to utf-8 - if(pre->flags & PREF_UTF) { - oldmessage_utf = oldmessage; - } else if(pre->flags & PREF_UNICODE) { //UNSURE!! - oldmessage_utf = mir_utf8encodeW((wchar_t*)(&oldmessage[strlen(oldmessage)+1])); - } else { - oldmessage_utf = mir_utf8encode(oldmessage); - } - if (!oldmessage_utf) return 1; - - - char *newmessage = NULL; - OtrlTLV *tlvs = NULL; - OtrlTLV *tlv = NULL; - BOOL ignore_msg; - ConnContext *context; - //NextExpectedSMP nextMsg; - - char *uname = contact_get_id(ccs->hContact); - lib_cs_lock(); - ignore_msg = otrl_message_receiving(otr_user_state, &ops, (void*)ccs->hContact, - proto, proto, uname, oldmessage_utf, - &newmessage, &tlvs, add_appdata, (void*)ccs->hContact); - lib_cs_unlock(); - mir_free(uname); - - if ( !(pre->flags & PREF_UTF)) mir_free(oldmessage_utf); - oldmessage_utf = NULL; - - - tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED); - if (tlv && !Miranda_Terminated()) { - /* Notify the user that the other side disconnected. */ - TCHAR buff[256]; - mir_sntprintf(buff, 256, TranslateT(LANG_SESSION_TERMINATED_BY_OTR), contact_get_nameT(ccs->hContact)); - //MessageBox(0, buff, Translate("OTR Information"), MB_OK); - ShowMessage((HANDLE)ccs->hContact, buff); - - //if(options.timeout_finished) ResetFinishedTimer(); - } - - lib_cs_lock(); - context = otrl_context_find_miranda(otr_user_state, ccs->hContact); - lib_cs_unlock(); - /* Keep track of our current progress in the Socialist Millionaires' - * Protocol. */ - - /* - if (context && ( (context->smstate->sm_prog_state == OTRL_SMP_PROG_CHEATED) || - otrl_tlv_find(tlvs, OTRL_TLV_SMP1Q) || - otrl_tlv_find(tlvs, OTRL_TLV_SMP1) || - otrl_tlv_find(tlvs, OTRL_TLV_SMP2) || - otrl_tlv_find(tlvs, OTRL_TLV_SMP3) || - otrl_tlv_find(tlvs, OTRL_TLV_SMP4) ) - ) - { - otr_abort_smp(context); // we do not support it (yet), notify partner to shorten wait time - } - */ - - - if (context) { - NextExpectedSMP nextMsg = context->smstate->nextExpected; - - if (context->smstate->sm_prog_state == OTRL_SMP_PROG_CHEATED) { - otr_abort_smp(context); - //otrg_dialog_update_smp(context, 0.0); - SMPDialogUpdate(context, 0); - context->smstate->nextExpected = OTRL_SMP_EXPECT1; - context->smstate->sm_prog_state = OTRL_SMP_PROG_OK; - } else { - - tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1Q); - if (tlv) { - if (nextMsg != OTRL_SMP_EXPECT1) - otr_abort_smp(context); - else { - char *question = (char *)tlv->data; - char *eoq = (char*)memchr(question, '\0', tlv->len); - if (eoq) { - SMPDialogReply(context, question); - } - } - } - tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1); - if (tlv) { - if (nextMsg != OTRL_SMP_EXPECT1) - otr_abort_smp(context); - else { - SMPDialogReply(context, NULL); - } - } - tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP2); - if (tlv) { - if (nextMsg != OTRL_SMP_EXPECT2) - otr_abort_smp(context); - else { - context->smstate->nextExpected = OTRL_SMP_EXPECT4; - SMPDialogUpdate(context, 60); - } - } - tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP3); - if (tlv) { - if (nextMsg != OTRL_SMP_EXPECT3) - otr_abort_smp(context); - else { - context->smstate->nextExpected = OTRL_SMP_EXPECT1; - SMPDialogUpdate(context, 100); - //otrg_dialog_update_smp(context, 1.0); - } - } - tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP4); - if (tlv) { - if (nextMsg != OTRL_SMP_EXPECT4) - otr_abort_smp(context); - else { - SMPDialogUpdate(context, 100); - //otrg_dialog_update_smp(context, 1.0); - context->smstate->nextExpected = OTRL_SMP_EXPECT1; - } - } - tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP_ABORT); - if (tlv) { - SMPDialogUpdate(context, 0); - context->smstate->nextExpected = OTRL_SMP_EXPECT1; - } - } - } - otrl_tlv_free(tlvs); - - /* If we're supposed to ignore this incoming message (because it's a - * protocol message), set it to NULL, so that other plugins that - * catch receiving-im-msg don't return 0, and cause it to be - * displayed anyway. */ - if (ignore_msg) { - /* should not be required ;) - char t[3] = {0, 0, 0}; - char t[3] = {0, 0, 0}; - if(pre->flags & PREF_UNICODE) { //TODO!! lstrlen(pre->szMessage)+1 ?? - if (pre->szMessage && strlen(pre->szMessage)) memcpy(pre->szMessage, t,3 ); - } else { - if (pre->szMessage && strlen(pre->szMessage)) memcpy(pre->szMessage, t, 1); - } - */ - if (newmessage) otrl_message_free(newmessage); - return 1; - } else if (newmessage) { - //bool free=false; - DWORD flags = pre->flags; - /* if(pre->flags & PREF_UTF) { - oldmessage_utf = newmessage; - } else if(pre->flags & PREF_UNICODE) { //TODO!! lstrlen(pre->szMessage)+1 ?? - oldmessage_utf = (char*)mir_utf8decodeW(newmessage); - free = true; - } else { - mir_utf8decode(newmessage, NULL); - oldmessage_utf = newmessage; - } */ - - //pre->szMessage = oldmessage_utf; - pre->flags &= ~PREF_UNICODE; - pre->flags |= PREF_UTF; // just use UTF, so we do not have to recode the message - - bool is_miralloc = false; - if (context) { - TrustLevel level = otr_context_get_trust(context); - if (level >= TRUST_UNVERIFIED) { - char* premsg; - if (db_get_b(ccs->hContact, MODULENAME, "HTMLConv", 0)) { - premsg = striphtml(newmessage); - otrl_message_free(newmessage); - newmessage = premsg; - is_miralloc = true; - } - - if (options.prefix_messages) { - size_t len = (strlen(options.prefix)+strlen(newmessage)+1)*sizeof(char); - premsg = (char*)mir_alloc( len ); - memset(premsg, 0, len); - strcpy(premsg, options.prefix); - strcat(premsg, newmessage); - (is_miralloc) ? mir_free(newmessage) : otrl_message_free(newmessage); - newmessage = premsg; - is_miralloc = true; - } - } - } - pre->szMessage = newmessage; - BOOL ret = CallService(MS_PROTO_CHAINRECV, wParam, lParam); - pre->flags = flags; - pre->szMessage = oldmessage; - if (is_miralloc) - mir_free(newmessage); - else - otrl_message_free(newmessage); - - // if (free) mir_free(oldmessage_utf); - return ret; - } - return CallService(MS_PROTO_CHAINRECV, wParam, lParam); - -} - -/* Abort the SMP protocol. Used when malformed or unexpected messages - * are received. */ -void otr_abort_smp(ConnContext *context) -{ - otrl_message_abort_smp(otr_user_state, &ops, context->app_data, context); -} - -/* Start the Socialist Millionaires' Protocol over the current connection, - * using the given initial secret, and optionally a question to pass to - * the buddy. */ -void otr_start_smp(ConnContext *context, const char *question, - const unsigned char *secret, size_t secretlen) -{ - otrl_message_initiate_smp_q(otr_user_state, &ops, context->app_data, - context, question, secret, secretlen); -} - -/* Continue the Socialist Millionaires' Protocol over the current connection, - * using the given initial secret (ie finish step 2). */ -void otr_continue_smp(ConnContext *context, - const unsigned char *secret, size_t secretlen) -{ - otrl_message_respond_smp(otr_user_state, &ops, context->app_data, - context, secret, secretlen); -} \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/svcs_proto.h b/plugins/MirOTR/MirOTR/svcs_proto.h deleted file mode 100644 index fe0db53a4e..0000000000 --- a/plugins/MirOTR/MirOTR/svcs_proto.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -INT_PTR SVC_OTRSendMessage(WPARAM wParam,LPARAM lParam); -INT_PTR SVC_OTRSendMessageW(WPARAM wParam, LPARAM lParam); -INT_PTR SVC_OTRRecvMessage(WPARAM wParam,LPARAM lParam); - -void otr_abort_smp(ConnContext *context); - -void otr_start_smp(ConnContext *context, const char *question, - const unsigned char *secret, size_t secretlen); - -void otr_continue_smp(ConnContext *context, - const unsigned char *secret, size_t secretlen); \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/svcs_srmm.cpp b/plugins/MirOTR/MirOTR/svcs_srmm.cpp deleted file mode 100644 index 707eb0a020..0000000000 --- a/plugins/MirOTR/MirOTR/svcs_srmm.cpp +++ /dev/null @@ -1,292 +0,0 @@ -#include "stdafx.h" -#include "mirotrmenu.h" -HANDLE hEventIconPressed; -HICON hIconNotSecure, hIconFinished, hIconPrivate, hIconUnverified; -BBButton OTRButton; - -/* Plugin init and deinit */ -// int WindowEvent(WPARAM wParam, LPARAM lParam) { -// MessageWindowEventData *mwd = (MessageWindowEventData *)lParam; -// -// if(mwd->uType == MSG_WINDOW_EVT_CLOSE && options.end_window_close) { -// FinishSession(mwd->hContact); -// return 0; -// } -// -// if(mwd->uType != MSG_WINDOW_EVT_OPEN) return 0; -// if (!options.bHaveSRMMIcons) return 0; -// -// HANDLE hContact = mwd->hContact, hTemp; -// if(options.bHaveMetaContacts && (hTemp = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0)) != 0) -// hContact = hTemp; -// -// if (!CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)MODULENAME)) -// return 0; -// -// lib_cs_lock(); -// ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact); -// lib_cs_unlock(); -// -// SetEncryptionStatus(hContact, otr_context_get_trust(context)); -// -// return 0; -// } - -int SVC_IconPressed(WPARAM wParam, LPARAM lParam) { - HANDLE hContact = (HANDLE)wParam; - StatusIconClickData *sicd = (StatusIconClickData *)lParam; - if(sicd->cbSize < (int)sizeof(StatusIconClickData)) - return 0; - - if(strcmp(sicd->szModule, MODULENAME) == 0) { - char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); - if(proto && DBGetContactSettingByte(hContact, proto, "ChatRoom", 0)) - return 0; - ShowOTRMenu(hContact, sicd->clickLocation); - /* - HMENU hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_CONTEXT)); - CallService(MS_LANGPACK_TRANSLATEMENU, (WPARAM)hMenu, 0); - TrustLevel level = (TrustLevel) db_get_dw(hContact, MODULENAME, "TrustLevel", TRUST_NOT_PRIVATE); - MENUITEMINFO minfo = {0}; - minfo.cbSize = sizeof(MENUITEMINFO); - minfo.fMask = MIIM_STRING|MIIM_STATE|MIIM_BITMAP; - minfo.fState = MF_DISABLED; - - HWND wnd = GetFocus(); - HDC dc = GetDC(wnd), hdc = CreateCompatibleDC(dc); - HBITMAP bmpIconPrivate = CreateCompatibleBitmap(dc, 16, 16); - HGDIOBJ old = SelectObject(hdc, bmpIconPrivate); - DrawIconEx(hdc, 0, 0, hIconPrivate,16, 16, 0, GetSysColorBrush(COLOR_MENU), DI_NORMAL); - - HBITMAP bmpIconUnverified = CreateCompatibleBitmap(dc, 16, 16); - SelectObject(hdc, bmpIconUnverified); - DrawIconEx(hdc, 0, 0, hIconUnverified,16, 16, 0, GetSysColorBrush(COLOR_MENU), DI_NORMAL); - - HBITMAP bmpIconFinished = CreateCompatibleBitmap(dc, 16, 16); - SelectObject(hdc, bmpIconFinished); - DrawIconEx(hdc, 0, 0, hIconFinished,16, 16, 0, GetSysColorBrush(COLOR_MENU), DI_NORMAL); - - HBITMAP bmpIconNotSecure = CreateCompatibleBitmap(dc, 16, 16); - SelectObject(hdc, bmpIconNotSecure); - DrawIconEx(hdc, 0, 0, hIconNotSecure,16, 16, 0, GetSysColorBrush(COLOR_MENU), DI_NORMAL); - - switch (level) { - case TRUST_PRIVATE: - minfo.hbmpItem = bmpIconPrivate; - minfo.dwTypeData = TranslateT(LANG_STATUS_PRIVATE); - break; - case TRUST_UNVERIFIED: - minfo.hbmpItem = bmpIconUnverified; - minfo.dwTypeData = TranslateT(LANG_STATUS_UNVERIFIED); - break; - case TRUST_FINISHED: - minfo.hbmpItem = bmpIconFinished; - minfo.dwTypeData = TranslateT(LANG_STATUS_FINISHED); - break; - default: - minfo.hbmpItem = bmpIconNotSecure; - minfo.dwTypeData = TranslateT(LANG_STATUS_DISABLED); - } - - SelectObject(hdc, old); - DeleteDC(hdc); - ReleaseDC(wnd, dc); - - SetMenuItemInfo(hMenu, IDM_OTR_STATUS, FALSE, &minfo); - - minfo.fMask = MIIM_STATE|MIIM_BITMAP; - minfo.fState = (level==TRUST_NOT_PRIVATE)?MF_ENABLED:MF_GRAYED; - minfo.hbmpItem = bmpIconUnverified; - SetMenuItemInfo(hMenu, IDM_OTR_START, FALSE, &minfo); - - minfo.fState = (level==TRUST_NOT_PRIVATE)?MF_GRAYED:MF_ENABLED; - minfo.hbmpItem = bmpIconNotSecure; - SetMenuItemInfo(hMenu, IDM_OTR_STOP, FALSE, &minfo); - - minfo.fState = (level==TRUST_NOT_PRIVATE)?MF_GRAYED:MF_ENABLED; - minfo.hbmpItem = bmpIconFinished; - SetMenuItemInfo(hMenu, IDM_OTR_REFRESH, FALSE, &minfo); - - minfo.fState = (level==TRUST_NOT_PRIVATE||level==TRUST_FINISHED)?MF_GRAYED:MF_ENABLED; - minfo.hbmpItem = bmpIconPrivate; - SetMenuItemInfo(hMenu, IDM_OTR_VERIFY, FALSE, &minfo); - - switch ( (DWORD) TrackPopupMenu(GetSubMenu(hMenu, 0), TPM_NONOTIFY|TPM_RETURNCMD, sicd->clickLocation.x, sicd->clickLocation.y, 0, GetFocus(), 0) ) - { - case IDM_OTR_START: - SVC_StartOTR(wParam, 0); - break; - case IDM_OTR_REFRESH: - SVC_RefreshOTR(wParam, 0); - break; - case IDM_OTR_STOP: - SVC_StopOTR(wParam, 0); - break; - case IDM_OTR_VERIFY: - ConnContext *context = otrl_context_find_miranda(otr_user_state, (HANDLE)wParam); - if (context) VerifyContextDialog(context); - break; - } - DeleteObject(bmpIconPrivate); - DeleteObject(bmpIconFinished); - DeleteObject(bmpIconNotSecure); - DeleteObject(bmpIconUnverified); - */ - } - - return 0; -} - -// set SRMM icon status, if applicable -void SetEncryptionStatus(HANDLE hContact, TrustLevel level) { - //char dbg_msg[2048]; - //dbg_msg[0] = 0; - - //strcat(dbg_msg, "Set encyption status: "); - //strcat(dbg_msg, (encrypted ? "true" : "false")); - - char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); - bool chat_room = (proto && DBGetContactSettingByte(hContact, proto, "ChatRoom", 0)); - - // if (!chat_room) DBWriteContactSettingByte(hContact, MODULENAME, "Encrypted", (encrypted ? 1 : 0)); - - if(options.bHaveSRMMIcons || options.bHaveButtonsBar) { - //strcat(dbg_msg, "\nchanging icon"); - BBButton button = OTRButton; - StatusIconData sid = {0}, sid2={0}; - sid.cbSize = sizeof(sid); - sid.szModule = MODULENAME; - sid.dwId = 0; - sid.flags = MBF_HIDDEN; - - sid2.cbSize = sid.cbSize; - sid2.szModule = MODULENAME; - sid2.dwId = 1; - sid2.flags = MBF_HIDDEN; - if (!chat_room) { - switch (level) { - case TRUST_FINISHED: - sid.flags = 0; - button.ptszTooltip = TranslateT(LANG_STATUS_FINISHED); - button.hIcon = GetIconHandle(ICON_FINISHED); - break; - case TRUST_UNVERIFIED: - sid2.flags = MBF_DISABLED; - button.ptszTooltip = TranslateT(LANG_STATUS_UNVERIFIED); - button.hIcon = GetIconHandle(ICON_UNVERIFIED); - break; - case TRUST_PRIVATE: - sid2.flags = 0; - button.ptszTooltip = TranslateT(LANG_STATUS_PRIVATE); - button.hIcon = GetIconHandle(ICON_PRIVATE); - break; - default: - sid.flags = MBF_DISABLED; - button.ptszTooltip = TranslateT(LANG_STATUS_DISABLED); - button.hIcon = GetIconHandle(ICON_NOT_PRIVATE); - break; - } - button.bbbFlags = 0; - } else { - button.bbbFlags = BBSF_HIDDEN; - } - if (options.bHaveSRMMIcons) { - CallService(MS_MSG_MODIFYICON, (WPARAM)hContact, (LPARAM)&sid); - CallService(MS_MSG_MODIFYICON, (WPARAM)hContact, (LPARAM)&sid2); - } - if (options.bHaveButtonsBar) CallService(MS_BB_SETBUTTONSTATE, (WPARAM)hContact, (LPARAM)&button); - db_set_dw(hContact, MODULENAME, "TrustLevel", level); - - if (!chat_room && options.bHaveMetaContacts) { - HANDLE hMeta = (HANDLE)CallService(MS_MC_GETMETACONTACT, (WPARAM)hContact, 0); - HANDLE hMostOnline = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hMeta, 0); - if(hMeta && hContact == hMostOnline) { - //strcat(dbg_msg, "\nrecursing for meta"); - SetEncryptionStatus(hMeta, level); - } - else if(hMeta) { - /* in case the new most online contact has changed - (e.g. when the otr subcontact goes offline) */ - ConnContext *context = otrl_context_find_miranda(otr_user_state, hMostOnline); - TrustLevel encrypted = otr_context_get_trust(context); - SetEncryptionStatus(hMeta, encrypted); - } - } - } - //PUShowMessage(dbg_msg, SM_NOTIFY); -} - -int SVC_ButtonsBarLoaded(WPARAM, LPARAM) { - CallService(MS_BB_ADDBUTTON, 0, (LPARAM)&OTRButton); - return 0; -} -int SVC_ButtonsBarPressed(WPARAM w, LPARAM l) { - CustomButtonClickData* cbcd = (CustomButtonClickData *)l; - if (cbcd->cbSize == (int)sizeof(CustomButtonClickData) && cbcd->dwButtonId == 0 && strcmp(cbcd->pszModule, MODULENAME)==0) { - HANDLE hContact = (HANDLE)w; - - char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); - if(proto && DBGetContactSettingByte(hContact, proto, "ChatRoom", 0)) - return 0; - ShowOTRMenu(hContact, cbcd->pt); - - } - return 0; -} - -void InitSRMM() { - // add icon to srmm status icons - InitMirOTRMenu(); - if(options.bHaveSRMMIcons) { - hIconNotSecure = LoadIcon(ICON_NOT_PRIVATE, 0); - hIconFinished = LoadIcon(ICON_FINISHED, 0); - hIconPrivate = LoadIcon(ICON_PRIVATE, 0); - hIconUnverified = LoadIcon(ICON_UNVERIFIED, 0); - - StatusIconData sid = {0}; - sid.cbSize = sizeof(sid); - sid.szModule = MODULENAME; - sid.dwId = 0; - sid.hIcon = hIconFinished; - sid.hIconDisabled = hIconNotSecure; - sid.flags = MBF_DISABLED | MBF_HIDDEN; - sid.szTooltip = Translate(LANG_OTR_TOOLTIP); - CallService(MS_MSG_ADDICON, 0, (LPARAM)&sid); - - sid.dwId = 1; - sid.hIcon = hIconPrivate; - sid.hIconDisabled = hIconUnverified; - CallService(MS_MSG_ADDICON, 0, (LPARAM)&sid); - - // hook the window events so that we can can change the status of the icon - - hEventIconPressed = HookEvent(ME_MSG_ICONPRESSED, SVC_IconPressed); - } - if (options.bHaveButtonsBar) { - ZeroMemory(&OTRButton, sizeof(OTRButton)); - OTRButton.cbSize = sizeof(OTRButton); - OTRButton.dwButtonID = 0; - OTRButton.pszModuleName = MODULENAME; - OTRButton.dwDefPos = 200; -#ifdef _UNICODE - OTRButton.bbbFlags = BBBF_ISRSIDEBUTTON|BBBF_CANBEHIDDEN|BBBF_ISIMBUTTON; -#else - OTRButton.bbbFlags = BBBF_ISRSIDEBUTTON|BBBF_CANBEHIDDEN|BBBF_ISIMBUTTON|BBBF_ANSITOOLTIP; -#endif - OTRButton.ptszTooltip = TranslateT(LANG_OTR_TOOLTIP); - OTRButton.hIcon = GetIconHandle(ICON_NOT_PRIVATE); - HookEvent(ME_MSG_TOOLBARLOADED, SVC_ButtonsBarLoaded); - HookEvent(ME_MSG_BUTTONPRESSED, SVC_ButtonsBarPressed); - } -} -void DeinitSRMM() { - if(options.bHaveSRMMIcons) { - UnhookEvent(hEventIconPressed); - ReleaseIcon(ICON_NOT_PRIVATE, 0); - ReleaseIcon(ICON_FINISHED, 0); - ReleaseIcon(ICON_PRIVATE, 0); - ReleaseIcon(ICON_UNVERIFIED, 0); - hIconNotSecure = hIconFinished = hIconPrivate = hIconUnverified =0; - } - UninitMirOTRMenu(); -} \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/svcs_srmm.h b/plugins/MirOTR/MirOTR/svcs_srmm.h deleted file mode 100644 index 4bc204656d..0000000000 --- a/plugins/MirOTR/MirOTR/svcs_srmm.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -int WindowEvent(WPARAM wParam, LPARAM lParam); -int SVC_IconPressed(WPARAM wParam, LPARAM lParam); -void SetEncryptionStatus(HANDLE hContact, TrustLevel level); -void InitSRMM(); -void DeinitSRMM(); \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/targetver.h b/plugins/MirOTR/MirOTR/targetver.h deleted file mode 100644 index 4b435d653b..0000000000 --- a/plugins/MirOTR/MirOTR/targetver.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -// Die folgenden Makros definieren die mindestens erforderliche Plattform. Die mindestens erforderliche Plattform -// ist die früheste Windows-, Internet Explorer-Version usw., die über die erforderlichen Features zur Ausführung -// Ihrer Anwendung verfügt. Die Makros aktivieren alle Funktionen, die auf den Plattformversionen bis -// einschließlich der angegebenen Version verfügbar sind. - -// Ändern Sie folgende Definitionen für Plattformen, die älter als die unten angegebenen sind. -// Unter MSDN finden Sie die neuesten Informationen über die entsprechenden Werte für die unterschiedlichen Plattformen. - -#ifndef WINVER // Gibt an, dass Windows 2000 die mindestens erforderliche Plattform ist. -#define WINVER 0x0500 // Ändern Sie den entsprechenden Wert, um auf andere Versionen von Windows abzuzielen. -#endif - -#ifndef _WIN32_WINNT // Gibt an, dass Windows 2000 die mindestens erforderliche Plattform ist. -#define _WIN32_WINNT 0x0500 // Ändern Sie den entsprechenden Wert, um auf andere Versionen von Windows abzuzielen. -#endif - -#ifndef _WIN32_IE // Gibt an, dass Internet Explorer 7.0 die mindestens erforderliche Plattform ist. -#define _WIN32_IE 0x0700 // Ändern Sie den entsprechenden Wert, um auf andere Versionen von IE abzuzielen. -#endif diff --git a/plugins/MirOTR/MirOTR/utils.cpp b/plugins/MirOTR/MirOTR/utils.cpp deleted file mode 100644 index ce2bbc5b9a..0000000000 --- a/plugins/MirOTR/MirOTR/utils.cpp +++ /dev/null @@ -1,417 +0,0 @@ -#include "stdafx.h" -#include "utils.h" - -CRITICAL_SECTION lib_cs; - -void InitUtils() { - InitializeCriticalSection(&lib_cs); -} -void DeinitUtils() { - DeleteCriticalSection(&lib_cs); -} - -void lib_cs_lock() { - EnterCriticalSection(&lib_cs); -} - -void lib_cs_unlock() { - LeaveCriticalSection(&lib_cs); -} - -HANDLE find_contact(const char* userid, const char* protocol) { - HANDLE hContact = db_find_first(); - while ( hContact != NULL ) - { - const char *proto = contact_get_proto(hContact); - if(proto && strcmp(proto, protocol) == 0) { - char *name = contact_get_id(hContact); - if(name && strcmp(name, userid) == 0) { - mir_free(name); - return hContact; - } - mir_free(name); - } - hContact = db_find_next(hContact); - } - - return 0; -} - -/* Look up a connection context by hContact from the given -* OtrlUserState. If add_if_missing is true, allocate and return a new -* context if one does not currently exist. In that event, call -* add_app_data(data, context) so that app_data and app_data_free can be -* filled in by the application, and set *addedp to 1. */ -ConnContext * otrl_context_find_miranda(OtrlUserState us, HANDLE hContact) -{ - ConnContext ** curp; - if (!hContact) return NULL; - for (curp = &(us->context_root); *curp; curp = &((*curp)->next)) { - if ((*curp)->app_data == hContact ) return *curp; - } - return NULL; -} - -/* What level of trust do we have in the privacy of this ConnContext? */ -TrustLevel otr_context_get_trust(ConnContext *context) -{ - TrustLevel level = TRUST_NOT_PRIVATE; - - if (context && context->msgstate == OTRL_MSGSTATE_ENCRYPTED) { - if (context->active_fingerprint->trust && - context->active_fingerprint->trust[0] != '\0') { - level = TRUST_PRIVATE; - } else { - level = TRUST_UNVERIFIED; - } - } else if (context && context->msgstate == OTRL_MSGSTATE_FINISHED) { - level = TRUST_FINISHED; - } - - return level; -} - -/* Set verification of fingerprint */ -void VerifyFingerprint(ConnContext *context, bool verify) { - lib_cs_lock(); - otrl_context_set_trust(context->active_fingerprint, (verify)?"verified":NULL); - otrl_privkey_write_fingerprints(otr_user_state, g_fingerprint_store_filename); - lib_cs_unlock(); - VerifyFingerprintMessage(context, verify); -} - -void VerifyFingerprintMessage(ConnContext *context, bool verify) { - TCHAR msg[1024]; - mir_sntprintf(msg, 1024, (verify)?TranslateT(LANG_FINGERPRINT_VERIFIED):TranslateT(LANG_FINGERPRINT_NOT_VERIFIED), contact_get_nameT((HANDLE)context->app_data)); - msg[1023] = '\0'; - ShowMessage((HANDLE)context->app_data, msg); - SetEncryptionStatus(context->app_data, otr_context_get_trust(context)); -} - -/* Convert a 20-byte hash value to a 45-byte human-readable value */ -void otrl_privkey_hash_to_humanT(TCHAR human[45], const unsigned char hash[20]) -{ - int word, byte; - TCHAR *p = human; - - for(word=0; word<5; ++word) { - for(byte=0; byte<4; ++byte) { - _stprintf(p, _T("%02X"), hash[word*4+byte]); - p += 2; - } - *(p++) = ' '; - } - /* Change that last ' ' to a '\0' */ - --p; - *p = '\0'; -} - -char* contact_get_id(HANDLE hContact, bool bNameOnError) { - char* pszUniqueID = NULL; - CONTACTINFO ci; - ZeroMemory(&ci, sizeof(ci)); - ci.cbSize = sizeof(ci); - ci.hContact = hContact; - ci.dwFlag = CNF_UNIQUEID; - - if (CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci) == 0) - { - if (ci.type == CNFT_ASCIIZ) { - pszUniqueID = (char*)ci.pszVal; // MS_CONTACT_GETCONTACTINFO uses mir_alloc - } else if (ci.type == CNFT_DWORD) { - pszUniqueID = (char*)mir_alloc(15); - if (pszUniqueID) - mir_snprintf(pszUniqueID, 15, ("%u"), ci.dVal); - } else if (ci.type == CNFT_WORD) { - pszUniqueID = (char*)mir_alloc(15); - if (pszUniqueID) - mir_snprintf(pszUniqueID, 15, ("%u"), ci.wVal); - } else if (ci.type == CNFT_BYTE) { - pszUniqueID = (char*)mir_alloc(15); - if (pszUniqueID) - mir_snprintf(pszUniqueID, 15, ("%u"), ci.bVal); - } - } - if (!pszUniqueID && bNameOnError) { - char *name = (char *)CallService( MS_CLIST_GETCONTACTDISPLAYNAME, ( WPARAM )hContact, 0 ); - if (name) pszUniqueID = mir_strdup(name); - } - return pszUniqueID; -} - -__inline const TCHAR* contact_get_nameT(HANDLE hContact) { - return (TCHAR*)CallService( MS_CLIST_GETCONTACTDISPLAYNAME, ( WPARAM )hContact, GCDNF_TCHAR ); -} - -__inline const char* contact_get_proto(HANDLE hContact) { - char *uproto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); - return uproto; -} - -__inline const char* contact_get_account(HANDLE hContact) { - char *uacc = (char *)CallService(MS_PROTO_GETCONTACTBASEACCOUNT, (WPARAM)hContact, 0); - return uacc; -} - -void ShowPopup(const TCHAR* line1, const TCHAR* line2, int timeout, const HANDLE hContact) { - if(CallService(MS_SYSTEM_TERMINATED, 0, 0)) return; - - if ( !options.bHavePopups) { - TCHAR title[256]; - _stprintf(title, _T("%s Message"), _T(MODULENAME)); - - if(line1 && line2) { - TCHAR *message = new TCHAR[_tcslen(line1) + _tcslen(line2) + 3]; // newline and null terminator - _stprintf(message, _T("%s\r\n%s"), line1, line2); - MessageBox( NULL, message, title, MB_OK | MB_ICONINFORMATION ); - delete message; - } else if(line1) { - MessageBox( NULL, line1, title, MB_OK | MB_ICONINFORMATION ); - } else if(line2) { - MessageBox( NULL, line2, title, MB_OK | MB_ICONINFORMATION ); - } - return; - } - - POPUPDATAT ppd = {0}; - //memset((void *)&ppd, 0, sizeof(POPUPDATAT)); - - ppd.lchContact = hContact; - ppd.lchIcon = NULL; - - if(line1 && line2) { - _tcsncpy( ppd.lptzContactName, line1, MAX_CONTACTNAME-1 ); - _tcsncpy( ppd.lptzText, line2, MAX_SECONDLINE-1 ); - } else if(line1) { - if (PUIsSecondLineShown()) _tcsncpy( ppd.lptzText, line1, MAX_SECONDLINE-1 ); - else _tcsncpy( ppd.lptzContactName, line1, MAX_CONTACTNAME-1 ); - } - else if(line2) { - if (PUIsSecondLineShown()) _tcsncpy( ppd.lptzText, line2, MAX_SECONDLINE-1 ); - else _tcsncpy( ppd.lptzContactName, line2, MAX_CONTACTNAME-1 ); - } - - ppd.iSeconds = timeout; - - ppd.PluginWindowProc = NULL; - ppd.PluginData = NULL; - - PUAddPopUpT(&ppd); - -} - -void ShowWarning(TCHAR *msg) { - TCHAR buffer[512]; - ErrorDisplay disp = options.err_method; - // funny logic :) ... try to avoid message boxes - // if want baloons but no balloons, try popups - // if want popups but no popups, try baloons - // if, after that, you want balloons but no balloons, revert to message boxes - if(disp == ED_BAL && !ServiceExists(MS_CLIST_SYSTRAY_NOTIFY)) disp = ED_POP; - if(disp == ED_POP && !options.bHavePopups) disp = ED_BAL; - if(disp == ED_BAL && !ServiceExists(MS_CLIST_SYSTRAY_NOTIFY)) disp = ED_MB; - - _stprintf(buffer, _T("%s Warning"), _T(MODULENAME)); - - TCHAR *message; - switch(disp) { - case ED_POP: - message = new TCHAR[_tcslen(msg) + 515]; // newline and null terminator - _stprintf(message, _T("%s\r\n%s"), buffer, msg); - PUShowMessageT(message, SM_WARNING); - delete message; - break; - case ED_MB: - MessageBox(0, msg, buffer, MB_OK | MB_ICONWARNING); - break; - case ED_BAL: - { - MIRANDASYSTRAYNOTIFY sn = {0}; - sn.cbSize = sizeof(sn); - sn.szProto= MODULENAME; - sn.tszInfoTitle = buffer; - sn.tszInfo = msg; -#ifdef _UNICODE - sn.dwInfoFlags = NIIF_WARNING | NIIF_INTERN_UNICODE; -#else - sn.dwInfoFlags = NIIF_WARNING; -#endif - sn.uTimeout = 10; - - CallService(MS_CLIST_SYSTRAY_NOTIFY, 0, (LPARAM)&sn); - } - - break; - } -} - -void ShowError(TCHAR *msg) { - TCHAR buffer[512]; - ErrorDisplay disp = options.err_method; - // funny logic :) ... try to avoid message boxes - // if want baloons but no balloons, try popups - // if want popups but no popups, try baloons - // if, after that, you want balloons but no balloons, revert to message boxes - if(disp == ED_BAL && !ServiceExists(MS_CLIST_SYSTRAY_NOTIFY)) disp = ED_POP; - if(disp == ED_POP && !options.bHavePopups) disp = ED_BAL; - if(disp == ED_BAL && !ServiceExists(MS_CLIST_SYSTRAY_NOTIFY)) disp = ED_MB; - - _stprintf(buffer, _T("%s Error"), _T(MODULENAME)); - - - TCHAR *message; - switch(disp) { - case ED_POP: - message = new TCHAR[_tcslen(msg) + 515]; // newline and null terminator - _stprintf(message, _T("%s\r\n%s"), buffer, msg); - PUShowMessageT(message, SM_WARNING); - delete message; - break; - case ED_MB: - MessageBox(0, msg, buffer, MB_OK | MB_ICONERROR); - break; - case ED_BAL: - { - MIRANDASYSTRAYNOTIFY sn = {0}; - sn.cbSize = sizeof(sn); - sn.szProto = MODULENAME; - sn.tszInfoTitle = buffer; - sn.tszInfo = msg; -#ifdef _UNICODE - sn.dwInfoFlags = NIIF_ERROR | NIIF_INTERN_UNICODE; -#else - sn.dwInfoFlags = NIIF_ERROR; -#endif - sn.uTimeout = 10; - - CallService(MS_CLIST_SYSTRAY_NOTIFY, 0, (LPARAM)&sn); - } - - break; - } -} - - -void ShowPopupUtf(const char* line1, const char* line2, int timeout, const HANDLE hContact) { - TCHAR* l1 = (line1) ? mir_utf8decodeT(line1) : NULL; - TCHAR* l2 = (line2) ? mir_utf8decodeT(line2) : NULL; - ShowPopup(l1, l2, timeout, hContact); - if (l1) mir_free(l1); - if (l2) mir_free(l2); -} - -void ShowWarningUtf(char* msg) { - TCHAR* m = (msg) ? mir_utf8decodeT(msg) : NULL; - ShowWarning(m); - if (m) mir_free(m); -} -void ShowErrorUtf(char* msg) { - TCHAR* m = (msg) ? mir_utf8decodeT(msg) : NULL; - ShowError(m); - if (m) mir_free(m); -} - -void ShowMessageInline(const HANDLE hContact, const TCHAR *msg) { - TCHAR buff[1024]; - mir_sntprintf(buff, 1024, _T("%s%s"), TranslateT(LANG_INLINE_PREFIX), msg); - - PROTORECVEVENT pre = {0}; - pre.timestamp = time(0); - char *utf = mir_utf8encodeT(buff); - pre.szMessage = utf; - pre.flags = PREF_UTF|PREF_BYPASS_OTR; - //CallContactService(hContact, PSR_MESSAGE, 0, (LPARAM)&pre); - - CCSDATA ccs = {0}; - ccs.hContact = hContact; - ccs.szProtoService = PSR_MESSAGE; - ccs.lParam = (LPARAM)⪯ - - CallService(MS_PROTO_CHAINRECV, 0, (LPARAM)&ccs); - mir_free(utf); -} - -void ShowMessageInlineUtf(const HANDLE hContact, const char *msg) { - char buff[1024]; - mir_snprintf(buff, 1024, "%s%s", Translate(LANG_INLINE_PREFIX), msg); - - PROTORECVEVENT pre = {0}; - pre.timestamp = time(0); - pre.szMessage = buff; - pre.flags = PREF_UTF|PREF_BYPASS_OTR; - //CallContactService(hContact, PSR_MESSAGE, 0, (LPARAM)&pre); - - CCSDATA ccs = {0}; - ccs.hContact = hContact; - ccs.szProtoService = PSR_MESSAGE; - ccs.lParam = (LPARAM)⪯ - - CallService(MS_PROTO_CHAINRECV, 0, (LPARAM)&ccs); -} - - -void ShowMessageUtf(const HANDLE hContact, const char *msg) { - if(options.msg_inline) - ShowMessageInlineUtf(hContact, msg); - if(options.msg_popup) - ShowPopupUtf(Translate(LANG_OTR_INFO), msg, 0, hContact); -} - -void ShowMessage(const HANDLE hContact, const TCHAR *msg) { - if(options.msg_inline) - ShowMessageInline(hContact, msg); - if(options.msg_popup) - ShowPopup(TranslateT(LANG_OTR_INFO), msg, 0, hContact); -} - - -/* -bool GetEncryptionStatus(HANDLE hContact) { - char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); - bool chat_room = (proto && DBGetContactSettingByte(hContact, proto, "ChatRoom", 0)); - - if (!chat_room) { - if (options.bHaveMetaContacts) { - HANDLE hMeta = (HANDLE)CallService(MS_MC_GETMETACONTACT, (WPARAM)hContact, 0); - if(hMeta && hContact == (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hMeta, 0)) { - //strcat(dbg_msg, "\nrecursing for meta"); - return GetEncryptionStatus(hMeta); - } - return 0!=DBGetContactSettingByte(hContact, MODULENAME, "Encrypted", 0 ); - } - } - return 0; -} -*/ - -const TCHAR *policy_to_string(OtrlPolicy policy) { - switch (policy) { - case OTRL_POLICY_NEVER: - return TranslateT(LANG_POLICY_NEVER); - break; - case OTRL_POLICY_OPPORTUNISTIC: - return TranslateT(LANG_POLICY_OPP); - break; - case OTRL_POLICY_MANUAL: - case OTRL_POLICY_MANUAL_MOD: - return TranslateT(LANG_POLICY_MANUAL); - break; - case OTRL_POLICY_ALWAYS: - return TranslateT(LANG_POLICY_ALWAYS); - break; - } - return TranslateT(LANG_POLICY_DEFAULT); -} - -OtrlPolicy policy_from_string(const TCHAR *polstring) { - if (_tcscmp(polstring, TranslateT(LANG_POLICY_NEVER)) == 0) - return OTRL_POLICY_NEVER; - else if (_tcscmp(polstring, TranslateT(LANG_POLICY_OPP)) == 0) - return OTRL_POLICY_OPPORTUNISTIC; - else if (_tcscmp(polstring, TranslateT(LANG_POLICY_MANUAL)) == 0) - return OTRL_POLICY_MANUAL_MOD; - else if (_tcscmp(polstring, TranslateT(LANG_POLICY_ALWAYS)) == 0) - return OTRL_POLICY_ALWAYS; - else - return CONTACT_DEFAULT_POLICY; -} \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/utils.h b/plugins/MirOTR/MirOTR/utils.h deleted file mode 100644 index 01c1b44f69..0000000000 --- a/plugins/MirOTR/MirOTR/utils.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once -#ifndef __HEADER_UTILS_H -#define __HEADER_UTILS_H -#include "stdafx.h" - - -void lib_cs_lock(); -void lib_cs_unlock(); - -HANDLE find_contact(const char* userid, const char* protocol); -ConnContext * otrl_context_find_miranda(OtrlUserState us, HANDLE hContact); - -typedef enum { - TRUST_NOT_PRIVATE, - TRUST_FINISHED, - TRUST_UNVERIFIED, - TRUST_PRIVATE -} TrustLevel; -TrustLevel otr_context_get_trust(ConnContext *context); -void VerifyFingerprint(ConnContext *context, bool verify); -void VerifyFingerprintMessage(ConnContext *context, bool verify); - -void otrl_privkey_hash_to_humanT(TCHAR human[45], const unsigned char hash[20]); - -char* contact_get_id(HANDLE hContact, bool bNameOnError=true); -__inline const char* contact_get_proto(HANDLE hContact); -__inline const char* contact_get_account(HANDLE hContact); -extern __inline const TCHAR* contact_get_nameT(HANDLE hContact); - -void ShowPopup(const TCHAR* line1, const TCHAR* line2, int timeout, const HANDLE hContact = NULL); -void ShowWarning(TCHAR* msg); -void ShowError(TCHAR* msg); -void ShowPopupUtf(const char* line1, const char* line2, int timeout, const HANDLE hContact = NULL); -void ShowWarningUtf(char* msg); -void ShowErrorUtf(char* msg); - -void ShowMessageInline(const HANDLE hContact, const TCHAR *msg); -void ShowMessageInlineUtf(const HANDLE hContact, const char *msg); - -void ShowMessage(const HANDLE hContact, const TCHAR *msg); -void ShowMessageUtf(const HANDLE hContact, const char *msg); - -void InitUtils(); -void DeinitUtils(); - -const TCHAR *policy_to_string(OtrlPolicy policy); -OtrlPolicy policy_from_string(const TCHAR *polstring); - -#endif \ No newline at end of file diff --git a/plugins/MirOTR/MirOTR/version.h b/plugins/MirOTR/MirOTR/version.h deleted file mode 100644 index 2bd9618de7..0000000000 --- a/plugins/MirOTR/MirOTR/version.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef OTR_PRIVATE_H -#define OTR_PRIVATE_H - -/* VERSION DEFINITIONS */ -#define VER_MAJOR 0 -#define VER_MINOR 11 -#define VER_RELEASE 0 -#define VER_BUILD 4 - -#define __STRINGIZE(x) #x -#define VER_STRING "0.11.0.4" - -#ifdef _UNICODE - #define SHORT_NAME_STRING "Miranda OTR" - #define DESC_STRING "OTR (Off-the-Record) plugin for Miranda NG" -#else - #define SHORT_NAME_STRING "Miranda OTR (x64)" - #define DESC_STRING "OTR (Off-the-Record) plugin for Miranda NG (64Bit)" -#endif -#define LONGDESC_STRING DESC_STRING "\r\n(using some code and ideas from SecureIM, Pidgin-OTR and old Miranda OTR (by SJE))." -#define COMPANY_NAME "" -#define FILE_VERSION VER_STRING -#define FILE_DESCRIPTION DESC_STRING -#define INTERNAL_NAME "" -#define LEGAL_COPYRIGHT "© ProgAndy & CHEF-KOCH" -#define LEGAL_COPYRIGHT_LONG "© ProgAndy & CHEF-KOCH" -#define LEGAL_TRADEMARKS "" -#define ORIGINAL_FILENAME "mirotr.dll" -#define PRODUCT_NAME DESC_STRING -#define PRODUCT_VERSION VER_STRING - - -#define AUTHOR "ProgAndy & CHEF-KOCH" -#define AUTHOR_MAIL "" -#define HOMEPAGE "http://miranda-ng.org/" - -#endif /*OTR_PRIVATE_H*/ -- cgit v1.2.3