1 | #pragma once |
2 | |
3 | /// @file |
4 | /// @brief Various utility functions for http requests. |
5 | |
6 | #include <cstdint> |
7 | #include <iosfwd> |
8 | #include <map> |
9 | #include <string> |
10 | |
11 | namespace mtx { |
12 | namespace client { |
13 | //! Utility namespace. |
14 | namespace utils { |
15 | |
16 | //! Representation of Matrix Content (MXC) URIs. |
17 | struct MxcUrl |
18 | { |
19 | //! The name of the homeserver where the content originated. |
20 | std::string server; |
21 | //! An opaque ID which identifies the content. |
22 | std::string media_id; |
23 | }; |
24 | |
25 | //! Parse a matrix content URI into its server & media_id components. |
26 | MxcUrl |
27 | parse_mxc_url(const std::string &url); |
28 | |
29 | //! Check if the given string represents a number. |
30 | bool |
31 | is_number(const std::string &s); |
32 | |
33 | //! Generates a random string of the given size. |
34 | std::string |
35 | random_token(uint8_t len = 12, bool with_symbols = true) noexcept; |
36 | |
37 | //! Construct query string from the given parameter pairs. |
38 | std::string |
39 | query_params(const std::map<std::string, std::string> ¶ms) noexcept; |
40 | |
41 | //! URL-encode the input string. |
42 | std::string |
43 | url_encode(const std::string &s) noexcept; |
44 | } |
45 | } |
46 | } |
47 | |