From 8c2efbf3effd0190e2f98613cf783d411f7b43ee Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 29 May 2022 17:41:01 +0300 Subject: fixes #2911 (Add OMEMO-related info to user info) --- protocols/JabberG/jabber.vcxproj | 51 ++++++++++ protocols/JabberG/jabber.vcxproj.filters | 149 ++++++++++++++++++++++++++++++ protocols/JabberG/res/jabber.rc | 4 +- protocols/JabberG/src/jabber_omemo.h | 1 + protocols/JabberG/src/jabber_userinfo.cpp | 77 ++++++++++----- protocols/JabberG/src/jabber_vcard.cpp | 9 ++ 6 files changed, 269 insertions(+), 22 deletions(-) diff --git a/protocols/JabberG/jabber.vcxproj b/protocols/JabberG/jabber.vcxproj index 632ea83ce6..66f77c1e19 100644 --- a/protocols/JabberG/jabber.vcxproj +++ b/protocols/JabberG/jabber.vcxproj @@ -126,4 +126,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/protocols/JabberG/jabber.vcxproj.filters b/protocols/JabberG/jabber.vcxproj.filters index 8f8f5a9e4e..6fb571920e 100644 --- a/protocols/JabberG/jabber.vcxproj.filters +++ b/protocols/JabberG/jabber.vcxproj.filters @@ -244,4 +244,153 @@ Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + \ No newline at end of file diff --git a/protocols/JabberG/res/jabber.rc b/protocols/JabberG/res/jabber.rc index 5016761346..44b2ed6c07 100644 --- a/protocols/JabberG/res/jabber.rc +++ b/protocols/JabberG/res/jabber.rc @@ -321,12 +321,13 @@ BEGIN PUSHBUTTON "Cancel",IDCANCEL,96,88,50,14 END -IDD_INFO_OMEMO DIALOGEX 0, 0, 222, 132 +IDD_INFO_OMEMO DIALOGEX 0, 0, 222, 153 STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD EXSTYLE WS_EX_CONTROLPARENT FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN CONTROL "",IDC_LIST,"SysListView32",LVS_REPORT | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,0,0,221,131 + LTEXT "(*) marks the current session",IDC_STATIC,4,137,214,8 END IDD_VCARD_PHOTO DIALOGEX 0, 0, 222, 132 @@ -746,6 +747,7 @@ BEGIN IDD_INFO_OMEMO, DIALOG BEGIN + BOTTOMMARGIN, 132 END IDD_BOOKMARKS, DIALOG diff --git a/protocols/JabberG/src/jabber_omemo.h b/protocols/JabberG/src/jabber_omemo.h index 8d5eafd818..a5797889d6 100644 --- a/protocols/JabberG/src/jabber_omemo.h +++ b/protocols/JabberG/src/jabber_omemo.h @@ -33,6 +33,7 @@ struct signal_crypto_provider; namespace omemo { const char IdentityPrefix[] = "OmemoSignalIdentity_"; + const char DevicePrefix[] = "OmemoDeviceId"; struct omemo_device; diff --git a/protocols/JabberG/src/jabber_userinfo.cpp b/protocols/JabberG/src/jabber_userinfo.cpp index 96266010b9..a9eb606348 100644 --- a/protocols/JabberG/src/jabber_userinfo.cpp +++ b/protocols/JabberG/src/jabber_userinfo.cpp @@ -759,6 +759,17 @@ struct USER_OMEMO_INFO CJabberProto *ppro; }; +static int EnumOwnSessions(const char *szSetting, void *param) +{ + auto *pList = (LIST*)param; + + if (!memcmp(szSetting, omemo::DevicePrefix, sizeof(omemo::DevicePrefix)-1)) + if (szSetting[sizeof(omemo::DevicePrefix)] != 0) + pList->insert(mir_strdup(szSetting)); + + return 0; +} + static int EnumOmemoSessions(const char *szSetting, void *param) { auto *pList = (LIST*)param; @@ -769,7 +780,19 @@ static int EnumOmemoSessions(const char *szSetting, void *param) return 0; } -static INT_PTR CALLBACK JabberUserOmemoDlgProc(HWND hwndDlg, UINT msg, WPARAM, LPARAM lParam) +static void AddListItem(HWND hwndList, const CMStringA &pszStr1, const CMStringA &pszStr2) +{ + LVITEMA lvi = {}; + lvi.mask = LVIF_TEXT; + lvi.pszText = (char*)pszStr1.c_str(); + int idx = SendMessage(hwndList, LVM_INSERTITEMA, 0, LPARAM(&lvi)); + + lvi.iSubItem = 1; + lvi.pszText = (char *)pszStr2.c_str(); + SendMessage(hwndList, LVM_SETITEMTEXTA, idx, LPARAM(&lvi)); +} + +INT_PTR CALLBACK JabberUserOmemoDlgProc(HWND hwndDlg, UINT msg, WPARAM, LPARAM lParam) { auto *pInfo = (USER_OMEMO_INFO *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); HWND hwndList = GetDlgItem(hwndDlg, IDC_LIST); @@ -794,6 +817,9 @@ static INT_PTR CALLBACK JabberUserOmemoDlgProc(HWND hwndDlg, UINT msg, WPARAM, L lvc.pszText = TranslateT("Fingerprint"); ListView_InsertColumn(hwndList, 2, &lvc); } + + if (lParam == 0) + PostMessage(hwndDlg, WM_PROTO_REFRESH, 0, 0); break; case WM_NOTIFY: @@ -815,28 +841,37 @@ static INT_PTR CALLBACK JabberUserOmemoDlgProc(HWND hwndDlg, UINT msg, WPARAM, L case WM_PROTO_REFRESH: ListView_DeleteAllItems(hwndList); - LIST arSettings(1); - db_enum_settings(pInfo->hContact, EnumOmemoSessions, pInfo->ppro->m_szModuleName, &arSettings); - for (auto &it : arSettings) { - size_t len; - ptrA binVal((char*)mir_base64_decode(it, &len)); - - if (len <= sizeof(uint32_t)) - continue; - - uint32_t deviceId = *(uint32_t *)(binVal.get() + len - sizeof(uint32_t)); - CMStringA szText(FORMAT, "%X", deviceId); + if (pInfo->hContact == 0) { + uint32_t ownDeviceId = pInfo->ppro->getDword("OmemoDeviceId"); + CMStringA str1(FORMAT, "* %X", ownDeviceId); + CMStringA str2(pInfo->ppro->getMStringA("OmemoFingerprintOwn")); + AddListItem(hwndList, str1, str2); - LVITEMA lvi = {}; - lvi.mask = LVIF_TEXT; - lvi.pszText = szText.GetBuffer(); - int idx = SendMessage(hwndList, LVM_INSERTITEMA, 0, LPARAM(&lvi)); + LIST arSettings(1); + db_enum_settings(pInfo->hContact, EnumOwnSessions, pInfo->ppro->m_szModuleName, &arSettings); - szText.Truncate(int(len) * 2); - bin2hex(binVal, len - sizeof(uint32_t), szText.GetBuffer()); - lvi.iSubItem = 1; - lvi.pszText = szText.GetBuffer(); - SendMessage(hwndList, LVM_SETITEMTEXTA, idx, LPARAM(&lvi)); + str2 = ""; + for (auto &it : arSettings) { + str1.Format("%X", pInfo->ppro->getDword(it)); + AddListItem(hwndList, str1, str2); + } + } + else { + LIST arSettings(1); + db_enum_settings(pInfo->hContact, EnumOmemoSessions, pInfo->ppro->m_szModuleName, &arSettings); + for (auto &it : arSettings) { + size_t len; + ptrA binVal((char *)mir_base64_decode(it, &len)); + + if (len <= sizeof(uint32_t)) + continue; + + uint32_t deviceId = *(uint32_t *)(binVal.get() + len - sizeof(uint32_t)); + CMStringA str1(FORMAT, "%X", deviceId), str2; + str2.Truncate(int(len) * 2); + bin2hex(binVal, len - sizeof(uint32_t), str2.GetBuffer()); + AddListItem(hwndList, str1, str2); + } } break; } diff --git a/protocols/JabberG/src/jabber_vcard.cpp b/protocols/JabberG/src/jabber_vcard.cpp index 11ff67829c..6bd987f2a0 100644 --- a/protocols/JabberG/src/jabber_vcard.cpp +++ b/protocols/JabberG/src/jabber_vcard.cpp @@ -1174,6 +1174,8 @@ void CJabberProto::SetServerVcard(BOOL bPhotoChanged, wchar_t *szPhotoFileName) ///////////////////////////////////////////////////////////////////////////////////////// +INT_PTR CALLBACK JabberUserOmemoDlgProc(HWND hwndDlg, UINT msg, WPARAM, LPARAM lParam); + void CJabberProto::OnUserInfoInit_VCard(WPARAM wParam, LPARAM) { m_vCardUpdates = 0; @@ -1215,5 +1217,12 @@ void CJabberProto::OnUserInfoInit_VCard(WPARAM wParam, LPARAM) odp.szTab.w = LPGENW("Note"); g_plugin.addUserInfo(wParam, &odp); + if (m_bUseOMEMO) { + odp.pfnDlgProc = JabberUserOmemoDlgProc; + odp.pszTemplate = MAKEINTRESOURCEA(IDD_INFO_OMEMO); + odp.szTab.w = LPGENW("OMEMO"); + g_plugin.addUserInfo(wParam, &odp); + } + SendGetVcard(0); } -- cgit v1.2.3