Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
websocketpp::http::parser Namespace Reference

Namespaces

namespace  body_encoding
 
namespace  state
 

Classes

class  parser
 Base HTTP parser. More...
 
class  request
 Stores, parses, and manipulates HTTP requests. More...
 
class  response
 Stores, parses, and manipulates HTTP responses. More...
 

Typedefs

typedef std::map< std::string, std::string, utility::ci_lessheader_list
 

Functions

template<typename InputIterator >
std::pair< std::string, InputIterator > extract_token (InputIterator begin, InputIterator end)
 Read and return the next token in the stream.
 
template<typename InputIterator >
std::pair< std::string, InputIterator > extract_quoted_string (InputIterator begin, InputIterator end)
 Read and return the next quoted string in the stream.
 
template<typename InputIterator >
InputIterator extract_lws (InputIterator begin, InputIterator end)
 Read and discard one unit of linear whitespace.
 
template<typename InputIterator >
InputIterator extract_all_lws (InputIterator begin, InputIterator end)
 Read and discard linear whitespace.
 
template<typename InputIterator >
InputIterator extract_attributes (InputIterator begin, InputIterator end, attribute_list &attributes)
 Extract HTTP attributes.
 
template<typename InputIterator >
InputIterator extract_parameters (InputIterator begin, InputIterator end, parameter_list &parameters)
 Extract HTTP parameters.
 
std::string strip_lws (std::string const &input)
 

Typedef Documentation

◆ header_list

typedef std::map<std::string, std::string, utility::ci_less > websocketpp::http::parser::header_list

Definition at line 60 of file parser.hpp.

Function Documentation

◆ extract_all_lws()

template<typename InputIterator >
InputIterator websocketpp::http::parser::extract_all_lws ( InputIterator begin,
InputIterator end )

Read linear white space until a non-lws character is read and return an iterator to that character. If begin is returned, no whitespace was extracted.

Parameters
beginAn iterator to the beginning of the sequence
endAn iterator to the end of the sequence
Returns
An iterator to the character after the linear whitespace read

Definition at line 164 of file parser.hpp.

164 {
165 InputIterator old_it;
166 InputIterator new_it = begin;
167
168 do {
169 // Pull value from previous iteration
170 old_it = new_it;
171
172 // look ahead another pass
173 new_it = extract_lws(old_it,end);
174 } while (new_it != end && old_it != new_it);
175
176 return new_it;
177}
InputIterator extract_lws(InputIterator begin, InputIterator end)
Read and discard one unit of linear whitespace.
Definition parser.hpp:139
Here is the call graph for this function:
Here is the caller graph for this function:

◆ extract_attributes()

template<typename InputIterator >
InputIterator websocketpp::http::parser::extract_attributes ( InputIterator begin,
InputIterator end,
attribute_list & attributes )

An http attributes list is a semicolon delimited list of key value pairs in the format: *( ";" attribute "=" value ) where attribute is a token and value is a token or quoted string.

Attributes extracted are appended to the supplied attributes list attributes.

Parameters
[in]beginAn iterator to the beginning of the sequence
[in]endAn iterator to the end of the sequence
[out]attributesA reference to the attributes list to append attribute/value pairs extracted to
Returns
An iterator to the character after the last atribute read

Definition at line 195 of file parser.hpp.

