diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2016-05-04 16:22:54 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2016-05-04 16:22:54 +0000 |
commit | 8e09c4d75e26ed3fc165cd35fd1fc79614b1420e (patch) | |
tree | 5991c15526aa4fbe13d12d956cc039e8e3edaf9a | |
parent | 0a43d6b600e48abd24097a4dc8d82f4dc7f0a188 (diff) |
Tox:
- removed own logger
- bootstrap splitted into two functions: udp and tcp
git-svn-id: http://svn.miranda-ng.org/main/trunk@16801 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/Tox/src/stdafx.h | 1 | ||||
-rw-r--r-- | protocols/Tox/src/tox_avatars.cpp | 22 | ||||
-rw-r--r-- | protocols/Tox/src/tox_chatrooms.cpp | 8 | ||||
-rw-r--r-- | protocols/Tox/src/tox_contacts.cpp | 25 | ||||
-rw-r--r-- | protocols/Tox/src/tox_core.cpp | 14 | ||||
-rw-r--r-- | protocols/Tox/src/tox_logger.h | 28 | ||||
-rw-r--r-- | protocols/Tox/src/tox_messages.cpp | 8 | ||||
-rw-r--r-- | protocols/Tox/src/tox_multimedia.cpp | 50 | ||||
-rw-r--r-- | protocols/Tox/src/tox_netlib.cpp | 10 | ||||
-rw-r--r-- | protocols/Tox/src/tox_network.cpp | 149 | ||||
-rw-r--r-- | protocols/Tox/src/tox_options.cpp | 4 | ||||
-rw-r--r-- | protocols/Tox/src/tox_profile.cpp | 14 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.cpp | 4 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.h | 7 | ||||
-rw-r--r-- | protocols/Tox/src/tox_services.cpp | 2 | ||||
-rw-r--r-- | protocols/Tox/src/tox_transfer.cpp | 52 |
16 files changed, 206 insertions, 192 deletions
diff --git a/protocols/Tox/src/stdafx.h b/protocols/Tox/src/stdafx.h index 12dfcc7845..a2de2a5528 100644 --- a/protocols/Tox/src/stdafx.h +++ b/protocols/Tox/src/stdafx.h @@ -54,7 +54,6 @@ struct CToxProto; #include "version.h"
#include "resource.h"
#include "tox_menus.h"
-#include "tox_logger.h"
#include "tox_thread.h"
#include "tox_address.h"
#include "tox_dialogs.h"
diff --git a/protocols/Tox/src/tox_avatars.cpp b/protocols/Tox/src/tox_avatars.cpp index 9b1e4a36dd..dad9aad980 100644 --- a/protocols/Tox/src/tox_avatars.cpp +++ b/protocols/Tox/src/tox_avatars.cpp @@ -27,17 +27,17 @@ void CToxProto::SetToxAvatar(const TCHAR* path) FILE *hFile = _tfopen(path, L"rb");
if (!hFile)
{
- logger->Log(__FUNCTION__": failed to open avatar file");
+ debugLogA(__FUNCTION__": failed to open avatar file");
return;
}
fseek(hFile, 0, SEEK_END);
- long length = ftell(hFile);
+ size_t length = ftell(hFile);
rewind(hFile);
if (length > TOX_MAX_AVATAR_SIZE)
{
fclose(hFile);
- logger->Log(__FUNCTION__": new avatar size is excessive");
+ debugLogA(__FUNCTION__": new avatar size is excessive");
return;
}
@@ -45,7 +45,7 @@ void CToxProto::SetToxAvatar(const TCHAR* path) if (fread(data, sizeof(uint8_t), length, hFile) != length)
{
fclose(hFile);
- logger->Log(__FUNCTION__": failed to read avatar file");
+ debugLogA(__FUNCTION__": failed to read avatar file");
mir_free(data);
return;
}
@@ -60,7 +60,7 @@ void CToxProto::SetToxAvatar(const TCHAR* path) {
db_free(&dbv);
mir_free(data);
- logger->Log(__FUNCTION__": new avatar is same with old");
+ debugLogA(__FUNCTION__": new avatar is same with old");
return;
}
db_free(&dbv);
@@ -79,7 +79,7 @@ void CToxProto::SetToxAvatar(const TCHAR* path) if (friendNumber == UINT32_MAX)
{
mir_free(data);
- logger->Log(__FUNCTION__": failed to set new avatar");
+ debugLogA(__FUNCTION__": failed to set new avatar");
return;
}
@@ -88,7 +88,7 @@ void CToxProto::SetToxAvatar(const TCHAR* path) if (error != TOX_ERR_FILE_SEND_OK)
{
mir_free(data);
- logger->Log(__FUNCTION__": failed to set new avatar");
+ debugLogA(__FUNCTION__": failed to set new avatar");
return;
}
@@ -157,15 +157,15 @@ INT_PTR CToxProto::GetMyAvatar(WPARAM wParam, LPARAM lParam) INT_PTR CToxProto::SetMyAvatar(WPARAM, LPARAM lParam)
{
- logger->Log("CToxProto::SetMyAvatar: setting avatar");
+ debugLogA(__FUNCTION__": setting avatar");
TCHAR *path = (TCHAR*)lParam;
ptrT avatarPath(GetAvatarFilePath());
if (path != NULL)
{
- logger->Log("CToxProto::SetMyAvatar: copy new avatar");
+ debugLogA(__FUNCTION__": copy new avatar");
if (!CopyFile(path, avatarPath, FALSE))
{
- logger->Log("CToxProto::SetMyAvatar: failed to copy new avatar to avatar cache");
+ debugLogA(__FUNCTION__": failed to copy new avatar to avatar cache");
return 0;
}
@@ -189,7 +189,7 @@ INT_PTR CToxProto::SetMyAvatar(WPARAM, LPARAM lParam) 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);
+ debugLogA(__FUNCTION__": failed to unset avatar (%d)", error);
return 0;
}
}
diff --git a/protocols/Tox/src/tox_chatrooms.cpp b/protocols/Tox/src/tox_chatrooms.cpp index d5a6dd4ebc..aba34e46b6 100644 --- a/protocols/Tox/src/tox_chatrooms.cpp +++ b/protocols/Tox/src/tox_chatrooms.cpp @@ -49,7 +49,7 @@ void CToxProto::LoadChatRoomList(void*) uint32_t count = tox_count_chatlist(toxThread->Tox());
if (count == 0)
{
- logger->Log("CToxProto::LoadGroupChatList: your group chat list is empty");
+ debugLogA(__FUNCTION__": your group chat list is empty");
return;
}
int32_t *groupChats = (int32_t*)mir_alloc(count * sizeof(int32_t));
@@ -175,21 +175,21 @@ void CToxProto::OnGroupChatInvite(Tox *tox, int32_t friendNumber, uint8_t type, if (type == TOX_GROUPCHAT_TYPE_AV)
{
- proto->logger->Log("CToxProto::OnGroupChatInvite: audio chat is not supported yet");
+ Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": audio chat is not supported yet");
return;
}
int groupNumber = tox_join_groupchat(tox, friendNumber, data, length);
if (groupNumber == TOX_ERROR)
{
- proto->logger->Log("CToxProto::OnFriendRequest: failed to join to group chat");
+ Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": failed to join to group chat");
return;
}
MCONTACT hContact = proto->AddChatRoom(groupNumber);
if (!hContact)
{
- proto->logger->Log("CToxProto::OnFriendRequest: failed to create group chat");
+ Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": failed to create group chat");
}
}
diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp index 22901b5a6e..fc1727aaac 100644 --- a/protocols/Tox/src/tox_contacts.cpp +++ b/protocols/Tox/src/tox_contacts.cpp @@ -43,7 +43,7 @@ MCONTACT CToxProto::GetContact(const int friendNumber) TOX_ERR_FRIEND_GET_PUBLIC_KEY error;
if (!tox_friend_get_public_key(toxThread->Tox(), friendNumber, data, &error))
{
- logger->Log(__FUNCTION__": failed to get friend (%d) public key (%d)", friendNumber, error);
+ debugLogA(__FUNCTION__": failed to get friend (%d) public key (%d)", friendNumber, error);
return NULL;
}
ToxHexAddress pubKey(data, TOX_PUBLIC_KEY_SIZE);
@@ -69,7 +69,7 @@ ToxHexAddress CToxProto::GetContactPublicKey(const int friendNumber) TOX_ERR_FRIEND_GET_PUBLIC_KEY error;
if (!tox_friend_get_public_key(toxThread->Tox(), friendNumber, data, &error))
{
- logger->Log(__FUNCTION__": failed to get friend (%d) public key (%d)", friendNumber, error);
+ debugLogA(__FUNCTION__": failed to get friend (%d) public key (%d)", friendNumber, error);
return ToxHexAddress::Empty();
}
ToxHexAddress pubKey(data, TOX_PUBLIC_KEY_SIZE);
@@ -114,7 +114,7 @@ uint32_t CToxProto::GetToxFriendNumber(MCONTACT hContact) TOX_ERR_FRIEND_BY_PUBLIC_KEY 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);
+ debugLogA(__FUNCTION__": failed to get friend number (%d)", error);
return friendNumber;
}
@@ -126,7 +126,6 @@ void CToxProto::LoadFriendList(void*) uint32_t *friends = (uint32_t*)mir_alloc(count * sizeof(uint32_t));
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];
@@ -146,14 +145,14 @@ void CToxProto::LoadFriendList(void*) 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);
+ debugLogA(__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);
if (getLastOnlineResult == TOX_ERR_FRIEND_GET_LAST_ONLINE_OK)
setDword(hContact, "LastEventDateTS", timestamp);
else
- logger->Log(__FUNCTION__": failed to get friend last online (%d)", getLastOnlineResult);
+ debugLogA(__FUNCTION__": failed to get friend last online (%d)", getLastOnlineResult);
}
}
mir_free(friends);
@@ -173,7 +172,7 @@ INT_PTR CToxProto::OnRequestAuth(WPARAM hContact, LPARAM lParam) 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);
+ debugLogA(__FUNCTION__": failed to request auth(%d)", addFriendResult);
return addFriendResult;
}
@@ -185,7 +184,7 @@ INT_PTR CToxProto::OnRequestAuth(WPARAM hContact, LPARAM lParam) 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);
+ debugLogA(__FUNCTION__": failed to get friend name (%d)", errorFriendQuery);
return 0;
}
@@ -200,7 +199,7 @@ INT_PTR CToxProto::OnGrantAuth(WPARAM hContact, LPARAM) tox_friend_add_norequest(toxThread->Tox(), pubKey, &error);
if (error != TOX_ERR_FRIEND_ADD_OK)
{
- logger->Log(__FUNCTION__": failed to grant auth (%d)", error);
+ debugLogA(__FUNCTION__": failed to grant auth (%d)", error);
return error;
}
@@ -223,7 +222,7 @@ int CToxProto::OnContactDeleted(MCONTACT hContact, LPARAM) TOX_ERR_FRIEND_DELETE error;
if (!tox_friend_delete(toxThread->Tox(), friendNumber, &error))
{
- logger->Log(__FUNCTION__": failed to delete friend (%d)", error);
+ debugLogA(__FUNCTION__": failed to delete friend (%d)", error);
return error;
}
SaveToxProfile(toxThread);
@@ -249,7 +248,7 @@ void CToxProto::OnFriendRequest(Tox*, const uint8_t *pubKey, const uint8_t *mess MCONTACT hContact = proto->AddContact(address);
if (!hContact)
{
- proto->logger->Log(__FUNCTION__": failed to create contact");
+ Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": failed to create contact");
return;
}
@@ -340,7 +339,7 @@ void CToxProto::OnConnectionStatusChanged(Tox*, uint32_t friendNumber, TOX_CONNE FILE *hFile = _tfopen(avatarPath, L"rb");
if (!hFile)
{
- proto->logger->Log(__FUNCTION__": failed to open avatar file");
+ Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": failed to open avatar file");
return;
}
@@ -360,7 +359,7 @@ void CToxProto::OnConnectionStatusChanged(Tox*, uint32_t friendNumber, TOX_CONNE 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");
+ Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": failed to set new avatar");
fclose(hFile);
return;
}
diff --git a/protocols/Tox/src/tox_core.cpp b/protocols/Tox/src/tox_core.cpp index 9910f8cc1f..4f338db5cc 100644 --- a/protocols/Tox/src/tox_core.cpp +++ b/protocols/Tox/src/tox_core.cpp @@ -6,23 +6,23 @@ Tox_Options* CToxProto::GetToxOptions() Tox_Options *options = tox_options_new(&error);
if (error != TOX_ERR_OPTIONS_NEW_OK)
{
- logger->Log(__FUNCTION__": failed to initialize tox options (%d)", error);
+ debugLogA(__FUNCTION__": failed to initialize tox options (%d)", error);
return NULL;
}
options->udp_enabled = getBool("EnableUDP", 1);
options->ipv6_enabled = getBool("EnableIPv6", 0);
- if (hNetlib != NULL)
+ if (m_hNetlibUser != NULL)
{
NETLIBUSERSETTINGS nlus = { sizeof(NETLIBUSERSETTINGS) };
- CallService(MS_NETLIB_GETUSERSETTINGS, (WPARAM)hNetlib, (LPARAM)&nlus);
+ CallService(MS_NETLIB_GETUSERSETTINGS, (WPARAM)m_hNetlibUser, (LPARAM)&nlus);
if (nlus.useProxy)
{
if (nlus.proxyType == PROXYTYPE_HTTP || nlus.proxyType == PROXYTYPE_HTTPS)
{
- logger->Log("CToxProto::InitToxCore: setting http user proxy config");
+ debugLogA(__FUNCTION__": setting http user proxy config");
options->proxy_type = TOX_PROXY_TYPE_HTTP;
mir_strcpy((char*)&options->proxy_host[0], nlus.szProxyServer);
options->proxy_port = nlus.wProxyPort;
@@ -30,7 +30,7 @@ Tox_Options* CToxProto::GetToxOptions() if (nlus.proxyType == PROXYTYPE_SOCKS4 || nlus.proxyType == PROXYTYPE_SOCKS5)
{
- logger->Log(__FUNCTION__": setting socks user proxy config");
+ debugLogA(__FUNCTION__": setting socks user proxy config");
options->proxy_type = TOX_PROXY_TYPE_SOCKS5;
mir_strcpy((char*)&options->proxy_host[0], nlus.szProxyServer);
options->proxy_port = nlus.wProxyPort;
@@ -50,7 +50,7 @@ Tox_Options* CToxProto::GetToxOptions() bool CToxProto::InitToxCore(CToxThread *toxThread)
{
- logger->Log(__FUNCTION__": initializing tox core");
+ debugLogA(__FUNCTION__": initializing tox core");
if (toxThread == NULL)
return false;
@@ -65,7 +65,7 @@ bool CToxProto::InitToxCore(CToxThread *toxThread) toxThread->Tox() = tox_new(options, &initError);
if (initError != TOX_ERR_NEW_OK)
{
- logger->Log(__FUNCTION__": failed to initialize tox core (%d)", initError);
+ 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;
diff --git a/protocols/Tox/src/tox_logger.h b/protocols/Tox/src/tox_logger.h deleted file mode 100644 index b460f87de7..0000000000 --- a/protocols/Tox/src/tox_logger.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _TOX_LOGGER_H_
-#define _TOX_LOGGER_H_
-
-class CLogger
-{
-private:
- HANDLE hNetlibUser;
-
-public:
- CLogger(HANDLE hNetlibUser) : hNetlibUser(hNetlibUser) {}
-
- __inline void Log(LPCSTR szFormat, ...) const
- {
- va_list args;
- va_start(args, szFormat);
- CallService(MS_NETLIB_LOG, (WPARAM)hNetlibUser, (LPARAM)(CMStringA().FormatV(szFormat, args)));
- va_end(args);
- }
- __inline void Log(LPCWSTR wszFormat, ...) const
- {
- va_list args;
- va_start(args, wszFormat);
- CallService(MS_NETLIB_LOGW, (WPARAM)hNetlibUser, (LPARAM)(CMStringW().FormatV(wszFormat, args)));
- va_end(args);
- }
-};
-
-#endif //_TOX_LOGGER_H_
\ No newline at end of file diff --git a/protocols/Tox/src/tox_messages.cpp b/protocols/Tox/src/tox_messages.cpp index 0fb393e5da..a44c1084de 100644 --- a/protocols/Tox/src/tox_messages.cpp +++ b/protocols/Tox/src/tox_messages.cpp @@ -61,7 +61,7 @@ void CToxProto::SendMessageAsync(void *arg) 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);
+ debugLogA(__FUNCTION__": failed to send message for %d (%d)", friendNumber, sendError);
ProtoBroadcastAck(param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)param->hMessage, (LPARAM)_T2A(ToxErrorToString(sendError)));
}
uint64_t messageId = (((int64_t)friendNumber) << 32) | ((int64_t)messageNumber);
@@ -142,7 +142,7 @@ void CToxProto::GetStatusMessageAsync(void* arg) 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);
+ debugLogA(__FUNCTION__": failed to get status message for (%d) (%d)", friendNumber, error);
ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_FAILED, (HANDLE)hContact, 0);
return;
}
@@ -150,7 +150,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))
{
- logger->Log(__FUNCTION__": failed to get status message for (%d) (%d)", friendNumber, error);
+ debugLogA(__FUNCTION__": failed to get status message for (%d) (%d)", friendNumber, error);
ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_FAILED, (HANDLE)hContact, 0);
return;
}
@@ -168,7 +168,7 @@ int CToxProto::OnUserIsTyping(MCONTACT hContact, int type) TOX_ERR_SET_TYPING error;
if (!tox_self_set_typing(toxThread->Tox(), friendNumber, type == PROTOTYPE_SELFTYPING_ON, &error))
- logger->Log(__FUNCTION__": failed to send typing (%d)", 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 6fc188fed8..8bc9fd8dd3 100644 --- a/protocols/Tox/src/tox_multimedia.cpp +++ b/protocols/Tox/src/tox_multimedia.cpp @@ -85,7 +85,7 @@ void CToxIncomingCall::OnAnswer(CCtrlBase*) TOXAV_ERR_ANSWER error;
if (!toxav_answer(m_proto->toxThread->ToxAV(), friendNumber, 0, 0, &error))
{
- m_proto->logger->Log(__FUNCTION__": failed to answer the call (%d)", error);
+ m_proto->debugLogA(__FUNCTION__": failed to answer the call (%d)", error);
Close();
}
}
@@ -142,7 +142,7 @@ void CToxOutgoingCall::OnCall(CCtrlBase*) 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);
+ m_proto->debugLogA(__FUNCTION__": failed to make a call (%d)", error);
return;
}
//mir_free(cSettings);
@@ -215,7 +215,7 @@ void CToxCallDialog::OnClose() MMRESULT error = waveInGetDevCaps(deviceId, &wic, sizeof(WAVEINCAPS));
if (error != MMSYSERR_NOERROR)
{
- logger->Log(__FUNCTION__": failed to get input device caps (%d)", error);
+ debugLogA(__FUNCTION__": failed to get input device caps (%d)", error);
TCHAR errorMessage[MAX_PATH];
waveInGetErrorText(error, errorMessage, _countof(errorMessage));
@@ -270,7 +270,7 @@ void CToxCallDialog::OnClose() }
else
{
- logger->Log(__FUNCTION__": failed to parse input device caps");
+ debugLogA(__FUNCTION__": failed to parse input device caps");
mir_free(cSettings);
return NULL;
}
@@ -288,7 +288,7 @@ void CToxProto::OnFriendCall(ToxAV *toxAV, uint32_t friend_number, bool audio_en 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");
+ proto->debugLogA(__FUNCTION__": failed to get friend number");
toxav_reject(proto->toxThread->Tox()AV, callId, NULL);
return;
}
@@ -296,7 +296,7 @@ void CToxProto::OnFriendCall(ToxAV *toxAV, uint32_t friend_number, bool audio_en MCONTACT hContact = proto->GetContact(friendNumber);
if (hContact == NULL)
{
- proto->logger->Log(__FUNCTION__": failed to find contact");
+ proto->debugLogA(__FUNCTION__": failed to find contact");
toxav_reject(proto->toxThread->Tox()AV, callId, NULL);
return;
}
@@ -304,14 +304,14 @@ void CToxProto::OnFriendCall(ToxAV *toxAV, uint32_t friend_number, bool audio_en ToxAvCSettings cSettings;
if (toxav_get_peer_csettings(proto->toxThread->Tox()AV, callId, 0, &cSettings) != av_ErrorNone)
{
- proto->logger->Log(__FUNCTION__": failed to get codec settings");
+ proto->debugLogA(__FUNCTION__": failed to get codec settings");
toxav_reject(proto->toxThread->Tox()AV, callId, NULL);
return;
}
if (cSettings.call_type != av_TypeAudio)
{
- proto->logger->Log(__FUNCTION__": video call is unsupported");
+ proto->debugLogA(__FUNCTION__": video call is unsupported");
toxav_reject(proto->toxThread->Tox()AV, callId, Translate("Video call is unsupported"));
return;
}
@@ -380,14 +380,14 @@ INT_PTR CToxProto::OnAudioRing(WPARAM, LPARAM lParam) 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");
+ proto->debugLogA(__FUNCTION__": failed to get friend number");
return;
}
MCONTACT hContact = proto->GetContact(friendNumber);
if (hContact == NULL)
{
- proto->logger->Log(__FUNCTION__": failed to find contact");
+ proto->debugLogA(__FUNCTION__": failed to find contact");
return;
}
@@ -425,14 +425,14 @@ INT_PTR CToxProto::OnSendAudioCall(WPARAM hContact, LPARAM) 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");
+ proto->debugLogA(__FUNCTION__": failed to get friend number");
return;
}
MCONTACT hContact = proto->GetContact(friendNumber);
if (hContact == NULL)
{
- proto->logger->Log(__FUNCTION__": failed to find contact");
+ proto->debugLogA(__FUNCTION__": failed to find contact");
return;
}
@@ -449,14 +449,14 @@ void CToxProto::OnAvCallTimeout(void*, int32_t callId, void *arg) 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");
+ proto->debugLogA(__FUNCTION__": failed to get friend number");
return;
}
MCONTACT hContact = proto->GetContact(friendNumber);
if (hContact == NULL)
{
- proto->logger->Log(__FUNCTION__": failed to find contact");
+ proto->debugLogA(__FUNCTION__": failed to find contact");
return;
}
@@ -494,14 +494,14 @@ static void CALLBACK ToxShowDialogApcProc(void *arg) 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);
+ proto->debugLogA(__FUNCTION__": failed to get codec settings (%d)", cSettingsError);
toxav_hangup(proto->toxThread->Tox()AV, callId);
return;
}
if (cSettings.call_type != av_TypeAudio)
{
- proto->logger->Log(__FUNCTION__": video call is unsupported");
+ proto->debugLogA(__FUNCTION__": video call is unsupported");
toxav_hangup(proto->toxThread->Tox()AV, callId);
return;
}
@@ -518,7 +518,7 @@ static void CALLBACK ToxShowDialogApcProc(void *arg) MMRESULT error = waveOutOpen(&proto->hOutDevice, deviceId, &wfx, (DWORD_PTR)WaveOutCallback, (DWORD_PTR)proto, CALLBACK_FUNCTION);
if (error != MMSYSERR_NOERROR)
{
- proto->logger->Log(__FUNCTION__": failed to open audio device (%d)", error);
+ proto->debugLogA(__FUNCTION__": failed to open audio device (%d)", error);
toxav_hangup(proto->toxThread->Tox()AV, callId);
TCHAR errorMessage[MAX_PATH];
@@ -533,7 +533,7 @@ static void CALLBACK ToxShowDialogApcProc(void *arg) 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");
+ proto->debugLogA(__FUNCTION__": failed to get friend number");
toxav_hangup(proto->toxThread->Tox()AV, callId);
return;
}
@@ -541,14 +541,14 @@ static void CALLBACK ToxShowDialogApcProc(void *arg) MCONTACT hContact = proto->GetContact(friendNumber);
if (hContact == NULL)
{
- proto->logger->Log(__FUNCTION__": failed to find contact");
+ proto->debugLogA(__FUNCTION__": failed to find contact");
toxav_hangup(proto->toxThread->Tox()AV, callId);
return;
}
if (toxav_prepare_transmission(proto->toxThread->Tox()AV, callId, false) == TOX_ERROR)
{
- proto->logger->Log(__FUNCTION__": failed to prepare audio transmition");
+ proto->debugLogA(__FUNCTION__": failed to prepare audio transmition");
toxav_hangup(proto->toxThread->Tox()AV, callId);
return;
}
@@ -573,14 +573,14 @@ void CToxProto::OnAvEnd(void*, int32_t callId, void *arg) 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");
+ proto->debugLogA(__FUNCTION__": failed to get friend number");
return;
}
MCONTACT hContact = proto->GetContact(friendNumber);
if (hContact == NULL)
{
- proto->logger->Log(__FUNCTION__": failed to find contact");
+ proto->debugLogA(__FUNCTION__": failed to find contact");
return;
}
@@ -606,7 +606,7 @@ void CToxProto::OnAvPeerTimeout(void *av, int32_t callId, void *arg) return;
default:
- proto->logger->Log(__FUNCTION__": failed to handle callState");
+ proto->debugLogA(__FUNCTION__": failed to handle callState");
break;
}
}*/
@@ -625,14 +625,14 @@ void CToxProto::OnFriendAudioFrame(ToxAV *toxAV, uint32_t friend_number, const i MMRESULT error = waveOutPrepareHeader(proto->hOutDevice, header, sizeof(WAVEHDR));
if (error != MMSYSERR_NOERROR)
{
- proto->logger->Log(__FUNCTION__": failed to prepare audio buffer (%d)", error);
+ proto->debugLogA(__FUNCTION__": failed to prepare audio buffer (%d)", error);
return;
}
error = waveOutWrite(proto->hOutDevice, header, sizeof(WAVEHDR));
if (error != MMSYSERR_NOERROR)
{
- proto->logger->Log(__FUNCTION__": failed to play audio samples (%d)", error);
+ proto->debugLogA(__FUNCTION__": failed to play audio samples (%d)", error);
return;
}*/
}
\ No newline at end of file diff --git a/protocols/Tox/src/tox_netlib.cpp b/protocols/Tox/src/tox_netlib.cpp index 580a024360..c32e8059c8 100644 --- a/protocols/Tox/src/tox_netlib.cpp +++ b/protocols/Tox/src/tox_netlib.cpp @@ -10,15 +10,13 @@ void CToxProto::InitNetlib() nlu.flags = NUF_OUTGOING | NUF_INCOMING | NUF_HTTPCONNS | NUF_UNICODE;
nlu.ptszDescriptiveName = name;
nlu.szSettingsModule = m_szModuleName;
- hNetlib = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
+ m_hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
- logger = new CLogger(hNetlib);
-
- logger->Log("Setting protocol/module name to '%s'", m_szModuleName);
+ debugLogA(__FUNCTION__":Setting protocol / module name to '%s'", m_szModuleName);
}
void CToxProto::UninitNetlib()
{
- Netlib_CloseHandle(hNetlib);
- hNetlib = NULL;
+ Netlib_CloseHandle(m_hNetlibUser);
+ m_hNetlibUser = NULL;
}
diff --git a/protocols/Tox/src/tox_network.cpp b/protocols/Tox/src/tox_network.cpp index 1090b75e0c..a325102b9a 100644 --- a/protocols/Tox/src/tox_network.cpp +++ b/protocols/Tox/src/tox_network.cpp @@ -5,17 +5,32 @@ bool CToxProto::IsOnline() return toxThread && toxThread->IsConnected() && m_iStatus >= ID_STATUS_ONLINE;
}
-void CToxProto::BootstrapNode(const char *address, int port, const char *hexKey)
+void CToxProto::BootstrapUdpNode(const char *address, int port, const char *hexKey)
{
- if (hexKey == NULL || toxThread == NULL)
+ if (!toxThread)
+ return;
+
+ if (address == NULL || hexKey == NULL)
return;
ToxBinAddress binKey(hexKey, TOX_PUBLIC_KEY_SIZE * 2);
TOX_ERR_BOOTSTRAP 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);
+ debugLogA(__FUNCTION__ ": failed to bootstrap node %s:%d \"%s\" (%d)", address, port, hexKey, error);
+}
+
+void CToxProto::BootstrapTcpRelay(const char *address, int port, const char *hexKey)
+{
+ if (!toxThread)
+ return;
+
+ if (address == NULL || hexKey == NULL)
+ return;
+
+ ToxBinAddress binKey(hexKey, TOX_PUBLIC_KEY_SIZE * 2);
+ TOX_ERR_BOOTSTRAP 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);
+ debugLogA(__FUNCTION__ ": failed to add tcp relay %s:%d \"%s\" (%d)", address, port, hexKey, error);
}
void CToxProto::BootstrapNodesFromDb(bool isIPv6)
@@ -34,12 +49,14 @@ void CToxProto::BootstrapNodesFromDb(bool isIPv6) int port = db_get_w(NULL, module, setting, 33445);
mir_snprintf(setting, TOX_SETTINGS_NODE_PKEY, i);
ptrA pubKey(db_get_sa(NULL, module, setting));
- BootstrapNode(address, port, pubKey);
+ BootstrapUdpNode(address, port, pubKey);
+ BootstrapTcpRelay(address, port, pubKey);
if (isIPv6)
{
mir_snprintf(setting, TOX_SETTINGS_NODE_IPV6, i);
address = db_get_sa(NULL, module, setting);
- BootstrapNode(address, port, pubKey);
+ BootstrapUdpNode(address, port, pubKey);
+ BootstrapTcpRelay(address, port, pubKey);
}
}
}
@@ -79,13 +96,32 @@ void CToxProto::BootstrapNodesFromJson(bool isIPv6) JSONNode node = nodes[i];
JSONNode address = node.at("ipv4");
- int port = node.at("port").as_int();
JSONNode pubKey = node.at("public_key");
- BootstrapNode(address.as_string().c_str(), port, pubKey.as_string().c_str());
- if (isIPv6)
+
+ bool isUdp = getBool("EnableUDP", 1);
+ if (isUdp)
{
- address = node.at("ipv6");
- BootstrapNode(address.as_string().c_str(), port, pubKey.as_string().c_str());
+ int port = node.at("port").as_int();
+ BootstrapUdpNode(address.as_string().c_str(), port, pubKey.as_string().c_str());
+ if (isIPv6)
+ {
+ address = node.at("ipv6");
+ BootstrapUdpNode(address.as_string().c_str(), port, pubKey.as_string().c_str());
+ }
+ }
+ else
+ {
+ JSONNode tcpPorts = root.at("tcp_ports").as_array();
+ for (size_t i = 0; i < tcpPorts.size(); i++)
+ {
+ int port = tcpPorts[i].as_int();
+ BootstrapTcpRelay(address.as_string().c_str(), port, pubKey.as_string().c_str());
+ if (isIPv6)
+ {
+ address = node.at("ipv6");
+ BootstrapTcpRelay(address.as_string().c_str(), port, pubKey.as_string().c_str());
+ }
+ }
}
}
}
@@ -94,7 +130,7 @@ void CToxProto::BootstrapNodesFromJson(bool isIPv6) void CToxProto::BootstrapNodes()
{
- logger->Log(__FUNCTION__": bootstraping DHT");
+ debugLogA(__FUNCTION__": bootstraping DHT");
bool isIPv6 = getBool("EnableIPv6", 0);
BootstrapNodesFromDb(isIPv6);
BootstrapNodesFromJson(isIPv6);
@@ -102,55 +138,64 @@ void CToxProto::BootstrapNodes() void CToxProto::UpdateNodes()
{
- ptrT path(mir_tstrdup((TCHAR*)VARST(_T(TOX_JSON_PATH))));
+ HttpRequest request(REQUEST_GET, "https://nodes.tox.chat/json");
+ NLHR_PTR response(request.Send(m_hNetlibUser));
+ if (response->resultCode != HTTP_CODE_OK || !response->pData)
+ {
+ debugLogA(__FUNCTION__": failed to dowload tox.json");
+ return;
+ }
+
+ ptrT path(mir_tstrdup((TCHAR*)VARST(_T(TOX_JSON_PATH))));
if (!IsFileExists(path))
{
HANDLE hProfile = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
if (hProfile == NULL)
{
- logger->Log(__FUNCTION__": failed to create tox.json");
+ debugLogA(__FUNCTION__": failed to create tox.json");
return;
}
CloseHandle(hProfile);
}
- HttpRequest request(REQUEST_GET, "https://nodes.tox.chat/json");
- NLHR_PTR response(request.Send(hNetlib));
-
- if (response->resultCode == 200 && response->pData)
+ FILE *hFile = _tfopen(path, _T("w"));
+ if (!hFile)
{
- FILE *hFile = _tfopen(path, _T("w"));
- if (hFile)
- {
- fwrite(response->pData, sizeof(char), response->dataLength, hFile);
- fclose(hFile);
- }
+ debugLogA(__FUNCTION__": failed to open tox.json");
+ return;
}
+
+ if (fwrite(response->pData, sizeof(char), response->dataLength, hFile) != response->dataLength)
+ debugLogA(__FUNCTION__": failed to write tox.json");
+
+ fclose(hFile);
}
void CToxProto::TryConnect()
{
- if (toxThread != NULL)
+ if (!toxThread)
{
- if (tox_self_get_connection_status(toxThread->Tox()) != TOX_CONNECTION_NONE)
- {
- toxThread->Connect();
- logger->Log(__FUNCTION__": successfuly connected to DHT");
+ return;
+ }
- ForkThread(&CToxProto::LoadFriendList, NULL);
+ if (tox_self_get_connection_status(toxThread->Tox()) != TOX_CONNECTION_NONE)
+ {
+ toxThread->Connect();
+ debugLogA(__FUNCTION__": successfuly connected to DHT");
- 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));
- logger->Log(__FUNCTION__": changing status from %i to %i", ID_STATUS_CONNECTING, m_iDesiredStatus);
- }
- else if (m_iStatus++ > TOX_MAX_CONNECT_RETRIES)
- {
- SetStatus(ID_STATUS_OFFLINE);
- ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_NONETWORK);
- logger->Log(__FUNCTION__": failed to connect 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));
+ debugLogA(__FUNCTION__": changing status from %i to %i", ID_STATUS_CONNECTING, m_iDesiredStatus);
+ }
+ else if (m_iStatus++ > TOX_MAX_CONNECT_RETRIES)
+ {
+ SetStatus(ID_STATUS_OFFLINE);
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_NONETWORK);
+ debugLogA(__FUNCTION__": failed to connect to DHT");
}
}
@@ -164,7 +209,7 @@ void CToxProto::CheckConnection(int &retriesCount) {
if (retriesCount < TOX_MAX_DISCONNECT_RETRIES)
{
- logger->Log(__FUNCTION__": restored connection with DHT");
+ debugLogA(__FUNCTION__": restored connection with DHT");
retriesCount = TOX_MAX_DISCONNECT_RETRIES;
}
}
@@ -173,17 +218,17 @@ void CToxProto::CheckConnection(int &retriesCount) if (retriesCount == TOX_MAX_DISCONNECT_RETRIES)
{
retriesCount--;
- logger->Log(__FUNCTION__": lost connection with DHT");
+ debugLogA(__FUNCTION__": lost connection with DHT");
}
- else if (retriesCount % 50 == 0)
+ /*else if (retriesCount % 50 == 0)
{
retriesCount--;
BootstrapNodes();
- }
+ }*/
else if (!(--retriesCount))
{
toxThread->Disconnect();
- logger->Log(__FUNCTION__": disconnected from DHT");
+ debugLogA(__FUNCTION__": disconnected from DHT");
SetStatus(ID_STATUS_OFFLINE);
}
}
@@ -191,12 +236,14 @@ void CToxProto::CheckConnection(int &retriesCount) void CToxProto::PollingThread(void*)
{
+ debugLogA(__FUNCTION__": entering");
+
Tox_Options *options = GetToxOptions();
if (!options)
{
SetStatus(ID_STATUS_OFFLINE);
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL);
- logger->Log(__FUNCTION__": leaving");
+ debugLogA(__FUNCTION__": leaving");
return;
}
@@ -204,7 +251,7 @@ void CToxProto::PollingThread(void*) CToxThread toxThread(options, &error);
if (error != TOX_ERR_NEW_OK)
{
- logger->Log(__FUNCTION__": failed to initialize tox core (%d)", error);
+ debugLogA(__FUNCTION__": failed to initialize tox core (%d)", error);
ShowNotification(ToxErrorToString(error), TranslateT("Unable to initialize Tox core"), MB_ICONERROR);
tox_options_free(options);
}
@@ -212,14 +259,12 @@ void CToxProto::PollingThread(void*) this->toxThread = &toxThread;
- logger->Log(__FUNCTION__": entering");
-
if (!InitToxCore(&toxThread))
{
UninitToxCore(&toxThread);
SetStatus(ID_STATUS_OFFLINE);
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_WRONGPASSWORD);
- logger->Log(__FUNCTION__": leaving");
+ debugLogA(__FUNCTION__": leaving");
return;
}
@@ -237,5 +282,5 @@ void CToxProto::PollingThread(void*) toxThread.Disconnect();
UninitToxCore(&toxThread);
- logger->Log(__FUNCTION__": leaving");
+ 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 4bc67d2735..b248deabea 100644 --- a/protocols/Tox/src/tox_options.cpp +++ b/protocols/Tox/src/tox_options.cpp @@ -62,7 +62,7 @@ void CToxOptionsMain::ToxAddressCopy_OnClick(CCtrlButton*) void CToxOptionsMain::ProfileCreate_OnClick(CCtrlButton*)
{
- Tox_Options *options;
+ Tox_Options *options = NULL;
tox_options_default(options);
CToxThread toxThread(options);
tox_options_free(options);
@@ -73,7 +73,7 @@ void CToxOptionsMain::ProfileCreate_OnClick(CCtrlButton*) HANDLE hProfile = CreateFile(profilePath, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
if (hProfile == NULL)
{
- m_proto->logger->Log(__FUNCTION__": failed to create tox profile");
+ m_proto->debugLogA(__FUNCTION__": failed to create tox profile");
return;
}
CloseHandle(hProfile);
diff --git a/protocols/Tox/src/tox_profile.cpp b/protocols/Tox/src/tox_profile.cpp index 556d017144..28cef7b286 100644 --- a/protocols/Tox/src/tox_profile.cpp +++ b/protocols/Tox/src/tox_profile.cpp @@ -18,7 +18,7 @@ TCHAR* CToxProto::GetToxProfilePath(const TCHAR *accountName) bool CToxProto::LoadToxProfile(Tox_Options *options)
{
- logger->Log(__FUNCTION__": loading tox profile");
+ debugLogA(__FUNCTION__": loading tox profile");
mir_cslock locker(profileLock);
@@ -30,7 +30,7 @@ bool CToxProto::LoadToxProfile(Tox_Options *options) if (profile == NULL)
{
ShowNotification(TranslateT("Unable to open Tox profile"), MB_ICONERROR);
- logger->Log(__FUNCTION__": failed to open tox profile");
+ debugLogA(__FUNCTION__": failed to open tox profile");
return false;
}
@@ -54,7 +54,7 @@ bool CToxProto::LoadToxProfile(Tox_Options *options) {
fclose(profile);
ShowNotification(TranslateT("Unable to read Tox profile"), MB_ICONERROR);
- logger->Log(__FUNCTION__": failed to read tox profile");
+ debugLogA(__FUNCTION__": failed to read tox profile");
mir_free(data);
return false;
}
@@ -77,7 +77,7 @@ bool CToxProto::LoadToxProfile(Tox_Options *options) if (!tox_pass_decrypt(data, size, (uint8_t*)(char*)password, mir_strlen(password), encryptedData, &coreDecryptError))
{
ShowNotification(TranslateT("Unable to decrypt Tox profile"), MB_ICONERROR);
- logger->Log(__FUNCTION__": failed to decrypt tox profile (%d)", coreDecryptError);
+ debugLogA(__FUNCTION__": failed to decrypt tox profile (%d)", coreDecryptError);
mir_free(data);
return false;
}
@@ -114,7 +114,7 @@ void CToxProto::SaveToxProfile(CToxThread *toxThread) TOX_ERR_ENCRYPTION coreEncryptError;
if (!tox_pass_encrypt(data, size, (uint8_t*)(char*)password, mir_strlen(password), data, &coreEncryptError))
{
- logger->Log(__FUNCTION__": failed to encrypt tox profile");
+ debugLogA(__FUNCTION__": failed to encrypt tox profile");
mir_free(data);
return;
}
@@ -125,7 +125,7 @@ void CToxProto::SaveToxProfile(CToxThread *toxThread) FILE *profile = _tfopen(profilePath, _T("wb"));
if (profile == NULL)
{
- logger->Log(__FUNCTION__": failed to open tox profile");
+ debugLogA(__FUNCTION__": failed to open tox profile");
mir_free(data);
return;
}
@@ -133,7 +133,7 @@ void CToxProto::SaveToxProfile(CToxThread *toxThread) size_t written = fwrite(data, sizeof(char), size, profile);
if (size != written)
{
- logger->Log(__FUNCTION__": failed to write tox profile");
+ debugLogA(__FUNCTION__": failed to write tox profile");
}
fclose(profile);
diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp index 3c483f40d9..064ad7cc91 100644 --- a/protocols/Tox/src/tox_proto.cpp +++ b/protocols/Tox/src/tox_proto.cpp @@ -143,7 +143,7 @@ int CToxProto::SetStatus(int iNewStatus) iNewStatus = MapStatus(iNewStatus);
- logger->Log("CToxProto::SetStatus: changing status from %i to %i", m_iStatus, iNewStatus);
+ debugLogA(__FUNCTION__": changing status from %i to %i", m_iStatus, iNewStatus);
int old_status = m_iStatus;
m_iDesiredStatus = iNewStatus;
@@ -207,7 +207,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))
- logger->Log("CToxProto::SetAwayMsg: failed to set status status message %s (%d)", msg, error);
+ debugLogA(__FUNCTION__": failed to set status status message %s (%d)", msg, error);
}
return 0;
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index 996c34a681..e0a2189675 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -69,9 +69,8 @@ private: CToxThread *toxThread;
mir_cs profileLock;
TCHAR *accountName;
- HANDLE hNetlib, hPollingThread;
+ HANDLE hPollingThread;
CTransferList transfers;
- CLogger *logger;
ULONG hMessageProcess;
static HANDLE hProfileFolderPath;
@@ -93,7 +92,9 @@ private: // tox network
bool IsOnline();
- void BootstrapNode(const char *address, int port, const char *pubKey);
+ void BootstrapUdpNode(const char *address, int port, const char *pubKey);
+ void BootstrapTcpRelay(const char *address, int port, const char *pubKey);
+
void BootstrapNodesFromDb(bool isIPv6);
void BootstrapNodesFromJson(bool isIPv6);
void BootstrapNodes();
diff --git a/protocols/Tox/src/tox_services.cpp b/protocols/Tox/src/tox_services.cpp index 8ea301c6fa..3875a66f47 100644 --- a/protocols/Tox/src/tox_services.cpp +++ b/protocols/Tox/src/tox_services.cpp @@ -10,7 +10,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))
- logger->Log(__FUNCTION__": failed to set nick name");
+ debugLogA(__FUNCTION__": failed to set nick name");
}
return 0;
diff --git a/protocols/Tox/src/tox_transfer.cpp b/protocols/Tox/src/tox_transfer.cpp index c703d886f6..e701aef03c 100644 --- a/protocols/Tox/src/tox_transfer.cpp +++ b/protocols/Tox/src/tox_transfer.cpp @@ -16,7 +16,7 @@ void CToxProto::OnFriendFile(Tox*, uint32_t friendNumber, uint32_t fileNumber, u {
case TOX_FILE_KIND_AVATAR:
{
- proto->logger->Log(__FUNCTION__": incoming avatar (%d) from (%d)", fileNumber, friendNumber);
+ Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": incoming avatar (%d) from (%d)", fileNumber, friendNumber);
ptrT address(proto->getTStringA(hContact, TOX_SETTINGS_ID));
TCHAR avatarName[MAX_PATH];
@@ -31,7 +31,7 @@ void CToxProto::OnFriendFile(Tox*, uint32_t friendNumber, uint32_t fileNumber, u 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 %s(%d) cause (%d)", fileNumber, (const char*)pubKey, friendNumber, error);
+ Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": unable to get avatar hash (%d) from %s(%d) cause (%d)", fileNumber, (const char*)pubKey, friendNumber, error);
memset(transfer->hash, 0, TOX_HASH_LENGTH);
}
proto->OnGotFriendAvatarInfo(transfer);
@@ -40,7 +40,7 @@ void CToxProto::OnFriendFile(Tox*, uint32_t friendNumber, uint32_t fileNumber, u case TOX_FILE_KIND_DATA:
{
- proto->logger->Log(__FUNCTION__": incoming file (%d) from %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
+ Netlib_Logf(proto->m_hNetlibUser, __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:
- proto->logger->Log(__FUNCTION__": unsupported transfer (%d) from %s(%d) with type (%d)", fileNumber, (const char*)pubKey, friendNumber, kind);
+ Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": unsupported transfer (%d) from %s(%d) with type (%d)", fileNumber, (const char*)pubKey, friendNumber, kind);
return;
}
}
@@ -114,17 +114,17 @@ int CToxProto::OnFileResume(HANDLE hTransfer, int *action, const TCHAR **szFilen TCHAR *mode = *action == FILERESUME_OVERWRITE ? _T("wb") : _T("ab");
if (!transfer->OpenFile(mode))
{
- logger->Log(__FUNCTION__": failed to open file (%d) from %s(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber);
+ debugLogA(__FUNCTION__": failed to open file (%d) from %s(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber);
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 %s(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber);
+ debugLogA(__FUNCTION__": start receiving file (%d) from %s(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber);
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 %s(%d) cause (%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber, error);
+ debugLogA(__FUNCTION__": failed to start receiving of file(%d) from %s(%d) cause (%d)", transfer->fileNumber, (const char*)pubKey, 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);
transfers.Remove(transfer);
@@ -137,10 +137,10 @@ void CToxProto::OnTransferCompleted(FileTransferParam *transfer) {
ToxHexAddress pubKey = GetContactPublicKey(transfer->friendNumber);
- logger->Log(__FUNCTION__": finised the transfer of file (%d) from %s(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber);
+ debugLogA(__FUNCTION__": finised the transfer of file (%d) from %s(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber);
bool isFileFullyTransfered = transfer->pfts.currentFileProgress == transfer->pfts.currentFileSize;
if (!isFileFullyTransfered)
- logger->Log(__FUNCTION__": file (%d) from %s(%d) is transferred not completely", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber);
+ debugLogA(__FUNCTION__": file (%d) from %s(%d) is transferred not completely", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber);
if (transfer->transferType == TOX_FILE_KIND_AVATAR)
{
@@ -162,7 +162,7 @@ void CToxProto::OnDataReceiving(Tox*, uint32_t friendNumber, uint32_t fileNumber FileTransferParam *transfer = proto->transfers.Get(friendNumber, fileNumber);
if (transfer == NULL)
{
- proto->logger->Log(__FUNCTION__": failed to find transfer (%d) from %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
+ Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": failed to find transfer (%d) from %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
return;
}
@@ -176,7 +176,7 @@ void CToxProto::OnDataReceiving(Tox*, uint32_t friendNumber, uint32_t fileNumber MCONTACT hContact = proto->GetContact(friendNumber);
if (hContact == NULL)
{
- proto->logger->Log(__FUNCTION__": cannot find contact %s(%d)", (const char*)pubKey, friendNumber);
+ Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": cannot find contact %s(%d)", (const char*)pubKey, friendNumber);
tox_file_control(proto->toxThread->Tox(), friendNumber, fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
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)
{
- proto->logger->Log(__FUNCTION__": failed write to file (%d)", fileNumber);
+ Netlib_Logf(proto->m_hNetlibUser, __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;
@@ -209,7 +209,7 @@ HANDLE CToxProto::OnSendFile(MCONTACT hContact, const TCHAR*, TCHAR **ppszFiles) FILE *hFile = _tfopen(ppszFiles[0], _T("rb"));
if (hFile == NULL)
{
- logger->Log(__FUNCTION__": cannot open file %s", ppszFiles[0]);
+ debugLogA(__FUNCTION__": cannot open file %s", ppszFiles[0]);
return NULL;
}
@@ -230,12 +230,12 @@ HANDLE CToxProto::OnSendFile(MCONTACT hContact, const TCHAR*, TCHAR **ppszFiles) 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 %s(%d) cause (%d)", fileNumber, (const char*)pubKey, friendNumber, sendError);
+ debugLogA(__FUNCTION__": failed to send file (%d) to %s(%d) cause (%d)", fileNumber, (const char*)pubKey, friendNumber, sendError);
mir_free(fileDir);
mir_free(name);
return NULL;
}
- logger->Log(__FUNCTION__": start sending file (%d) to %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
+ debugLogA(__FUNCTION__": start sending file (%d) to %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
FileTransferParam *transfer = new FileTransferParam(friendNumber, fileNumber, fileName, fileSize);
transfer->pfts.flags |= PFTS_SENDING;
@@ -257,17 +257,17 @@ void CToxProto::OnFileSendData(Tox*, uint32_t friendNumber, uint32_t fileNumber, FileTransferParam *transfer = proto->transfers.Get(friendNumber, fileNumber);
if (transfer == NULL)
{
- proto->logger->Log(__FUNCTION__": failed to find transfer (%d) to %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
+ Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": failed to find transfer (%d) to %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
return;
}
if (length == 0)
{
// file sending is finished
- proto->logger->Log(__FUNCTION__": finised the transfer of file (%d) to %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
+ Netlib_Logf(proto->m_hNetlibUser, __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)
- proto->logger->Log(__FUNCTION__": file (%d) is not completely transferred to %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
+ Netlib_Logf(proto->m_hNetlibUser, __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)
{
- proto->logger->Log(__FUNCTION__": failed to read from file (%d) to %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
+ Netlib_Logf(proto->m_hNetlibUser, __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;
}
- proto->logger->Log(__FUNCTION__": failed to send file chunk (%d) to %s(%d) cause (%d)", fileNumber, (const char*)pubKey, friendNumber, error);
+ Netlib_Logf(proto->m_hNetlibUser, __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);
@@ -314,7 +314,7 @@ void CToxProto::OnFileSendData(Tox*, uint32_t friendNumber, uint32_t fileNumber, int CToxProto::OnFileCancel(MCONTACT, HANDLE hTransfer)
{
FileTransferParam *transfer = (FileTransferParam*)hTransfer;
- logger->Log(__FUNCTION__": Transfer (%d) is canceled", transfer->fileNumber);
+ debugLogA(__FUNCTION__": Transfer (%d) is canceled", transfer->fileNumber);
tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
transfers.Remove(transfer);
@@ -331,11 +331,11 @@ void CToxProto::PauseOutgoingTransfers(uint32_t friendNumber) {
ToxHexAddress pubKey = GetContactPublicKey(friendNumber);
- logger->Log(__FUNCTION__": sending ask to pause the transfer of file (%d) to %s(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber);
+ debugLogA(__FUNCTION__": sending ask to pause the transfer of file (%d) to %s(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber);
TOX_ERR_FILE_CONTROL 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 %s(%d) cause(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber, error);
+ debugLogA(__FUNCTION__": failed to pause the transfer (%d) to %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);
}
}
@@ -352,11 +352,11 @@ void CToxProto::ResumeIncomingTransfers(uint32_t friendNumber) {
ToxHexAddress pubKey = GetContactPublicKey(friendNumber);
- logger->Log(__FUNCTION__": sending ask to resume the transfer of file (%d) from %s(%d) cause(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber);
+ debugLogA(__FUNCTION__": sending ask to resume the transfer of file (%d) from %s(%d) cause(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber);
TOX_ERR_FILE_CONTROL 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 %s(%d) cause(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber, 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);
}
}
@@ -385,7 +385,7 @@ void CToxProto::OnFileRequest(Tox*, uint32_t friendNumber, uint32_t fileNumber, FileTransferParam *transfer = proto->transfers.Get(friendNumber, fileNumber);
if (transfer == NULL)
{
- proto->logger->Log(__FUNCTION__": failed to find transfer (%d)", fileNumber);
+ Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": failed to find transfer (%d)", fileNumber);
return;
}
|