summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_utils.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2014-09-27 10:19:26 +0000
committerAlexander Lantsev <aunsane@gmail.com>2014-09-27 10:19:26 +0000
commit22b35cdc0d13336366efe44b57d682d5be6bae52 (patch)
treedc4fb01f13f4b11391c2c1c704d10b4ecc9c66b8 /protocols/Tox/src/tox_utils.cpp
parent93467b8c3702be5fc9f9b60c3ff6863cb37ccd8d (diff)
Tox:
- password field temporary disables - some changes git-svn-id: http://svn.miranda-ng.org/main/trunk@10613 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox/src/tox_utils.cpp')
-rw-r--r--protocols/Tox/src/tox_utils.cpp50
1 files changed, 33 insertions, 17 deletions
diff --git a/protocols/Tox/src/tox_utils.cpp b/protocols/Tox/src/tox_utils.cpp
index 2b2d5daa75..d294be81cd 100644
--- a/protocols/Tox/src/tox_utils.cpp
+++ b/protocols/Tox/src/tox_utils.cpp
@@ -121,16 +121,6 @@ bool CToxProto::IsFileExists(std::tstring path)
return false;
}
-std::tstring CToxProto::GetToxProfilePath()
-{
- std::tstring profilePath;
- TCHAR defaultPath[MAX_PATH];
- mir_sntprintf(defaultPath, MAX_PATH, _T("%s\\%s.tox"), VARST(_T("%miranda_userdata%")), m_tszUserName);
- profilePath = defaultPath;
-
- return profilePath;
-}
-
void CToxProto::LoadToxData()
{
std::tstring toxProfilePath = GetToxProfilePath();
@@ -146,7 +136,6 @@ void CToxProto::LoadToxData()
rewind(hFile);
uint8_t *data = (uint8_t*)mir_alloc(size);
-
if (fread(data, sizeof(uint8_t), size, hFile) != size)
{
debugLogA("CToxProto::LoadToxData: could not read tox profile");
@@ -155,12 +144,23 @@ void CToxProto::LoadToxData()
return;
}
- if (tox_is_data_encrypted(data)) {
- ptrA password(mir_utf8encodeW(ptrT(getTStringA("Password"))));
- tox_encrypted_load(tox, data, size, (uint8_t*)(char*)password, strlen(password));
+ if (tox_is_data_encrypted(data))
+ {
+ ptrT password(getTStringA("Password"));
+ char *password_utf8 = mir_utf8encodeW(password);
+ if (tox_encrypted_load(tox, data, size, (uint8_t*)password_utf8, strlen(password_utf8)) == TOX_ERROR)
+ {
+ debugLogA("CToxProto::LoadToxData: could not decrypt tox profile");
+ }
+ mir_free(password_utf8);
}
else
- tox_load(tox, data, size);
+ {
+ if (tox_load(tox, data, size) == TOX_ERROR)
+ {
+ debugLogA("CToxProto::LoadToxData: could not load tox profile");
+ }
+ }
mir_free(data);
fclose(hFile);
@@ -178,8 +178,24 @@ void CToxProto::SaveToxData()
uint32_t size = tox_encrypted_size(tox);
uint8_t *data = (uint8_t*)mir_alloc(size);
- ptrA password(mir_utf8encodeW(ptrT(getTStringA("Password"))));
- tox_encrypted_save(tox, data, (uint8_t*)(char*)password, strlen(password));
+ ptrT password(getTStringA("Password"));
+ if (password && _tcslen(password))
+ {
+ char *password_utf8 = mir_utf8encodeW(password);
+ if (tox_encrypted_save(tox, data, (uint8_t*)password_utf8, strlen(password_utf8)) == TOX_ERROR)
+ {
+ debugLogA("CToxProto::LoadToxData: could not encrypt tox profile");
+ mir_free(password_utf8);
+ mir_free(data);
+ fclose(hFile);
+ return;
+ }
+ mir_free(password_utf8);
+ }
+ else
+ {
+ tox_save(tox, data);
+ }
if (fwrite(data, sizeof(uint8_t), size, hFile) != size)
{