X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=parse.h;h=1924cc08c9f3aab49c54bff4917ab38a6fb0a88d;hp=3cfa09119458efbdd2d182bd09381e1111f8191c;hb=1d285bcbfd1aa3f7911cfb98a947a37f68154428;hpb=019b96a9cc6fa2902690e98a2aa033517efef3ed diff --git a/parse.h b/parse.h index 3cfa091..1924cc0 100644 --- a/parse.h +++ b/parse.h @@ -1,17 +1,12 @@ #ifndef _PARSE_H #define _PARSE_H -// Various routines that deal with parsing; both configuration files and HTTP requests. +// Various routines that deal with parsing; both HTTP requests and more generic text. -#include -#include +#include #include - -struct ConfigLine { - std::string keyword; - std::vector arguments; - std::map parameters; -}; +#include +#include // Split a line on whitespace, e.g. "foo bar baz" -> {"foo", "bar", "baz"}. std::vector split_tokens(const std::string &line); @@ -19,21 +14,10 @@ std::vector split_tokens(const std::string &line); // Split a string on \n or \r\n, e.g. "foo\nbar\r\n\nbaz\r\n\r\n" -> {"foo", "bar", "baz"}. std::vector split_lines(const std::string &str); -// Parse the configuration file. -std::vector parse_config(const std::string &filename); - -enum ParameterType { - PARAMETER_OPTIONAL, - PARAMATER_MANDATORY, -}; - -std::string fetch_config_string(const std::vector &config, const std::string &keyword, - ParameterType parameter_type, const std::string &default_value = ""); - -// Note: Limits are inclusive. -int fetch_config_int(const std::vector &config, const std::string &keyword, - int min_limit, int max_limit, - ParameterType parameter_type, int default_value = -1); +// Extract HTTP headers from a request or response. Ignores the first line, +// where the verb or the return code is. +std::unordered_multimap extract_headers( + const std::vector &lines, const std::string &log_context); // Add the new data to an existing string, looking for \r\n\r\n // (typical of HTTP requests and/or responses). Will return one