diff options
-rw-r--r-- | plugins/MirOTR/src/dbfilter.cpp | 9 | ||||
-rw-r--r-- | plugins/MirOTR/src/dialogs.cpp | 460 | ||||
-rw-r--r-- | plugins/MirOTR/src/dialogs.h | 1 | ||||
-rw-r--r-- | plugins/MirOTR/src/dllmain.cpp | 11 | ||||
-rw-r--r-- | plugins/MirOTR/src/options.cpp | 3 | ||||
-rw-r--r-- | plugins/MirOTR/src/stdafx.h | 2 | ||||
-rw-r--r-- | plugins/MirOTR/src/svcs_menu.cpp | 47 | ||||
-rw-r--r-- | plugins/MirOTR/src/svcs_proto.cpp | 18 | ||||
-rw-r--r-- | plugins/MirOTR/src/utils.cpp | 18 | ||||
-rw-r--r-- | plugins/MirOTR/src/utils.h | 4 | ||||
-rw-r--r-- | plugins/MirOTR/src/version.h | 4 |
11 files changed, 190 insertions, 387 deletions
diff --git a/plugins/MirOTR/src/dbfilter.cpp b/plugins/MirOTR/src/dbfilter.cpp index 155907a3cf..7feb81219b 100644 --- a/plugins/MirOTR/src/dbfilter.cpp +++ b/plugins/MirOTR/src/dbfilter.cpp @@ -181,8 +181,11 @@ int WindowEvent(WPARAM, LPARAM lParam) if (!Proto_IsProtoOnContact(hContact, MODULENAME)) return 0; - lib_cs_lock(); - ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact); + ConnContext *context; + { + mir_cslock lck(lib_cs); + context = otrl_context_find_miranda(otr_user_state, hContact); + } SetEncryptionStatus(hContact, otr_context_get_trust(context)); return 0; } @@ -197,7 +200,7 @@ int StatusModeChange(WPARAM wParam, LPARAM lParam) const char *proto = (char *)lParam; - lib_cs_lock(); + mir_cslock lck(lib_cs); ConnContext *context = otr_user_state->context_root; while (context) { diff --git a/plugins/MirOTR/src/dialogs.cpp b/plugins/MirOTR/src/dialogs.cpp index 35d7b32c42..2244b644e0 100644 --- a/plugins/MirOTR/src/dialogs.cpp +++ b/plugins/MirOTR/src/dialogs.cpp @@ -8,18 +8,15 @@ struct SmpData bool responder; wchar_t *question; }; + typedef std::map<HANDLE, SmpData> SmpForContactMap; SmpForContactMap smp_for_contact; - static INT_PTR CALLBACK DlgSMPUpdateProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { + ConnContext *context = (ConnContext*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + switch (msg) { - case WM_DESTROY: { - ConnContext *context = (ConnContext*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - if (context) - otr_abort_smp(context); - break; } case WM_INITDIALOG: { if (!lParam) { @@ -29,7 +26,7 @@ static INT_PTR CALLBACK DlgSMPUpdateProc(HWND hwndDlg, UINT msg, WPARAM wParam, TranslateDialogDefault(hwndDlg); SmpData *data = (SmpData*)lParam; - ConnContext *context = data->context; + context = data->context; MCONTACT hContact = (UINT_PTR)context->app_data; data->dialog = hwndDlg; //smp_for_contact.insert(SmpForContactMap::value_type(context->app_data, *data)); @@ -52,9 +49,8 @@ static INT_PTR CALLBACK DlgSMPUpdateProc(HWND hwndDlg, UINT msg, WPARAM wParam, // Move window to screen center // Get the owner window and dialog box rectangles. HWND hwndOwner; RECT rcOwner, rcDlg, rc; - if ((hwndOwner = GetParent(hwndDlg)) == nullptr) { + if ((hwndOwner = GetParent(hwndDlg)) == nullptr) hwndOwner = GetDesktopWindow(); - } GetWindowRect(hwndOwner, &rcOwner); GetWindowRect(hwndDlg, &rcDlg); @@ -85,62 +81,57 @@ static INT_PTR CALLBACK DlgSMPUpdateProc(HWND hwndDlg, UINT msg, WPARAM wParam, EnableWindow(GetDlgItem(hwndDlg, IDCANCEL), true); EnableWindow(GetDlgItem(hwndDlg, IDOK), false); - - return TRUE; } + 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, TranslateW(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, TranslateW(LANG_SMP_SUCCESS)); - } - else { - SetDlgItemText(hwndDlg, IDC_STC_SMP_PROGRESS, TranslateW(LANG_SMP_SUCCESS_VERIFY)); - } - } - else { - SetDlgItemText(hwndDlg, IDC_STC_SMP_PROGRESS, TranslateW(LANG_SMP_FAILED)); - } - } - break; - default: - SetDlgItemText(hwndDlg, IDC_STC_SMP_PROGRESS, L""); + 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, TranslateW(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, TranslateW(LANG_SMP_SUCCESS)); + else + SetDlgItemText(hwndDlg, IDC_STC_SMP_PROGRESS, TranslateW(LANG_SMP_SUCCESS_VERIFY)); } + else SetDlgItemText(hwndDlg, IDC_STC_SMP_PROGRESS, TranslateW(LANG_SMP_FAILED)); + break; + + default: + SetDlgItemText(hwndDlg, IDC_STC_SMP_PROGRESS, L""); } break; case WM_COMMAND: switch (HIWORD(wParam)) { case BN_CLICKED: - { - ConnContext *context = (ConnContext*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - switch (LOWORD(wParam)) { - case IDOK: - smp_for_contact.erase(context->app_data); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, NULL); - // fall through - case IDCANCEL: - DestroyWindow(hwndDlg); - break; - } - }break; + switch (LOWORD(wParam)) { + case IDOK: + smp_for_contact.erase(context->app_data); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, NULL); + __fallthrough; + + case IDCANCEL: + DestroyWindow(hwndDlg); + break; + } } + break; + case WM_DESTROY: + if (context) + otr_abort_smp(context); + break; } return FALSE; @@ -158,22 +149,19 @@ static void SMPInitUpdateDialog(ConnContext *context, bool responder) static INT_PTR CALLBACK DlgSMPResponseProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { + ConnContext *context = (ConnContext*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + switch (msg) { - case WM_DESTROY: { - ConnContext *context = (ConnContext*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - if (context) - otr_abort_smp(context); - break; } case WM_INITDIALOG: - { - if (!lParam) { - DestroyWindow(hwndDlg); - return FALSE; - } - TranslateDialogDefault(hwndDlg); + if (!lParam) { + DestroyWindow(hwndDlg); + return FALSE; + } + TranslateDialogDefault(hwndDlg); + { SmpData *data = (SmpData*)lParam; - ConnContext *context = data->context; + context = data->context; MCONTACT hContact = (UINT_PTR)context->app_data; data->dialog = hwndDlg; //smp_for_contact.insert(SmpForContactMap::value_type(context->app_data, *data)); @@ -266,7 +254,6 @@ static INT_PTR CALLBACK DlgSMPResponseProc(HWND hwndDlg, UINT msg, WPARAM wParam case WM_COMMAND: switch (HIWORD(wParam)) { case BN_CLICKED: - ConnContext *context = (ConnContext *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); switch (LOWORD(wParam)) { case IDOK: SMPInitUpdateDialog(context, true); @@ -291,25 +278,20 @@ static INT_PTR CALLBACK DlgSMPResponseProc(HWND hwndDlg, UINT msg, WPARAM wParam } } break; + + case WM_DESTROY: + if (context) + otr_abort_smp(context); + break; } return FALSE; } -/* -void SMPInitResponseDialog(ConnContext *context, const wchar_t *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_wstrdup(question) : NULL; - CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_SMP_INPUT), 0, DlgSMPResponseProc, (LPARAM) data); -} -*/ - static INT_PTR CALLBACK DlgProcSMPInitProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { + ConnContext *context = (ConnContext*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + switch (msg) { case WM_INITDIALOG: { @@ -319,7 +301,7 @@ static INT_PTR CALLBACK DlgProcSMPInitProc(HWND hwndDlg, UINT msg, WPARAM wParam } TranslateDialogDefault(hwndDlg); - ConnContext *context = (ConnContext*)lParam; + context = (ConnContext*)lParam; if (smp_for_contact.find(context->app_data) != smp_for_contact.end()) { DestroyWindow(hwndDlg); return FALSE; @@ -347,14 +329,12 @@ static INT_PTR CALLBACK DlgProcSMPInitProc(HWND hwndDlg, UINT msg, WPARAM wParam // 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), @@ -362,9 +342,6 @@ static INT_PTR CALLBACK DlgProcSMPInitProc(HWND hwndDlg, UINT msg, WPARAM wParam 0, 0, // Ignores size arguments. SWP_NOSIZE); - // end center dialog - - HWND cmb = GetDlgItem(hwndDlg, IDC_CBO_SMP_CHOOSE); SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateW(LANG_SMPTYPE_QUESTION)); SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateW(LANG_SMPTYPE_PASSWORD)); @@ -372,12 +349,12 @@ static INT_PTR CALLBACK DlgProcSMPInitProc(HWND hwndDlg, UINT msg, WPARAM wParam SendMessage(cmb, CB_SELECTSTRING, -1, (WPARAM)TranslateW(LANG_SMPTYPE_QUESTION)); EnableWindow(GetDlgItem(hwndDlg, IDC_CBO_SMP_CHOOSE), TRUE); - Fingerprint *fp = context->active_fingerprint; if (!fp) { DestroyWindow(hwndDlg); return FALSE; } + wchar_t buff[1024]; if (!fp->trust || fp->trust[0] == '\0') mir_snwprintf(buff, TranslateW(LANG_OTR_SMPQUESTION_VERIFY_DESC), contact_get_nameT(hContact)); @@ -399,15 +376,13 @@ static INT_PTR CALLBACK DlgProcSMPInitProc(HWND hwndDlg, UINT msg, WPARAM wParam ShowWindow(GetDlgItem(hwndDlg, IDYES), SW_HIDE); ShowWindow(GetDlgItem(hwndDlg, IDNO), SW_HIDE); SetFocus(GetDlgItem(hwndDlg, IDC_CBO_SMP_CHOOSE)); - - return FALSE; } + return FALSE; case WM_COMMAND: switch (HIWORD(wParam)) { case BN_CLICKED: { - ConnContext *context = (ConnContext*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); MCONTACT hContact = (UINT_PTR)context->app_data; wchar_t szMsg[1024]; switch (LOWORD(wParam)) { @@ -474,99 +449,101 @@ static INT_PTR CALLBACK DlgProcSMPInitProc(HWND hwndDlg, UINT msg, WPARAM wParam case CBN_SELCHANGE: switch (LOWORD(wParam)) { case IDC_CBO_SMP_CHOOSE: - { - ConnContext *context = (ConnContext*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - MCONTACT hContact = (UINT_PTR)context->app_data; - Fingerprint *fp = context->active_fingerprint; - if (!fp) { - DestroyWindow(hwndDlg); - return TRUE; - } - BOOL trusted = false; - if (fp->trust && fp->trust[0] != '\0') trusted = true; + MCONTACT hContact = (UINT_PTR)context->app_data; + Fingerprint *fp = context->active_fingerprint; + if (!fp) { + DestroyWindow(hwndDlg); + return TRUE; + } + BOOL trusted = false; + if (fp->trust && fp->trust[0] != '\0') trusted = true; - wchar_t buff[512]; - GetDlgItemText(hwndDlg, IDC_CBO_SMP_CHOOSE, buff, 255); - if (wcsncmp(buff, TranslateW(LANG_SMPTYPE_QUESTION), 255) == 0) { - if (trusted) - mir_snwprintf(buff, TranslateW(LANG_OTR_SMPQUESTION_VERIFIED_DESC), contact_get_nameT(hContact)); - else - mir_snwprintf(buff, TranslateW(LANG_OTR_SMPQUESTION_VERIFY_DESC), contact_get_nameT(hContact)); + wchar_t buff[512]; + GetDlgItemText(hwndDlg, IDC_CBO_SMP_CHOOSE, buff, 255); + if (wcsncmp(buff, TranslateW(LANG_SMPTYPE_QUESTION), 255) == 0) { + if (trusted) + mir_snwprintf(buff, TranslateW(LANG_OTR_SMPQUESTION_VERIFIED_DESC), contact_get_nameT(hContact)); + else + mir_snwprintf(buff, TranslateW(LANG_OTR_SMPQUESTION_VERIFY_DESC), contact_get_nameT(hContact)); - SetDlgItemText(hwndDlg, IDC_STC_SMP_INFO, buff); + SetDlgItemText(hwndDlg, IDC_STC_SMP_INFO, buff); - SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, L""); - SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, FALSE, 0); - SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, TranslateW(LANG_SMP_QUESTION)); + SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, L""); + SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, FALSE, 0); + SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, TranslateW(LANG_SMP_QUESTION)); - SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, L""); - SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, EM_SETREADONLY, FALSE, 0); - SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD2, TranslateW(LANG_SMP_ANSWER)); + SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, L""); + SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, EM_SETREADONLY, FALSE, 0); + SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD2, TranslateW(LANG_SMP_ANSWER)); - ShowWindow(GetDlgItem(hwndDlg, IDOK), SW_SHOWNA); - ShowWindow(GetDlgItem(hwndDlg, IDYES), SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDNO), SW_HIDE); - } - else if (wcsncmp(buff, TranslateW(LANG_SMPTYPE_PASSWORD), 255) == 0) { - if (trusted) - mir_snwprintf(buff, TranslateW(LANG_OTR_SMPPASSWORD_VERIFIED_DESC), contact_get_nameT(hContact)); - else - mir_snwprintf(buff, TranslateW(LANG_OTR_SMPPASSWORD_VERIFY_DESC), contact_get_nameT(hContact)); + ShowWindow(GetDlgItem(hwndDlg, IDOK), SW_SHOWNA); + ShowWindow(GetDlgItem(hwndDlg, IDYES), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDNO), SW_HIDE); + } + else if (wcsncmp(buff, TranslateW(LANG_SMPTYPE_PASSWORD), 255) == 0) { + if (trusted) + mir_snwprintf(buff, TranslateW(LANG_OTR_SMPPASSWORD_VERIFIED_DESC), contact_get_nameT(hContact)); + else + mir_snwprintf(buff, TranslateW(LANG_OTR_SMPPASSWORD_VERIFY_DESC), contact_get_nameT(hContact)); - SetDlgItemText(hwndDlg, IDC_STC_SMP_INFO, buff); + SetDlgItemText(hwndDlg, IDC_STC_SMP_INFO, buff); - SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, L""); - SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, TRUE, 0); - SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, L""); + SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, L""); + SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, TRUE, 0); + SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, L""); - SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, L""); - SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, EM_SETREADONLY, FALSE, 0); - SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD2, TranslateW(LANG_SMP_PASSWORD)); + SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, L""); + SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, EM_SETREADONLY, FALSE, 0); + SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD2, TranslateW(LANG_SMP_PASSWORD)); - ShowWindow(GetDlgItem(hwndDlg, IDOK), SW_SHOWNA); - ShowWindow(GetDlgItem(hwndDlg, IDYES), SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDNO), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDOK), SW_SHOWNA); + ShowWindow(GetDlgItem(hwndDlg, IDYES), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDNO), SW_HIDE); + } + else if (wcsncmp(buff, TranslateW(LANG_SMPTYPE_FINGERPRINT), 255) == 0) { + if (trusted) + mir_snwprintf(buff, TranslateW(LANG_OTR_FPVERIFIED_DESC), contact_get_nameT(hContact)); + else + mir_snwprintf(buff, TranslateW(LANG_OTR_FPVERIFY_DESC), contact_get_nameT(hContact)); + + SetDlgItemText(hwndDlg, IDC_STC_SMP_INFO, buff); + + unsigned char hash[20]; + BYTE *ret; + { + mir_cslock lck(lib_cs); + ret = otrl_privkey_fingerprint_raw(otr_user_state, hash, context->accountname, context->protocol); + } + if (!ret) { + DestroyWindow(hwndDlg); + return FALSE; } - else if (wcsncmp(buff, TranslateW(LANG_SMPTYPE_FINGERPRINT), 255) == 0) { - if (trusted) - mir_snwprintf(buff, TranslateW(LANG_OTR_FPVERIFIED_DESC), contact_get_nameT(hContact)); - else - mir_snwprintf(buff, TranslateW(LANG_OTR_FPVERIFY_DESC), contact_get_nameT(hContact)); - - 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)) { - DestroyWindow(hwndDlg); - return FALSE; - } - otrl_privkey_hash_to_humanT(buff, hash); - SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, buff); - SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, TRUE, 0); - SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, TranslateW(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, TranslateW(LANG_CONTACT_FINGERPRINT)); + otrl_privkey_hash_to_humanT(buff, hash); + SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, buff); + SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, TRUE, 0); + SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, TranslateW(LANG_YOUR_PRIVKEY)); - ShowWindow(GetDlgItem(hwndDlg, IDOK), SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDYES), SW_SHOWNA); - ShowWindow(GetDlgItem(hwndDlg, IDNO), SW_SHOWNA); + 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, TranslateW(LANG_CONTACT_FINGERPRINT)); - } - }break; + 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) @@ -586,22 +563,8 @@ void SMPDialogUpdate(ConnContext *context, int percent) else if (level == TRUST_UNVERIFIED) VerifyFingerprintMessage(context, false); } - //if (percent == 100) - /* - switch (percent){ - case 0: - VerifyFingerprint(context, false); - ShowWarning(L"SMP failed"); - break; - case 100: - VerifyFingerprint(context, true); - ShowWarning(L"SMP successful"); - break; - default: - ShowWarning(L"Received an SMP update"); - } - */ } + void SMPDialogReply(ConnContext *context, const char* question) { SmpData *data = (SmpData*)mir_calloc(sizeof(SmpData)); @@ -610,153 +573,4 @@ void SMPDialogReply(ConnContext *context, const char* question) data->responder = true; data->question = (question) ? mir_utf8decodeW(question) : nullptr; CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_SMP_INPUT), nullptr, DlgSMPResponseProc, (LPARAM)data); - /* - ShowError(L"SMP requires user password (NOT IMPL YET)"); - otr_abort_smp(context); - */ - //otr_continue_smp(context, pass, mir_strlen(pass)); -} - -static INT_PTR CALLBACK DlgBoxProcVerifyContext(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch (msg) { - case WM_INITDIALOG: - { - if (!lParam) { - EndDialog(hwndDlg, IDCANCEL); - return FALSE; - } - SetWindowText(hwndDlg, LANG_OTR_FPVERIFY_TITLE); - SetDlgItemText(hwndDlg, IDC_STC_SMP_HEAD, 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 = GetParent(hwndDlg); - if (hwndOwner == nullptr) - hwndOwner = GetDesktopWindow(); - - RECT rcOwner, rcDlg, rc; - 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; - MCONTACT hContact = (UINT_PTR)context->app_data; - Fingerprint *fp = context->active_fingerprint; - if (!fp) { - EndDialog(hwndDlg, IDCANCEL); - return FALSE; - } - wchar_t buff[512]; - if (!fp->trust || fp->trust[0] == '\0') - mir_snwprintf(buff, TranslateW(LANG_OTR_FPVERIFY_DESC), contact_get_nameT(hContact)); - else - mir_snwprintf(buff, TranslateW(LANG_OTR_FPVERIFIED_DESC), contact_get_nameT(hContact)); - - 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)) { - EndDialog(hwndDlg, IDCANCEL); - return FALSE; - } - otrl_privkey_hash_to_humanT(buff, hash); - SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, buff); - SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, TRUE, 0); - SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, TranslateW(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, TranslateW(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; -} - -static unsigned int CALLBACK verify_context_thread(void *param) -{ - Thread_Push(nullptr); - - if (param) { - ConnContext *context = (ConnContext *)param; - MCONTACT hContact = (UINT_PTR)context->app_data; - wchar_t msg[1024]; - switch (DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_SMP_INPUT), nullptr, DlgBoxProcVerifyContext, (LPARAM)param)) { - case IDOK: - case IDYES: - lib_cs_lock(); - otrl_context_set_trust(context->active_fingerprint, "verified"); - otrl_privkey_write_fingerprints(otr_user_state, _T2A(g_fingerprint_store_filename)); - mir_snwprintf(msg, TranslateW(LANG_FINGERPRINT_VERIFIED), contact_get_nameT(hContact)); - ShowMessage(hContact, msg); - SetEncryptionStatus(hContact, otr_context_get_trust(context)); - break; - - case IDNO: - lib_cs_lock(); - otrl_context_set_trust(context->active_fingerprint, nullptr); - otrl_privkey_write_fingerprints(otr_user_state, _T2A(g_fingerprint_store_filename)); - mir_snwprintf(msg, TranslateW(LANG_FINGERPRINT_NOT_VERIFIED), contact_get_nameT(hContact)); - ShowMessage(hContact, msg); - SetEncryptionStatus(hContact, otr_context_get_trust(context)); - break; - } - } - - Thread_Pop(); - return 0; -} - -void VerifyContextDialog(ConnContext* context) -{ - if (!context) return; - CloseHandle((HANDLE)_beginthreadex(nullptr, 0, verify_context_thread, context, 0, nullptr)); } diff --git a/plugins/MirOTR/src/dialogs.h b/plugins/MirOTR/src/dialogs.h index 3e259d2797..a5272316dc 100644 --- a/plugins/MirOTR/src/dialogs.h +++ b/plugins/MirOTR/src/dialogs.h @@ -1,5 +1,4 @@ #pragma once -void VerifyContextDialog(ConnContext* context); void SMPInitDialog(ConnContext* context); void SMPDialogUpdate(ConnContext *context, int percent); void SMPDialogReply(ConnContext *context, const char* question); diff --git a/plugins/MirOTR/src/dllmain.cpp b/plugins/MirOTR/src/dllmain.cpp index c6ff084d8b..f0bc0ca0dd 100644 --- a/plugins/MirOTR/src/dllmain.cpp +++ b/plugins/MirOTR/src/dllmain.cpp @@ -26,9 +26,6 @@ CMPlugin::CMPlugin() : int ModulesLoaded(WPARAM, LPARAM)
{
- lib_cs_lock();
- otr_user_state = otrl_userstate_create();
-
// this calls ReadPrivkeyFiles (above) to set filename values (also called on ME_FOLDERS_PATH_CHANGED)
InitOptions();
@@ -51,7 +48,10 @@ int ModulesLoaded(WPARAM, LPARAM) int CMPlugin::Load()
{
DEBUGOUTA("LOAD MIROTR");
-
+ {
+ mir_cslock lck(lib_cs);
+ otr_user_state = otrl_userstate_create();
+ }
InitIcons();
OTRL_INIT;
@@ -91,8 +91,7 @@ int CMPlugin::Unload() DeinitSRMM();
DeinitDBFilter();
- lib_cs_lock();
+ mir_cslock lck(lib_cs);
otrl_userstate_free(otr_user_state);
-
return 0;
}
diff --git a/plugins/MirOTR/src/options.cpp b/plugins/MirOTR/src/options.cpp index ab0e698f32..00d94dbb36 100644 --- a/plugins/MirOTR/src/options.cpp +++ b/plugins/MirOTR/src/options.cpp @@ -120,7 +120,8 @@ extern "C" void set_context_contact(void *, ConnContext *context) void ReadPrivkeyFiles() { DEBUGOUTA("READ privkey"); - lib_cs_lock(); + + mir_cslock lck(lib_cs); otrl_privkey_read(otr_user_state, _T2A(g_private_key_filename)); otrl_privkey_read_fingerprints(otr_user_state, _T2A(g_fingerprint_store_filename), set_context_contact, nullptr); otrl_instag_read(otr_user_state, _T2A(g_instag_filename)); diff --git a/plugins/MirOTR/src/stdafx.h b/plugins/MirOTR/src/stdafx.h index 981a5b04fd..f98cdb7fb1 100644 --- a/plugins/MirOTR/src/stdafx.h +++ b/plugins/MirOTR/src/stdafx.h @@ -55,11 +55,9 @@ using namespace std; #include "dialogs.h"
#include "version.h"
#include "entities.h"
-#include "icons.h"
#include "mirotrmenu.h"
#include "striphtml.h"
#include "ekhtml.h"
-#include "svcs_proto.h"
#ifdef _DEBUG
#define DEBUGOUTA(x) OutputDebugStringA(x)
diff --git a/plugins/MirOTR/src/svcs_menu.cpp b/plugins/MirOTR/src/svcs_menu.cpp index a4c7797fb5..c05fb30cdc 100644 --- a/plugins/MirOTR/src/svcs_menu.cpp +++ b/plugins/MirOTR/src/svcs_menu.cpp @@ -8,18 +8,18 @@ static HGENMENU hStopItem, hStartItem; int StartOTR(MCONTACT hContact) { const char *proto = GetContactProto(hContact); - if (!proto) return 1; // error - char *uname = contact_get_id(hContact); - if (!uname) return 1; // error + if (!proto) + return 1; // error + + ptrA uname(contact_get_id(hContact)); + if (!uname) + return 1; // error + DWORD pol = g_plugin.getDword(hContact, "Policy", CONTACT_DEFAULT_POLICY); - if (pol == CONTACT_DEFAULT_POLICY) pol = options.default_policy; - - lib_cs_lock(); -#ifndef MIROTR_PROTO_HELLO_MSG - char *msg = otrl_proto_default_query_msg(MODULENAME, pol); - otr_gui_inject_message((void*)hContact, proto, proto, uname, msg ? msg : MIROTR_PROTO_HELLO); - free(msg); -#else + if (pol == CONTACT_DEFAULT_POLICY) + pol = options.default_policy; + + mir_cslock lck(lib_cs); wchar_t* nick = ProtoGetNickname(proto); if (nick) { wchar_t msg[1024]; @@ -44,8 +44,6 @@ int StartOTR(MCONTACT hContact) T2Utf msg_utf8(msg); otr_gui_inject_message((void*)hContact, proto, proto, uname, msg_utf8 ? msg_utf8 : MIROTR_PROTO_HELLO); } -#endif - mir_free(uname); return 0; } @@ -86,10 +84,7 @@ INT_PTR SVC_RefreshOTR(WPARAM hContact, LPARAM) mir_snwprintf(buff, TranslateW(LANG_SESSION_TRY_CONTINUE_OTR), contact_get_nameT(hContact)); ShowMessage(hContact, buff); - int res = StartOTR(hContact); - if (res) return res; - - return 0; + return StartOTR(hContact); } int otr_disconnect_contact(MCONTACT hContact) @@ -99,20 +94,23 @@ int otr_disconnect_contact(MCONTACT hContact) hContact = hSub; const char *proto = GetContactProto(hContact); - if (!proto) return 1; // error - char *uname = contact_get_id(hContact); - if (!uname) return 1; // error - - lib_cs_lock(); + if (!proto) + return 1; // error + + ptrA uname(contact_get_id(hContact)); + if (!uname) + return 1; // error + + mir_cslock lck(lib_cs); otrl_message_disconnect_all_instances(otr_user_state, &ops, (void*)hContact, proto, proto, uname); - mir_free(uname); return 0; } INT_PTR SVC_StopOTR(WPARAM hContact, LPARAM) { // 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; + if (otr_disconnect_contact(hContact)) + return 0; SetEncryptionStatus(hContact, TRUST_NOT_PRIVATE); @@ -132,7 +130,6 @@ INT_PTR SVC_VerifyOTR(WPARAM hContact, LPARAM) if (!context) return 1; - //VerifyContextDialog(context); SMPInitDialog(context); return 0; } diff --git a/plugins/MirOTR/src/svcs_proto.cpp b/plugins/MirOTR/src/svcs_proto.cpp index f28c12c792..b909e4346a 100644 --- a/plugins/MirOTR/src/svcs_proto.cpp +++ b/plugins/MirOTR/src/svcs_proto.cpp @@ -39,9 +39,9 @@ INT_PTR SVC_OTRSendMessage(WPARAM wParam,LPARAM lParam){ } char *newmessage = nullptr; - char *username = contact_get_id(ccs->hContact); - gcry_error_t err = otrl_message_sending(otr_user_state, &ops, (void*)ccs->hContact, proto, proto, username, OTRL_INSTAG_BEST, oldmessage, nullptr, &newmessage, OTRL_FRAGMENT_SEND_ALL_BUT_LAST, nullptr, add_appdata, (void*)ccs->hContact); - mir_free(username); + gcry_error_t err = otrl_message_sending(otr_user_state, &ops, (void*)ccs->hContact, proto, proto, + ptrA(contact_get_id(ccs->hContact)), OTRL_INSTAG_BEST, oldmessage, nullptr, &newmessage, + OTRL_FRAGMENT_SEND_ALL_BUT_LAST, nullptr, add_appdata, (void*)ccs->hContact); if (err) { /* Be *sure* not to send out plaintext */ DEBUGOUTA("otrl_message_sending err"); @@ -97,15 +97,15 @@ INT_PTR SVC_OTRRecvMessage(WPARAM wParam,LPARAM lParam) return 1; ConnContext* context=nullptr; - char *uname = contact_get_id(ccs->hContact); char *newmessage = nullptr; OtrlTLV *tlvs = nullptr; - lib_cs_lock(); - int ignore_msg = otrl_message_receiving(otr_user_state, &ops, (void*)ccs->hContact, - proto, proto, uname, oldmessage, - &newmessage, &tlvs, &context, add_appdata, (void*)ccs->hContact); - mir_free(uname); + int ignore_msg; + { + mir_cslock lck(lib_cs); + ignore_msg = otrl_message_receiving(otr_user_state, &ops, (void*)ccs->hContact, proto, proto, ptrA(contact_get_id(ccs->hContact)), + oldmessage, &newmessage, &tlvs, &context, add_appdata, (void*)ccs->hContact); + } OtrlTLV *tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED); if (tlv && !Miranda_IsTerminated()) { diff --git a/plugins/MirOTR/src/utils.cpp b/plugins/MirOTR/src/utils.cpp index e3dbd2164b..3ef32fa1e8 100644 --- a/plugins/MirOTR/src/utils.cpp +++ b/plugins/MirOTR/src/utils.cpp @@ -11,16 +11,13 @@ MCONTACT find_contact(const char* userid, const char* protocol) { for (auto &hContact : Contacts()) { const char *proto = GetContactProto(hContact); - if(proto && mir_strcmp(proto, protocol) == 0) { - char *name = contact_get_id(hContact); - if(name && mir_strcmp(name, userid) == 0) { - mir_free(name); + if (proto && mir_strcmp(proto, protocol) == 0) { + ptrA name(contact_get_id(hContact)); + if (name && mir_strcmp(name, userid) == 0) return hContact; - } - mir_free(name); } } - + return 0; } @@ -29,13 +26,10 @@ MCONTACT find_contact(const char* userid, const char* protocol) * 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, MCONTACT hContact) +ConnContext* otrl_context_find_miranda(OtrlUserState us, MCONTACT hContact) { const char *proto = GetContactProto(hContact); - char *username = contact_get_id(hContact); - ConnContext* ret = otrl_context_find(us, username, proto, proto, OTRL_INSTAG_BEST, 0, nullptr, nullptr, nullptr); - mir_free(username); - return ret; + return otrl_context_find(us, ptrA(contact_get_id(hContact)), proto, proto, OTRL_INSTAG_BEST, 0, nullptr, nullptr, nullptr); } /* What level of trust do we have in the privacy of this ConnContext? */ diff --git a/plugins/MirOTR/src/utils.h b/plugins/MirOTR/src/utils.h index aec0e4a01a..52d6f0775d 100644 --- a/plugins/MirOTR/src/utils.h +++ b/plugins/MirOTR/src/utils.h @@ -1,10 +1,8 @@ #pragma once #ifndef __HEADER_UTILS_H #define __HEADER_UTILS_H -#include "stdafx.h" - -void lib_cs_lock(); +extern mir_cs lib_cs; MCONTACT find_contact(const char* userid, const char* protocol); ConnContext * otrl_context_find_miranda(OtrlUserState us, MCONTACT hContact); diff --git a/plugins/MirOTR/src/version.h b/plugins/MirOTR/src/version.h index 74d7a2ca6f..51d5559c4f 100644 --- a/plugins/MirOTR/src/version.h +++ b/plugins/MirOTR/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 14
-#define __RELEASE_NUM 1
-#define __BUILD_NUM 17
+#define __RELEASE_NUM 2
+#define __BUILD_NUM 1
#include <stdver.h>
|