MACE
1.0.0
|
00001 // 00002 // request_parser.hpp 00003 // ~~~~~~~~~~~~~~~~~~ 00004 // 00005 // Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com) 00006 // 00007 // Distributed under the Boost Software License, Version 1.0. (See accompanying 00008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 00009 // 00010 00011 #ifndef MACE_RPC_HTTP_REQUEST_PARSER_HPP 00012 #define MACE_RPC_HTTP_REQUEST_PARSER_HPP 00013 00014 #include <string> 00015 #include <boost/logic/tribool.hpp> 00016 #include <boost/tuple/tuple.hpp> 00017 #include <mace/rpc/http/coroutine.hpp> 00018 00019 namespace mace { namespace rpc { namespace http { 00020 00021 struct request; 00022 00024 class request_parser : coroutine { 00025 public: 00030 template <typename InputIterator> 00031 boost::tuple<boost::tribool, InputIterator> parse(request& req, 00032 InputIterator begin, InputIterator end) 00033 { 00034 while (begin != end) 00035 { 00036 boost::tribool result = consume(req, *begin++); 00037 if (result || !result) 00038 return boost::make_tuple(result, begin); 00039 } 00040 boost::tribool result = boost::indeterminate; 00041 return boost::make_tuple(result, begin); 00042 } 00043 template<typename Stream> 00044 boost::tribool parse(request& req, Stream& s) { 00045 while (!s.eof()) 00046 { 00047 boost::tribool result = consume(req, s.get()); 00048 if (result || !result) 00049 return result; 00050 } 00051 boost::tribool result = boost::indeterminate; 00052 return result; 00053 } 00054 00055 00056 private: 00058 static std::string content_length_name_; 00059 00061 std::size_t content_length_; 00062 00064 boost::tribool consume(request& req, char input); 00065 00067 static bool is_char(int c); 00068 00070 static bool is_ctl(int c); 00071 00073 static bool is_tspecial(int c); 00074 00076 static bool is_digit(int c); 00077 00079 static bool tolower_compare(char a, char b); 00080 00082 bool headers_equal(const std::string& a, const std::string& b); 00083 }; 00084 00085 } } } // namespace mace::rpc::http 00086 00087 #endif // MACE_RPC_HTTP_REQUEST_PARSER_HPP