AirInv Logo  0.1.2
C++ Simulated Airline Inventory Management System library
RequestParser.hpp
Go to the documentation of this file.
00001 #ifndef __AIRINV_SVR_REQUESTPARSER_HPP
00002 #define __AIRINV_SVR_REQUESTPARSER_HPP
00003 
00004 // //////////////////////////////////////////////////////////////////////
00005 // Import section
00006 // //////////////////////////////////////////////////////////////////////
00007 // STL
00008 // Boost
00009 #include <boost/logic/tribool.hpp>
00010 #include <boost/tuple/tuple.hpp>
00011 
00012 namespace AIRINV {
00013 
00014   struct Request;
00015 
00017   class RequestParser {
00018   public:
00020     RequestParser();
00021 
00023     void reset();
00024 
00029     template <typename InputIterator>
00030     boost::tuple<boost::tribool, InputIterator> parse (Request& req,
00031                                                        InputIterator begin,
00032                                                        InputIterator end) {
00033 
00034       while (begin != end) {
00035         boost::tribool result = consume(req, *begin++);
00036         if (result || !result)
00037           return boost::make_tuple(result, begin);
00038       }
00039     
00040       boost::tribool result = boost::indeterminate;
00041       return boost::make_tuple(result, begin);
00042     }
00043 
00044   private:
00046     boost::tribool consume (Request& req, char input);
00047 
00049     static bool is_char(int c);
00050 
00052     static bool is_ctl(int c);
00053 
00055     static bool is_tspecial(int c);
00056 
00058     static bool is_digit(int c);
00059 
00061     enum state {
00062       method_start,
00063       method,
00064       uri_start,
00065       uri,
00066       http_version_h,
00067       http_version_t_1,
00068       http_version_t_2,
00069       http_version_p,
00070       http_version_slash,
00071       http_version_major_start,
00072       http_version_major,
00073       http_version_minor_start,
00074       http_version_minor,
00075       expecting_newline_1,
00076       header_line_start,
00077       header_lws,
00078       header_name,
00079       space_before_header_value,
00080       header_value,
00081       expecting_newline_2,
00082       expecting_newline_3
00083     } state_;
00084   };
00085 
00086 }
00087 #endif // __AIRINV_SVR_REQUESTPARSER_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines