diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/gpg_wrapper.cpp | 2 | ||||
-rwxr-xr-x | src/messages.cpp | 5 | ||||
-rwxr-xr-x | src/utilities.cpp | 97 | ||||
-rwxr-xr-x | src/utilities.h | 4 |
4 files changed, 88 insertions, 20 deletions
diff --git a/src/gpg_wrapper.cpp b/src/gpg_wrapper.cpp index e420faa..d743af4 100755 --- a/src/gpg_wrapper.cpp +++ b/src/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/src/messages.cpp b/src/messages.cpp index 292ad10..5e3e609 100755 --- a/src/messages.cpp +++ b/src/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); @@ -780,7 +781,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()) { @@ -821,6 +825,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/src/utilities.cpp b/src/utilities.cpp index 3f25394..16a3022 100755 --- a/src/utilities.cpp +++ b/src/utilities.cpp @@ -739,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; @@ -832,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; @@ -871,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); @@ -900,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; } @@ -932,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) @@ -961,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; @@ -985,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 ? @@ -1840,4 +1869,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/src/utilities.h b/src/utilities.h index 30e9f68..739495a 100755 --- a/src/utilities.h +++ b/src/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
|