From bd39a0d0ea64bec7b0025d80adb2d1ee8357bea6 Mon Sep 17 00:00:00 2001 From: sje Date: Fri, 16 Feb 2007 03:26:31 +0000 Subject: fix folders implementation show user fingerprints in options git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@122 4f64403b-2f21-0410-a795-97e2b3489a10 --- otr/common.h | 3 +++ otr/dllmain.cpp | 19 +++++++++++++++++++ otr/options.cpp | 41 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/otr/common.h b/otr/common.h index e4c7741..7889661 100644 --- a/otr/common.h +++ b/otr/common.h @@ -67,6 +67,9 @@ extern char fingerprint_store_filename[MAX_PATH]; // read the files named above void ReadPrivkeyFiles(); +// get human readable fingerprint for a contact +bool GetFingerprint(HANDLE hContact, char buff[45]); + #define MS_OTR_MENUSTART "OTR/Start" #define MS_OTR_MENUSTOP "OTR/Stop" diff --git a/otr/dllmain.cpp b/otr/dllmain.cpp index 9fed847..4f19e47 100644 --- a/otr/dllmain.cpp +++ b/otr/dllmain.cpp @@ -74,6 +74,25 @@ HANDLE get_contact(const char *protocol, const char *disp_name) { return 0; } +bool GetFingerprint(HANDLE hContact, char buff[45]) { + char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); + char *uname = (char *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, 0); + if(proto == 0 || uname == 0) return false; + + ConnContext *context = otrl_context_find(otr_user_state, uname, MODULE, proto, FALSE, 0, 0, 0); + if(context == 0) return false; + + if(context->active_fingerprint != 0) { + otrl_privkey_hash_to_human(buff, context->active_fingerprint->fingerprint); + return true; + } else if(context->fingerprint_root.next != 0){ + otrl_privkey_hash_to_human(buff, context->fingerprint_root.next->fingerprint); + return true; + } + + return false; +} + // wish there was an EVENTTYPE_INLINEMSG :) void ShowMessageInline(const HANDLE hContact, const char *msg) { char buff[1024]; diff --git a/otr/options.cpp b/otr/options.cpp index d94afa0..650da18 100644 --- a/otr/options.cpp +++ b/otr/options.cpp @@ -9,6 +9,9 @@ Options options; #include typedef std::map ContactPolicyMap; +typedef std::map ContactFingerprintMap; + +HANDLE hFolderPath = 0; void SetFilenames(const char *path) { strcpy(fingerprint_store_filename, path); @@ -38,7 +41,7 @@ int FoldersChanged(WPARAM wParam, LPARAM lParam) { fgd.nMaxPathSize = sizeof(path); fgd.szPath = path; - CallService(MS_FOLDERS_GET_PATH, 0, (LPARAM)&fgd); + CallService(MS_FOLDERS_GET_PATH, (LPARAM)hFolderPath, (LPARAM)&fgd); SetFilenames(path); ReadPrivkeyFiles(); @@ -54,7 +57,7 @@ void LoadFilenames() { strncpy(fd.szName, "Private Data", FOLDERS_NAME_MAX_SIZE); fd.szFormat = PROFILE_PATH "\\OTR_data"; - CallService(MS_FOLDERS_REGISTER_PATH, 0, (LPARAM)&fd); + hFolderPath = (HANDLE)CallService(MS_FOLDERS_REGISTER_PATH, 0, (LPARAM)&fd); HookEvent(ME_FOLDERS_PATH_CHANGED, FoldersChanged); // get the path - above are only defaults - there may be a different value in the db @@ -126,6 +129,7 @@ void SaveOptions(ContactPolicyMap *contact_policies) { DBWriteContactSettingByte(0, MODULE, "DeleteHistory", options.delete_history ? 1 : 0); } +ContactFingerprintMap strlist; // temp storage for fingerprint string pointers INT_PTR CALLBACK DlgProcOpts1(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch ( msg ) { @@ -199,8 +203,13 @@ INT_PTR CALLBACK DlgProcOpts1(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar lvc.iSubItem = 2; lvc.pszText = Translate("Policy"); - lvc.cx = 100; // width of column in pixels + lvc.cx = 130; // width of column in pixels ListView_InsertColumn(GetDlgItem(hwndDlg, IDC_CLIST), 2, &lvc); + + lvc.iSubItem = 3; + lvc.pszText = Translate("Fingerprint"); + lvc.cx = 300; // width of column in pixels + ListView_InsertColumn(GetDlgItem(hwndDlg, IDC_CLIST), 3, &lvc); } SendMessage(hwndDlg, WMU_REFRESHLIST, 0, 0); @@ -258,8 +267,19 @@ INT_PTR CALLBACK DlgProcOpts1(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar lvI.iSubItem = 2; lvI.pszText = LPSTR_TEXTCALLBACK; ListView_SetItem(GetDlgItem(hwndDlg, IDC_CLIST), &lvI); + + lvI.iSubItem = 3; + lvI.pszText = LPSTR_TEXTCALLBACK; + ListView_SetItem(GetDlgItem(hwndDlg, IDC_CLIST), &lvI); + + // fill fingerprint map + if(strlist.find(hContact) != strlist.end()) free(strlist[hContact]); + char fp[45]; + if(GetFingerprint(hContact, fp)) + strlist[hContact] = strdup(fp); } + hContact = ( HANDLE )CallService( MS_DB_CONTACT_FINDNEXT,( WPARAM )hContact, 0 ); } } @@ -376,6 +396,8 @@ INT_PTR CALLBACK DlgProcOpts1(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar ListView_RedrawItems(GetDlgItem(hwndDlg, IDC_CLIST), lvi.iItem, lvi.iItem); SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + } else if(((LPNMLISTVIEW)lParam)->iSubItem == 3) { + // forget fingerprint? } break; case LVN_GETDISPINFO: @@ -426,7 +448,17 @@ INT_PTR CALLBACK DlgProcOpts1(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar } break; + case 3: + { + HANDLE hContact = (HANDLE)lvi.lParam; + if(strlist.find(hContact) != strlist.end()) + ((NMLVDISPINFO *)lParam)->item.pszText = strlist[hContact]; + else + ((NMLVDISPINFO *)lParam)->item.pszText = Translate("None"); + } + break; } + } break; } @@ -459,6 +491,9 @@ INT_PTR CALLBACK DlgProcOpts1(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar ContactPolicyMap *contact_policies = (ContactPolicyMap *)GetWindowLong(hwndDlg, GWL_USERDATA); SetWindowLong(hwndDlg, GWL_USERDATA, 0); delete contact_policies; + + for(std::map::iterator i = strlist.begin(); i != strlist.end(); i++) + free(i->second); } } -- cgit v1.2.3