From 5d5c55596e33f89b10bd4c951f8bf7e4c72ea566 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 1 Nov 2018 20:08:20 +0300 Subject: [PATCH] Minor improvements. GitOrigin-RevId: 2f2099d91867ec302ff2d9426b6b088c8c625720 --- td/mtproto/SessionConnection.cpp | 4 ++-- td/telegram/net/DcAuthManager.h | 1 + td/telegram/net/Session.cpp | 6 +++--- td/telegram/net/Session.h | 6 +++--- tdnet/td/net/HttpReader.cpp | 8 ++++---- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/td/mtproto/SessionConnection.cpp b/td/mtproto/SessionConnection.cpp index 8aebb104..c960b158 100644 --- a/td/mtproto/SessionConnection.cpp +++ b/td/mtproto/SessionConnection.cpp @@ -291,8 +291,8 @@ Status SessionConnection::on_packet(const MsgInfo &info, const mtproto_api::rpc_ } Status SessionConnection::on_packet(const MsgInfo &info, uint64 req_msg_id, const mtproto_api::rpc_error &rpc_error) { - VLOG(mtproto) << "ERROR [code:" << rpc_error.error_code_ << "] [msg:" << rpc_error.error_message_.str().c_str() << "]" - << " " << tag("req_msg_id", req_msg_id); + VLOG(mtproto) << "ERROR " << tag("code", rpc_error.error_code_) << tag("message", rpc_error.error_message_) + << tag("req_msg_id", req_msg_id); if (req_msg_id != 0) { callback_->on_message_result_error(req_msg_id, rpc_error.error_code_, as_buffer_slice(rpc_error.error_message_)); } else { diff --git a/td/telegram/net/DcAuthManager.h b/td/telegram/net/DcAuthManager.h index 52df29a7..cb57c823 100644 --- a/td/telegram/net/DcAuthManager.h +++ b/td/telegram/net/DcAuthManager.h @@ -10,6 +10,7 @@ #include "td/telegram/net/AuthDataShared.h" #include "td/telegram/net/DcId.h" #include "td/telegram/net/NetQuery.h" + #include "td/actor/actor.h" #include "td/utils/buffer.h" diff --git a/td/telegram/net/Session.cpp b/td/telegram/net/Session.cpp index bf1a1546..40a7f87f 100644 --- a/td/telegram/net/Session.cpp +++ b/td/telegram/net/Session.cpp @@ -146,7 +146,7 @@ Session::Session(unique_ptr callback, std::shared_ptr last_activity_timestamp_ = Time::now(); } -bool Session::can_destroy_auth_key() { +bool Session::can_destroy_auth_key() const { return need_destroy_; } @@ -1006,10 +1006,10 @@ void Session::connection_close(ConnectionInfo *info) { CHECK(info->state == ConnectionInfo::State::Empty); } -bool Session::need_send_bind_key() { +bool Session::need_send_bind_key() const { return auth_data_.use_pfs() && !auth_data_.get_bind_flag() && auth_data_.get_tmp_auth_key().id() != tmp_auth_key_id_; } -bool Session::need_send_query() { +bool Session::need_send_query() const { return !close_flag_ && (!auth_data_.use_pfs() || auth_data_.get_bind_flag()) && !pending_queries_.empty() && !can_destroy_auth_key(); } diff --git a/td/telegram/net/Session.h b/td/telegram/net/Session.h index eb422f72..da042fa7 100644 --- a/td/telegram/net/Session.h +++ b/td/telegram/net/Session.h @@ -222,9 +222,9 @@ class Session final void connection_close(ConnectionInfo *info); void connection_flush(ConnectionInfo *info); void connection_send_query(ConnectionInfo *info, NetQueryPtr &&net_query, uint64 message_id = 0); - bool need_send_bind_key(); - bool need_send_query(); - bool can_destroy_auth_key(); + bool need_send_bind_key() const; + bool need_send_query() const; + bool can_destroy_auth_key() const; bool connection_send_bind_key(ConnectionInfo *info); void on_result(NetQueryPtr query) override; diff --git a/tdnet/td/net/HttpReader.cpp b/tdnet/td/net/HttpReader.cpp index e8021f75..c1fe011d 100644 --- a/tdnet/td/net/HttpReader.cpp +++ b/tdnet/td/net/HttpReader.cpp @@ -124,7 +124,7 @@ Result HttpReader::read_next(HttpQuery *query) { return Status::Error(413, PSLICE() << "Request Entity Too Large: content length is " << content_length_); } - if (std::strstr(content_type_lowercased_.c_str(), "multipart/form-data")) { + if (content_type_lowercased_.find("multipart/form-data") != string::npos) { state_ = ReadMultipartFormData; const char *p = std::strstr(content_type_lowercased_.c_str(), "boundary"); @@ -157,8 +157,8 @@ Result HttpReader::read_next(HttpQuery *query) { form_data_parse_state_ = SkipPrologue; form_data_read_length_ = 0; form_data_skipped_length_ = 0; - } else if (std::strstr(content_type_lowercased_.c_str(), "application/x-www-form-urlencoded") || - std::strstr(content_type_lowercased_.c_str(), "application/json")) { + } else if (content_type_lowercased_.find("application/x-www-form-urlencoded") != string::npos || + content_type_lowercased_.find("application/json") != string::npos) { state_ = ReadArgs; } else { form_data_skipped_length_ = 0; @@ -210,7 +210,7 @@ Result HttpReader::read_next(HttpQuery *query) { if (flow_sink_.is_ready()) { query_->container_.emplace_back(content_->cut_head(size).move_as_buffer_slice()); Status result; - if (std::strstr(content_type_lowercased_.c_str(), "application/x-www-form-urlencoded")) { + if (content_type_lowercased_.find("application/x-www-form-urlencoded") != string::npos) { result = parse_parameters(query_->container_.back().as_slice()); } else { result = parse_json_parameters(query_->container_.back().as_slice());