]> git.sesse.net Git - cubemap/blob - parse.h
Add a missing compilation step to the README.
[cubemap] / parse.h
1 #ifndef _PARSE_H
2 #define _PARSE_H
3
4 // Various routines that deal with parsing; both HTTP requests and more generic text.
5
6 #include <stddef.h>
7 #include <map>
8 #include <string>
9 #include <vector>
10
11 // Split a line on whitespace, e.g. "foo  bar baz" -> {"foo", "bar", "baz"}.
12 std::vector<std::string> split_tokens(const std::string &line);
13
14 // Split a string on \n or \r\n, e.g. "foo\nbar\r\n\nbaz\r\n\r\n" -> {"foo", "bar", "baz"}.
15 std::vector<std::string> split_lines(const std::string &str);
16
17 // Extract HTTP headers from a request or response. Ignores the first line,
18 // where the verb or the return code is.
19 std::multimap<std::string, std::string> extract_headers(
20         const std::vector<std::string> &lines, const std::string &log_context);
21
22 // Add the new data to an existing string, looking for \r\n\r\n
23 // (typical of HTTP requests and/or responses). Will return one
24 // of the given statuses.
25 //
26 // Note that if you give too much data in new_data_size, you could
27 // get an RP_OUT_OF_SPACE even if you expected RP_EXTRA_DATA.
28 // Be careful about how large reads you give in.
29 enum RequestParseStatus {
30         RP_OUT_OF_SPACE,       // If larger than 16 kB.
31         RP_NOT_FINISHED_YET,   // Did not get \r\n\r\n yet. 
32         RP_EXTRA_DATA,         // Got \r\n\r\n, but there was extra data behind it.
33         RP_FINISHED,           // Ended exactly in \r\n\r\n.
34 };
35 RequestParseStatus wait_for_double_newline(std::string *existing_data, const char *new_data, size_t new_data_size);
36
37 #endif  // !defined(_PARSE_H)