From afe644994d365883bb683cdaf79e383259632d6e Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Tue, 31 Aug 2010 02:22:05 +0300 Subject: more or less thread save code --- main.cpp | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index ec491aa..1fefc89 100644 --- a/main.cpp +++ b/main.cpp @@ -464,6 +464,9 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP static BOOL CALLBACK DlgProcNewKeyDialog(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { extern HANDLE new_key_hcnt; + extern HANDLE new_key_hcnt_mutex; + HANDLE hContact = new_key_hcnt; + CloseHandle(new_key_hcnt_mutex); void ImportKey(); TCHAR *tmp = NULL; switch (msg) @@ -471,14 +474,14 @@ static BOOL CALLBACK DlgProcNewKeyDialog(HWND hwndDlg, UINT msg, WPARAM wParam, case WM_INITDIALOG: { TranslateDialogDefault(hwndDlg); - TCHAR *tmp = UniGetContactSettingUtf(new_key_hcnt, szGPGModuleName, "GPGPubKey", _T("")); + TCHAR *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); SetDlgItemText(hwndDlg, IDC_MESSAGE, (_tcslen(tmp) > 0)?_T("There is existing key for contact, would you like to replace with new key ?"):_T("New public key was received, do you want to import it?")); - EnableWindow(GetDlgItem(hwndDlg, IDC_IMPORT_AND_USE), DBGetContactSettingByte(new_key_hcnt, szGPGModuleName, "GPGEncryption", 0)?0:1); + EnableWindow(GetDlgItem(hwndDlg, IDC_IMPORT_AND_USE), DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0)?0:1); SetDlgItemText(hwndDlg, ID_IMPORT, (_tcslen(tmp) > 0)?_T("Replace"):_T("Accept")); mir_free(tmp); tmp = new TCHAR [256]; _tcscpy(tmp, _T("Received key from ")); - _tcscat(tmp, (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)new_key_hcnt, (LPARAM)GCDNF_TCHAR)); + _tcscat(tmp, (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, (LPARAM)GCDNF_TCHAR)); SetDlgItemText(hwndDlg, IDC_KEY_FROM, tmp); delete [] tmp; return TRUE; @@ -495,11 +498,11 @@ static BOOL CALLBACK DlgProcNewKeyDialog(HWND hwndDlg, UINT msg, WPARAM wParam, break; case IDC_IMPORT_AND_USE: ImportKey(); - DBWriteContactSettingByte(new_key_hcnt, szGPGModuleName, "GPGEncryption", 1); + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1); void setSrmmIcon(HANDLE hContact); void setClistIcon(HANDLE hContact); - setSrmmIcon(new_key_hcnt); - setClistIcon(new_key_hcnt); + setSrmmIcon(hContact); + setClistIcon(hContact); DestroyWindow(hwndDlg); break; case IDC_IGNORE_KEY: @@ -1094,7 +1097,10 @@ void ImportKey() { extern wstring new_key; extern HANDLE new_key_hcnt; - DBWriteContactSettingTString(new_key_hcnt, szGPGModuleName, "GPGPubKey", new_key.c_str()); + extern HANDLE new_key_hcnt_mutex; + HANDLE hContact = new_key_hcnt; + CloseHandle(new_key_hcnt_mutex); + DBWriteContactSettingTString(hContact, szGPGModuleName, "GPGPubKey", new_key.c_str()); { //gpg execute block wstring cmd; TCHAR tmp2[MAX_PATH] = {0}; @@ -1108,7 +1114,7 @@ void ImportKey() _tcscat(tmp2, _T("\\")); _tcscat(tmp2, _T("temporary_exported.asc")); wfstream f(tmp2, std::ios::out); - ptmp = UniGetContactSettingUtf(new_key_hcnt, szGPGModuleName, "GPGPubKey", _T("")); + ptmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); wstring new_key = ptmp; mir_free(ptmp); f<", s2); @@ -1162,14 +1168,14 @@ void ImportKey() tmp = new char [output.substr(s2,s-s2).length()+1]; strcpy(tmp, output.substr(s2,s-s2).c_str()); mir_utf8decode(tmp, 0); - DBWriteContactSettingString(new_key_hcnt, szGPGModuleName, "KeyComment", tmp); + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyComment", tmp); mir_free(tmp); s+=3; s2 = output.find(">", s); tmp = new char [output.substr(s,s2-s).length()+1]; strcpy(tmp, output.substr(s,s2-s).c_str()); mir_utf8decode(tmp, 0); - DBWriteContactSettingString(new_key_hcnt, szGPGModuleName, "KeyMainEmail", tmp); + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", tmp); mir_free(tmp); } else @@ -1177,7 +1183,7 @@ void ImportKey() tmp = new char [output.substr(s2,s-s2).length()+1]; strcpy(tmp, output.substr(s2,s-s2).c_str()); mir_utf8decode(tmp, 0); - DBWriteContactSettingString(new_key_hcnt, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); mir_free(tmp); } } -- cgit v1.2.3