summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gpg_wrapper.cpp5
-rw-r--r--main.cpp36
-rw-r--r--messages.cpp6
3 files changed, 32 insertions, 15 deletions
diff --git a/gpg_wrapper.cpp b/gpg_wrapper.cpp
index db7d134..1907ed1 100644
--- a/gpg_wrapper.cpp
+++ b/gpg_wrapper.cpp
@@ -18,9 +18,12 @@
//thx gpg module from Harald Treder, Zakhar V. Bardymov
+HANDLE gpg_mutex = NULL;
+
pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result)
{
+ WaitForSingleObject(gpg_mutex, INFINITE);
extern logtofile debuglog;
BOOL success;
STARTUPINFO sinfo = {0};
@@ -89,6 +92,7 @@ pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD
debuglog<<"in: "<<commandline<<"\n";
+ gpg_mutex = CreateMutex(NULL, FALSE, NULL);
setlocale( LC_ALL, "C" );
success = CreateProcess(NULL, (TCHAR*)commandline.c_str(), NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &sinfo, &pri);
@@ -119,6 +123,7 @@ pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD
inputpos+=transfered;
Sleep(200);
}
+ CloseHandle(gpg_mutex);
storeOutput(readstdout,aoutput);
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<<new_key.c_str();
@@ -1136,23 +1142,23 @@ void ImportKey()
MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
return;
}
- DBDeleteContactSetting(new_key_hcnt, szGPGModuleName, "bAlwatsTrust");
+ DBDeleteContactSetting(hContact, szGPGModuleName, "bAlwatsTrust");
{
char *tmp = NULL;
string::size_type s = output.find("gpg: key ") + strlen("gpg: key ");
string::size_type s2 = output.find(":", s);
- DBWriteContactSettingString(new_key_hcnt, szGPGModuleName, "KeyID", output.substr(s,s2-s).c_str());
+ DBWriteContactSettingString(hContact, szGPGModuleName, "KeyID", output.substr(s,s2-s).c_str());
s2+=2;
s = output.find("\"", s2)-1;
if(s != s2-1)
- DBWriteContactSettingString(new_key_hcnt, szGPGModuleName, "KeyType", output.substr(s2,s-s2).c_str());
+ DBWriteContactSettingString(hContact, szGPGModuleName, "KeyType", output.substr(s2,s-s2).c_str());
s+=2;
if((s2 = output.find("(", s)) == string::npos)
s2 = output.find("<", s);
tmp = new char [output.substr(s,s2-s-1).length()+1];
strcpy(tmp, output.substr(s,s2-s-1).c_str());
mir_utf8decode(tmp, 0);
- DBWriteContactSettingString(new_key_hcnt, szGPGModuleName, "KeyMainName", tmp);
+ DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainName", tmp);
mir_free(tmp);
if((s = output.find(")", s2)) == string::npos)
s = output.find(">", 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);
}
}
diff --git a/messages.cpp b/messages.cpp
index 8a909c1..15972e4 100644
--- a/messages.cpp
+++ b/messages.cpp
@@ -19,6 +19,7 @@
wstring new_key;
HANDLE new_key_hcnt = NULL;
+HANDLE new_key_hcnt_mutex = NULL;
bool _terminate = false;
BOOL isProtoMetaContacts(HANDLE hContact);
@@ -78,6 +79,8 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
s2 += _tcslen(_T("-----END PGP PRIVATE KEY BLOCK-----"));
}
new_key.append(str.substr(s1,s2-s1));
+ WaitForSingleObject(new_key_hcnt_mutex, INFINITE);
+ new_key_hcnt_mutex = CreateMutex(NULL, FALSE, NULL);
new_key_hcnt = hContact;
ShowNewKeyDialog();
return CallService(MS_PROTO_CHAINRECV, w, l);
@@ -204,6 +207,8 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
DBWriteContactSettingString(hContact, szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str());
}
void ShowLoadKeyPasswordWindow();
+ WaitForSingleObject(new_key_hcnt_mutex, INFINITE);
+ new_key_hcnt_mutex = CreateMutex(NULL, FALSE, NULL);
new_key_hcnt = hContact;
ShowLoadKeyPasswordWindow();
wstring cmd2 = cmd;
@@ -513,6 +518,7 @@ int TestHook(WPARAM w, LPARAM l)
static BOOL CALLBACK DlgProcKeyPassword(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
HANDLE hContact = new_key_hcnt;
+ CloseHandle(new_key_hcnt_mutex);
TCHAR *tmp = NULL;
char *inkeyid = UniGetContactSettingUtf(hContact, szGPGModuleName, "InKeyID", "");
switch (msg)