summaryrefslogtreecommitdiff
path: root/protocols/Tox
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2014-09-11 17:44:27 +0000
committerAlexander Lantsev <aunsane@gmail.com>2014-09-11 17:44:27 +0000
commit2ba67eb43c31f37d87b60f920be31f85e5273865 (patch)
tree4978a7ab93940c63ec77792cf2ff8bc9d7552daa /protocols/Tox
parent96261c4359752ed0ebaf2340209a85f0916ab3c1 (diff)
Tox: fixed file sending
git-svn-id: http://svn.miranda-ng.org/main/trunk@10431 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox')
-rw-r--r--protocols/Tox/src/tox_proto.cpp2
-rw-r--r--protocols/Tox/src/tox_transfer.cpp25
2 files changed, 13 insertions, 14 deletions
diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp
index fa08e4f42f..2461aa0518 100644
--- a/protocols/Tox/src/tox_proto.cpp
+++ b/protocols/Tox/src/tox_proto.cpp
@@ -49,7 +49,7 @@ DWORD_PTR __cdecl CToxProto::GetCaps(int type, MCONTACT hContact)
switch (type)
{
case PFLAGNUM_1:
- return PF1_IM | PF1_FILERECV | PF1_AUTHREQ | PF1_EXTSEARCH;
+ return PF1_IM | PF1_FILE | PF1_AUTHREQ | PF1_EXTSEARCH;
case PFLAGNUM_2:
return PF2_ONLINE | PF2_SHORTAWAY | PF2_LIGHTDND;
case PFLAGNUM_4:
diff --git a/protocols/Tox/src/tox_transfer.cpp b/protocols/Tox/src/tox_transfer.cpp
index 05eedf7bfc..5bb4159359 100644
--- a/protocols/Tox/src/tox_transfer.cpp
+++ b/protocols/Tox/src/tox_transfer.cpp
@@ -156,7 +156,7 @@ void CToxProto::OnFileData(Tox *tox, int32_t number, uint8_t fileNumber, const u
HANDLE __cdecl CToxProto::SendFile(MCONTACT hContact, const PROTOCHAR* szDescription, PROTOCHAR** ppszFiles)
{
DBVARIANT dbv;
- std::vector<uint8_t> id;
+ std::vector<uint8_t> id(TOX_CLIENT_ID_SIZE);
if (!db_get(hContact, m_szModuleName, TOX_SETTINGS_ID, &dbv))
{
memcpy(&id[0], dbv.pbVal, TOX_CLIENT_ID_SIZE);
@@ -205,14 +205,15 @@ void CToxProto::SendFileAsync(void* arg)
FileTransferParam *transfer = (FileTransferParam*)arg;
DBVARIANT dbv;
- std::vector<uint8_t> id;
+ std::vector<uint8_t> id(TOX_CLIENT_ID_SIZE);
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, id.data()) > TOX_ERROR)
+ int32_t number = tox_get_friend_number(tox, id.data());
+ if (number > TOX_ERROR)
{
ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_CONNECTED, (HANDLE)transfer, 0);
@@ -231,25 +232,23 @@ void CToxProto::SendFileAsync(void* arg)
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 (data == NULL)
+ if (fread(data, sizeof(uint8_t), size, hFile) != size)
{
- fread(data, sizeof(uint8_t), size, hFile);// == size
+ ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)transfer, 0);
+ tox_file_send_control(tox, number, transfer->GetTransferStatus(), transfer->number, TOX_FILECONTROL_KILL, NULL, 0);
+ return;
}
- 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
+ while (tox_file_send_data(tox, number, transfer->number, data, size) == TOX_ERROR)
{
Sleep(50);
}
+
+ transfer->pfts.totalProgress = transfer->pfts.currentFileProgress = fileProgress += size;
+ ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_DATA, (HANDLE)transfer, (LPARAM)&transfer->pfts);
}
mir_free(data);