| Home | Libraries | People | FAQ | More

# http/server/request_parser.hpp

Go to the documentation of this file.

    00001 #ifndef HTTP_REQUEST_PARSER_HPP
    00002 #define HTTP_REQUEST_PARSER_HPP
    00003
    00004 #include <boost/logic/tribool.hpp>
    00005 #include <boost/tuple/tuple.hpp>
    00006
    00007 namespace http {
    00008 namespace server {
    00009
    00010 struct request;
    00011
    00013 class request_parser
    00014 {
    00015 public:
    00017   request_parser();
    00018
    00020   void reset();
    00021
    00026   template <typename InputIterator>
    00027   boost::tuple<boost::tribool, InputIterator> parse(request& req,
    00028       InputIterator begin, InputIterator end)
    00029   {
    00030     while (begin != end)
    00031     {
    00032       boost::tribool result = consume(req, *begin++);
    00033       if (result || !result)
    00034         return boost::make_tuple(result, begin);
    00035     }
    00036     boost::tribool result = boost::indeterminate;
    00037     return boost::make_tuple(result, begin);
    00038   }
    00039
    00040 private:
    00042   boost::tribool consume(request& req, char input);
    00043
    00045   static bool is_char(int c);
    00046
    00048   static bool is_ctl(int c);
    00049
    00051   static bool is_tspecial(int c);
    00052
    00054   static bool is_digit(int c);
    00055
    00057   enum state
    00058   {
    00059     method_start,
    00060     method,
    00061     uri_start,
    00062     uri,
    00063     http_version_h,
    00064     http_version_t_1,
    00065     http_version_t_2,
    00066     http_version_p,
    00067     http_version_slash,
    00068     http_version_major_start,
    00069     http_version_major,
    00070     http_version_minor_start,
    00071     http_version_minor,
    00072     expecting_newline_1,
    00073     header_line_start,
    00074     header_lws,
    00075     header_name,
    00076     space_before_header_value,
    00077     header_value,
    00078     expecting_newline_2,
    00079     expecting_newline_3
    00080   } state_;
    00081 };
    00082
    00083 } // namespace server
    00084 } // namespace http
    00085
    00086 #endif // HTTP_REQUEST_PARSER_HPP

| Copyright © 2003 - 2006 Christopher M. Kohlhoff