summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2012-08-22 06:32:09 +0300
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2012-08-22 06:32:09 +0300
commitc83fb4b4bfd6b29e0264d5215ce43f6afe10ce51 (patch)
tree4138c085fd34d5f240fee74923d97f593f3f9068
parenteb9bd73e489c5b7a0e75f1c3140dfbd9b9f29ae4 (diff)
autoexchange fixes
db event filter fixes backported fixes from miranda_ng port
-rwxr-xr-xgpg_wrapper.cpp4
-rwxr-xr-xmain.cpp88
-rwxr-xr-xmessages.cpp172
-rwxr-xr-xoptions.cpp29
-rwxr-xr-xutilities.cpp25
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<<time_str()<<": gpg in: "<<commandline<<"\n";
diff --git a/main.cpp b/main.cpp
index 3857f38..e28114c 100755
--- a/main.cpp
+++ b/main.cpp
@@ -1218,16 +1218,17 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam,
{
wstring path;
{ //data sanity checks
- TCHAR *tmp = new TCHAR [5];
+ TCHAR *tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*5);
GetDlgItemText(hwndDlg, IDC_KEY_TYPE, tmp, 5);
if(_tcslen(tmp) < 3)
{
- mir_free(tmp);
+ mir_free(tmp); tmp = NULL;
MessageBox(0, TranslateT("You must set encryption algorythm first"), TranslateT("Error"), MB_OK);
break;
}
- mir_free(tmp);
- tmp = new TCHAR [5];
+ if(tmp)
+ mir_free(tmp);
+ tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*6);
GetDlgItemText(hwndDlg, IDC_KEY_LENGTH, tmp, 5);
int length = _ttoi(tmp);
mir_free(tmp);
@@ -1236,39 +1237,39 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam,
MessageBox(0, TranslateT("Key length must be of length from 1024 to 4096 bits"), TranslateT("Error"), MB_OK);
break;
}
- tmp = new TCHAR [12];
- GetDlgItemText(hwndDlg, IDC_KEY_EXPIRE_DATE, tmp, 12);
+ tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*12);
+ GetDlgItemText(hwndDlg, IDC_KEY_EXPIRE_DATE, tmp, 11);
if(_tcslen(tmp) != 10 && tmp[0] != '0')
{
MessageBox(0, TranslateT("Invalid date"), TranslateT("Error"), MB_OK);
- delete [] tmp;
+ mir_free(tmp);
break;
}
- delete [] tmp;
- tmp = new TCHAR [128];
- GetDlgItemText(hwndDlg, IDC_KEY_REAL_NAME, tmp, 128);
+ mir_free(tmp);
+ tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*128);
+ GetDlgItemText(hwndDlg, IDC_KEY_REAL_NAME, tmp, 127);
if(_tcslen(tmp) < 5)
{
MessageBox(0, TranslateT("Name must contain at least 5 characters"), TranslateT("Error"), MB_OK);
- delete [] tmp;
+ mir_free(tmp);
break;
}
else if (_tcschr(tmp, _T('(')) || _tcschr(tmp, _T(')')))
{
MessageBox(0, TranslateT("Name cannot contain '(' or ')'"), TranslateT("Error"), MB_OK);
- delete [] tmp;
+ mir_free(tmp);
break;
}
- delete [] tmp;
- tmp = new TCHAR [128];
+ mir_free(tmp);
+ tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*128);
GetDlgItemText(hwndDlg, IDC_KEY_EMAIL, tmp, 128);
if((_tcslen(tmp)) < 5 || (!_tcschr(tmp, _T('@'))) || (!_tcschr(tmp, _T('.'))))
{
MessageBox(0, TranslateT("Invalid Email"), TranslateT("Error"), MB_OK);
- delete [] tmp;
+ mir_free(tmp);
break;
}
- delete [] tmp;
+ mir_free(tmp);
}
{ //generating key file
TCHAR *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T(""));
@@ -1284,11 +1285,11 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam,
break;
}
f<<"Key-Type: ";
- tmp = new TCHAR [5];
+ tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*5);
GetDlgItemText(hwndDlg, IDC_KEY_TYPE, tmp, 5);
tmp2 = mir_t2a(tmp);
- delete [] tmp;
- char *subkeytype = new char [6];
+ mir_free(tmp);
+ char *subkeytype = (char*)mir_alloc(6);
if(strstr(tmp2, "RSA"))
strcpy(subkeytype, "RSA");
else if(strstr(tmp2, "DSA")) //this is useless check for now, but it will be required if someone add another key types support
@@ -1297,10 +1298,10 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam,
mir_free(tmp2);
f<<"\n";
f<<"Key-Length: ";
- tmp = new TCHAR [5];
+ tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*5);
GetDlgItemText(hwndDlg, IDC_KEY_LENGTH, tmp, 5);
int length = _ttoi(tmp);
- delete [] tmp;
+ mir_free(tmp);
f<<length;
f<<"\n";
f<<"Subkey-Length: ";
@@ -1308,9 +1309,9 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam,
f<<"\n";
f<<"Subkey-Type: ";
f<<subkeytype;
- delete [] subkeytype;
+ mir_free(subkeytype);
f<<"\n";
- tmp = new TCHAR [64]; //i hope this is enough for password
+ tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*64); //i hope this is enough for password
GetDlgItemText(hwndDlg, IDC_KEY_PASSWD, tmp, 64);
if(tmp[0])
{
@@ -1320,16 +1321,16 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam,
f<<"\n";
mir_free(tmp2);
}
- delete [] tmp;
+ mir_free(tmp);
f<<"Name-Real: ";
- tmp = new TCHAR [128];
+ tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*128);
GetDlgItemText(hwndDlg, IDC_KEY_REAL_NAME, tmp, 128);
tmp2 = mir_strdup(toUTF8(tmp).c_str());
f<<tmp2;
mir_free(tmp2);
- delete [] tmp;
+ mir_free(tmp);
f<<"\n";
- tmp = new TCHAR [512];
+ tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*512);
GetDlgItemText(hwndDlg, IDC_KEY_COMMENT, tmp, 512);
if(tmp[0])
{
@@ -1339,22 +1340,22 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam,
f<<"\n";
}
mir_free(tmp2);
- delete [] tmp;
+ mir_free(tmp);
f<<"Name-Email: ";
- tmp = new TCHAR [128];
+ tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*128);
GetDlgItemText(hwndDlg, IDC_KEY_EMAIL, tmp, 128);
tmp2 = mir_strdup(toUTF8(tmp).c_str());
f<<tmp2;
mir_free(tmp2);
- delete [] tmp;
+ mir_free(tmp);
f<<"\n";
f<<"Expire-Date: ";
- tmp = new TCHAR [12];
+ tmp = (TCHAR*)mir_alloc(sizeof(TCHAR)*12);
GetDlgItemText(hwndDlg, IDC_KEY_EXPIRE_DATE, tmp, 12);
tmp2 = mir_strdup(toUTF8(tmp).c_str());
f<<tmp2;
mir_free(tmp2);
- delete [] tmp;
+ mir_free(tmp);
f<<"\n";
f.close();
}
@@ -2023,14 +2024,25 @@ void InitCheck()
mir_free(path);
}
extern bool bAutoExchange;
- if(bAutoExchange && (ServiceExists("ICQ"PS_ICQ_ADDCAPABILITY))) //work only for one icq instance
+ if(bAutoExchange)
{
+ int count = 0;
+ PROTOACCOUNT **accounts;
+ ProtoEnumAccounts(&count, &accounts);
ICQ_CUSTOMCAP cap;
cap.cbSize = sizeof(ICQ_CUSTOMCAP);
cap.hIcon = 0;
strcpy(cap.name, "GPG Key AutoExchange");
strcpy(cap.caps, "GPG AutoExchange");
- CallService("ICQ"PS_ICQ_ADDCAPABILITY, 0, (LPARAM)&cap);
+
+ for(int i = 0; i < count; i++)
+ {
+ char svc[64];
+ strcpy(svc, accounts[i]->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<HANDLE> 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, &params));
@@ -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 <JabberAccount*> Accounts;
+ list<JabberAccount*>::iterator end = Accounts.end();
+ for(list<JabberAccount*>::iterator p = Accounts.begin(); p != end; p++)
{
- extern list <JabberAccount*> Accounts;
- list<JabberAccount*>::iterator end = Accounts.end();
- for(list<JabberAccount*>::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<<time_str()<<": GPG execution timed out, aborted\n";
mir_free(msg);
- return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
+ CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
+ return;
}
if(result == pxNotFound)
{
mir_free(msg);
- return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
+ CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
+ return;
}
+ //TODO: check gpg output for errors
if(out.find("There is no assurance this key belongs to the named user") != string::npos)
{
out.clear();
@@ -729,18 +750,21 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags)
params.hProcess = NULL;
debuglog<<time_str()<<": GPG execution timed out, aborted\n";
mir_free(msg);
- return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
+ CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
+ return;
}
if(result == pxNotFound)
{
mir_free(msg);
- return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
+ CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
+ return;
}
+ //TODO: check gpg output for errors
}
else
{
mir_free(msg);
- return 0;
+ return;
}
}
if(out.find("usage: ") != string::npos)
@@ -748,7 +772,8 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags)
MessageBox(0, _T("Something wrong, gpg does not understand us, aborting encryption."), _T("Warning"), MB_OK);
DeleteFile(path.c_str());
mir_free(msg);
- return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
+ CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
+ return;
}
DeleteFile(path.c_str());
path.append(_T(".asc"));
@@ -774,7 +799,8 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags)
hcontact_data[hContact].msgs_to_pass.push_back("Failed to encrypt message with GPG");
debuglog<<time_str()<<": info: Failed to encrypt message with GPG\n";
mir_free(msg);
- return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
+ CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
+ return;
}
string str_event = msg;
if(bAppendTags)
@@ -794,9 +820,10 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags)
HistoryLog(hContact, db_event((char*)str_event.c_str(), 0,0, dbflags|DBEF_SENT));
if(!(flags & PREF_UTF))
flags |= PREF_UTF;
- sent_msgs.push_back((HANDLE)CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)toUTF8(str).c_str()));
+ HANDLE hProcess = NULL;
+ sent_msgs.push_back(hProcess = (HANDLE)CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)toUTF8(str).c_str()));
mir_free(msg);
- return 0;
+ return;
}
int SendMsgSvc(WPARAM w, LPARAM l)
@@ -821,11 +848,16 @@ int SendMsgSvc(WPARAM w, LPARAM l)
DWORD uin = DBGetContactSettingDword(ccs->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;
}