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);
30 std::string fetch_config_string(const std::vector<ConfigLine> &config, const std::string &keyword,
31 ParameterType parameter_type, const std::string &default_value = "");
33 // Note: Limits are inclusive.
34 int fetch_config_int(const std::vector<ConfigLine> &config, const std::string &keyword,
35 int min_limit, int max_limit,
36 ParameterType parameter_type, int default_value = -1);
38 // Add the new data to an existing string, looking for \r\n\r\n
39 // (typical of HTTP requests and/or responses). Will return one
40 // of the given statuses.
42 // Note that if you give too much data in new_data_size, you could
43 // get an RP_OUT_OF_SPACE even if you expected RP_EXTRA_DATA.
44 // Be careful about how large reads you give in.
45 enum RequestParseStatus {
46 RP_OUT_OF_SPACE, // If larger than 16 kB.
47 RP_NOT_FINISHED_YET, // Did not get \r\n\r\n yet.
48 RP_EXTRA_DATA, // Got \r\n\r\n, but there was extra data behind it.
49 RP_FINISHED, // Ended exactly in \r\n\r\n.
51 RequestParseStatus wait_for_double_newline(std::string *existing_data, const char *new_data, size_t new_data_size);
53 #endif // !defined(_PARSE_H)