4 // Various routines that deal with parsing; both configuration files and HTTP requests.
12 std::vector<std::string> arguments;
13 std::map<std::string, std::string> parameters;
16 // Split a line on whitespace, e.g. "foo bar baz" -> {"foo", "bar", "baz"}.
17 std::vector<std::string> split_tokens(const std::string &line);
19 // Split a string on \n or \r\n, e.g. "foo\nbar\r\n\nbaz\r\n\r\n" -> {"foo", "bar", "baz"}.
20 std::vector<std::string> split_lines(const std::string &str);
22 // Parse the configuration file.
23 std::vector<ConfigLine> parse_config(const std::string &filename);
25 // Note: Limits are inclusive.
26 int fetch_config_int(const std::vector<ConfigLine> &config, const std::string &keyword, int min_limit, int max_limit);
28 // Add the new data to an existing string, looking for \r\n\r\n
29 // (typical of HTTP requests and/or responses). Will return one
30 // of the given statuses.
32 // Note that if you give too much data in new_data_size, you could
33 // get an RP_OUT_OF_SPACE even if you expected RP_EXTRA_DATA.
34 // Be careful about how large reads you give in.
35 enum RequestParseStatus {
36 RP_OUT_OF_SPACE, // If larger than 16 kB.
37 RP_NOT_FINISHED_YET, // Did not get \r\n\r\n yet.
38 RP_EXTRA_DATA, // Got \r\n\r\n, but there was extra data behind it.
39 RP_FINISHED, // Ended exactly in \r\n\r\n.
41 RequestParseStatus wait_for_double_newline(std::string *existing_data, const char *new_data, size_t new_data_size);
43 #endif // !defined(_PARSE_H)