summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_transfer.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2014-09-09 19:52:07 +0000
committerAlexander Lantsev <aunsane@gmail.com>2014-09-09 19:52:07 +0000
commit56c1f62b71e28b12e83e4ee7999461f73a3367fb (patch)
tree4a8f66d01a94d3bed7bcd614d5bcaaa1250221ae /protocols/Tox/src/tox_transfer.cpp
parent4becc46d15baf8393a347c1d3897af5d8d55dea6 (diff)
Tox: id saves in db as blob at now
git-svn-id: http://svn.miranda-ng.org/main/trunk@10412 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox/src/tox_transfer.cpp')
-rw-r--r--protocols/Tox/src/tox_transfer.cpp72
1 files changed, 53 insertions, 19 deletions
diff --git a/protocols/Tox/src/tox_transfer.cpp b/protocols/Tox/src/tox_transfer.cpp
index f9955c367d..05eedf7bfc 100644
--- a/protocols/Tox/src/tox_transfer.cpp
+++ b/protocols/Tox/src/tox_transfer.cpp
@@ -56,10 +56,15 @@ void CToxProto::OnFriendFile(Tox *tox, int32_t number, uint8_t fileNumber, uint6
// file request is allowed
HANDLE __cdecl CToxProto::FileAllow(MCONTACT hContact, HANDLE hTransfer, const PROTOCHAR* tszPath)
{
- std::string toxId(getStringA(hContact, TOX_SETTINGS_ID));
- std::vector<uint8_t> clientId = HexStringToData(toxId);
+ DBVARIANT dbv;
+ std::vector<uint8_t> id;
+ if (!db_get(hContact, m_szModuleName, TOX_SETTINGS_ID, &dbv))
+ {
+ memcpy(&id[0], dbv.pbVal, TOX_CLIENT_ID_SIZE);
+ db_free(&dbv);
+ }
- uint32_t number = tox_get_friend_number(tox, clientId.data());
+ uint32_t number = tox_get_friend_number(tox, id.data());
FileTransferParam *transfer = (FileTransferParam*)hTransfer;
transfer->pfts.tszWorkingDir = mir_tstrdup(tszPath);
@@ -82,10 +87,15 @@ int __cdecl CToxProto::FileResume(HANDLE hTransfer, int* action, const PROTOCHAR
{
FileTransferParam *transfer = (FileTransferParam*)hTransfer;
- std::string toxId(getStringA(transfer->pfts.hContact, TOX_SETTINGS_ID));
- std::vector<uint8_t> clientId = HexStringToData(toxId);
+ DBVARIANT dbv;
+ std::vector<uint8_t> id;
+ if (!db_get(transfer->pfts.hContact, m_szModuleName, TOX_SETTINGS_ID, &dbv))
+ {
+ memcpy(&id[0], dbv.pbVal, TOX_CLIENT_ID_SIZE);
+ db_free(&dbv);
+ }
- uint32_t number = tox_get_friend_number(tox, clientId.data());
+ uint32_t number = tox_get_friend_number(tox, id.data());
switch (*action)
{
@@ -145,10 +155,15 @@ void CToxProto::OnFileData(Tox *tox, int32_t number, uint8_t fileNumber, const u
// send request through tox
HANDLE __cdecl CToxProto::SendFile(MCONTACT hContact, const PROTOCHAR* szDescription, PROTOCHAR** ppszFiles)
{
- std::string toxId(getStringA(hContact, TOX_SETTINGS_ID));
- std::vector<uint8_t> clientId = HexStringToData(toxId);
+ DBVARIANT dbv;
+ std::vector<uint8_t> id;
+ if (!db_get(hContact, m_szModuleName, TOX_SETTINGS_ID, &dbv))
+ {
+ memcpy(&id[0], dbv.pbVal, TOX_CLIENT_ID_SIZE);
+ db_free(&dbv);
+ }
- uint32_t number = tox_get_friend_number(tox, clientId.data());
+ uint32_t number = tox_get_friend_number(tox, id.data());
TCHAR *fileName = _tcsrchr(ppszFiles[0], '\\') + 1;
@@ -189,10 +204,15 @@ void CToxProto::SendFileAsync(void* arg)
{
FileTransferParam *transfer = (FileTransferParam*)arg;
- std::string toxId(getStringA(transfer->pfts.hContact, TOX_SETTINGS_ID));
- std::vector<uint8_t> clientId = HexStringToData(toxId);
+ DBVARIANT dbv;
+ std::vector<uint8_t> id;
+ if (!db_get(transfer->pfts.hContact, m_szModuleName, TOX_SETTINGS_ID, &dbv))
+ {
+ memcpy(&id[0], dbv.pbVal, TOX_CLIENT_ID_SIZE);
+ db_free(&dbv);
+ }
- if (uint32_t number = tox_get_friend_number(tox, clientId.data()) > TOX_ERROR)
+ if (uint32_t number = tox_get_friend_number(tox, id.data()) > TOX_ERROR)
{
ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_CONNECTED, (HANDLE)transfer, 0);
@@ -209,18 +229,27 @@ void CToxProto::SendFileAsync(void* arg)
return;
}
- size_t chunkSize = min(tox_file_data_size(tox, number), fileSize);
+ size_t chunkSize = min(fileSize, (size_t)tox_file_data_size(tox, number));
uint8_t *data = (uint8_t*)mir_alloc(chunkSize);
+ data = NULL;
while (!feof(hFile) && fileProgress < fileSize)
{
size_t size = min(chunkSize, fileSize - fileProgress);
- if (fread(data, sizeof(uint8_t), size, hFile) == size)
+ if (data == NULL)
{
- tox_file_send_data(tox, number, transfer->number, data, size);
- transfer->pfts.totalProgress = transfer->pfts.currentFileProgress = fileProgress += size;
+ fread(data, sizeof(uint8_t), size, hFile);// == size
+ }
+ if (tox_file_send_data(tox, number, transfer->number, data, size) != TOX_ERROR)
+ {
+ data = NULL;
+ transfer->pfts.totalProgress = transfer->pfts.currentFileProgress = fileProgress += size;
ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_DATA, (HANDLE)transfer, (LPARAM)&transfer->pfts);
}
+ else
+ {
+ Sleep(50);
+ }
}
mir_free(data);
@@ -234,10 +263,15 @@ void CToxProto::SendFileAsync(void* arg)
// file request is cancelled
int __cdecl CToxProto::FileCancel(MCONTACT hContact, HANDLE hTransfer)
{
- std::string toxId(getStringA(hContact, TOX_SETTINGS_ID));
- std::vector<uint8_t> clientId = HexStringToData(toxId);
+ DBVARIANT dbv;
+ std::vector<uint8_t> id;
+ if (!db_get(hContact, m_szModuleName, TOX_SETTINGS_ID, &dbv))
+ {
+ memcpy(&id[0], dbv.pbVal, TOX_CLIENT_ID_SIZE);
+ db_free(&dbv);
+ }
- uint32_t number = tox_get_friend_number(tox, clientId.data());
+ uint32_t number = tox_get_friend_number(tox, id.data());
FileTransferParam *transfer = (FileTransferParam*)hTransfer;