summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2012-12-24 00:58:01 +0200
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2012-12-24 00:58:01 +0200
commitb0b170cb9f6159b8cfc4d52da53b1fab4ee5035e (patch)
treec6633250a0444af5b7753523a4c0341d6a8427a2
parent70db5d1f4792f41f34c232c97ac30b45672e0f67 (diff)
merged fixes from miranda_ng main repo
-rwxr-xr-xgpg_wrapper.cpp2
-rwxr-xr-xmain.cpp36
-rwxr-xr-xmessages.cpp14
-rwxr-xr-xutilities.cpp100
-rwxr-xr-xutilities.h4
5 files changed, 132 insertions, 24 deletions
diff --git a/gpg_wrapper.cpp b/gpg_wrapper.cpp
index e420faa..d743af4 100755
--- a/gpg_wrapper.cpp
+++ b/gpg_wrapper.cpp
@@ -140,6 +140,8 @@ pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD
storeOutput(readstdout,aoutput);
+ fix_line_term(*aoutput);
+
debuglog<<time_str()<<": gpg out: "<<aoutput->c_str();
WaitForSingleObject(pri.hProcess,INFINITE);
diff --git a/main.cpp b/main.cpp
index b38d57c..9918b66 100755
--- a/main.cpp
+++ b/main.cpp
@@ -71,6 +71,12 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR
col.fmt = LVCFMT_LEFT;
col.cx = 30;
ListView_InsertColumn(hwndList, 4, &col);
+ ZeroMemory(&col,sizeof(col));
+ col.pszText = TranslateT("Accounts");
+ col.mask = LVCF_TEXT | LVCF_WIDTH;
+ col.fmt = LVCFMT_LEFT;
+ col.cx = 30;
+ ListView_InsertColumn(hwndList, 5, &col);
ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_FULLROWSELECT);
int i = 1, iRow = 0;
{
@@ -121,6 +127,7 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR
p = out.find(" ", p2);
tmp = mir_wstrdup(toUTF16(out.substr(p2,p-p2)).c_str());
ListView_SetItemText(hwndList, iRow, 0, tmp);
+ std::wstring key_id = tmp;
mir_free(tmp);
p = out.find("uid ", p);
p2 = out.find_first_not_of(" ", p+5);
@@ -144,6 +151,33 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR
ListView_SetColumnWidth(hwndList, 2, LVSCW_AUTOSIZE);
ListView_SetColumnWidth(hwndList, 3, LVSCW_AUTOSIZE);
ListView_SetColumnWidth(hwndList, 4, LVSCW_AUTOSIZE);
+ { //get accounts
+ int count = 0;
+ PROTOACCOUNT **accounts;
+ ProtoEnumAccounts(&count, &accounts);
+ std::wstring accs;
+ for(int i = 0; i < count; i++)
+ {
+ std::string setting = toUTF8(accounts[i]->tszAccountName);
+ setting += "(";
+ setting += accounts[i]->szModuleName;
+ setting += ")" ;
+ setting += "_KeyID";
+ TCHAR *str = UniGetContactSettingUtf(NULL, szGPGModuleName, setting.c_str(), _T(""));
+ if(key_id == str)
+ {
+ if(accs.empty())
+ accs += accounts[i]->tszAccountName;
+ else
+ {
+ accs += _T(",");
+ accs += accounts[i]->tszAccountName;
+ }
+ }
+ }
+ ListView_SetItemText(hwndList, iRow, 5, (TCHAR*)accs.c_str());
+ ListView_SetColumnWidth(hwndList, 5, LVSCW_AUTOSIZE);
+ }
i++;
}
}
@@ -1123,7 +1157,7 @@ static INT_PTR CALLBACK DlgProcNewKeyDialog(HWND hwndDlg, UINT msg, WPARAM wPara
case WM_INITDIALOG:
{
hContact = new_key_hcnt;
- new_key_hcnt_mutex.unlock();
+ //new_key_hcnt_mutex.unlock();
SetWindowPos(hwndDlg, 0, new_key_rect.left, new_key_rect.top, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW);
TranslateDialogDefault(hwndDlg);
TCHAR *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T(""));
diff --git a/messages.cpp b/messages.cpp
index 7eb598c..e1081b6 100755
--- a/messages.cpp
+++ b/messages.cpp
@@ -333,6 +333,7 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags,
}
else
{
+ fix_line_term(str);
if(bAppendTags)
{
str.insert(0, inopentag);
@@ -410,7 +411,11 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
_tcscpy(tmp2, ptmp);
mir_free(ptmp);
_tcscat(tmp2, _T("\\"));
- _tcscat(tmp2, _T("temporary_exported.asc"));
+ TCHAR *tmp3 = mir_a2t(get_random(5).c_str());
+ _tcscat(tmp2, tmp3);
+ _tcscat(tmp2, _T(".asc"));
+ mir_free(tmp3);
+ //_tcscat(tmp2, _T("temporary_exported.asc"));
DeleteFile(tmp2);
wfstream f(tmp2, std::ios::out);
while(!f.is_open())
@@ -443,6 +448,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
}
if(result == pxNotFound)
return 1;
+ DeleteFile(tmp2);
//TODO: check gpg output for errors
{
char *tmp = NULL;
@@ -543,7 +549,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
s2 += _tcslen(_T("-----END PGP PRIVATE KEY BLOCK-----"));
}
new_key.append(str.substr(s1,s2-s1));
- new_key_hcnt_mutex.lock();
+ //new_key_hcnt_mutex.lock();
new_key_hcnt = ccs->hContact;
ShowNewKeyDialog();
HistoryLog(ccs->hContact, db_event(msg, 0, 0, dbflags));
@@ -777,7 +783,10 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags)
path.append(_T(".asc"));
wfstream f(path.c_str(), std::ios::in | std::ios::ate | std::ios::binary);
while(!f.is_open())
+ {
+ boost::this_thread::sleep(boost::posix_time::milliseconds(100));
f.open(path.c_str(), std::ios::in | std::ios::ate | std::ios::binary);
+ }
str.clear();
if(f.is_open())
{
@@ -818,6 +827,7 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags)
HistoryLog(hContact, db_event((char*)str_event.c_str(), 0,0, dbflags|DBEF_SENT));
if(!(flags & PREF_UTF))
flags |= PREF_UTF;
+ fix_line_term(str);
sent_msgs.push_back((HANDLE)CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)toUTF8(str).c_str()));
mir_free(msg);
return;
diff --git a/utilities.cpp b/utilities.cpp
index 8f38801..c305216 100755
--- a/utilities.cpp
+++ b/utilities.cpp
@@ -321,6 +321,7 @@ int onProtoAck(WPARAM w, LPARAM l)
}
if(_tcsstr(filename, _T(".gpg"))) //decrypt it
{ //process encrypted file
+ HistoryLog(ack->hContact, db_event("Recieved encrypted file, trying to decrypt", 0,0, 0));
if(_waccess(f->tszCurrentFile, 0) == -1)
{
if(errno == ENOENT)
@@ -567,7 +568,7 @@ int onSendFile(WPARAM w, LPARAM l)
CCSDATA *ccs=(CCSDATA*)l;
if(isContactSecured(ccs->hContact))
{
-
+ HistoryLog(ccs->hContact, db_event(Translate("encrypting file for transfer"), 0, 0, DBEF_SENT));
DWORD flags = (DWORD)ccs->wParam; //check for PFTS_UNICODE here
int i;
// if(flags & PFTS_UNICODE) //this does not work ....
@@ -738,13 +739,10 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU
p1 = data.find(_T("Encoding: "), p1);
p1 = data.find(_T("\n"), p1);
}
- p1+=2;
+ p1+=3;
wstring::size_type p2 = data.find(_T("-----END PGP MESSAGE-----"));
- wstring data2 = data.substr(p1, p2-p1);
- for(std::wstring::size_type i = data2.find(_T("\r")); i != std::wstring::npos; i = data2.find(_T("\r"), i+1))
- data2.erase(i, 1);
- for(std::wstring::size_type i = data2.find(_T("\n")); i != std::wstring::npos; i = data2.find(_T("\n"), i+1))
- data2.erase(i, 1);
+ wstring data2 = data.substr(p1, p2-p1-2);
+ strip_line_term(data2);
HXML encrypted_data = xi.addChild(node, _T("x"), data2.c_str());
xi.addAttr(encrypted_data, _T("xmlns"), _T("jabber:x:encrypted"));
return FALSE;
@@ -831,7 +829,7 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU
cmd += _T(" --default-key ");
cmd += path_c;
mir_free(path_c);
- cmd += _T(" --batch --yes -a -s \"");
+ cmd += _T(" --batch --yes -a -b -s \"");
cmd += path_out;
cmd += _T("\" ");
gpg_execution_params params;
@@ -870,9 +868,9 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU
debuglog<<time_str()<<": info: Failed to read prescense sign from file\n";
return FALSE;
}
- if(data.find(_T("-----BEGIN PGP MESSAGE-----")) != wstring::npos && data.find(_T("-----END PGP MESSAGE-----")) != wstring::npos)
+ if(data.find(_T("-----BEGIN PGP SIGNATURE-----")) != wstring::npos && data.find(_T("-----END PGP SIGNATURE-----")) != wstring::npos)
{
- wstring::size_type p1 = data.find(_T("-----BEGIN PGP MESSAGE-----")) + _tcslen(_T("-----BEGIN PGP MESSAGE-----"));
+ wstring::size_type p1 = data.find(_T("-----BEGIN PGP SIGNATURE-----")) + _tcslen(_T("-----BEGIN PGP SIGNATURE-----"));
if(data.find(_T("Version: "), p1) != wstring::npos)
{
p1 = data.find(_T("Version: "), p1);
@@ -899,9 +897,14 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU
}
else
p1+=1;
- wstring::size_type p2 = data.find(_T("-----END PGP MESSAGE-----"));
- HXML encrypted_data = xi.addChild(node, _T("x"), data.substr(p1, p2-p1).c_str());
- xi.addAttr(encrypted_data, _T("xmlns"), _T("jabber:x:signed"));
+ p1++;
+ wstring::size_type p2 = data.find(_T("-----END PGP SIGNATURE-----"));
+ {
+ std::wstring tmp = data.substr(p1, p2-p1);
+ strip_line_term(tmp);
+ HXML encrypted_data = xi.addChild(node, _T("x"), tmp.c_str());
+ xi.addAttr(encrypted_data, _T("xmlns"), _T("jabber:x:signed"));
+ }
}
return FALSE;
}
@@ -931,23 +934,46 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi
LPCTSTR value = xi.getAttrValue(local_node, name);
if(_tcsstr(value, _T("jabber:x:signed")))
{
+ std::wstring status_str;
+ HXML local_node2 = node;
+ for(int n = 0; n <= xi.getChildCount(node); n++)
+ {
+ LPCTSTR nodename2 = xi.getName(local_node2);
+ if(_tcsstr(nodename2, _T("status")))
+ {
+ LPCTSTR status = xi.getText(local_node2);
+ status_str = status;
+ break;
+ }
+ local_node2 = xi.getChild(node, n);
+ }
LPCTSTR data = xi.getText(local_node);
- wstring sign = _T("-----BEGIN PGP MESSAGE-----\n\n");
- wstring file = toUTF16(get_random(10));
+ wstring sign = _T("-----BEGIN PGP SIGNATURE-----\n\n");
+ wstring file = toUTF16(get_random(10)), status_file = toUTF16(get_random(10));
sign += data;
- sign += _T("\n-----END PGP MESSAGE-----\n");
+ sign += _T("\n-----END PGP SIGNATURE-----\n");
TCHAR *path_c = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T(""));
- wstring path_out = path_c;
+ wstring path_out = path_c, status_file_out = path_c;
mir_free(path_c);
- path_out += _T("\\tmp\\");
+ path_out += L"\\tmp\\";
path_out += file;
+ path_out += L".sig";
+ status_file_out += L"\\tmp\\";
+ status_file_out += status_file;
+ status_file_out += L".status";
// sign_file_mutex.lock();
DeleteFile(path_out.c_str());
+ DeleteFile(status_file_out.c_str());
wfstream f(path_out.c_str(), std::ios::out);
while(!f.is_open())
f.open(path_out.c_str(), std::ios::out);
f<<toUTF8(sign).c_str();
f.close();
+ f.open(status_file_out.c_str(), std::ios::out);
+ while(!f.is_open())
+ f.open(status_file_out.c_str(), std::ios::out);
+ f<<toUTF8(status_str).c_str();
+ f.close();
if(_waccess(path_out.c_str(), 0) == -1)
{
if(errno == ENOENT)
@@ -960,9 +986,12 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi
{ //gpg
string out;
DWORD code;
- wstring cmd = _T(" --verify -a \"");
+ wstring cmd = L" --verify -a \"";
cmd += path_out;
- cmd += _T("\"");
+ cmd += L"\"";
+ cmd += L" \"";
+ cmd += status_file_out;
+ cmd += L"\"";
gpg_execution_params params;
pxResult result;
params.cmd = &cmd;
@@ -984,6 +1013,7 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi
return FALSE;
}
DeleteFile(path_out.c_str());
+ DeleteFile(status_file_out.c_str());
if(out.find("key ID ") != string::npos)
{
//need to get hcontact here, i can get jid from hxml, and get handle from jid, maybe exists better way ?
@@ -1838,4 +1868,32 @@ INT_PTR ImportGpGKeys(WPARAM w, LPARAM l)
mir_snprintf(msg, 511, "we have succesfully processed %d keys", processed_keys);
MessageBoxA(NULL, msg, Translate("Keys import result"), MB_OK);
return 0;
-} \ No newline at end of file
+}
+
+void fix_line_term(std::string &s)
+{
+ for(std::string::size_type s1 = s.find("\r\r", 0); s1 != string::npos; s1 = s.find("\r\r", s1))
+ s.erase(s1, 1);
+}
+
+void fix_line_term(std::wstring &s)
+{
+ for(std::wstring::size_type s1 = s.find(_T("\r\r"), 0); s1 != wstring::npos; s1 = s.find(_T("\r\r"), s1))
+ s.erase(s1, 1);
+}
+
+void strip_line_term(std::wstring &s)
+{
+ for(std::wstring::size_type i = s.find(_T("\r")); i != std::wstring::npos; i = s.find(_T("\r"), i+1))
+ s.erase(i, 1);
+ for(std::wstring::size_type i = s.find(_T("\n")); i != std::wstring::npos; i = s.find(_T("\n"), i+1))
+ s.erase(i, 1);
+}
+
+void strip_line_term(std::string &s)
+{
+ for(std::string::size_type i = s.find("\r"); i != std::string::npos; i = s.find("\r", i+1))
+ s.erase(i, 1);
+ for(std::string::size_type i = s.find("\n"); i != std::string::npos; i = s.find("\n", i+1))
+ s.erase(i, 1);
+}
diff --git a/utilities.h b/utilities.h
index 30e9f68..739495a 100755
--- a/utilities.h
+++ b/utilities.h
@@ -100,5 +100,9 @@ public:
}
};
void HistoryLog(HANDLE, db_event);
+void fix_line_term(std::string &s);
+void fix_line_term(std::wstring &s);
+void strip_line_term(std::wstring &s);
+void strip_line_term(std::string &s);
#endif