From c83fb4b4bfd6b29e0264d5215ce43f6afe10ce51 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 22 Aug 2012 06:32:09 +0300 Subject: autoexchange fixes db event filter fixes backported fixes from miranda_ng port --- gpg_wrapper.cpp | 4 +- main.cpp | 88 ++++++++++++++++------------- messages.cpp | 172 +++++++++++++++++++++++++++++++++----------------------- options.cpp | 29 +++++----- utilities.cpp | 25 ++++---- 5 files changed, 183 insertions(+), 135 deletions(-) diff --git a/gpg_wrapper.cpp b/gpg_wrapper.cpp index 3ad3d23..e420faa 100755 --- a/gpg_wrapper.cpp +++ b/gpg_wrapper.cpp @@ -96,8 +96,8 @@ pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD commandline += _T("--display-charset utf-8 "); commandline += _T("-z 9 "); commandline += *acommandline; - delete [] bin_path; //hmm - delete [] home_dir; + mir_free(bin_path); + mir_free(home_dir); } debuglog<szProtoName); + strcat(svc, PS_ICQ_ADDCAPABILITY); + if(ServiceExists(svc)) + CallService(svc, 0, (LPARAM)&cap); + } } } @@ -2249,7 +2261,7 @@ void ImportKey() 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]; + tmp = (char*)mir_alloc(sizeof(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); @@ -2261,14 +2273,14 @@ void ImportKey() s2++; if(output[s] == ')') { - tmp = new char [output.substr(s2,s-s2).length()+1]; + tmp = (char*)mir_alloc(sizeof(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]; + tmp = (char*) mir_alloc(sizeof(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); @@ -2276,7 +2288,7 @@ void ImportKey() } else { - tmp = new char [output.substr(s2,s-s2).length()+1]; + tmp = (char*)mir_alloc(sizeof(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()); diff --git a/messages.cpp b/messages.cpp index 18b2378..5dc673c 100755 --- a/messages.cpp +++ b/messages.cpp @@ -25,7 +25,7 @@ int returnNoError(HANDLE hContact); std::list sent_msgs; -int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, DWORD timestamp) +void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, DWORD timestamp) { DWORD dbflags = DBEF_UTF; { //check for gpg related data @@ -69,7 +69,7 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, D { HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); - return 0; + return; } } { @@ -169,14 +169,15 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, D CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"Unable to decrypt PGP encrypted message"); HistoryLog(hContact, db_event("Error message sent", 0, 0, DBEF_SENT)); DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc); - return 0; + return; } if(result == pxNotFound) { DeleteFile(path.c_str()); HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); - return 0; + return; } + //TODO: check gpg output for errors _terminate = false; while(out.find("public key decryption failed: bad passphrase") != string::npos) { @@ -232,14 +233,15 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, D CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"Unable to decrypt PGP encrypted message"); HistoryLog(hContact, db_event("Error message sent", 0, 0, DBEF_SENT)); DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc); - return 0; + return; } if(result == pxNotFound) { DeleteFile(path.c_str()); HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); - return 0; + return; } + //TODO: check gpg output for errors } out.clear(); gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); @@ -256,13 +258,14 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, D CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"Unable to decrypt PGP encrypted message"); HistoryLog(hContact, db_event("Error message sent", 0, 0, DBEF_SENT)); DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc); - return 0; + return; } if(result == pxNotFound) { DeleteFile(path.c_str()); HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); } + //TODO: check gpg output for errors { wstring tmp = tmp2; tmp += _T("\\tmp\\"); @@ -289,7 +292,7 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, D HistoryLog(hContact, db_event("Error message sent", 0, 0, DBEF_SENT)); DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc); mir_free(tmp); - return 0; + return; } } } @@ -326,7 +329,7 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, D HistoryLog(hContact, db_event("Error message sent", 0, 0, DBEF_SENT)); DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc); mir_free(tmp); - return 0; + return; } else { @@ -341,12 +344,12 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, D HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags|DBEF_READ)); HistoryLog(metaGetContact(hContact), db_event(msg, timestamp, 0, dbflags)); mir_free(msg); - return 0; + return; } char *tmp = mir_strdup(toUTF8(str).c_str()); HistoryLog(hContact, db_event(tmp, timestamp, 0, dbflags)); mir_free(tmp); - return 0; + return; } } } @@ -358,13 +361,13 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, D { HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags|DBEF_READ)); HistoryLog(metaGetContact(hContact), db_event(msg, timestamp, 0, dbflags)); - return 0; + return; } HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags|DBEF_READ)); - return 0; + return; } HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); - return 0; + return; } int RecvMsgSvc(WPARAM w, LPARAM l) @@ -381,7 +384,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) 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)) + if(bAutoExchange && (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-----")); @@ -389,7 +392,6 @@ int RecvMsgSvc(WPARAM w, LPARAM l) { 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}; @@ -434,6 +436,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) } if(result == pxNotFound) return 1; + //TODO: check gpg output for errors { char *tmp = NULL; string::size_type s = output.find("gpg: key ") + strlen("gpg: key "); @@ -452,7 +455,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) 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]; + tmp = (char*)mir_alloc(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); @@ -464,14 +467,14 @@ int RecvMsgSvc(WPARAM w, LPARAM l) s2++; if(output[s] == ')') { - tmp = new char [output.substr(s2,s-s2).length()+1]; + tmp = (char*)mir_alloc(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]; + tmp = (char*)mir_alloc(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); @@ -479,12 +482,13 @@ int RecvMsgSvc(WPARAM w, LPARAM l) } else { - tmp = new char [output.substr(s2,s-s2).length()+1]; + tmp = (char*)mir_alloc(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, "GPGEncryption", 1); DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "bAlwatsTrust", 1); void setSrmmIcon(HANDLE); void setClistIcon(HANDLE); @@ -550,64 +554,77 @@ int RecvMsgSvc(WPARAM w, LPARAM l) char *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", ""); if(tmp[0]) { - DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "GPGEncryption", 0); + int enc_state = DBGetContactSettingByte(ccs->hContact, szGPGModuleName, "GPGEncryption", 0); + if(enc_state) + 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); + if(enc_state) + DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "GPGEncryption", 1); } mir_free(tmp); - if(!isContactHaveKey(ccs->hContact) && bAutoExchange && gpg_valid && gpg_keyexist) + return returnNoError(ccs->hContact); + } + else if(!isContactHaveKey(ccs->hContact) && bAutoExchange && gpg_valid && gpg_keyexist) + { + LPSTR proto = (LPSTR)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)ccs->hContact, 0); + DWORD uin = DBGetContactSettingDword(ccs->hContact, proto, "UIN", 0); + if(uin) { - LPSTR proto = (LPSTR)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)ccs->hContact, 0); - DWORD uin = DBGetContactSettingDword(ccs->hContact, proto, "UIN", 0); - if(uin) + char *proto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)ccs->hContact, 0); + char svc[64]; + strcpy(svc, proto); + strcat(svc, PS_ICQ_CHECKCAPABILITY); + if(ServiceExists(svc)) { - if(ServiceExists("ICQ"PS_ICQ_CHECKCAPABILITY)) + ICQ_CUSTOMCAP cap = {0}; + strcpy(cap.caps, "GPG AutoExchange"); + if(CallService(svc, (WPARAM)ccs->hContact, (LPARAM)&cap)) { - 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-----"); + CallContactService(ccs->hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"-----PGP KEY REQUEST-----"); + return returnNoError(ccs->hContact); } } - else + } + else + { + TCHAR *jid = UniGetContactSettingUtf(ccs->hContact, proto, "jid", _T("")); + if(jid[0]) { - 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++) { - 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) { - 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) { - 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-----"); + CallContactService(ccs->hContact, PSS_MESSAGE, (WPARAM)0, (LPARAM)"-----PGP KEY REQUEST-----"); + return returnNoError(ccs->hContact); } } } } } - 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, pre->timestamp)); - return returnNoError(ccs->hContact); + boost::thread *thr = new boost::thread(boost::bind(RecvMsgSvc_func, ccs->hContact, str, msg, ccs->wParam, pre->timestamp)); + return returnNoError(ccs->hContact); } -int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) +void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) { wstring str; bool isansi = false; @@ -654,7 +671,8 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) HistoryLog(hContact, db_event("Failed to encrypt message with GPG", 0,0, 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); + CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); + return; } if(!bJabberAPI || !bIsMiranda09) //force jabber to handle encrypted message by itself cmd += _T("--comment \"\" --no-version "); @@ -700,13 +718,16 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) params.hProcess = NULL; debuglog<hContact, proto, "UIN", 0); if(uin) { - if(ServiceExists("ICQ"PS_ICQ_CHECKCAPABILITY)) + char *proto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)ccs->hContact, 0); + char svc[64]; + strcpy(svc, proto); + strcat(svc, PS_ICQ_CHECKCAPABILITY); + + if(ServiceExists(svc)) { ICQ_CUSTOMCAP cap = {0}; strcpy(cap.caps, "GPG AutoExchange"); - if(CallService("ICQ"PS_ICQ_CHECKCAPABILITY, (WPARAM)ccs->hContact, (LPARAM)&cap)) + if(CallService(svc, (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); @@ -848,7 +880,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) if(caps) { wstring str; - for(int i =0;;i++) + for(int i=0;;i++) { str.push_back(caps[i]); if(caps[i] == '\0') @@ -893,12 +925,14 @@ int HookSendMsg(WPARAM w, LPARAM l) DBEVENTINFO * dbei = (DBEVENTINFO*)l; if(dbei->eventType != EVENTTYPE_MESSAGE) return 0; + HANDLE hContact = (HANDLE)w; 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. + if(isContactSecured(hContact) && strstr((char*)dbei->pBlob, "-----BEGIN PGP MESSAGE-----")) //our service data, can be double added by metacontacts e.t.c. + return 1; + if(bAutoExchange && (strstr((char*)dbei->pBlob, "-----PGP KEY RESPONSE-----") || strstr((char*)dbei->pBlob, "-----PGP KEY REQUEST-----"))) ///do not show service data in history return 1; } - HANDLE hContact = (HANDLE)w; if(isContactSecured(hContact) && (dbei->flags & DBEF_SENT)) //aggressive outgoing events filtering { if(!hcontact_data[hContact].msgs_to_pass.empty()) diff --git a/options.cpp b/options.cpp index 109d54c..5cd837d 100755 --- a/options.cpp +++ b/options.cpp @@ -669,22 +669,22 @@ static BOOL CALLBACK DlgProcGpgMsgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP GetDlgItemText(hwndDlg, IDC_IN_OPEN_TAG, tmp, 128); DBWriteContactSettingTString(NULL, szGPGModuleName, "szInOpenTag", tmp); mir_free(inopentag); - inopentag = new TCHAR [_tcslen(tmp)+1]; + inopentag = (TCHAR*)mir_alloc(sizeof(TCHAR)* (_tcslen(tmp)+1)); _tcscpy(inopentag, tmp); GetDlgItemText(hwndDlg, IDC_IN_CLOSE_TAG, tmp, 128); DBWriteContactSettingTString(NULL, szGPGModuleName, "szInCloseTag", tmp); mir_free(inclosetag); - inclosetag = new TCHAR [_tcslen(tmp)+1]; + inclosetag = (TCHAR*)mir_alloc(sizeof(TCHAR)* (_tcslen(tmp)+1)); _tcscpy(inclosetag, tmp); GetDlgItemText(hwndDlg, IDC_OUT_OPEN_TAG, tmp, 128); DBWriteContactSettingTString(NULL, szGPGModuleName, "szOutOpenTag", tmp); mir_free(outopentag); - outopentag = new TCHAR [_tcslen(tmp)+1]; + outopentag = (TCHAR*)mir_alloc(sizeof(TCHAR)* (_tcslen(tmp)+1)); _tcscpy(outopentag, tmp); GetDlgItemText(hwndDlg, IDC_OUT_CLOSE_TAG, tmp, 128); DBWriteContactSettingTString(NULL, szGPGModuleName, "szOutCloseTag", tmp); mir_free(outclosetag); - outclosetag = new TCHAR [_tcslen(tmp)+1]; + outclosetag = (TCHAR*)mir_alloc(sizeof(TCHAR)*(_tcslen(tmp)+1)); _tcscpy(outclosetag, tmp); } return TRUE; @@ -796,7 +796,7 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP { tmp = UniGetContactSettingUtf(hcnt, szGPGModuleName, "GPGPubKey", _T("")); wstring str = tmp; - mir_free(tmp); + mir_free(tmp); tmp = NULL; wstring::size_type p = 0, stop = 0; if(!str.empty()) { @@ -878,7 +878,8 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP } mir_free(tmp2); } - mir_free(tmp); + if(tmp) + mir_free(tmp); SetDlgItemText(hwndDlg, IDC_PUBLIC_KEY_EDIT, !str.empty()?str.c_str():_T("")); } hPubKeyEdit = GetDlgItem(hwndDlg, IDC_PUBLIC_KEY_EDIT); @@ -904,16 +905,16 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP ws1 = 0; if(((ws2 = key_buf.find(_T("-----END PGP PUBLIC KEY BLOCK-----"))) != wstring::npos) && ((ws1 = key_buf.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----"))) != wstring::npos)) { - begin = new TCHAR [_tcslen(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")) + 1]; + begin = (TCHAR*)mir_alloc(sizeof(TCHAR) * (_tcslen(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")) + 1)); _tcscpy(begin, _T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); - end = new TCHAR [_tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----")) + 1]; + end = (TCHAR*)mir_alloc(sizeof( TCHAR) * (_tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----")) + 1)); _tcscpy(end, _T("-----END PGP PUBLIC KEY BLOCK-----")); } else if(((ws2 = key_buf.find(_T("-----END PGP PRIVATE KEY BLOCK-----"))) != wstring::npos) && ((ws1 = key_buf.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----"))) != wstring::npos)) { - begin = new TCHAR [_tcslen(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")) + 1]; + begin = (TCHAR*)mir_alloc(sizeof(TCHAR) * (_tcslen(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")) + 1)); _tcscpy(begin, _T("-----BEGIN PGP PRIVATE KEY BLOCK-----")); - end = new TCHAR [_tcslen(_T("-----END PGP PRIVATE KEY BLOCK-----")) + 1]; + end = (TCHAR*)mir_alloc(sizeof(TCHAR) * (_tcslen(_T("-----END PGP PRIVATE KEY BLOCK-----")) + 1)); _tcscpy(end, _T("-----END PGP PRIVATE KEY BLOCK-----")); } else @@ -944,7 +945,7 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP else DBWriteContactSettingTString(hContact, szGPGModuleName, "GPGPubKey", key_buf.substr(ws1,ws2-ws1).c_str()); } - tmp = new TCHAR [key_buf.length()+1]; + tmp = (TCHAR*)mir_alloc(sizeof( TCHAR) * (key_buf.length()+1)); _tcscpy(tmp, key_buf.substr(ws1,ws2-ws1).c_str()); { //gpg execute block wstring cmd; @@ -1030,7 +1031,7 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP char *tmp2; string::size_type s = output.find("gpg: key ") + strlen("gpg: key "); string::size_type s2 = output.find(":", s); - tmp2 = new char [output.substr(s,s2-s).length()+1]; + tmp2 = (char*)mir_alloc(output.substr(s,s2-s).length()+1); strcpy(tmp2, output.substr(s,s2-s).c_str()); mir_utf8decode(tmp2, 0); { @@ -1072,7 +1073,7 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP s2 = output.find("<", s); if(s2 != string::npos) { - tmp2 = new char [output.substr(s,s2-s-1).length()+1]; + tmp2 = (char*)mir_alloc(output.substr(s,s2-s-1).length()+1); strcpy(tmp2, output.substr(s,s2-s-1).c_str()); mir_utf8decode(tmp2, 0); if(hContact) @@ -1167,7 +1168,7 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP } else { - tmp2 = new char [output.substr(s2,s-s2).length()+1]; + tmp2 = (char*)mir_alloc(output.substr(s2,s-s2).length()+1); strcpy(tmp2, output.substr(s2,s-s2).c_str()); mir_utf8decode(tmp2, 0); if(hContact) diff --git a/utilities.cpp b/utilities.cpp index 56d3033..e071aaf 100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -23,9 +23,9 @@ TCHAR* __stdcall UniGetContactSettingUtf(HANDLE hContact, const char *szModule,c DBVARIANT dbv = {DBVT_DELETED}; TCHAR* szRes; if (DBGetContactSettingTString(hContact, szModule, szSetting, &dbv)) - return _tcsdup(szDef); + return mir_tstrdup(szDef); if(dbv.pszVal) - szRes = _tcsdup(dbv.ptszVal); + szRes = mir_tstrdup(dbv.ptszVal); DBFreeVariant(&dbv); return szRes; } @@ -35,9 +35,9 @@ char* __stdcall UniGetContactSettingUtf(HANDLE hContact, const char *szModule,co DBVARIANT dbv = {DBVT_DELETED}; char* szRes; if (DBGetContactSettingString(hContact, szModule, szSetting, &dbv)) - return _strdup(szDef); + return mir_strdup(szDef); if(dbv.pszVal) - szRes = _strdup(dbv.pszVal); + szRes = mir_strdup(dbv.pszVal); DBFreeVariant(&dbv); return szRes; } @@ -1091,14 +1091,14 @@ bool isGPGValid() else { mir_free(tmp); - TCHAR *path = new TCHAR [MAX_PATH]; - char *mir_path = new char [MAX_PATH]; + TCHAR *path = (TCHAR*)mir_alloc(sizeof(TCHAR)*MAX_PATH); + char *mir_path = (char*)mir_alloc(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]; + //mir_realloc(path, (_tcslen(path)+64)*sizeof(TCHAR)); + TCHAR *gpg_path = (TCHAR*)mir_alloc(sizeof(TCHAR)*MAX_PATH); _tcscpy(gpg_path, tmp); _tcscat(gpg_path, _T("\\GnuPG\\gpg.exe")); mir_free(tmp); @@ -1108,8 +1108,8 @@ bool isGPGValid() _tcscpy(path, _T("GnuPG\\gpg.exe")); } mir_free(gpg_path); - tmp = mir_wstrdup(path); - delete [] path; + tmp = mir_tstrdup(path); + mir_free(path); } DWORD len = MAX_PATH; if(gpg_exists) @@ -1139,14 +1139,15 @@ bool isGPGValid() if(p1 == string::npos) is_valid = false; } - mir_free(tmp); + mir_free(tmp); tmp = NULL; if(!gpg_exists) { wstring path_ = _wgetenv(_T("APPDATA")); path_ += _T("\\GnuPG"); tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", (TCHAR*)path_.c_str()); } - mir_free(tmp); + if(tmp) + mir_free(tmp); return is_valid; } -- cgit v1.2.3