summaryrefslogtreecommitdiff
path: root/protocols/Tox
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-06-03 11:23:36 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-06-03 11:23:36 +0000
commit0d1323b8c457b055784416e658740e9db518ca63 (patch)
tree361edd0f36d3d7401526cd9c5017f1fad5224108 /protocols/Tox
parentf48a5222bd112f09e962fee0381878b06df79bfa (diff)
Tox: more correct transfer logging
git-svn-id: http://svn.miranda-ng.org/main/trunk@13981 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox')
-rw-r--r--protocols/Tox/src/tox_contacts.cpp21
-rw-r--r--protocols/Tox/src/tox_proto.h3
-rw-r--r--protocols/Tox/src/tox_transfer.cpp85
3 files changed, 73 insertions, 36 deletions
diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp
index abf80745de..532f23ab48 100644
--- a/protocols/Tox/src/tox_contacts.cpp
+++ b/protocols/Tox/src/tox_contacts.cpp
@@ -319,22 +319,8 @@ void CToxProto::OnConnectionStatusChanged(Tox*, uint32_t friendNumber, TOX_CONNE
proto->delSetting(hContact, "Auth");
proto->delSetting(hContact, "Grant");
- // resume transfers
- for (size_t i = 0; i < proto->transfers.Count(); i++)
- {
- // only for receiving
- FileTransferParam *transfer = proto->transfers.GetAt(i);
- if (transfer->friendNumber == friendNumber && transfer->GetDirection() == 1)
- {
- proto->debugLogA(__FUNCTION__": sending ask to resume the transfer of file (%d)", transfer->fileNumber);
- TOX_ERR_FILE_CONTROL error;
- if (!tox_file_control(proto->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_RESUME, &error))
- {
- proto->debugLogA(__FUNCTION__": failed to resume the transfer (%d)", error);
- tox_file_control(proto->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
- }
- }
- }
+ // resume incoming transfers
+ proto->ResumeIncomingTransfers(friendNumber);
// update avatar
std::tstring avatarPath = proto->GetAvatarFilePath();
@@ -381,6 +367,9 @@ void CToxProto::OnConnectionStatusChanged(Tox*, uint32_t friendNumber, TOX_CONNE
{
proto->SetContactStatus(hContact, ID_STATUS_OFFLINE);
proto->setDword(hContact, "LastEventDateTS", time(NULL));
+
+ // pause outgoing transfers
+ proto->PauseOutgoingTransfers(friendNumber);
}
}
}
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h
index 481bfabebf..f9ff422ee8 100644
--- a/protocols/Tox/src/tox_proto.h
+++ b/protocols/Tox/src/tox_proto.h
@@ -235,6 +235,9 @@ private:
void OnTransferCompleted(FileTransferParam *transfer);
+ void PauseOutgoingTransfers(uint32_t friendNumber);
+ void ResumeIncomingTransfers(uint32_t friendNumber);
+
// avatars
std::tstring GetAvatarFilePath(MCONTACT hContact = NULL);
void SetToxAvatar(std::tstring path);
diff --git a/protocols/Tox/src/tox_transfer.cpp b/protocols/Tox/src/tox_transfer.cpp
index 63495eb883..b2b0949237 100644
--- a/protocols/Tox/src/tox_transfer.cpp
+++ b/protocols/Tox/src/tox_transfer.cpp
@@ -10,9 +10,12 @@ void CToxProto::OnFriendFile(Tox*, uint32_t friendNumber, uint32_t fileNumber, u
MCONTACT hContact = proto->GetContact(friendNumber);
if (hContact)
{
- switch (kind) {
+ switch (kind)
+ {
case TOX_FILE_KIND_AVATAR:
{
+ proto->debugLogA(__FUNCTION__": incoming avatar (%d) from (%d)", fileNumber, friendNumber);
+
ptrT address(proto->getTStringA(hContact, TOX_SETTINGS_ID));
TCHAR avatarName[MAX_PATH];
mir_sntprintf(avatarName, MAX_PATH, _T("%s.png"), address);
@@ -24,8 +27,9 @@ void CToxProto::OnFriendFile(Tox*, uint32_t friendNumber, uint32_t fileNumber, u
TOX_ERR_FILE_GET error;
tox_file_get_file_id(proto->tox, friendNumber, fileNumber, transfer->hash, &error);
- if (error != TOX_ERR_FILE_GET_OK) {
- proto->debugLogA(__FUNCTION__": unable to get avatar hash (%d)", error);
+ if (error != TOX_ERR_FILE_GET_OK)
+ {
+ proto->debugLogA(__FUNCTION__": unable to get avatar hash (%d) from (%d) cause (%d)", fileNumber, friendNumber, error);
memset(transfer->hash, 0, TOX_HASH_LENGTH);
}
proto->OnGotFriendAvatarInfo(transfer);
@@ -34,6 +38,8 @@ void CToxProto::OnFriendFile(Tox*, uint32_t friendNumber, uint32_t fileNumber, u
case TOX_FILE_KIND_DATA:
{
+ proto->debugLogA(__FUNCTION__": incoming file (%d) from (%d)", fileNumber, friendNumber);
+
ptrA rawName((char*)mir_alloc(filenameLength + 1));
memcpy(rawName, fileName, filenameLength);
rawName[filenameLength] = 0;
@@ -56,7 +62,7 @@ void CToxProto::OnFriendFile(Tox*, uint32_t friendNumber, uint32_t fileNumber, u
break;
default:
- proto->debugLogA(__FUNCTION__": unsupported transfer type (%d)", kind);
+ proto->debugLogA(__FUNCTION__": unsupported transfer (%d) from (%d) with type (%d)", fileNumber, friendNumber, kind);
return;
}
}
@@ -104,17 +110,17 @@ int CToxProto::OnFileResume(HANDLE hTransfer, int *action, const TCHAR **szFilen
TCHAR *mode = *action == FILERESUME_OVERWRITE ? _T("wb") : _T("ab");
if (!transfer->OpenFile(mode))
{
- debugLogA(__FUNCTION__": failed to open file (%d)", transfer->fileNumber);
+ debugLogA(__FUNCTION__": failed to open file (%d) from (%d)", transfer->fileNumber, transfer->friendNumber);
tox_file_control(tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
transfers.Remove(transfer);
return NULL;
}
TOX_ERR_FILE_CONTROL error;
- debugLogA(__FUNCTION__": start receiving file (%d) to (%d)", transfer->fileNumber, transfer->friendNumber);
+ debugLogA(__FUNCTION__": start receiving file (%d) from (%d)", transfer->fileNumber, transfer->friendNumber);
if (!tox_file_control(tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_RESUME, &error))
{
- debugLogA(__FUNCTION__": failed to start the transfer of file(%d) to (%d): (%d)", transfer->fileNumber, transfer->friendNumber, error);
+ debugLogA(__FUNCTION__": failed to start receiving of file(%d) from (%d) cause (%d)", transfer->fileNumber, transfer->friendNumber, error);
ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)transfer, 0);
tox_file_control(tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
transfers.Remove(transfer);
@@ -125,10 +131,10 @@ int CToxProto::OnFileResume(HANDLE hTransfer, int *action, const TCHAR **szFilen
void CToxProto::OnTransferCompleted(FileTransferParam *transfer)
{
- debugLogA(__FUNCTION__": finised the transfer of file (%d)", transfer->fileNumber);
+ debugLogA(__FUNCTION__": finised the transfer of file (%d) from (%d)", transfer->fileNumber, transfer->friendNumber);
bool isFileFullyTransfered = transfer->pfts.currentFileProgress == transfer->pfts.currentFileSize;
if (!isFileFullyTransfered)
- debugLogA(__FUNCTION__": file (%d) is transferred not completely", transfer->fileNumber);
+ debugLogA(__FUNCTION__": file (%d) from (%d) is transferred not completely", transfer->fileNumber, transfer->friendNumber);
if (transfer->transferType == TOX_FILE_KIND_AVATAR)
{
@@ -148,7 +154,7 @@ void CToxProto::OnDataReceiving(Tox*, uint32_t friendNumber, uint32_t fileNumber
FileTransferParam *transfer = proto->transfers.Get(friendNumber, fileNumber);
if (transfer == NULL)
{
- proto->debugLogA(__FUNCTION__": failed to find transfer (%d)", fileNumber);
+ proto->debugLogA(__FUNCTION__": failed to find transfer (%d) from (%d)", fileNumber, friendNumber);
return;
}
@@ -162,7 +168,7 @@ void CToxProto::OnDataReceiving(Tox*, uint32_t friendNumber, uint32_t fileNumber
MCONTACT hContact = proto->GetContact(friendNumber);
if (hContact == NULL)
{
- proto->debugLogA("CToxProto::OnFileData: cannot find contact by number (%d)", friendNumber);
+ proto->debugLogA(__FUNCTION__": cannot find contact by number (%d)", friendNumber);
tox_file_control(proto->tox, friendNumber, fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
return;
}
@@ -192,7 +198,7 @@ HANDLE CToxProto::OnSendFile(MCONTACT hContact, const TCHAR*, TCHAR **ppszFiles)
FILE *hFile = _tfopen(ppszFiles[0], _T("rb"));
if (hFile == NULL)
{
- debugLogA(__FUNCTION__": cannot open file");
+ debugLogA(__FUNCTION__": cannot open file %s", ppszFiles[0]);
return NULL;
}
@@ -211,11 +217,12 @@ HANDLE CToxProto::OnSendFile(MCONTACT hContact, const TCHAR*, TCHAR **ppszFiles)
uint32_t fileNumber = tox_file_send(tox, friendNumber, TOX_FILE_KIND_DATA, fileSize, NULL, (uint8_t*)name, mir_strlen(name), &sendError);
if (sendError != TOX_ERR_FILE_SEND_OK)
{
- debugLogA(__FUNCTION__": failed to send file (%d)", sendError);
+ debugLogA(__FUNCTION__": failed to send file (%d) to (%d) cause (%d)", fileNumber, friendNumber, sendError);
mir_free(fileDir);
mir_free(name);
return NULL;
}
+ debugLogA(__FUNCTION__": start sending file (%d) to (%d)", fileNumber, friendNumber);
FileTransferParam *transfer = new FileTransferParam(friendNumber, fileNumber, fileName, fileSize);
transfer->pfts.flags |= PFTS_SENDING;
@@ -235,17 +242,17 @@ void CToxProto::OnFileSendData(Tox*, uint32_t friendNumber, uint32_t fileNumber,
FileTransferParam *transfer = proto->transfers.Get(friendNumber, fileNumber);
if (transfer == NULL)
{
- proto->debugLogA(__FUNCTION__": failed to fing transfer (%d)", fileNumber);
+ proto->debugLogA(__FUNCTION__": failed to find transfer (%d) to (%d)", fileNumber, friendNumber);
return;
}
if (length == 0)
{
// file sending is finished
- proto->debugLogA(__FUNCTION__": finised the transfer of file (%d)", fileNumber);
+ proto->debugLogA(__FUNCTION__": finised the transfer of file (%d) to (%d)", fileNumber, friendNumber);
bool isFileFullyTransfered = transfer->pfts.currentFileProgress == transfer->pfts.currentFileSize;
if (!isFileFullyTransfered)
- proto->debugLogA(__FUNCTION__": file (%d) is not completely transferred", fileNumber);
+ proto->debugLogA(__FUNCTION__": file (%d) is not completely transferred to (%d)", fileNumber, friendNumber);
proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, isFileFullyTransfered ? ACKRESULT_SUCCESS : ACKRESULT_FAILED, (HANDLE)transfer, 0);
proto->transfers.Remove(transfer);
return;
@@ -258,7 +265,7 @@ void CToxProto::OnFileSendData(Tox*, uint32_t friendNumber, uint32_t fileNumber,
uint8_t *data = (uint8_t*)mir_alloc(length);
if (fread(data, sizeof(uint8_t), length, transfer->hFile) != length)
{
- proto->debugLogA(__FUNCTION__": failed to read from file (%d)", transfer->fileNumber);
+ proto->debugLogA(__FUNCTION__": failed to read from file (%d) to (%d)", fileNumber, friendNumber);
proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)transfer, 0);
tox_file_control(proto->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
mir_free(data);
@@ -273,7 +280,7 @@ void CToxProto::OnFileSendData(Tox*, uint32_t friendNumber, uint32_t fileNumber,
mir_free(data);
return;
}
- proto->debugLogA(__FUNCTION__": failed to send file chunk (%d)", error);
+ proto->debugLogA(__FUNCTION__": failed to send file chunk (%d) to (%d) cause (%d)", fileNumber, friendNumber, error);
proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)transfer, 0);
tox_file_control(proto->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
mir_free(data);
@@ -292,12 +299,51 @@ void CToxProto::OnFileSendData(Tox*, uint32_t friendNumber, uint32_t fileNumber,
int CToxProto::OnFileCancel(MCONTACT, HANDLE hTransfer)
{
FileTransferParam *transfer = (FileTransferParam*)hTransfer;
+ debugLogA(__FUNCTION__": Transfer (%d) is canceled", transfer->fileNumber);
tox_file_control(tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
transfers.Remove(transfer);
return 0;
}
+void CToxProto::PauseOutgoingTransfers(uint32_t friendNumber)
+{
+ for (size_t i = 0; i < transfers.Count(); i++)
+ {
+ // only for sending
+ FileTransferParam *transfer = transfers.GetAt(i);
+ if (transfer->friendNumber == friendNumber && transfer->GetDirection() == 0)
+ {
+ debugLogA(__FUNCTION__": sending ask to pause the transfer of file (%d) to (%d)", transfer->fileNumber, transfer->friendNumber);
+ TOX_ERR_FILE_CONTROL error;
+ if (!tox_file_control(tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_PAUSE, &error))
+ {
+ debugLogA(__FUNCTION__": failed to pause the transfer (%d) to (%d) cause(%d)", transfer->fileNumber, transfer->friendNumber, error);
+ tox_file_control(tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
+ }
+ }
+ }
+}
+
+void CToxProto::ResumeIncomingTransfers(uint32_t friendNumber)
+{
+ for (size_t i = 0; i < transfers.Count(); i++)
+ {
+ // only for receiving
+ FileTransferParam *transfer = transfers.GetAt(i);
+ if (transfer->friendNumber == friendNumber && transfer->GetDirection() == 1)
+ {
+ debugLogA(__FUNCTION__": sending ask to resume the transfer of file (%d) from (%d) cause(%d)", transfer->fileNumber, transfer->friendNumber);
+ TOX_ERR_FILE_CONTROL error;
+ if (!tox_file_control(tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_RESUME, &error))
+ {
+ debugLogA(__FUNCTION__": failed to resume the transfer (%d) from (%d) cause(%d)", transfer->fileNumber, transfer->friendNumber, error);
+ tox_file_control(tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
+ }
+ }
+ }
+}
+
void CToxProto::OnFileRequest(Tox*, uint32_t friendNumber, uint32_t fileNumber, TOX_FILE_CONTROL control, void *arg)
{
CToxProto *proto = (CToxProto*)arg;
@@ -308,7 +354,7 @@ void CToxProto::OnFileRequest(Tox*, uint32_t friendNumber, uint32_t fileNumber,
FileTransferParam *transfer = proto->transfers.Get(friendNumber, fileNumber);
if (transfer == NULL)
{
- proto->debugLogA(__FUNCTION__": failed to fing transfer (%d)", fileNumber);
+ proto->debugLogA(__FUNCTION__": failed to find transfer (%d)", fileNumber);
return;
}
@@ -318,7 +364,6 @@ void CToxProto::OnFileRequest(Tox*, uint32_t friendNumber, uint32_t fileNumber,
break;
case TOX_FILE_CONTROL_RESUME:
- proto->debugLogA("CToxProto::OnFileRequest: start/resume the transfer of file (%d)", transfer->fileNumber);
break;
case TOX_FILE_CONTROL_CANCEL: