summaryrefslogtreecommitdiff
path: root/plugins/MirOTR/src/dialogs.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/MirOTR/src/dialogs.cpp')
-rw-r--r--plugins/MirOTR/src/dialogs.cpp460
1 files changed, 137 insertions, 323 deletions
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));
}