Fix style warnings reported by cpplint.
This commit is contained in:
+24
-14
@@ -6,8 +6,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"directory": "/home/adam/github/webcc/build/src/webcc",
|
"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",
|
"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/common.cc"
|
"file": "/home/adam/github/webcc/src/webcc/globals.cc"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"directory": "/home/adam/github/webcc/build/src/webcc",
|
"directory": "/home/adam/github/webcc/build/src/webcc",
|
||||||
@@ -66,8 +66,18 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"directory": "/home/adam/github/webcc/build/src/webcc",
|
"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",
|
"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_server.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",
|
"directory": "/home/adam/github/webcc/build/src/webcc",
|
||||||
@@ -84,6 +94,16 @@
|
|||||||
"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/utility.cc.o -c /home/adam/github/webcc/src/webcc/utility.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/utility.cc.o -c /home/adam/github/webcc/src/webcc/utility.cc",
|
||||||
"file": "/home/adam/github/webcc/src/webcc/utility.cc"
|
"file": "/home/adam/github/webcc/src/webcc/utility.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_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_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",
|
"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",
|
"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",
|
||||||
@@ -99,16 +119,6 @@
|
|||||||
"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",
|
"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"
|
"file": "/home/adam/github/webcc/src/webcc/soap_response.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"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"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"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"directory": "/home/adam/github/webcc/build/src/webcc",
|
"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_client.cc.o -c /home/adam/github/webcc/src/webcc/soap_client.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_client.cc.o -c /home/adam/github/webcc/src/webcc/soap_client.cc",
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "webcc/globals.h"
|
#include "webcc/globals.h"
|
||||||
|
|
||||||
|
#include <utility> // for move()
|
||||||
|
|
||||||
namespace webcc {
|
namespace webcc {
|
||||||
|
|
||||||
// NOTE:
|
// NOTE:
|
||||||
|
|||||||
@@ -1,14 +1,9 @@
|
|||||||
#include "webcc/http_async_client.h"
|
#include "webcc/http_async_client.h"
|
||||||
|
|
||||||
#if WEBCC_DEBUG_OUTPUT
|
|
||||||
#include <iostream>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#include "boost/asio.hpp"
|
#include "boost/asio.hpp"
|
||||||
#else
|
#else
|
||||||
#include "boost/asio/connect.hpp"
|
#include "boost/asio/connect.hpp"
|
||||||
//#include "boost/asio/ip/tcp.hpp"
|
|
||||||
#include "boost/asio/read.hpp"
|
#include "boost/asio/read.hpp"
|
||||||
#include "boost/asio/write.hpp"
|
#include "boost/asio/write.hpp"
|
||||||
#endif
|
#endif
|
||||||
@@ -119,11 +114,6 @@ void HttpAsyncClient::HandleRead(boost::system::error_code ec,
|
|||||||
return;
|
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.
|
// Parse the response piece just read.
|
||||||
// If the content has been fully received, next time flag "finished_"
|
// If the content has been fully received, next time flag "finished_"
|
||||||
// will be set.
|
// will be set.
|
||||||
@@ -158,12 +148,6 @@ void HttpAsyncClient::HandleRead(boost::system::error_code ec,
|
|||||||
// return error;
|
// return error;
|
||||||
//}
|
//}
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//#if WEBCC_DEBUG_OUTPUT
|
|
||||||
// std::cout << std::endl;
|
|
||||||
// std::cout << "--- RESPONSE (PARSED) ---" << std::endl;
|
|
||||||
// std::cout << *response << std::endl;
|
|
||||||
//#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace webcc
|
} // namespace webcc
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
#include "webcc/http_client.h"
|
#include "webcc/http_client.h"
|
||||||
|
|
||||||
#include "boost/date_time/posix_time/posix_time.hpp"
|
#include <string>
|
||||||
#include "boost/lambda/bind.hpp"
|
|
||||||
#include "boost/lambda/lambda.hpp"
|
|
||||||
#include "boost/asio/connect.hpp"
|
#include "boost/asio/connect.hpp"
|
||||||
#include "boost/asio/read.hpp"
|
#include "boost/asio/read.hpp"
|
||||||
#include "boost/asio/write.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/logger.h"
|
||||||
#include "webcc/http_request.h"
|
#include "webcc/http_request.h"
|
||||||
@@ -26,10 +28,9 @@ static const int kReceiveMaxSeconds = 30;
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
HttpClient::HttpClient()
|
HttpClient::HttpClient()
|
||||||
: socket_(io_context_)
|
: socket_(io_context_),
|
||||||
, timeout_seconds_(kReceiveMaxSeconds)
|
timeout_seconds_(kReceiveMaxSeconds),
|
||||||
, deadline_timer_(io_context_) {
|
deadline_timer_(io_context_) {
|
||||||
|
|
||||||
deadline_timer_.expires_at(boost::posix_time::pos_infin);
|
deadline_timer_.expires_at(boost::posix_time::pos_infin);
|
||||||
|
|
||||||
// Start the persistent actor that checks for deadline expiry.
|
// Start the persistent actor that checks for deadline expiry.
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility> // for move()
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "webcc/globals.h"
|
#include "webcc/globals.h"
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,12 @@
|
|||||||
namespace webcc {
|
namespace webcc {
|
||||||
|
|
||||||
HttpParser::HttpParser(HttpMessage* message)
|
HttpParser::HttpParser(HttpMessage* message)
|
||||||
: message_(message)
|
: message_(message),
|
||||||
, content_length_(kInvalidLength)
|
content_length_(kInvalidLength),
|
||||||
, start_line_parsed_(false)
|
start_line_parsed_(false),
|
||||||
, content_length_parsed_(false)
|
content_length_parsed_(false),
|
||||||
, header_parsed_(false)
|
header_parsed_(false),
|
||||||
, finished_(false) {
|
finished_(false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Error HttpParser::Parse(const char* data, std::size_t len) {
|
Error HttpParser::Parse(const char* data, std::size_t len) {
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ protected:
|
|||||||
|
|
||||||
bool IsContentFull() const;
|
bool IsContentFull() const;
|
||||||
|
|
||||||
protected:
|
|
||||||
// The result HTTP message.
|
// The result HTTP message.
|
||||||
HttpMessage* message_;
|
HttpMessage* message_;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define WEBCC_HTTP_REQUEST_H_
|
#define WEBCC_HTTP_REQUEST_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "boost/asio/buffer.hpp" // for const_buffer
|
#include "boost/asio/buffer.hpp" // for const_buffer
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef WEBCC_HTTP_REQUEST_PARSER_H_
|
#ifndef WEBCC_HTTP_REQUEST_PARSER_H_
|
||||||
#define WEBCC_HTTP_REQUEST_PARSER_H_
|
#define WEBCC_HTTP_REQUEST_PARSER_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "webcc/http_parser.h"
|
#include "webcc/http_parser.h"
|
||||||
|
|
||||||
namespace webcc {
|
namespace webcc {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define WEBCC_HTTP_RESPONSE_H_
|
#define WEBCC_HTTP_RESPONSE_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "boost/asio/buffer.hpp" // for const_buffer
|
#include "boost/asio/buffer.hpp" // for const_buffer
|
||||||
|
|
||||||
|
|||||||
@@ -7,16 +7,15 @@
|
|||||||
namespace webcc {
|
namespace webcc {
|
||||||
|
|
||||||
HttpResponseParser::HttpResponseParser(HttpResponse* response)
|
HttpResponseParser::HttpResponseParser(HttpResponse* response)
|
||||||
: HttpParser(response)
|
: HttpParser(response), response_(response) {
|
||||||
, response_(response) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Error HttpResponseParser::ParseStartLine(const std::string& line) {
|
Error HttpResponseParser::ParseStartLine(const std::string& line) {
|
||||||
response_->set_start_line(line + "\r\n");
|
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) {
|
if (pos == std::string::npos) {
|
||||||
return kHttpStartLineError;
|
return kHttpStartLineError;
|
||||||
}
|
}
|
||||||
@@ -39,8 +38,6 @@ Error HttpResponseParser::ParseStartLine(const std::string& line) {
|
|||||||
return kHttpStartLineError;
|
return kHttpStartLineError;
|
||||||
}
|
}
|
||||||
|
|
||||||
off = pos + 1; // Skip space.
|
|
||||||
|
|
||||||
if (response_->status() != HttpStatus::kOK) {
|
if (response_->status() != HttpStatus::kOK) {
|
||||||
return kHttpStatusError;
|
return kHttpStatusError;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef WEBCC_HTTP_RESPONSE_PARSER_H_
|
#ifndef WEBCC_HTTP_RESPONSE_PARSER_H_
|
||||||
#define WEBCC_HTTP_RESPONSE_PARSER_H_
|
#define WEBCC_HTTP_RESPONSE_PARSER_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "webcc/http_parser.h"
|
#include "webcc/http_parser.h"
|
||||||
|
|
||||||
namespace webcc {
|
namespace webcc {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "webcc/http_server.h"
|
#include "webcc/http_server.h"
|
||||||
|
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "webcc/http_request_handler.h"
|
#include "webcc/http_request_handler.h"
|
||||||
#include "webcc/logger.h"
|
#include "webcc/logger.h"
|
||||||
@@ -12,13 +13,10 @@ using tcp = boost::asio::ip::tcp;
|
|||||||
namespace webcc {
|
namespace webcc {
|
||||||
|
|
||||||
HttpServer::HttpServer(unsigned short port, std::size_t workers)
|
HttpServer::HttpServer(unsigned short port, std::size_t workers)
|
||||||
: signals_(io_context_)
|
: signals_(io_context_) , workers_(workers) {
|
||||||
, workers_(workers) {
|
|
||||||
|
|
||||||
// Register to handle the signals that indicate when the server should exit.
|
// 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,
|
// 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.
|
// provided all registration for the specified signal is made through asio.
|
||||||
// TODO: Verify if this works for Windows.
|
|
||||||
signals_.add(SIGINT);
|
signals_.add(SIGINT);
|
||||||
signals_.add(SIGTERM);
|
signals_.add(SIGTERM);
|
||||||
#if defined(SIGQUIT)
|
#if defined(SIGQUIT)
|
||||||
@@ -32,7 +30,6 @@ HttpServer::HttpServer(unsigned short port, std::size_t workers)
|
|||||||
// For more details about SO_REUSEADDR, see:
|
// For more details about SO_REUSEADDR, see:
|
||||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms740621(v=vs.85).aspx
|
// 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/
|
// http://www.andy-pearce.com/blog/posts/2013/Feb/so_reuseaddr-on-windows/
|
||||||
// TODO: SO_EXCLUSIVEADDRUSE
|
|
||||||
acceptor_.reset(new tcp::acceptor(io_context_,
|
acceptor_.reset(new tcp::acceptor(io_context_,
|
||||||
tcp::endpoint(tcp::v4(), port),
|
tcp::endpoint(tcp::v4(), port),
|
||||||
true)); // reuse_addr
|
true)); // reuse_addr
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "webcc/http_session.h"
|
#include "webcc/http_session.h"
|
||||||
|
|
||||||
|
#include <utility> // for move()
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "boost/asio/write.hpp"
|
#include "boost/asio/write.hpp"
|
||||||
@@ -12,9 +13,9 @@ namespace webcc {
|
|||||||
|
|
||||||
HttpSession::HttpSession(boost::asio::ip::tcp::socket socket,
|
HttpSession::HttpSession(boost::asio::ip::tcp::socket socket,
|
||||||
HttpRequestHandler* handler)
|
HttpRequestHandler* handler)
|
||||||
: socket_(std::move(socket))
|
: socket_(std::move(socket)),
|
||||||
, request_handler_(handler)
|
request_handler_(handler),
|
||||||
, request_parser_(&request_) {
|
request_parser_(&request_) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpSession::Start() {
|
void HttpSession::Start() {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "boost/asio/ip/tcp.hpp" // for ip::tcp::socket
|
#include "boost/asio/ip/tcp.hpp" // for ip::tcp::socket
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -4,7 +4,8 @@
|
|||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
#include <mutex>
|
#include <mutex> // NOLINT
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "boost/thread.hpp" // For thread ID.
|
#include "boost/thread.hpp" // For thread ID.
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
#include "webcc/rest_request_handler.h"
|
#include "webcc/rest_request_handler.h"
|
||||||
|
|
||||||
|
#include <utility> // for move()
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "webcc/logger.h"
|
#include "webcc/logger.h"
|
||||||
#include "webcc/url.h"
|
#include "webcc/url.h"
|
||||||
|
|
||||||
@@ -28,7 +31,6 @@ void RestRequestHandler::HandleSession(HttpSessionPtr session) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Only for GET?
|
|
||||||
UrlQuery query;
|
UrlQuery query;
|
||||||
Url::SplitQuery(url.query(), &query);
|
Url::SplitQuery(url.query(), &query);
|
||||||
|
|
||||||
@@ -39,7 +41,6 @@ void RestRequestHandler::HandleSession(HttpSessionPtr session) {
|
|||||||
session->request().content(),
|
session->request().content(),
|
||||||
&content);
|
&content);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
// TODO: Could be other than kBadRequest.
|
|
||||||
session->SendResponse(HttpStatus::kBadRequest);
|
session->SendResponse(HttpStatus::kBadRequest);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
// HTTP server handling REST requests.
|
// HTTP server handling REST requests.
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "webcc/http_request_handler.h"
|
#include "webcc/http_request_handler.h"
|
||||||
#include "webcc/rest_service_manager.h"
|
#include "webcc/rest_service_manager.h"
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
// HTTP server handling REST requests.
|
// HTTP server handling REST requests.
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "webcc/http_server.h"
|
#include "webcc/http_server.h"
|
||||||
#include "webcc/rest_request_handler.h"
|
#include "webcc/rest_request_handler.h"
|
||||||
#include "webcc/rest_service.h"
|
#include "webcc/rest_service.h"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
// NOTE:
|
// NOTE:
|
||||||
// The design of RestListService and RestDetailService is very similar to
|
// 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
|
// 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
|
// a lot. But if you find the filtered parameters cannot meet your needs, feel
|
||||||
// free to derive from RestService directly.
|
// free to derive from RestService directly.
|
||||||
@@ -19,7 +19,7 @@ namespace webcc {
|
|||||||
|
|
||||||
class UrlQuery;
|
class UrlQuery;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
// Base class for your REST service.
|
// Base class for your REST service.
|
||||||
class RestService {
|
class RestService {
|
||||||
@@ -40,7 +40,7 @@ class RestService {
|
|||||||
|
|
||||||
typedef std::shared_ptr<RestService> RestServicePtr;
|
typedef std::shared_ptr<RestService> RestServicePtr;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class RestListService : public RestService {
|
class RestListService : public RestService {
|
||||||
public:
|
public:
|
||||||
@@ -64,7 +64,7 @@ class RestListService : public RestService {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class RestDetailService : public RestService {
|
class RestDetailService : public RestService {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -23,10 +23,8 @@ bool RestServiceManager::AddService(RestServicePtr service,
|
|||||||
try {
|
try {
|
||||||
// Compile the regex.
|
// Compile the regex.
|
||||||
item.url_regex.assign(url, flags);
|
item.url_regex.assign(url, flags);
|
||||||
|
|
||||||
service_items_.push_back(std::move(item));
|
service_items_.push_back(std::move(item));
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} catch (std::regex_error& e) {
|
} catch (std::regex_error& e) {
|
||||||
LOG_ERRO("URL is not a valid regular expression: %s", e.what());
|
LOG_ERRO("URL is not a valid regular expression: %s", e.what());
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
#ifndef WEBCC_REST_SERVICE_MANAGER_H_
|
#ifndef WEBCC_REST_SERVICE_MANAGER_H_
|
||||||
#define WEBCC_REST_SERVICE_MANAGER_H_
|
#define WEBCC_REST_SERVICE_MANAGER_H_
|
||||||
|
|
||||||
#include <regex>
|
#include <regex> // NOLINT
|
||||||
|
#include <string>
|
||||||
|
#include <utility> // for move()
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "webcc/rest_service.h"
|
#include "webcc/rest_service.h"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "webcc/soap_client.h"
|
#include "webcc/soap_client.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <utility> // for move()
|
||||||
|
|
||||||
#include "webcc/http_client.h"
|
#include "webcc/http_client.h"
|
||||||
#include "webcc/http_request.h"
|
#include "webcc/http_request.h"
|
||||||
|
|||||||
@@ -18,17 +18,18 @@ void SoapMessage::ToXml(std::string* xml_string) {
|
|||||||
|
|
||||||
pugi::xml_document xdoc;
|
pugi::xml_document xdoc;
|
||||||
|
|
||||||
// TODO:
|
// TODO(Adam):
|
||||||
// When save with format_default, declaration will be generated
|
// When save with format_default, declaration will be generated
|
||||||
// automatically but without encoding.
|
// automatically but without encoding.
|
||||||
// pugi::xml_node xdecl = xdoc.prepend_child(pugi::node_declaration);
|
// pugi::xml_node xdecl = xdoc.prepend_child(pugi::node_declaration);
|
||||||
// xdecl.append_attribute("version").set_value("1.0");
|
// 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);
|
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);
|
ToXmlBody(xbody);
|
||||||
|
|
||||||
|
|||||||
@@ -24,11 +24,11 @@ const std::string& SoapRequest::GetParameter(const std::string& key) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SoapRequest::ToXmlBody(pugi::xml_node xbody) {
|
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);
|
soap_xml::AddNSAttr(xop, service_ns_.name, service_ns_.url);
|
||||||
|
|
||||||
for (Parameter& p : parameters_) {
|
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());
|
xparam.text().set(p.value().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef WEBCC_SOAP_REQUEST_H_
|
#ifndef WEBCC_SOAP_REQUEST_H_
|
||||||
#define WEBCC_SOAP_REQUEST_H_
|
#define WEBCC_SOAP_REQUEST_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "webcc/soap_message.h"
|
#include "webcc/soap_message.h"
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "webcc/soap_request_handler.h"
|
#include "webcc/soap_request_handler.h"
|
||||||
|
|
||||||
|
#include <utility> // for move()
|
||||||
|
|
||||||
#include "webcc/logger.h"
|
#include "webcc/logger.h"
|
||||||
#include "webcc/soap_request.h"
|
#include "webcc/soap_request.h"
|
||||||
#include "webcc/soap_response.h"
|
#include "webcc/soap_response.h"
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define WEBCC_SOAP_REQUEST_HANDLER_H_
|
#define WEBCC_SOAP_REQUEST_HANDLER_H_
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "webcc/http_request_handler.h"
|
#include "webcc/http_request_handler.h"
|
||||||
|
|
||||||
|
|||||||
@@ -6,14 +6,12 @@
|
|||||||
namespace webcc {
|
namespace webcc {
|
||||||
|
|
||||||
void SoapResponse::ToXmlBody(pugi::xml_node xbody) {
|
void SoapResponse::ToXmlBody(pugi::xml_node xbody) {
|
||||||
pugi::xml_node xop = soap_xml::AddChild(xbody,
|
pugi::xml_node xop = soap_xml::AddChild(service_ns_.name,
|
||||||
service_ns_.name,
|
operation_ + "Response", &xbody);
|
||||||
operation_ + "Response");
|
|
||||||
soap_xml::AddNSAttr(xop, service_ns_.name, service_ns_.url);
|
soap_xml::AddNSAttr(xop, service_ns_.name, service_ns_.url);
|
||||||
|
|
||||||
pugi::xml_node xresult = soap_xml::AddChild(xop,
|
pugi::xml_node xresult = soap_xml::AddChild(service_ns_.name, result_name_,
|
||||||
service_ns_.name,
|
&xop);
|
||||||
result_name_);
|
|
||||||
xresult.text().set(result_.c_str());
|
xresult.text().set(result_.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
#ifndef WEBCC_SOAP_RESPONSE_H_
|
#ifndef WEBCC_SOAP_RESPONSE_H_
|
||||||
#define WEBCC_SOAP_RESPONSE_H_
|
#define WEBCC_SOAP_RESPONSE_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <utility> // for move()
|
||||||
|
|
||||||
#include "webcc/soap_message.h"
|
#include "webcc/soap_message.h"
|
||||||
|
|
||||||
namespace webcc {
|
namespace webcc {
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
// HTTP server handling SOAP requests.
|
// HTTP server handling SOAP requests.
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "webcc/soap_request_handler.h"
|
#include "webcc/soap_request_handler.h"
|
||||||
#include "webcc/http_server.h"
|
#include "webcc/http_server.h"
|
||||||
|
|
||||||
|
|||||||
@@ -38,17 +38,18 @@ std::string GetNameNoPrefix(const pugi::xml_node& xnode) {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
pugi::xml_node AddChild(pugi::xml_node& xnode, const std::string& ns,
|
pugi::xml_node AddChild(const std::string& ns, const std::string& name,
|
||||||
const std::string& name) {
|
pugi::xml_node* xnode) {
|
||||||
return xnode.append_child((ns + ":" + name).c_str());
|
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) {
|
const std::string& name) {
|
||||||
return xnode.child((ns + ":" + name).c_str());
|
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();
|
pugi::xml_node xchild = xnode.first_child();
|
||||||
while (xchild) {
|
while (xchild) {
|
||||||
std::string child_name = xchild.name();
|
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);
|
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;
|
std::string attr_name = "xmlns:" + ns_name;
|
||||||
return xnode.attribute(attr_name.c_str()).as_string();
|
return xnode.attribute(attr_name.c_str()).as_string();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
// Add a child with the given name which is prefixed by a namespace.
|
||||||
// E.g., AppendChild(xnode, "soapenv", "Envelope") will append a child with
|
// E.g., AppendChild(xnode, "soapenv", "Envelope") will append a child with
|
||||||
// name "soapenv:Envelope".
|
// name "soapenv:Envelope".
|
||||||
pugi::xml_node AddChild(pugi::xml_node& xnode, const std::string& ns,
|
pugi::xml_node AddChild(const std::string& ns, const std::string& name,
|
||||||
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);
|
const std::string& name);
|
||||||
|
|
||||||
// TODO: Remove
|
// 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.
|
// Add an attribute with the given name which is prefixed by a namespace.
|
||||||
void AddAttr(pugi::xml_node& xnode, const std::string& ns,
|
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.
|
// Get namespace attribute value.
|
||||||
// E.g., if the given namespace name is "soapenv", the value of
|
// E.g., if the given namespace name is "soapenv", the value of
|
||||||
// attribute "xmlns:soapenv" will be returned.
|
// 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.
|
// An XML writer writing to a referenced string.
|
||||||
// Example:
|
// Example:
|
||||||
|
|||||||
+5
-4
@@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <utility> // for move()
|
||||||
|
|
||||||
namespace webcc {
|
namespace webcc {
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
// -----------------------------------------------------------------------------
|
||||||
// Helper functions to decode URL string.
|
// Helper functions to decode URL string.
|
||||||
|
|
||||||
// Convert a hex character digit to a decimal character value.
|
// 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
UrlQuery::UrlQuery(const std::map<std::string, std::string>& map) {
|
UrlQuery::UrlQuery(const std::map<std::string, std::string>& map) {
|
||||||
for (auto& pair : 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; });
|
[&key](const Parameter& p) { return p.key() == key; });
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
Url::Url(const std::string& str, bool decode) {
|
Url::Url(const std::string& str, bool decode) {
|
||||||
if (!decode || str.find('%') == std::string::npos) {
|
if (!decode || str.find('%') == std::string::npos) {
|
||||||
@@ -128,7 +129,7 @@ Url::Url(const std::string& str, bool decode) {
|
|||||||
if (Decode(str, &decoded)) {
|
if (Decode(str, &decoded)) {
|
||||||
Init(decoded);
|
Init(decoded);
|
||||||
} else {
|
} else {
|
||||||
// TODO: Exception?
|
// TODO(Adam): Exception?
|
||||||
Init(str);
|
Init(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace webcc {
|
|||||||
|
|
||||||
// Print the resolved endpoints.
|
// Print the resolved endpoints.
|
||||||
// NOTE: Endpoint is one word, don't use "end point".
|
// 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;
|
std::cout << "Endpoints: " << endpoints.size() << std::endl;
|
||||||
|
|
||||||
tcp::resolver::results_type::iterator it = endpoints.begin();
|
tcp::resolver::results_type::iterator it = endpoints.begin();
|
||||||
|
|||||||
+2
-1
@@ -7,7 +7,8 @@ namespace webcc {
|
|||||||
|
|
||||||
// Print the resolved endpoints.
|
// Print the resolved endpoints.
|
||||||
// NOTE: Endpoint is one word, don't use "end point".
|
// 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
|
} // namespace webcc
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user