From edf0d7a9790d958023fe5280f0ee2097e2b4d7f5 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Tue, 22 Mar 2011 03:29:51 +0200 Subject: modified: utilities.cpp --- utilities.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utilities.cpp b/utilities.cpp index 0ba8e12..3168f7f 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -439,10 +439,10 @@ int onSendFile(WPARAM w, LPARAM l) } } } -// mir_free(file[i]); -// file[i] = mir_tstrdup(path_out.c_str()); - mir_realloc(file[i], path_out.length()*sizeof(TCHAR)+1); - _tcscpy(file[i], path_out.c_str()); + mir_free(file[i]); + file[i] = mir_tstrdup(path_out.c_str()); +// mir_realloc(file[i], path_out.length()*sizeof(TCHAR)+1); +// _tcscpy(file[i], path_out.c_str()); delete [] file_out; transfers.push_back(path_out); } -- cgit v1.2.3 From 56581778c96e4955f90b7f492d1419503f12fd94 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Tue, 22 Mar 2011 05:09:10 +0200 Subject: password checking in file sending code --- utilities.cpp | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 99 insertions(+), 15 deletions(-) diff --git a/utilities.cpp b/utilities.cpp index 3168f7f..05d0bde 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -314,7 +314,7 @@ int onProtoAck(WPARAM w, LPARAM l) if(_waccess(f->tszCurrentFile, 0) == -1) { if(errno == ENOENT) - break; + return 0; } string out; DWORD code; @@ -326,7 +326,7 @@ int onProtoAck(WPARAM w, LPARAM l) if(_waccess(file.c_str(), 0) != -1) { if(MessageBox(0, _T("Target file exists, do you want to replace it ?"), _T("Warning"), MB_YESNO) == IDNO) - break; + return 0; } DeleteFile(file.c_str()); file.insert(0, _T("\"")); @@ -335,6 +335,43 @@ int onProtoAck(WPARAM w, LPARAM l) cmd += _T(" -d \""); cmd += filename; cmd += _T("\""); + extern TCHAR *password; + { // password + TCHAR *pass = NULL; + char *keyid = UniGetContactSettingUtf(ccs->hContact, szGPGModuleName, "KeyID", ""); + if(strlen(keyid) > 0) + { + string dbsetting = "szKey_"; + dbsetting += keyid; + dbsetting += "_Password"; + pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), _T("")); + if(_tcslen(pass) > 0) + debuglog<hContact, GCDNF_TCHAR)<<" with password\n"; + } + else + { + pass = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", _T("")); + if(_tcslen(pass) > 0) + debuglog<hContact, GCDNF_TCHAR)<<" with password\n"; + } + if(_tcslen(pass) > 0) + { + cmd += _T("--passphrase \""); + cmd += pass; + cmd += _T("\" "); + } + else if(password) + { + debuglog<hContact, GCDNF_TCHAR)<<" with password\n"; + cmd += _T("--passphrase \""); + cmd += password; + cmd += _T("\" "); + } + else + debuglog<hContact, GCDNF_TCHAR)<<" with out password\n"; + mir_free(pass); + mir_free(keyid); + } gpg_execution_params params; params.cmd = &cmd; params.useless = ""; @@ -346,6 +383,57 @@ int onProtoAck(WPARAM w, LPARAM l) { delete gpg_thread; debuglog<hContact, GCDNF_TCHAR)<<" password needed, trying to get one\n"; + if(_terminate) + break; + { //save inkey id + string::size_type s = out.find(" encrypted with "); + s = out.find(" ID ", s); + s += strlen(" ID "); + string::size_type s2 = out.find(",",s); + DBWriteContactSettingString(metaGetCurrent(ccs->hContact), szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str()); + } + void ShowLoadKeyPasswordWindow(); + new_key_hcnt_mutex.lock(); + new_key_hcnt = ccs->hContact; + ShowLoadKeyPasswordWindow(); + wstring cmd2 = cmd; + if(password) + { + debuglog<hContact, GCDNF_TCHAR)<<"\n"; + wstring tmp = _T("--passphrase \""); + tmp += password; + tmp += _T("\" "); + cmd2.insert(0, tmp); + } + out.clear(); + gpg_execution_params params; + pxResult result; + params.cmd = &cmd2; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + gpg_thread = gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread->timed_join(boost::posix_time::seconds(10))) + { + delete gpg_thread; + debuglog<hContact, szGPGModuleName, "KeyID", ""); wstring cmd = _T("--batch --yes -r "); + char *keyid = UniGetContactSettingUtf(ccs->hContact, szGPGModuleName, "KeyID", ""); if(DBGetContactSettingByte(ccs->hContact, szGPGModuleName, "bAlwaysTrust", 0)) cmd += _T("--trust-model always "); TCHAR *szKeyid = mir_a2t(keyid); @@ -411,11 +499,13 @@ int onSendFile(WPARAM w, LPARAM l) params.out = &out; params.code = &code; params.result = &result; + mir_free(keyid); boost::thread *gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); if(!gpg_thread->timed_join(boost::posix_time::seconds(180))) { delete gpg_thread; debuglog<hContact, szGPGModuleName, "bAlwaysTrust", 1); cmd.insert(0, _T("--trust-model always ")); - gpg_execution_params params; - pxResult result; - params.cmd = &cmd; - params.useless = ""; - params.out = &out; - params.code = &code; - params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(180))) + gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread->timed_join(boost::posix_time::seconds(180))) { - gpg_thread.~thread(); + delete gpg_thread; debuglog< Date: Tue, 22 Mar 2011 08:23:16 +0200 Subject: extended threading (test) --- messages.cpp | 177 ++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 113 insertions(+), 64 deletions(-) diff --git a/messages.cpp b/messages.cpp index dbb87c2..b37bbd0 100644 --- a/messages.cpp +++ b/messages.cpp @@ -23,24 +23,13 @@ boost::mutex new_key_hcnt_mutex; bool _terminate = false; int returnNoError(HANDLE hContact); -int RecvMsgSvc(WPARAM w, LPARAM l) +int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) { - CCSDATA *ccs = (CCSDATA*)l; - if (!ccs) - return CallService(MS_PROTO_CHAINRECV, w, l); - PROTORECVEVENT *pre = (PROTORECVEVENT*)(ccs->lParam); - if (!pre) - return CallService(MS_PROTO_CHAINRECV, w, l); - char *msg = pre->szMessage; - if (!msg) - return CallService(MS_PROTO_CHAINRECV, w, l); - HANDLE hContact = ccs->hContact; - { //check for gpg related data wstring str = toUTF16(msg); wstring::size_type s1 = wstring::npos, s2 = wstring::npos; - if((str.find(_T("-----PGP KEY RESPONSE-----")) != wstring::npos) && !metaIsProtoMetaContacts(ccs->hContact)) + if((str.find(_T("-----PGP KEY RESPONSE-----")) != wstring::npos) && !metaIsProtoMetaContacts(hContact)) { s2 = str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")); s1 = str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); @@ -85,10 +74,14 @@ int RecvMsgSvc(WPARAM w, LPARAM l) { gpg_thread.~thread(); debuglog<szMessage; - mir_free((void**)pre->szMessage); + string str = msg; str.insert(0, "Received unencrypted message:\n"); debuglog<szMessage = tmp; - return CallService(MS_PROTO_CHAINRECV, w, (LPARAM)ccs); + HistoryLog(hContact, tmp, EVENTTYPE_MESSAGE, flags); + mir_free(tmp); + mir_free(msg); + return 0; } } } @@ -486,12 +502,14 @@ int RecvMsgSvc(WPARAM w, LPARAM l) } if(str.empty()) { - string str = pre->szMessage; - mir_free((void**)pre->szMessage); + string str = msg; str.insert(0, "Failed to decrypt GPG encrypted message.\nMessage body for manual decryption:\n"); debuglog<szMessage = mir_strdup(str.c_str()); - return CallService(MS_PROTO_CHAINRECV, w, (LPARAM)ccs); + char *tmp = mir_strdup(str.c_str()); + HistoryLog(hContact, tmp, EVENTTYPE_MESSAGE, flags); + mir_free(tmp); + mir_free(msg); + return 0; } else { @@ -508,9 +526,13 @@ int RecvMsgSvc(WPARAM w, LPARAM l) mir_free(msg); return 1; } - mir_free((void**)pre->szMessage); - pre->szMessage = mir_strdup(toUTF8(str).c_str()); - return CallService(MS_PROTO_CHAINRECV, w, (LPARAM)ccs); + char *tmp = mir_strdup(toUTF8(str).c_str()); + if(!(flags & DBEF_UTF)) + flags |= DBEF_UTF; + HistoryLog(hContact, tmp, EVENTTYPE_MESSAGE, flags); + mir_free(tmp); + mir_free(msg); + return 0; } } } @@ -526,31 +548,35 @@ int RecvMsgSvc(WPARAM w, LPARAM l) return 1; } string str = msg; - mir_free((void**)pre->szMessage); str.insert(0, "Received unencrypted message:\n"); - pre->szMessage = mir_strdup(str.c_str()); - return CallService(MS_PROTO_CHAINRECV, w, (LPARAM)ccs); + char *tmp = mir_strdup(str.c_str()); + HistoryLog(hContact, tmp, EVENTTYPE_MESSAGE, flags); + mir_free(tmp); + mir_free(msg); + return 0; } - return CallService(MS_PROTO_CHAINRECV, w, l); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, flags); + mir_free(msg); + return 0; } -int SendMsgSvc(WPARAM w, LPARAM l) +int RecvMsgSvc(WPARAM w, LPARAM l) { CCSDATA *ccs = (CCSDATA*)l; if (!ccs) - return CallService(MS_PROTO_CHAINSEND, w, l); - - char *msg = (char*)(ccs->lParam); + return CallService(MS_PROTO_CHAINRECV, w, l); + PROTORECVEVENT *pre = (PROTORECVEVENT*)(ccs->lParam); + if (!pre) + return CallService(MS_PROTO_CHAINRECV, w, l); + char *msg = mir_strdup(pre->szMessage); if (!msg) - return CallService(MS_PROTO_CHAINSEND, w, l); - if(strstr(msg,"-----BEGIN PGP MESSAGE-----")) //metecontacts .... %) - return CallService(MS_PROTO_CHAINSEND, w, l); - HANDLE hContact = ccs->hContact; - if(metaIsProtoMetaContacts(hContact)) - { - hcontact_data[ccs->hContact].msgs_to_ignore.push_back((char*)ccs->lParam); - return CallService(MS_PROTO_CHAINSEND, w, l); - } + return CallService(MS_PROTO_CHAINRECV, w, l); + boost::thread *thr = new boost::thread(boost::bind(RecvMsgSvc_func, ccs->hContact, msg, ccs->wParam)); + return returnNoError(ccs->hContact); +} + +int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) +{ if(!isContactHaveKey(hContact) && bAutoExchange && !strstr(msg, "-----PGP KEY REQUEST-----") && !strstr(msg, "-----BEGIN PGP PUBLIC KEY BLOCK-----") && isGPGConfigured()) { void send_encrypted_msgs_thread(HANDLE hContact); @@ -564,7 +590,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) strcpy(cap.caps, "GPG AutoExchange"); if(CallService("ICQ"PS_ICQ_CHECKCAPABILITY, (WPARAM)hContact, (LPARAM)&cap)) { - CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"-----PGP KEY REQUEST-----"); + CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)"-----PGP KEY REQUEST-----"); hcontact_data[hContact].msgs_to_ignore.push_back(msg); hcontact_data[hContact].msgs_to_send.push_back(msg); boost::thread *thr = new boost::thread(boost::bind(send_encrypted_msgs_thread, hContact)); @@ -595,7 +621,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) mir_free(caps); if(str.find(_T("GPG_Key_Auto_Exchange:0")) != string::npos) { - CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"-----PGP KEY REQUEST-----"); + CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)"-----PGP KEY REQUEST-----"); hcontact_data[hContact].msgs_to_ignore.push_back(msg); hcontact_data[hContact].msgs_to_send.push_back(msg); boost::thread *thr = new boost::thread(boost::bind(send_encrypted_msgs_thread, hContact)); @@ -607,7 +633,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) } } if(!isContactSecured(hContact)) - return CallService(MS_PROTO_CHAINSEND, w, l); + return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); { //encrypt data here wstring str; @@ -636,7 +662,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) { mir_free(tmp); HistoryLog(hContact, "Failed to encrypt message with GPG", EVENTTYPE_MESSAGE, DBEF_SENT); - return CallService(MS_PROTO_CHAINSEND, w, l); + return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); } if(!bJabberAPI || !bIsMiranda09) //force jabber to handle encrypted message by itself cmd += _T("--comment \"\" --no-version "); @@ -675,10 +701,10 @@ int SendMsgSvc(WPARAM w, LPARAM l) { gpg_thread.~thread(); debuglog<lParam; + string str_event = msg; if(bAppendTags) { //utf8 tag will cause problems here str_event.insert(0, toUTF8(outopentag)); @@ -755,11 +781,34 @@ int SendMsgSvc(WPARAM w, LPARAM l) return returnNoError(hContact); } if(bAppendTags) - hcontact_data[hContact].msgs_to_tag.push_back((char*)ccs->lParam); - ccs->lParam = (LPARAM)mir_strdup(toUTF8(str).c_str()); + hcontact_data[hContact].msgs_to_tag.push_back(msg); + mir_free(msg); + msg = mir_strdup(toUTF8(str).c_str()); } } - return CallService(MS_PROTO_CHAINSEND, w, l); + if(!(flags & PREF_UTF)) + flags |= PREF_UTF; + CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); + return 0; +} + +int SendMsgSvc(WPARAM w, LPARAM l) +{ + CCSDATA *ccs = (CCSDATA*)l; + if (!ccs) + return CallService(MS_PROTO_CHAINSEND, w, l); + char *msg = mir_strdup((char*)(ccs->lParam)); + if (!msg) + return CallService(MS_PROTO_CHAINSEND, w, l); + if(strstr(msg,"-----BEGIN PGP MESSAGE-----")) + return CallService(MS_PROTO_CHAINSEND, w, l); + if(metaIsProtoMetaContacts(ccs->hContact)) + { + hcontact_data[ccs->hContact].msgs_to_ignore.push_back((char*)msg); + return CallService(MS_PROTO_CHAINSEND, w, l); + } + boost::thread *thr = new boost::thread(boost::bind(SendMsgSvc_func, ccs->hContact, msg, (DWORD)ccs->wParam)); + return returnNoError(ccs->hContact); } int HookSendMsg(WPARAM w, LPARAM l) -- cgit v1.2.3 From 59822f2c393d553d43adb4a5eb8daf77609063f2 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Tue, 22 Mar 2011 14:09:37 +0200 Subject: new threading code (part 2, usable) --- main.h | 2 +- messages.cpp | 490 +++++++++++++++++++++++++++---------------------------- metacontacts.cpp | 4 +- utilities.cpp | 7 +- 4 files changed, 246 insertions(+), 257 deletions(-) diff --git a/main.h b/main.h index 102821c..e4ff5f2 100644 --- a/main.h +++ b/main.h @@ -18,7 +18,7 @@ struct contact_data { - list msgs_to_tag, msgs_to_ignore, msgs_to_send; + list msgs_to_send, msgs_to_pass; string key_in_prescense; }; diff --git a/messages.cpp b/messages.cpp index b37bbd0..05d138a 100644 --- a/messages.cpp +++ b/messages.cpp @@ -28,6 +28,9 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) { //check for gpg related data wstring str = toUTF16(msg); wstring::size_type s1 = wstring::npos, s2 = wstring::npos; + DWORD dbflags = 0; + if(flags & PREF_UTF) + flags |= DBEF_UTF; if((str.find(_T("-----PGP KEY RESPONSE-----")) != wstring::npos) && !metaIsProtoMetaContacts(hContact)) { @@ -147,7 +150,6 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) HistoryLog(hContact, "PGP Encryption turned on by key autoexchange feature", EVENTTYPE_MESSAGE, 0); } } - hcontact_data[hContact].msgs_to_ignore.push_back(msg); mir_free(msg); return 1; } @@ -166,7 +168,7 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) { //this is public key if(metaIsSubcontact(hContact)) { - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, flags); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); mir_free(msg); return 0; } @@ -193,7 +195,7 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) new_key_hcnt_mutex.lock(); new_key_hcnt = hContact; ShowNewKeyDialog(); - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, flags); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); mir_free(msg); return 0; } @@ -290,7 +292,7 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) } else if(MessageBox(0, _T("Do you want try to decrypt encrypted message ?"), _T("Warning"), MB_YESNO) == IDNO) { - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, flags); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); mir_free(msg); return 0; } @@ -376,14 +378,14 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) delete gpg_thread; debuglog< Accounts; - list::iterator end = Accounts.end(); - for(list::iterator p = Accounts.begin(); p != end; p++) - { - TCHAR *caps = (*p)->getJabberInterface()->Net()->GetResourceFeatures(jid); - if(caps) - { - wstring str; - for(int i =0;;i++) - { - str.push_back(caps[i]); - if(caps[i] == '\0') - if(caps[i+1] == '\0') - break; - } - mir_free(caps); - if(str.find(_T("GPG_Key_Auto_Exchange:0")) != string::npos) - { - CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)"-----PGP KEY REQUEST-----"); - hcontact_data[hContact].msgs_to_ignore.push_back(msg); - hcontact_data[hContact].msgs_to_send.push_back(msg); - boost::thread *thr = new boost::thread(boost::bind(send_encrypted_msgs_thread, hContact)); - return returnNoError(hContact); - } - } - } - } + tmp = mir_a2t(msg); + isansi = true; } + str.append(tmp); + mir_free(tmp); } - if(!isContactSecured(hContact)) + string out; + DWORD code; + wstring cmd; + wstring path; + extern bool bJabberAPI, bIsMiranda09; + char *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", ""); + if(!tmp[0]) + { + mir_free(tmp); + HistoryLog(hContact, "Failed to encrypt message with GPG", EVENTTYPE_MESSAGE, DBEF_SENT); + hcontact_data[hContact].msgs_to_pass.push_back("Failed to encrypt message with GPG"); + mir_free(msg); return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); - - { //encrypt data here - wstring str; - bool isansi = false; - if(!metaIsSubcontact(hContact)) - str = toUTF16(msg); - else - {//workaround ... - wchar_t *tmp = mir_utf8decodeW(msg); - if(!tmp) - { - tmp = mir_a2t(msg); - isansi = true; - } - str.append(tmp); - mir_free(tmp); - } + } + if(!bJabberAPI || !bIsMiranda09) //force jabber to handle encrypted message by itself + cmd += _T("--comment \"\" --no-version "); + if(DBGetContactSettingByte(hContact, szGPGModuleName, "bAlwaysTrust", 0)) + cmd += _T("--trust-model always "); + cmd += _T("--batch --yes -e -a -r "); + TCHAR *tmp2 = mir_a2t(tmp); + mir_free(tmp); + cmd += tmp2; + mir_free(tmp2); + cmd += _T(" \""); + tmp2 = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); + path.append(tmp2); + cmd += tmp2; + mir_free(tmp2); + cmd += _T("\\exported_data"); + path.append(_T("\\exported_data")); + cmd += _T("\""); + { + char *tmp; + tmp = mir_strdup(toUTF8(str).c_str()); + fstream f(path.c_str(), std::ios::out); + f<lParam)); if (!msg) + { + mir_free(msg); return CallService(MS_PROTO_CHAINSEND, w, l); + } if(strstr(msg,"-----BEGIN PGP MESSAGE-----")) return CallService(MS_PROTO_CHAINSEND, w, l); + if(!isContactHaveKey(ccs->hContact)) + { + if(bAutoExchange && !strstr(msg, "-----PGP KEY REQUEST-----") && !strstr(msg, "-----BEGIN PGP PUBLIC KEY BLOCK-----") && isGPGConfigured()) + { + void send_encrypted_msgs_thread(HANDLE hContact); + LPSTR proto = (LPSTR)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)ccs->hContact, 0); + DWORD uin = DBGetContactSettingDword(ccs->hContact, proto, "UIN", 0); + if(uin) + { + if(ServiceExists("ICQ"PS_ICQ_CHECKCAPABILITY)) + { + ICQ_CUSTOMCAP cap = {0}; + strcpy(cap.caps, "GPG AutoExchange"); + if(CallService("ICQ"PS_ICQ_CHECKCAPABILITY, (WPARAM)ccs->hContact, (LPARAM)&cap)) + { + CallContactService(ccs->hContact, PSS_MESSAGE, (WPARAM)ccs->wParam, (LPARAM)"-----PGP KEY REQUEST-----"); + hcontact_data[ccs->hContact].msgs_to_send.push_back(msg); + boost::thread *thr = new boost::thread(boost::bind(send_encrypted_msgs_thread, ccs->hContact)); + mir_free(msg); + return returnNoError(ccs->hContact); + } + } + } + else + { + TCHAR *jid = UniGetContactSettingUtf(ccs->hContact, proto, "jid", _T("")); + if(jid[0]) + { + extern list Accounts; + list::iterator end = Accounts.end(); + for(list::iterator p = Accounts.begin(); p != end; p++) + { + TCHAR *caps = (*p)->getJabberInterface()->Net()->GetResourceFeatures(jid); + if(caps) + { + wstring str; + for(int i =0;;i++) + { + str.push_back(caps[i]); + if(caps[i] == '\0') + if(caps[i+1] == '\0') + break; + } + mir_free(caps); + if(str.find(_T("GPG_Key_Auto_Exchange:0")) != string::npos) + { + CallContactService(ccs->hContact, PSS_MESSAGE, (WPARAM)ccs->wParam, (LPARAM)"-----PGP KEY REQUEST-----"); + hcontact_data[ccs->hContact].msgs_to_send.push_back(msg); + boost::thread *thr = new boost::thread(boost::bind(send_encrypted_msgs_thread, ccs->hContact)); + mir_free(msg); + return returnNoError(ccs->hContact); + } + } + } + } + } + } + else + { + mir_free(msg); + return CallService(MS_PROTO_CHAINSEND, w, l); + } + } if(metaIsProtoMetaContacts(ccs->hContact)) { - hcontact_data[ccs->hContact].msgs_to_ignore.push_back((char*)msg); + mir_free(msg); return CallService(MS_PROTO_CHAINSEND, w, l); } boost::thread *thr = new boost::thread(boost::bind(SendMsgSvc_func, ccs->hContact, msg, (DWORD)ccs->wParam)); return returnNoError(ccs->hContact); } +boost::mutex event_processing_mutex; + int HookSendMsg(WPARAM w, LPARAM l) -{ //TODO: implement additional filtering for metacontacts data... +{ if(!l) return 0; DBEVENTINFO * dbei = (DBEVENTINFO*)l; - if((dbei->eventType == EVENTTYPE_MESSAGE) && (dbei->flags & DBEF_SENT)) + if(dbei->eventType != EVENTTYPE_MESSAGE) + return 0; + if(dbei->flags & DBEF_SENT) { if(strstr((char*)dbei->pBlob, "-----BEGIN PGP MESSAGE-----") || strstr((char*)dbei->pBlob, "-----PGP KEY RESPONSE-----") || strstr((char*)dbei->pBlob, "-----PGP KEY REQUEST-----") || strstr((char*)dbei->pBlob, "-----PGP KEY RESPONSE-----")) //our service data, can be double added by metacontacts e.t.c. return 1; - HANDLE hContact = NULL; - if(!hcontact_data[(HANDLE)w].msgs_to_ignore.empty()) - hContact = (HANDLE)w; - else if(!hcontact_data[metaGetContact((HANDLE)w)].msgs_to_ignore.empty()) - hContact = metaGetContact((HANDLE)w); - if(hContact) - { - list::iterator end = hcontact_data[hContact].msgs_to_ignore.end(); - for(list::iterator p = hcontact_data[hContact].msgs_to_ignore.begin(); p != end; p++) - { - if(*p == (char*)dbei->pBlob) - { - hcontact_data[hContact].msgs_to_ignore.erase(p); - return 1; - } - } - } } HANDLE hContact = (HANDLE)w; - - - if(metaIsProtoMetaContacts(hContact)) - hContact = metaGetCurrent(hContact); - if(!DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0)) - return 0; - - if(bAppendTags) + if(isContactSecured(hContact) && (dbei->flags & DBEF_SENT)) //aggressive outgoing events filtering { - if((dbei->eventType == EVENTTYPE_MESSAGE) && (dbei->flags & DBEF_SENT)) + if(!hcontact_data[hContact].msgs_to_pass.empty()) { - if(!hcontact_data[hContact].msgs_to_tag.empty()) + event_processing_mutex.lock(); + std::list::iterator end = hcontact_data[hContact].msgs_to_pass.end(); + for(std::list::iterator i = hcontact_data[hContact].msgs_to_pass.begin(); i != end; ++i) { - std::list::iterator end = hcontact_data[hContact].msgs_to_tag.end(); - for(std::list::iterator i = hcontact_data[hContact].msgs_to_tag.begin(); i != end; ++i) + if(!strcmp((*i).c_str(), (char*)dbei->pBlob)) { - if(*i == (char*)dbei->pBlob) - { - char *msg = (char*)dbei->pBlob; - wstring str = toUTF16(msg); - str.insert(0, outopentag); - str.append(outclosetag); - char *msg2 = mir_strdup(toUTF8(str).c_str()); - mir_free(dbei->pBlob); - dbei->pBlob = (PBYTE)msg2; - dbei->cbBlob = strlen(msg2)+1; - hcontact_data[hContact].msgs_to_tag.erase(i); - break; - } + hcontact_data[hContact].msgs_to_pass.erase(i); + event_processing_mutex.unlock(); + return 0; } } + event_processing_mutex.unlock(); } + return 1; } - if((dbei->eventType == EVENTTYPE_MESSAGE) && !(dbei->flags & DBEF_SENT) && metaIsProtoMetaContacts((HANDLE)w)) + if(!DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0)) + return 0; + if(!(dbei->flags & DBEF_SENT) && metaIsProtoMetaContacts((HANDLE)w)) { char tmp[29]; strncpy(tmp, (char*)dbei->pBlob, 27); @@ -883,11 +872,6 @@ int HookSendMsg(WPARAM w, LPARAM l) return 0; } -int TestHook(WPARAM w, LPARAM l) -{ - return 0; -} - static BOOL CALLBACK DlgProcKeyPassword(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { diff --git a/metacontacts.cpp b/metacontacts.cpp index 30d3a75..c451d9f 100644 --- a/metacontacts.cpp +++ b/metacontacts.cpp @@ -58,14 +58,14 @@ HANDLE metaGetMostOnline(HANDLE hContact) if(bMetaContacts) return (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT,(WPARAM)hContact,0); - return 0; + return hContact; } HANDLE metaGetDefault(HANDLE hContact) { if(bMetaContacts) return (HANDLE)CallService(MS_MC_GETDEFAULTCONTACT,(WPARAM)hContact,0); - return 0; + return hContact; } HANDLE metaGetCurrent(HANDLE hContact) diff --git a/utilities.cpp b/utilities.cpp index 05d0bde..40c4b32 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -933,7 +933,12 @@ void AddHandlers() bool isContactSecured(HANDLE hContact) { TCHAR *key = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); - if(DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0) && (_tcslen(key) > 0)) + if(!key[0]) + { + mir_free(key); + key = UniGetContactSettingUtf(metaGetMostOnline(hContact), szGPGModuleName, "GPGPubKey", _T("")); + } + if((DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0) > 0 || DBGetContactSettingByte(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", 0) > 0) && (_tcslen(key) > 0)) { mir_free(key); return true; -- cgit v1.2.3 From 5f55dcc2e10098ac93710d13176939e4c30d5b5f Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Tue, 22 Mar 2011 17:04:43 +0200 Subject: thread safety (incompete) --- messages.cpp | 62 +++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/messages.cpp b/messages.cpp index 05d138a..6875ece 100644 --- a/messages.cpp +++ b/messages.cpp @@ -19,18 +19,16 @@ wstring new_key; HANDLE new_key_hcnt = NULL; -boost::mutex new_key_hcnt_mutex; +boost::mutex new_key_hcnt_mutex, gpg_file_mutex; bool _terminate = false; int returnNoError(HANDLE hContact); int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) -{ +{ + DWORD dbflags = DBEF_UTF; { //check for gpg related data wstring str = toUTF16(msg); wstring::size_type s1 = wstring::npos, s2 = wstring::npos; - DWORD dbflags = 0; - if(flags & PREF_UTF) - flags |= DBEF_UTF; if((str.find(_T("-----PGP KEY RESPONSE-----")) != wstring::npos) && !metaIsProtoMetaContacts(hContact)) { @@ -54,7 +52,10 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) _tcscat(tmp2, _T("\\")); _tcscat(tmp2, _T("temporary_exported.asc")); DeleteFile(tmp2); + gpg_file_mutex.timed_lock(boost::posix_time::minutes(1)); wfstream f(tmp2, std::ios::out); + while(!f.is_open()) + f.open(tmp2, std::ios::out); ptmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); wstring new_key = ptmp; mir_free(ptmp); @@ -78,13 +79,16 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) gpg_thread.~thread(); debuglog< Date: Wed, 23 Mar 2011 12:18:19 +0200 Subject: modified: init.cpp modified: messages.cpp modified: new_gpg.rc --- init.cpp | 2 +- messages.cpp | 14 +++++++++----- new_gpg.rc | 18 +++++++----------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/init.cpp b/init.cpp index 8af16e6..6f591ac 100644 --- a/init.cpp +++ b/init.cpp @@ -42,7 +42,7 @@ std::map hcontact_data; PLUGININFOEX pluginInfo={ sizeof(PLUGININFOEX), 0, - PLUGIN_MAKE_VERSION(0,0,0,10), + PLUGIN_MAKE_VERSION(0,0,0,11), "new GPG encryption support plugin, based on code from old gpg plugin and secureim", "sss", "sss123next@list.ru", diff --git a/messages.cpp b/messages.cpp index 6875ece..3cb59c0 100644 --- a/messages.cpp +++ b/messages.cpp @@ -52,7 +52,8 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) _tcscat(tmp2, _T("\\")); _tcscat(tmp2, _T("temporary_exported.asc")); DeleteFile(tmp2); - gpg_file_mutex.timed_lock(boost::posix_time::minutes(1)); + while(!gpg_file_mutex.timed_lock(boost::posix_time::seconds(15))) + gpg_file_mutex.unlock(); wfstream f(tmp2, std::ios::out); while(!f.is_open()) f.open(tmp2, std::ios::out); @@ -312,7 +313,8 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) wstring path = tmp2; path.append(_T("\\encrypted_data.asc")); DeleteFile(path.c_str()); - gpg_file_mutex.timed_lock(boost::posix_time::minutes(1)); + while(!gpg_file_mutex.timed_lock(boost::posix_time::seconds(15))) + gpg_file_mutex.unlock(); fstream f(path.c_str(), std::ios::out); while(!f.is_open()) f.open(path.c_str(), std::ios::out); @@ -500,7 +502,8 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) wstring path = tmp2; mir_free(tmp2); path += _T("\\decrypted_data"); - gpg_file_mutex.timed_lock(boost::posix_time::minutes(1)); + while(!gpg_file_mutex.timed_lock(boost::posix_time::seconds(15))) + gpg_file_mutex.unlock(); fstream f(path.c_str(), std::ios::in | std::ios::ate | std::ios::binary); if(f.is_open()) { @@ -642,7 +645,8 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) { char *tmp; tmp = mir_strdup(toUTF8(str).c_str()); - gpg_file_mutex.timed_lock(boost::posix_time::minutes(1)); + while(!gpg_file_mutex.timed_lock(boost::posix_time::seconds(15))) + gpg_file_mutex.unlock(); fstream f(path.c_str(), std::ios::out); while(!f.is_open()) f.open(path.c_str(), std::ios::out); @@ -840,7 +844,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) return CallService(MS_PROTO_CHAINSEND, w, l); } } - if(metaIsProtoMetaContacts(ccs->hContact)) + if(metaIsProtoMetaContacts(ccs->hContact) || !isContactSecured(ccs->hContact)) { mir_free(msg); return CallService(MS_PROTO_CHAINSEND, w, l); diff --git a/new_gpg.rc b/new_gpg.rc index 97d20dd..b0c87ab 100644 --- a/new_gpg.rc +++ b/new_gpg.rc @@ -13,13 +13,11 @@ #undef APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// -// русский resources +// Russian (Russia) resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS) -#ifdef _WIN32 LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT #pragma code_page(1251) -#endif //_WIN32 #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// @@ -177,7 +175,7 @@ END // #ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO +GUIDELINES DESIGNINFO BEGIN IDD_LOAD_PUBLIC_KEY, DIALOG BEGIN @@ -263,7 +261,7 @@ IDI_UNSECURED ICON "icons\\unsecured.ico" // VS_VERSION_INFO VERSIONINFO - FILEVERSION 0,0,0,10 + FILEVERSION 0,0,0,11 PRODUCTVERSION 0,9,0,0 FILEFLAGSMASK 0x17L #ifdef _DEBUG @@ -280,7 +278,7 @@ BEGIN BLOCK "041904b0" BEGIN VALUE "FileDescription", "new_gpg" - VALUE "FileVersion", "0.0.0.10" + VALUE "FileVersion", "0.0.0.11" VALUE "InternalName", "new_gpg" VALUE "LegalCopyright", "Copyright (C) 2010-2011 sss" VALUE "OriginalFilename", "new_gpg" @@ -294,18 +292,16 @@ BEGIN END END -#endif // русский resources +#endif // Russian (Russia) resources ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// -// английский (США) resources +// English (United States) resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -#ifdef _WIN32 LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US #pragma code_page(1252) -#endif //_WIN32 ///////////////////////////////////////////////////////////////////////////// // @@ -361,7 +357,7 @@ BEGIN RTEXT "Close:",IDC_STATIC,127,49,23,8 END -#endif // английский (США) resources +#endif // English (United States) resources ///////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From 9588dec6833519fa4060cc347f11f808f99ca1e6 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 23 Mar 2011 13:44:24 +0200 Subject: modified: utilities.cpp --- utilities.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/utilities.cpp b/utilities.cpp index 40c4b32..afa9440 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -831,6 +831,8 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi sign_file_mutex.lock(); DeleteFile(path_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<getJabberInterface()->Sys()->ContactFromJID(xi.getAttrValue(node, _T("from"))); if(hContact) -// DBWriteContactSettingString(hContact, szGPGModuleName, "KeyID_Prescense", out.substr(p1, p2-p1-1).c_str()); hcontact_data[hContact].key_in_prescense = out.substr(p1, p2-p1-1).c_str(); } } -- cgit v1.2.3 From b32258ea916b0ba101decfbc0b59b4088c707202 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 23 Mar 2011 22:39:52 +0200 Subject: file recieving fix --- utilities.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/utilities.cpp b/utilities.cpp index afa9440..2ba305a 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -282,11 +282,6 @@ int onProtoAck(WPARAM w, LPARAM l) CCSDATA *ccs=(CCSDATA*)ack->lParam; if (ack->type!=ACKTYPE_FILE) return 0; - PROTOFILETRANSFERSTATUS *f = (PROTOFILETRANSFERSTATUS*) ack->lParam; -// if(!f) -// f = (PROTOFILETRANSFERSTATUS*) ack->hProcess; - if(!f) - return 0; switch(ack->result) { @@ -294,6 +289,7 @@ int onProtoAck(WPARAM w, LPARAM l) break; case ACKRESULT_SUCCESS: { + PROTOFILETRANSFERSTATUS *f = (PROTOFILETRANSFERSTATUS*) ack->hProcess; TCHAR *filename = NULL; if(f->flags & PFTS_UNICODE) { -- cgit v1.2.3 From ca3192f3ccce5f59c9fbe58701c48fca557532b7 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 23 Mar 2011 22:43:49 +0200 Subject: modified: utilities.cpp --- utilities.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/utilities.cpp b/utilities.cpp index 2ba305a..a2ca82b 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -449,6 +449,7 @@ int onSendFile(WPARAM w, LPARAM l) if(isContactSecured(ccs->hContact)) { TCHAR **file=(TCHAR **)ccs->lParam; + DWORD flags = (DWORD)ccs->wParam; //check for PFTS_UNICODE here int i; for(i = 0; file[i]; i++) { -- cgit v1.2.3 From 3d5b89807b16d724a877b305c1bd023e177f92fc Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Thu, 24 Mar 2011 02:20:32 +0200 Subject: modified: utilities.cpp --- utilities.cpp | 172 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 101 insertions(+), 71 deletions(-) diff --git a/utilities.cpp b/utilities.cpp index a2ca82b..34307cc 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -440,6 +440,76 @@ int onProtoAck(WPARAM w, LPARAM l) return 0; } +std::wstring encrypt_file(HANDLE hContact, TCHAR *filename) +{ + string out; + DWORD code; + pxResult result; + wstring cmd = _T("--batch --yes -r "); + char *keyid = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", ""); + if(DBGetContactSettingByte(hContact, szGPGModuleName, "bAlwaysTrust", 0)) + cmd += _T("--trust-model always "); + TCHAR *szKeyid = mir_a2t(keyid); + TCHAR *name = _tcsrchr(filename,_T('\\')); + if( !name ) + name = filename; + else + name++; + TCHAR *file_out = new TCHAR [_tcslen(filename)+4]; + mir_sntprintf(file_out, _tcslen(name)+7, _T("%s.gpg"), name); + cmd += szKeyid; + mir_free(szKeyid); + mir_free(keyid); + cmd += _T(" -o \""); + TCHAR *temp = _tgetenv(_T("TEMP")); + cmd += temp; + cmd += _T("\\"); + cmd += file_out; + wstring path_out = temp; + path_out += _T("\\"); + path_out += file_out; + DeleteFile(path_out.c_str()); + cmd += _T("\" "); + mir_free(temp); + cmd += _T(" -e \""); + cmd += filename; + cmd += _T("\" "); + gpg_execution_params params; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + mir_free(keyid); + delete [] file_out; + boost::thread *gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread->timed_join(boost::posix_time::seconds(180))) + { + delete gpg_thread; + debuglog<timed_join(boost::posix_time::seconds(180))) + { + delete gpg_thread; + debuglog<hContact)) { - TCHAR **file=(TCHAR **)ccs->lParam; + DWORD flags = (DWORD)ccs->wParam; //check for PFTS_UNICODE here int i; - for(i = 0; file[i]; i++) + if(flags & PFTS_UNICODE) { - if (_tcsstr(file[i],_T(".gpg"))) - continue; - if(_waccess(file[i], 0) == -1) - if(errno == ENOENT) - return 0; //we do not want to send file unencrypted (sometimes ack have wrong info) - TCHAR *name = _tcsrchr(file[i],_T('\\')); - if( !name ) - name = file[i]; - else - name++; - TCHAR *file_out = new TCHAR [_tcslen(file[i])+4]; - mir_sntprintf(file_out, _tcslen(name)+7, _T("%s.gpg"), name); - string out; - DWORD code; - pxResult result; - wstring cmd = _T("--batch --yes -r "); - char *keyid = UniGetContactSettingUtf(ccs->hContact, szGPGModuleName, "KeyID", ""); - if(DBGetContactSettingByte(ccs->hContact, szGPGModuleName, "bAlwaysTrust", 0)) - cmd += _T("--trust-model always "); - TCHAR *szKeyid = mir_a2t(keyid); - cmd += szKeyid; - mir_free(szKeyid); - mir_free(keyid); - cmd += _T(" -o \""); - TCHAR *temp = _tgetenv(_T("TEMP")); - cmd += temp; - cmd += _T("\\"); - cmd += file_out; - wstring path_out = temp; - path_out += _T("\\"); - path_out += file_out; - DeleteFile(path_out.c_str()); - cmd += _T("\" "); - mir_free(temp); - cmd += _T(" -e \""); - cmd += file[i]; - cmd += _T("\" "); - gpg_execution_params params; - params.cmd = &cmd; - params.useless = ""; - params.out = &out; - params.code = &code; - params.result = &result; - mir_free(keyid); - boost::thread *gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread->timed_join(boost::posix_time::seconds(180))) + TCHAR **file=(TCHAR **)ccs->lParam; + for(i = 0; file[i]; i++) { - delete gpg_thread; - debuglog<hContact, file[i]); + mir_free(file[i]); + file[i] = mir_tstrdup(path_out.c_str()); + transfers.push_back(path_out); } - if(out.find("There is no assurance this key belongs to the named user") != string::npos) + } + else + { + char **file = (char**) ccs->lParam; + for(i = 0; file[i]; i++) { - out.clear(); - if(MessageBox(0, _T("We trying to encrypt with untrusted key, do you want to trust this key permanently ?"), _T("Warning"), MB_YESNO) == IDYES) - { - DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "bAlwaysTrust", 1); - cmd.insert(0, _T("--trust-model always ")); - gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread->timed_join(boost::posix_time::seconds(180))) - { - delete gpg_thread; - debuglog<hContact, tmp); + mir_free(tmp); + char* tmp2 = mir_utf8encodeW(path_out.c_str()); + mir_free(file[i]); + file[i] = tmp2; + transfers.push_back(path_out); + } - mir_free(file[i]); - file[i] = mir_tstrdup(path_out.c_str()); - delete [] file_out; - transfers.push_back(path_out); } } return CallService(MS_PROTO_CHAINSEND, w, l); -- cgit v1.2.3 From c5e0140f26c8f95a1f83f1e2c86e1eb11820e901 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Thu, 24 Mar 2011 04:47:22 +0200 Subject: modified: messages.cpp modified: utilities.cpp --- messages.cpp | 483 ++++++++++++++++++++++++++++------------------------------ utilities.cpp | 3 +- 2 files changed, 236 insertions(+), 250 deletions(-) diff --git a/messages.cpp b/messages.cpp index 3cb59c0..ef6cf97 100644 --- a/messages.cpp +++ b/messages.cpp @@ -23,244 +23,12 @@ boost::mutex new_key_hcnt_mutex, gpg_file_mutex; bool _terminate = false; int returnNoError(HANDLE hContact); -int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) +int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags) { DWORD dbflags = DBEF_UTF; { //check for gpg related data - wstring str = toUTF16(msg); wstring::size_type s1 = wstring::npos, s2 = wstring::npos; - if((str.find(_T("-----PGP KEY RESPONSE-----")) != wstring::npos) && !metaIsProtoMetaContacts(hContact)) - { - s2 = str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")); - s1 = str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); - if(s1 != wstring::npos && s2 != wstring::npos) - { - s2 += _tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----")); - DBWriteContactSettingTString(hContact, szGPGModuleName, "GPGPubKey", str.substr(s1,s2-s1).c_str()); - DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1); - { //gpg execute block - wstring cmd; - TCHAR tmp2[MAX_PATH] = {0}; - TCHAR *ptmp; - string output; - DWORD exitcode; - { - ptmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); - _tcscpy(tmp2, ptmp); - mir_free(ptmp); - _tcscat(tmp2, _T("\\")); - _tcscat(tmp2, _T("temporary_exported.asc")); - DeleteFile(tmp2); - while(!gpg_file_mutex.timed_lock(boost::posix_time::seconds(15))) - gpg_file_mutex.unlock(); - wfstream f(tmp2, std::ios::out); - while(!f.is_open()) - f.open(tmp2, std::ios::out); - ptmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); - wstring new_key = ptmp; - mir_free(ptmp); - f< output.find("<", s)) - 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(hContact, szGPGModuleName, "KeyMainName", tmp); - mir_free(tmp); - if((s = output.find(")", s2)) == string::npos) - s = output.find(">", s2); - else if(s > output.find(">", s2)) - s = output.find(">", s2); - s2++; - if(output[s] == ')') - { - tmp = new char [output.substr(s2,s-s2).length()+1]; - strcpy(tmp, output.substr(s2,s-s2).c_str()); - mir_utf8decode(tmp, 0); - 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(hContact, szGPGModuleName, "KeyMainEmail", tmp); - mir_free(tmp); - } - else - { - tmp = new char [output.substr(s2,s-s2).length()+1]; - strcpy(tmp, output.substr(s2,s-s2).c_str()); - mir_utf8decode(tmp, 0); - DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); - mir_free(tmp); - } - DBWriteContactSettingByte(hContact, szGPGModuleName, "bAlwatsTrust", 1); - void setSrmmIcon(HANDLE); - void setClistIcon(HANDLE); - setSrmmIcon(hContact); - setClistIcon(hContact); - if(metaIsSubcontact(hContact)) - { - setSrmmIcon(metaGetContact(hContact)); - setClistIcon(metaGetContact(hContact)); - HistoryLog(metaGetContact(hContact), "PGP Encryption turned on by key autoexchange feature", EVENTTYPE_MESSAGE, 0); - } - HistoryLog(hContact, "PGP Encryption turned on by key autoexchange feature", EVENTTYPE_MESSAGE, 0); - } - } - mir_free(msg); - return 1; - } - } - if((str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")) != wstring::npos) && (str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")) != wstring::npos)) - { - s2 = str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")); - s1 = str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); - } - else if((str.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")) != wstring::npos) && (str.find(_T("-----END PGP PRIVATE KEY BLOCK-----")) != wstring::npos)) - { - s2 = str.find(_T("-----END PGP PRIVATE KEY BLOCK-----")); - s1 = str.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")); - } - if((s2 != wstring::npos) && (s1 != wstring::npos)) - { //this is public key - if(metaIsSubcontact(hContact)) - { - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); - mir_free(msg); - return 0; - } - debuglog< Accounts; - list::iterator end = Accounts.end(); - for(list::iterator p = Accounts.begin(); p != end; p++) - { - TCHAR *caps = (*p)->getJabberInterface()->Net()->GetResourceFeatures(jid); - if(caps) - { - wstring str; - for(int i =0;;i++) - { - str.push_back(caps[i]); - if(caps[i] == '\0') - if(caps[i+1] == '\0') - break; - } - mir_free(caps); - if(str.find(_T("GPG_Key_Auto_Exchange:0")) != string::npos) - CallContactService(hContact, PSS_MESSAGE, (WPARAM)0, (LPARAM)"-----PGP KEY REQUEST-----"); - } - } - } - } - } - mir_free(msg); - return 1; - } s1 = str.find(_T("-----BEGIN PGP MESSAGE-----")); s2 = str.find(_T("-----END PGP MESSAGE-----")); if((s2 != wstring::npos) && (s1 != wstring::npos)) @@ -298,7 +66,6 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) else if(MessageBox(0, _T("Do you want try to decrypt encrypted message ?"), _T("Warning"), MB_YESNO) == IDNO) { HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); - mir_free(msg); return 0; } } @@ -388,7 +155,6 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) debuglog<lParam); if (!pre) return CallService(MS_PROTO_CHAINRECV, w, l); - char *msg = mir_strdup(pre->szMessage); + char *msg = pre->szMessage; if (!msg) return CallService(MS_PROTO_CHAINRECV, w, l); - boost::thread *thr = new boost::thread(boost::bind(RecvMsgSvc_func, ccs->hContact, msg, ccs->wParam)); + wstring str = toUTF16(msg); + wstring::size_type s1 = wstring::npos, s2 = wstring::npos; + DWORD dbflags = DBEF_UTF; + if((str.find(_T("-----PGP KEY RESPONSE-----")) != wstring::npos) && !metaIsProtoMetaContacts(ccs->hContact)) + { + s2 = str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")); + s1 = str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); + if(s1 != wstring::npos && s2 != wstring::npos) + { + s2 += _tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----")); + DBWriteContactSettingTString(ccs->hContact, szGPGModuleName, "GPGPubKey", str.substr(s1,s2-s1).c_str()); + DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "GPGEncryption", 1); + { //gpg execute block + wstring cmd; + TCHAR tmp2[MAX_PATH] = {0}; + TCHAR *ptmp; + string output; + DWORD exitcode; + { + ptmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); + _tcscpy(tmp2, ptmp); + mir_free(ptmp); + _tcscat(tmp2, _T("\\")); + _tcscat(tmp2, _T("temporary_exported.asc")); + DeleteFile(tmp2); + while(!gpg_file_mutex.timed_lock(boost::posix_time::seconds(15))) + gpg_file_mutex.unlock(); + wfstream f(tmp2, std::ios::out); + while(!f.is_open()) + f.open(tmp2, std::ios::out); + ptmp = UniGetContactSettingUtf(ccs->hContact, szGPGModuleName, "GPGPubKey", _T("")); + wstring new_key = ptmp; + mir_free(ptmp); + f<hContact, szGPGModuleName, "KeyID", output.substr(s,s2-s).c_str()); + s2+=2; + s = output.find("“", s2); + if(s == string::npos) + { + s = output.find("\"", s2); + s += 1; + } + else + s += 3; + if((s2 = output.find("(", s)) == string::npos) + s2 = output.find("<", s); + else if(s2 > output.find("<", s)) + 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(ccs->hContact, szGPGModuleName, "KeyMainName", tmp); + mir_free(tmp); + if((s = output.find(")", s2)) == string::npos) + s = output.find(">", s2); + else if(s > output.find(">", s2)) + s = output.find(">", s2); + s2++; + if(output[s] == ')') + { + tmp = new char [output.substr(s2,s-s2).length()+1]; + strcpy(tmp, output.substr(s2,s-s2).c_str()); + mir_utf8decode(tmp, 0); + DBWriteContactSettingString(ccs->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(ccs->hContact, szGPGModuleName, "KeyMainEmail", tmp); + mir_free(tmp); + } + else + { + tmp = new char [output.substr(s2,s-s2).length()+1]; + strcpy(tmp, output.substr(s2,s-s2).c_str()); + mir_utf8decode(tmp, 0); + DBWriteContactSettingString(ccs->hContact, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); + mir_free(tmp); + } + DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "bAlwatsTrust", 1); + void setSrmmIcon(HANDLE); + void setClistIcon(HANDLE); + setSrmmIcon(ccs->hContact); + setClistIcon(ccs->hContact); + if(metaIsSubcontact(ccs->hContact)) + { + setSrmmIcon(metaGetContact(ccs->hContact)); + setClistIcon(metaGetContact(ccs->hContact)); + HistoryLog(metaGetContact(ccs->hContact), "PGP Encryption turned on by key autoexchange feature", EVENTTYPE_MESSAGE, 0); + } + HistoryLog(ccs->hContact, "PGP Encryption turned on by key autoexchange feature", EVENTTYPE_MESSAGE, 0); + } + } + return 1; + } + } + if((str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")) != wstring::npos) && (str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")) != wstring::npos)) + { + s2 = str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")); + s1 = str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); + } + else if((str.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")) != wstring::npos) && (str.find(_T("-----END PGP PRIVATE KEY BLOCK-----")) != wstring::npos)) + { + s2 = str.find(_T("-----END PGP PRIVATE KEY BLOCK-----")); + s1 = str.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")); + } + if((s2 != wstring::npos) && (s1 != wstring::npos)) + { //this is public key + if(metaIsSubcontact(ccs->hContact)) + { + HistoryLog(ccs->hContact, msg, EVENTTYPE_MESSAGE, dbflags); + return 0; + } + debuglog<hContact, GCDNF_TCHAR)<<"\n"; + s1 = 0; + while((s1 = str.find(_T("\r"), s1)) != wstring::npos) + { + str.erase(s1, 1); + } + void ShowNewKeyDialog(); + if((str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")) != wstring::npos) && (str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")) != wstring::npos)) + { + s2 = str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")); + s1 = str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); + s2 += _tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----")); + } + else if((str.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")) != wstring::npos) && (str.find(_T("-----END PGP PRIVATE KEY BLOCK-----")) != wstring::npos)) + { + s2 = str.find(_T("-----END PGP PRIVATE KEY BLOCK-----")); + s1 = str.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")); + s2 += _tcslen(_T("-----END PGP PRIVATE KEY BLOCK-----")); + } + new_key.append(str.substr(s1,s2-s1)); + new_key_hcnt_mutex.lock(); + new_key_hcnt = ccs->hContact; + ShowNewKeyDialog(); + HistoryLog(ccs->hContact, msg, EVENTTYPE_MESSAGE, dbflags); + return 0; + } + if(bAutoExchange && strstr(msg, "-----PGP KEY REQUEST-----") && isGPGConfigured()) + { + char *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", ""); + if(tmp[0]) + { + DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "GPGEncryption", 0); + string str = "-----PGP KEY RESPONSE-----"; + str.append(tmp); + CallContactService(ccs->hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)str.c_str()); + DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "GPGEncryption", 1); + } + mir_free(tmp); + if(!isContactHaveKey(ccs->hContact) && bAutoExchange && isGPGConfigured()) + { + LPSTR proto = (LPSTR)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)ccs->hContact, 0); + DWORD uin = DBGetContactSettingDword(ccs->hContact, proto, "UIN", 0); + if(uin) + { + if(ServiceExists("ICQ"PS_ICQ_CHECKCAPABILITY)) + { + ICQ_CUSTOMCAP cap = {0}; + strcpy(cap.caps, "GPG AutoExchange"); + if(CallService("ICQ"PS_ICQ_CHECKCAPABILITY, (WPARAM)ccs->hContact, (LPARAM)&cap)) + CallContactService(ccs->hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"-----PGP KEY REQUEST-----"); + } + } + else + { + TCHAR *jid = UniGetContactSettingUtf(ccs->hContact, proto, "jid", _T("")); + if(jid[0]) + { + extern list Accounts; + list::iterator end = Accounts.end(); + for(list::iterator p = Accounts.begin(); p != end; p++) + { + TCHAR *caps = (*p)->getJabberInterface()->Net()->GetResourceFeatures(jid); + if(caps) + { + wstring str; + for(int i =0;;i++) + { + str.push_back(caps[i]); + if(caps[i] == '\0') + if(caps[i+1] == '\0') + break; + } + mir_free(caps); + if(str.find(_T("GPG_Key_Auto_Exchange:0")) != string::npos) + CallContactService(ccs->hContact, PSS_MESSAGE, (WPARAM)0, (LPARAM)"-----PGP KEY REQUEST-----"); + } + } + } + } + } + return 1; + } + if(!(strstr(msg, "-----BEGIN PGP MESSAGE-----") && strstr(msg, "-----END PGP MESSAGE-----"))) + return CallService(MS_PROTO_CHAINRECV, w, l); + boost::thread *thr = new boost::thread(boost::bind(RecvMsgSvc_func, ccs->hContact, str, msg, ccs->wParam)); return returnNoError(ccs->hContact); } @@ -887,7 +872,7 @@ int HookSendMsg(WPARAM w, LPARAM l) } return 1; } - if(!DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0)) + if(!isContactSecured(hContact)) return 0; if(!(dbei->flags & DBEF_SENT) && metaIsProtoMetaContacts((HANDLE)w)) { diff --git a/utilities.cpp b/utilities.cpp index 34307cc..e87bb8c 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -231,10 +231,11 @@ int ToggleEncryption(WPARAM w, LPARAM l) if(hcnt) DBWriteContactSettingByte(hcnt, szGPGModuleName, "GPGEncryption", enc?0:1); } + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc?0:1); } } else - DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc?0:1); + DBWriteContactSettingByte(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", enc?0:1); } void setSrmmIcon(HANDLE hContact); void setClistIcon(HANDLE hContact); -- cgit v1.2.3 From 8174eb73282e177112615c2dd332b69401959764 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 30 Mar 2011 08:51:28 +0300 Subject: one more threading variant (without mutexes) --- gpg_wrapper.cpp | 16 +++++++-------- main.cpp | 9 +++++---- messages.cpp | 63 ++++++++++++++++++++------------------------------------- new_gpg.vcxproj | 12 +++++------ utilities.cpp | 39 ++++++++++++++++++----------------- 5 files changed, 60 insertions(+), 79 deletions(-) diff --git a/gpg_wrapper.cpp b/gpg_wrapper.cpp index 3091566..b85d24b 100644 --- a/gpg_wrapper.cpp +++ b/gpg_wrapper.cpp @@ -18,12 +18,12 @@ //thx gpg module from Harald Treder, Zakhar V. Bardymov -boost::mutex gpg_mutex; +//boost::mutex gpg_mutex; pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result) { - gpg_mutex.lock(); +// gpg_mutex.lock(); if(!gpg_configured) return pxNotConfigured; extern logtofile debuglog; @@ -80,6 +80,7 @@ pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD if(errno == ENOENT) { mir_free(bin_path); + debuglog<cmd, params->useless, params->out, params->code, params->result); - if(result == pxNotFound) - { - debuglog< Disabled - x:\temp\windows\libs\utf8cpp\include;X:\temp\windows\libs\Boost\include\boost-1_46;x:\install\git\miranda\miranda-im\miranda\include;x:\install\git\miranda\mim_plugs;../../include;%(AdditionalIncludeDirectories) + e:\temp\windows\libs\utf8cpp\include;e:\temp\windows\libs\Boost\include\boost-1_46;e:\install\git\miranda\miranda-im\miranda\include;x:\install\git\miranda\mim_plugs;../../include;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USRDLL;TESTPLUG_EXPORTS;_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebug @@ -501,7 +501,7 @@ shlwapi.lib;%(AdditionalDependencies) libboost_thread-vc100-mt-sgd-1_46_1.lib true - X:\temp\windows\libs\Boost\lib-debug;%(AdditionalLibraryDirectories) + e:\temp\windows\libs\Boost\lib-debug;%(AdditionalLibraryDirectories) true true false @@ -685,7 +685,7 @@ Size true true - x:\temp\windows\libs\utf8cpp\include;X:\temp\windows\libs\Boost\include\boost-1_46;x:\install\git\miranda\miranda-im\miranda\include;x:\install\git\miranda\mim_plugs;../../include + e:\temp\windows\libs\utf8cpp\include;e:\temp\windows\libs\Boost\include\boost-1_46;e:\install\git\miranda\miranda-im\miranda\include;e:\install\git\miranda\mim_plugs;../../include WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;_UNICODE;%(PreprocessorDefinitions) true MultiThreaded @@ -708,7 +708,7 @@ shlwapi.lib;%(AdditionalDependencies) true - X:\temp\windows\libs\Boost\lib-release;%(AdditionalLibraryDirectories) + e:\temp\windows\libs\Boost\lib-release;%(AdditionalLibraryDirectories) false NotSet true @@ -739,7 +739,7 @@ Size true true - x:\temp\windows\libs\utf8cpp\include;X:\temp\windows\libs\Boost\include\boost-1_46;x:\install\git\miranda\miranda-im\miranda\include;x:\install\git\miranda\mim_plugs;../../include;%(AdditionalIncludeDirectories) + e:\temp\windows\libs\utf8cpp\include;e:\temp\windows\libs\Boost\include\boost-1_46;e:\install\git\miranda\miranda-im\miranda\include;x:\install\git\miranda\mim_plugs;../../include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;_UNICODE;%(PreprocessorDefinitions) true MultiThreaded @@ -762,7 +762,7 @@ shlwapi.lib;%(AdditionalDependencies) true - X:\temp\windows\libs\Boost\lib-release-x64;%(AdditionalLibraryDirectories) + e:\temp\windows\libs\Boost\lib-release-x64;%(AdditionalLibraryDirectories) false NotSet true diff --git a/utilities.cpp b/utilities.cpp index e87bb8c..43d5828 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -376,7 +376,7 @@ int onProtoAck(WPARAM w, LPARAM l) params.code = &code; params.result = &result; boost::thread *gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread->timed_join(boost::posix_time::minutes(10))) + if(!gpg_thread->timed_join(boost::posix_time::minutes(15))) { delete gpg_thread; debuglog<timed_join(boost::posix_time::seconds(10))) + if(!gpg_thread->timed_join(boost::posix_time::seconds(15))) { delete gpg_thread; debuglog< 0 || DBGetContactSettingByte(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", 0) > 0) && (_tcslen(key) > 0)) - { - mir_free(key); - return true; + return false; } mir_free(key); - return false; + return true; } bool isContactHaveKey(HANDLE hContact) -- cgit v1.2.3 From 903cf85316f641a2d7fcc7fb87ed75889469d2dc Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 30 Mar 2011 09:36:35 +0300 Subject: some agression ) --- gpg_wrapper.cpp | 7 ++++--- gpg_wrapper.h | 1 + main.cpp | 29 +++++++++++++++++++++++++++++ messages.cpp | 6 ++++++ options.cpp | 7 +++++++ utilities.cpp | 6 ++++++ 6 files changed, 53 insertions(+), 3 deletions(-) diff --git a/gpg_wrapper.cpp b/gpg_wrapper.cpp index b85d24b..3ed7f4a 100644 --- a/gpg_wrapper.cpp +++ b/gpg_wrapper.cpp @@ -21,7 +21,7 @@ //boost::mutex gpg_mutex; -pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result) +pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result, HANDLE hProcess) { // gpg_mutex.lock(); if(!gpg_configured) @@ -102,7 +102,6 @@ pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD debuglog<cmd, params->useless, params->out, params->code, params->result); + pxResult result = pxExecute(params->cmd, params->useless, params->out, params->code, params->result, params->hProcess); } diff --git a/gpg_wrapper.h b/gpg_wrapper.h index d9a02c9..f9d6670 100644 --- a/gpg_wrapper.h +++ b/gpg_wrapper.h @@ -24,6 +24,7 @@ struct gpg_execution_params string *out; LPDWORD code; pxResult *result; + HANDLE hProcess; }; void pxEexcute_thread(void *param); diff --git a/main.cpp b/main.cpp index ad091f6..3f8b70c 100644 --- a/main.cpp +++ b/main.cpp @@ -94,6 +94,7 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { gpg_thread.~thread(); + TerminateProcess(params.hProcess, 1); debuglog<timed_join(boost::posix_time::seconds(10))) { delete gpg_thread; + TerminateProcess(params.hProcess, 1); debuglog<timed_join(boost::posix_time::seconds(10))) { delete gpg_thread; + TerminateProcess(params.hProcess, 1); debuglog<timed_join(boost::posix_time::seconds(10))) { delete gpg_thread; + TerminateProcess(params.hProcess, 1); debuglog<timed_join(boost::posix_time::seconds(10))) { delete gpg_thread; + TerminateProcess(params.hProcess, 1); debuglog<timed_join(boost::posix_time::seconds(10))) { delete gpg_thread; + TerminateProcess(params.hProcess, 1); debuglog<timed_join(boost::posix_time::minutes(15))) { delete gpg_thread; + TerminateProcess(params.hProcess, 1); debuglog<timed_join(boost::posix_time::seconds(15))) { delete gpg_thread; + TerminateProcess(params.hProcess, 1); debuglog<timed_join(boost::posix_time::seconds(180))) { delete gpg_thread; + TerminateProcess(params.hProcess, 1); debuglog<timed_join(boost::posix_time::seconds(180))) { delete gpg_thread; + TerminateProcess(params.hProcess, 1); debuglog< Date: Thu, 31 Mar 2011 20:32:41 +0300 Subject: fixed another metacontacts problem, optimized some functions --- messages.cpp | 1 + metacontacts.cpp | 2 +- utilities.cpp | 8 +++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/messages.cpp b/messages.cpp index 226445a..e1b3bdf 100644 --- a/messages.cpp +++ b/messages.cpp @@ -820,6 +820,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) { mir_free(msg); return CallService(MS_PROTO_CHAINSEND, w, l); +// return returnNoError(ccs->hContact); } boost::thread *thr = new boost::thread(boost::bind(SendMsgSvc_func, ccs->hContact, msg, (DWORD)ccs->wParam)); return returnNoError(ccs->hContact); diff --git a/metacontacts.cpp b/metacontacts.cpp index c451d9f..8e282c6 100644 --- a/metacontacts.cpp +++ b/metacontacts.cpp @@ -43,7 +43,7 @@ HANDLE metaGetContact(HANDLE hContact) { if(bMetaContacts) return (HANDLE)CallService(MS_MC_GETMETACONTACT,(WPARAM)hContact,0); - return 0; + return hContact; } bool metaIsSubcontact(HANDLE hContact) { diff --git a/utilities.cpp b/utilities.cpp index 8a2fe53..f05ebed 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -975,7 +975,13 @@ void AddHandlers() bool isContactSecured(HANDLE hContact) { - if(!DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0)) + BYTE gpg_enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); + if(!gpg_enc) + { + hContact = metaGetContact(hContact); + gpg_enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); + } + if(!gpg_enc) return false; TCHAR *key = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); if(!key[0]) -- cgit v1.2.3 From 089c1fb6bcbdb5ea07419486b78da9c3e120ee9c Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Fri, 1 Apr 2011 01:28:48 +0300 Subject: ) --- icons.cpp | 10 +++++++--- messages.cpp | 1 - utilities.cpp | 7 ++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/icons.cpp b/icons.cpp index 1f4d353..a4099db 100644 --- a/icons.cpp +++ b/icons.cpp @@ -81,9 +81,11 @@ void setClistIcon(HANDLE hContact) { bool enabled = isContactSecured(hContact); extern HANDLE g_hCLIcon; - HANDLE hMC = metaGetContact(hContact); + HANDLE hMC = hContact; + if(metaIsProtoMetaContacts(hContact)) + hMC = metaGetContact(hContact); if(g_hCLIcon && enabled) - { // обновить иконки в clist + { HICON icon = IconLibGetIcon("secured"); IconExtraColumn iec = {0}; iec.cbSize = sizeof(iec); @@ -104,7 +106,9 @@ void setSrmmIcon(HANDLE hContact) { hContact = metaGetCurrent(hContact); bool enabled = isContactSecured(hContact); - HANDLE hMC = metaGetContact(hContact); + HANDLE hMC = hContact; + if(metaIsProtoMetaContacts(hContact)) + hMC = metaGetContact(hContact); if(ServiceExists(MS_MSG_MODIFYICON)) { // обновить иконки в srmm StatusIconData sid = {0}; diff --git a/messages.cpp b/messages.cpp index e1b3bdf..226445a 100644 --- a/messages.cpp +++ b/messages.cpp @@ -820,7 +820,6 @@ int SendMsgSvc(WPARAM w, LPARAM l) { mir_free(msg); return CallService(MS_PROTO_CHAINSEND, w, l); -// return returnNoError(ccs->hContact); } boost::thread *thr = new boost::thread(boost::bind(SendMsgSvc_func, ccs->hContact, msg, (DWORD)ccs->wParam)); return returnNoError(ccs->hContact); diff --git a/utilities.cpp b/utilities.cpp index f05ebed..201f359 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -975,12 +975,9 @@ void AddHandlers() bool isContactSecured(HANDLE hContact) { - BYTE gpg_enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); - if(!gpg_enc) - { + if(metaIsProtoMetaContacts(hContact)) hContact = metaGetContact(hContact); - gpg_enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); - } + BYTE gpg_enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); if(!gpg_enc) return false; TCHAR *key = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); -- cgit v1.2.3 From 8cdda41b119526a2741938d57b7e066e1697315b Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Fri, 1 Apr 2011 02:20:17 +0300 Subject: hm )) --- icons.cpp | 2 +- main.cpp | 16 ++++++++-------- messages.cpp | 12 ++++++------ metacontacts.cpp | 24 ++++++------------------ metacontacts.h | 1 - utilities.cpp | 2 +- 6 files changed, 22 insertions(+), 35 deletions(-) diff --git a/icons.cpp b/icons.cpp index a4099db..cd32911 100644 --- a/icons.cpp +++ b/icons.cpp @@ -104,7 +104,7 @@ void setClistIcon(HANDLE hContact) void setSrmmIcon(HANDLE hContact) { - hContact = metaGetCurrent(hContact); + hContact = metaGetMostOnline(hContact); bool enabled = isContactSecured(hContact); HANDLE hMC = hContact; if(metaIsProtoMetaContacts(hContact)) diff --git a/main.cpp b/main.cpp index 3f8b70c..cccb846 100644 --- a/main.cpp +++ b/main.cpp @@ -1839,7 +1839,7 @@ void ImportKey() } } else - DBWriteContactSettingTString(metaGetCurrent(hContact), szGPGModuleName, "GPGPubKey", new_key.c_str()); + DBWriteContactSettingTString(metaGetMostOnline(hContact), szGPGModuleName, "GPGPubKey", new_key.c_str()); } else DBWriteContactSettingTString(hContact, szGPGModuleName, "GPGPubKey", new_key.c_str()); @@ -1859,7 +1859,7 @@ void ImportKey() DeleteFile(tmp2); wfstream f(tmp2, std::ios::out); if(metaIsProtoMetaContacts(hContact)) - ptmp = UniGetContactSettingUtf(metaGetCurrent(hContact), szGPGModuleName, "GPGPubKey", _T("")); + ptmp = UniGetContactSettingUtf(metaGetMostOnline(hContact), szGPGModuleName, "GPGPubKey", _T("")); else ptmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); wstring new_key = ptmp; @@ -1959,7 +1959,7 @@ void ImportKey() char *tmp = NULL; string::size_type s = output.find("gpg: key ") + strlen("gpg: key "); string::size_type s2 = output.find(":", s); - DBWriteContactSettingString(metaGetCurrent(hContact), szGPGModuleName, "KeyID", output.substr(s,s2-s).c_str()); + DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyID", output.substr(s,s2-s).c_str()); s2+=2; s = output.find("“", s2); if(s == string::npos) @@ -1976,7 +1976,7 @@ void ImportKey() 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(metaGetCurrent(hContact), szGPGModuleName, "KeyMainName", tmp); + DBWriteContactSettingString(metaGetContact(hContact), szGPGModuleName, "KeyMainName", tmp); mir_free(tmp); if((s = output.find(")", s2)) == string::npos) s = output.find(">", s2); @@ -1988,14 +1988,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(metaGetCurrent(hContact), szGPGModuleName, "KeyComment", tmp); + DBWriteContactSettingString(metaGetMostOnline(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(metaGetCurrent(hContact), szGPGModuleName, "KeyMainEmail", tmp); + DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyMainEmail", tmp); mir_free(tmp); } else @@ -2003,10 +2003,10 @@ 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(metaGetCurrent(hContact), szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); + DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); mir_free(tmp); } - DBDeleteContactSetting(metaGetCurrent(hContact), szGPGModuleName, "bAlwatsTrust"); + DBDeleteContactSetting(metaGetMostOnline(hContact), szGPGModuleName, "bAlwatsTrust"); } } else diff --git a/messages.cpp b/messages.cpp index 226445a..f7ea63f 100644 --- a/messages.cpp +++ b/messages.cpp @@ -36,7 +36,7 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags) void setSrmmIcon(HANDLE); void setClistIcon(HANDLE); bool isContactHaveKey(HANDLE hContact); - if(!DBGetContactSettingByte(metaGetCurrent(hContact), szGPGModuleName, "GPGEncryption", 0)) + if(!DBGetContactSettingByte(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", 0)) { debuglog< 0) { @@ -179,7 +179,7 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags) s = out.find(" ID ", s); s += strlen(" ID "); string::size_type s2 = out.find(",",s); - DBWriteContactSettingString(metaGetCurrent(hContact), szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str()); + DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str()); } void ShowLoadKeyPasswordWindow(); new_key_hcnt_mutex.lock(); @@ -313,7 +313,7 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags) } } } - if(DBGetContactSettingByte(metaGetCurrent(hContact), szGPGModuleName, "GPGEncryption", 0)) + if(DBGetContactSettingByte(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", 0)) { if(metaIsSubcontact(hContact)) { diff --git a/metacontacts.cpp b/metacontacts.cpp index 8e282c6..46185e4 100644 --- a/metacontacts.cpp +++ b/metacontacts.cpp @@ -42,7 +42,8 @@ bool metaIsDefaultSubContact(HANDLE hContact) HANDLE metaGetContact(HANDLE hContact) { if(bMetaContacts) - return (HANDLE)CallService(MS_MC_GETMETACONTACT,(WPARAM)hContact,0); + if(metaIsSubcontact(hContact)) + return (HANDLE)CallService(MS_MC_GETMETACONTACT,(WPARAM)hContact,0); return hContact; } bool metaIsSubcontact(HANDLE hContact) @@ -57,32 +58,19 @@ HANDLE metaGetMostOnline(HANDLE hContact) { if(bMetaContacts) - return (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT,(WPARAM)hContact,0); + if(metaIsProtoMetaContacts(hContact)) + return (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT,(WPARAM)hContact,0); return hContact; } HANDLE metaGetDefault(HANDLE hContact) { if(bMetaContacts) - return (HANDLE)CallService(MS_MC_GETDEFAULTCONTACT,(WPARAM)hContact,0); + if(metaIsProtoMetaContacts(hContact)) + return (HANDLE)CallService(MS_MC_GETDEFAULTCONTACT,(WPARAM)hContact,0); return hContact; } -HANDLE metaGetCurrent(HANDLE hContact) -{ - bool IsOnline(HANDLE hContact); - if(bMetaContacts) - { - if(!metaIsProtoMetaContacts(hContact)) - return hContact; - HANDLE hcnt = metaGetMostOnline (hContact); - if(!hcnt) - hcnt = metaGetDefault(hContact); - return hcnt; - } - return hContact; -} - DWORD metaGetContactsNum(HANDLE hContact) { diff --git a/metacontacts.h b/metacontacts.h index b7928a9..f7dcfe7 100644 --- a/metacontacts.h +++ b/metacontacts.h @@ -20,6 +20,5 @@ HANDLE metaGetContact(HANDLE hContact); bool metaIsSubcontact(HANDLE hContact); HANDLE metaGetMostOnline(HANDLE hContact); HANDLE metaGetDefault(HANDLE hContact); -HANDLE metaGetCurrent(HANDLE hContact); DWORD metaGetContactsNum(HANDLE hContact); HANDLE metaGetSubcontact(HANDLE hContact, int num); \ No newline at end of file diff --git a/utilities.cpp b/utilities.cpp index 201f359..d368c56 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -396,7 +396,7 @@ int onProtoAck(WPARAM w, LPARAM l) s = out.find(" ID ", s); s += strlen(" ID "); string::size_type s2 = out.find(",",s); - DBWriteContactSettingString(metaGetCurrent(ccs->hContact), szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str()); + DBWriteContactSettingString(metaGetMostOnline(ccs->hContact), szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str()); } void ShowLoadKeyPasswordWindow(); new_key_hcnt_mutex.lock(); -- cgit v1.2.3