197{
198 InputIterator cursor;
199 bool first = true;
200
201 if (begin == end) {
202 return begin;
203 }
204
205 cursor = begin;
206 std::pair<std::string,InputIterator> ret;
207
208 while (cursor != end) {
209 std::string name;
210
211 cursor = http::parser::extract_all_lws(cursor,end);
212 if (cursor == end) {
213 break;
214 }
215
216 if (first) {
217 // ignore this check for the very first pass
218 first = false;
219 } else {
220 if (*cursor == ';') {
221 // advance past the ';'
222 ++cursor;
223 } else {
224 // non-semicolon in this position indicates end end of the
225 // attribute list, break and return.
226 break;
227 }
228 }
229
230 cursor = http::parser::extract_all_lws(cursor,end);
231 ret = http::parser::extract_token(cursor,end);
232
233 if (ret.first.empty()) {
234 // error: expected a token
235 return begin;
236 } else {
237 name = ret.first;
238 cursor = ret.second;
239 }
240
241 cursor = http::parser::extract_all_lws(cursor,end);
242 if (cursor == end || *cursor != '=') {
243 // if there is an equals sign, read the attribute value. Otherwise
244 // record a blank value and continue
245 attributes[name].clear();
246 continue;
247 }
248
249 // advance past the '='
250 ++cursor;
251
252 cursor = http::parser::extract_all_lws(cursor,end);
253 if (cursor == end) {
254 // error: expected a token or quoted string
255 return begin;
256 }
257
258 ret = http::parser::extract_quoted_string(cursor,end);
259 if (ret.second != cursor) {
260 attributes[name] = ret.first;
261 cursor = ret.second;
262 continue;
263 }
264
265 ret = http::parser::extract_token(cursor,end);
266 if (ret.first.empty()) {
267 // error : expected token or quoted string
268 return begin;
269 } else {
270 attributes[name] = ret.first;
271 cursor = ret.second;
272 }
273 }
274
275 return cursor;
276}
std::string name
CK_RV ret
Here is the call graph for this function:
Here is the caller graph for this function:

◆ extract_lws()

template<typename InputIterator >
InputIterator websocketpp::http::parser::extract_lws ( InputIterator begin,
InputIterator end )

Read one unit of linear white space and return the iterator to the character afterwards. If begin is returned, no whitespace was extracted.

Parameters
beginAn iterator to the beginning of the sequence
endAn iterator to the end of the sequence
Returns
An iterator to the character after the linear whitespace read

Definition at line 139 of file parser.hpp.

139 {
140 InputIterator it = begin;
141
142 // strip leading CRLF
143 if (end-begin > 2 && *begin == '\r' && *(begin+1) == '\n' &&
144 is_whitespace_char(static_cast<unsigned char>(*(begin+2))))
145 {
146 it+=3;
147 }
148
149 it = std::find_if(it,end,&is_not_whitespace_char);
150 return it;
151}
bool is_whitespace_char(unsigned char c)
Is the character whitespace.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ extract_parameters()

template<typename InputIterator >
InputIterator websocketpp::http::parser::extract_parameters ( InputIterator begin,
InputIterator end,
parameter_list & parameters )

An http parameters list is a comma delimited list of tokens followed by optional semicolon delimited attributes lists.

Parameters extracted are appended to the supplied parameters list parameters.

Parameters
[in]beginAn iterator to the beginning of the sequence
[in]endAn iterator to the end of the sequence
[out]parametersA reference to the parameters list to append paramter values extracted to
Returns
An iterator to the character after the last parameter read

LWS token LWS *(";" method-param) LWS ,=loop again

Definition at line 293 of file parser.hpp.

