| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "na64util/str-fmt.hh" | ||
| 4 | |||
| 5 | #include <string> | ||
| 6 | #include <vector> | ||
| 7 | #include <unordered_map> | ||
| 8 | #include <regex> | ||
| 9 | #include <cstdint> | ||
| 10 | |||
| 11 | namespace na64dp { | ||
| 12 | namespace errors { | ||
| 13 | class InvalidURI : public GenericRuntimeError { | ||
| 14 | public: | ||
| 15 | InvalidURI(const char *) throw(); | ||
| 16 | }; | ||
| 17 | } // namespace ::na64dp::errors | ||
| 18 | namespace util { | ||
| 19 | |||
| 20 | /// A C++ wrapper -- uses C wordexp() function to expand file names. | ||
| 21 | std::vector<std::string> expand_names( const std::string & expr ); | ||
| 22 | |||
| 23 | /// Same as `expand_names()` but expects string to expand to a single | ||
| 24 | /// non-empty path (does not check path for existance, though). | ||
| 25 | std::string expand_name( const std::string & expr ); | ||
| 26 | |||
| 27 | /// A parsed URI identifier representation | ||
| 28 | /// | ||
| 29 | /// \todo custom regex-based representation | ||
| 30 | class URI { | ||
| 31 | public: | ||
| 32 | /// Performs "URL-encoding" (note: space is numeric) | ||
| 33 | static std::string encode(const std::string &); | ||
| 34 | /// Performs "URL-decoding" (note plus interpreted as space) | ||
| 35 | static std::string decode(const std::string &); | ||
| 36 | |||
| 37 | /// A simple query string parser | ||
| 38 | static std::unordered_multimap<std::string, std::string> | ||
| 39 | parse_query_string(const std::string &, const std::string & delimRx=R"(&)"); | ||
| 40 | private: | ||
| 41 | std::string _scheme | ||
| 42 | , _userinfo | ||
| 43 | , _host | ||
| 44 | , _port | ||
| 45 | , _path | ||
| 46 | //, _query | ||
| 47 | , _fragment | ||
| 48 | ; | ||
| 49 | std::unordered_multimap<std::string, std::string> _qParams; | ||
| 50 | public: | ||
| 51 | URI() = default; | ||
| 52 | URI(const std::string & uri); | ||
| 53 | 2 | ~URI() = default; | |
| 54 | |||
| 55 | 2 | const std::string & scheme() const { return _scheme; } | |
| 56 | 2 | const std::string & userinfo() const { return _userinfo; } | |
| 57 | 2 | const std::string & host() const { return _host; } | |
| 58 | 2 | const std::string & port() const { return _port; } | |
| 59 | 2 | const std::string & path() const { return _path; } | |
| 60 | std::string query_str() const; | ||
| 61 | const std::unordered_multimap<std::string, std::string> & query() const {return _qParams;} | ||
| 62 | 5 | std::unordered_multimap<std::string, std::string> & query() {return _qParams;} | |
| 63 | 2 | const std::string & fragment() const { return _fragment; } | |
| 64 | |||
| 65 | std::string authority() const; | ||
| 66 | |||
| 67 | void scheme(const std::string & v); | ||
| 68 | void host(const std::string &); | ||
| 69 | void port(const std::string &); | ||
| 70 | void port(uint16_t); | ||
| 71 | void path(const std::string &); | ||
| 72 | //void query(const std::string &); | ||
| 73 | void fragment(const std::string &); | ||
| 74 | |||
| 75 | bool is_valid() const; | ||
| 76 | std::string to_str(bool noCheck=false) const; | ||
| 77 | }; | ||
| 78 | |||
| 79 | } // namespace ::na64dp::util | ||
| 80 | } // namespace na64dp | ||
| 81 |