diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2016-05-06 15:58:45 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2016-05-06 15:58:45 +0000 |
commit | b158dd53ea1d868e1fa123206f7ef3c8b54112f3 (patch) | |
tree | 2ac893861c622f064288203af0b5e717c92d7e6a /protocols/Tox | |
parent | f6c3afc4b7eb38a4c2a189fa7e5ba9d44c095cc4 (diff) |
Tox: attempt to avoid file lock on transfer
git-svn-id: http://svn.miranda-ng.org/main/trunk@16807 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox')
-rw-r--r-- | protocols/Tox/src/tox_avatars.cpp | 2 | ||||
-rw-r--r-- | protocols/Tox/src/tox_core.cpp | 122 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.cpp | 2 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.h | 5 | ||||
-rw-r--r-- | protocols/Tox/src/tox_transfer.cpp | 25 |
5 files changed, 63 insertions, 93 deletions
diff --git a/protocols/Tox/src/tox_avatars.cpp b/protocols/Tox/src/tox_avatars.cpp index dad9aad980..b7282e781f 100644 --- a/protocols/Tox/src/tox_avatars.cpp +++ b/protocols/Tox/src/tox_avatars.cpp @@ -224,7 +224,7 @@ void CToxProto::OnGotFriendAvatarInfo(AvatarTransferParam *transfer) if (memcmp(transfer->hash, dbv.pbVal, TOX_HASH_LENGTH) == 0)
{
db_free(&dbv);
- OnFileCancel(transfer->pfts.hContact, transfer);
+ CancelTransfer(transfer->pfts.hContact, transfer);
return;
}
db_free(&dbv);
diff --git a/protocols/Tox/src/tox_core.cpp b/protocols/Tox/src/tox_core.cpp index 4f338db5cc..838edd6a1a 100644 --- a/protocols/Tox/src/tox_core.cpp +++ b/protocols/Tox/src/tox_core.cpp @@ -55,72 +55,51 @@ bool CToxProto::InitToxCore(CToxThread *toxThread) if (toxThread == NULL)
return false;
- /*Tox_Options *options = GetToxOptions();
- if (options == NULL)
- return false;
-
- if (LoadToxProfile(options))
- {
- TOX_ERR_NEW initError;
- toxThread->Tox() = tox_new(options, &initError);
- if (initError != TOX_ERR_NEW_OK)
- {
- debugLogA(__FUNCTION__": failed to initialize tox core (%d)", initError);
- ShowNotification(ToxErrorToString(initError), TranslateT("Unable to initialize Tox core"), MB_ICONERROR);
- tox_options_free(options);
- return false;
- }*/
-
- tox_callback_friend_request(toxThread->Tox(), OnFriendRequest, this);
- tox_callback_friend_message(toxThread->Tox(), OnFriendMessage, this);
- tox_callback_friend_read_receipt(toxThread->Tox(), OnReadReceipt, this);
- tox_callback_friend_typing(toxThread->Tox(), OnTypingChanged, this);
- //
- tox_callback_friend_name(toxThread->Tox(), OnFriendNameChange, this);
- tox_callback_friend_status_message(toxThread->Tox(), OnStatusMessageChanged, this);
- tox_callback_friend_status(toxThread->Tox(), OnUserStatusChanged, this);
- tox_callback_friend_connection_status(toxThread->Tox(), OnConnectionStatusChanged, this);
- // transfers
- tox_callback_file_recv_control(toxThread->Tox(), OnFileRequest, this);
- tox_callback_file_recv(toxThread->Tox(), OnFriendFile, this);
- tox_callback_file_recv_chunk(toxThread->Tox(), OnDataReceiving, this);
- tox_callback_file_chunk_request(toxThread->Tox(), OnFileSendData, this);
- // group chats
- //tox_callback_group_invite(tox, OnGroupChatInvite, this);
- // a/v
- //if (IsWinVerVistaPlus())
- //{
- // TOXAV_ERR_NEW avInitError;
- // toxThread->Tox()AV = toxav_new(toxThread->Tox(), &avInitError);
- // if (initError != TOX_ERR_NEW_OK)
- // {
- // toxav_callback_call(toxThread->Tox()AV, OnFriendCall, this);
- // toxav_callback_call_state(toxThread->Tox()AV, OnFriendCallState, this);
- // toxav_callback_bit_rate_status(toxThread->Tox()AV, OnBitrateChanged, this);
- // toxav_callback_audio_receive_frame(toxThread->Tox()AV, OnFriendAudioFrame, this);
- // //toxav_callback_video_receive_frame(toxThread->Tox()AV, , this);
- // }
- //}
-
- uint8_t data[TOX_ADDRESS_SIZE];
- tox_self_get_address(toxThread->Tox(), data);
- ToxHexAddress address(data);
- setString(TOX_SETTINGS_ID, address);
-
- uint8_t nick[TOX_MAX_NAME_LENGTH] = { 0 };
- tox_self_get_name(toxThread->Tox(), nick);
- setTString("Nick", ptrT(Utf8DecodeT((char*)nick)));
-
- uint8_t statusMessage[TOX_MAX_STATUS_MESSAGE_LENGTH] = { 0 };
- tox_self_get_status_message(toxThread->Tox(), statusMessage);
- setTString("StatusMsg", ptrT(Utf8DecodeT((char*)statusMessage)));
-
- return true;
- /*}
-
- tox_options_free(options);
-
- return false;*/
+ tox_callback_friend_request(toxThread->Tox(), OnFriendRequest, this);
+ tox_callback_friend_message(toxThread->Tox(), OnFriendMessage, this);
+ tox_callback_friend_read_receipt(toxThread->Tox(), OnReadReceipt, this);
+ tox_callback_friend_typing(toxThread->Tox(), OnTypingChanged, this);
+ //
+ tox_callback_friend_name(toxThread->Tox(), OnFriendNameChange, this);
+ tox_callback_friend_status_message(toxThread->Tox(), OnStatusMessageChanged, this);
+ tox_callback_friend_status(toxThread->Tox(), OnUserStatusChanged, this);
+ tox_callback_friend_connection_status(toxThread->Tox(), OnConnectionStatusChanged, this);
+ // transfers
+ tox_callback_file_recv_control(toxThread->Tox(), OnFileRequest, this);
+ tox_callback_file_recv(toxThread->Tox(), OnFriendFile, this);
+ tox_callback_file_recv_chunk(toxThread->Tox(), OnDataReceiving, this);
+ tox_callback_file_chunk_request(toxThread->Tox(), OnFileSendData, this);
+ // group chats
+ //tox_callback_group_invite(tox, OnGroupChatInvite, this);
+ // a/v
+ //if (IsWinVerVistaPlus())
+ //{
+ // TOXAV_ERR_NEW avInitError;
+ // toxThread->Tox()AV = toxav_new(toxThread->Tox(), &avInitError);
+ // if (initError != TOX_ERR_NEW_OK)
+ // {
+ // toxav_callback_call(toxThread->Tox()AV, OnFriendCall, this);
+ // toxav_callback_call_state(toxThread->Tox()AV, OnFriendCallState, this);
+ // toxav_callback_bit_rate_status(toxThread->Tox()AV, OnBitrateChanged, this);
+ // toxav_callback_audio_receive_frame(toxThread->Tox()AV, OnFriendAudioFrame, this);
+ // //toxav_callback_video_receive_frame(toxThread->Tox()AV, , this);
+ // }
+ //}
+
+ uint8_t data[TOX_ADDRESS_SIZE];
+ tox_self_get_address(toxThread->Tox(), data);
+ ToxHexAddress address(data);
+ setString(TOX_SETTINGS_ID, address);
+
+ uint8_t nick[TOX_MAX_NAME_LENGTH] = { 0 };
+ tox_self_get_name(toxThread->Tox(), nick);
+ setTString("Nick", ptrT(Utf8DecodeT((char*)nick)));
+
+ uint8_t statusMessage[TOX_MAX_STATUS_MESSAGE_LENGTH] = { 0 };
+ tox_self_get_status_message(toxThread->Tox(), statusMessage);
+ setTString("StatusMsg", ptrT(Utf8DecodeT((char*)statusMessage)));
+
+ return true;
}
void CToxProto::UninitToxCore(CToxThread *toxThread)
@@ -128,15 +107,6 @@ void CToxProto::UninitToxCore(CToxThread *toxThread) if (toxThread == NULL)
return;
- /*if (toxThread->ToxAV())
- toxav_kill(toxThread->ToxAV());
-
- if (toxThread->Tox() == NULL)
- return;*/
-
- CancelAllTransfers();
+ CancelAllTransfers(toxThread);
SaveToxProfile(toxThread);
-
- //tox_kill(toxThread->Tox());
- //toxThread->Tox() = NULL;
}
\ No newline at end of file diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp index 064ad7cc91..f73e776f0d 100644 --- a/protocols/Tox/src/tox_proto.cpp +++ b/protocols/Tox/src/tox_proto.cpp @@ -103,7 +103,7 @@ HANDLE CToxProto::FileAllow(MCONTACT hContact, HANDLE hTransfer, const TCHAR *ts int CToxProto::FileCancel(MCONTACT hContact, HANDLE hTransfer)
{
- return OnFileCancel(hContact, hTransfer);
+ return CancelTransfer(hContact, hTransfer);
}
int CToxProto::FileDeny(MCONTACT hContact, HANDLE hTransfer, const TCHAR*)
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index ca3828bca0..d5bd786be9 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -227,9 +227,10 @@ private: // transfer
HANDLE OnFileAllow(MCONTACT hContact, HANDLE hTransfer, const TCHAR *tszPath);
int OnFileResume(HANDLE hTransfer, int *action, const TCHAR **szFilename);
- int OnFileCancel(MCONTACT hContact, HANDLE hTransfer);
HANDLE OnSendFile(MCONTACT hContact, const TCHAR*, TCHAR **ppszFiles);
+ int CancelTransfer(MCONTACT hContact, HANDLE hTransfer);
+
static void OnFileRequest(Tox *tox, uint32_t friendNumber, uint32_t fileNumber, TOX_FILE_CONTROL control, void *arg);
static void OnFriendFile(Tox *tox, uint32_t friendNumber, uint32_t fileNumber, uint32_t kind, uint64_t fileSize, const uint8_t *fileName, size_t filenameLength, void *arg);
static void OnDataReceiving(Tox *tox, uint32_t friendNumber, uint32_t fileNumber, uint64_t position, const uint8_t *data, size_t length, void *arg);
@@ -240,7 +241,7 @@ private: void PauseOutgoingTransfers(uint32_t friendNumber);
void ResumeIncomingTransfers(uint32_t friendNumber);
- void CancelAllTransfers();
+ void CancelAllTransfers(CToxThread *toxThread);
// avatars
TCHAR* GetAvatarFilePath(MCONTACT hContact = NULL);
diff --git a/protocols/Tox/src/tox_transfer.cpp b/protocols/Tox/src/tox_transfer.cpp index e701aef03c..5c9ca9b56d 100644 --- a/protocols/Tox/src/tox_transfer.cpp +++ b/protocols/Tox/src/tox_transfer.cpp @@ -40,7 +40,7 @@ void CToxProto::OnFriendFile(Tox*, uint32_t friendNumber, uint32_t fileNumber, u case TOX_FILE_KIND_DATA:
{
- Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": incoming file (%d) from %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
+ proto->debugLogA(__FUNCTION__": incoming file (%d) from %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
ptrA rawName((char*)mir_alloc(filenameLength + 1));
memcpy(rawName, fileName, filenameLength);
@@ -64,7 +64,7 @@ void CToxProto::OnFriendFile(Tox*, uint32_t friendNumber, uint32_t fileNumber, u break;
default:
- Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": unsupported transfer (%d) from %s(%d) with type (%d)", fileNumber, (const char*)pubKey, friendNumber, kind);
+ proto->debugLogA(__FUNCTION__": unsupported transfer (%d) from %s(%d) with type (%d)", fileNumber, (const char*)pubKey, friendNumber, kind);
return;
}
}
@@ -187,7 +187,7 @@ void CToxProto::OnDataReceiving(Tox*, uint32_t friendNumber, uint32_t fileNumber if (fwrite(data, sizeof(uint8_t), length, transfer->hFile) != length)
{
- Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": failed write to file (%d)", fileNumber);
+ proto->debugLogA(__FUNCTION__": failed write to file (%d)", fileNumber);
proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)transfer, 0);
tox_file_control(proto->toxThread->Tox(), friendNumber, fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
return;
@@ -257,17 +257,17 @@ void CToxProto::OnFileSendData(Tox*, uint32_t friendNumber, uint32_t fileNumber, FileTransferParam *transfer = proto->transfers.Get(friendNumber, fileNumber);
if (transfer == NULL)
{
- Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": failed to find transfer (%d) to %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
+ proto->debugLogA(__FUNCTION__": failed to find transfer (%d) to %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
return;
}
if (length == 0)
{
// file sending is finished
- Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": finised the transfer of file (%d) to %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
+ proto->debugLogA(__FUNCTION__": finised the transfer of file (%d) to %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
bool isFileFullyTransfered = transfer->pfts.currentFileProgress == transfer->pfts.currentFileSize;
if (!isFileFullyTransfered)
- Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": file (%d) is not completely transferred to %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
+ proto->debugLogA(__FUNCTION__": file (%d) is not completely transferred to %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, isFileFullyTransfered ? ACKRESULT_SUCCESS : ACKRESULT_FAILED, (HANDLE)transfer, 0);
proto->transfers.Remove(transfer);
return;
@@ -280,7 +280,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)
{
- Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": failed to read from file (%d) to %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
+ proto->debugLogA(__FUNCTION__": failed to read from file (%d) to %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)transfer, 0);
tox_file_control(proto->toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
mir_free(data);
@@ -295,7 +295,7 @@ void CToxProto::OnFileSendData(Tox*, uint32_t friendNumber, uint32_t fileNumber, mir_free(data);
return;
}
- Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": failed to send file chunk (%d) to %s(%d) cause (%d)", fileNumber, (const char*)pubKey, friendNumber, error);
+ proto->debugLogA(__FUNCTION__": failed to send file chunk (%d) to %s(%d) cause (%d)", fileNumber, (const char*)pubKey, friendNumber, error);
proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)transfer, 0);
tox_file_control(proto->toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
mir_free(data);
@@ -310,8 +310,7 @@ void CToxProto::OnFileSendData(Tox*, uint32_t friendNumber, uint32_t fileNumber, /* COMMON */
-// file request is cancelled
-int CToxProto::OnFileCancel(MCONTACT, HANDLE hTransfer)
+int CToxProto::CancelTransfer(MCONTACT, HANDLE hTransfer)
{
FileTransferParam *transfer = (FileTransferParam*)hTransfer;
debugLogA(__FUNCTION__": Transfer (%d) is canceled", transfer->fileNumber);
@@ -357,13 +356,13 @@ void CToxProto::ResumeIncomingTransfers(uint32_t friendNumber) if (!tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_RESUME, &error))
{
debugLogA(__FUNCTION__": failed to resume the transfer (%d) from %s(%d) cause(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber, error);
- tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
+ CancelTransfer(NULL, transfer);
}
}
}
}
-void CToxProto::CancelAllTransfers()
+void CToxProto::CancelAllTransfers(CToxThread *toxThread)
{
for (size_t i = 0; i < transfers.Count(); i++)
{
@@ -385,7 +384,7 @@ void CToxProto::OnFileRequest(Tox*, uint32_t friendNumber, uint32_t fileNumber, FileTransferParam *transfer = proto->transfers.Get(friendNumber, fileNumber);
if (transfer == NULL)
{
- Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": failed to find transfer (%d)", fileNumber);
+ proto->debugLogA(__FUNCTION__": failed to find transfer (%d)", fileNumber);
return;
}
|