Add namespace around all files
This commit is contained in:
+14
-11
@@ -10,7 +10,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace http
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
|
||||
Connection::Connection(boost::asio::io_service &io_service, RequestHandler &handler)
|
||||
@@ -38,14 +40,14 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t
|
||||
}
|
||||
|
||||
// no error detected, let's parse the request
|
||||
compression_type compression_type(no_compression);
|
||||
osrm::tribool result;
|
||||
http::compression_type compression_type(http::no_compression);
|
||||
util::tribool result;
|
||||
std::tie(result, compression_type) =
|
||||
request_parser.parse(current_request, incoming_data_buffer.data(),
|
||||
incoming_data_buffer.data() + bytes_transferred);
|
||||
|
||||
// the request has been parsed
|
||||
if (result == osrm::tribool::yes)
|
||||
if (result == util::tribool::yes)
|
||||
{
|
||||
current_request.endpoint = TCP_socket.remote_endpoint().address();
|
||||
request_handler.handle_request(current_request, current_reply);
|
||||
@@ -56,7 +58,7 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t
|
||||
// compress the result w/ gzip/deflate if requested
|
||||
switch (compression_type)
|
||||
{
|
||||
case deflate_rfc1951:
|
||||
case http::deflate_rfc1951:
|
||||
// use deflate for compression
|
||||
current_reply.headers.insert(current_reply.headers.begin(),
|
||||
{"Content-Encoding", "deflate"});
|
||||
@@ -65,7 +67,7 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t
|
||||
output_buffer = current_reply.headers_to_buffers();
|
||||
output_buffer.push_back(boost::asio::buffer(compressed_output));
|
||||
break;
|
||||
case gzip_rfc1952:
|
||||
case http::gzip_rfc1952:
|
||||
// use gzip for compression
|
||||
current_reply.headers.insert(current_reply.headers.begin(),
|
||||
{"Content-Encoding", "gzip"});
|
||||
@@ -74,7 +76,7 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t
|
||||
output_buffer = current_reply.headers_to_buffers();
|
||||
output_buffer.push_back(boost::asio::buffer(compressed_output));
|
||||
break;
|
||||
case no_compression:
|
||||
case http::no_compression:
|
||||
// don't use any compression
|
||||
current_reply.set_uncompressed_size();
|
||||
output_buffer = current_reply.to_buffers();
|
||||
@@ -86,9 +88,9 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t
|
||||
strand.wrap(boost::bind(&Connection::handle_write, this->shared_from_this(),
|
||||
boost::asio::placeholders::error)));
|
||||
}
|
||||
else if (result == osrm::tribool::no)
|
||||
else if (result == util::tribool::no)
|
||||
{ // request is not parseable
|
||||
current_reply = reply::stock_reply(reply::bad_request);
|
||||
current_reply = http::reply::stock_reply(http::reply::bad_request);
|
||||
|
||||
boost::asio::async_write(
|
||||
TCP_socket, current_reply.to_buffers(),
|
||||
@@ -118,14 +120,14 @@ void Connection::handle_write(const boost::system::error_code &error)
|
||||
}
|
||||
|
||||
std::vector<char> Connection::compress_buffers(const std::vector<char> &uncompressed_data,
|
||||
const compression_type compression_type)
|
||||
const http::compression_type compression_type)
|
||||
{
|
||||
boost::iostreams::gzip_params compression_parameters;
|
||||
|
||||
// there's a trade-off between speed and size. speed wins
|
||||
compression_parameters.level = boost::iostreams::zlib::best_speed;
|
||||
// check which compression flavor is used
|
||||
if (deflate_rfc1951 == compression_type)
|
||||
if (http::deflate_rfc1951 == compression_type)
|
||||
{
|
||||
compression_parameters.noheader = true;
|
||||
}
|
||||
@@ -141,3 +143,4 @@ std::vector<char> Connection::compress_buffers(const std::vector<char> &uncompre
|
||||
return compressed_data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
namespace http
|
||||
{
|
||||
|
||||
@@ -101,3 +105,5 @@ boost::asio::const_buffer reply::status_to_buffer(const reply::status_type statu
|
||||
|
||||
reply::reply() : status(ok) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,22 +20,27 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
|
||||
RequestHandler::RequestHandler() : routing_machine(nullptr) {}
|
||||
|
||||
void RequestHandler::handle_request(const http::request ¤t_request,
|
||||
http::reply ¤t_reply)
|
||||
{
|
||||
osrm::json::Object json_result;
|
||||
util::json::Object json_result;
|
||||
|
||||
// parse command
|
||||
try
|
||||
{
|
||||
std::string request_string;
|
||||
URIDecode(current_request.uri, request_string);
|
||||
util::URIDecode(current_request.uri, request_string);
|
||||
|
||||
// deactivated as GCC apparently does not implement that, not even in 4.9
|
||||
// std::time_t t = std::time(nullptr);
|
||||
// SimpleLogger().Write() << std::put_time(std::localtime(&t), "%m-%d-%Y %H:%M:%S") <<
|
||||
// util::SimpleLogger().Write() << std::put_time(std::localtime(&t), "%m-%d-%Y %H:%M:%S") <<
|
||||
// " " << current_request.endpoint.to_string() << " " <<
|
||||
// current_request.referrer << ( 0 == current_request.referrer.length() ? "- " :" ") <<
|
||||
// current_request.agent << ( 0 == current_request.agent.length() ? "- " :" ") <<
|
||||
@@ -48,7 +53,7 @@ void RequestHandler::handle_request(const http::request ¤t_request,
|
||||
time_stamp = localtime(<ime);
|
||||
|
||||
// log timestamp
|
||||
SimpleLogger().Write() << (time_stamp->tm_mday < 10 ? "0" : "") << time_stamp->tm_mday
|
||||
util::SimpleLogger().Write() << (time_stamp->tm_mday < 10 ? "0" : "") << time_stamp->tm_mday
|
||||
<< "-" << (time_stamp->tm_mon + 1 < 10 ? "0" : "")
|
||||
<< (time_stamp->tm_mon + 1) << "-" << 1900 + time_stamp->tm_year
|
||||
<< " " << (time_stamp->tm_hour < 10 ? "0" : "")
|
||||
@@ -61,7 +66,7 @@ void RequestHandler::handle_request(const http::request ¤t_request,
|
||||
<< (0 == current_request.agent.length() ? "- " : " ")
|
||||
<< request_string;
|
||||
|
||||
RouteParameters route_parameters;
|
||||
engine::RouteParameters route_parameters;
|
||||
APIGrammarParser api_parser(&route_parameters);
|
||||
|
||||
auto api_iterator = request_string.begin();
|
||||
@@ -116,7 +121,7 @@ void RequestHandler::handle_request(const http::request ¤t_request,
|
||||
std::to_string(current_reply.content.size()));
|
||||
if ("gpx" == route_parameters.output_format)
|
||||
{ // gpx file
|
||||
osrm::json::gpx_render(current_reply.content, json_result.values["route"]);
|
||||
util::json::gpx_render(current_reply.content, json_result.values["route"]);
|
||||
current_reply.headers.emplace_back("Content-Type",
|
||||
"application/gpx+xml; charset=UTF-8");
|
||||
current_reply.headers.emplace_back("Content-Disposition",
|
||||
@@ -124,14 +129,14 @@ void RequestHandler::handle_request(const http::request ¤t_request,
|
||||
}
|
||||
else if (route_parameters.jsonp_parameter.empty())
|
||||
{ // json file
|
||||
osrm::json::render(current_reply.content, json_result);
|
||||
util::json::render(current_reply.content, json_result);
|
||||
current_reply.headers.emplace_back("Content-Type", "application/json; charset=UTF-8");
|
||||
current_reply.headers.emplace_back("Content-Disposition",
|
||||
"inline; filename=\"response.json\"");
|
||||
}
|
||||
else
|
||||
{ // jsonp
|
||||
osrm::json::render(current_reply.content, json_result);
|
||||
util::json::render(current_reply.content, json_result);
|
||||
current_reply.headers.emplace_back("Content-Type", "text/javascript; charset=UTF-8");
|
||||
current_reply.headers.emplace_back("Content-Disposition",
|
||||
"inline; filename=\"response.js\"");
|
||||
@@ -145,9 +150,11 @@ void RequestHandler::handle_request(const http::request ¤t_request,
|
||||
{
|
||||
current_reply = http::reply::stock_reply(http::reply::internal_server_error);
|
||||
;
|
||||
SimpleLogger().Write(logWARNING) << "[server error] code: " << e.what()
|
||||
util::SimpleLogger().Write(logWARNING) << "[server error] code: " << e.what()
|
||||
<< ", uri: " << current_request.uri;
|
||||
}
|
||||
}
|
||||
|
||||
void RequestHandler::RegisterRoutingMachine(OSRM *osrm) { routing_machine = osrm; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,197 +10,199 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace http
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
|
||||
RequestParser::RequestParser()
|
||||
: state(internal_state::method_start), current_header({"", ""}),
|
||||
selected_compression(no_compression), is_post_header(false), content_length(0)
|
||||
selected_compression(http::no_compression), is_post_header(false), content_length(0)
|
||||
{
|
||||
}
|
||||
|
||||
std::tuple<osrm::tribool, compression_type>
|
||||
RequestParser::parse(request ¤t_request, char *begin, char *end)
|
||||
std::tuple<util::tribool, http::compression_type>
|
||||
RequestParser::parse(http::request ¤t_request, char *begin, char *end)
|
||||
{
|
||||
while (begin != end)
|
||||
{
|
||||
osrm::tribool result = consume(current_request, *begin++);
|
||||
if (result != osrm::tribool::indeterminate)
|
||||
util::tribool result = consume(current_request, *begin++);
|
||||
if (result != util::tribool::indeterminate)
|
||||
{
|
||||
return std::make_tuple(result, selected_compression);
|
||||
}
|
||||
}
|
||||
osrm::tribool result = osrm::tribool::indeterminate;
|
||||
util::tribool result = util::tribool::indeterminate;
|
||||
|
||||
if (state == internal_state::post_request && content_length <= 0)
|
||||
{
|
||||
result = osrm::tribool::yes;
|
||||
result = util::tribool::yes;
|
||||
}
|
||||
return std::make_tuple(result, selected_compression);
|
||||
}
|
||||
|
||||
osrm::tribool RequestParser::consume(request ¤t_request, const char input)
|
||||
util::tribool RequestParser::consume(http::request ¤t_request, const char input)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case internal_state::method_start:
|
||||
if (!is_char(input) || is_CTL(input) || is_special(input))
|
||||
{
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
}
|
||||
if (input == 'P')
|
||||
{
|
||||
state = internal_state::post_O;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
state = internal_state::method;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
case internal_state::post_O:
|
||||
if (input == 'O')
|
||||
{
|
||||
state = internal_state::post_S;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::post_S:
|
||||
if (input == 'S')
|
||||
{
|
||||
state = internal_state::post_T;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::post_T:
|
||||
if (input == 'T')
|
||||
{
|
||||
is_post_header = true;
|
||||
state = internal_state::method;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::post_request:
|
||||
current_request.uri.push_back(input);
|
||||
--content_length;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
case internal_state::method:
|
||||
if (input == ' ')
|
||||
{
|
||||
state = internal_state::uri;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
if (!is_char(input) || is_CTL(input) || is_special(input))
|
||||
{
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
}
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
case internal_state::uri_start:
|
||||
if (is_CTL(input))
|
||||
{
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
}
|
||||
state = internal_state::uri;
|
||||
current_request.uri.push_back(input);
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
case internal_state::uri:
|
||||
if (input == ' ')
|
||||
{
|
||||
state = internal_state::http_version_h;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
if (is_CTL(input))
|
||||
{
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
}
|
||||
current_request.uri.push_back(input);
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
case internal_state::http_version_h:
|
||||
if (input == 'H')
|
||||
{
|
||||
state = internal_state::http_version_t_1;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::http_version_t_1:
|
||||
if (input == 'T')
|
||||
{
|
||||
state = internal_state::http_version_t_2;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::http_version_t_2:
|
||||
if (input == 'T')
|
||||
{
|
||||
state = internal_state::http_version_p;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::http_version_p:
|
||||
if (input == 'P')
|
||||
{
|
||||
state = internal_state::http_version_slash;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::http_version_slash:
|
||||
if (input == '/')
|
||||
{
|
||||
state = internal_state::http_version_major_start;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::http_version_major_start:
|
||||
if (is_digit(input))
|
||||
{
|
||||
state = internal_state::http_version_major;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::http_version_major:
|
||||
if (input == '.')
|
||||
{
|
||||
state = internal_state::http_version_minor_start;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
if (is_digit(input))
|
||||
{
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::http_version_minor_start:
|
||||
if (is_digit(input))
|
||||
{
|
||||
state = internal_state::http_version_minor;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::http_version_minor:
|
||||
if (input == '\r')
|
||||
{
|
||||
state = internal_state::expecting_newline_1;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
if (is_digit(input))
|
||||
{
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::expecting_newline_1:
|
||||
if (input == '\n')
|
||||
{
|
||||
state = internal_state::header_line_start;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::header_line_start:
|
||||
if (boost::iequals(current_header.name, "Accept-Encoding"))
|
||||
{
|
||||
/* giving gzip precedence over deflate */
|
||||
if (boost::icontains(current_header.value, "deflate"))
|
||||
{
|
||||
selected_compression = deflate_rfc1951;
|
||||
selected_compression = http::deflate_rfc1951;
|
||||
}
|
||||
if (boost::icontains(current_header.value, "gzip"))
|
||||
{
|
||||
selected_compression = gzip_rfc1952;
|
||||
selected_compression = http::gzip_rfc1952;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,77 +230,77 @@ osrm::tribool RequestParser::consume(request ¤t_request, const char input)
|
||||
{
|
||||
if (!boost::icontains(current_header.value, "application/x-www-form-urlencoded"))
|
||||
{
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
}
|
||||
}
|
||||
|
||||
if (input == '\r')
|
||||
{
|
||||
state = internal_state::expecting_newline_3;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
if (!is_char(input) || is_CTL(input) || is_special(input))
|
||||
{
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
}
|
||||
state = internal_state::header_name;
|
||||
current_header.clear();
|
||||
current_header.name.push_back(input);
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
case internal_state::header_lws:
|
||||
if (input == '\r')
|
||||
{
|
||||
state = internal_state::expecting_newline_2;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
if (input == ' ' || input == '\t')
|
||||
{
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
if (is_CTL(input))
|
||||
{
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
}
|
||||
state = internal_state::header_value;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
case internal_state::header_name:
|
||||
if (input == ':')
|
||||
{
|
||||
state = internal_state::space_before_header_value;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
if (!is_char(input) || is_CTL(input) || is_special(input))
|
||||
{
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
}
|
||||
current_header.name.push_back(input);
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
case internal_state::space_before_header_value:
|
||||
if (input == ' ')
|
||||
{
|
||||
state = internal_state::header_value;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::header_value:
|
||||
if (input == '\r')
|
||||
{
|
||||
state = internal_state::expecting_newline_2;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
if (is_CTL(input))
|
||||
{
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
}
|
||||
current_header.value.push_back(input);
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
case internal_state::expecting_newline_2:
|
||||
if (input == '\n')
|
||||
{
|
||||
state = internal_state::header_line_start;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::expecting_newline_3:
|
||||
if (input == '\n')
|
||||
{
|
||||
@@ -309,13 +311,13 @@ osrm::tribool RequestParser::consume(request ¤t_request, const char input)
|
||||
current_request.uri.push_back('?');
|
||||
}
|
||||
state = internal_state::post_request;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::yes;
|
||||
return util::tribool::yes;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
default: // should never be reached
|
||||
return input == '\n' ? osrm::tribool::yes : osrm::tribool::no;
|
||||
return input == '\n' ? util::tribool::yes : util::tribool::no;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,3 +365,4 @@ bool RequestParser::is_digit(const int character) const
|
||||
return character >= '0' && character <= '9';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user