summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rwxr-xr-xmain.cpp88
1 files changed, 50 insertions, 38 deletions
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());