From 78f97fe198286a120370f6c56921205191f986b0 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Fri, 10 Apr 2015 12:01:55 +0000 Subject: Tox: - switched to new api - updated tox core git-svn-id: http://svn.miranda-ng.org/main/trunk@12726 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_core.cpp | 152 ++++++++++++++++++----------------------- 1 file changed, 65 insertions(+), 87 deletions(-) (limited to 'protocols/Tox/src/tox_core.cpp') diff --git a/protocols/Tox/src/tox_core.cpp b/protocols/Tox/src/tox_core.cpp index 5e1eae29d1..6ca63506b0 100644 --- a/protocols/Tox/src/tox_core.cpp +++ b/protocols/Tox/src/tox_core.cpp @@ -1,17 +1,18 @@ #include "common.h" -bool CToxProto::IsToxCoreInited() -{ - return tox != NULL; -} - bool CToxProto::InitToxCore() { - debugLogA("CToxProto::InitToxCore: initializing tox core"); + debugLogA(__FUNCTION__": initializing tox core"); - Tox_Options options = { 0 }; - options.udp_disabled = getBool("DisableUDP", 0); - options.ipv6enabled = !getBool("DisableIPv6", 0); + TOX_ERR_OPTIONS_NEW error; + Tox_Options *options = tox_options_new(&error); + if (error != TOX_ERR_OPTIONS_NEW::TOX_ERR_OPTIONS_NEW_OK) + { + debugLogA(__FUNCTION__": failed to initialize tox options (%d)", error); + return false; + } + options->udp_enabled = getBool("EnableUDP", 1); + options->ipv6_enabled = getBool("EnableIPv6", 0); if (hNetlib != NULL) { @@ -23,114 +24,91 @@ bool CToxProto::InitToxCore() if (nlus.proxyType == PROXYTYPE_HTTP || nlus.proxyType == PROXYTYPE_HTTPS) { debugLogA("CToxProto::InitToxCore: setting http user proxy config"); - options.proxy_type = TOX_PROXY_HTTP; - strcpy(&options.proxy_address[0], nlus.szProxyServer); - options.proxy_port = nlus.wProxyPort; + options->proxy_type = TOX_PROXY_TYPE_HTTP; + mir_strcpy((char*)&options->proxy_host[0], nlus.szProxyServer); + options->proxy_port = nlus.wProxyPort; } if (nlus.proxyType == PROXYTYPE_SOCKS4 || nlus.proxyType == PROXYTYPE_SOCKS5) { debugLogA("CToxProto::InitToxCore: setting socks user proxy config"); - options.proxy_type = TOX_PROXY_SOCKS5; - strcpy(&options.proxy_address[0], nlus.szProxyServer); - options.proxy_port = nlus.wProxyPort; + options->proxy_type = TOX_PROXY_TYPE_SOCKS5; + mir_strcpy((char*)&options->proxy_host[0], nlus.szProxyServer); + options->proxy_port = nlus.wProxyPort; } } } debugLogA("CToxProto::InitToxCore: loading tox profile"); - tox = tox_new(&options); - password = mir_utf8encodeW(ptrT(getTStringA("Password"))); - bool isProfileLoaded = LoadToxProfile(); - if (isProfileLoaded) + if (LoadToxProfile(options)) { - debugLogA("CToxProto::InitToxCore: tox profile load successfully"); - tox_callback_friend_request(tox, OnFriendRequest, this); tox_callback_friend_message(tox, OnFriendMessage, this); - tox_callback_friend_action(tox, OnFriendAction, this); - tox_callback_typing_change(tox, OnTypingChanged, this); - tox_callback_name_change(tox, OnFriendNameChange, this); - tox_callback_status_message(tox, OnStatusMessageChanged, this); - tox_callback_user_status(tox, OnUserStatusChanged, this); - tox_callback_read_receipt(tox, OnReadReceipt, this); - tox_callback_connection_status(tox, OnConnectionStatusChanged, this); + tox_callback_friend_read_receipt(tox, OnReadReceipt, this); + tox_callback_friend_typing(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); // file transfers - tox_callback_file_control(tox, OnFileRequest, this); - tox_callback_file_send_request(tox, OnFriendFile, this); - tox_callback_file_data(tox, OnFileData, this); - // avatars - tox_callback_avatar_info(tox, OnGotFriendAvatarInfo, this); - tox_callback_avatar_data(tox, OnGotFriendAvatarData, this); + tox_callback_file_recv_control(tox, OnFileRequest, this); + tox_callback_file_recv(tox, OnFriendFile, this); + tox_callback_file_recv_chunk(tox, OnFileReceiveData, this); + tox_callback_file_chunk_request(tox, OnFileSendData, this); // group chats - tox_callback_group_invite(tox, OnGroupChatInvite, this); + //tox_callback_group_invite(tox, OnGroupChatInvite, this); - uint8_t data[TOX_FRIEND_ADDRESS_SIZE]; - tox_get_address(tox, data); - ToxHexAddress address(data, TOX_FRIEND_ADDRESS_SIZE); + uint8_t data[TOX_ADDRESS_SIZE]; + tox_self_get_address(tox, data); + ToxHexAddress address(data, TOX_ADDRESS_SIZE); setString(TOX_SETTINGS_ID, address); - int size = tox_get_self_name_size(tox); - std::string nick(size, 0); - tox_get_self_name(tox, (uint8_t*)nick.data()); - setWString("Nick", ptrW(Utf8DecodeW(nick.c_str()))); + uint8_t nick[TOX_MAX_NAME_LENGTH] = { 0 }; + tox_self_get_name(tox, nick); + setWString("Nick", ptrW(Utf8DecodeW((char*)nick))); - //temporary - size = tox_get_self_status_message_size(tox); - std::string statusmes(size, 0); - tox_get_self_status_message(tox, (uint8_t*)statusmes.data(), size); - setWString("StatusMsg", ptrW(Utf8DecodeW(statusmes.c_str()))); + uint8_t statusMessage[TOX_MAX_STATUS_MESSAGE_LENGTH] = { 0 }; + tox_self_get_status_message(tox, statusMessage); + setWString("StatusMsg", ptrW(Utf8DecodeW((char*)statusMessage))); - std::tstring avatarPath = GetAvatarFilePath(); - if (IsFileExists(avatarPath)) - { - SetToxAvatar(avatarPath); - } + return true; } - else - { - debugLogA("CToxProto::InitToxCore: failed to load tox profile"); - if (password != NULL) - { - mir_free(password); - password = NULL; - } - tox_kill(tox); - tox = NULL; - } + tox_options_free(options); - return isProfileLoaded; + return false; } void CToxProto::UninitToxCore() { - for (size_t i = 0; i < transfers.Count(); i++) - { - FileTransferParam *transfer = transfers.GetAt(i); - transfer->status = CANCELED; - tox_file_send_control(tox, transfer->friendNumber, transfer->GetDirection(), transfer->fileNumber, TOX_FILECONTROL_KILL, NULL, 0); - ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_DENIED, (HANDLE)transfer, 0); - transfers.Remove(transfer); - } + if (tox) { + for (size_t i = 0; i < transfers.Count(); i++) + { + FileTransferParam *transfer = transfers.GetAt(i); + transfer->status = CANCELED; + tox_file_control(tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); + ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_DENIED, (HANDLE)transfer, 0); + transfers.Remove(transfer); + } - if (IsToxCoreInited()) - { - ptrA nickname(mir_utf8encodeW(ptrT(getTStringA("Nick")))); - tox_set_name(tox, (uint8_t*)(char*)nickname, mir_strlen(nickname)); + //if (IsToxCoreInited()) + //{ + // ptrA nickname(mir_utf8encodeW(ptrT(getTStringA("Nick")))); + // tox_set_name(tox, (uint8_t*)(char*)nickname, mir_strlen(nickname)); - //temporary - ptrA statusmes(mir_utf8encodeW(ptrT(getTStringA("StatusMsg")))); - tox_set_status_message(tox, (uint8_t*)(char*)statusmes, mir_strlen(statusmes)); - } + // //temporary + // ptrA statusmes(mir_utf8encodeW(ptrT(getTStringA("StatusMsg")))); + // tox_set_status_message(tox, (uint8_t*)(char*)statusmes, mir_strlen(statusmes)); + //} - SaveToxProfile(); - if (password != NULL) - { - mir_free(password); - password = NULL; + SaveToxProfile(); + if (password != NULL) + { + mir_free(password); + password = NULL; + } + tox_kill(tox); + tox = NULL; } - tox_kill(tox); - tox = NULL; } \ No newline at end of file -- cgit v1.2.3