2011-01-09 16:42:27 -05:00
|
|
|
/*
|
2013-10-14 07:42:28 -04:00
|
|
|
|
2015-01-23 11:14:12 -05:00
|
|
|
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
2013-10-14 07:42:28 -04:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
Redistributions of source code must retain the above copyright notice, this list
|
|
|
|
of conditions and the following disclaimer.
|
|
|
|
Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
2011-01-09 16:42:27 -05:00
|
|
|
|
|
|
|
#ifndef REQUEST_PARSER_H
|
|
|
|
#define REQUEST_PARSER_H
|
|
|
|
|
2013-11-14 12:42:33 -05:00
|
|
|
#include "Http/CompressionType.h"
|
2014-11-24 11:57:01 -05:00
|
|
|
#include "Http/Header.h"
|
2015-01-23 11:46:40 -05:00
|
|
|
#include "../data_structures/tribool.hpp"
|
|
|
|
|
2015-01-23 11:14:12 -05:00
|
|
|
#include <tuple>
|
2011-01-09 16:42:27 -05:00
|
|
|
|
2014-05-07 11:14:57 -04:00
|
|
|
namespace http
|
|
|
|
{
|
2011-01-09 16:42:27 -05:00
|
|
|
|
2013-12-16 05:29:38 -05:00
|
|
|
struct Request;
|
|
|
|
|
2014-05-07 11:14:57 -04:00
|
|
|
class RequestParser
|
|
|
|
{
|
|
|
|
public:
|
2013-11-14 12:29:56 -05:00
|
|
|
RequestParser();
|
|
|
|
void Reset();
|
2011-01-09 16:42:27 -05:00
|
|
|
|
2015-01-23 12:53:37 -05:00
|
|
|
std::tuple<osrm::tribool, CompressionType> Parse(Request &req, char *begin, char *end);
|
2011-01-09 16:42:27 -05:00
|
|
|
|
2014-05-07 11:14:57 -04:00
|
|
|
private:
|
2015-01-23 12:53:37 -05:00
|
|
|
osrm::tribool consume(Request &req, char input);
|
2012-04-20 10:19:56 -04:00
|
|
|
|
2015-01-26 07:20:22 -05:00
|
|
|
bool is_char(int c) const;
|
2012-05-03 05:07:53 -04:00
|
|
|
|
2015-01-26 07:20:22 -05:00
|
|
|
bool is_CTL(int c) const;
|
2012-06-08 04:12:42 -04:00
|
|
|
|
2015-01-26 07:20:22 -05:00
|
|
|
bool is_special(int c) const;
|
2011-01-09 16:42:27 -05:00
|
|
|
|
2015-01-26 07:20:22 -05:00
|
|
|
bool is_digit(int c) const;
|
2011-01-09 16:42:27 -05:00
|
|
|
|
2015-01-26 07:20:22 -05:00
|
|
|
enum class internal_state : unsigned char
|
2015-01-23 11:14:12 -05:00
|
|
|
{
|
|
|
|
method_start,
|
|
|
|
method,
|
|
|
|
uri_start,
|
|
|
|
uri,
|
|
|
|
http_version_h,
|
|
|
|
http_version_t_1,
|
|
|
|
http_version_t_2,
|
|
|
|
http_version_p,
|
|
|
|
http_version_slash,
|
|
|
|
http_version_major_start,
|
|
|
|
http_version_major,
|
|
|
|
http_version_minor_start,
|
|
|
|
http_version_minor,
|
|
|
|
expecting_newline_1,
|
|
|
|
header_line_start,
|
|
|
|
header_lws,
|
|
|
|
header_name,
|
|
|
|
space_before_header_value,
|
|
|
|
header_value,
|
|
|
|
expecting_newline_2,
|
|
|
|
expecting_newline_3
|
2015-01-26 07:20:22 -05:00
|
|
|
} state;
|
2011-02-11 11:12:37 -05:00
|
|
|
|
|
|
|
Header header;
|
2015-01-23 12:53:37 -05:00
|
|
|
CompressionType compression_type;
|
2011-01-09 16:42:27 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace http
|
|
|
|
|
|
|
|
#endif // REQUEST_PARSER_H
|