#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("Services"); //"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; CallService( MS_OPT_ADDPAGE, wParam,( LPARAM )&odp ); odp.ptszTab = _T(LANG_OPT_PROTO); odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_PROTO); odp.pfnDlgProc = DlgProcMirOTROptsProto; CallService( MS_OPT_ADDPAGE, wParam,( LPARAM )&odp ); odp.ptszTab = _T(LANG_OPT_CONTACTS); odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_CONTACTS); odp.pfnDlgProc = DlgProcMirOTROptsContacts; CallService( MS_OPT_ADDPAGE, wParam,( LPARAM )&odp ); odp.ptszTab = _T(LANG_OPT_FINGER); odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_FINGER); odp.pfnDlgProc = DlgProcMirOTROptsFinger; CallService( MS_OPT_ADDPAGE, wParam,( LPARAM )&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) { CallService(MS_SYSTEM_THREAD_PUSH, 0, 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; CallService(MS_SYSTEM_THREAD_POP, 0, 0); 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; PROTOCOLDESCRIPTOR **pppDesc; int ilvItem; LV_ITEM item = {0}; char fprint[45]; TCHAR* temp; //BOOL unicode = ListView_GetUnicodeFormat(lv); CallService(MS_PROTO_ENUMPROTOCOLS, (LPARAM)&num_protocols, (WPARAM)&pppDesc); for(int i = 0; i < num_protocols; i++) { if(pppDesc[i]->type == PROTOTYPE_PROTOCOL && (!g_metaproto || strcmp(pppDesc[i]->szName, g_metaproto) != 0) && (CallProtoService(pppDesc[i]->szName, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IM) == PF1_IM) { //if (unicode) { item.mask = LVIF_TEXT; temp = mir_a2t(pppDesc[i]->szName); item.pszText = temp; ilvItem = ListView_InsertItem(lv, &item); mir_free(temp); ListView_SetItemText(lv, ilvItem, 1, (TCHAR*)policy_to_string(db_dword_get(0,MODULENAME"_ProtoPol", pppDesc[i]->szName, CONTACT_DEFAULT_POLICY)) ); if(otrl_privkey_fingerprint(otr_user_state, fprint, pppDesc[i]->szName, pppDesc[i]->szName)) { temp = mir_a2t(fprint); ListView_SetItemText(lv, ilvItem, 2, temp); mir_free(temp); } /*} else { //using ASCII item.pszText = (TCHAR*)pppDesc[i]->szName; ilvItem = ListView_InsertItem(lv, &item); if(otrl_privkey_fingerprint(otr_user_state, fprint, pppDesc[i]->szName, pppDesc[i]->szName)) { ListView_SetItemText(lv, ilvItem, 2, (TCHAR*)fprint); } }*/ } } } 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_dword_set(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 = ( HANDLE )CallService( MS_DB_CONTACT_FINDFIRST, 0, 0 ); while ( hContact != NULL ) { proto = contact_get_proto(hContact); if(proto && db_byte_get(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_dword_get(hContact, MODULENAME, "Policy", CONTACT_DEFAULT_POLICY)) ); ListView_SetItemText(lv, lvI.iItem, 3, (db_byte_get(hContact, MODULENAME, "HTMLConv", 0))?TranslateT(LANG_YES):TranslateT(LANG_NO) ); } hContact = ( HANDLE )CallService( MS_DB_CONTACT_FINDNEXT,( WPARAM )hContact, 0 ); } } 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_byte_set(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; }