From 4d9fce6f544f0c6782a7ade4900afd3e1c6c9c52 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sat, 29 Jan 2011 15:17:51 +0300 Subject: Better metacontacts handling\nFixed subkey length in keygen --- messages.cpp | 285 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 142 insertions(+), 143 deletions(-) (limited to 'messages.cpp') diff --git a/messages.cpp b/messages.cpp index e8954e1..0289685 100644 --- a/messages.cpp +++ b/messages.cpp @@ -36,7 +36,6 @@ int RecvMsgSvc(WPARAM w, LPARAM l) 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; @@ -49,98 +48,98 @@ int RecvMsgSvc(WPARAM w, LPARAM l) { 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); - wfstream f(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, "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); + wfstream f(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); @@ -227,26 +226,26 @@ int RecvMsgSvc(WPARAM w, LPARAM l) else { TCHAR *jid = UniGetContactSettingUtf(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(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"-----PGP KEY REQUEST-----"); + 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(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"-----PGP KEY REQUEST-----"); } } } @@ -496,21 +495,21 @@ int RecvMsgSvc(WPARAM w, LPARAM l) } else { - mir_free((void**)pre->szMessage); if(bAppendTags) { str.insert(0, inopentag); str.append(inclosetag); } - pre->szMessage = mir_strdup(toUTF8(str).c_str()); if(metaIsSubcontact(hContact)) { char *msg = mir_strdup(toUTF8(str).c_str()); - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, DBEF_UTF); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, DBEF_UTF|DBEF_READ); HistoryLog(metaGetContact(hContact), msg, EVENTTYPE_MESSAGE, DBEF_UTF); 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); } } @@ -578,32 +577,32 @@ int SendMsgSvc(WPARAM w, LPARAM l) TCHAR *jid = UniGetContactSettingUtf(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(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (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); - } - } - } + 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(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (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); + } + } + } } } } @@ -738,7 +737,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) str_event.append(toUTF8(outclosetag)); } HistoryLog(hContact, (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT); - HistoryLog(metaGetContact(hContact), (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT); + HistoryLog(metaGetContact(hContact), (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT); hcontact_data[hContact].msgs_to_ignore.push_back((char*)ccs->lParam); hcontact_data[metaGetContact(hContact)].msgs_to_ignore.push_back((char*)ccs->lParam); //hmm, twice ? metacontacts !! %) CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)toUTF8(str).c_str()); -- cgit v1.2.3 From 094d38a1686a807bf6b3a2cea3ef027bd70bb05b Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sat, 29 Jan 2011 17:28:12 +0300 Subject: Metacontacts encodings fix --- messages.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'messages.cpp') diff --git a/messages.cpp b/messages.cpp index 0289685..c597ee3 100644 --- a/messages.cpp +++ b/messages.cpp @@ -1,4 +1,4 @@ -// Copyright © 2010 sss +// Copyright © 2010-2011 sss // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -619,7 +619,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) str.append(tmp); mir_free(tmp); } - { //not xmpp, just replace whole message + { string out; DWORD code; wstring cmd; @@ -736,11 +736,11 @@ int SendMsgSvc(WPARAM w, LPARAM l) str_event.insert(0, toUTF8(outopentag)); str_event.append(toUTF8(outclosetag)); } - HistoryLog(hContact, (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT); - HistoryLog(metaGetContact(hContact), (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT); + HistoryLog(hContact, (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT | DBEF_UTF); + HistoryLog(metaGetContact(hContact), (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT |DBEF_UTF); hcontact_data[hContact].msgs_to_ignore.push_back((char*)ccs->lParam); hcontact_data[metaGetContact(hContact)].msgs_to_ignore.push_back((char*)ccs->lParam); //hmm, twice ? metacontacts !! %) - CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)toUTF8(str).c_str()); + CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UNICODE, (LPARAM)str.c_str()); return returnNoError(hContact); } if(bAppendTags) -- cgit v1.2.3 From 86da56a08b722b906f5e660ab965a995a3ba1ff4 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sat, 29 Jan 2011 17:29:36 +0300 Subject: Additional encoding conversion --- messages.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'messages.cpp') diff --git a/messages.cpp b/messages.cpp index c597ee3..36434ea 100644 --- a/messages.cpp +++ b/messages.cpp @@ -738,8 +738,8 @@ int SendMsgSvc(WPARAM w, LPARAM l) } HistoryLog(hContact, (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT | DBEF_UTF); HistoryLog(metaGetContact(hContact), (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT |DBEF_UTF); - hcontact_data[hContact].msgs_to_ignore.push_back((char*)ccs->lParam); - hcontact_data[metaGetContact(hContact)].msgs_to_ignore.push_back((char*)ccs->lParam); //hmm, twice ? metacontacts !! %) + hcontact_data[hContact].msgs_to_ignore.push_back(toUTF8(toUTF16((char*)ccs->lParam))); + hcontact_data[metaGetContact(hContact)].msgs_to_ignore.push_back(toUTF8(toUTF16((char*)ccs->lParam))); //hmm, twice ? metacontacts !! %) CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UNICODE, (LPARAM)str.c_str()); return returnNoError(hContact); } -- cgit v1.2.3 From 1bfecda76700e3ed89a1e381789a77ab26e262a8 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Tue, 1 Feb 2011 03:48:36 +0300 Subject: metacontacts fixes --- messages.cpp | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'messages.cpp') diff --git a/messages.cpp b/messages.cpp index 36434ea..952d9e5 100644 --- a/messages.cpp +++ b/messages.cpp @@ -520,7 +520,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) { if(metaIsSubcontact(hContact)) { - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, DBEF_UTF); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, DBEF_UTF| DBEF_READ); HistoryLog(metaGetContact(hContact), msg, EVENTTYPE_MESSAGE, DBEF_UTF); mir_free(msg); return 1; @@ -551,7 +551,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) hcontact_data[ccs->hContact].msgs_to_ignore.push_back((char*)ccs->lParam); return CallService(MS_PROTO_CHAINSEND, w, l); } - if(!isContactHaveKey(hContact) && bAutoExchange && !strstr(msg, "-----PGP KEY REQUEST-----") && !strstr(msg, "-----BEGIN PGP PUBLIC KEY BLOCK-----") && isGPGConfigured()) //TODO: add all mesages to list, and send after key exchange done, encrypted + if(!isContactHaveKey(hContact) && 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)hContact, 0); @@ -611,11 +611,17 @@ int SendMsgSvc(WPARAM w, LPARAM l) { //encrypt data here wstring str; + bool isansi = false; if(!metaIsSubcontact(hContact)) str = toUTF16(msg); else {//workaround ... - wchar_t *tmp = mir_a2t(msg); + wchar_t *tmp = mir_utf8decodeW(msg); + if(!tmp) + { + tmp = mir_a2t(msg); + isansi = true; + } str.append(tmp); mir_free(tmp); } @@ -702,7 +708,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) } if(out.find("usage: ") != string::npos) { - MessageBox(0, _T("Something wrong, gpg does not understand us, aborting encrypting."), _T("Warning"), MB_OK); + MessageBox(0, _T("Something wrong, gpg does not understand us, aborting encryption."), _T("Warning"), MB_OK); DeleteFile(path.c_str()); return CallService(MS_PROTO_CHAINSEND, w, l); } @@ -732,15 +738,22 @@ int SendMsgSvc(WPARAM w, LPARAM l) { //dirty hack to avoid metacontacts problem ..., this also broke filters chain string str_event = (char*)ccs->lParam; if(bAppendTags) - { + { //utf8 tag will cause problems here str_event.insert(0, toUTF8(outopentag)); str_event.append(toUTF8(outclosetag)); } - HistoryLog(hContact, (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT | DBEF_UTF); - HistoryLog(metaGetContact(hContact), (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT |DBEF_UTF); - hcontact_data[hContact].msgs_to_ignore.push_back(toUTF8(toUTF16((char*)ccs->lParam))); - hcontact_data[metaGetContact(hContact)].msgs_to_ignore.push_back(toUTF8(toUTF16((char*)ccs->lParam))); //hmm, twice ? metacontacts !! %) - CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UNICODE, (LPARAM)str.c_str()); + DWORD flags = 0, flags2 = 0; + if(!isansi) //message from metacontact itself, yet another metacontacts workaround... + flags |= DBEF_UTF; + else + flags2 |= DBEF_READ; + HistoryLog(hContact, (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT | flags2 | flags); + HistoryLog(metaGetContact(hContact), (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT | flags); + hcontact_data[hContact].msgs_to_ignore.push_back(msg); + if(isansi) + hcontact_data[hContact].msgs_to_ignore.push_back(msg); + hcontact_data[metaGetContact(hContact)].msgs_to_ignore.push_back(msg); + CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)toUTF8(str).c_str()); return returnNoError(hContact); } if(bAppendTags) @@ -758,7 +771,7 @@ int HookSendMsg(WPARAM w, LPARAM l) DBEVENTINFO * dbei = (DBEVENTINFO*)l; if((dbei->eventType == EVENTTYPE_MESSAGE) && (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-----")) //grrrr! + 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()) -- cgit v1.2.3 From 02fa894d6d4ecada2f3c79a2fd3fb84c0d4425ad Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Tue, 1 Feb 2011 04:11:54 +0300 Subject: hm... --- messages.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'messages.cpp') diff --git a/messages.cpp b/messages.cpp index 952d9e5..a0389a7 100644 --- a/messages.cpp +++ b/messages.cpp @@ -750,8 +750,6 @@ int SendMsgSvc(WPARAM w, LPARAM l) HistoryLog(hContact, (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT | flags2 | flags); HistoryLog(metaGetContact(hContact), (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT | flags); hcontact_data[hContact].msgs_to_ignore.push_back(msg); - if(isansi) - hcontact_data[hContact].msgs_to_ignore.push_back(msg); hcontact_data[metaGetContact(hContact)].msgs_to_ignore.push_back(msg); CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)toUTF8(str).c_str()); return returnNoError(hContact); -- cgit v1.2.3