295{
296 InputIterator cursor;
297
298 if (begin == end) {
299 // error: expected non-zero length range
300 return begin;
301 }
302
303 cursor = begin;
304 std::pair<std::string,InputIterator> ret;
305
314 while (cursor != end) {
315 std::string parameter_name;
316 attribute_list attributes;
317
318 // extract any stray whitespace
319 cursor = http::parser::extract_all_lws(cursor,end);
320 if (cursor == end) {break;}
321
322 ret = http::parser::extract_token(cursor,end);
323
324 if (ret.first.empty()) {
325 // error: expected a token
326 return begin;
327 } else {
328 parameter_name = ret.first;
329 cursor = ret.second;
330 }
331
332 // Safe break point, insert parameter with blank attributes and exit
333 cursor = http::parser::extract_all_lws(cursor,end);
334 if (cursor == end) {
335 //parameters[parameter_name] = attributes;
336 parameters.push_back(std::make_pair(parameter_name,attributes));
337 break;
338 }
339
340 // If there is an attribute list, read it in
341 if (*cursor == ';') {
342 InputIterator acursor;
343
344 ++cursor;
345 acursor = http::parser::extract_attributes(cursor,end,attributes);
346
347 if (acursor == cursor) {
348 // attribute extraction ended in syntax error
349 return begin;
350 }
351
352 cursor = acursor;
353 }
354
355 // insert parameter into output list
356 //parameters[parameter_name] = attributes;
357 parameters.push_back(std::make_pair(parameter_name,attributes));
358
359 cursor = http::parser::extract_all_lws(cursor,end);
360 if (cursor == end) {break;}
361
362 // if next char is ',' then read another parameter, else stop
363 if (*cursor != ',') {
364 break;
365 }
366
367 // advance past comma
368 ++cursor;
369
370 if (cursor == end) {
371 // expected more bytes after a comma
372 return begin;
373 }
374 }
375
376 return cursor;
377}
std::map< std::string, std::string > attribute_list
The type of an HTTP attribute list.
Definition constants.hpp:45
Here is the call graph for this function:
Here is the caller graph for this function:

◆ extract_quoted_string()

template<typename InputIterator >
std::pair< std::string, InputIterator > websocketpp::http::parser::extract_quoted_string ( InputIterator begin,
InputIterator end )

Read a double quoted string starting at begin. The quotes themselves are stripped. The quoted value is returned along with an iterator to the next character to read

Parameters
beginAn iterator to the beginning of the sequence
endAn iterator to the end of the sequence
Returns
A pair containing the string read and an iterator to the next character in the stream

Definition at line 92 of file parser.hpp.

94{
95 std::string s;
96
97 if (end == begin) {
98 return std::make_pair(s,begin);
99 }
100
101 if (*begin != '"') {
102 return std::make_pair(s,begin);
103 }
104
105 InputIterator cursor = begin+1;
106 InputIterator marker = cursor;
107
108 cursor = std::find(cursor,end,'"');
109
110 while (cursor != end) {
111 // either this is the end or a quoted string
112 if (*(cursor-1) == '\\') {
113 s.append(marker,cursor-1);
114 s.append(1,'"');
115 ++cursor;
116 marker = cursor;
117 } else {
118 s.append(marker,cursor);
119 ++cursor;
120 return std::make_pair(s,cursor);
121 }
122
123 cursor = std::find(cursor,end,'"');
124 }
125
126 return std::make_pair("",begin);
127}
char * s
Here is the caller graph for this function:

◆ extract_token()

template<typename InputIterator >
std::pair< std::string, InputIterator > websocketpp::http::parser::extract_token ( InputIterator begin,
InputIterator end )

Read until a non-token character is found and then return the token and iterator to the next character to read

Parameters
beginAn iterator to the beginning of the sequence
endAn iterator to the end of the sequence
Returns
A pair containing the token and an iterator to the next character in the stream

Definition at line 73 of file parser.hpp.

75{
76 InputIterator it = std::find_if(begin,end,&is_not_token_char);
77 return std::make_pair(std::string(begin,it),it);
78}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ strip_lws()

std::string websocketpp::http::parser::strip_lws ( std::string const & input)
inline

Definition at line 379 of file parser.hpp.

379 {
380 std::string::const_iterator begin = extract_all_lws(input.begin(),input.end());
381 if (begin == input.end()) {
382 return std::string();
383 }
384
385 std::string::const_reverse_iterator rbegin = extract_all_lws(input.rbegin(),input.rend());
386 if (rbegin == input.rend()) {
387 return std::string();
388 }
389
390 return std::string(begin,rbegin.base());
391}
InputIterator extract_all_lws(InputIterator begin, InputIterator end)
Read and discard linear whitespace.
Definition parser.hpp:164
Here is the call graph for this function:
Here is the caller graph for this function: