include parsers hpp include algorithm include iterator namespace tunne

 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
#include "parsers.hpp"
#include <algorithm>
#include <iterator>
namespace tunnel
{
/**
* Parses internal buffer
*
* @return true on success, false on failure and
* indeterminate if more data need
*/
boost::tribool parser::parse_data()
{
switch(state_)
{
case undefined: case blank: return false;
case parsing_first_line: return parse_first_line();
case parsing_headers: return parse_headers();
case parsing_body: return parse_body();
default: return false;
}
return false;
}
boost::tribool parser::parse_first_line()
{
std::string line_end = "\r\n";
std::string::const_iterator first_line_end =
std::search(current_pos_, buffer_.end(),
line_end.begin(), line_end.end());
if(first_line_end == buffer_.end())
return boost::indeterminate;
std::copy(current_pos_, first_line_end,
std::back_inserter(package_.start_line_));
return true;
}
}