From 0db366bfe0e2816f350e31c432c691e292c014e0 Mon Sep 17 00:00:00 2001 From: Chunting Gu Date: Fri, 8 Mar 2019 14:14:33 +0800 Subject: [PATCH] Drop the support of VS2013 --- webcc/globals.cc | 11 +++++++++-- webcc/globals.h | 33 ++++++--------------------------- webcc/http_client_base.h | 3 ++- webcc/http_client_session.cc | 2 +- webcc/http_connection.h | 3 ++- webcc/http_parser.h | 3 ++- webcc/http_request_args.h | 33 --------------------------------- webcc/http_request_handler.h | 3 ++- webcc/http_response.cc | 2 +- webcc/http_server.h | 3 ++- webcc/rest_service_manager.h | 3 ++- webcc/soap_client.cc | 9 ++++++++- webcc/soap_client.h | 3 ++- webcc/soap_parameter.h | 20 -------------------- webcc/url.h | 25 ------------------------- webcc/utility.cc | 10 ---------- webcc/utility.h | 3 --- 17 files changed, 39 insertions(+), 130 deletions(-) diff --git a/webcc/globals.cc b/webcc/globals.cc index a41fe96..535c750 100644 --- a/webcc/globals.cc +++ b/webcc/globals.cc @@ -1,10 +1,17 @@ #include "webcc/globals.h" -#include "boost/algorithm/string.hpp" +#include "webcc/version.h" namespace webcc { -// ----------------------------------------------------------------------------- +namespace http { + +const std::string& UserAgent() { + static std::string s_user_agent = std::string("Webcc/") + WEBCC_VERSION; + return s_user_agent; +} + +} // namespace http const char* DescribeError(Error error) { switch (error) { diff --git a/webcc/globals.h b/webcc/globals.h index 82b2e6b..0c5a62e 100644 --- a/webcc/globals.h +++ b/webcc/globals.h @@ -2,33 +2,8 @@ #define WEBCC_GLOBALS_H_ #include +#include #include -#include - -#include "webcc/version.h" - -// ----------------------------------------------------------------------------- -// Macros - -// Does the compiler support "= default" for move copy constructor and -// move assignment operator? -#ifdef _MSC_VER - #if _MSC_VER <= 1800 // VS 2013 - #define WEBCC_DEFAULT_MOVE_COPY_ASSIGN 0 - #else - #define WEBCC_DEFAULT_MOVE_COPY_ASSIGN 1 - #endif // _MSC_VER <= 1800 -#else - #define WEBCC_DEFAULT_MOVE_COPY_ASSIGN 1 -#endif // _MSC_VER - -// Explicitly declare the copy constructor and assignment operator as deleted. -#define WEBCC_DELETE_COPY_ASSIGN(TypeName) \ - TypeName(const TypeName&) = delete; \ - TypeName& operator=(const TypeName&) = delete; - -// Default user agent. -#define USER_AGENT "Webcc/" WEBCC_VERSION namespace webcc { @@ -120,6 +95,9 @@ const char* const kUtf8 = "utf-8"; } // namespace charsets +// Return default user agent for HTTP headers. +const std::string& UserAgent(); + } // namespace http // ----------------------------------------------------------------------------- @@ -156,7 +134,8 @@ public: explicit Exception(Error error = kNoError, bool timeout = false, const std::string& details = ""); - const char* what() const override { + // Note that `noexcept` is required by GCC. + const char* what() const noexcept override { return msg_.c_str(); } diff --git a/webcc/http_client_base.h b/webcc/http_client_base.h index eb6157f..a6152ae 100644 --- a/webcc/http_client_base.h +++ b/webcc/http_client_base.h @@ -29,7 +29,8 @@ public: virtual ~HttpClientBase() = default; - WEBCC_DELETE_COPY_ASSIGN(HttpClientBase); + HttpClientBase(const HttpClientBase&) = delete; + HttpClientBase& operator=(const HttpClientBase&) = delete; // Set the timeout seconds for reading response. // The |seconds| is only effective when greater than 0. diff --git a/webcc/http_client_session.cc b/webcc/http_client_session.cc index 6e85896..d323f44 100644 --- a/webcc/http_client_session.cc +++ b/webcc/http_client_session.cc @@ -82,7 +82,7 @@ HttpResponsePtr HttpClientSession::Post(const std::string& url, void HttpClientSession::InitHeaders() { // NOTE: C++11 requires a space between literal and string macro. - headers_.Add(http::headers::kUserAgent, USER_AGENT); + headers_.Add(http::headers::kUserAgent, http::UserAgent()); // TODO: Support gzip, deflate headers_.Add(http::headers::kAcceptEncoding, "identity"); diff --git a/webcc/http_connection.h b/webcc/http_connection.h index 497150a..7ae7f35 100644 --- a/webcc/http_connection.h +++ b/webcc/http_connection.h @@ -26,7 +26,8 @@ public: ~HttpConnection() = default; - WEBCC_DELETE_COPY_ASSIGN(HttpConnection); + HttpConnection(const HttpConnection&) = delete; + HttpConnection& operator=(const HttpConnection&) = delete; const HttpRequest& request() const { return request_; diff --git a/webcc/http_parser.h b/webcc/http_parser.h index 5a9f34e..cba3abe 100644 --- a/webcc/http_parser.h +++ b/webcc/http_parser.h @@ -16,7 +16,8 @@ public: virtual ~HttpParser() = default; - WEBCC_DELETE_COPY_ASSIGN(HttpParser); + HttpParser(const HttpParser&) = delete; + HttpParser& operator=(const HttpParser&) = delete; bool finished() const { return finished_; } diff --git a/webcc/http_request_args.h b/webcc/http_request_args.h index 64181d3..6aa3e23 100644 --- a/webcc/http_request_args.h +++ b/webcc/http_request_args.h @@ -24,42 +24,9 @@ public: HttpRequestArgs(const HttpRequestArgs&) = default; HttpRequestArgs& operator=(const HttpRequestArgs&) = default; -#if WEBCC_DEFAULT_MOVE_COPY_ASSIGN - HttpRequestArgs(HttpRequestArgs&&) = default; HttpRequestArgs& operator=(HttpRequestArgs&&) = default; -#else - - HttpRequestArgs(HttpRequestArgs&& rhs) - : method_(std::move(rhs.method_)), - url_(std::move(rhs.url_)), - parameters_(std::move(rhs.parameters_)), - data_(std::move(rhs.data_)), - json_(rhs.json_), - headers_(std::move(rhs.headers_)), - ssl_verify_(rhs.ssl_verify_), - buffer_size_(rhs.buffer_size_) { - LOG_VERB("HttpRequestArgs(&&)"); - } - - HttpRequestArgs& operator=(HttpRequestArgs&& rhs) { - if (&rhs != this) { - method_ = std::move(rhs.method_); - url_ = std::move(rhs.url_); - parameters_ = std::move(rhs.parameters_); - data_ = std::move(rhs.data_); - json_ = rhs.json_; - headers_ = std::move(rhs.headers_); - ssl_verify_ = rhs.ssl_verify_; - buffer_size_ = buffer_size_; - } - LOG_VERB("HttpRequestArgs& operator=(&&)"); - return *this; - } - -#endif // WEBCC_DEFAULT_MOVE_COPY_ASSIGN - HttpRequestArgs&& method(const std::string& method) { method_ = method; return std::move(*this); diff --git a/webcc/http_request_handler.h b/webcc/http_request_handler.h index ac7c2cb..7a13f0d 100644 --- a/webcc/http_request_handler.h +++ b/webcc/http_request_handler.h @@ -20,7 +20,8 @@ public: HttpRequestHandler() = default; virtual ~HttpRequestHandler() = default; - WEBCC_DELETE_COPY_ASSIGN(HttpRequestHandler); + HttpRequestHandler(const HttpRequestHandler&) = delete; + HttpRequestHandler& operator=(const HttpRequestHandler&) = delete; // Put the connection into the queue. void Enqueue(HttpConnectionPtr connection); diff --git a/webcc/http_response.cc b/webcc/http_response.cc index 97294a6..831ae2b 100644 --- a/webcc/http_response.cc +++ b/webcc/http_response.cc @@ -60,7 +60,7 @@ const std::string& ToString(int status) { bool HttpResponse::Prepare() { start_line_ = status_strings::ToString(status_); - SetHeader("Server", USER_AGENT); + SetHeader("Server", http::UserAgent()); SetHeader("Date", GetHttpDateTimestamp()); return true; diff --git a/webcc/http_server.h b/webcc/http_server.h index 8d6fa12..1956991 100644 --- a/webcc/http_server.h +++ b/webcc/http_server.h @@ -22,7 +22,8 @@ public: virtual ~HttpServer() = default; - WEBCC_DELETE_COPY_ASSIGN(HttpServer); + HttpServer(const HttpServer&) = delete; + HttpServer& operator=(const HttpServer&) = delete; // Run the server's io_service loop. void Run(); diff --git a/webcc/rest_service_manager.h b/webcc/rest_service_manager.h index d758264..740aafc 100644 --- a/webcc/rest_service_manager.h +++ b/webcc/rest_service_manager.h @@ -14,7 +14,8 @@ class RestServiceManager { public: RestServiceManager() = default; - WEBCC_DELETE_COPY_ASSIGN(RestServiceManager); + RestServiceManager(const RestServiceManager&) = delete; + RestServiceManager& operator=(const RestServiceManager&) = delete; // Add a service and bind it with the given URL. // The |url| should start with "/" and will be treated as a regular expression diff --git a/webcc/soap_client.cc b/webcc/soap_client.cc index c0f42f7..18ee245 100644 --- a/webcc/soap_client.cc +++ b/webcc/soap_client.cc @@ -15,7 +15,14 @@ SoapClient::SoapClient(const std::string& host, const std::string& port, : host_(host), port_(port), soap_version_(soap_version), http_client_(buffer_size), format_raw_(true), error_(kNoError) { - AdjustHostPort(host_, port_); + // Try to extract port from host if it's empty. + if (port_.empty()) { + std::size_t i = host_.find_last_of(':'); + if (i != std::string::npos) { + port_ = host_.substr(i + 1); + host_ = host_.substr(0, i); + } + } } bool SoapClient::Request(const std::string& operation, diff --git a/webcc/soap_client.h b/webcc/soap_client.h index ad27555..ab3da4f 100644 --- a/webcc/soap_client.h +++ b/webcc/soap_client.h @@ -21,7 +21,8 @@ public: ~SoapClient() = default; - WEBCC_DELETE_COPY_ASSIGN(SoapClient); + SoapClient(const SoapClient&) = delete; + SoapClient& operator=(const SoapClient&) = delete; void SetTimeout(int seconds) { http_client_.SetTimeout(seconds); diff --git a/webcc/soap_parameter.h b/webcc/soap_parameter.h index 9effe85..4975661 100644 --- a/webcc/soap_parameter.h +++ b/webcc/soap_parameter.h @@ -46,29 +46,9 @@ public: as_cdata_(false) { } -#if WEBCC_DEFAULT_MOVE_COPY_ASSIGN - SoapParameter(SoapParameter&&) = default; SoapParameter& operator=(SoapParameter&&) = default; -#else - - SoapParameter(SoapParameter&& rhs) - : key_(std::move(rhs.key_)), value_(std::move(rhs.value_)), - as_cdata_(rhs.as_cdata_) { - } - - SoapParameter& operator=(SoapParameter&& rhs) { - if (&rhs != this) { - key_ = std::move(rhs.key_); - value_ = std::move(rhs.value_); - as_cdata_ = rhs.as_cdata_; - } - return *this; - } - -#endif // WEBCC_DEFAULT_MOVE_COPY_ASSIGN - const std::string& key() const { return key_; } const std::string& value() const { return value_; } diff --git a/webcc/url.h b/webcc/url.h index 958058a..22d8f38 100644 --- a/webcc/url.h +++ b/webcc/url.h @@ -61,34 +61,9 @@ public: explicit Url(const std::string& str, bool decode = true); -#if WEBCC_DEFAULT_MOVE_COPY_ASSIGN - Url(Url&&) = default; Url& operator=(Url&&) = default; -#else - - Url(Url&& rhs) - : scheme_(std::move(rhs.scheme_)), - host_(std::move(rhs.host_)), - port_(std::move(rhs.port_)), - path_(std::move(rhs.path_)), - query_(std::move(rhs.query_)) { - } - - Url& operator=(Url&& rhs) { - if (&rhs != this) { - scheme_ = std::move(rhs.scheme_); - host_ = std::move(rhs.host_); - port_ = std::move(rhs.port_); - path_ = std::move(rhs.path_); - query_ = std::move(rhs.query_); - } - return *this; - } - -#endif // WEBCC_DEFAULT_MOVE_COPY_ASSIGN - void Init(const std::string& str, bool decode = true, bool clear = true); const std::string& scheme() const { diff --git a/webcc/utility.cc b/webcc/utility.cc index f26e1d2..93e780d 100644 --- a/webcc/utility.cc +++ b/webcc/utility.cc @@ -12,16 +12,6 @@ using tcp = boost::asio::ip::tcp; namespace webcc { -void AdjustHostPort(std::string& host, std::string& port) { - if (port.empty()) { - std::size_t i = host.find_last_of(':'); - if (i != std::string::npos) { - port = host.substr(i + 1); - host = host.substr(0, i); - } - } -} - void PrintEndpoint(std::ostream& ostream, const TcpEndpoint& endpoint) { ostream << endpoint; if (endpoint.protocol() == tcp::v4()) { diff --git a/webcc/utility.h b/webcc/utility.h index 46e0009..c34ec9f 100644 --- a/webcc/utility.h +++ b/webcc/utility.h @@ -9,9 +9,6 @@ namespace webcc { -// If |port| is empty, try to extract it from |host| (separated by ':'). -void AdjustHostPort(std::string& host, std::string& port); - typedef boost::asio::ip::tcp::endpoint TcpEndpoint; typedef boost::asio::ip::tcp::resolver::results_type TcpEndpoints;