Granada  1.54.0
Structured layer on top of C++ REST SDK for building server applications in C++. Granada implements sessions, server side plug-in framework, C++ OAuth 2.0 server, data storage access, server script running, server browsing.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Functions
granada::http::parser Namespace Reference

Functions

std::unordered_map
< std::string, std::string > 
ParseCookies (const web::http::http_request &request)
 
std::unordered_map
< std::string, std::string > 
ParseQueryString (const std::string &query_string)
 
std::unordered_map
< std::string,
std::unordered_map
< std::string, std::vector
< unsigned char > > > 
ParseMultipartFormData (const web::http::http_request &request)
 
std::string ExtractBoundaryMDF (const web::http::http_headers &headers)
 
bool ParseFieldsAndPropertiesMDF (std::vector< unsigned char > &body, const std::string &boundary, std::unordered_map< std::string, std::unordered_map< std::string, std::vector< unsigned char >>> &multipart_data_form)
 
bool ParsePropertyMDF (std::vector< unsigned char > &properties, std::unordered_map< std::string, std::vector< unsigned char >> &parsed_properties)
 
std::vector< unsigned char >
::iterator 
GetIteratorMDF (const char *chr, std::vector< unsigned char > &body, const bool end)
 
std::string ParseURIFromReferer (const web::http::http_request &request)
 

Function Documentation

std::string granada::http::parser::ExtractBoundaryMDF ( const web::http::http_headers &  headers)

Returns the value of the boundary of the multipart/form data

Parameters
headersHeaders of the HTTP Request
Returns
Boundary of the multipart/form data. Example: WebKitFormBoundaryKS484Mi6jduf07q
std::vector<unsigned char>::iterator granada::http::parser::GetIteratorMDF ( const char *  chr,
std::vector< unsigned char > &  body,
const bool  end 
)

Search the position of first appearance of chr in body vector and returns the position iterator of the begining or the end.

Parameters
chrText to search.
bodyContains all the data where we want to search chr.
endIf true extract the iterator corresponding to the position after the first appearance of chr in body, If false before the first appearance of chr.
Returns
Iterator of the begining or the end of the first appearance of chr.
std::unordered_map<std::string, std::string> granada::http::parser::ParseCookies ( const web::http::http_request &  request)

Parse cookies of an http_request into an unordered map Example: cookie1=content1;cookie2=content2

will be parsed into: cookies (unordered map) |_ cookie1 => content1 |_ cookie2 => content2

bool granada::http::parser::ParseFieldsAndPropertiesMDF ( std::vector< unsigned char > &  body,
const std::string &  boundary,
std::unordered_map< std::string, std::unordered_map< std::string, std::vector< unsigned char >>> &  multipart_data_form 
)

Fill parsed multi part form data unordered_map with fields, properties and values.

Parameters
bodyNon-parsed multipart/form data fields, properties and values.
boundaryBoundary of the multipart/form data.
multipart_data_formParsed multipart/form data in unordered_map.
Returns
Return true if there are more fields, properties and values after this one. Return false if this is there is no more data to parse after.
std::unordered_map<std::string, std::unordered_map<std::string, std::vector<unsigned char> > > granada::http::parser::ParseMultipartFormData ( const web::http::http_request &  request)
bool granada::http::parser::ParsePropertyMDF ( std::vector< unsigned char > &  properties,
std::unordered_map< std::string, std::vector< unsigned char >> &  parsed_properties 
)

Parse property with this format: name="file"; of a multipart/form data field into key-value pair and insert it into the parsed properties unordered_map.

Parameters
propertiesNon-parsed properties
parsed_propertiesParsed properties.
Returns
True if there is another property after it, False if there is no other property to parse after it.
std::unordered_map<std::string, std::string> granada::http::parser::ParseQueryString ( const std::string &  query_string)

Parse Body in query form into an unordered map Example: id=0&quantity=2

will be parsed into: query (unordered map) |_ id => 0 |_ quantity => 2

std::string granada::http::parser::ParseURIFromReferer ( const web::http::http_request &  request)

Returns an URI extracted from the Referer header.

Parameters
requestHTTP request containing the Referer header.
Returns
Parsed URI.