Unify enum constant name style.

GitOrigin-RevId: 2e36eef9b54c23da0d1bc9beb7e07af8835f702d
This commit is contained in:
levlam 2020-06-15 04:23:47 +03:00
parent 715146c65c
commit ea4841a37c
10 changed files with 36 additions and 36 deletions

View File

@ -29,7 +29,7 @@ Result<size_t> Transport::read_next(BufferSlice *message, uint32 *quick_ack) {
if (r_size.is_error() || r_size.ok() != 0) { if (r_size.is_error() || r_size.ok() != 0) {
return r_size; return r_size;
} }
if (http_query_.type_ != HttpQuery::Type::RESPONSE) { if (http_query_.type_ != HttpQuery::Type::Response) {
return Status::Error("Unexpected HTTP query type"); return Status::Error("Unexpected HTTP query type");
} }
if (http_query_.container_.size() != 2u) { if (http_query_.container_.size() != 2u) {

View File

@ -332,7 +332,7 @@ Result<string> check_url(Slice url) {
} }
TRY_RESULT(http_url, parse_url(url)); TRY_RESULT(http_url, parse_url(url));
if (is_tg || is_ton) { if (is_tg || is_ton) {
if (tolower_begins_with(url, "http://") || http_url.protocol_ == HttpUrl::Protocol::HTTPS || if (tolower_begins_with(url, "http://") || http_url.protocol_ == HttpUrl::Protocol::Https ||
!http_url.userinfo_.empty() || http_url.specified_port_ != 0 || http_url.is_ipv6_) { !http_url.userinfo_.empty() || http_url.specified_port_ != 0 || http_url.is_ipv6_) {
return Status::Error(is_tg ? Slice("Wrong tg URL") : Slice("Wrong ton URL")); return Status::Error(is_tg ? Slice("Wrong tg URL") : Slice("Wrong ton URL"));
} }

View File

@ -164,7 +164,7 @@ void HttpConnectionBase::loop() {
} }
if (state_ == State::Close) { if (state_ == State::Close) {
LOG_IF(INFO, fd_.need_flush_write()) << "Close nonempty connection"; LOG_IF(INFO, fd_.need_flush_write()) << "Close nonempty connection";
LOG_IF(INFO, want_read && (fd_.input_buffer().size() > 0 || current_query_->type_ != HttpQuery::Type::EMPTY)) LOG_IF(INFO, want_read && (fd_.input_buffer().size() > 0 || current_query_->type_ != HttpQuery::Type::Empty))
<< "Close connection while reading request/response"; << "Close connection while reading request/response";
return stop(); return stop();
} }

View File

@ -48,20 +48,20 @@ int HttpQuery::get_retry_after() const {
StringBuilder &operator<<(StringBuilder &sb, const HttpQuery &q) { StringBuilder &operator<<(StringBuilder &sb, const HttpQuery &q) {
switch (q.type_) { switch (q.type_) {
case HttpQuery::Type::EMPTY: case HttpQuery::Type::Empty:
sb << "EMPTY"; sb << "EMPTY";
return sb; return sb;
case HttpQuery::Type::GET: case HttpQuery::Type::Get:
sb << "GET"; sb << "GET";
break; break;
case HttpQuery::Type::POST: case HttpQuery::Type::Post:
sb << "POST"; sb << "POST";
break; break;
case HttpQuery::Type::RESPONSE: case HttpQuery::Type::Response:
sb << "RESPONSE"; sb << "RESPONSE";
break; break;
} }
if (q.type_ == HttpQuery::Type::RESPONSE) { if (q.type_ == HttpQuery::Type::Response) {
sb << ":" << q.code_ << ":" << q.reason_; sb << ":" << q.code_ << ":" << q.reason_;
} else { } else {
sb << ":" << q.url_path_; sb << ":" << q.url_path_;

View File

@ -19,10 +19,10 @@ namespace td {
class HttpQuery { class HttpQuery {
public: public:
enum class Type : int8 { EMPTY, GET, POST, RESPONSE }; enum class Type : int8 { Empty, Get, Post, Response };
td::vector<BufferSlice> container_; td::vector<BufferSlice> container_;
Type type_ = Type::EMPTY; Type type_ = Type::Empty;
int32 code_ = 0; int32 code_ = 0;
MutableSlice url_path_; MutableSlice url_path_;
td::vector<std::pair<MutableSlice, MutableSlice>> args_; td::vector<std::pair<MutableSlice, MutableSlice>> args_;

View File

@ -663,12 +663,12 @@ Status HttpReader::parse_head(MutableSlice head) {
parser.skip(' '); parser.skip(' ');
// GET POST HTTP/1.1 // GET POST HTTP/1.1
if (type == "GET") { if (type == "GET") {
query_->type_ = HttpQuery::Type::GET; query_->type_ = HttpQuery::Type::Get;
} else if (type == "POST") { } else if (type == "POST") {
query_->type_ = HttpQuery::Type::POST; query_->type_ = HttpQuery::Type::Post;
} else if (type.size() >= 4 && type.substr(0, 4) == "HTTP") { } else if (type.size() >= 4 && type.substr(0, 4) == "HTTP") {
if (type == "HTTP/1.1" || type == "HTTP/1.0") { if (type == "HTTP/1.1" || type == "HTTP/1.0") {
query_->type_ = HttpQuery::Type::RESPONSE; query_->type_ = HttpQuery::Type::Response;
} else { } else {
LOG(INFO) << "Unsupported HTTP version: " << type; LOG(INFO) << "Unsupported HTTP version: " << type;
return Status::Error(505, "HTTP Version Not Supported"); return Status::Error(505, "HTTP Version Not Supported");
@ -680,7 +680,7 @@ Status HttpReader::parse_head(MutableSlice head) {
query_->args_.clear(); query_->args_.clear();
if (query_->type_ == HttpQuery::Type::RESPONSE) { if (query_->type_ == HttpQuery::Type::Response) {
query_->code_ = to_integer<int32>(parser.read_till(' ')); query_->code_ = to_integer<int32>(parser.read_till(' '));
parser.skip(' '); parser.skip(' ');
query_->reason_ = parser.read_till('\r'); query_->reason_ = parser.read_till('\r');

View File

@ -74,7 +74,7 @@ Status Wget::try_init() {
TRY_STATUS(addr.init_host_port(url.host_, url.port_, prefer_ipv6_)); TRY_STATUS(addr.init_host_port(url.host_, url.port_, prefer_ipv6_));
TRY_RESULT(fd, SocketFd::open(addr)); TRY_RESULT(fd, SocketFd::open(addr));
if (url.protocol_ == HttpUrl::Protocol::HTTP) { if (url.protocol_ == HttpUrl::Protocol::Http) {
connection_ = create_actor<HttpOutboundConnection>("Connect", std::move(fd), SslStream{}, connection_ = create_actor<HttpOutboundConnection>("Connect", std::move(fd), SslStream{},
std::numeric_limits<std::size_t>::max(), 0, 0, std::numeric_limits<std::size_t>::max(), 0, 0,
ActorOwn<HttpOutboundConnection::Callback>(actor_id(this))); ActorOwn<HttpOutboundConnection::Callback>(actor_id(this)));

View File

@ -17,10 +17,10 @@ namespace td {
string HttpUrl::get_url() const { string HttpUrl::get_url() const {
string result; string result;
switch (protocol_) { switch (protocol_) {
case Protocol::HTTP: case Protocol::Http:
result += "http://"; result += "http://";
break; break;
case Protocol::HTTPS: case Protocol::Https:
result += "https://"; result += "https://";
break; break;
default: default:
@ -49,9 +49,9 @@ Result<HttpUrl> parse_url(Slice url, HttpUrl::Protocol default_protocol) {
if (parser.start_with("://")) { if (parser.start_with("://")) {
parser.advance(3); parser.advance(3);
if (protocol_str == "http") { if (protocol_str == "http") {
protocol = HttpUrl::Protocol::HTTP; protocol = HttpUrl::Protocol::Http;
} else if (protocol_str == "https") { } else if (protocol_str == "https") {
protocol = HttpUrl::Protocol::HTTPS; protocol = HttpUrl::Protocol::Https;
} else { } else {
return Status::Error("Unsupported URL protocol"); return Status::Error("Unsupported URL protocol");
} }
@ -99,10 +99,10 @@ Result<HttpUrl> parse_url(Slice url, HttpUrl::Protocol default_protocol) {
int specified_port = port; int specified_port = port;
if (port == 0) { if (port == 0) {
if (protocol == HttpUrl::Protocol::HTTP) { if (protocol == HttpUrl::Protocol::Http) {
port = 80; port = 80;
} else { } else {
CHECK(protocol == HttpUrl::Protocol::HTTPS); CHECK(protocol == HttpUrl::Protocol::Https);
port = 443; port = 443;
} }
} }
@ -169,7 +169,7 @@ Result<HttpUrl> parse_url(Slice url, HttpUrl::Protocol default_protocol) {
} }
StringBuilder &operator<<(StringBuilder &sb, const HttpUrl &url) { StringBuilder &operator<<(StringBuilder &sb, const HttpUrl &url) {
sb << tag("protocol", url.protocol_ == HttpUrl::Protocol::HTTP ? "HTTP" : "HTTPS") << tag("userinfo", url.userinfo_) sb << tag("protocol", url.protocol_ == HttpUrl::Protocol::Http ? "HTTP" : "HTTPS") << tag("userinfo", url.userinfo_)
<< tag("host", url.host_) << tag("port", url.port_) << tag("query", url.query_); << tag("host", url.host_) << tag("port", url.port_) << tag("query", url.query_);
return sb; return sb;
} }

View File

@ -15,7 +15,7 @@ namespace td {
class HttpUrl { class HttpUrl {
public: public:
enum class Protocol { HTTP, HTTPS } protocol_ = Protocol::HTTP; enum class Protocol { Http, Https } protocol_ = Protocol::Http;
string userinfo_; string userinfo_;
string host_; string host_;
bool is_ipv6_ = false; bool is_ipv6_ = false;
@ -37,7 +37,7 @@ class HttpUrl {
}; };
Result<HttpUrl> parse_url(Slice url, Result<HttpUrl> parse_url(Slice url,
HttpUrl::Protocol default_protocol = HttpUrl::Protocol::HTTP) TD_WARN_UNUSED_RESULT; HttpUrl::Protocol default_protocol = HttpUrl::Protocol::Http) TD_WARN_UNUSED_RESULT;
StringBuilder &operator<<(StringBuilder &sb, const HttpUrl &url); StringBuilder &operator<<(StringBuilder &sb, const HttpUrl &url);

View File

@ -104,7 +104,7 @@ string winerror_to_string(int code);
#endif #endif
class Status { class Status {
enum class ErrorType : int8 { general, os }; enum class ErrorType : int8 { General, Os };
public: public:
Status() = default; Status() = default;
@ -129,7 +129,7 @@ class Status {
} }
static Status Error(int err, Slice message = Slice()) TD_WARN_UNUSED_RESULT { static Status Error(int err, Slice message = Slice()) TD_WARN_UNUSED_RESULT {
return Status(false, ErrorType::general, err, message); return Status(false, ErrorType::General, err, message);
} }
static Status Error(Slice message) TD_WARN_UNUSED_RESULT { static Status Error(Slice message) TD_WARN_UNUSED_RESULT {
@ -138,13 +138,13 @@ class Status {
#if TD_PORT_WINDOWS #if TD_PORT_WINDOWS
static Status WindowsError(int saved_error, Slice message) TD_WARN_UNUSED_RESULT { static Status WindowsError(int saved_error, Slice message) TD_WARN_UNUSED_RESULT {
return Status(false, ErrorType::os, saved_error, message); return Status(false, ErrorType::Os, saved_error, message);
} }
#endif #endif
#if TD_PORT_POSIX #if TD_PORT_POSIX
static Status PosixError(int32 saved_errno, Slice message) TD_WARN_UNUSED_RESULT { static Status PosixError(int32 saved_errno, Slice message) TD_WARN_UNUSED_RESULT {
return Status(false, ErrorType::os, saved_errno, message); return Status(false, ErrorType::Os, saved_errno, message);
} }
#endif #endif
@ -154,7 +154,7 @@ class Status {
template <int Code> template <int Code>
static Status Error() { static Status Error() {
static Status status(true, ErrorType::general, Code, ""); static Status status(true, ErrorType::General, Code, "");
return status.clone_static(); return status.clone_static();
} }
@ -164,10 +164,10 @@ class Status {
} }
Info info = get_info(); Info info = get_info();
switch (info.error_type) { switch (info.error_type) {
case ErrorType::general: case ErrorType::General:
sb << "[Error"; sb << "[Error";
break; break;
case ErrorType::os: case ErrorType::Os:
#if TD_PORT_POSIX #if TD_PORT_POSIX
sb << "[PosixError : " << strerror_safe(info.error_code); sb << "[PosixError : " << strerror_safe(info.error_code);
#elif TD_PORT_WINDOWS #elif TD_PORT_WINDOWS
@ -246,9 +246,9 @@ class Status {
} }
Info info = get_info(); Info info = get_info();
switch (info.error_type) { switch (info.error_type) {
case ErrorType::general: case ErrorType::General:
return message().str(); return message().str();
case ErrorType::os: case ErrorType::Os:
#if TD_PORT_POSIX #if TD_PORT_POSIX
return strerror_safe(info.error_code).str(); return strerror_safe(info.error_code).str();
#elif TD_PORT_WINDOWS #elif TD_PORT_WINDOWS
@ -276,10 +276,10 @@ class Status {
CHECK(is_error()); CHECK(is_error());
Info info = get_info(); Info info = get_info();
switch (info.error_type) { switch (info.error_type) {
case ErrorType::general: case ErrorType::General:
return Error(code(), PSLICE() << prefix << message()); return Error(code(), PSLICE() << prefix << message());
case ErrorType::os: case ErrorType::Os:
return Status(false, ErrorType::os, code(), PSLICE() << prefix << message()); return Status(false, ErrorType::Os, code(), PSLICE() << prefix << message());
default: default:
UNREACHABLE(); UNREACHABLE();
return {}; return {};