diff options
-rw-r--r-- | gpg_wrapper.cpp | 22 | ||||
-rw-r--r-- | gpg_wrapper.h | 2 | ||||
-rw-r--r-- | main.cpp | 12 | ||||
-rw-r--r-- | messages.cpp | 57 | ||||
-rw-r--r-- | options.cpp | 22 |
5 files changed, 49 insertions, 66 deletions
diff --git a/gpg_wrapper.cpp b/gpg_wrapper.cpp index b9e9029..53f06dc 100644 --- a/gpg_wrapper.cpp +++ b/gpg_wrapper.cpp @@ -18,7 +18,7 @@ //thx gpg module from Harald Treder, Zakhar V. Bardymov
-pxResult pxExecute(TCHAR *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode)
+pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode)
{
BOOL success;
STARTUPINFO sinfo = {0};
@@ -39,8 +39,7 @@ pxResult pxExecute(TCHAR *acommandline, char *ainput, string *aoutput, LPDWORD a return pxNotFound;
}
}
- TCHAR *home_dir = UniGetContactSettingUtf(NULL, szModuleName, "szHomePath", _T(""));
- TCHAR commandline[4096] = {0};
+ wstring commandline;
sattrs.nLength=sizeof(SECURITY_ATTRIBUTES);
sattrs.bInheritHandle=TRUE;
@@ -70,19 +69,18 @@ pxResult pxExecute(TCHAR *acommandline, char *ainput, string *aoutput, LPDWORD a sinfo.hStdInput=newstdin;
{ //form initial command
- _tcscpy(commandline, _T("\""));
- _tcscat(commandline, bin_path);
- _tcscat(commandline, _T("\""));
- _tcscat(commandline, _T(" --homedir"));
- _tcscat(commandline, _T(" \""));
- _tcscat(commandline, home_dir);
- _tcscat(commandline, _T("\" "));
- _tcscat(commandline, acommandline);
+ commandline += _T("\"");
+ commandline += bin_path;
+ commandline += _T("\" --homedir \"");
+ TCHAR *home_dir = UniGetContactSettingUtf(NULL, szModuleName, "szHomePath", _T(""));
+ commandline += home_dir;
+ commandline += _T("\" ");
+ commandline += *acommandline;
mir_free(bin_path);
mir_free(home_dir);
}
- success = CreateProcess(NULL, commandline, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &sinfo, &pri);
+ success = CreateProcess(NULL, (TCHAR*)commandline.c_str(), NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &sinfo, &pri);
if (!success)
{
diff --git a/gpg_wrapper.h b/gpg_wrapper.h index 99d9da8..9c0d513 100644 --- a/gpg_wrapper.h +++ b/gpg_wrapper.h @@ -14,6 +14,6 @@ typedef enum { }
pxResult;
-pxResult pxExecute(TCHAR *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode);
+pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode);
#endif
\ No newline at end of file @@ -87,9 +87,8 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM DWORD code;
string::size_type p = 0, p2 = 0, stop = 0;
{
- TCHAR cmd[512];
- _tcscpy(cmd, _T("--list-secret-keys"));
- pxExecute(cmd, "", &out, &code);
+ wstring cmd = _T("--list-secret-keys");
+ pxExecute(&cmd, "", &out, &code);
}
cp866_to_cp1251(&out);
while(p != string::npos)
@@ -151,10 +150,9 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM {
string out;
DWORD code;
- TCHAR cmd[64];
- _tcscpy(cmd, _T("--export -a "));
- _tcscat(cmd, fp);
- pxExecute(cmd, "", &out, &code);
+ wstring cmd = _T("--export -a ");
+ cmd += fp;
+ pxExecute(&cmd, "", &out, &code);
DBWriteContactSettingString(NULL, szModuleName, "GPGPubKey", out.c_str());
}
DestroyWindow(hwndDlg);
diff --git a/messages.cpp b/messages.cpp index f6cff09..cb38468 100644 --- a/messages.cpp +++ b/messages.cpp @@ -52,6 +52,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) char *tmp = mir_t2a(str.c_str());
TCHAR *tmp2 = UniGetContactSettingUtf(NULL, szModuleName, "szHomePath", _T(""));
wstring path = tmp2;
+ mir_free(tmp2);
path.append(_T("\\encrypted_data.asc"));
wfstream f(path.c_str(), std::ios::out);
f<<tmp;
@@ -60,34 +61,22 @@ int RecvMsgSvc(WPARAM w, LPARAM l) {
string out;
DWORD code;
- TCHAR cmd[512] = {0};
- _tcscpy(cmd, _T(" -d \""));
- _tcscat(cmd, path.c_str());
- _tcscat(cmd, _T("\" > "));
- wstring path2 = tmp2;
- mir_free(tmp2);
- path2.append(_T("\\decrypted_data"));
- _tcscat(cmd, _T("\""));
- _tcscat(cmd, path2.c_str());
- _tcscat(cmd, _T("\""));
- pxExecute(cmd, "", &out, &code);
- wfstream f(path2.c_str(), std::ios::in);
- str.clear();
- while(!f.eof() && f.is_open())
- {
- TCHAR tmp[128];
- f.getline(tmp, 128);
- str.append(tmp);
- str.append(_T("\n"));
- }
- f.close();
+ wstring cmd;
+ cmd += _T(" -d -a \"");
+ cmd += path;
+ pxExecute(&cmd, "", &out, &code);
DeleteFile(path.c_str());
- DeleteFile(path2.c_str());
- if(str.length() > 0)
+ cp866_to_cp1251(&out);
{
- mir_free((void**)ccs->lParam);
- char *utf = mir_utf8encodeW(str.c_str());
- ccs->lParam = (LPARAM)utf;
+ string::size_type p = out.find(">\"\n") +3;
+ TCHAR *tmp = mir_a2t (out.substr(p).c_str());
+ if(_tcslen(tmp) > 0)
+ {
+ mir_free((void**)ccs->lParam);
+ char *utf = mir_utf8encodeW(tmp);
+ ccs->lParam = (LPARAM)utf;
+ return CallService(MS_PROTO_CHAINRECV, w, (LPARAM)ccs);
+ }
}
}
}
@@ -126,7 +115,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) { //not xmpp, just replace whole message
string out;
DWORD code;
- TCHAR cmd[128];
+ wstring cmd;
wstring path;
char *tmp = UniGetContactSettingUtf(ccs->hContact, szModuleName, "KeyFingerprint", "");
if(strlen(tmp) < 2)
@@ -134,19 +123,19 @@ int SendMsgSvc(WPARAM w, LPARAM l) mir_free(tmp);
return CallService(MS_PROTO_CHAINSEND, w, l);
}
- _tcscpy(cmd, _T("--batch --yes -e -a -r "));
+ cmd += _T("--batch --yes -e -a -r ");
TCHAR *tmp2 = mir_a2t(tmp);
mir_free(tmp);
- _tcscat(cmd, tmp2);
+ cmd += tmp2;
mir_free(tmp2);
- _tcscat(cmd, _T(" \""));
+ cmd += _T(" \"");
tmp2 = UniGetContactSettingUtf(NULL, szModuleName, "szHomePath", _T(""));
path.append(tmp2);
- _tcscat(cmd, tmp2);
+ cmd += tmp2;
mir_free(tmp2);
- _tcscat(cmd, _T("\\exported_data"));
+ cmd += _T("\\exported_data");
path.append(_T("\\exported_data"));
- _tcscat(cmd, _T("\""));
+ cmd += _T("\"");
{
char *tmp = mir_t2a(str.c_str());
wfstream f(path.c_str(), std::ios::out);
@@ -154,7 +143,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) mir_free(tmp);
f.close();
}
- pxExecute(cmd, "", &out, &code);
+ pxExecute(&cmd, "", &out, &code);
DeleteFile(path.c_str());
path.append(_T(".asc"));
wfstream f(path.c_str(), std::ios::in);
diff --git a/options.cpp b/options.cpp index 4f2dbce..906119a 100644 --- a/options.cpp +++ b/options.cpp @@ -139,7 +139,6 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA return TRUE;
case IDC_DELETE_KEY_BUTTON:
{ //gpg execute block
- TCHAR cmd[40960] = {0};
TCHAR tmp2[MAX_PATH] = {0};
TCHAR *ptmp;
char *tmp;
@@ -161,15 +160,14 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA }
if(!keep)
{
+ wstring cmd;
string output;
DWORD exitcode;
- _tcscat(cmd, _T(" --batch"));
- _tcscat(cmd, _T(" --yes"));
- _tcscat(cmd, _T(" --delete-key "));
+ cmd += _T(" --batch --yes --delete-key ");
ptmp = mir_a2t(tmp);
- _tcscat(cmd, ptmp);
+ cmd += ptmp;
mir_free(ptmp);
- pxExecute(cmd, "", &output,&exitcode);
+ pxExecute(&cmd, "", &output,&exitcode);
MessageBoxA(0, "Key removed from GPG keyring", "info", MB_OK);
}
mir_free(tmp);
@@ -351,12 +349,12 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP _tcscpy(tmp, key_buf.substr(ws1,ws2-ws1).c_str());
ListView_SetItemText(hwndList_p, item_num, 2, tmp);
{ //gpg execute block
- TCHAR cmd[4096] = {0};
+ wstring cmd;
TCHAR tmp2[MAX_PATH] = {0};
TCHAR *ptmp;
string output;
DWORD exitcode;
- _tcscat(cmd, _T(" --import "));
+
{
ptmp = UniGetContactSettingUtf(NULL, szModuleName, "szHomePath", _T(""));
_tcscpy(tmp2, ptmp);
@@ -374,11 +372,11 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP }
f<<str.c_str();
f.close();
- _tcscat(cmd, _T(" \""));
- _tcscat(cmd, tmp2);
- _tcscat(cmd, _T("\""));
+ cmd += _T(" --import \"");
+ cmd += tmp2;
+ cmd += _T("\"");
}
- pxExecute(cmd, "", &output, &exitcode);
+ pxExecute(&cmd, "", &output, &exitcode);
cp866_to_cp1251(&output);
{
string::size_type s = output.find("gpg: key ") + strlen("gpg: key ");
|