untangle server and http components
This commit is contained in:
parent
d538c35532
commit
dc4a3e9b89
@ -40,23 +40,24 @@ file( GLOB PrepareGlob Contractor/*.cpp )
|
|||||||
set( PrepareSources prepare.cpp ${PrepareGlob} )
|
set( PrepareSources prepare.cpp ${PrepareGlob} )
|
||||||
add_executable( osrm-prepare ${PrepareSources} )
|
add_executable( osrm-prepare ${PrepareSources} )
|
||||||
|
|
||||||
add_executable(osrm-routed routed.cpp)
|
|
||||||
set_target_properties(osrm-routed PROPERTIES COMPILE_FLAGS -DROUTED)
|
|
||||||
add_executable(osrm-datastore datastore.cpp)
|
|
||||||
|
|
||||||
file(GLOB ServerGlob Server/*.cpp)
|
file(GLOB ServerGlob Server/*.cpp)
|
||||||
file(GLOB DescriptorGlob Descriptors/*.cpp)
|
file(GLOB DescriptorGlob Descriptors/*.cpp)
|
||||||
file(GLOB DatastructureGlob DataStructures/*.cpp)
|
file(GLOB DatastructureGlob DataStructures/*.cpp)
|
||||||
file(GLOB AlgorithmGlob Algorithms/*.cpp)
|
file(GLOB AlgorithmGlob Algorithms/*.cpp)
|
||||||
|
file(GLOB HttpGlob Server/Http/*.cpp)
|
||||||
file(GLOB LibOSRMGlob Library/*.cpp)
|
file(GLOB LibOSRMGlob Library/*.cpp)
|
||||||
|
|
||||||
set(OSRMSources ${LibOSRMGlob} ${DescriptorGlob} ${DatastructureGlob} ${AlgorithmGlob} ${ServerGlob})
|
set(OSRMSources ${LibOSRMGlob} ${DescriptorGlob} ${DatastructureGlob} ${AlgorithmGlob} ${HttpGlob})
|
||||||
add_library( OSRM SHARED ${OSRMSources} )
|
add_library( OSRM SHARED ${OSRMSources} )
|
||||||
add_library( UUID STATIC Util/UUID.cpp )
|
add_library( UUID STATIC Util/UUID.cpp )
|
||||||
add_library( GITDESCRIPTION STATIC Util/GitDescription.cpp )
|
add_library( GITDESCRIPTION STATIC Util/GitDescription.cpp )
|
||||||
add_dependencies( UUID UUIDConfigure )
|
add_dependencies( UUID UUIDConfigure )
|
||||||
add_dependencies( GITDESCRIPTION GIT_DESCRIPTION )
|
add_dependencies( GITDESCRIPTION GIT_DESCRIPTION )
|
||||||
|
|
||||||
|
add_executable(osrm-routed routed.cpp ${ServerGlob})
|
||||||
|
set_target_properties(osrm-routed PROPERTIES COMPILE_FLAGS -DROUTED)
|
||||||
|
add_executable(osrm-datastore datastore.cpp)
|
||||||
|
|
||||||
# Check the release mode
|
# Check the release mode
|
||||||
if(NOT CMAKE_BUILD_TYPE MATCHES Debug)
|
if(NOT CMAKE_BUILD_TYPE MATCHES Debug)
|
||||||
set(CMAKE_BUILD_TYPE Release)
|
set(CMAKE_BUILD_TYPE Release)
|
||||||
|
@ -45,7 +45,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include "../Util/OSRMException.h"
|
#include "../Util/OSRMException.h"
|
||||||
// #include "../Util/ProgramOptions.h"
|
// #include "../Util/ProgramOptions.h"
|
||||||
#include "../Util/SimpleLogger.h"
|
#include "../Util/SimpleLogger.h"
|
||||||
#include "../Server/BasicDatastructures.h"
|
// #include "../Server/Http/BasicDatastructures.h"
|
||||||
|
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
@ -29,8 +29,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#define BASEPLUGIN_H_
|
#define BASEPLUGIN_H_
|
||||||
|
|
||||||
#include "../DataStructures/Coordinate.h"
|
#include "../DataStructures/Coordinate.h"
|
||||||
#include "../Server/BasicDatastructures.h"
|
#include "../Server/Http/BasicDatastructures.h"
|
||||||
#include "../Server/Reply.h"
|
#include "../Server/Http/Reply.h"
|
||||||
#include "../Server/DataStructures/RouteParameters.h"
|
#include "../Server/DataStructures/RouteParameters.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#ifndef CONNECTION_H
|
#ifndef CONNECTION_H
|
||||||
#define CONNECTION_H
|
#define CONNECTION_H
|
||||||
|
|
||||||
#include "BasicDatastructures.h"
|
#include "Http/BasicDatastructures.h"
|
||||||
#include "RequestHandler.h"
|
#include "RequestHandler.h"
|
||||||
#include "RequestParser.h"
|
#include "RequestParser.h"
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#define REQUEST_HANDLER_H
|
#define REQUEST_HANDLER_H
|
||||||
|
|
||||||
#include "APIGrammar.h"
|
#include "APIGrammar.h"
|
||||||
#include "BasicDatastructures.h"
|
|
||||||
#include "DataStructures/RouteParameters.h"
|
#include "DataStructures/RouteParameters.h"
|
||||||
|
#include "Http/Request.h"
|
||||||
#include "../Library/OSRM.h"
|
#include "../Library/OSRM.h"
|
||||||
#include "../Util/SimpleLogger.h"
|
#include "../Util/SimpleLogger.h"
|
||||||
#include "../Util/StringUtil.h"
|
#include "../Util/StringUtil.h"
|
||||||
|
@ -28,7 +28,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#ifndef REQUEST_PARSER_H
|
#ifndef REQUEST_PARSER_H
|
||||||
#define REQUEST_PARSER_H
|
#define REQUEST_PARSER_H
|
||||||
|
|
||||||
#include "BasicDatastructures.h"
|
#include "Http/BasicDatastructures.h"
|
||||||
|
#include "Http/Header.h"
|
||||||
|
#include "Http/Request.h"
|
||||||
|
|
||||||
#include <boost/logic/tribool.hpp>
|
#include <boost/logic/tribool.hpp>
|
||||||
#include <boost/tuple/tuple.hpp>
|
#include <boost/tuple/tuple.hpp>
|
||||||
@ -37,235 +39,21 @@ namespace http {
|
|||||||
|
|
||||||
class RequestParser {
|
class RequestParser {
|
||||||
public:
|
public:
|
||||||
RequestParser() : state_(method_start) { }
|
RequestParser();
|
||||||
void Reset() { state_ = method_start; }
|
void Reset();
|
||||||
|
|
||||||
boost::tuple<boost::tribool, char*> Parse(Request& req, char* begin, char* end, CompressionType * compressionType) {
|
boost::tuple<boost::tribool, char*> Parse(Request& req, char* begin, char* end, CompressionType * compressionType);
|
||||||
while (begin != end) {
|
|
||||||
boost::tribool result = consume(req, *begin++, compressionType);
|
|
||||||
if (result || !result){
|
|
||||||
return boost::make_tuple(result, begin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
boost::tribool result = boost::indeterminate;
|
|
||||||
return boost::make_tuple(result, begin);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
boost::tribool consume(Request& req, char input, CompressionType * compressionType) {
|
boost::tribool consume(Request& req, char input, CompressionType * compressionType);
|
||||||
switch (state_) {
|
|
||||||
case method_start:
|
|
||||||
if (!isChar(input) || isCTL(input) || isTSpecial(input)) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
state_ = method;
|
|
||||||
return boost::indeterminate;
|
|
||||||
}
|
|
||||||
case method:
|
|
||||||
if (input == ' ') {
|
|
||||||
state_ = uri;
|
|
||||||
return boost::indeterminate;
|
|
||||||
} else if (!isChar(input) || isCTL(input) || isTSpecial(input)) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return boost::indeterminate;
|
|
||||||
}
|
|
||||||
case uri_start:
|
|
||||||
if (isCTL(input)) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
state_ = uri;
|
|
||||||
req.uri.push_back(input);
|
|
||||||
return boost::indeterminate;
|
|
||||||
}
|
|
||||||
case uri:
|
|
||||||
if (input == ' ') {
|
|
||||||
state_ = http_version_h;
|
|
||||||
return boost::indeterminate;
|
|
||||||
} else if (isCTL(input)) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
req.uri.push_back(input);
|
|
||||||
return boost::indeterminate;
|
|
||||||
}
|
|
||||||
case http_version_h:
|
|
||||||
if (input == 'H') {
|
|
||||||
state_ = http_version_t_1;
|
|
||||||
return boost::indeterminate;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
case http_version_t_1:
|
|
||||||
if (input == 'T') {
|
|
||||||
state_ = http_version_t_2;
|
|
||||||
return boost::indeterminate;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
case http_version_t_2:
|
|
||||||
if (input == 'T') {
|
|
||||||
state_ = http_version_p;
|
|
||||||
return boost::indeterminate;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
case http_version_p:
|
|
||||||
if (input == 'P') {
|
|
||||||
state_ = http_version_slash;
|
|
||||||
return boost::indeterminate;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
case http_version_slash:
|
|
||||||
if (input == '/') {
|
|
||||||
state_ = http_version_major_start;
|
|
||||||
return boost::indeterminate;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
case http_version_major_start:
|
|
||||||
if (isDigit(input)) {
|
|
||||||
state_ = http_version_major;
|
|
||||||
return boost::indeterminate;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
case http_version_major:
|
|
||||||
if (input == '.') {
|
|
||||||
state_ = http_version_minor_start;
|
|
||||||
return boost::indeterminate;
|
|
||||||
} else if (isDigit(input)) {
|
|
||||||
return boost::indeterminate;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
case http_version_minor_start:
|
|
||||||
if (isDigit(input)) {
|
|
||||||
state_ = http_version_minor;
|
|
||||||
return boost::indeterminate;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
case http_version_minor:
|
|
||||||
if (input == '\r') {
|
|
||||||
state_ = expecting_newline_1;
|
|
||||||
return boost::indeterminate;
|
|
||||||
} else if (isDigit(input)) {
|
|
||||||
return boost::indeterminate;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
case expecting_newline_1:
|
|
||||||
if (input == '\n') {
|
|
||||||
state_ = header_line_start;
|
|
||||||
return boost::indeterminate;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
case header_line_start:
|
|
||||||
if(header.name == "Accept-Encoding") {
|
|
||||||
/* giving gzip precedence over deflate */
|
|
||||||
if(header.value.find("deflate") != std::string::npos)
|
|
||||||
*compressionType = deflateRFC1951;
|
|
||||||
if(header.value.find("gzip") != std::string::npos)
|
|
||||||
*compressionType = gzipRFC1952;
|
|
||||||
}
|
|
||||||
|
|
||||||
if("Referer" == header.name)
|
inline bool isChar(int c);
|
||||||
req.referrer = header.value;
|
|
||||||
|
|
||||||
if("User-Agent" == header.name)
|
inline bool isCTL(int c);
|
||||||
req.agent = header.value;
|
|
||||||
|
|
||||||
if (input == '\r') {
|
inline bool isTSpecial(int c);
|
||||||
state_ = expecting_newline_3;
|
|
||||||
return boost::indeterminate;
|
|
||||||
} else if (!isChar(input) || isCTL(input) || isTSpecial(input)) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
state_ = header_name;
|
|
||||||
header.Clear();
|
|
||||||
header.name.push_back(input);
|
|
||||||
return boost::indeterminate;
|
|
||||||
}
|
|
||||||
case header_lws:
|
|
||||||
if (input == '\r') {
|
|
||||||
state_ = expecting_newline_2;
|
|
||||||
return boost::indeterminate;
|
|
||||||
} else if (input == ' ' || input == '\t') {
|
|
||||||
return boost::indeterminate;
|
|
||||||
}
|
|
||||||
else if (isCTL(input)) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
state_ = header_value;
|
|
||||||
return boost::indeterminate;
|
|
||||||
}
|
|
||||||
case header_name:
|
|
||||||
if (input == ':') {
|
|
||||||
state_ = space_before_header_value;
|
|
||||||
return boost::indeterminate;
|
|
||||||
} else if (!isChar(input) || isCTL(input) || isTSpecial(input)) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
header.name.push_back(input);
|
|
||||||
return boost::indeterminate;
|
|
||||||
}
|
|
||||||
case space_before_header_value:
|
|
||||||
if (input == ' ') {
|
|
||||||
state_ = header_value;
|
|
||||||
return boost::indeterminate;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
case header_value:
|
|
||||||
if (input == '\r') {
|
|
||||||
state_ = expecting_newline_2;
|
|
||||||
return boost::indeterminate;
|
|
||||||
} else if (isCTL(input)) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
header.value.push_back(input);
|
|
||||||
return boost::indeterminate;
|
|
||||||
}
|
|
||||||
case expecting_newline_2:
|
|
||||||
if (input == '\n') {
|
|
||||||
state_ = header_line_start;
|
|
||||||
return boost::indeterminate;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
case expecting_newline_3:
|
|
||||||
return (input == '\n');
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool isChar(int c) {
|
inline bool isDigit(int c);
|
||||||
return c >= 0 && c <= 127;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool isCTL(int c) {
|
|
||||||
return (c >= 0 && c <= 31) || (c == 127);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool isTSpecial(int c) {
|
|
||||||
switch (c) {
|
|
||||||
case '(': case ')': case '<': case '>': case '@':
|
|
||||||
case ',': case ';': case ':': case '\\': case '"':
|
|
||||||
case '/': case '[': case ']': case '?': case '=':
|
|
||||||
case '{': case '}': case ' ': case '\t':
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool isDigit(int c) {
|
|
||||||
return c >= '0' && c <= '9';
|
|
||||||
}
|
|
||||||
|
|
||||||
enum state {
|
enum state {
|
||||||
method_start,
|
method_start,
|
||||||
|
Loading…
Reference in New Issue
Block a user