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
11namespace mtx {
12namespace client {
13//! Utility namespace.
14namespace utils {
15
16//! Representation of Matrix Content (MXC) URIs.
17struct 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.
26MxcUrl
27parse_mxc_url(const std::string &url);
28
29//! Check if the given string represents a number.
30bool
31is_number(const std::string &s);
32
33//! Generates a random string of the given size.
34std::string
35random_token(uint8_t len = 12, bool with_symbols = true) noexcept;
36
37//! Construct query string from the given parameter pairs.
38std::string
39query_params(const std::map<std::string, std::string> &params) noexcept;
40
41//! URL-encode the input string.
42std::string
43url_encode(const std::string &s) noexcept;
44}
45}
46}
47