summaryrefslogtreecommitdiff
path: root/protocols/Tox
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-09-10 11:58:58 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-09-10 11:58:58 +0000
commit510f938a5c6f0ee95ac0b36e56aced065228298e (patch)
tree19f907a09498b6f76a4b7aae6ee90a16bf693aa2 /protocols/Tox
parent86c868a76a5ba3d638b3b7302cd5401df06591d8 (diff)
Tox: tox pointers should store in PollingThread to avoid cross thread using
git-svn-id: http://svn.miranda-ng.org/main/trunk@15316 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox')
-rw-r--r--protocols/Tox/src/tox_avatars.cpp4
-rw-r--r--protocols/Tox/src/tox_chatrooms.cpp12
-rw-r--r--protocols/Tox/src/tox_contacts.cpp26
-rw-r--r--protocols/Tox/src/tox_core.cpp86
-rw-r--r--protocols/Tox/src/tox_menus.cpp2
-rw-r--r--protocols/Tox/src/tox_messages.cpp8
-rw-r--r--protocols/Tox/src/tox_multimedia.cpp52
-rw-r--r--protocols/Tox/src/tox_network.cpp47
-rw-r--r--protocols/Tox/src/tox_options.cpp13
-rw-r--r--protocols/Tox/src/tox_profile.cpp22
-rw-r--r--protocols/Tox/src/tox_proto.cpp19
-rw-r--r--protocols/Tox/src/tox_proto.h26
-rw-r--r--protocols/Tox/src/tox_services.cpp2
-rw-r--r--protocols/Tox/src/tox_transfer.cpp32
-rw-r--r--protocols/Tox/src/version.h2
15 files changed, 181 insertions, 172 deletions
diff --git a/protocols/Tox/src/tox_avatars.cpp b/protocols/Tox/src/tox_avatars.cpp
index e8aab00e57..2aede1cbe1 100644
--- a/protocols/Tox/src/tox_avatars.cpp
+++ b/protocols/Tox/src/tox_avatars.cpp
@@ -82,7 +82,7 @@ void CToxProto::SetToxAvatar(std::tstring path)
}
TOX_ERR_FILE_SEND error;
- uint32_t fileNumber = tox_file_send(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);
@@ -184,7 +184,7 @@ INT_PTR CToxProto::SetMyAvatar(WPARAM, LPARAM lParam)
continue;
TOX_ERR_FILE_SEND error;
- tox_file_send(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)
{
debugLogA(__FUNCTION__": failed to unset avatar (%d)", error);
diff --git a/protocols/Tox/src/tox_chatrooms.cpp b/protocols/Tox/src/tox_chatrooms.cpp
index 3f999a0d4f..cff9447d84 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(tox);
+ uint32_t count = tox_count_chatlist(toxThread->tox);
if (count == 0)
{
debugLogA("CToxProto::LoadGroupChatList: your group chat list is empty");
return;
}
int32_t *groupChats = (int32_t*)mir_alloc(count * sizeof(int32_t));
- tox_get_chatlist(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(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(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)));
}
}
@@ -124,7 +124,7 @@ INT_PTR CToxProto::OnCreateChatRoom(WPARAM, LPARAM)
CToxProto::ChatRoomInviteProc,
(LPARAM)&param) == IDOK && !param.invitedContacts.empty())
{
- int groupNumber = tox_add_groupchat(tox);
+ int groupNumber = tox_add_groupchat(toxThread->tox);
if (groupNumber == TOX_ERROR)
{
return 1;
@@ -132,7 +132,7 @@ INT_PTR CToxProto::OnCreateChatRoom(WPARAM, LPARAM)
for (std::vector<MCONTACT>::iterator it = param.invitedContacts.begin(); it != param.invitedContacts.end(); ++it)
{
int32_t friendNumber = GetToxFriendNumber(*it);
- if (friendNumber == TOX_ERROR || tox_invite_friend(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 d5b166ce75..5bf327f060 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(tox, friendNumber, data, &error))
+ if (!tox_friend_get_public_key(toxThread->tox, friendNumber, data, &error))
{
debugLogA(__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(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)
debugLogA(__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(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(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(tox, friendNumber, data, &getPublicKeyResult))
+ if (!tox_friend_get_public_key(toxThread->tox, friendNumber, data, &getPublicKeyResult))
{
debugLogA(__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(tox, friendNumber, nick, &getNameResult))
+ if (tox_friend_get_name(toxThread->tox, friendNumber, nick, &getNameResult))
setTString(hContact, "Nick", ptrT(mir_utf8decodeT((char*)nick)));
else
debugLogA(__FUNCTION__": failed to get friend name (%d)", getNameResult);
TOX_ERR_FRIEND_GET_LAST_ONLINE getLastOnlineResult;
- uint64_t timestamp = tox_friend_get_last_online(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(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)
{
debugLogA(__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(tox, friendNumber, nick, &errorFriendQuery))
+ if (tox_friend_get_name(toxThread->tox, friendNumber, nick, &errorFriendQuery))
setTString(hContact, "Nick", ptrT(mir_utf8decodeT((char*)nick)));
else
debugLogA(__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(tox, pubKey, &error);
+ tox_friend_add_norequest(toxThread->tox, pubKey, &error);
if (error != TOX_ERR_FRIEND_ADD_OK)
{
debugLogA(__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(tox, friendNumber, &error))
+ if (!tox_friend_delete(toxThread->tox, friendNumber, &error))
{
debugLogA(__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->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->debugLogA(__FUNCTION__": failed to set new avatar");
@@ -361,7 +361,7 @@ void CToxProto::OnConnectionStatusChanged(Tox*, uint32_t friendNumber, TOX_CONNE
proto->transfers.Add(transfer);
}
else
- tox_file_send(proto->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 e2c683d751..043f904c75 100644
--- a/protocols/Tox/src/tox_core.cpp
+++ b/protocols/Tox/src/tox_core.cpp
@@ -1,16 +1,15 @@
#include "stdafx.h"
-bool CToxProto::InitToxCore()
+Tox_Options* CToxProto::GetToxOptions()
{
- debugLogA(__FUNCTION__": initializing tox core");
-
TOX_ERR_OPTIONS_NEW error;
Tox_Options *options = tox_options_new(&error);
if (error != TOX_ERR_OPTIONS_NEW_OK)
{
debugLogA(__FUNCTION__": failed to initialize tox options (%d)", error);
- return false;
+ return NULL;
}
+
options->udp_enabled = getBool("EnableUDP", 1);
options->ipv6_enabled = getBool("EnableIPv6", 0);
@@ -38,11 +37,22 @@ bool CToxProto::InitToxCore()
}
}
}
+
+ return options;
+}
+
+bool CToxProto::InitToxCore(ToxThreadData *toxThread)
+{
+ debugLogA(__FUNCTION__": initializing tox core");
+
+ Tox_Options *options = GetToxOptions();
+ if (options == NULL)
+ return false;
if (LoadToxProfile(options))
{
TOX_ERR_NEW initError;
- tox = tox_new(options, &initError);
+ toxThread->tox = tox_new(options, &initError);
if (initError != TOX_ERR_NEW_OK)
{
debugLogA(__FUNCTION__": failed to initialize tox core (%d)", initError);
@@ -51,47 +61,47 @@ bool CToxProto::InitToxCore()
return false;
}
- tox_callback_friend_request(tox, OnFriendRequest, this);
- tox_callback_friend_message(tox, OnFriendMessage, this);
- tox_callback_friend_read_receipt(tox, OnReadReceipt, this);
- tox_callback_friend_typing(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(tox, OnFriendNameChange, this);
- tox_callback_friend_status_message(tox, OnStatusMessageChanged, this);
- tox_callback_friend_status(tox, OnUserStatusChanged, this);
- tox_callback_friend_connection_status(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(tox, OnFileRequest, this);
- tox_callback_file_recv(tox, OnFriendFile, this);
- tox_callback_file_recv_chunk(tox, OnDataReceiving, this);
- tox_callback_file_chunk_request(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 = toxav_new(tox, TOX_MAX_CALLS);
- toxav_register_audio_callback(toxAv, OnFriendAudio, this);
- toxav_register_callstate_callback(toxAv, OnAvInvite, av_OnInvite, this);
- toxav_register_callstate_callback(toxAv, OnAvStart, av_OnStart, this);
- toxav_register_callstate_callback(toxAv, OnAvCancel, av_OnCancel, this);
- toxav_register_callstate_callback(toxAv, OnAvReject, av_OnReject, this);
- toxav_register_callstate_callback(toxAv, OnAvEnd, av_OnEnd, this);
- toxav_register_callstate_callback(toxAv, OnAvCallTimeout, av_OnRequestTimeout, this);
- toxav_register_callstate_callback(toxAv, OnAvPeerTimeout, av_OnPeerTimeout, this);*/
+ toxav_register_audio_callback(toxThread->toxAv, OnFriendAudio, this);
+ toxav_register_callstate_callbacktox(Thread->toxAv, OnAvInvite, av_OnInvite, this);
+ toxav_register_callstate_callbacktox(Thread->toxAv, OnAvStart, av_OnStart, this);
+ toxav_register_callstate_callbacktox(Thread->toxAv, OnAvCancel, av_OnCancel, this);
+ toxav_register_callstate_callbacktox(Thread->toxAv, OnAvReject, av_OnReject, this);
+ toxav_register_callstate_callback(toxThread->toxAv, OnAvEnd, av_OnEnd, this);
+ toxav_register_callstate_callback(toxThread->toxAv, OnAvCallTimeout, av_OnRequestTimeout, this);
+ toxav_register_callstate_callback(toxThread->toxAv, OnAvPeerTimeout, av_OnPeerTimeout, this);*/
}
uint8_t data[TOX_ADDRESS_SIZE];
- tox_self_get_address(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(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(tox, statusMessage);
+ tox_self_get_status_message(toxThread->tox, statusMessage);
setTString("StatusMsg", ptrT(Utf8DecodeT((char*)statusMessage)));
return true;
@@ -102,14 +112,14 @@ bool CToxProto::InitToxCore()
return false;
}
-void CToxProto::UninitToxCore()
+void CToxProto::UninitToxCore(ToxThreadData *toxThread)
{
- if (tox)
+ if (toxThread->tox)
{
for (size_t i = 0; i < transfers.Count(); i++)
{
FileTransferParam *transfer = transfers.GetAt(i);
- tox_file_control(tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
+ 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);
}
@@ -124,16 +134,12 @@ void CToxProto::UninitToxCore()
// tox_set_status_message(tox, (uint8_t*)(char*)statusmes, mir_strlen(statusmes));
//}
- if (toxAv)
- toxav_kill(toxAv);
+ if (toxThread->toxAv)
+ toxav_kill(toxThread->toxAv);
SaveToxProfile();
- if (password != NULL)
- {
- mir_free(password);
- password = NULL;
- }
- tox_kill(tox);
- tox = NULL;
+
+ tox_kill(toxThread->tox);
+ toxThread = NULL;
}
} \ No newline at end of file
diff --git a/protocols/Tox/src/tox_menus.cpp b/protocols/Tox/src/tox_menus.cpp
index bd342903dd..1bf262ae60 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], 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 00e928f168..fe3b205b0b 100644
--- a/protocols/Tox/src/tox_messages.cpp
+++ b/protocols/Tox/src/tox_messages.cpp
@@ -74,7 +74,7 @@ int CToxProto::OnSendMessage(MCONTACT hContact, const char *szMessage)
}
TOX_ERR_FRIEND_SEND_MESSAGE sendError;
- int messageId = tox_friend_send_message(tox, friendNumber, type, msg, msgLen, &sendError);
+ int messageId = tox_friend_send_message(toxThread->tox, friendNumber, type, msg, msgLen, &sendError);
if (sendError != TOX_ERR_FRIEND_SEND_MESSAGE_OK)
{
debugLogA(__FUNCTION__": failed to send message for %d (%d)", friendNumber, sendError);
@@ -131,7 +131,7 @@ void CToxProto::GetStatusMessageAsync(void* arg)
}
TOX_ERR_FRIEND_QUERY error;
- size_t size = tox_friend_get_status_message_size(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)
{
debugLogA(__FUNCTION__": failed to get status message for (%d) (%d)", friendNumber, error);
@@ -140,7 +140,7 @@ void CToxProto::GetStatusMessageAsync(void* arg)
}
ptrA statusMessage((char*)mir_calloc(size + 1));
- if (!tox_friend_get_status_message(tox, friendNumber, (uint8_t*)(char*)statusMessage, &error))
+ if (!tox_friend_get_status_message(toxThread->tox, friendNumber, (uint8_t*)(char*)statusMessage, &error))
{
debugLogA(__FUNCTION__": failed to get status message for (%d) (%d)", friendNumber, error);
ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_FAILED, (HANDLE)hContact, 0);
@@ -159,7 +159,7 @@ int CToxProto::OnUserIsTyping(MCONTACT hContact, int type)
return 0;
TOX_ERR_SET_TYPING error;
- if (!tox_self_set_typing(tox, friendNumber, type == PROTOTYPE_SELFTYPING_ON, &error))
+ if (!tox_self_set_typing(toxThread->tox, friendNumber, type == PROTOTYPE_SELFTYPING_ON, &error))
debugLogA(__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 d24a5df474..ca034a188c 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_reject(m_proto->toxAv, m_proto->calls[hContact], NULL);
+ toxav_reject(m_proto->toxThread->toxAv, m_proto->calls[hContact], NULL);
Utils_SaveWindowPosition(m_hwnd, NULL, m_proto->m_szModuleName, "IncomingCallWindow_");
CToxCallDlgBase::OnClose();
}
@@ -74,7 +74,7 @@ void CToxIncomingCall::OnAnswer(CCtrlBase*)
if (cSettings == NULL)
return;
- if (toxav_answer(m_proto->toxAv, m_proto->calls[hContact], cSettings) == TOX_ERROR)
+ if (toxav_answer(m_proto->toxThread->toxAv, m_proto->calls[hContact], cSettings) == TOX_ERROR)
m_proto->debugLogA(__FUNCTION__": failed to start call");
}
@@ -127,7 +127,7 @@ void CToxOutgoingCall::OnCall(CCtrlBase*)
}
int32_t callId;
- if (toxav_call(m_proto->toxAv, &callId, friendNumber, cSettings, 10) == TOX_ERROR)
+ if (toxav_call(m_proto->toxThread->toxAv, &callId, friendNumber, cSettings, 10) == TOX_ERROR)
{
mir_free(cSettings);
m_proto->debugLogA(__FUNCTION__": failed to start outgoing call");
@@ -151,7 +151,7 @@ void CToxOutgoingCall::OnCall(CCtrlBase*)
void CToxOutgoingCall::OnCancel(CCtrlBase*)
{
if (!call.Enabled())
- toxav_cancel(m_proto->toxAv, m_proto->calls[hContact], 0, NULL);
+ toxav_cancel(m_proto->toxThread->toxAv, m_proto->calls[hContact], 0, NULL);
}
//////////////////////////////////////////////////////////////////////////////////////////////
@@ -170,7 +170,7 @@ void CToxCallDialog::OnInitDialog()
void CToxCallDialog::OnClose()
{
- toxav_hangup(m_proto->toxAv, m_proto->calls[hContact]);
+ toxav_hangup(m_proto->toxThread->toxAv, m_proto->calls[hContact]);
Utils_SaveWindowPosition(m_hwnd, NULL, m_proto->m_szModuleName, "CallWindow_");
CToxCallDlgBase::OnClose();
}
@@ -258,11 +258,11 @@ void CToxProto::OnAvInvite(void*, int32_t callId, void *arg)
{
CToxProto *proto = (CToxProto*)arg;
- int friendNumber = toxav_get_peer_id(proto->toxAv, callId, 0);
+ int friendNumber = toxav_get_peer_id(proto->toxThread->toxAv, callId, 0);
if (friendNumber == TOX_ERROR)
{
proto->debugLogA(__FUNCTION__": failed to get friend number");
- toxav_reject(proto->toxAv, callId, NULL);
+ toxav_reject(proto->toxThread->toxAv, callId, NULL);
return;
}
@@ -270,22 +270,22 @@ void CToxProto::OnAvInvite(void*, int32_t callId, void *arg)
if (hContact == NULL)
{
proto->debugLogA(__FUNCTION__": failed to find contact");
- toxav_reject(proto->toxAv, callId, NULL);
+ toxav_reject(proto->toxThread->toxAv, callId, NULL);
return;
}
ToxAvCSettings cSettings;
- if (toxav_get_peer_csettings(proto->toxAv, callId, 0, &cSettings) != av_ErrorNone)
+ if (toxav_get_peer_csettings(proto->toxThread->toxAv, callId, 0, &cSettings) != av_ErrorNone)
{
proto->debugLogA(__FUNCTION__": failed to get codec settings");
- toxav_reject(proto->toxAv, callId, NULL);
+ toxav_reject(proto->toxThread->toxAv, callId, NULL);
return;
}
if (cSettings.call_type != av_TypeAudio)
{
proto->debugLogA(__FUNCTION__": video call is unsupported");
- toxav_reject(proto->toxAv, callId, Translate("Video call is unsupported"));
+ toxav_reject(proto->toxThread->toxAv, callId, Translate("Video call is unsupported"));
return;
}
@@ -343,7 +343,7 @@ void CToxProto::OnAvCancel(void*, int32_t callId, void *arg)
{
CToxProto *proto = (CToxProto*)arg;
- int friendNumber = toxav_get_peer_id(proto->toxAv, callId, 0);
+ int friendNumber = toxav_get_peer_id(proto->toxThread->toxAv, callId, 0);
if (friendNumber == TOX_ERROR)
{
proto->debugLogA(__FUNCTION__": failed to get friend number");
@@ -388,7 +388,7 @@ void CToxProto::OnAvReject(void*, int32_t callId, void *arg)
{
CToxProto *proto = (CToxProto*)arg;
- int friendNumber = toxav_get_peer_id(proto->toxAv, callId, 0);
+ int friendNumber = toxav_get_peer_id(proto->toxThread->toxAv, callId, 0);
if (friendNumber == TOX_ERROR)
{
proto->debugLogA(__FUNCTION__": failed to get friend number");
@@ -412,7 +412,7 @@ void CToxProto::OnAvCallTimeout(void*, int32_t callId, void *arg)
{
CToxProto *proto = (CToxProto*)arg;
- int friendNumber = toxav_get_peer_id(proto->toxAv, callId, 0);
+ int friendNumber = toxav_get_peer_id(proto->toxThread->toxAv, callId, 0);
if (friendNumber == TOX_ERROR)
{
proto->debugLogA(__FUNCTION__": failed to get friend number");
@@ -457,18 +457,18 @@ void CToxProto::OnAvStart(void*, int32_t callId, void *arg)
CToxProto *proto = (CToxProto*)arg;
ToxAvCSettings cSettings;
- int cSettingsError = toxav_get_peer_csettings(proto->toxAv, callId, 0, &cSettings);
+ int cSettingsError = toxav_get_peer_csettings(proto->toxThread->toxAv, callId, 0, &cSettings);
if (cSettingsError != av_ErrorNone)
{
proto->debugLogA(__FUNCTION__": failed to get codec settings (%d)", cSettingsError);
- toxav_hangup(proto->toxAv, callId);
+ toxav_hangup(proto->toxThread->toxAv, callId);
return;
}
if (cSettings.call_type != av_TypeAudio)
{
proto->debugLogA(__FUNCTION__": video call is unsupported");
- toxav_hangup(proto->toxAv, callId);
+ toxav_hangup(proto->toxThread->toxAv, callId);
return;
}
@@ -485,7 +485,7 @@ void CToxProto::OnAvStart(void*, int32_t callId, void *arg)
if (error != MMSYSERR_NOERROR)
{
proto->debugLogA(__FUNCTION__": failed to open audio device (%d)", error);
- toxav_hangup(proto->toxAv, callId);
+ toxav_hangup(proto->toxThread->toxAv, callId);
TCHAR errorMessage[MAX_PATH];
waveInGetErrorText(error, errorMessage, _countof(errorMessage));
@@ -496,11 +496,11 @@ void CToxProto::OnAvStart(void*, int32_t callId, void *arg)
return;
}
- int friendNumber = toxav_get_peer_id(proto->toxAv, callId, 0);
+ int friendNumber = toxav_get_peer_id(proto->toxThread->toxAv, callId, 0);
if (friendNumber == TOX_ERROR)
{
proto->debugLogA(__FUNCTION__": failed to get friend number");
- toxav_hangup(proto->toxAv, callId);
+ toxav_hangup(proto->toxThread->toxAv, callId);
return;
}
@@ -508,14 +508,14 @@ void CToxProto::OnAvStart(void*, int32_t callId, void *arg)
if (hContact == NULL)
{
proto->debugLogA(__FUNCTION__": failed to find contact");
- toxav_hangup(proto->toxAv, callId);
+ toxav_hangup(proto->toxThread->toxAv, callId);
return;
}
- if (toxav_prepare_transmission(proto->toxAv, callId, false) == TOX_ERROR)
+ if (toxav_prepare_transmission(proto->toxThread->toxAv, callId, false) == TOX_ERROR)
{
proto->debugLogA(__FUNCTION__": failed to prepare audio transmition");
- toxav_hangup(proto->toxAv, callId);
+ toxav_hangup(proto->toxThread->toxAv, callId);
return;
}
@@ -534,9 +534,9 @@ void CToxProto::OnAvEnd(void*, int32_t callId, void *arg)
waveOutReset(proto->hOutDevice);
waveOutClose(proto->hOutDevice);
- toxav_kill_transmission(proto->toxAv, callId);
+ toxav_kill_transmission(proto->toxThread->toxAv, callId);
- int friendNumber = toxav_get_peer_id(proto->toxAv, callId, 0);
+ int friendNumber = toxav_get_peer_id(proto->toxThread->toxAv, callId, 0);
if (friendNumber == TOX_ERROR)
{
proto->debugLogA(__FUNCTION__": failed to get friend number");
@@ -560,7 +560,7 @@ void CToxProto::OnAvPeerTimeout(void *av, int32_t callId, void *arg)
{
CToxProto *proto = (CToxProto*)arg;
- ToxAvCallState callState = toxav_get_call_state(proto->toxAv, callId);
+ ToxAvCallState callState = toxav_get_call_state(proto->toxThread->toxAv, callId);
switch (callState)
{
case av_CallStarting:
diff --git a/protocols/Tox/src/tox_network.cpp b/protocols/Tox/src/tox_network.cpp
index 8db001a5a5..03134d1034 100644
--- a/protocols/Tox/src/tox_network.cpp
+++ b/protocols/Tox/src/tox_network.cpp
@@ -2,7 +2,7 @@
bool CToxProto::IsOnline()
{
- return 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)
@@ -11,10 +11,10 @@ void CToxProto::BootstrapNode(const char *address, int port, const char *hexKey)
return;
ToxBinAddress binKey(hexKey, TOX_PUBLIC_KEY_SIZE * 2);
TOX_ERR_BOOTSTRAP error;
- if (!tox_bootstrap(tox, address, port, binKey, &error))
+ if (!tox_bootstrap(toxThread->tox, address, port, binKey, &error))
debugLogA(__FUNCTION__ ": failed to bootstrap node %s:%d \"%s\" (%d)", address, port, hexKey, error);
- if (!tox_add_tcp_relay(tox, address, port, binKey, &error))
- debugLogA(__FUNCTION__ ": failed to add tcp relay%s:%d \"%s\" (%d)", address, port, hexKey, error);
+ if (!tox_add_tcp_relay(toxThread->tox, address, port, binKey, &error))
+ debugLogA(__FUNCTION__ ": failed to add tcp relay %s:%d \"%s\" (%d)", address, port, hexKey, error);
}
void CToxProto::BootstrapNodesFromDb(bool isIPv6)
@@ -86,16 +86,16 @@ void CToxProto::BootstrapNodes()
void CToxProto::TryConnect()
{
- if (tox_self_get_connection_status(tox) != TOX_CONNECTION_NONE)
+ if (tox_self_get_connection_status(toxThread->tox) != TOX_CONNECTION_NONE)
{
- isConnected = true;
+ toxThread->isConnected = true;
debugLogA(__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(tox, MirandaToToxStatus(m_iStatus));
+ tox_self_set_status(toxThread->tox, MirandaToToxStatus(m_iStatus));
debugLogA(__FUNCTION__": changing status from %i to %i", ID_STATUS_CONNECTING, m_iDesiredStatus);
}
else if (m_iStatus++ > TOX_MAX_CONNECT_RETRIES)
@@ -108,11 +108,11 @@ void CToxProto::TryConnect()
void CToxProto::CheckConnection(int &retriesCount)
{
- if (!isConnected)
+ if (!toxThread->isConnected)
{
TryConnect();
}
- else if (tox_self_get_connection_status(tox) != TOX_CONNECTION_NONE)
+ else if (tox_self_get_connection_status(toxThread->tox) != TOX_CONNECTION_NONE)
{
if (retriesCount < TOX_MAX_DISCONNECT_RETRIES)
{
@@ -134,30 +134,33 @@ void CToxProto::CheckConnection(int &retriesCount)
}
else if (!(--retriesCount))
{
- isConnected = false;
+ toxThread->isConnected = false;
debugLogA(__FUNCTION__": disconnected from DHT");
SetStatus(ID_STATUS_OFFLINE);
}
}
}
-void CToxProto::DoTox()
+void DoTox(ToxThreadData *toxThread)
{
{
- mir_cslock lock(toxLock);
- tox_iterate(tox);
- if (toxAv)
- toxav_do(toxAv);
+ mir_cslock lock(toxThread->toxLock);
+ tox_iterate(toxThread->tox);
+ if (toxThread->toxAv)
+ toxav_do(toxThread->toxAv);
}
- uint32_t interval = tox_iteration_interval(tox);
+ uint32_t interval = tox_iteration_interval(toxThread->tox);
Sleep(interval);
}
void CToxProto::PollingThread(void*)
{
+ ToxThreadData toxThread;
+ this->toxThread = &toxThread;
+
debugLogA(__FUNCTION__": entering");
- if (!InitToxCore())
+ if (!InitToxCore(&toxThread))
{
SetStatus(ID_STATUS_OFFLINE);
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, (HANDLE)NULL, LOGINERR_WRONGPASSWORD);
@@ -166,17 +169,17 @@ void CToxProto::PollingThread(void*)
}
int retriesCount = TOX_MAX_DISCONNECT_RETRIES;
- isConnected = false;
+ toxThread.isConnected = false;
BootstrapNodes();
- while (!isTerminated)
+ while (!toxThread.isTerminated)
{
CheckConnection(retriesCount);
- DoTox();
+ DoTox(&toxThread);
}
- UninitToxCore();
- isConnected = false;
+ UninitToxCore(&toxThread);
+ toxThread.isConnected = false;
debugLogA(__FUNCTION__": leaving");
} \ No newline at end of file
diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp
index 87b9df8ce3..ddebf72d92 100644
--- a/protocols/Tox/src/tox_options.cpp
+++ b/protocols/Tox/src/tox_options.cpp
@@ -62,6 +62,8 @@ void CToxOptionsMain::ToxAddressCopy_OnClick(CCtrlButton*)
void CToxOptionsMain::ProfileCreate_OnClick(CCtrlButton*)
{
+ ToxThreadData toxThread;
+
std::tstring profilePath = m_proto->GetToxProfilePath();
if (!m_proto->IsFileExists(profilePath))
{
@@ -74,7 +76,7 @@ void CToxOptionsMain::ProfileCreate_OnClick(CCtrlButton*)
CloseHandle(hProfile);
TOX_ERR_NEW initError;
- m_proto->tox = tox_new(NULL, &initError);
+ toxThread.tox = tox_new(NULL, &initError);
if (initError != TOX_ERR_NEW_OK)
{
m_proto->debugLogA(__FUNCTION__": failed to load tox profile (%d)", initError);
@@ -82,14 +84,14 @@ void CToxOptionsMain::ProfileCreate_OnClick(CCtrlButton*)
}
}
- if (m_proto->InitToxCore())
+ if (m_proto->InitToxCore(&toxThread))
{
TCHAR *group = m_group.GetText();
if (mir_tstrlen(group) > 0 && Clist_GroupExists(group))
Clist_CreateGroup(0, group);
m_proto->LoadFriendList(NULL);
- m_proto->UninitToxCore();
+ m_proto->UninitToxCore(&toxThread);
m_toxAddress.Enable();
m_toxAddress.SetTextA(ptrA(m_proto->getStringA(TOX_SETTINGS_ID)));
@@ -175,9 +177,8 @@ void CToxOptionsMain::OnApply()
{
CallProtoService(m_proto->m_szModuleName, PS_SETMYNICKNAME, SMNN_TCHAR, (LPARAM)ptrT(m_nickname.GetText()));
- if (m_proto->password != NULL)
- mir_free(m_proto->password);
- m_proto->password = mir_utf8encodeW(ptrT(m_password.GetText()));
+ // todo: add checkbox
+ m_proto->setTString("Password", pass_ptrT(m_password.GetText()));
m_proto->SaveToxProfile();
}
diff --git a/protocols/Tox/src/tox_profile.cpp b/protocols/Tox/src/tox_profile.cpp
index d6fff1c75d..82754c5d6c 100644
--- a/protocols/Tox/src/tox_profile.cpp
+++ b/protocols/Tox/src/tox_profile.cpp
@@ -59,7 +59,7 @@ bool CToxProto::LoadToxProfile(Tox_Options *options)
if (data && tox_is_data_encrypted(data))
{
- password = mir_utf8encodeW(ptrT(getTStringA("Password")));
+ pass_ptrA password(mir_utf8encodeW(pass_ptrT(getTStringA("Password"))));
if (password == NULL || mir_strlen(password) == 0)
{
CToxPasswordEditor passwordEditor(this);
@@ -71,7 +71,7 @@ bool CToxProto::LoadToxProfile(Tox_Options *options)
}
uint8_t *encryptedData = (uint8_t*)mir_calloc(size - TOX_PASS_ENCRYPTION_EXTRA_LENGTH);
TOX_ERR_DECRYPTION coreDecryptError;
- if (!tox_pass_decrypt(data, size, (uint8_t*)password, mir_strlen(password), encryptedData, &coreDecryptError))
+ if (!tox_pass_decrypt(data, size, (uint8_t*)(char*)password, mir_strlen(password), encryptedData, &coreDecryptError))
{
ShowNotification(TranslateT("Unable to decrypt Tox profile"), MB_ICONERROR);
debugLogA(__FUNCTION__": failed to decrypt tox profile (%d)", coreDecryptError);
@@ -98,15 +98,18 @@ void CToxProto::SaveToxProfile()
{
mir_cslock locker(profileLock);
- size_t size = tox_get_savedata_size(tox);
+ if (!toxThread)
+ return;
+
+ 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(tox, data);
+ tox_get_savedata(toxThread->tox, data);
- size_t passwordLen = mir_strlen(password);
- if (password && passwordLen)
+ pass_ptrA password(mir_utf8encodeW(pass_ptrT(getTStringA("Password"))));
+ if (password && mir_strlen(password))
{
TOX_ERR_ENCRYPTION coreEncryptError;
- if (!tox_pass_encrypt(data, size, (uint8_t*)password, passwordLen, data, &coreEncryptError))
+ if (!tox_pass_encrypt(data, size, (uint8_t*)(char*)password, mir_strlen(password), data, &coreEncryptError))
{
debugLogA(__FUNCTION__": failed to encrypt tox profile");
mir_free(data);
@@ -159,12 +162,9 @@ CToxPasswordEditor::CToxPasswordEditor(CToxProto *proto) :
void CToxPasswordEditor::OnOk(CCtrlButton*)
{
- ptrT tszPassword(password.GetText());
+ pass_ptrT tszPassword(password.GetText());
if (savePermanently.Enabled())
m_proto->setTString("Password", tszPassword);
- if (m_proto->password != NULL)
- mir_free(m_proto->password);
- m_proto->password = mir_utf8encodeW(tszPassword);
EndDialog(m_hwnd, 1);
}
diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp
index 1718f9f0bc..d2f9b943de 100644
--- a/protocols/Tox/src/tox_proto.cpp
+++ b/protocols/Tox/src/tox_proto.cpp
@@ -2,8 +2,6 @@
CToxProto::CToxProto(const char* protoName, const TCHAR* userName)
: PROTO<CToxProto>(protoName, userName),
- tox(NULL), toxAv(NULL), password(NULL),
- isTerminated(false), isConnected(false),
hPollingThread(NULL), hOutDevice(NULL)
{
InitNetlib();
@@ -173,9 +171,9 @@ int CToxProto::SetStatus(int iNewStatus)
if (iNewStatus == ID_STATUS_OFFLINE)
{
// logout
- isTerminated = true;
- WaitForSingleObject(hPollingThread, INFINITE);
- hPollingThread = NULL;
+ if (toxThread)
+ toxThread->isTerminated = true;
+ toxThread = NULL;
if (!Miranda_Terminated())
{
@@ -194,23 +192,16 @@ int CToxProto::SetStatus(int iNewStatus)
if (old_status == ID_STATUS_OFFLINE && !IsOnline())
{
- if (hPollingThread != NULL)
- {
- m_iDesiredStatus = old_status;
- return 0;
- }
-
// login
m_iStatus = ID_STATUS_CONNECTING;
- isTerminated = false;
hPollingThread = ForkThreadEx(&CToxProto::PollingThread, 0, NULL);
}
else
{
// set tox status
m_iStatus = iNewStatus;
- tox_self_set_status(tox, MirandaToToxStatus(iNewStatus));
+ tox_self_set_status(toxThread->tox, MirandaToToxStatus(iNewStatus));
}
}
@@ -235,7 +226,7 @@ int CToxProto::SetAwayMsg(int, const TCHAR *msg)
{
T2Utf statusMessage(msg);
TOX_ERR_SET_INFO error;
- if (tox_self_set_status_message(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))
debugLogA("CToxProto::SetAwayMsg: failed to set status status message %s (%d)", msg, error);
}
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h
index cb33550aa0..9b8b2e171c 100644
--- a/protocols/Tox/src/tox_proto.h
+++ b/protocols/Tox/src/tox_proto.h
@@ -1,6 +1,19 @@
#ifndef _TOX_PROTO_H_
#define _TOX_PROTO_H_
+struct ToxThreadData
+{
+ Tox *tox;
+ ToxAv *toxAv;
+ bool isConnected;
+ bool isTerminated;
+
+ mir_cs toxLock;
+
+ ToxThreadData() : tox(NULL), toxAv(NULL),
+ isConnected(false), isTerminated(false) { }
+};
+
struct CToxProto : public PROTO<CToxProto>
{
friend CToxPasswordEditor;
@@ -69,14 +82,10 @@ public:
static int OnModulesLoaded(WPARAM, LPARAM);
private:
- Tox *tox;
- ToxAv *toxAv;
- char *password;
- mir_cs toxLock;
+ ToxThreadData *toxThread;
mir_cs profileLock;
TCHAR *accountName;
HANDLE hNetlib, hPollingThread;
- bool isTerminated, isConnected;
CTransferList transfers;
static HANDLE hProfileFolderPath;
@@ -91,8 +100,9 @@ private:
INT_PTR __cdecl OnCopyToxID(WPARAM, LPARAM);
// tox core
- bool InitToxCore();
- void UninitToxCore();
+ Tox_Options* GetToxOptions();
+ bool InitToxCore(ToxThreadData *toxThread);
+ void UninitToxCore(ToxThreadData *toxThread);
// tox network
bool IsOnline();
@@ -103,7 +113,6 @@ private:
void BootstrapNodes();
void TryConnect();
void CheckConnection(int &retriesCount);
- void DoTox();
void __cdecl PollingThread(void*);
@@ -224,7 +233,6 @@ private:
int __cdecl OnPreCreateMessage(WPARAM wParam, LPARAM lParam);
// 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);
diff --git a/protocols/Tox/src/tox_services.cpp b/protocols/Tox/src/tox_services.cpp
index c9fc238f34..2a2c188e59 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(tox, szNick8, mir_strlen(szNick8), &error))
+ if (!tox_self_set_name(toxThread->tox, szNick8, mir_strlen(szNick8), &error))
debugLogA(__FUNCTION__": failed to set nick name");
}
diff --git a/protocols/Tox/src/tox_transfer.cpp b/protocols/Tox/src/tox_transfer.cpp
index da28e1f120..cef5c4bec9 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->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->debugLogA(__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(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))
{
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);
+ tox_file_control(toxThread->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) from (%d)", transfer->fileNumber, transfer->friendNumber);
- if (!tox_file_control(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))
{
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);
+ 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->debugLogA(__FUNCTION__": cannot find contact by number (%d)", friendNumber);
- tox_file_control(proto->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->debugLogA(__FUNCTION__": failed write to file (%d)", fileNumber);
proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)transfer, 0);
- tox_file_control(proto->tox, friendNumber, fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
+ tox_file_control(proto->toxThread->tox, friendNumber, fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
return;
}
@@ -218,7 +218,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(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)
{
debugLogA(__FUNCTION__": failed to send file (%d) to (%d) cause (%d)", fileNumber, friendNumber, sendError);
@@ -271,13 +271,13 @@ void CToxProto::OnFileSendData(Tox*, uint32_t friendNumber, uint32_t 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);
+ 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->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)
{
@@ -286,7 +286,7 @@ void CToxProto::OnFileSendData(Tox*, uint32_t friendNumber, uint32_t fileNumber,
}
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);
+ tox_file_control(proto->toxThread->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
mir_free(data);
return;
}
@@ -304,7 +304,7 @@ 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);
+ tox_file_control(toxThread->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
transfers.Remove(transfer);
return 0;
@@ -320,10 +320,10 @@ void CToxProto::PauseOutgoingTransfers(uint32_t friendNumber)
{
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))
+ if (!tox_file_control(toxThread->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);
+ tox_file_control(toxThread->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
}
}
}
@@ -339,10 +339,10 @@ void CToxProto::ResumeIncomingTransfers(uint32_t friendNumber)
{
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))
+ if (!tox_file_control(toxThread->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);
+ tox_file_control(toxThread->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
}
}
}
diff --git a/protocols/Tox/src/version.h b/protocols/Tox/src/version.h
index 212005609f..27d4ec0000 100644
--- a/protocols/Tox/src/version.h
+++ b/protocols/Tox/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 11
#define __RELEASE_NUM 1
-#define __BUILD_NUM 13
+#define __BUILD_NUM 14
#include <stdver.h>