From b41dfcebd94f1af03649eed14288a6c253733d32 Mon Sep 17 00:00:00 2001 From: Chunting Gu Date: Wed, 23 May 2018 11:03:39 +0800 Subject: [PATCH] Fix style warnings reported by cpplint. --- compile_commands.json | 38 +++++++++++++++++++------------ src/webcc/globals.cc | 2 ++ src/webcc/http_async_client.cc | 16 ------------- src/webcc/http_client.cc | 15 ++++++------ src/webcc/http_message.h | 2 ++ src/webcc/http_parser.cc | 14 ++++++------ src/webcc/http_parser.h | 5 ++-- src/webcc/http_request.h | 5 ++-- src/webcc/http_request_parser.h | 2 ++ src/webcc/http_response.h | 1 + src/webcc/http_response_parser.cc | 9 +++----- src/webcc/http_response_parser.h | 2 ++ src/webcc/http_server.cc | 7 ++---- src/webcc/http_session.cc | 7 +++--- src/webcc/http_session.h | 1 + src/webcc/logger.cc | 3 ++- src/webcc/rest_request_handler.cc | 5 ++-- src/webcc/rest_request_handler.h | 2 ++ src/webcc/rest_server.h | 2 ++ src/webcc/rest_service.h | 8 +++---- src/webcc/rest_service_manager.cc | 2 -- src/webcc/rest_service_manager.h | 4 +++- src/webcc/soap_client.cc | 1 + src/webcc/soap_message.cc | 7 +++--- src/webcc/soap_request.cc | 4 ++-- src/webcc/soap_request.h | 1 + src/webcc/soap_request_handler.cc | 2 ++ src/webcc/soap_request_handler.h | 1 + src/webcc/soap_response.cc | 10 ++++---- src/webcc/soap_response.h | 3 +++ src/webcc/soap_server.h | 2 ++ src/webcc/soap_xml.cc | 13 ++++++----- src/webcc/soap_xml.h | 16 +++++++------ src/webcc/url.cc | 9 ++++---- src/webcc/utility.cc | 2 +- src/webcc/utility.h | 3 ++- 36 files changed, 123 insertions(+), 103 deletions(-) diff --git a/compile_commands.json b/compile_commands.json index 7490d83..291e5a9 100644 --- a/compile_commands.json +++ b/compile_commands.json @@ -6,8 +6,8 @@ }, { "directory": "/home/adam/github/webcc/build/src/webcc", - "command": "/usr/bin/c++ -DBOOST_ASIO_NO_DEPRECATED -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -I/home/adam/github/webcc/src -I/home/adam/github/webcc/third_party -std=c++11 -o CMakeFiles/webcc.dir/common.cc.o -c /home/adam/github/webcc/src/webcc/common.cc", - "file": "/home/adam/github/webcc/src/webcc/common.cc" + "command": "/usr/bin/c++ -DBOOST_ASIO_NO_DEPRECATED -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -I/home/adam/github/webcc/src -I/home/adam/github/webcc/third_party -std=c++11 -o CMakeFiles/webcc.dir/globals.cc.o -c /home/adam/github/webcc/src/webcc/globals.cc", + "file": "/home/adam/github/webcc/src/webcc/globals.cc" }, { "directory": "/home/adam/github/webcc/build/src/webcc", @@ -66,8 +66,18 @@ }, { "directory": "/home/adam/github/webcc/build/src/webcc", - "command": "/usr/bin/c++ -DBOOST_ASIO_NO_DEPRECATED -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -I/home/adam/github/webcc/src -I/home/adam/github/webcc/third_party -std=c++11 -o CMakeFiles/webcc.dir/rest_server.cc.o -c /home/adam/github/webcc/src/webcc/rest_server.cc", - "file": "/home/adam/github/webcc/src/webcc/rest_server.cc" + "command": "/usr/bin/c++ -DBOOST_ASIO_NO_DEPRECATED -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -I/home/adam/github/webcc/src -I/home/adam/github/webcc/third_party -std=c++11 -o CMakeFiles/webcc.dir/rest_client.cc.o -c /home/adam/github/webcc/src/webcc/rest_client.cc", + "file": "/home/adam/github/webcc/src/webcc/rest_client.cc" +}, +{ + "directory": "/home/adam/github/webcc/build/src/webcc", + "command": "/usr/bin/c++ -DBOOST_ASIO_NO_DEPRECATED -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -I/home/adam/github/webcc/src -I/home/adam/github/webcc/third_party -std=c++11 -o CMakeFiles/webcc.dir/rest_request_handler.cc.o -c /home/adam/github/webcc/src/webcc/rest_request_handler.cc", + "file": "/home/adam/github/webcc/src/webcc/rest_request_handler.cc" +}, +{ + "directory": "/home/adam/github/webcc/build/src/webcc", + "command": "/usr/bin/c++ -DBOOST_ASIO_NO_DEPRECATED -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -I/home/adam/github/webcc/src -I/home/adam/github/webcc/third_party -std=c++11 -o CMakeFiles/webcc.dir/rest_service_manager.cc.o -c /home/adam/github/webcc/src/webcc/rest_service_manager.cc", + "file": "/home/adam/github/webcc/src/webcc/rest_service_manager.cc" }, { "directory": "/home/adam/github/webcc/build/src/webcc", @@ -86,28 +96,28 @@ }, { "directory": "/home/adam/github/webcc/build/src/webcc", - "command": "/usr/bin/c++ -DBOOST_ASIO_NO_DEPRECATED -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -I/home/adam/github/webcc/src -I/home/adam/github/webcc/third_party -std=c++11 -o CMakeFiles/webcc.dir/soap_message.cc.o -c /home/adam/github/webcc/src/webcc/soap_message.cc", - "file": "/home/adam/github/webcc/src/webcc/soap_message.cc" + "command": "/usr/bin/c++ -DBOOST_ASIO_NO_DEPRECATED -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -I/home/adam/github/webcc/src -I/home/adam/github/webcc/third_party -std=c++11 -o CMakeFiles/webcc.dir/soap_request_handler.cc.o -c /home/adam/github/webcc/src/webcc/soap_request_handler.cc", + "file": "/home/adam/github/webcc/src/webcc/soap_request_handler.cc" }, { "directory": "/home/adam/github/webcc/build/src/webcc", - "command": "/usr/bin/c++ -DBOOST_ASIO_NO_DEPRECATED -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -I/home/adam/github/webcc/src -I/home/adam/github/webcc/third_party -std=c++11 -o CMakeFiles/webcc.dir/soap_request.cc.o -c /home/adam/github/webcc/src/webcc/soap_request.cc", - "file": "/home/adam/github/webcc/src/webcc/soap_request.cc" + "command": "/usr/bin/c++ -DBOOST_ASIO_NO_DEPRECATED -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -I/home/adam/github/webcc/src -I/home/adam/github/webcc/third_party -std=c++11 -o CMakeFiles/webcc.dir/soap_xml.cc.o -c /home/adam/github/webcc/src/webcc/soap_xml.cc", + "file": "/home/adam/github/webcc/src/webcc/soap_xml.cc" }, { "directory": "/home/adam/github/webcc/build/src/webcc", - "command": "/usr/bin/c++ -DBOOST_ASIO_NO_DEPRECATED -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -I/home/adam/github/webcc/src -I/home/adam/github/webcc/third_party -std=c++11 -o CMakeFiles/webcc.dir/soap_response.cc.o -c /home/adam/github/webcc/src/webcc/soap_response.cc", - "file": "/home/adam/github/webcc/src/webcc/soap_response.cc" + "command": "/usr/bin/c++ -DBOOST_ASIO_NO_DEPRECATED -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -I/home/adam/github/webcc/src -I/home/adam/github/webcc/third_party -std=c++11 -o CMakeFiles/webcc.dir/soap_message.cc.o -c /home/adam/github/webcc/src/webcc/soap_message.cc", + "file": "/home/adam/github/webcc/src/webcc/soap_message.cc" }, { "directory": "/home/adam/github/webcc/build/src/webcc", - "command": "/usr/bin/c++ -DBOOST_ASIO_NO_DEPRECATED -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -I/home/adam/github/webcc/src -I/home/adam/github/webcc/third_party -std=c++11 -o CMakeFiles/webcc.dir/soap_xml.cc.o -c /home/adam/github/webcc/src/webcc/soap_xml.cc", - "file": "/home/adam/github/webcc/src/webcc/soap_xml.cc" + "command": "/usr/bin/c++ -DBOOST_ASIO_NO_DEPRECATED -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -I/home/adam/github/webcc/src -I/home/adam/github/webcc/third_party -std=c++11 -o CMakeFiles/webcc.dir/soap_request.cc.o -c /home/adam/github/webcc/src/webcc/soap_request.cc", + "file": "/home/adam/github/webcc/src/webcc/soap_request.cc" }, { "directory": "/home/adam/github/webcc/build/src/webcc", - "command": "/usr/bin/c++ -DBOOST_ASIO_NO_DEPRECATED -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -I/home/adam/github/webcc/src -I/home/adam/github/webcc/third_party -std=c++11 -o CMakeFiles/webcc.dir/soap_server.cc.o -c /home/adam/github/webcc/src/webcc/soap_server.cc", - "file": "/home/adam/github/webcc/src/webcc/soap_server.cc" + "command": "/usr/bin/c++ -DBOOST_ASIO_NO_DEPRECATED -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -I/home/adam/github/webcc/src -I/home/adam/github/webcc/third_party -std=c++11 -o CMakeFiles/webcc.dir/soap_response.cc.o -c /home/adam/github/webcc/src/webcc/soap_response.cc", + "file": "/home/adam/github/webcc/src/webcc/soap_response.cc" }, { "directory": "/home/adam/github/webcc/build/src/webcc", diff --git a/src/webcc/globals.cc b/src/webcc/globals.cc index 46ad4c9..41af1ff 100644 --- a/src/webcc/globals.cc +++ b/src/webcc/globals.cc @@ -1,5 +1,7 @@ #include "webcc/globals.h" +#include // for move() + namespace webcc { // NOTE: diff --git a/src/webcc/http_async_client.cc b/src/webcc/http_async_client.cc index 3f26649..705273c 100644 --- a/src/webcc/http_async_client.cc +++ b/src/webcc/http_async_client.cc @@ -1,14 +1,9 @@ #include "webcc/http_async_client.h" -#if WEBCC_DEBUG_OUTPUT -#include -#endif - #if 0 #include "boost/asio.hpp" #else #include "boost/asio/connect.hpp" -//#include "boost/asio/ip/tcp.hpp" #include "boost/asio/read.hpp" #include "boost/asio/write.hpp" #endif @@ -119,11 +114,6 @@ void HttpAsyncClient::HandleRead(boost::system::error_code ec, return; } -#if WEBCC_DEBUG_OUTPUT - // NOTE: the content XML might not be well formated. - std::cout.write(buffer_.data(), length); -#endif - // Parse the response piece just read. // If the content has been fully received, next time flag "finished_" // will be set. @@ -158,12 +148,6 @@ void HttpAsyncClient::HandleRead(boost::system::error_code ec, // return error; //} //} - -//#if WEBCC_DEBUG_OUTPUT -// std::cout << std::endl; -// std::cout << "--- RESPONSE (PARSED) ---" << std::endl; -// std::cout << *response << std::endl; -//#endif } } // namespace webcc diff --git a/src/webcc/http_client.cc b/src/webcc/http_client.cc index 72a403b..7226da7 100644 --- a/src/webcc/http_client.cc +++ b/src/webcc/http_client.cc @@ -1,11 +1,13 @@ #include "webcc/http_client.h" -#include "boost/date_time/posix_time/posix_time.hpp" -#include "boost/lambda/bind.hpp" -#include "boost/lambda/lambda.hpp" +#include + #include "boost/asio/connect.hpp" #include "boost/asio/read.hpp" #include "boost/asio/write.hpp" +#include "boost/date_time/posix_time/posix_time.hpp" +#include "boost/lambda/bind.hpp" +#include "boost/lambda/lambda.hpp" #include "webcc/logger.h" #include "webcc/http_request.h" @@ -26,10 +28,9 @@ static const int kReceiveMaxSeconds = 30; //////////////////////////////////////////////////////////////////////////////// HttpClient::HttpClient() - : socket_(io_context_) - , timeout_seconds_(kReceiveMaxSeconds) - , deadline_timer_(io_context_) { - + : socket_(io_context_), + timeout_seconds_(kReceiveMaxSeconds), + deadline_timer_(io_context_) { deadline_timer_.expires_at(boost::posix_time::pos_infin); // Start the persistent actor that checks for deadline expiry. diff --git a/src/webcc/http_message.h b/src/webcc/http_message.h index ff160ae..b4fa265 100644 --- a/src/webcc/http_message.h +++ b/src/webcc/http_message.h @@ -3,6 +3,8 @@ #include #include +#include // for move() +#include #include "webcc/globals.h" diff --git a/src/webcc/http_parser.cc b/src/webcc/http_parser.cc index caa3538..680102d 100644 --- a/src/webcc/http_parser.cc +++ b/src/webcc/http_parser.cc @@ -8,12 +8,12 @@ namespace webcc { HttpParser::HttpParser(HttpMessage* message) - : message_(message) - , content_length_(kInvalidLength) - , start_line_parsed_(false) - , content_length_parsed_(false) - , header_parsed_(false) - , finished_(false) { + : message_(message), + content_length_(kInvalidLength), + start_line_parsed_(false), + content_length_parsed_(false), + header_parsed_(false), + finished_(false) { } Error HttpParser::Parse(const char* data, std::size_t len) { @@ -71,7 +71,7 @@ Error HttpParser::Parse(const char* data, std::size_t len) { Finish(); return kNoError; } else { - // Invalid Content-Length in the request. + // Invalid Content-Length in the request. if (content_length_ == kInvalidLength) { return kHttpContentLengthError; } diff --git a/src/webcc/http_parser.h b/src/webcc/http_parser.h index 89271cd..8a0550e 100644 --- a/src/webcc/http_parser.h +++ b/src/webcc/http_parser.h @@ -11,7 +11,7 @@ class HttpMessage; // HttpParser parses HTTP request and response. class HttpParser { -public: + public: explicit HttpParser(HttpMessage* message); virtual ~HttpParser() = default; @@ -22,7 +22,7 @@ public: Error Parse(const char* data, std::size_t len); -protected: + protected: // Parse HTTP start line. virtual Error ParseStartLine(const std::string& line) = 0; @@ -35,7 +35,6 @@ protected: bool IsContentFull() const; -protected: // The result HTTP message. HttpMessage* message_; diff --git a/src/webcc/http_request.h b/src/webcc/http_request.h index 00efb66..eac4eaa 100644 --- a/src/webcc/http_request.h +++ b/src/webcc/http_request.h @@ -2,6 +2,7 @@ #define WEBCC_HTTP_REQUEST_H_ #include +#include #include "boost/asio/buffer.hpp" // for const_buffer @@ -14,7 +15,7 @@ class HttpRequest; std::ostream& operator<<(std::ostream& os, const HttpRequest& request); class HttpRequest : public HttpMessage { -public: + public: HttpRequest() = default; HttpRequest(const HttpRequest&) = default; HttpRequest& operator=(const HttpRequest&) = default; @@ -62,7 +63,7 @@ public: // Dump as string, only used by logger. std::string Dump() const; -private: + private: friend std::ostream& operator<<(std::ostream& os, const HttpRequest& request); // HTTP method. diff --git a/src/webcc/http_request_parser.h b/src/webcc/http_request_parser.h index 2093840..e6d5c1e 100644 --- a/src/webcc/http_request_parser.h +++ b/src/webcc/http_request_parser.h @@ -1,6 +1,8 @@ #ifndef WEBCC_HTTP_REQUEST_PARSER_H_ #define WEBCC_HTTP_REQUEST_PARSER_H_ +#include + #include "webcc/http_parser.h" namespace webcc { diff --git a/src/webcc/http_response.h b/src/webcc/http_response.h index 26c309b..adf4f79 100644 --- a/src/webcc/http_response.h +++ b/src/webcc/http_response.h @@ -2,6 +2,7 @@ #define WEBCC_HTTP_RESPONSE_H_ #include +#include #include "boost/asio/buffer.hpp" // for const_buffer diff --git a/src/webcc/http_response_parser.cc b/src/webcc/http_response_parser.cc index c6ae836..1b21462 100644 --- a/src/webcc/http_response_parser.cc +++ b/src/webcc/http_response_parser.cc @@ -7,16 +7,15 @@ namespace webcc { HttpResponseParser::HttpResponseParser(HttpResponse* response) - : HttpParser(response) - , response_(response) { + : HttpParser(response), response_(response) { } Error HttpResponseParser::ParseStartLine(const std::string& line) { response_->set_start_line(line + "\r\n"); - size_t off = 0; + std::size_t off = 0; - size_t pos = line.find(' '); + std::size_t pos = line.find(' '); if (pos == std::string::npos) { return kHttpStartLineError; } @@ -39,8 +38,6 @@ Error HttpResponseParser::ParseStartLine(const std::string& line) { return kHttpStartLineError; } - off = pos + 1; // Skip space. - if (response_->status() != HttpStatus::kOK) { return kHttpStatusError; } diff --git a/src/webcc/http_response_parser.h b/src/webcc/http_response_parser.h index 414c0cf..f9a20e9 100644 --- a/src/webcc/http_response_parser.h +++ b/src/webcc/http_response_parser.h @@ -1,6 +1,8 @@ #ifndef WEBCC_HTTP_RESPONSE_PARSER_H_ #define WEBCC_HTTP_RESPONSE_PARSER_H_ +#include + #include "webcc/http_parser.h" namespace webcc { diff --git a/src/webcc/http_server.cc b/src/webcc/http_server.cc index f9488f2..a4b7dfd 100644 --- a/src/webcc/http_server.cc +++ b/src/webcc/http_server.cc @@ -1,6 +1,7 @@ #include "webcc/http_server.h" #include +#include #include "webcc/http_request_handler.h" #include "webcc/logger.h" @@ -12,13 +13,10 @@ using tcp = boost::asio::ip::tcp; namespace webcc { HttpServer::HttpServer(unsigned short port, std::size_t workers) - : signals_(io_context_) - , workers_(workers) { - + : signals_(io_context_) , workers_(workers) { // Register to handle the signals that indicate when the server should exit. // It is safe to register for the same signal multiple times in a program, // provided all registration for the specified signal is made through asio. - // TODO: Verify if this works for Windows. signals_.add(SIGINT); signals_.add(SIGTERM); #if defined(SIGQUIT) @@ -32,7 +30,6 @@ HttpServer::HttpServer(unsigned short port, std::size_t workers) // For more details about SO_REUSEADDR, see: // https://msdn.microsoft.com/en-us/library/windows/desktop/ms740621(v=vs.85).aspx // http://www.andy-pearce.com/blog/posts/2013/Feb/so_reuseaddr-on-windows/ - // TODO: SO_EXCLUSIVEADDRUSE acceptor_.reset(new tcp::acceptor(io_context_, tcp::endpoint(tcp::v4(), port), true)); // reuse_addr diff --git a/src/webcc/http_session.cc b/src/webcc/http_session.cc index 8f4dc30..7ce44b3 100644 --- a/src/webcc/http_session.cc +++ b/src/webcc/http_session.cc @@ -1,5 +1,6 @@ #include "webcc/http_session.h" +#include // for move() #include #include "boost/asio/write.hpp" @@ -12,9 +13,9 @@ namespace webcc { HttpSession::HttpSession(boost::asio::ip::tcp::socket socket, HttpRequestHandler* handler) - : socket_(std::move(socket)) - , request_handler_(handler) - , request_parser_(&request_) { + : socket_(std::move(socket)), + request_handler_(handler), + request_parser_(&request_) { } void HttpSession::Start() { diff --git a/src/webcc/http_session.h b/src/webcc/http_session.h index 9cc11f7..efe12d7 100644 --- a/src/webcc/http_session.h +++ b/src/webcc/http_session.h @@ -3,6 +3,7 @@ #include #include +#include #include "boost/asio/ip/tcp.hpp" // for ip::tcp::socket diff --git a/src/webcc/logger.cc b/src/webcc/logger.cc index fafb0d5..d4be330 100644 --- a/src/webcc/logger.cc +++ b/src/webcc/logger.cc @@ -4,7 +4,8 @@ #include #include -#include +#include // NOLINT +#include #include "boost/thread.hpp" // For thread ID. diff --git a/src/webcc/rest_request_handler.cc b/src/webcc/rest_request_handler.cc index d4ce3d2..89faecd 100644 --- a/src/webcc/rest_request_handler.cc +++ b/src/webcc/rest_request_handler.cc @@ -1,5 +1,8 @@ #include "webcc/rest_request_handler.h" +#include // for move() +#include + #include "webcc/logger.h" #include "webcc/url.h" @@ -28,7 +31,6 @@ void RestRequestHandler::HandleSession(HttpSessionPtr session) { return; } - // TODO: Only for GET? UrlQuery query; Url::SplitQuery(url.query(), &query); @@ -39,7 +41,6 @@ void RestRequestHandler::HandleSession(HttpSessionPtr session) { session->request().content(), &content); if (!ok) { - // TODO: Could be other than kBadRequest. session->SendResponse(HttpStatus::kBadRequest); return; } diff --git a/src/webcc/rest_request_handler.h b/src/webcc/rest_request_handler.h index aa723da..281910f 100644 --- a/src/webcc/rest_request_handler.h +++ b/src/webcc/rest_request_handler.h @@ -3,6 +3,8 @@ // HTTP server handling REST requests. +#include + #include "webcc/http_request_handler.h" #include "webcc/rest_service_manager.h" diff --git a/src/webcc/rest_server.h b/src/webcc/rest_server.h index a04663e..82d3560 100644 --- a/src/webcc/rest_server.h +++ b/src/webcc/rest_server.h @@ -3,6 +3,8 @@ // HTTP server handling REST requests. +#include + #include "webcc/http_server.h" #include "webcc/rest_request_handler.h" #include "webcc/rest_service.h" diff --git a/src/webcc/rest_service.h b/src/webcc/rest_service.h index bcfc739..2fb1ec0 100644 --- a/src/webcc/rest_service.h +++ b/src/webcc/rest_service.h @@ -3,7 +3,7 @@ // NOTE: // The design of RestListService and RestDetailService is very similar to -// XxxListView and XxxDetailView in Django Rest Framework. +// XxxListView and XxxDetailView in Python Django Rest Framework. // Deriving from them instead of RestService can simplify your own REST services // a lot. But if you find the filtered parameters cannot meet your needs, feel // free to derive from RestService directly. @@ -19,7 +19,7 @@ namespace webcc { class UrlQuery; -//////////////////////////////////////////////////////////////////////////////// +// ----------------------------------------------------------------------------- // Base class for your REST service. class RestService { @@ -40,7 +40,7 @@ class RestService { typedef std::shared_ptr RestServicePtr; -//////////////////////////////////////////////////////////////////////////////// +// ----------------------------------------------------------------------------- class RestListService : public RestService { public: @@ -64,7 +64,7 @@ class RestListService : public RestService { } }; -//////////////////////////////////////////////////////////////////////////////// +// ----------------------------------------------------------------------------- class RestDetailService : public RestService { public: diff --git a/src/webcc/rest_service_manager.cc b/src/webcc/rest_service_manager.cc index 19051e3..626b2c2 100644 --- a/src/webcc/rest_service_manager.cc +++ b/src/webcc/rest_service_manager.cc @@ -23,10 +23,8 @@ bool RestServiceManager::AddService(RestServicePtr service, try { // Compile the regex. item.url_regex.assign(url, flags); - service_items_.push_back(std::move(item)); return true; - } catch (std::regex_error& e) { LOG_ERRO("URL is not a valid regular expression: %s", e.what()); return false; diff --git a/src/webcc/rest_service_manager.h b/src/webcc/rest_service_manager.h index 5f0a721..d631589 100644 --- a/src/webcc/rest_service_manager.h +++ b/src/webcc/rest_service_manager.h @@ -1,7 +1,9 @@ #ifndef WEBCC_REST_SERVICE_MANAGER_H_ #define WEBCC_REST_SERVICE_MANAGER_H_ -#include +#include // NOLINT +#include +#include // for move() #include #include "webcc/rest_service.h" diff --git a/src/webcc/soap_client.cc b/src/webcc/soap_client.cc index ea01cf2..7f7a430 100644 --- a/src/webcc/soap_client.cc +++ b/src/webcc/soap_client.cc @@ -1,6 +1,7 @@ #include "webcc/soap_client.h" #include +#include // for move() #include "webcc/http_client.h" #include "webcc/http_request.h" diff --git a/src/webcc/soap_message.cc b/src/webcc/soap_message.cc index a003112..1d64653 100644 --- a/src/webcc/soap_message.cc +++ b/src/webcc/soap_message.cc @@ -18,17 +18,18 @@ void SoapMessage::ToXml(std::string* xml_string) { pugi::xml_document xdoc; - // TODO: + // TODO(Adam): // When save with format_default, declaration will be generated // automatically but without encoding. // pugi::xml_node xdecl = xdoc.prepend_child(pugi::node_declaration); // xdecl.append_attribute("version").set_value("1.0"); - pugi::xml_node xroot = soap_xml::AddChild(xdoc, soapenv_ns_.name, "Envelope"); + pugi::xml_node xroot = soap_xml::AddChild(soapenv_ns_.name, "Envelope", + &xdoc); soap_xml::AddNSAttr(xroot, soapenv_ns_.name, soapenv_ns_.url); - pugi::xml_node xbody = soap_xml::AddChild(xroot, soapenv_ns_.name, "Body"); + pugi::xml_node xbody = soap_xml::AddChild(soapenv_ns_.name, "Body", &xroot); ToXmlBody(xbody); diff --git a/src/webcc/soap_request.cc b/src/webcc/soap_request.cc index ea7332b..0aa339b 100644 --- a/src/webcc/soap_request.cc +++ b/src/webcc/soap_request.cc @@ -24,11 +24,11 @@ const std::string& SoapRequest::GetParameter(const std::string& key) const { } void SoapRequest::ToXmlBody(pugi::xml_node xbody) { - pugi::xml_node xop = soap_xml::AddChild(xbody, service_ns_.name, operation_); + pugi::xml_node xop = soap_xml::AddChild(service_ns_.name, operation_, &xbody); soap_xml::AddNSAttr(xop, service_ns_.name, service_ns_.url); for (Parameter& p : parameters_) { - pugi::xml_node xparam = soap_xml::AddChild(xop, service_ns_.name, p.key()); + pugi::xml_node xparam = soap_xml::AddChild(service_ns_.name, p.key(), &xop); xparam.text().set(p.value().c_str()); } } diff --git a/src/webcc/soap_request.h b/src/webcc/soap_request.h index 7f75864..33bc305 100644 --- a/src/webcc/soap_request.h +++ b/src/webcc/soap_request.h @@ -1,6 +1,7 @@ #ifndef WEBCC_SOAP_REQUEST_H_ #define WEBCC_SOAP_REQUEST_H_ +#include #include #include "webcc/soap_message.h" diff --git a/src/webcc/soap_request_handler.cc b/src/webcc/soap_request_handler.cc index 564e4b3..4ec8b2c 100644 --- a/src/webcc/soap_request_handler.cc +++ b/src/webcc/soap_request_handler.cc @@ -1,5 +1,7 @@ #include "webcc/soap_request_handler.h" +#include // for move() + #include "webcc/logger.h" #include "webcc/soap_request.h" #include "webcc/soap_response.h" diff --git a/src/webcc/soap_request_handler.h b/src/webcc/soap_request_handler.h index 25fdf00..d711e6c 100644 --- a/src/webcc/soap_request_handler.h +++ b/src/webcc/soap_request_handler.h @@ -2,6 +2,7 @@ #define WEBCC_SOAP_REQUEST_HANDLER_H_ #include +#include #include "webcc/http_request_handler.h" diff --git a/src/webcc/soap_response.cc b/src/webcc/soap_response.cc index 38c5be8..383a1ef 100644 --- a/src/webcc/soap_response.cc +++ b/src/webcc/soap_response.cc @@ -6,14 +6,12 @@ namespace webcc { void SoapResponse::ToXmlBody(pugi::xml_node xbody) { - pugi::xml_node xop = soap_xml::AddChild(xbody, - service_ns_.name, - operation_ + "Response"); + pugi::xml_node xop = soap_xml::AddChild(service_ns_.name, + operation_ + "Response", &xbody); soap_xml::AddNSAttr(xop, service_ns_.name, service_ns_.url); - pugi::xml_node xresult = soap_xml::AddChild(xop, - service_ns_.name, - result_name_); + pugi::xml_node xresult = soap_xml::AddChild(service_ns_.name, result_name_, + &xop); xresult.text().set(result_.c_str()); } diff --git a/src/webcc/soap_response.h b/src/webcc/soap_response.h index 44ac008..887247d 100644 --- a/src/webcc/soap_response.h +++ b/src/webcc/soap_response.h @@ -1,6 +1,9 @@ #ifndef WEBCC_SOAP_RESPONSE_H_ #define WEBCC_SOAP_RESPONSE_H_ +#include +#include // for move() + #include "webcc/soap_message.h" namespace webcc { diff --git a/src/webcc/soap_server.h b/src/webcc/soap_server.h index 3e8d8af..200e9ad 100644 --- a/src/webcc/soap_server.h +++ b/src/webcc/soap_server.h @@ -3,6 +3,8 @@ // HTTP server handling SOAP requests. +#include + #include "webcc/soap_request_handler.h" #include "webcc/http_server.h" diff --git a/src/webcc/soap_xml.cc b/src/webcc/soap_xml.cc index c7e2506..98212ef 100644 --- a/src/webcc/soap_xml.cc +++ b/src/webcc/soap_xml.cc @@ -38,17 +38,18 @@ std::string GetNameNoPrefix(const pugi::xml_node& xnode) { return name; } -pugi::xml_node AddChild(pugi::xml_node& xnode, const std::string& ns, - const std::string& name) { - return xnode.append_child((ns + ":" + name).c_str()); +pugi::xml_node AddChild(const std::string& ns, const std::string& name, + pugi::xml_node* xnode) { + return xnode->append_child((ns + ":" + name).c_str()); } -pugi::xml_node GetChild(pugi::xml_node& xnode, const std::string& ns, +pugi::xml_node GetChild(const pugi::xml_node& xnode, const std::string& ns, const std::string& name) { return xnode.child((ns + ":" + name).c_str()); } -pugi::xml_node GetChildNoNS(pugi::xml_node& xnode, const std::string& name) { +pugi::xml_node GetChildNoNS(const pugi::xml_node& xnode, + const std::string& name) { pugi::xml_node xchild = xnode.first_child(); while (xchild) { std::string child_name = xchild.name(); @@ -80,7 +81,7 @@ void AddNSAttr(pugi::xml_node& xnode, const std::string& ns_name, AddAttr(xnode, "xmlns", ns_name, ns_url); } -std::string GetNSAttr(pugi::xml_node& xnode, const std::string& ns_name) { +std::string GetNSAttr(const pugi::xml_node& xnode, const std::string& ns_name) { std::string attr_name = "xmlns:" + ns_name; return xnode.attribute(attr_name.c_str()).as_string(); } diff --git a/src/webcc/soap_xml.h b/src/webcc/soap_xml.h index 0664ba4..8a143fb 100644 --- a/src/webcc/soap_xml.h +++ b/src/webcc/soap_xml.h @@ -26,14 +26,15 @@ std::string GetNameNoPrefix(const pugi::xml_node& xnode); // Add a child with the given name which is prefixed by a namespace. // E.g., AppendChild(xnode, "soapenv", "Envelope") will append a child with // name "soapenv:Envelope". -pugi::xml_node AddChild(pugi::xml_node& xnode, const std::string& ns, - const std::string& name); +pugi::xml_node AddChild(const std::string& ns, const std::string& name, + pugi::xml_node* xnode); -pugi::xml_node GetChild(pugi::xml_node& xnode, const std::string& ns, +pugi::xml_node GetChild(const pugi::xml_node& xnode, const std::string& ns, const std::string& name); // TODO: Remove -pugi::xml_node GetChildNoNS(pugi::xml_node& xnode, const std::string& name); +pugi::xml_node GetChildNoNS(const pugi::xml_node& xnode, + const std::string& name); // Add an attribute with the given name which is prefixed by a namespace. void AddAttr(pugi::xml_node& xnode, const std::string& ns, @@ -50,7 +51,8 @@ void AddNSAttr(pugi::xml_node& xnode, const std::string& ns_name, // Get namespace attribute value. // E.g., if the given namespace name is "soapenv", the value of // attribute "xmlns:soapenv" will be returned. -std::string GetNSAttr(pugi::xml_node& xnode, const std::string& ns_name); +std::string GetNSAttr(const pugi::xml_node& xnode, + const std::string& ns_name); // An XML writer writing to a referenced string. // Example: @@ -60,7 +62,7 @@ std::string GetNSAttr(pugi::xml_node& xnode, const std::string& ns_name); // XmlStrRefWriter writer(&xml_string); // xdoc.save(writer, "\t", pugi::format_default, pugi::encoding_utf8); class XmlStrRefWriter : public pugi::xml_writer { -public: + public: explicit XmlStrRefWriter(std::string* result) : result_(result) { result_->clear(); } @@ -69,7 +71,7 @@ public: result_->append(static_cast(data), size); } -private: + private: std::string* result_; }; diff --git a/src/webcc/url.cc b/src/webcc/url.cc index 54c322c..b5bda58 100644 --- a/src/webcc/url.cc +++ b/src/webcc/url.cc @@ -2,10 +2,11 @@ #include #include +#include // for move() namespace webcc { -//////////////////////////////////////////////////////////////////////////////// +// ----------------------------------------------------------------------------- // Helper functions to decode URL string. // Convert a hex character digit to a decimal character value. @@ -58,7 +59,7 @@ static bool Decode(const std::string& encoded, std::string* raw) { return true; } -//////////////////////////////////////////////////////////////////////////////// +// ----------------------------------------------------------------------------- UrlQuery::UrlQuery(const std::map& map) { for (auto& pair : map) { @@ -116,7 +117,7 @@ UrlQuery::ConstIterator UrlQuery::Find(const std::string& key) const { [&key](const Parameter& p) { return p.key() == key; }); } -//////////////////////////////////////////////////////////////////////////////// +// ----------------------------------------------------------------------------- Url::Url(const std::string& str, bool decode) { if (!decode || str.find('%') == std::string::npos) { @@ -128,7 +129,7 @@ Url::Url(const std::string& str, bool decode) { if (Decode(str, &decoded)) { Init(decoded); } else { - // TODO: Exception? + // TODO(Adam): Exception? Init(str); } } diff --git a/src/webcc/utility.cc b/src/webcc/utility.cc index c0c24d0..5e9c1b2 100644 --- a/src/webcc/utility.cc +++ b/src/webcc/utility.cc @@ -8,7 +8,7 @@ namespace webcc { // Print the resolved endpoints. // NOTE: Endpoint is one word, don't use "end point". -void DumpEndpoints(tcp::resolver::results_type& endpoints) { +void DumpEndpoints(const tcp::resolver::results_type& endpoints) { std::cout << "Endpoints: " << endpoints.size() << std::endl; tcp::resolver::results_type::iterator it = endpoints.begin(); diff --git a/src/webcc/utility.h b/src/webcc/utility.h index 1ff5e39..b49d3b8 100644 --- a/src/webcc/utility.h +++ b/src/webcc/utility.h @@ -7,7 +7,8 @@ namespace webcc { // Print the resolved endpoints. // NOTE: Endpoint is one word, don't use "end point". -void DumpEndpoints(boost::asio::ip::tcp::resolver::results_type& endpoints); +void DumpEndpoints( + const boost::asio::ip::tcp::resolver::results_type& endpoints); } // namespace webcc