From 6524ac4e637dba2de42df5ca6eac4a9a5501a4d2 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Wed, 27 Apr 2016 12:44:53 +0000 Subject: Tox: - attempt to fix avatar hash - some changes with toxThread git-svn-id: http://svn.miranda-ng.org/main/trunk@16773 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/api_main.cpp | 5 +++ protocols/Tox/src/tox_avatars.cpp | 6 +-- protocols/Tox/src/tox_chatrooms.cpp | 12 +++--- protocols/Tox/src/tox_contacts.cpp | 26 ++++++------- protocols/Tox/src/tox_core.cpp | 73 ++++++++++++++++++++---------------- protocols/Tox/src/tox_menus.cpp | 2 +- protocols/Tox/src/tox_messages.cpp | 8 ++-- protocols/Tox/src/tox_multimedia.cpp | 52 ++++++++++++------------- protocols/Tox/src/tox_network.cpp | 46 ++++++++++++++++------- protocols/Tox/src/tox_options.cpp | 5 ++- protocols/Tox/src/tox_profile.cpp | 4 +- protocols/Tox/src/tox_proto.cpp | 4 +- protocols/Tox/src/tox_services.cpp | 2 +- protocols/Tox/src/tox_thread.h | 70 +++++++++++++++++++++++++++++++--- protocols/Tox/src/tox_transfer.cpp | 36 +++++++++--------- 15 files changed, 222 insertions(+), 129 deletions(-) diff --git a/protocols/Tox/src/api_main.cpp b/protocols/Tox/src/api_main.cpp index 5473c88f6f..a63bc729b8 100644 --- a/protocols/Tox/src/api_main.cpp +++ b/protocols/Tox/src/api_main.cpp @@ -7,6 +7,11 @@ struct Tox_Options *tox_options_new(TOX_ERR_OPTIONS_NEW *error) return CreateFunction(__FUNCTION__)(error); } +void tox_options_default(struct Tox_Options *options) +{ + CreateFunction(__FUNCTION__)(options); +} + void tox_options_free(struct Tox_Options *options) { CreateFunction(__FUNCTION__)(options); diff --git a/protocols/Tox/src/tox_avatars.cpp b/protocols/Tox/src/tox_avatars.cpp index efa04e6861..9b1e4a36dd 100644 --- a/protocols/Tox/src/tox_avatars.cpp +++ b/protocols/Tox/src/tox_avatars.cpp @@ -53,7 +53,7 @@ void CToxProto::SetToxAvatar(const TCHAR* path) DBVARIANT dbv; uint8_t hash[TOX_HASH_LENGTH]; - tox_hash(hash, data, TOX_HASH_LENGTH); + tox_hash(hash, data, length); if (!db_get(NULL, m_szModuleName, TOX_SETTINGS_AVATAR_HASH, &dbv)) { if (memcmp(hash, dbv.pbVal, TOX_HASH_LENGTH) == 0) @@ -84,7 +84,7 @@ void CToxProto::SetToxAvatar(const TCHAR* path) } TOX_ERR_FILE_SEND error; - uint32_t fileNumber = tox_file_send(toxThread->tox, friendNumber, TOX_FILE_KIND_AVATAR, length, hash, NULL, 0, &error); + uint32_t fileNumber = tox_file_send(toxThread->Tox(), friendNumber, TOX_FILE_KIND_AVATAR, length, hash, NULL, 0, &error); if (error != TOX_ERR_FILE_SEND_OK) { mir_free(data); @@ -186,7 +186,7 @@ INT_PTR CToxProto::SetMyAvatar(WPARAM, LPARAM lParam) continue; TOX_ERR_FILE_SEND error; - tox_file_send(toxThread->tox, friendNumber, TOX_FILE_KIND_AVATAR, 0, NULL, NULL, 0, &error); + tox_file_send(toxThread->Tox(), friendNumber, TOX_FILE_KIND_AVATAR, 0, NULL, NULL, 0, &error); if (error != TOX_ERR_FILE_SEND_OK) { logger->Log(__FUNCTION__": failed to unset avatar (%d)", error); diff --git a/protocols/Tox/src/tox_chatrooms.cpp b/protocols/Tox/src/tox_chatrooms.cpp index 08195104c0..d5a6dd4ebc 100644 --- a/protocols/Tox/src/tox_chatrooms.cpp +++ b/protocols/Tox/src/tox_chatrooms.cpp @@ -46,18 +46,18 @@ MCONTACT CToxProto::AddChatRoom(int groupNumber) void CToxProto::LoadChatRoomList(void*) { - uint32_t count = tox_count_chatlist(toxThread->tox); + uint32_t count = tox_count_chatlist(toxThread->Tox()); if (count == 0) { logger->Log("CToxProto::LoadGroupChatList: your group chat list is empty"); return; } int32_t *groupChats = (int32_t*)mir_alloc(count * sizeof(int32_t)); - tox_get_chatlist(toxThread->tox, groupChats, count); + tox_get_chatlist(toxThread->Tox(), groupChats, count); for (uint32_t i = 0; i < count; i++) { int32_t groupNumber = groupChats[i]; - int type = tox_group_get_type(toxThread->tox, groupNumber); + int type = tox_group_get_type(toxThread->Tox(), groupNumber); if (type == TOX_GROUPCHAT_TYPE_AV) { continue; @@ -66,7 +66,7 @@ void CToxProto::LoadChatRoomList(void*) if (hContact) { uint8_t title[TOX_MAX_NAME_LENGTH] = { 0 }; - tox_group_get_title(toxThread->tox, groupNumber, title, TOX_MAX_NAME_LENGTH); + tox_group_get_title(toxThread->Tox(), groupNumber, title, TOX_MAX_NAME_LENGTH); setWString(hContact, "Nick", ptrT(mir_utf8decodeT((char*)title))); } } @@ -110,7 +110,7 @@ INT_PTR CToxProto::OnCreateChatRoom(WPARAM, LPARAM) CToxProto::ChatRoomInviteProc, (LPARAM)¶m) == IDOK && !param.invitedContacts.empty()) { - int groupNumber = tox_add_groupchat(toxThread->tox); + int groupNumber = tox_add_groupchat(toxThread->Tox()); if (groupNumber == TOX_ERROR) { return 1; @@ -118,7 +118,7 @@ INT_PTR CToxProto::OnCreateChatRoom(WPARAM, LPARAM) for (std::vector::iterator it = param.invitedContacts.begin(); it != param.invitedContacts.end(); ++it) { int32_t friendNumber = GetToxFriendNumber(*it); - if (friendNumber == TOX_ERROR || tox_invite_friend(toxThread->tox, friendNumber, groupNumber) == TOX_ERROR) + if (friendNumber == TOX_ERROR || tox_invite_friend(toxThread->Tox(), friendNumber, groupNumber) == TOX_ERROR) { return 1; } diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp index fb0cf283a4..02a1869a37 100644 --- a/protocols/Tox/src/tox_contacts.cpp +++ b/protocols/Tox/src/tox_contacts.cpp @@ -41,7 +41,7 @@ MCONTACT CToxProto::GetContact(const int friendNumber) { uint8_t data[TOX_PUBLIC_KEY_SIZE]; TOX_ERR_FRIEND_GET_PUBLIC_KEY error; - if (!tox_friend_get_public_key(toxThread->tox, friendNumber, data, &error)) + if (!tox_friend_get_public_key(toxThread->Tox(), friendNumber, data, &error)) { logger->Log(__FUNCTION__": failed to get friend public key (%d)", error); return NULL; @@ -99,7 +99,7 @@ uint32_t CToxProto::GetToxFriendNumber(MCONTACT hContact) { ToxBinAddress pubKey(ptrA(getStringA(hContact, TOX_SETTINGS_ID))); TOX_ERR_FRIEND_BY_PUBLIC_KEY error; - uint32_t friendNumber = tox_friend_by_public_key(toxThread->tox, pubKey.GetPubKey(), &error); + uint32_t friendNumber = tox_friend_by_public_key(toxThread->Tox(), pubKey.GetPubKey(), &error); if (error != TOX_ERR_FRIEND_BY_PUBLIC_KEY_OK) logger->Log(__FUNCTION__": failed to get friend number (%d)", error); return friendNumber; @@ -107,18 +107,18 @@ uint32_t CToxProto::GetToxFriendNumber(MCONTACT hContact) void CToxProto::LoadFriendList(void*) { - size_t count = tox_self_get_friend_list_size(toxThread->tox); + size_t count = tox_self_get_friend_list_size(toxThread->Tox()); if (count > 0) { uint32_t *friends = (uint32_t*)mir_alloc(count * sizeof(uint32_t)); - tox_self_get_friend_list(toxThread->tox, friends); + tox_self_get_friend_list(toxThread->Tox(), friends); uint8_t data[TOX_PUBLIC_KEY_SIZE]; for (size_t i = 0; i < count; i++) { uint32_t friendNumber = friends[i]; TOX_ERR_FRIEND_GET_PUBLIC_KEY getPublicKeyResult; - if (!tox_friend_get_public_key(toxThread->tox, friendNumber, data, &getPublicKeyResult)) + if (!tox_friend_get_public_key(toxThread->Tox(), friendNumber, data, &getPublicKeyResult)) { logger->Log(__FUNCTION__": failed to get friend public key (%d)", getPublicKeyResult); continue; @@ -132,13 +132,13 @@ void CToxProto::LoadFriendList(void*) TOX_ERR_FRIEND_QUERY getNameResult; uint8_t nick[TOX_MAX_NAME_LENGTH] = { 0 }; - if (tox_friend_get_name(toxThread->tox, friendNumber, nick, &getNameResult)) + if (tox_friend_get_name(toxThread->Tox(), friendNumber, nick, &getNameResult)) setTString(hContact, "Nick", ptrT(mir_utf8decodeT((char*)nick))); else logger->Log(__FUNCTION__": failed to get friend name (%d)", getNameResult); TOX_ERR_FRIEND_GET_LAST_ONLINE getLastOnlineResult; - uint64_t timestamp = tox_friend_get_last_online(toxThread->tox, friendNumber, &getLastOnlineResult); + uint64_t timestamp = tox_friend_get_last_online(toxThread->Tox(), friendNumber, &getLastOnlineResult); if (getLastOnlineResult == TOX_ERR_FRIEND_GET_LAST_ONLINE_OK) setDword(hContact, "LastEventDateTS", timestamp); else @@ -159,7 +159,7 @@ INT_PTR CToxProto::OnRequestAuth(WPARAM hContact, LPARAM lParam) ToxBinAddress address(ptrA(getStringA(hContact, TOX_SETTINGS_ID))); TOX_ERR_FRIEND_ADD addFriendResult; - int32_t friendNumber = tox_friend_add(toxThread->tox, address, (uint8_t*)reason, length, &addFriendResult); + int32_t friendNumber = tox_friend_add(toxThread->Tox(), address, (uint8_t*)reason, length, &addFriendResult); if (addFriendResult != TOX_ERR_FRIEND_ADD_OK) { logger->Log(__FUNCTION__": failed to request auth (%d)", addFriendResult); @@ -171,7 +171,7 @@ INT_PTR CToxProto::OnRequestAuth(WPARAM hContact, LPARAM lParam) uint8_t nick[TOX_MAX_NAME_LENGTH] = { 0 }; TOX_ERR_FRIEND_QUERY errorFriendQuery; - if (tox_friend_get_name(toxThread->tox, friendNumber, nick, &errorFriendQuery)) + if (tox_friend_get_name(toxThread->Tox(), friendNumber, nick, &errorFriendQuery)) setTString(hContact, "Nick", ptrT(mir_utf8decodeT((char*)nick))); else logger->Log(__FUNCTION__": failed to get friend name (%d)", errorFriendQuery); @@ -186,7 +186,7 @@ INT_PTR CToxProto::OnGrantAuth(WPARAM hContact, LPARAM) ToxBinAddress pubKey(ptrA(getStringA(hContact, TOX_SETTINGS_ID))); TOX_ERR_FRIEND_ADD error; - tox_friend_add_norequest(toxThread->tox, pubKey, &error); + tox_friend_add_norequest(toxThread->Tox(), pubKey, &error); if (error != TOX_ERR_FRIEND_ADD_OK) { logger->Log(__FUNCTION__": failed to grant auth (%d)", error); @@ -210,7 +210,7 @@ int CToxProto::OnContactDeleted(MCONTACT hContact, LPARAM) { int32_t friendNumber = GetToxFriendNumber(hContact); TOX_ERR_FRIEND_DELETE error; - if (!tox_friend_delete(toxThread->tox, friendNumber, &error)) + if (!tox_friend_delete(toxThread->Tox(), friendNumber, &error)) { logger->Log(__FUNCTION__": failed to delete friend (%d)", error); return error; @@ -346,7 +346,7 @@ void CToxProto::OnConnectionStatusChanged(Tox*, uint32_t friendNumber, TOX_CONNE } TOX_ERR_FILE_SEND error; - uint32_t fileNumber = tox_file_send(proto->toxThread->tox, friendNumber, TOX_FILE_KIND_AVATAR, length, hash, NULL, 0, &error); + uint32_t fileNumber = tox_file_send(proto->toxThread->Tox(), friendNumber, TOX_FILE_KIND_AVATAR, length, hash, NULL, 0, &error); if (error != TOX_ERR_FILE_SEND_OK) { proto->logger->Log(__FUNCTION__": failed to set new avatar"); @@ -362,7 +362,7 @@ void CToxProto::OnConnectionStatusChanged(Tox*, uint32_t friendNumber, TOX_CONNE proto->transfers.Add(transfer); } else - tox_file_send(proto->toxThread->tox, friendNumber, TOX_FILE_KIND_AVATAR, 0, NULL, NULL, 0, NULL); + tox_file_send(proto->toxThread->Tox(), friendNumber, TOX_FILE_KIND_AVATAR, 0, NULL, NULL, 0, NULL); } else { diff --git a/protocols/Tox/src/tox_core.cpp b/protocols/Tox/src/tox_core.cpp index f37ec8d866..9910f8cc1f 100644 --- a/protocols/Tox/src/tox_core.cpp +++ b/protocols/Tox/src/tox_core.cpp @@ -38,7 +38,14 @@ Tox_Options* CToxProto::GetToxOptions() } } - return options; + if (LoadToxProfile(options)) + { + return options; + } + + tox_options_free(options); + + return NULL; } bool CToxProto::InitToxCore(CToxThread *toxThread) @@ -48,72 +55,72 @@ bool CToxProto::InitToxCore(CToxThread *toxThread) if (toxThread == NULL) return false; - Tox_Options *options = GetToxOptions(); + /*Tox_Options *options = GetToxOptions(); if (options == NULL) return false; if (LoadToxProfile(options)) { TOX_ERR_NEW initError; - toxThread->tox = tox_new(options, &initError); + toxThread->Tox() = tox_new(options, &initError); if (initError != TOX_ERR_NEW_OK) { logger->Log(__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_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); + 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); + 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->toxAV = toxav_new(toxThread->tox, &avInitError); + // toxThread->Tox()AV = toxav_new(toxThread->Tox(), &avInitError); // if (initError != TOX_ERR_NEW_OK) // { - // toxav_callback_call(toxThread->toxAV, OnFriendCall, this); - // toxav_callback_call_state(toxThread->toxAV, OnFriendCallState, this); - // toxav_callback_bit_rate_status(toxThread->toxAV, OnBitrateChanged, this); - // toxav_callback_audio_receive_frame(toxThread->toxAV, OnFriendAudioFrame, this); - // //toxav_callback_video_receive_frame(toxThread->toxAV, , this); + // 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); + 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); + 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); + tox_self_get_status_message(toxThread->Tox(), statusMessage); setTString("StatusMsg", ptrT(Utf8DecodeT((char*)statusMessage))); return true; - } + /*} tox_options_free(options); - return false; + return false;*/ } void CToxProto::UninitToxCore(CToxThread *toxThread) @@ -121,15 +128,15 @@ void CToxProto::UninitToxCore(CToxThread *toxThread) if (toxThread == NULL) return; - if (toxThread->toxAV) - toxav_kill(toxThread->toxAV); + /*if (toxThread->ToxAV()) + toxav_kill(toxThread->ToxAV()); - if (toxThread->tox == NULL) - return; + if (toxThread->Tox() == NULL) + return;*/ CancelAllTransfers(); SaveToxProfile(toxThread); - tox_kill(toxThread->tox); - toxThread->tox = NULL; + //tox_kill(toxThread->Tox()); + //toxThread->Tox() = NULL; } \ No newline at end of file diff --git a/protocols/Tox/src/tox_menus.cpp b/protocols/Tox/src/tox_menus.cpp index 0c99ad85cb..50f51fada4 100644 --- a/protocols/Tox/src/tox_menus.cpp +++ b/protocols/Tox/src/tox_menus.cpp @@ -22,7 +22,7 @@ int CToxProto::OnPrebuildContactMenu(WPARAM hContact, LPARAM) Menu_ShowItem(ContactMenuItems[CMI_AUTH_GRANT], isCtrlPressed || isGrantNeed); bool isContactOnline = GetContactStatus(hContact) > ID_STATUS_OFFLINE; - Menu_ShowItem(ContactMenuItems[CMI_AUDIO_CALL], toxThread->toxAV && isContactOnline); + Menu_ShowItem(ContactMenuItems[CMI_AUDIO_CALL], toxThread->ToxAV() && isContactOnline); return 0; } diff --git a/protocols/Tox/src/tox_messages.cpp b/protocols/Tox/src/tox_messages.cpp index aa5f2a1935..0fb393e5da 100644 --- a/protocols/Tox/src/tox_messages.cpp +++ b/protocols/Tox/src/tox_messages.cpp @@ -58,7 +58,7 @@ void CToxProto::SendMessageAsync(void *arg) } TOX_ERR_FRIEND_SEND_MESSAGE sendError; - int messageNumber = tox_friend_send_message(toxThread->tox, friendNumber, type, msg, msgLen, &sendError); + int messageNumber = tox_friend_send_message(toxThread->Tox(), friendNumber, type, msg, msgLen, &sendError); if (sendError != TOX_ERR_FRIEND_SEND_MESSAGE_OK) { logger->Log(__FUNCTION__": failed to send message for %d (%d)", friendNumber, sendError); @@ -139,7 +139,7 @@ void CToxProto::GetStatusMessageAsync(void* arg) } TOX_ERR_FRIEND_QUERY error; - size_t size = tox_friend_get_status_message_size(toxThread->tox, friendNumber, &error); + size_t size = tox_friend_get_status_message_size(toxThread->Tox(), friendNumber, &error); if (error != TOX_ERR_FRIEND_QUERY::TOX_ERR_FRIEND_QUERY_OK) { logger->Log(__FUNCTION__": failed to get status message for (%d) (%d)", friendNumber, error); @@ -148,7 +148,7 @@ void CToxProto::GetStatusMessageAsync(void* arg) } ptrA statusMessage((char*)mir_calloc(size + 1)); - if (!tox_friend_get_status_message(toxThread->tox, friendNumber, (uint8_t*)(char*)statusMessage, &error)) + if (!tox_friend_get_status_message(toxThread->Tox(), friendNumber, (uint8_t*)(char*)statusMessage, &error)) { logger->Log(__FUNCTION__": failed to get status message for (%d) (%d)", friendNumber, error); ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_FAILED, (HANDLE)hContact, 0); @@ -167,7 +167,7 @@ int CToxProto::OnUserIsTyping(MCONTACT hContact, int type) return 0; TOX_ERR_SET_TYPING error; - if (!tox_self_set_typing(toxThread->tox, friendNumber, type == PROTOTYPE_SELFTYPING_ON, &error)) + if (!tox_self_set_typing(toxThread->Tox(), friendNumber, type == PROTOTYPE_SELFTYPING_ON, &error)) logger->Log(__FUNCTION__": failed to send typing (%d)", error); return 0; diff --git a/protocols/Tox/src/tox_multimedia.cpp b/protocols/Tox/src/tox_multimedia.cpp index 0ef2cec23a..6fc188fed8 100644 --- a/protocols/Tox/src/tox_multimedia.cpp +++ b/protocols/Tox/src/tox_multimedia.cpp @@ -63,7 +63,7 @@ void CToxIncomingCall::OnInitDialog() void CToxIncomingCall::OnClose() { - toxav_call_control(m_proto->toxThread->toxAV, m_proto->calls[hContact], TOXAV_CALL_CONTROL_CANCEL, NULL); + toxav_call_control(m_proto->toxThread->ToxAV(), m_proto->calls[hContact], TOXAV_CALL_CONTROL_CANCEL, NULL); Utils_SaveWindowPosition(m_hwnd, NULL, m_proto->m_szModuleName, "IncomingCallWindow_"); CToxCallDlgBase::OnClose(); } @@ -83,7 +83,7 @@ void CToxIncomingCall::OnAnswer(CCtrlBase*) } TOXAV_ERR_ANSWER error; - if (!toxav_answer(m_proto->toxThread->toxAV, friendNumber, 0, 0, &error)) + if (!toxav_answer(m_proto->toxThread->ToxAV(), friendNumber, 0, 0, &error)) { m_proto->logger->Log(__FUNCTION__": failed to answer the call (%d)", error); Close(); @@ -139,7 +139,7 @@ void CToxOutgoingCall::OnCall(CCtrlBase*) } TOXAV_ERR_CALL error; - if (!toxav_call(m_proto->toxThread->toxAV, friendNumber, 0, 0, &error)) + if (!toxav_call(m_proto->toxThread->ToxAV(), friendNumber, 0, 0, &error)) { //mir_free(cSettings); m_proto->logger->Log(__FUNCTION__": failed to make a call (%d)", error); @@ -170,7 +170,7 @@ void CToxOutgoingCall::OnCancel(CCtrlBase*) } if (!call.Enabled()) - toxav_call_control(m_proto->toxThread->toxAV, friendNumber, TOXAV_CALL_CONTROL_CANCEL, NULL); + toxav_call_control(m_proto->toxThread->ToxAV(), friendNumber, TOXAV_CALL_CONTROL_CANCEL, NULL); } ////////////////////////////////////////////////////////////////////////////////////////////// @@ -197,7 +197,7 @@ void CToxCallDialog::OnClose() return; } - toxav_call_control(m_proto->toxThread->toxAV, friendNumber, TOXAV_CALL_CONTROL_CANCEL, NULL); + toxav_call_control(m_proto->toxThread->ToxAV(), friendNumber, TOXAV_CALL_CONTROL_CANCEL, NULL); Utils_SaveWindowPosition(m_hwnd, NULL, m_proto->m_szModuleName, "CallWindow_"); CToxCallDlgBase::OnClose(); } @@ -285,11 +285,11 @@ void CToxProto::OnFriendCall(ToxAV *toxAV, uint32_t friend_number, bool audio_en { /*CToxProto *proto = (CToxProto*)arg; - int friendNumber = toxav_get_peer_id(proto->toxThread->ToxAV, callId, 0); + int friendNumber = toxav_get_peer_id(proto->toxThread->Tox()AV, callId, 0); if (friendNumber == TOX_ERROR) { proto->logger->Log(__FUNCTION__": failed to get friend number"); - toxav_reject(proto->toxThread->ToxAV, callId, NULL); + toxav_reject(proto->toxThread->Tox()AV, callId, NULL); return; } @@ -297,22 +297,22 @@ void CToxProto::OnFriendCall(ToxAV *toxAV, uint32_t friend_number, bool audio_en if (hContact == NULL) { proto->logger->Log(__FUNCTION__": failed to find contact"); - toxav_reject(proto->toxThread->ToxAV, callId, NULL); + toxav_reject(proto->toxThread->Tox()AV, callId, NULL); return; } ToxAvCSettings cSettings; - if (toxav_get_peer_csettings(proto->toxThread->ToxAV, callId, 0, &cSettings) != av_ErrorNone) + if (toxav_get_peer_csettings(proto->toxThread->Tox()AV, callId, 0, &cSettings) != av_ErrorNone) { proto->logger->Log(__FUNCTION__": failed to get codec settings"); - toxav_reject(proto->toxThread->ToxAV, callId, NULL); + toxav_reject(proto->toxThread->Tox()AV, callId, NULL); return; } if (cSettings.call_type != av_TypeAudio) { proto->logger->Log(__FUNCTION__": video call is unsupported"); - toxav_reject(proto->toxThread->ToxAV, callId, Translate("Video call is unsupported")); + toxav_reject(proto->toxThread->Tox()AV, callId, Translate("Video call is unsupported")); return; } @@ -377,7 +377,7 @@ INT_PTR CToxProto::OnAudioRing(WPARAM, LPARAM lParam) { CToxProto *proto = (CToxProto*)arg; - int friendNumber = toxav_get_peer_id(proto->toxThread->ToxAV, callId, 0); + int friendNumber = toxav_get_peer_id(proto->toxThread->Tox()AV, callId, 0); if (friendNumber == TOX_ERROR) { proto->logger->Log(__FUNCTION__": failed to get friend number"); @@ -422,7 +422,7 @@ INT_PTR CToxProto::OnSendAudioCall(WPARAM hContact, LPARAM) { CToxProto *proto = (CToxProto*)arg; - int friendNumber = toxav_get_peer_id(proto->toxThread->ToxAV, callId, 0); + int friendNumber = toxav_get_peer_id(proto->toxThread->Tox()AV, callId, 0); if (friendNumber == TOX_ERROR) { proto->logger->Log(__FUNCTION__": failed to get friend number"); @@ -446,7 +446,7 @@ void CToxProto::OnAvCallTimeout(void*, int32_t callId, void *arg) { CToxProto *proto = (CToxProto*)arg; - int friendNumber = toxav_get_peer_id(proto->toxThread->ToxAV, callId, 0); + int friendNumber = toxav_get_peer_id(proto->toxThread->Tox()AV, callId, 0); if (friendNumber == TOX_ERROR) { proto->logger->Log(__FUNCTION__": failed to get friend number"); @@ -491,18 +491,18 @@ static void CALLBACK ToxShowDialogApcProc(void *arg) CToxProto *proto = (CToxProto*)arg; ToxAvCSettings cSettings; - int cSettingsError = toxav_get_peer_csettings(proto->toxThread->ToxAV, callId, 0, &cSettings); + int cSettingsError = toxav_get_peer_csettings(proto->toxThread->Tox()AV, callId, 0, &cSettings); if (cSettingsError != av_ErrorNone) { proto->logger->Log(__FUNCTION__": failed to get codec settings (%d)", cSettingsError); - toxav_hangup(proto->toxThread->ToxAV, callId); + toxav_hangup(proto->toxThread->Tox()AV, callId); return; } if (cSettings.call_type != av_TypeAudio) { proto->logger->Log(__FUNCTION__": video call is unsupported"); - toxav_hangup(proto->toxThread->ToxAV, callId); + toxav_hangup(proto->toxThread->Tox()AV, callId); return; } @@ -519,7 +519,7 @@ static void CALLBACK ToxShowDialogApcProc(void *arg) if (error != MMSYSERR_NOERROR) { proto->logger->Log(__FUNCTION__": failed to open audio device (%d)", error); - toxav_hangup(proto->toxThread->ToxAV, callId); + toxav_hangup(proto->toxThread->Tox()AV, callId); TCHAR errorMessage[MAX_PATH]; waveInGetErrorText(error, errorMessage, _countof(errorMessage)); @@ -530,11 +530,11 @@ static void CALLBACK ToxShowDialogApcProc(void *arg) return; } - int friendNumber = toxav_get_peer_id(proto->toxThread->ToxAV, callId, 0); + int friendNumber = toxav_get_peer_id(proto->toxThread->Tox()AV, callId, 0); if (friendNumber == TOX_ERROR) { proto->logger->Log(__FUNCTION__": failed to get friend number"); - toxav_hangup(proto->toxThread->ToxAV, callId); + toxav_hangup(proto->toxThread->Tox()AV, callId); return; } @@ -542,14 +542,14 @@ static void CALLBACK ToxShowDialogApcProc(void *arg) if (hContact == NULL) { proto->logger->Log(__FUNCTION__": failed to find contact"); - toxav_hangup(proto->toxThread->ToxAV, callId); + toxav_hangup(proto->toxThread->Tox()AV, callId); return; } - if (toxav_prepare_transmission(proto->toxThread->ToxAV, callId, false) == TOX_ERROR) + if (toxav_prepare_transmission(proto->toxThread->Tox()AV, callId, false) == TOX_ERROR) { proto->logger->Log(__FUNCTION__": failed to prepare audio transmition"); - toxav_hangup(proto->toxThread->ToxAV, callId); + toxav_hangup(proto->toxThread->Tox()AV, callId); return; } @@ -568,9 +568,9 @@ void CToxProto::OnAvEnd(void*, int32_t callId, void *arg) waveOutReset(proto->hOutDevice); waveOutClose(proto->hOutDevice); - toxav_kill_transmission(proto->toxThread->ToxAV, callId); + toxav_kill_transmission(proto->toxThread->Tox()AV, callId); - int friendNumber = toxav_get_peer_id(proto->toxThread->ToxAV, callId, 0); + int friendNumber = toxav_get_peer_id(proto->toxThread->Tox()AV, callId, 0); if (friendNumber == TOX_ERROR) { proto->logger->Log(__FUNCTION__": failed to get friend number"); @@ -594,7 +594,7 @@ void CToxProto::OnAvPeerTimeout(void *av, int32_t callId, void *arg) { CToxProto *proto = (CToxProto*)arg; - ToxAvCallState callState = toxav_get_call_state(proto->toxThread->ToxAV, callId); + ToxAvCallState callState = toxav_get_call_state(proto->toxThread->Tox()AV, callId); switch (callState) { case av_CallStarting: diff --git a/protocols/Tox/src/tox_network.cpp b/protocols/Tox/src/tox_network.cpp index fa4c3866b8..90ce85754b 100644 --- a/protocols/Tox/src/tox_network.cpp +++ b/protocols/Tox/src/tox_network.cpp @@ -2,18 +2,19 @@ bool CToxProto::IsOnline() { - return toxThread && toxThread->tox && toxThread->isConnected && m_iStatus >= ID_STATUS_ONLINE; + return toxThread && toxThread->IsConnected() && m_iStatus >= ID_STATUS_ONLINE; } void CToxProto::BootstrapNode(const char *address, int port, const char *hexKey) { if (hexKey == NULL || toxThread == NULL) return; + ToxBinAddress binKey(hexKey, TOX_PUBLIC_KEY_SIZE * 2); TOX_ERR_BOOTSTRAP error; - if (!tox_bootstrap(toxThread->tox, address, port, binKey, &error)) + if (!tox_bootstrap(toxThread->Tox(), address, port, binKey, &error)) logger->Log(__FUNCTION__ ": failed to bootstrap node %s:%d \"%s\" (%d)", address, port, hexKey, error); - if (!tox_add_tcp_relay(toxThread->tox, address, port, binKey, &error)) + if (!tox_add_tcp_relay(toxThread->Tox(), address, port, binKey, &error)) logger->Log(__FUNCTION__ ": failed to add tcp relay %s:%d \"%s\" (%d)", address, port, hexKey, error); } @@ -88,16 +89,16 @@ void CToxProto::TryConnect() { if (toxThread != NULL) { - if (tox_self_get_connection_status(toxThread->tox) != TOX_CONNECTION_NONE) + if (tox_self_get_connection_status(toxThread->Tox()) != TOX_CONNECTION_NONE) { - toxThread->isConnected = true; + toxThread->Connect(); logger->Log(__FUNCTION__": successfuly connected to DHT"); ForkThread(&CToxProto::LoadFriendList, NULL); m_iStatus = m_iDesiredStatus; ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus); - tox_self_set_status(toxThread->tox, MirandaToToxStatus(m_iStatus)); + tox_self_set_status(toxThread->Tox(), MirandaToToxStatus(m_iStatus)); logger->Log(__FUNCTION__": changing status from %i to %i", ID_STATUS_CONNECTING, m_iDesiredStatus); } else if (m_iStatus++ > TOX_MAX_CONNECT_RETRIES) @@ -111,11 +112,11 @@ void CToxProto::TryConnect() void CToxProto::CheckConnection(int &retriesCount) { - if (!toxThread || !toxThread->isConnected) + if (!toxThread || !toxThread->IsConnected()) { TryConnect(); } - else if (tox_self_get_connection_status(toxThread->tox) != TOX_CONNECTION_NONE) + else if (tox_self_get_connection_status(toxThread->Tox()) != TOX_CONNECTION_NONE) { if (retriesCount < TOX_MAX_DISCONNECT_RETRIES) { @@ -137,7 +138,7 @@ void CToxProto::CheckConnection(int &retriesCount) } else if (!(--retriesCount)) { - toxThread->isConnected = false; + toxThread->Disconnect(); logger->Log(__FUNCTION__": disconnected from DHT"); SetStatus(ID_STATUS_OFFLINE); } @@ -146,7 +147,25 @@ void CToxProto::CheckConnection(int &retriesCount) void CToxProto::PollingThread(void*) { - CToxThread toxThread; + Tox_Options *options = GetToxOptions(); + if (!options) + { + SetStatus(ID_STATUS_OFFLINE); + ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL); + logger->Log(__FUNCTION__": leaving"); + return; + } + + TOX_ERR_NEW error; + CToxThread toxThread(options, &error); + if (error != TOX_ERR_NEW_OK) + { + logger->Log(__FUNCTION__": failed to initialize tox core (%d)", error); + ShowNotification(ToxErrorToString(error), TranslateT("Unable to initialize Tox core"), MB_ICONERROR); + tox_options_free(options); + } + tox_options_free(options); + this->toxThread = &toxThread; logger->Log(__FUNCTION__": entering"); @@ -161,16 +180,15 @@ void CToxProto::PollingThread(void*) } int retriesCount = TOX_MAX_DISCONNECT_RETRIES; - toxThread.isConnected = false; BootstrapNodes(); - while (!toxThread.isTerminated) + while (!toxThread.IsTerminated()) { CheckConnection(retriesCount); - toxThread.Do(); + toxThread.Iterate(); } - toxThread.isConnected = false; + toxThread.Disconnect(); UninitToxCore(&toxThread); logger->Log(__FUNCTION__": leaving"); diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp index f28009ade5..7b1a89ad16 100644 --- a/protocols/Tox/src/tox_options.cpp +++ b/protocols/Tox/src/tox_options.cpp @@ -62,7 +62,10 @@ void CToxOptionsMain::ToxAddressCopy_OnClick(CCtrlButton*) void CToxOptionsMain::ProfileCreate_OnClick(CCtrlButton*) { - CToxThread toxThread; + Tox_Options *options; + tox_options_default(options); + CToxThread toxThread(options); + tox_options_free(options); ptrT profilePath(m_proto->GetToxProfilePath()); if (!m_proto->IsFileExists(profilePath)) diff --git a/protocols/Tox/src/tox_profile.cpp b/protocols/Tox/src/tox_profile.cpp index c8d93c4a26..556d017144 100644 --- a/protocols/Tox/src/tox_profile.cpp +++ b/protocols/Tox/src/tox_profile.cpp @@ -104,9 +104,9 @@ void CToxProto::SaveToxProfile(CToxThread *toxThread) if (!toxThread) return; - size_t size = tox_get_savedata_size(toxThread->tox); + size_t size = tox_get_savedata_size(toxThread->Tox()); uint8_t *data = (uint8_t*)mir_calloc(size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH); - tox_get_savedata(toxThread->tox, data); + tox_get_savedata(toxThread->Tox(), data); pass_ptrA password(mir_utf8encodeW(pass_ptrT(getTStringA("Password")))); if (password && mir_strlen(password)) diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp index 7c6c4cb30c..3c483f40d9 100644 --- a/protocols/Tox/src/tox_proto.cpp +++ b/protocols/Tox/src/tox_proto.cpp @@ -182,7 +182,7 @@ int CToxProto::SetStatus(int iNewStatus) { // set tox status m_iStatus = iNewStatus; - tox_self_set_status(toxThread->tox, MirandaToToxStatus(iNewStatus)); + tox_self_set_status(toxThread->Tox(), MirandaToToxStatus(iNewStatus)); } ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus); @@ -206,7 +206,7 @@ int CToxProto::SetAwayMsg(int, const TCHAR *msg) { T2Utf statusMessage(msg); TOX_ERR_SET_INFO error; - if (!tox_self_set_status_message(toxThread->tox, (uint8_t*)(char*)statusMessage, min(TOX_MAX_STATUS_MESSAGE_LENGTH, mir_strlen(statusMessage)), &error)) + if (!tox_self_set_status_message(toxThread->Tox(), (uint8_t*)(char*)statusMessage, min(TOX_MAX_STATUS_MESSAGE_LENGTH, mir_strlen(statusMessage)), &error)) logger->Log("CToxProto::SetAwayMsg: failed to set status status message %s (%d)", msg, error); } diff --git a/protocols/Tox/src/tox_services.cpp b/protocols/Tox/src/tox_services.cpp index c5ead26307..8ea301c6fa 100644 --- a/protocols/Tox/src/tox_services.cpp +++ b/protocols/Tox/src/tox_services.cpp @@ -9,7 +9,7 @@ INT_PTR CToxProto::SetMyNickname(WPARAM wParam, LPARAM lParam) { T2Utf szNick8(nickname); TOX_ERR_SET_INFO error; - if (!tox_self_set_name(toxThread->tox, szNick8, mir_strlen(szNick8), &error)) + if (!tox_self_set_name(toxThread->Tox(), szNick8, mir_strlen(szNick8), &error)) logger->Log(__FUNCTION__": failed to set nick name"); } diff --git a/protocols/Tox/src/tox_thread.h b/protocols/Tox/src/tox_thread.h index b476f54686..59caa7ee30 100644 --- a/protocols/Tox/src/tox_thread.h +++ b/protocols/Tox/src/tox_thread.h @@ -3,7 +3,7 @@ class CToxThread { -public: +private: Tox *tox; ToxAV *toxAV; bool isConnected; @@ -11,10 +11,65 @@ public: mir_cs toxLock; - CToxThread() : tox(NULL), toxAV(NULL), - isConnected(false), isTerminated(false) { } + mir_cs lock; + +public: + CToxThread(Tox_Options *options, TOX_ERR_NEW *error = NULL) : tox(NULL), toxAV(NULL), + isConnected(false), isTerminated(false) + { + tox = tox_new(options, error); + } + + ~CToxThread() + { + if (toxAV) + { + toxav_kill(toxAV); + toxAV = NULL; + } + + if (tox) + { + tox_kill(tox); + tox = NULL; + } + } + + mir_cslock Lock() + { + return mir_cslock(lock); + } + + Tox* Tox() + { + return tox; + } + + ToxAV* ToxAV() + { + return toxAV; + } + + bool IsConnected() const + { + return tox && isConnected; + } + + void Connect() + { + Lock(); + + isConnected = true; + } - void Do() + void Disconnect() + { + Lock(); + + isConnected = false; + } + + void Iterate() { { mir_cslock lock(toxLock); @@ -23,10 +78,15 @@ public: // toxav_iterate(toxAV); } uint32_t interval = tox_iteration_interval(tox); - interval ++; /* Prevent zero sleep interval. */ + interval = interval ? interval : 50; Sleep(interval); } + bool IsTerminated() const + { + return !tox || isTerminated; + } + void Stop() { isTerminated = true; } }; diff --git a/protocols/Tox/src/tox_transfer.cpp b/protocols/Tox/src/tox_transfer.cpp index f98c5590b2..e4541d5343 100644 --- a/protocols/Tox/src/tox_transfer.cpp +++ b/protocols/Tox/src/tox_transfer.cpp @@ -26,7 +26,7 @@ void CToxProto::OnFriendFile(Tox*, uint32_t friendNumber, uint32_t fileNumber, u proto->transfers.Add(transfer); TOX_ERR_FILE_GET error; - tox_file_get_file_id(proto->toxThread->tox, friendNumber, fileNumber, transfer->hash, &error); + tox_file_get_file_id(proto->toxThread->Tox(), friendNumber, fileNumber, transfer->hash, &error); if (error != TOX_ERR_FILE_GET_OK) { proto->logger->Log(__FUNCTION__": unable to get avatar hash (%d) from (%d) cause (%d)", fileNumber, friendNumber, error); @@ -99,7 +99,7 @@ int CToxProto::OnFileResume(HANDLE hTransfer, int *action, const TCHAR **szFilen if (*action == FILERESUME_SKIP) { - tox_file_control(toxThread->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); + tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); transfers.Remove(transfer); return 0; } @@ -111,18 +111,18 @@ int CToxProto::OnFileResume(HANDLE hTransfer, int *action, const TCHAR **szFilen if (!transfer->OpenFile(mode)) { logger->Log(__FUNCTION__": failed to open file (%d) from (%d)", transfer->fileNumber, transfer->friendNumber); - tox_file_control(toxThread->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); + tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); transfers.Remove(transfer); return NULL; } TOX_ERR_FILE_CONTROL error; logger->Log(__FUNCTION__": start receiving file (%d) from (%d)", transfer->fileNumber, transfer->friendNumber); - if (!tox_file_control(toxThread->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_RESUME, &error)) + if (!tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_RESUME, &error)) { logger->Log(__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(toxThread->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); + tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); transfers.Remove(transfer); } @@ -169,7 +169,7 @@ void CToxProto::OnDataReceiving(Tox*, uint32_t friendNumber, uint32_t fileNumber if (hContact == NULL) { proto->logger->Log(__FUNCTION__": cannot find contact by number (%d)", friendNumber); - tox_file_control(proto->toxThread->tox, friendNumber, fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); + tox_file_control(proto->toxThread->Tox(), friendNumber, fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); return; } @@ -181,7 +181,7 @@ void CToxProto::OnDataReceiving(Tox*, uint32_t friendNumber, uint32_t fileNumber { proto->logger->Log(__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); + tox_file_control(proto->toxThread->Tox(), friendNumber, fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); return; } @@ -217,7 +217,7 @@ HANDLE CToxProto::OnSendFile(MCONTACT hContact, const TCHAR*, TCHAR **ppszFiles) char *name = mir_utf8encodeW(fileName); TOX_ERR_FILE_SEND sendError; - uint32_t fileNumber = tox_file_send(toxThread->tox, friendNumber, TOX_FILE_KIND_DATA, fileSize, NULL, (uint8_t*)name, mir_strlen(name), &sendError); + uint32_t fileNumber = tox_file_send(toxThread->Tox(), friendNumber, TOX_FILE_KIND_DATA, fileSize, NULL, (uint8_t*)name, mir_strlen(name), &sendError); if (sendError != TOX_ERR_FILE_SEND_OK) { logger->Log(__FUNCTION__": failed to send file (%d) to (%d) cause (%d)", fileNumber, friendNumber, sendError); @@ -270,13 +270,13 @@ void CToxProto::OnFileSendData(Tox*, uint32_t friendNumber, uint32_t fileNumber, { proto->logger->Log(__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->toxThread->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); + tox_file_control(proto->toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); mir_free(data); return; } TOX_ERR_FILE_SEND_CHUNK error; - if (!tox_file_send_chunk(proto->toxThread->tox, friendNumber, fileNumber, position, data, length, &error)) + if (!tox_file_send_chunk(proto->toxThread->Tox(), friendNumber, fileNumber, position, data, length, &error)) { if (error == TOX_ERR_FILE_SEND_CHUNK_FRIEND_NOT_CONNECTED) { @@ -285,7 +285,7 @@ void CToxProto::OnFileSendData(Tox*, uint32_t friendNumber, uint32_t fileNumber, } proto->logger->Log(__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->toxThread->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); + tox_file_control(proto->toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); mir_free(data); return; } @@ -303,7 +303,7 @@ int CToxProto::OnFileCancel(MCONTACT, HANDLE hTransfer) { FileTransferParam *transfer = (FileTransferParam*)hTransfer; logger->Log(__FUNCTION__": Transfer (%d) is canceled", transfer->fileNumber); - tox_file_control(toxThread->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); + tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); transfers.Remove(transfer); return 0; @@ -319,10 +319,10 @@ void CToxProto::PauseOutgoingTransfers(uint32_t friendNumber) { logger->Log(__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(toxThread->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_PAUSE, &error)) + if (!tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_PAUSE, &error)) { logger->Log(__FUNCTION__": failed to pause the transfer (%d) to (%d) cause(%d)", transfer->fileNumber, transfer->friendNumber, error); - tox_file_control(toxThread->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); + tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); } } } @@ -338,10 +338,10 @@ void CToxProto::ResumeIncomingTransfers(uint32_t friendNumber) { logger->Log(__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(toxThread->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_RESUME, &error)) + if (!tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_RESUME, &error)) { logger->Log(__FUNCTION__": failed to resume the transfer (%d) from (%d) cause(%d)", transfer->fileNumber, transfer->friendNumber, error); - tox_file_control(toxThread->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); + tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); } } } @@ -352,8 +352,8 @@ void CToxProto::CancelAllTransfers() for (size_t i = 0; i < transfers.Count(); i++) { FileTransferParam *transfer = transfers.GetAt(i); - if (toxThread && toxThread->tox) - tox_file_control(toxThread->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); + if (toxThread && toxThread->Tox()) + tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_DENIED, (HANDLE)transfer, 0); transfers.Remove(transfer); } -- cgit v1.2.3