From 823800856ab18c23357e108bb9d923cee497ea03 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 12 Oct 2011 17:12:04 +0300 Subject: modified: messages.cpp modified: new_gpg.vcxproj modified: utilities.cpp --- utilities.cpp | 264 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 138 insertions(+), 126 deletions(-) mode change 100644 => 100755 utilities.cpp (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp old mode 100644 new mode 100755 index dbf8786..b7498e5 --- a/utilities.cpp +++ b/utilities.cpp @@ -282,164 +282,176 @@ int onProtoAck(WPARAM w, LPARAM l) if (ack->type!=ACKTYPE_FILE) return 0; - switch(ack->result) + if(ack->type == ACKTYPE_FILE) { - case ACKRESULT_DENIED: case ACKRESULT_FAILED: - break; - case ACKRESULT_SUCCESS: + switch(ack->result) { - PROTOFILETRANSFERSTATUS *f = (PROTOFILETRANSFERSTATUS*) ack->hProcess; - TCHAR *filename = NULL; - if(f->flags & PFTS_UNICODE) - { - if(f->tszCurrentFile && f->tszCurrentFile[0]) - filename = mir_wstrdup(f->tszCurrentFile); - if(!filename) - return 0; - } - else + case ACKRESULT_DENIED: case ACKRESULT_FAILED: + break; + case ACKRESULT_SUCCESS: { - if(f->szCurrentFile && f->szCurrentFile[0]) - filename = mir_utf8decodeT(f->szCurrentFile); - if(!filename) - return 0; - } - if(_tcsstr(filename, _T(".gpg"))) //decrypt it - { //process encrypted file - if(_waccess(f->tszCurrentFile, 0) == -1) + PROTOFILETRANSFERSTATUS *f = (PROTOFILETRANSFERSTATUS*) ack->hProcess; + TCHAR *filename = NULL; + if(f->flags & PFTS_UNICODE) { - if(errno == ENOENT) + if(f->tszCurrentFile && f->tszCurrentFile[0]) + filename = mir_wstrdup(f->tszCurrentFile); + if(!filename) return 0; } - string out; - DWORD code; - pxResult result; - wstring cmd = _T("-o "); - wstring file = filename; - wstring::size_type p1 = file.rfind(_T(".gpg")); - file.erase(p1, _tcslen(_T(".gpg"))); - if(_waccess(file.c_str(), 0) != -1) + else { - if(MessageBox(0, _T("Target file exists, do you want to replace it ?"), _T("Warning"), MB_YESNO) == IDNO) + if(f->szCurrentFile && f->szCurrentFile[0]) + filename = mir_utf8decodeT(f->szCurrentFile); + if(!filename) return 0; } - DeleteFile(file.c_str()); - file.insert(0, _T("\"")); - file.insert(file.length(), _T("\" ")); - cmd += file; - 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) + if(_tcsstr(filename, _T(".gpg"))) //decrypt it + { //process encrypted file + if(_waccess(f->tszCurrentFile, 0) == -1) { - cmd += _T("--passphrase \""); - cmd += pass; - cmd += _T("\" "); + if(errno == ENOENT) + return 0; } - else if(password) + string out; + DWORD code; + pxResult result; + wstring cmd = _T("-o "); + wstring file = filename; + wstring::size_type p1 = file.rfind(_T(".gpg")); + file.erase(p1, _tcslen(_T(".gpg"))); + if(_waccess(file.c_str(), 0) != -1) { - debuglog<hContact, GCDNF_TCHAR)<<" with password\n"; - cmd += _T("--passphrase \""); - cmd += password; - cmd += _T("\" "); + if(MessageBox(0, _T("Target file exists, do you want to replace it ?"), _T("Warning"), MB_YESNO) == IDNO) + return 0; } - else - debuglog<hContact, GCDNF_TCHAR)<<" with out password\n"; - mir_free(pass); - mir_free(keyid); - } - gpg_execution_params params; - params.cmd = &cmd; - params.useless = ""; - params.out = &out; - 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(15))) - { - delete gpg_thread; - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - 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(metaGetMostOnline(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); + DeleteFile(file.c_str()); + file.insert(0, _T("\"")); + file.insert(file.length(), _T("\" ")); + cmd += file; + 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); } - out.clear(); gpg_execution_params params; - pxResult result; - params.cmd = &cmd2; + params.cmd = &cmd; 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(15))) + boost::thread *gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread->timed_join(boost::posix_time::minutes(15))) { delete gpg_thread; TerminateProcess(params.hProcess, 1); params.hProcess = NULL; 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(metaGetMostOnline(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(15))) + { + delete gpg_thread; + TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; + debuglog<type == ACKTYPE_MESSAGE) + { + extern std::list sent_msgs; + std::list::iterator it = std::find(sent_msgs.begin(), sent_msgs.end(), ack->hProcess); + if(it != sent_msgs.end()) + { + HistoryLog(ack->hContact, db_event("Failed to send encrypted message", 0,0, 0)); + } + } return 0; } -- cgit v1.2.3 From 4df8492d1da4ce2d4fb075221c0baf79e91f1734 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 12 Oct 2011 17:13:15 +0300 Subject: modified: utilities.cpp --- utilities.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index b7498e5..b066e22 100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -443,7 +443,7 @@ int onProtoAck(WPARAM w, LPARAM l) break; } } - else if(ack->type == ACKTYPE_MESSAGE) + else if(ack->type == ACKTYPE_MESSAGE && ack->result == ACKRESULT_FAILED) { extern std::list sent_msgs; std::list::iterator it = std::find(sent_msgs.begin(), sent_msgs.end(), ack->hProcess); -- cgit v1.2.3 From 16c7f7b357556eb8c38a3b265fbed5e67ac77789 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 12 Oct 2011 17:15:35 +0300 Subject: modified: utilities.cpp --- utilities.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index b066e22..83e13da 100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -446,10 +446,14 @@ int onProtoAck(WPARAM w, LPARAM l) else if(ack->type == ACKTYPE_MESSAGE && ack->result == ACKRESULT_FAILED) { extern std::list sent_msgs; - std::list::iterator it = std::find(sent_msgs.begin(), sent_msgs.end(), ack->hProcess); - if(it != sent_msgs.end()) + if(!sent_msgs.empty()) { - HistoryLog(ack->hContact, db_event("Failed to send encrypted message", 0,0, 0)); + std::list::iterator it = std::find(sent_msgs.begin(), sent_msgs.end(), ack->hProcess); + if(it != sent_msgs.end()) + { + HistoryLog(ack->hContact, db_event("Failed to send encrypted message", 0,0, 0)); + sent_msgs.erase(it); + } } } return 0; -- cgit v1.2.3 From 34317b53102eb8d1cad310fec31922a85bf9add9 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 12 Oct 2011 17:22:39 +0300 Subject: modified: utilities.cpp --- utilities.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index 83e13da..9356728 100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -275,14 +275,10 @@ extern bool bFileTransfers; int onProtoAck(WPARAM w, LPARAM l) { - if(!bFileTransfers) - return 0; ACKDATA *ack=(ACKDATA*)l; CCSDATA *ccs=(CCSDATA*)ack->lParam; - if (ack->type!=ACKTYPE_FILE) - return 0; - if(ack->type == ACKTYPE_FILE) + if(ack->type == ACKTYPE_FILE && bFileTransfers) { switch(ack->result) { -- cgit v1.2.3 From 448c6ca661ec9c826cd18bd160e050cf21da112c Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 12 Oct 2011 23:03:15 +0300 Subject: notification on failed delivery --- utilities.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index 9356728..9d2a9be 100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -439,16 +439,25 @@ int onProtoAck(WPARAM w, LPARAM l) break; } } - else if(ack->type == ACKTYPE_MESSAGE && ack->result == ACKRESULT_FAILED) + else if(ack->type == ACKTYPE_MESSAGE) { extern std::list sent_msgs; if(!sent_msgs.empty()) { - std::list::iterator it = std::find(sent_msgs.begin(), sent_msgs.end(), ack->hProcess); - if(it != sent_msgs.end()) + if(ack->result == ACKRESULT_FAILED) { - HistoryLog(ack->hContact, db_event("Failed to send encrypted message", 0,0, 0)); - sent_msgs.erase(it); + std::list::iterator it = std::find(sent_msgs.begin(), sent_msgs.end(), ack->hProcess); + if(it != sent_msgs.end()) + { + HistoryLog(ack->hContact, db_event("Failed to send encrypted message", 0,0, 0)); + + } + } + else if(ack->result == ACKRESULT_SUCCESS) + { + std::list::iterator it = std::find(sent_msgs.begin(), sent_msgs.end(), ack->hProcess); + if(it != sent_msgs.end()) + sent_msgs.erase(it); } } } @@ -1166,13 +1175,14 @@ void send_encrypted_msgs_thread(HANDLE hContact) { boost::this_thread::sleep(boost::posix_time::seconds(1)); list::iterator end = hcontact_data[hContact].msgs_to_send.end(); + extern std::list sent_msgs; for(list::iterator p = hcontact_data[hContact].msgs_to_send.begin(); p != end; ++p) { - CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)p->c_str()); - + sent_msgs.push_back((HANDLE)CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)p->c_str())); HistoryLog(hContact, db_event((char*)p->c_str(),0,0, DBEF_SENT)); boost::this_thread::sleep(boost::posix_time::seconds(1)); } + hcontact_data[hContact].msgs_to_send.clear(); return; } else -- cgit v1.2.3 From 24f43db848336aec381d0d61f30e5ec067905e32 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Thu, 3 Nov 2011 20:37:56 +0200 Subject: basic utf8cpp exceptions handling --- utilities.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index 9d2a9be..b651558 100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -1138,7 +1138,14 @@ int returnNoError(HANDLE hContact) { string toUTF8(wstring str) { string ustr; + try{ utf8::utf16to8(str.begin(), str.end(), back_inserter(ustr)); + } + catch(const utf8::exception& e) + { + debuglog< Date: Wed, 29 Feb 2012 04:51:39 +0200 Subject: psi gpg error handling code (not working) --- utilities.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index b651558..efebcfb 100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -970,6 +970,61 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi static JABBER_HANDLER_FUNC MessageHandler(IJabberInterface *ji, HXML node, void *pUserData) { + HXML local_node = node; + HANDLE hContact = NULL; + for(int n = 0; n <= xi.getChildCount(node); n++) + { + LPCTSTR str = xi.getText(local_node); + LPCTSTR nodename = xi.getName(local_node); + if(nodename) + { + if(!_tcscmp(nodename, _T("message"))) + { + for(int n = 0; n < xi.getAttrCount(local_node); n++) + { + LPCTSTR name = xi.getAttrName(local_node, n); + LPCTSTR value = xi.getAttrValue(local_node, name); + if(!_tcscmp(name, _T("from"))) + { + hContact = ji->Sys()->ContactFromJID(value); + if(!hContact) + return FALSE; + } + if(!_tcscmp(name, _T("type"))) + { + if(_tcscmp(value, _T("error"))) + return FALSE; + } + } + } + if(!_tcscmp(nodename, _T("error"))) + { + for(int n = 0; n < xi.getAttrCount(local_node); n++) + { + LPCTSTR name = xi.getAttrName(local_node, n); + LPCTSTR value = xi.getAttrValue(local_node, name); + if(!_tcscmp(name, _T("type"))) + { + if(_tcscmp(value, _T("modify"))) + return FALSE; + } + if(!_tcscmp(name, _T("code"))) + { + if(_tcscmp(value, _T("406"))) + return FALSE; + } + } + } + if(!_tcscmp(nodename, _T("text"))) + { + LPCTSTR msg = xi.getText(local_node); + if(hContact) + HistoryLog(hContact, (char*)toUTF8(msg).c_str()); + return FALSE; + } + } + local_node = xi.getChild(node, n); + } return FALSE; } @@ -989,7 +1044,7 @@ void AddHandlers() if((*p)->getPrescenseHandler() == INVALID_HANDLE_VALUE) (*p)->setPrescenseHandler((*p)->getJabberInterface()->Net()->AddPresenceHandler((JABBER_HANDLER_FUNC)PrescenseHandler)); if((*p)->getMessageHandler() == INVALID_HANDLE_VALUE) - (*p)->setMessageHandler((*p)->getJabberInterface()->Net()->AddMessageHandler((JABBER_HANDLER_FUNC)MessageHandler, JABBER_MESSAGE_TYPE_ERROR,0 ,0)); + (*p)->setMessageHandler((*p)->getJabberInterface()->Net()->AddMessageHandler((JABBER_HANDLER_FUNC)MessageHandler, JABBER_MESSAGE_TYPE_ANY ,NULL,NULL)); if(bAutoExchange) { (*p)->getJabberInterface()->Net()->RegisterFeature(_T("GPG_Key_Auto_Exchange:0"), _T("Indicates that gpg installed and configured to public key auto exchange (currently implemented in new_gpg Miranda IM plugin)")); -- cgit v1.2.3 From a1263e7ff1d2d2eecaa06c7c906cf1a15270b8f1 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Thu, 1 Mar 2012 03:41:02 +0200 Subject: modified: utilities.cpp --- utilities.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index efebcfb..f0a36fb 100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -970,7 +970,7 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi static JABBER_HANDLER_FUNC MessageHandler(IJabberInterface *ji, HXML node, void *pUserData) { - HXML local_node = node; +/* HXML local_node = node; HANDLE hContact = NULL; for(int n = 0; n <= xi.getChildCount(node); n++) { @@ -1024,7 +1024,7 @@ static JABBER_HANDLER_FUNC MessageHandler(IJabberInterface *ji, HXML node, void } } local_node = xi.getChild(node, n); - } + }*/ return FALSE; } @@ -1043,8 +1043,8 @@ void AddHandlers() (*p)->setSendHandler((*p)->getJabberInterface()->Net()->AddSendHandler((JABBER_HANDLER_FUNC)SendHandler)); if((*p)->getPrescenseHandler() == INVALID_HANDLE_VALUE) (*p)->setPrescenseHandler((*p)->getJabberInterface()->Net()->AddPresenceHandler((JABBER_HANDLER_FUNC)PrescenseHandler)); - if((*p)->getMessageHandler() == INVALID_HANDLE_VALUE) - (*p)->setMessageHandler((*p)->getJabberInterface()->Net()->AddMessageHandler((JABBER_HANDLER_FUNC)MessageHandler, JABBER_MESSAGE_TYPE_ANY ,NULL,NULL)); +// if((*p)->getMessageHandler() == INVALID_HANDLE_VALUE) +// (*p)->setMessageHandler((*p)->getJabberInterface()->Net()->AddMessageHandler((JABBER_HANDLER_FUNC)MessageHandler, JABBER_MESSAGE_TYPE_ANY ,NULL,NULL)); if(bAutoExchange) { (*p)->getJabberInterface()->Net()->RegisterFeature(_T("GPG_Key_Auto_Exchange:0"), _T("Indicates that gpg installed and configured to public key auto exchange (currently implemented in new_gpg Miranda IM plugin)")); -- cgit v1.2.3 From ffef21cd7a2a48d51ed40c71993b5810616d96d6 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sun, 4 Mar 2012 17:12:13 +0200 Subject: modified: utilities.cpp --- utilities.cpp | 55 ------------------------------------------------------- 1 file changed, 55 deletions(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index f0a36fb..78bbca5 100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -970,61 +970,6 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi static JABBER_HANDLER_FUNC MessageHandler(IJabberInterface *ji, HXML node, void *pUserData) { -/* HXML local_node = node; - HANDLE hContact = NULL; - for(int n = 0; n <= xi.getChildCount(node); n++) - { - LPCTSTR str = xi.getText(local_node); - LPCTSTR nodename = xi.getName(local_node); - if(nodename) - { - if(!_tcscmp(nodename, _T("message"))) - { - for(int n = 0; n < xi.getAttrCount(local_node); n++) - { - LPCTSTR name = xi.getAttrName(local_node, n); - LPCTSTR value = xi.getAttrValue(local_node, name); - if(!_tcscmp(name, _T("from"))) - { - hContact = ji->Sys()->ContactFromJID(value); - if(!hContact) - return FALSE; - } - if(!_tcscmp(name, _T("type"))) - { - if(_tcscmp(value, _T("error"))) - return FALSE; - } - } - } - if(!_tcscmp(nodename, _T("error"))) - { - for(int n = 0; n < xi.getAttrCount(local_node); n++) - { - LPCTSTR name = xi.getAttrName(local_node, n); - LPCTSTR value = xi.getAttrValue(local_node, name); - if(!_tcscmp(name, _T("type"))) - { - if(_tcscmp(value, _T("modify"))) - return FALSE; - } - if(!_tcscmp(name, _T("code"))) - { - if(_tcscmp(value, _T("406"))) - return FALSE; - } - } - } - if(!_tcscmp(nodename, _T("text"))) - { - LPCTSTR msg = xi.getText(local_node); - if(hContact) - HistoryLog(hContact, (char*)toUTF8(msg).c_str()); - return FALSE; - } - } - local_node = xi.getChild(node, n); - }*/ return FALSE; } -- cgit v1.2.3 From bf88761455597a47f1074d01c4a29c41e0fe270c Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sat, 10 Mar 2012 21:13:22 +0200 Subject: copyrights --- utilities.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index 78bbca5..f6a0290 100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -1,4 +1,4 @@ -// Copyright © 2010 sss +// Copyright © 2010-2012 sss // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License -- cgit v1.2.3 From 365d949d8ec2712fbdec479e73e78cbbe80b3399 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Fri, 18 May 2012 22:28:05 +0300 Subject: fixed (#33 Settings) --- utilities.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index f6a0290..0648c37 100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -1033,7 +1033,7 @@ bool isContactHaveKey(HANDLE hContact) return false; } -bool isGPGConfigured() +bool isGPGKeyExist() { TCHAR *id = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", _T("")); char *key = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", ""); @@ -1047,6 +1047,74 @@ bool isGPGConfigured() mir_free(key); return false; } +bool isGPGValid() +{ + TCHAR *tmp; + bool gpg_exists = false, is_valid = true; + tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", _T("")); + if(_waccess(tmp, 0) != -1) + gpg_exists = true; + else + { + mir_free(tmp); + TCHAR *path = new TCHAR [MAX_PATH]; + char *mir_path = new char [MAX_PATH]; + CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); + SetCurrentDirectoryA(mir_path); + tmp = mir_a2t(mir_path); + mir_free(mir_path); + mir_realloc(path, (_tcslen(path)+128)*sizeof(TCHAR)); + TCHAR *gpg_path = new TCHAR [MAX_PATH]; + _tcscpy(gpg_path, tmp); + _tcscat(gpg_path, _T("\\GnuPG\\gpg.exe")); + mir_free(tmp); + if(_waccess(gpg_path, 0) != -1) + { + gpg_exists = true; + _tcscpy(path, _T("GnuPG\\gpg.exe")); + } + mir_free(gpg_path); + tmp = mir_wstrdup(path); + delete [] path; + } + DWORD len = MAX_PATH; + if(gpg_exists) + { + DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp); + string out; + DWORD code; + wstring cmd = _T("--version"); + gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + gpg_valid = true; + boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + { + gpg_thread.~thread(); + TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; + debuglog< Date: Sun, 20 May 2012 07:24:29 +0300 Subject: metacontacts fixes --- utilities.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index 0648c37..67e0238 100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -234,7 +234,7 @@ int ToggleEncryption(WPARAM w, LPARAM l) } } else - DBWriteContactSettingByte(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", enc?0:1); + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc?0:1); void setSrmmIcon(HANDLE hContact); void setClistIcon(HANDLE hContact); setSrmmIcon(hContact); @@ -393,7 +393,10 @@ int onProtoAck(WPARAM w, LPARAM l) s = out.find(" ID ", s); s += strlen(" ID "); string::size_type s2 = out.find(",",s); - DBWriteContactSettingString(metaGetMostOnline(ccs->hContact), szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str()); + if(metaIsProtoMetaContacts(ccs->hContact)) + DBWriteContactSettingString(metaGetMostOnline(ccs->hContact), szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str()); + else + DBWriteContactSettingString(ccs->hContact, szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str()); } void ShowLoadKeyPasswordWindow(); new_key_hcnt_mutex.lock(); -- cgit v1.2.3 From 829c3778ac700f2d64e7032d0727f860196e4417 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Mon, 21 May 2012 00:38:28 +0300 Subject: fixed another metacontacts problem --- utilities.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index 67e0238..c52edde 100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -1280,3 +1280,28 @@ string time_str() boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); return (string)boost::posix_time::to_simple_string(now); } + +int handleEnum(const char *szSetting, LPARAM lParam) +{ + if(szSetting[0] && StriStr(szSetting, "tabsrmm")) + { + bool f = false, *found = (bool*)lParam; + f = !DBGetContactSettingByte(NULL, "PluginDisable", szSetting, 0); + if(f) + *found = f; + } + return 0; +} + +bool isTabsrmmUsed() +{ + DBCONTACTENUMSETTINGS enm = {0}; + bool found = false; + enm.lParam = (LPARAM)&found; + enm.pfnEnumProc = (DBSETTINGENUMPROC)&handleEnum; + enm.szModule = "PluginDisable"; + if(CallService(MS_DB_CONTACT_ENUMSETTINGS, (WPARAM)NULL, (LPARAM)&enm) == -1) + return false; + + return found; +} -- cgit v1.2.3 From 9f3797b01596d50ad2df063c1860eb3a5eb0b8e0 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Fri, 25 May 2012 17:42:34 +0300 Subject: fixed tabsrmm detection --- utilities.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index c52edde..1d0cde2 100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -1283,7 +1283,7 @@ string time_str() int handleEnum(const char *szSetting, LPARAM lParam) { - if(szSetting[0] && StriStr(szSetting, "tabsrmm")) + if(!*(bool*)lParam && szSetting[0] && StriStr(szSetting, "tabsrmm")) { bool f = false, *found = (bool*)lParam; f = !DBGetContactSettingByte(NULL, "PluginDisable", szSetting, 0); -- cgit v1.2.3 From 072e6741acb7323279beaf516107a5d09d91cf09 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Mon, 28 May 2012 02:54:36 +0300 Subject: keys export //TODO: keys import --- utilities.cpp | 193 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index 1d0cde2..af4eb3b 100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -1305,3 +1305,196 @@ bool isTabsrmmUsed() return found; } + + +int ExportGpGKeys(WPARAM w, LPARAM l) +{ + TCHAR *p = GetFilePath(_T("Choose file to export public keys"), _T("*"), _T("Any file"), true); + if(!p || !p[0]) + { + delete [] p; + //TODO: handle error + return 1; + } + char *path = mir_t2a(p); + delete [] p; + std::ofstream file; + file.open(path, std::ios::trunc | std::ios::out); + mir_free(path); + if(!file.is_open()) + return 1; //TODO: handle error + for (HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) + { + char *k = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", ""); + if(!k[0]) + { + mir_free(k); + continue; + } + std::string key = k; + mir_free(k); + + const char* proto = (const char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); + std::string id = "Comment: login "; + const char * uid = (const char*)CallProtoService(proto, PS_GETCAPS, (WPARAM)PFLAG_UNIQUEIDSETTING, 0); + DBVARIANT dbv = {0}; + DBCONTACTGETSETTING dbcgs = {0}; + dbcgs.pValue = &dbv; + dbcgs.szModule = proto; + dbcgs.szSetting = uid; + CallService(MS_DB_CONTACT_GETSETTING, 0, (LPARAM)&dbcgs); + switch(dbcgs.pValue->type) + { + case DBVT_DELETED: + continue; + break; + case DBVT_BYTE: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->bVal); + id += _id; + } + break; + case DBVT_WORD: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->wVal); + id += _id; + } + break; + case DBVT_DWORD: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->dVal); + id += _id; + } + break; + case DBVT_ASCIIZ: + { + id += dbcgs.pValue->pszVal; + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + } + break; + case DBVT_UTF8: + { + char *tmp = mir_utf8decodeA(dbcgs.pValue->pszVal); + if(tmp[0]) + id += tmp; + mir_free(tmp); + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + } + break; + case DBVT_BLOB: + //TODO + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + break; + case DBVT_WCHAR: + //TODO + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + break; + } + id += " contact_id "; + ZeroMemory(&dbv, sizeof(dbv)); + ZeroMemory(&dbcgs, sizeof(dbcgs)); + dbcgs.pValue = &dbv; + dbcgs.szModule = proto; + dbcgs.szSetting = uid; + CallService(MS_DB_CONTACT_GETSETTING, (WPARAM)hContact, (LPARAM)&dbcgs); + switch(dbcgs.pValue->type) + { + case DBVT_DELETED: + continue; + break; + case DBVT_BYTE: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->bVal); + id += _id; + } + break; + case DBVT_WORD: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->wVal); + id += _id; + } + break; + case DBVT_DWORD: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->dVal); + id += _id; + } + break; + case DBVT_ASCIIZ: + { + id += dbcgs.pValue->pszVal; + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + } + break; + case DBVT_UTF8: + { + char *tmp = mir_utf8decodeA(dbcgs.pValue->pszVal); + if(tmp[0]) + id += tmp; + mir_free(tmp); + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + } + break; + case DBVT_BLOB: + //TODO + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + break; + case DBVT_WCHAR: + //TODO + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + break; + } + + std::string::size_type p1 = key.find("-----BEGIN PGP PUBLIC KEY BLOCK-----"); + if(p1 == std::string::npos) + continue; + p1 += strlen("-----BEGIN PGP PUBLIC KEY BLOCK-----"); + p1 ++; + id += '\n'; + key.insert(p1, id); + file< Date: Mon, 28 May 2012 02:58:17 +0300 Subject: modified: utilities.cpp --- utilities.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index af4eb3b..1353ae0 100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -1487,10 +1487,12 @@ int ImportGpGKeys(WPARAM w, LPARAM l) return 1; //TODO: handle error std::string key, login, contact; key += line; + key += '\n'; while(file.is_open()) { file.getline(line, 255); key += line; + key += '\n'; if(strstr(line, "-----END PGP PUBLIC KEY BLOCK-----")) { //TODO: parse key key.clear(); -- cgit v1.2.3 From 31321966cc6b6008ba84236ba87748aa46a347ed Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Mon, 28 May 2012 13:53:01 +0300 Subject: keys import in progress --- utilities.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index 1353ae0..25d29c1 100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -1468,7 +1468,7 @@ int ExportGpGKeys(WPARAM w, LPARAM l) int ImportGpGKeys(WPARAM w, LPARAM l) { - TCHAR *p = GetFilePath(_T("Choose file to export import keys from"), _T("*"), _T("Any file")); + TCHAR *p = GetFilePath(_T("Choose file to import keys from"), _T("*"), _T("Any file")); if(!p || !p[0]) { delete [] p; @@ -1485,18 +1485,34 @@ int ImportGpGKeys(WPARAM w, LPARAM l) file.getline(line, 255); if(!strstr(line, "-----BEGIN PGP PUBLIC KEY BLOCK-----")) return 1; //TODO: handle error - std::string key, login, contact; + std::string key, login, contact_id; key += line; key += '\n'; - while(file.is_open()) + while(file.is_open() && !file.eof()) { file.getline(line, 255); key += line; key += '\n'; if(strstr(line, "-----END PGP PUBLIC KEY BLOCK-----")) { //TODO: parse key + std::string::size_type p1 = 0, p2 = 0; + p1 = key.find("Comment: login "); + p1 += strlen("Comment: login "); + p2 = key.find(" contact_id "); + login = key.substr(p1, p2-p1); + p2 += strlen(" contact_id "); + p1 = key.find("\n", p2); + contact_id = key.substr(p2, p1-p2); + p1 = key.find("Comment: login "); + p2 = key.find("\n", p1); + p2++; + key.erase(p1, p2-p1); + + key.clear(); } } + if(file.is_open()) + file.close(); return 0; } \ No newline at end of file -- cgit v1.2.3 From e321f6795124cc95aab0e194600f88d97aca5f45 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Mon, 28 May 2012 20:34:08 +0300 Subject: working key export/import --- utilities.cpp | 323 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 300 insertions(+), 23 deletions(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index 25d29c1..26354ea 100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -1321,9 +1321,10 @@ int ExportGpGKeys(WPARAM w, LPARAM l) std::ofstream file; file.open(path, std::ios::trunc | std::ios::out); mir_free(path); + int exported_keys = 0; if(!file.is_open()) return 1; //TODO: handle error - for (HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) + for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) { char *k = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", ""); if(!k[0]) @@ -1400,7 +1401,7 @@ int ExportGpGKeys(WPARAM w, LPARAM l) dbcgs.szModule = proto; dbcgs.szSetting = uid; CallService(MS_DB_CONTACT_GETSETTING, (WPARAM)hContact, (LPARAM)&dbcgs); - switch(dbcgs.pValue->type) + switch(dbcgs.pValue->type) { case DBVT_DELETED: continue; @@ -1450,7 +1451,6 @@ int ExportGpGKeys(WPARAM w, LPARAM l) CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); break; } - std::string::size_type p1 = key.find("-----BEGIN PGP PUBLIC KEY BLOCK-----"); if(p1 == std::string::npos) continue; @@ -1460,9 +1460,13 @@ int ExportGpGKeys(WPARAM w, LPARAM l) key.insert(p1, id); file<szModuleName, PS_GETCAPS, (WPARAM)PFLAG_UNIQUEIDSETTING, 0); + DBVARIANT dbv = {0}; + DBCONTACTGETSETTING dbcgs = {0}; + dbcgs.pValue = &dbv; + dbcgs.szModule = accs[i]->szModuleName; + dbcgs.szSetting = uid; + CallService(MS_DB_CONTACT_GETSETTING, 0, (LPARAM)&dbcgs); + std::string id; + switch(dbcgs.pValue->type) + { + case DBVT_DELETED: + continue; + break; + case DBVT_BYTE: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->bVal); + id += _id; + if(id == login) + acc = accs[i]->szModuleName; + } + break; + case DBVT_WORD: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->wVal); + id += _id; + if(id == login) + acc = accs[i]->szModuleName; + } + break; + case DBVT_DWORD: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->dVal); + id += _id; + if(id == login) + acc = accs[i]->szModuleName; + } + break; + case DBVT_ASCIIZ: + { + id += dbcgs.pValue->pszVal; + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + if(id == login) + acc = accs[i]->szModuleName; + } + break; + case DBVT_UTF8: + { + char *tmp = mir_utf8decodeA(dbcgs.pValue->pszVal); + if(tmp[0]) + id += tmp; + mir_free(tmp); + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + if(id == login) + acc = accs[i]->szModuleName; + } + break; + case DBVT_BLOB: + //TODO + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + break; + case DBVT_WCHAR: + //TODO + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + break; + } } + if(acc.length()) + { + const char * uid = (const char*)CallProtoService(acc.c_str(), PS_GETCAPS, (WPARAM)PFLAG_UNIQUEIDSETTING, 0); + for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, (LPARAM)acc.c_str()); hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, (LPARAM)acc.c_str())) + { + DBVARIANT dbv = {0}; + DBCONTACTGETSETTING dbcgs = {0}; + dbcgs.pValue = &dbv; + dbcgs.szModule = acc.c_str(); + dbcgs.szSetting = uid; + CallService(MS_DB_CONTACT_GETSETTING, (WPARAM)hContact, (LPARAM)&dbcgs); + std::string id; + bool found = false; + switch(dbcgs.pValue->type) + { + case DBVT_DELETED: + continue; + break; + case DBVT_BYTE: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->bVal); + id += _id; + if(id == contact_id) + found = true; + } + break; + case DBVT_WORD: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->wVal); + id += _id; + if(id == contact_id) + found = true; + } + break; + case DBVT_DWORD: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->dVal); + id += _id; + if(id == contact_id) + found = true; + } + break; + case DBVT_ASCIIZ: + { + id += dbcgs.pValue->pszVal; + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + if(id == contact_id) + found = true; + } + break; + case DBVT_UTF8: + { + char *tmp = mir_utf8decodeA(dbcgs.pValue->pszVal); + if(tmp[0]) + id += tmp; + mir_free(tmp); + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + if(id == contact_id) + found = true; + } + break; + case DBVT_BLOB: + //TODO + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + break; + case DBVT_WCHAR: + //TODO + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + break; + } + if(found) + { + wstring cmd; + TCHAR tmp2[MAX_PATH] = {0}; + TCHAR *ptmp; + string output; + DWORD exitcode; + { + HANDLE hcnt = hContact; + 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); + f< output.find("<", s)) + s2 = output.find("<", s); + if(s2 != string::npos) + { + tmp2 = new char [output.substr(s,s2-s-1).length()+1]; + strcpy(tmp2, output.substr(s,s2-s-1).c_str()); + mir_utf8decode(tmp2, 0); + if(hContact) + { + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainName", output.substr(s,s2-s-1).c_str()); + } + mir_free(tmp2); + 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] == ')') + { + tmp2 = new char [output.substr(s2,s-s2).length()+1]; + strcpy(tmp2, output.substr(s2,s-s2).c_str()); + mir_utf8decode(tmp2, 0); + if(hContact) + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyComment", output.substr(s2,s-s2).c_str()); + mir_free(tmp2); + s+=3; + s2 = output.find(">", s); + tmp2 = new char [output.substr(s,s2-s).length()+1]; + strcpy(tmp2, output.substr(s,s2-s).c_str()); + mir_utf8decode(tmp2, 0); + if(hContact) + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s,s2-s).c_str()); + mir_free(tmp2); + } + else + { + tmp2 = new char [output.substr(s2,s-s2).length()+1]; + strcpy(tmp2, output.substr(s2,s-s2).c_str()); + mir_utf8decode(tmp2, 0); + if(hContact) + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); + mir_free(tmp2); + } + } + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1); + DBWriteContactSettingTString(hContact, szGPGModuleName, "GPGPubKey", toUTF16(key).c_str()); + } + DeleteFile(tmp2); + break; + } + } + } + key.clear(); + } } if(file.is_open()) file.close(); + char msg[512]; + 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 -- cgit v1.2.3 From 7b7229fd6fa8df0fbe52f82aa7b08354ddda76ba Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sat, 2 Jun 2012 06:54:03 +0300 Subject: option to disable prescense subscription metacontacts fix --- utilities.cpp | 231 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 115 insertions(+), 116 deletions(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index 26354ea..56f7ccb 100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -716,7 +716,7 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU return FALSE; } } - if(nodename) + if(bPrescenseSubscription && nodename) { if(_tcsstr(nodename, _T("status"))) { @@ -1663,121 +1663,120 @@ int ImportGpGKeys(WPARAM w, LPARAM l) break; } if(found) - { - wstring cmd; - TCHAR tmp2[MAX_PATH] = {0}; - TCHAR *ptmp; - string output; - DWORD exitcode; - { - HANDLE hcnt = hContact; - 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); - f< output.find("<", s)) - s2 = output.find("<", s); - if(s2 != string::npos) - { - tmp2 = new char [output.substr(s,s2-s-1).length()+1]; - strcpy(tmp2, output.substr(s,s2-s-1).c_str()); - mir_utf8decode(tmp2, 0); - if(hContact) - { - DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainName", output.substr(s,s2-s-1).c_str()); - } - mir_free(tmp2); - 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] == ')') - { - tmp2 = new char [output.substr(s2,s-s2).length()+1]; - strcpy(tmp2, output.substr(s2,s-s2).c_str()); - mir_utf8decode(tmp2, 0); - if(hContact) - DBWriteContactSettingString(hContact, szGPGModuleName, "KeyComment", output.substr(s2,s-s2).c_str()); - mir_free(tmp2); - s+=3; - s2 = output.find(">", s); - tmp2 = new char [output.substr(s,s2-s).length()+1]; - strcpy(tmp2, output.substr(s,s2-s).c_str()); - mir_utf8decode(tmp2, 0); - if(hContact) - DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s,s2-s).c_str()); - mir_free(tmp2); - } - else - { - tmp2 = new char [output.substr(s2,s-s2).length()+1]; - strcpy(tmp2, output.substr(s2,s-s2).c_str()); - mir_utf8decode(tmp2, 0); - if(hContact) - DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); - mir_free(tmp2); - } - } - DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1); - DBWriteContactSettingTString(hContact, szGPGModuleName, "GPGPubKey", toUTF16(key).c_str()); - } + { + wstring cmd; + TCHAR tmp2[MAX_PATH] = {0}; + TCHAR *ptmp; + string output; + DWORD exitcode; + { + HANDLE hcnt = hContact; + 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); + f< output.find("<", s)) + s2 = output.find("<", s); + if(s2 != string::npos) + { + tmp2 = new char [output.substr(s,s2-s-1).length()+1]; + strcpy(tmp2, output.substr(s,s2-s-1).c_str()); + mir_utf8decode(tmp2, 0); + if(hContact) + { + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainName", output.substr(s,s2-s-1).c_str()); + } + mir_free(tmp2); + 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] == ')') + { + tmp2 = new char [output.substr(s2,s-s2).length()+1]; + strcpy(tmp2, output.substr(s2,s-s2).c_str()); + mir_utf8decode(tmp2, 0); + if(hContact) + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyComment", output.substr(s2,s-s2).c_str()); + mir_free(tmp2); + s+=3; + s2 = output.find(">", s); + tmp2 = new char [output.substr(s,s2-s).length()+1]; + strcpy(tmp2, output.substr(s,s2-s).c_str()); + mir_utf8decode(tmp2, 0); + if(hContact) + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s,s2-s).c_str()); + mir_free(tmp2); + } + else + { + tmp2 = new char [output.substr(s2,s-s2).length()+1]; + strcpy(tmp2, output.substr(s2,s-s2).c_str()); + mir_utf8decode(tmp2, 0); + if(hContact) + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); + mir_free(tmp2); + } + } + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1); + DBWriteContactSettingTString(hContact, szGPGModuleName, "GPGPubKey", toUTF16(key).c_str()); + } DeleteFile(tmp2); break; } -- cgit v1.2.3 From dd580e5cae07351821fa52c24fe7ac254bc8004f Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sat, 2 Jun 2012 08:58:30 +0300 Subject: typo fixes --- utilities.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index 56f7ccb..114f2dc 100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -716,7 +716,7 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU return FALSE; } } - if(bPrescenseSubscription && nodename) + if(bPresenceSigning && nodename) { if(_tcsstr(nodename, _T("status"))) { -- cgit v1.2.3 From ad52d967c7f67428bf7c6aea6c376a1a43c65735 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Mon, 4 Jun 2012 23:56:26 +0300 Subject: fixed filetransfers #21 (tested only with jabber) --- utilities.cpp | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index 114f2dc..6b2261d 100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -277,7 +277,7 @@ int onProtoAck(WPARAM w, LPARAM l) { ACKDATA *ack=(ACKDATA*)l; CCSDATA *ccs=(CCSDATA*)ack->lParam; - + if(ack->type == ACKTYPE_FILE && bFileTransfers) { switch(ack->result) @@ -312,7 +312,7 @@ int onProtoAck(WPARAM w, LPARAM l) string out; DWORD code; pxResult result; - wstring cmd = _T("-o "); + wstring cmd = _T(" -o "); wstring file = filename; wstring::size_type p1 = file.rfind(_T(".gpg")); file.erase(p1, _tcslen(_T(".gpg"))); @@ -325,13 +325,10 @@ int onProtoAck(WPARAM w, LPARAM l) file.insert(0, _T("\"")); file.insert(file.length(), _T("\" ")); cmd += file; - cmd += _T(" -d \""); - cmd += filename; - cmd += _T("\""); extern TCHAR *password; { // password TCHAR *pass = NULL; - char *keyid = UniGetContactSettingUtf(ccs->hContact, szGPGModuleName, "KeyID", ""); + char *keyid = UniGetContactSettingUtf(ack->hContact, szGPGModuleName, "KeyID", ""); if(strlen(keyid) > 0) { string dbsetting = "szKey_"; @@ -339,13 +336,13 @@ int onProtoAck(WPARAM w, LPARAM l) dbsetting += "_Password"; pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), _T("")); if(_tcslen(pass) > 0) - debuglog<hContact, GCDNF_TCHAR)<<" with password\n"; + 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"; + debuglog<hContact, GCDNF_TCHAR)<<" with password\n"; } if(_tcslen(pass) > 0) { @@ -355,16 +352,19 @@ int onProtoAck(WPARAM w, LPARAM l) } else if(password) { - debuglog<hContact, GCDNF_TCHAR)<<" with password\n"; + debuglog<hContact, GCDNF_TCHAR)<<" with password\n"; cmd += _T("--passphrase \""); cmd += password; cmd += _T("\" "); } else - debuglog<hContact, GCDNF_TCHAR)<<" with out password\n"; + debuglog<hContact, GCDNF_TCHAR)<<" with out password\n"; mir_free(pass); mir_free(keyid); } + cmd += _T(" -d \""); + cmd += filename; + cmd += _T("\""); gpg_execution_params params; params.cmd = &cmd; params.useless = ""; @@ -385,7 +385,7 @@ int onProtoAck(WPARAM w, LPARAM l) extern bool _terminate; extern HANDLE new_key_hcnt; extern boost::mutex new_key_hcnt_mutex; - debuglog<hContact, GCDNF_TCHAR)<<" password needed, trying to get one\n"; + debuglog<hContact, GCDNF_TCHAR)<<" password needed, trying to get one\n"; if(_terminate) break; { //save inkey id @@ -393,19 +393,19 @@ int onProtoAck(WPARAM w, LPARAM l) s = out.find(" ID ", s); s += strlen(" ID "); string::size_type s2 = out.find(",",s); - if(metaIsProtoMetaContacts(ccs->hContact)) - DBWriteContactSettingString(metaGetMostOnline(ccs->hContact), szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str()); + if(metaIsProtoMetaContacts(ack->hContact)) + DBWriteContactSettingString(metaGetMostOnline(ack->hContact), szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str()); else - DBWriteContactSettingString(ccs->hContact, szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str()); + DBWriteContactSettingString(ack->hContact, szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str()); } void ShowLoadKeyPasswordWindow(); new_key_hcnt_mutex.lock(); - new_key_hcnt = ccs->hContact; + new_key_hcnt = ack->hContact; ShowLoadKeyPasswordWindow(); wstring cmd2 = cmd; if(password) { - debuglog<hContact, GCDNF_TCHAR)<<"\n"; + debuglog<hContact, GCDNF_TCHAR)<<"\n"; wstring tmp = _T("--passphrase \""); tmp += password; tmp += _T("\" "); @@ -472,10 +472,9 @@ std::wstring encrypt_file(HANDLE hContact, TCHAR *filename) string out; DWORD code; pxResult result; + HANDLE hcnt = metaIsProtoMetaContacts(hContact)?metaGetMostOnline(hContact):hContact; wstring cmd = _T("--batch --yes -r "); - char *keyid = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", ""); - if(DBGetContactSettingByte(hContact, szGPGModuleName, "bAlwaysTrust", 0)) - cmd += _T("--trust-model always "); + char *keyid = UniGetContactSettingUtf(hcnt, szGPGModuleName, "KeyID", ""); TCHAR *szKeyid = mir_a2t(keyid); TCHAR *name = _tcsrchr(filename,_T('\\')); if( !name ) @@ -485,6 +484,8 @@ std::wstring encrypt_file(HANDLE hContact, TCHAR *filename) TCHAR *file_out = new TCHAR [_tcslen(filename)+4]; mir_sntprintf(file_out, _tcslen(name)+7, _T("%s.gpg"), name); cmd += szKeyid; + if(DBGetContactSettingByte(hcnt, szGPGModuleName, "bAlwaysTrust", 0)) + cmd += _T(" --trust-model always "); mir_free(szKeyid); mir_free(keyid); cmd += _T(" -o \""); @@ -523,7 +524,7 @@ std::wstring encrypt_file(HANDLE hContact, TCHAR *filename) 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(hContact, szGPGModuleName, "bAlwaysTrust", 1); + DBWriteContactSettingByte(hcnt, 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))) @@ -552,7 +553,8 @@ int onSendFile(WPARAM w, LPARAM l) DWORD flags = (DWORD)ccs->wParam; //check for PFTS_UNICODE here int i; - if(flags & PFTS_UNICODE) +// if(flags & PFTS_UNICODE) //this does not work .... + if(StriStr(ccs->szProtoService, "/sendfilew")) { TCHAR **file=(TCHAR **)ccs->lParam; for(i = 0; file[i]; i++) -- cgit v1.2.3 From e0db8851abe880553f48a0b2454dde293ffb22b2 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Mon, 2 Jul 2012 23:26:17 +0300 Subject: =?UTF-8?q?added=20ability=20to=20set=20private=20key=20for=20each?= =?UTF-8?q?=20protocol=20(#50=20=09=D0=A1=D0=B2=D0=BE=D0=B9=20=D0=BA=D0=BB?= =?UTF-8?q?=D1=8E=D1=87=20=D0=B4=D0=BB=D1=8F=20=D0=BA=D0=B0=D0=B6=D0=B4?= =?UTF-8?q?=D0=BE=D0=B9=20=D1=83=D1=87=D0=B5=D1=82=D0=BD=D0=BE=D0=B9=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D0=B8=D1=81=D0=B8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utilities.cpp | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index 6b2261d..2207213 100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -195,8 +195,23 @@ int SendKey(WPARAM w, LPARAM l) HANDLE hContact = (HANDLE)w; if(metaIsProtoMetaContacts(hContact)) hContact = metaGetMostOnline(hContact); - char *szMessage = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", ""); - if(strlen(szMessage) > 1) + char *szMessage; + { + char *proto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); + char setting[64]; + if(proto) + { + strcpy(setting, proto); + strcat(setting, "_GPGPubKey"); + szMessage = UniGetContactSettingUtf(NULL, szGPGModuleName, setting, ""); + } + if(!szMessage[0]) + { + mir_free(szMessage); + szMessage = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", ""); + } + } + if(szMessage[0]) { BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); @@ -746,7 +761,19 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU DWORD code; wstring cmd; { - char *inkeyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", ""); + char *inkeyid; + { + char *proto = ji->Sys()->GetModuleName(); + char setting[64]; + strcpy(setting, proto); + strcat(setting, "_KeyID"); + inkeyid = UniGetContactSettingUtf(NULL, szGPGModuleName, setting, ""); + if(!inkeyid[0]) + { + mir_free(inkeyid); + inkeyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", ""); + } + } TCHAR *pass = NULL; if(inkeyid[0]) { -- cgit v1.2.3