diff --git a/.gitattributes b/.gitattributes index 2d04f9b7e..06e5328a4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,6 +5,7 @@ *.h text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent *.c text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent *.tl text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent +*.mm text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent *.txt text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent *.sh text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent eol=lf *.php text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent @@ -18,6 +19,7 @@ *.java text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent *.py text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent *.js text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent +*.patch text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent *.swift text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent *.pbxproj text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent *.cs text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent @@ -32,7 +34,5 @@ sqlite/sqlite/* linguist-vendored -*.tlo binary - *.pfx binary *.png binary diff --git a/td/generate/tl-parser/CMakeLists.txt b/td/generate/tl-parser/CMakeLists.txt index 251eb2b39..442ce674a 100644 --- a/td/generate/tl-parser/CMakeLists.txt +++ b/td/generate/tl-parser/CMakeLists.txt @@ -15,5 +15,5 @@ endif() add_executable(${PROJECT_NAME} ${SOURCES}) if (NOT WIN32) - target_link_libraries(${PROJECT_NAME} m) + target_link_libraries(${PROJECT_NAME} PRIVATE m) endif() diff --git a/td/mtproto/RawConnection.cpp b/td/mtproto/RawConnection.cpp index 0c5976564..3aa77ef81 100644 --- a/td/mtproto/RawConnection.cpp +++ b/td/mtproto/RawConnection.cpp @@ -7,18 +7,26 @@ #include "td/mtproto/RawConnection.h" #include "td/mtproto/AuthKey.h" +#include "td/mtproto/IStreamTransport.h" +#include "td/mtproto/ProxySecret.h" #include "td/mtproto/Transport.h" #if TD_EXPERIMENTAL_WATCH_OS #include "td/net/DarwinHttp.h" #endif +#include "td/utils/BufferedFd.h" #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/MpscPollableQueue.h" +#include "td/utils/port/EventFd.h" +#include "td/utils/Slice.h" #include "td/utils/Status.h" #include "td/utils/StorerBase.h" +#include +#include #include namespace td { @@ -441,9 +449,8 @@ class RawConnectionHttp : public RawConnection { }; #endif -td::unique_ptr RawConnection::create(IPAddress ip_address, SocketFd socket_fd, - TransportType transport_type, - unique_ptr stats_callback) { +unique_ptr RawConnection::create(IPAddress ip_address, SocketFd socket_fd, TransportType transport_type, + unique_ptr stats_callback) { #if TD_EXPERIMENTAL_WATCH_OS return td::make_unique(ip_address, std::move(stats_callback)); #else diff --git a/td/mtproto/RawConnection.h b/td/mtproto/RawConnection.h index 90a602fd6..fa0713857 100644 --- a/td/mtproto/RawConnection.h +++ b/td/mtproto/RawConnection.h @@ -6,22 +6,19 @@ // #pragma once -#include "td/mtproto/IStreamTransport.h" +#include "td/telegram/StateManager.h" + #include "td/mtproto/PacketInfo.h" #include "td/mtproto/TransportType.h" #include "td/utils/buffer.h" -#include "td/utils/BufferedFd.h" #include "td/utils/common.h" #include "td/utils/port/detail/PollableFd.h" +#include "td/utils/port/IPAddress.h" #include "td/utils/port/SocketFd.h" #include "td/utils/Status.h" #include "td/utils/StorerBase.h" -#include "td/telegram/StateManager.h" - -#include - namespace td { namespace mtproto { @@ -39,9 +36,13 @@ class RawConnection { virtual void on_error() = 0; // called on RawConnection error. Such error should be very rare on good connections. virtual void on_mtproto_error() = 0; }; + RawConnection() = default; + RawConnection(const RawConnection &) = delete; + RawConnection &operator=(const RawConnection &) = delete; virtual ~RawConnection() = default; - static td::unique_ptr create(IPAddress ip_address, SocketFd socket_fd, TransportType transport_type, - unique_ptr stats_callback); + + static unique_ptr create(IPAddress ip_address, SocketFd socket_fd, TransportType transport_type, + unique_ptr stats_callback); virtual void set_connection_token(StateManager::ConnectionToken connection_token) = 0; diff --git a/td/telegram/GroupCallManager.h b/td/telegram/GroupCallManager.h index 12cf6bb7e..9afad8059 100644 --- a/td/telegram/GroupCallManager.h +++ b/td/telegram/GroupCallManager.h @@ -10,6 +10,7 @@ #include "td/telegram/DialogParticipant.h" #include "td/telegram/GroupCallId.h" #include "td/telegram/GroupCallParticipant.h" +#include "td/telegram/GroupCallParticipantOrder.h" #include "td/telegram/InputGroupCallId.h" #include "td/telegram/td_api.h" #include "td/telegram/telegram_api.h" diff --git a/td/telegram/GroupCallParticipant.cpp b/td/telegram/GroupCallParticipant.cpp index aedcfe37b..c380433bb 100644 --- a/td/telegram/GroupCallParticipant.cpp +++ b/td/telegram/GroupCallParticipant.cpp @@ -12,6 +12,8 @@ #include "td/utils/logging.h" +#include + namespace td { GroupCallParticipant::GroupCallParticipant(const tl_object_ptr &participant, diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 69a05d968..0c5a48533 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -30481,7 +30481,7 @@ void MessagesManager::send_dialog_action(DialogId dialog_id, MessageId top_threa tl_object_ptr input_peer; if (action == DialogAction::get_speaking_action()) { - input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Read); + input_peer = get_input_peer(dialog_id, AccessRights::Read); if (input_peer == nullptr) { return promise.set_error(Status::Error(400, "Have no access to the chat")); } @@ -30498,7 +30498,7 @@ void MessagesManager::send_dialog_action(DialogId dialog_id, MessageId top_threa return promise.set_value(Unit()); } - input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write); + input_peer = get_input_peer(dialog_id, AccessRights::Write); } if (dialog_id.get_type() == DialogType::SecretChat) { diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index b82cc15c8..f35a8ebc2 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -566,12 +566,12 @@ class TestProxyRequest : public RequestOnceActor { set_timeout_in(timeout_); promise_ = std::move(promise); - IPAddress ip; - auto status = ip.init_host_port(proxy_.server(), proxy_.port()); + IPAddress ip_address; + auto status = ip_address.init_host_port(proxy_.server(), proxy_.port()); if (status.is_error()) { return promise_.set_error(Status::Error(400, status.public_message())); } - auto r_socket_fd = SocketFd::open(ip); + auto r_socket_fd = SocketFd::open(ip_address); if (r_socket_fd.is_error()) { return promise_.set_error(Status::Error(400, r_socket_fd.error().public_message())); } @@ -590,9 +590,9 @@ class TestProxyRequest : public RequestOnceActor { send_closure(actor_id, &TestProxyRequest::on_connection_data, std::move(r_data)); }); - child_ = - ConnectionCreator::prepare_connection(ip, r_socket_fd.move_as_ok(), proxy_, mtproto_ip_address, get_transport(), - "Test", "TestPingDC2", nullptr, {}, false, std::move(connection_promise)); + child_ = ConnectionCreator::prepare_connection(ip_address, r_socket_fd.move_as_ok(), proxy_, mtproto_ip_address, + get_transport(), "Test", "TestPingDC2", nullptr, {}, false, + std::move(connection_promise)); } void on_connection_data(Result r_data) { diff --git a/td/telegram/net/ConnectionCreator.cpp b/td/telegram/net/ConnectionCreator.cpp index 63dd6a617..6bf5d47fa 100644 --- a/td/telegram/net/ConnectionCreator.cpp +++ b/td/telegram/net/ConnectionCreator.cpp @@ -323,19 +323,20 @@ void ConnectionCreator::ping_proxy(int32 proxy_id, Promise promise) { continue; } - auto ip = info.option->get_ip_address(); - auto r_socket_fd = SocketFd::open(ip); + auto ip_address = info.option->get_ip_address(); + auto r_socket_fd = SocketFd::open(ip_address); if (r_socket_fd.is_error()) { LOG(DEBUG) << "Failed to open socket: " << r_socket_fd.error(); on_ping_main_dc_result(token, r_socket_fd.move_as_error()); continue; } - ping_proxy_socket_fd( - ip, r_socket_fd.move_as_ok(), r_transport_type.move_as_ok(), PSTRING() << info.option->get_ip_address(), - PromiseCreator::lambda([actor_id = actor_id(this), token](Result result) { - send_closure(actor_id, &ConnectionCreator::on_ping_main_dc_result, token, std::move(result)); - })); + ping_proxy_socket_fd(std::move(ip_address), r_socket_fd.move_as_ok(), r_transport_type.move_as_ok(), + PSTRING() << info.option->get_ip_address(), + PromiseCreator::lambda([actor_id = actor_id(this), token](Result result) { + send_closure(actor_id, &ConnectionCreator::on_ping_main_dc_result, token, + std::move(result)); + })); } return; } diff --git a/tdnet/CMakeLists.txt b/tdnet/CMakeLists.txt index b613cfe34..b385bc236 100644 --- a/tdnet/CMakeLists.txt +++ b/tdnet/CMakeLists.txt @@ -47,7 +47,7 @@ set(TDNET_SOURCE ) if (TD_EXPERIMENTAL_WATCH_OS) - set (TDNET_SOURCE + set(TDNET_SOURCE ${TDNET_SOURCE} td/net/DarwinHttp.mm td/net/DarwinHttp.h diff --git a/tdnet/td/net/DarwinHttp.mm b/tdnet/td/net/DarwinHttp.mm index 11a491db3..d7cd819ba 100644 --- a/tdnet/td/net/DarwinHttp.mm +++ b/tdnet/td/net/DarwinHttp.mm @@ -6,6 +6,8 @@ // #include "td/net/DarwinHttp.h" +#include "td/utils/logging.h" + #import namespace td { @@ -16,7 +18,7 @@ NSString *to_ns_string(CSlice slice) { } NSData *to_ns_data(Slice data) { - return [NSData dataWithBytes:static_cast(data.data()) length:data.size()]; + return [NSData dataWithBytes:static_cast(data.data()) length:data.size()]; } auto http_get(CSlice url) { @@ -37,17 +39,17 @@ auto http_post(CSlice url, Slice data) { return request; } -void http_send(NSURLRequest *request, Promise promise) { +void http_send(NSURLRequest *request, Promise promise) { __block auto callback = std::move(promise); - NSURLSessionDataTask* dataTask = + NSURLSessionDataTask *dataTask = [NSURLSession.sharedSession dataTaskWithRequest:request completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) { - if(error == nil) { - callback(BufferSlice(Slice((const char *)([data bytes]), [data length]))); + if (error == nil) { + callback(BufferSlice(Slice((const char *)([data bytes]), [data length]))); } else { - callback(Status::Error(static_cast([error code]))); + callback(Status::Error(static_cast([error code]), "HTTP request failed")); } }]; [dataTask resume]; diff --git a/test/http.cpp b/test/http.cpp index 34fbd79c6..84b2f8817 100644 --- a/test/http.cpp +++ b/test/http.cpp @@ -42,8 +42,8 @@ #include #include -#include #include +#include REGISTER_TESTS(http) @@ -498,7 +498,7 @@ TEST(Http, Darwin) { Baton baton; //LOG(ERROR) << "???"; td::DarwinHttp::get("http://example.com", [&](td::BufferSlice data) { - LOG(ERROR) << data.as_slice(); + //LOG(ERROR) << data.as_slice(); baton.post(); }); //LOG(ERROR) << "!!!";