ifndef TUNNEL_PARSER_HPP define TUNNEL_PARSER_HPP include cctype inclu

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef TUNNEL_PARSER_HPP
#define TUNNEL_PARSER_HPP
#include <cctype>
#include <string>
#include <iostream>
#include <boost/logic/tribool.hpp>
#include "packages.hpp"
namespace tunnel
{
class parser
{
public:
parser(package& pack):state_(blank),package_(pack){}
inline virtual ~parser() = 0;
enum state
{
undefined = -1,
blank = 0,
parsing_first_line,
parsing_headers,
parsing_body
};
template<class InputIterator>
void parse(InputIterator begin, InputIterator end);
protected:
template <class InputIterator>
void append(InputIterator begin, InputIterator end);
boost::tribool parse_data();
boost::tribool parse_first_line();
boost::tribool parse_headers(){return true;};
boost::tribool parse_body(){return true;};
std::string buffer_;
std::string::const_iterator current_pos_;
state state_;
package& package_;
};
parser::~parser(){}
template <class InputIterator>
void parser::append(InputIterator begin, InputIterator end)
{
buffer_.append(begin, end);
}
template <class InputIterator>
void parser::parse(InputIterator begin, InputIterator end)
{
append(begin, end);
}
class request_parser
: public parser
{
public:
request_parser():parser(package_){};
private:
request_package package_;
};
class response_parser
: public parser
{
public:
response_parser():parser(package_){};
private:
response_package package_;
};
}
#endif