Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 1 | #pragma once |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 3 | #include "bmcweb_config.h" |
| 4 | |
Ed Tanous | 51dae67 | 2018-09-05 16:07:32 -0700 | [diff] [blame] | 5 | #include <openssl/crypto.h> |
| 6 | |
Ed Tanous | c867a83 | 2022-03-10 14:17:00 -0800 | [diff] [blame] | 7 | #include <boost/callable_traits.hpp> |
Ed Tanous | 079360a | 2022-06-29 10:05:19 -0700 | [diff] [blame] | 8 | #include <boost/url/parse.hpp> |
Ed Tanous | eae855c | 2021-10-26 11:26:02 -0700 | [diff] [blame] | 9 | #include <boost/url/url.hpp> |
Ed Tanous | 079360a | 2022-06-29 10:05:19 -0700 | [diff] [blame] | 10 | #include <boost/url/url_view.hpp> |
Ed Tanous | 71f2db7 | 2022-05-25 12:28:09 -0700 | [diff] [blame] | 11 | #include <nlohmann/json.hpp> |
Nan Zhou | 1d8782e | 2021-11-29 22:23:18 -0800 | [diff] [blame] | 12 | |
Ed Tanous | 9ea15c3 | 2022-01-04 14:18:22 -0800 | [diff] [blame] | 13 | #include <array> |
Ed Tanous | 74849be | 2021-02-05 09:47:47 -0800 | [diff] [blame] | 14 | #include <chrono> |
Ed Tanous | c715ec2 | 2022-03-10 15:38:01 -0800 | [diff] [blame] | 15 | #include <cstddef> |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 16 | #include <cstdint> |
Ed Tanous | 9ea15c3 | 2022-01-04 14:18:22 -0800 | [diff] [blame] | 17 | #include <ctime> |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 18 | #include <functional> |
Ed Tanous | 9896eae | 2022-07-23 15:07:33 -0700 | [diff] [blame] | 19 | #include <iomanip> |
Ed Tanous | 9ea15c3 | 2022-01-04 14:18:22 -0800 | [diff] [blame] | 20 | #include <limits> |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 21 | #include <stdexcept> |
| 22 | #include <string> |
Ed Tanous | 9ea15c3 | 2022-01-04 14:18:22 -0800 | [diff] [blame] | 23 | #include <string_view> |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 24 | #include <tuple> |
Ed Tanous | 9ea15c3 | 2022-01-04 14:18:22 -0800 | [diff] [blame] | 25 | #include <type_traits> |
| 26 | #include <utility> |
Szymon Dompke | ca1600c | 2022-03-03 14:42:52 +0100 | [diff] [blame] | 27 | #include <variant> |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 28 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 29 | namespace crow |
| 30 | { |
| 31 | namespace black_magic |
| 32 | { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 33 | |
Ed Tanous | c715ec2 | 2022-03-10 15:38:01 -0800 | [diff] [blame] | 34 | enum class TypeCode : uint8_t |
| 35 | { |
| 36 | Unspecified = 0, |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 37 | String = 1, |
| 38 | Path = 2, |
| 39 | Max = 3, |
Ed Tanous | c715ec2 | 2022-03-10 15:38:01 -0800 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | // Remove when we have c++23 |
| 43 | template <typename E> |
| 44 | constexpr typename std::underlying_type<E>::type toUnderlying(E e) noexcept |
| 45 | { |
| 46 | return static_cast<typename std::underlying_type<E>::type>(e); |
| 47 | } |
| 48 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 49 | template <typename... Args> |
Ed Tanous | 988403c | 2020-08-24 11:29:49 -0700 | [diff] [blame] | 50 | struct computeParameterTagFromArgsList; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 51 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 52 | template <> |
Ed Tanous | 988403c | 2020-08-24 11:29:49 -0700 | [diff] [blame] | 53 | struct computeParameterTagFromArgsList<> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 54 | { |
Ed Tanous | 6950901 | 2019-10-24 16:53:05 -0700 | [diff] [blame] | 55 | static constexpr int value = 0; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | template <typename Arg, typename... Args> |
Ed Tanous | 988403c | 2020-08-24 11:29:49 -0700 | [diff] [blame] | 59 | struct computeParameterTagFromArgsList<Arg, Args...> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 60 | { |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 61 | static_assert(std::is_same_v<std::string, std::decay_t<Arg>>); |
Ed Tanous | 6950901 | 2019-10-24 16:53:05 -0700 | [diff] [blame] | 62 | static constexpr int subValue = |
Ed Tanous | 988403c | 2020-08-24 11:29:49 -0700 | [diff] [blame] | 63 | computeParameterTagFromArgsList<Args...>::value; |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 64 | static constexpr int value = subValue * toUnderlying(TypeCode::String); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
Ed Tanous | 988403c | 2020-08-24 11:29:49 -0700 | [diff] [blame] | 67 | inline bool isParameterTagCompatible(uint64_t a, uint64_t b) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 68 | { |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 69 | while (true) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 70 | { |
Ed Tanous | ef641b6 | 2022-06-28 19:53:24 -0700 | [diff] [blame] | 71 | if (a == 0 && b == 0) |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 72 | { |
Ed Tanous | ef641b6 | 2022-06-28 19:53:24 -0700 | [diff] [blame] | 73 | // Both tags were equivalent, parameters are compatible |
| 74 | return true; |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 75 | } |
Ed Tanous | ef641b6 | 2022-06-28 19:53:24 -0700 | [diff] [blame] | 76 | if (a == 0 || b == 0) |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 77 | { |
Ed Tanous | ef641b6 | 2022-06-28 19:53:24 -0700 | [diff] [blame] | 78 | // one of the tags had more parameters than the other |
| 79 | return false; |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 80 | } |
Ed Tanous | c715ec2 | 2022-03-10 15:38:01 -0800 | [diff] [blame] | 81 | TypeCode sa = static_cast<TypeCode>(a % toUnderlying(TypeCode::Max)); |
| 82 | TypeCode sb = static_cast<TypeCode>(b % toUnderlying(TypeCode::Max)); |
| 83 | |
| 84 | if (sa == TypeCode::Path) |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 85 | { |
Ed Tanous | c715ec2 | 2022-03-10 15:38:01 -0800 | [diff] [blame] | 86 | sa = TypeCode::String; |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 87 | } |
Ed Tanous | c715ec2 | 2022-03-10 15:38:01 -0800 | [diff] [blame] | 88 | if (sb == TypeCode::Path) |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 89 | { |
Ed Tanous | c715ec2 | 2022-03-10 15:38:01 -0800 | [diff] [blame] | 90 | sb = TypeCode::String; |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 91 | } |
| 92 | if (sa != sb) |
| 93 | { |
| 94 | return false; |
| 95 | } |
Ed Tanous | c715ec2 | 2022-03-10 15:38:01 -0800 | [diff] [blame] | 96 | a /= toUnderlying(TypeCode::Max); |
| 97 | b /= toUnderlying(TypeCode::Max); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 98 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 101 | constexpr inline uint64_t getParameterTag(std::string_view url) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 102 | { |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 103 | uint64_t tagValue = 0; |
| 104 | size_t urlSegmentIndex = std::string_view::npos; |
Ed Tanous | b00dcc2 | 2021-02-23 12:52:50 -0800 | [diff] [blame] | 105 | |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 106 | size_t paramIndex = 0; |
| 107 | |
| 108 | for (size_t urlIndex = 0; urlIndex < url.size(); urlIndex++) |
| 109 | { |
| 110 | char character = url[urlIndex]; |
| 111 | if (character == '<') |
| 112 | { |
| 113 | if (urlSegmentIndex != std::string_view::npos) |
| 114 | { |
| 115 | return 0; |
| 116 | } |
| 117 | urlSegmentIndex = urlIndex; |
| 118 | } |
| 119 | if (character == '>') |
| 120 | { |
| 121 | if (urlSegmentIndex == std::string_view::npos) |
| 122 | { |
| 123 | return 0; |
| 124 | } |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 125 | std::string_view tag = url.substr(urlSegmentIndex, |
| 126 | urlIndex + 1 - urlSegmentIndex); |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 127 | |
| 128 | // Note, this is a really lame way to do std::pow(6, paramIndex) |
| 129 | // std::pow doesn't work in constexpr in clang. |
| 130 | // Ideally in the future we'd move this to use a power of 2 packing |
| 131 | // (probably 8 instead of 6) so that these just become bit shifts |
| 132 | uint64_t insertIndex = 1; |
| 133 | for (size_t unused = 0; unused < paramIndex; unused++) |
| 134 | { |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 135 | insertIndex *= 3; |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 136 | } |
| 137 | |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 138 | if (tag == "<str>" || tag == "<string>") |
| 139 | { |
Ed Tanous | c715ec2 | 2022-03-10 15:38:01 -0800 | [diff] [blame] | 140 | tagValue += insertIndex * toUnderlying(TypeCode::String); |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 141 | } |
| 142 | if (tag == "<path>") |
| 143 | { |
Ed Tanous | c715ec2 | 2022-03-10 15:38:01 -0800 | [diff] [blame] | 144 | tagValue += insertIndex * toUnderlying(TypeCode::Path); |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 145 | } |
| 146 | paramIndex++; |
| 147 | urlSegmentIndex = std::string_view::npos; |
| 148 | } |
| 149 | } |
| 150 | if (urlSegmentIndex != std::string_view::npos) |
Ed Tanous | 988403c | 2020-08-24 11:29:49 -0700 | [diff] [blame] | 151 | { |
| 152 | return 0; |
| 153 | } |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 154 | return tagValue; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 155 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 156 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 157 | template <typename... T> |
| 158 | struct S |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 159 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 160 | template <typename U> |
| 161 | using push = S<U, T...>; |
| 162 | template <typename U> |
| 163 | using push_back = S<T..., U>; |
| 164 | template <template <typename... Args> class U> |
| 165 | using rebind = U<T...>; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 166 | }; |
Ed Tanous | 988403c | 2020-08-24 11:29:49 -0700 | [diff] [blame] | 167 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 168 | template <typename F, typename Set> |
| 169 | struct CallHelper; |
Ed Tanous | 988403c | 2020-08-24 11:29:49 -0700 | [diff] [blame] | 170 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 171 | template <typename F, typename... Args> |
| 172 | struct CallHelper<F, S<Args...>> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 173 | { |
| 174 | template <typename F1, typename... Args1, |
| 175 | typename = decltype(std::declval<F1>()(std::declval<Args1>()...))> |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 176 | static char test(int); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 177 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 178 | template <typename...> |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 179 | static int test(...); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 180 | |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 181 | static constexpr bool value = sizeof(test<F, Args...>(0)) == sizeof(char); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 182 | }; |
| 183 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 184 | template <uint64_t Tag> |
| 185 | struct Arguments |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 186 | { |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 187 | using subarguments = typename Arguments<Tag / 3>::type; |
| 188 | using type = typename subarguments::template push<std::string>; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 189 | }; |
| 190 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 191 | template <> |
| 192 | struct Arguments<0> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 193 | { |
| 194 | using type = S<>; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 195 | }; |
| 196 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 197 | } // namespace black_magic |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 198 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 199 | namespace utility |
| 200 | { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 201 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 202 | template <typename T> |
Ed Tanous | c867a83 | 2022-03-10 14:17:00 -0800 | [diff] [blame] | 203 | struct FunctionTraits |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 204 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 205 | template <size_t i> |
Ed Tanous | c867a83 | 2022-03-10 14:17:00 -0800 | [diff] [blame] | 206 | using arg = std::tuple_element_t<i, boost::callable_traits::args_t<T>>; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 207 | }; |
| 208 | |
Ed Tanous | 26ccae3 | 2023-02-16 10:28:44 -0800 | [diff] [blame] | 209 | inline std::string base64encode(std::string_view data) |
Adriana Kobylak | d830ff5 | 2021-01-27 14:15:27 -0600 | [diff] [blame] | 210 | { |
| 211 | const std::array<char, 64> key = { |
| 212 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', |
| 213 | 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', |
| 214 | 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', |
| 215 | 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', |
| 216 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'}; |
| 217 | |
| 218 | size_t size = data.size(); |
| 219 | std::string ret; |
| 220 | ret.resize((size + 2) / 3 * 4); |
| 221 | auto it = ret.begin(); |
| 222 | |
| 223 | size_t i = 0; |
| 224 | while (i < size) |
| 225 | { |
Ed Tanous | 543f440 | 2022-01-06 13:12:53 -0800 | [diff] [blame] | 226 | size_t keyIndex = 0; |
Adriana Kobylak | d830ff5 | 2021-01-27 14:15:27 -0600 | [diff] [blame] | 227 | |
| 228 | keyIndex = static_cast<size_t>(data[i] & 0xFC) >> 2; |
| 229 | *it++ = key[keyIndex]; |
| 230 | |
| 231 | if (i + 1 < size) |
| 232 | { |
| 233 | keyIndex = static_cast<size_t>(data[i] & 0x03) << 4; |
| 234 | keyIndex += static_cast<size_t>(data[i + 1] & 0xF0) >> 4; |
| 235 | *it++ = key[keyIndex]; |
| 236 | |
| 237 | if (i + 2 < size) |
| 238 | { |
| 239 | keyIndex = static_cast<size_t>(data[i + 1] & 0x0F) << 2; |
| 240 | keyIndex += static_cast<size_t>(data[i + 2] & 0xC0) >> 6; |
| 241 | *it++ = key[keyIndex]; |
| 242 | |
| 243 | keyIndex = static_cast<size_t>(data[i + 2] & 0x3F); |
| 244 | *it++ = key[keyIndex]; |
| 245 | } |
| 246 | else |
| 247 | { |
| 248 | keyIndex = static_cast<size_t>(data[i + 1] & 0x0F) << 2; |
| 249 | *it++ = key[keyIndex]; |
| 250 | *it++ = '='; |
| 251 | } |
| 252 | } |
| 253 | else |
| 254 | { |
| 255 | keyIndex = static_cast<size_t>(data[i] & 0x03) << 4; |
| 256 | *it++ = key[keyIndex]; |
| 257 | *it++ = '='; |
| 258 | *it++ = '='; |
| 259 | } |
| 260 | |
| 261 | i += 3; |
| 262 | } |
| 263 | |
| 264 | return ret; |
| 265 | } |
| 266 | |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 267 | // TODO this is temporary and should be deleted once base64 is refactored out of |
| 268 | // crow |
Ed Tanous | 26ccae3 | 2023-02-16 10:28:44 -0800 | [diff] [blame] | 269 | inline bool base64Decode(std::string_view input, std::string& output) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 270 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 271 | static const char nop = static_cast<char>(-1); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 272 | // See note on encoding_data[] in above function |
Jonathan Doman | 5beaf84 | 2020-08-14 11:23:33 -0700 | [diff] [blame] | 273 | static const std::array<char, 256> decodingData = { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 274 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 275 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 276 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 277 | nop, 62, nop, nop, nop, 63, 52, 53, 54, 55, 56, 57, 58, 59, |
| 278 | 60, 61, nop, nop, nop, nop, nop, nop, nop, 0, 1, 2, 3, 4, |
| 279 | 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, |
| 280 | 19, 20, 21, 22, 23, 24, 25, nop, nop, nop, nop, nop, nop, 26, |
| 281 | 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, |
| 282 | 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, nop, nop, nop, |
| 283 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 284 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 285 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 286 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 287 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 288 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 289 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 290 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 291 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 292 | nop, nop, nop, nop}; |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 293 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 294 | size_t inputLength = input.size(); |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 295 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 296 | // allocate space for output string |
| 297 | output.clear(); |
| 298 | output.reserve(((inputLength + 2) / 3) * 4); |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 299 | |
Jonathan Doman | 5beaf84 | 2020-08-14 11:23:33 -0700 | [diff] [blame] | 300 | auto getCodeValue = [](char c) { |
| 301 | auto code = static_cast<unsigned char>(c); |
| 302 | // Ensure we cannot index outside the bounds of the decoding array |
| 303 | static_assert(std::numeric_limits<decltype(code)>::max() < |
| 304 | decodingData.size()); |
| 305 | return decodingData[code]; |
| 306 | }; |
| 307 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 308 | // for each 4-bytes sequence from the input, extract 4 6-bits sequences by |
Gunnar Mills | caa3ce3 | 2020-07-08 14:46:53 -0500 | [diff] [blame] | 309 | // dropping first two bits |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 310 | // and regenerate into 3 8-bits sequences |
James Feist | 5a80664 | 2020-07-31 16:40:33 +0000 | [diff] [blame] | 311 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 312 | for (size_t i = 0; i < inputLength; i++) |
| 313 | { |
Ed Tanous | 543f440 | 2022-01-06 13:12:53 -0800 | [diff] [blame] | 314 | char base64code0 = 0; |
| 315 | char base64code1 = 0; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 316 | char base64code2 = 0; // initialized to 0 to suppress warnings |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 317 | |
Jonathan Doman | 5beaf84 | 2020-08-14 11:23:33 -0700 | [diff] [blame] | 318 | base64code0 = getCodeValue(input[i]); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 319 | if (base64code0 == nop) |
| 320 | { // non base64 character |
| 321 | return false; |
| 322 | } |
| 323 | if (!(++i < inputLength)) |
| 324 | { // we need at least two input bytes for first |
| 325 | // byte output |
| 326 | return false; |
| 327 | } |
Jonathan Doman | 5beaf84 | 2020-08-14 11:23:33 -0700 | [diff] [blame] | 328 | base64code1 = getCodeValue(input[i]); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 329 | if (base64code1 == nop) |
| 330 | { // non base64 character |
| 331 | return false; |
| 332 | } |
| 333 | output += |
| 334 | static_cast<char>((base64code0 << 2) | ((base64code1 >> 4) & 0x3)); |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 335 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 336 | if (++i < inputLength) |
| 337 | { |
| 338 | char c = input[i]; |
| 339 | if (c == '=') |
| 340 | { // padding , end of input |
| 341 | return (base64code1 & 0x0f) == 0; |
| 342 | } |
Jonathan Doman | 5beaf84 | 2020-08-14 11:23:33 -0700 | [diff] [blame] | 343 | base64code2 = getCodeValue(input[i]); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 344 | if (base64code2 == nop) |
| 345 | { // non base64 character |
| 346 | return false; |
| 347 | } |
| 348 | output += static_cast<char>(((base64code1 << 4) & 0xf0) | |
| 349 | ((base64code2 >> 2) & 0x0f)); |
| 350 | } |
| 351 | |
| 352 | if (++i < inputLength) |
| 353 | { |
| 354 | char c = input[i]; |
| 355 | if (c == '=') |
| 356 | { // padding , end of input |
| 357 | return (base64code2 & 0x03) == 0; |
| 358 | } |
Ed Tanous | f8fe53e | 2022-06-30 15:55:45 -0700 | [diff] [blame] | 359 | char base64code3 = getCodeValue(input[i]); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 360 | if (base64code3 == nop) |
| 361 | { // non base64 character |
| 362 | return false; |
| 363 | } |
| 364 | output += |
| 365 | static_cast<char>((((base64code2 << 6) & 0xc0) | base64code3)); |
| 366 | } |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 367 | } |
| 368 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 369 | return true; |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 370 | } |
| 371 | |
Ed Tanous | 26ccae3 | 2023-02-16 10:28:44 -0800 | [diff] [blame] | 372 | inline bool constantTimeStringCompare(std::string_view a, std::string_view b) |
Ed Tanous | 51dae67 | 2018-09-05 16:07:32 -0700 | [diff] [blame] | 373 | { |
| 374 | // Important note, this function is ONLY constant time if the two input |
| 375 | // sizes are the same |
| 376 | if (a.size() != b.size()) |
| 377 | { |
| 378 | return false; |
| 379 | } |
| 380 | return CRYPTO_memcmp(a.data(), b.data(), a.size()) == 0; |
| 381 | } |
| 382 | |
| 383 | struct ConstantTimeCompare |
| 384 | { |
Ed Tanous | 26ccae3 | 2023-02-16 10:28:44 -0800 | [diff] [blame] | 385 | bool operator()(std::string_view a, std::string_view b) const |
Ed Tanous | 51dae67 | 2018-09-05 16:07:32 -0700 | [diff] [blame] | 386 | { |
| 387 | return constantTimeStringCompare(a, b); |
| 388 | } |
| 389 | }; |
| 390 | |
Ed Tanous | eae855c | 2021-10-26 11:26:02 -0700 | [diff] [blame] | 391 | namespace details |
| 392 | { |
| 393 | inline boost::urls::url |
Willy Tu | c6bcedc | 2022-09-27 05:36:59 +0000 | [diff] [blame] | 394 | appendUrlPieces(boost::urls::url& url, |
| 395 | const std::initializer_list<std::string_view> args) |
Ed Tanous | eae855c | 2021-10-26 11:26:02 -0700 | [diff] [blame] | 396 | { |
Ed Tanous | 26ccae3 | 2023-02-16 10:28:44 -0800 | [diff] [blame] | 397 | for (std::string_view arg : args) |
Ed Tanous | eae855c | 2021-10-26 11:26:02 -0700 | [diff] [blame] | 398 | { |
| 399 | url.segments().push_back(arg); |
| 400 | } |
| 401 | return url; |
| 402 | } |
Willy Tu | c6bcedc | 2022-09-27 05:36:59 +0000 | [diff] [blame] | 403 | |
Ed Tanous | eae855c | 2021-10-26 11:26:02 -0700 | [diff] [blame] | 404 | } // namespace details |
| 405 | |
Ed Tanous | 7f8d8fa | 2022-08-19 07:00:38 -0700 | [diff] [blame] | 406 | class OrMorePaths |
| 407 | {}; |
| 408 | |
Ed Tanous | eae855c | 2021-10-26 11:26:02 -0700 | [diff] [blame] | 409 | template <typename... AV> |
Willy Tu | c6bcedc | 2022-09-27 05:36:59 +0000 | [diff] [blame] | 410 | inline void appendUrlPieces(boost::urls::url& url, const AV... args) |
| 411 | { |
| 412 | details::appendUrlPieces(url, {args...}); |
| 413 | } |
| 414 | |
Szymon Dompke | ca1600c | 2022-03-03 14:42:52 +0100 | [diff] [blame] | 415 | namespace details |
| 416 | { |
| 417 | |
| 418 | // std::reference_wrapper<std::string> - extracts segment to variable |
| 419 | // std::string_view - checks if segment is equal to variable |
Ed Tanous | 7f8d8fa | 2022-08-19 07:00:38 -0700 | [diff] [blame] | 420 | using UrlSegment = std::variant<std::reference_wrapper<std::string>, |
| 421 | std::string_view, OrMorePaths>; |
| 422 | |
| 423 | enum class UrlParseResult |
| 424 | { |
| 425 | Continue, |
| 426 | Fail, |
| 427 | Done, |
| 428 | }; |
Szymon Dompke | ca1600c | 2022-03-03 14:42:52 +0100 | [diff] [blame] | 429 | |
| 430 | class UrlSegmentMatcherVisitor |
| 431 | { |
| 432 | public: |
Ed Tanous | 7f8d8fa | 2022-08-19 07:00:38 -0700 | [diff] [blame] | 433 | UrlParseResult operator()(std::string& output) |
Szymon Dompke | ca1600c | 2022-03-03 14:42:52 +0100 | [diff] [blame] | 434 | { |
Ed Tanous | 079360a | 2022-06-29 10:05:19 -0700 | [diff] [blame] | 435 | output = segment; |
Ed Tanous | 7f8d8fa | 2022-08-19 07:00:38 -0700 | [diff] [blame] | 436 | return UrlParseResult::Continue; |
Szymon Dompke | ca1600c | 2022-03-03 14:42:52 +0100 | [diff] [blame] | 437 | } |
| 438 | |
Ed Tanous | 7f8d8fa | 2022-08-19 07:00:38 -0700 | [diff] [blame] | 439 | UrlParseResult operator()(std::string_view expected) |
Szymon Dompke | ca1600c | 2022-03-03 14:42:52 +0100 | [diff] [blame] | 440 | { |
Ed Tanous | 079360a | 2022-06-29 10:05:19 -0700 | [diff] [blame] | 441 | if (segment == expected) |
Ed Tanous | 7f8d8fa | 2022-08-19 07:00:38 -0700 | [diff] [blame] | 442 | { |
| 443 | return UrlParseResult::Continue; |
| 444 | } |
| 445 | return UrlParseResult::Fail; |
| 446 | } |
| 447 | |
| 448 | UrlParseResult operator()(OrMorePaths /*unused*/) |
| 449 | { |
| 450 | return UrlParseResult::Done; |
Szymon Dompke | ca1600c | 2022-03-03 14:42:52 +0100 | [diff] [blame] | 451 | } |
| 452 | |
Ed Tanous | 079360a | 2022-06-29 10:05:19 -0700 | [diff] [blame] | 453 | explicit UrlSegmentMatcherVisitor(std::string_view segmentIn) : |
Szymon Dompke | ca1600c | 2022-03-03 14:42:52 +0100 | [diff] [blame] | 454 | segment(segmentIn) |
| 455 | {} |
| 456 | |
| 457 | private: |
Ed Tanous | 079360a | 2022-06-29 10:05:19 -0700 | [diff] [blame] | 458 | std::string_view segment; |
Szymon Dompke | ca1600c | 2022-03-03 14:42:52 +0100 | [diff] [blame] | 459 | }; |
| 460 | |
Ed Tanous | d9f466b | 2023-03-06 15:04:25 -0800 | [diff] [blame] | 461 | inline bool readUrlSegments(boost::urls::url_view url, |
Szymon Dompke | ca1600c | 2022-03-03 14:42:52 +0100 | [diff] [blame] | 462 | std::initializer_list<UrlSegment>&& segments) |
| 463 | { |
Ed Tanous | d9f466b | 2023-03-06 15:04:25 -0800 | [diff] [blame] | 464 | boost::urls::segments_view urlSegments = url.segments(); |
Szymon Dompke | ca1600c | 2022-03-03 14:42:52 +0100 | [diff] [blame] | 465 | |
Ed Tanous | 7f8d8fa | 2022-08-19 07:00:38 -0700 | [diff] [blame] | 466 | if (!urlSegments.is_absolute()) |
Szymon Dompke | ca1600c | 2022-03-03 14:42:52 +0100 | [diff] [blame] | 467 | { |
| 468 | return false; |
| 469 | } |
| 470 | |
| 471 | boost::urls::segments_view::iterator it = urlSegments.begin(); |
| 472 | boost::urls::segments_view::iterator end = urlSegments.end(); |
| 473 | |
| 474 | for (const auto& segment : segments) |
| 475 | { |
Ed Tanous | 7f8d8fa | 2022-08-19 07:00:38 -0700 | [diff] [blame] | 476 | if (it == end) |
| 477 | { |
| 478 | // If the request ends with an "any" path, this was successful |
| 479 | return std::holds_alternative<OrMorePaths>(segment); |
| 480 | } |
| 481 | UrlParseResult res = std::visit(UrlSegmentMatcherVisitor(*it), segment); |
| 482 | if (res == UrlParseResult::Done) |
| 483 | { |
| 484 | return true; |
| 485 | } |
| 486 | if (res == UrlParseResult::Fail) |
Szymon Dompke | ca1600c | 2022-03-03 14:42:52 +0100 | [diff] [blame] | 487 | { |
| 488 | return false; |
| 489 | } |
| 490 | it++; |
| 491 | } |
Carson Labrado | 4c30e22 | 2022-06-24 22:16:00 +0000 | [diff] [blame] | 492 | |
| 493 | // There will be an empty segment at the end if the URI ends with a "/" |
| 494 | // e.g. /redfish/v1/Chassis/ |
| 495 | if ((it != end) && urlSegments.back().empty()) |
| 496 | { |
| 497 | it++; |
| 498 | } |
Ed Tanous | 7f8d8fa | 2022-08-19 07:00:38 -0700 | [diff] [blame] | 499 | return it == end; |
Szymon Dompke | ca1600c | 2022-03-03 14:42:52 +0100 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | } // namespace details |
| 503 | |
| 504 | template <typename... Args> |
Ed Tanous | d9f466b | 2023-03-06 15:04:25 -0800 | [diff] [blame] | 505 | inline bool readUrlSegments(boost::urls::url_view url, Args&&... args) |
Szymon Dompke | ca1600c | 2022-03-03 14:42:52 +0100 | [diff] [blame] | 506 | { |
Ed Tanous | 39662a3 | 2023-02-06 15:09:46 -0800 | [diff] [blame] | 507 | return details::readUrlSegments(url, {std::forward<Args>(args)...}); |
Szymon Dompke | ca1600c | 2022-03-03 14:42:52 +0100 | [diff] [blame] | 508 | } |
| 509 | |
Ed Tanous | d9f466b | 2023-03-06 15:04:25 -0800 | [diff] [blame] | 510 | inline boost::urls::url replaceUrlSegment(boost::urls::url_view urlView, |
Carson Labrado | 1c0bb5c | 2022-05-18 00:12:52 +0000 | [diff] [blame] | 511 | const uint replaceLoc, |
Ed Tanous | 26ccae3 | 2023-02-16 10:28:44 -0800 | [diff] [blame] | 512 | std::string_view newSegment) |
Carson Labrado | 1c0bb5c | 2022-05-18 00:12:52 +0000 | [diff] [blame] | 513 | { |
Ed Tanous | d9f466b | 2023-03-06 15:04:25 -0800 | [diff] [blame] | 514 | boost::urls::segments_view urlSegments = urlView.segments(); |
Carson Labrado | 1c0bb5c | 2022-05-18 00:12:52 +0000 | [diff] [blame] | 515 | boost::urls::url url("/"); |
| 516 | |
| 517 | if (!urlSegments.is_absolute()) |
| 518 | { |
| 519 | return url; |
| 520 | } |
| 521 | |
| 522 | boost::urls::segments_view::iterator it = urlSegments.begin(); |
| 523 | boost::urls::segments_view::iterator end = urlSegments.end(); |
| 524 | |
| 525 | for (uint idx = 0; it != end; it++, idx++) |
| 526 | { |
| 527 | if (idx == replaceLoc) |
| 528 | { |
| 529 | url.segments().push_back(newSegment); |
| 530 | } |
| 531 | else |
| 532 | { |
| 533 | url.segments().push_back(*it); |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | return url; |
| 538 | } |
| 539 | |
Ed Tanous | d9f466b | 2023-03-06 15:04:25 -0800 | [diff] [blame] | 540 | inline std::string setProtocolDefaults(boost::urls::url_view urlView) |
Ed Tanous | eb1c47d | 2022-02-09 11:47:27 -0800 | [diff] [blame] | 541 | { |
Ed Tanous | 39662a3 | 2023-02-06 15:09:46 -0800 | [diff] [blame] | 542 | if (urlView.scheme() == "https") |
Ed Tanous | eb1c47d | 2022-02-09 11:47:27 -0800 | [diff] [blame] | 543 | { |
| 544 | return "https"; |
| 545 | } |
Ed Tanous | 39662a3 | 2023-02-06 15:09:46 -0800 | [diff] [blame] | 546 | if (urlView.scheme() == "http") |
Ed Tanous | eb1c47d | 2022-02-09 11:47:27 -0800 | [diff] [blame] | 547 | { |
| 548 | if (bmcwebInsecureEnableHttpPushStyleEventing) |
| 549 | { |
| 550 | return "http"; |
| 551 | } |
| 552 | return ""; |
| 553 | } |
| 554 | return ""; |
| 555 | } |
| 556 | |
Ed Tanous | d9f466b | 2023-03-06 15:04:25 -0800 | [diff] [blame] | 557 | inline uint16_t setPortDefaults(boost::urls::url_view url) |
Ed Tanous | eb1c47d | 2022-02-09 11:47:27 -0800 | [diff] [blame] | 558 | { |
| 559 | uint16_t port = url.port_number(); |
| 560 | if (port != 0) |
| 561 | { |
| 562 | // user picked a port already. |
| 563 | return port; |
| 564 | } |
| 565 | |
| 566 | // If the user hasn't explicitly stated a port, pick one explicitly for them |
| 567 | // based on the protocol defaults |
| 568 | if (url.scheme() == "http") |
| 569 | { |
| 570 | return 80; |
| 571 | } |
| 572 | if (url.scheme() == "https") |
| 573 | { |
| 574 | return 443; |
| 575 | } |
| 576 | return 0; |
| 577 | } |
| 578 | |
Ed Tanous | 11baefe | 2022-02-09 12:14:12 -0800 | [diff] [blame] | 579 | inline bool validateAndSplitUrl(std::string_view destUrl, std::string& urlProto, |
Ed Tanous | eb1c47d | 2022-02-09 11:47:27 -0800 | [diff] [blame] | 580 | std::string& host, uint16_t& port, |
Ed Tanous | 11baefe | 2022-02-09 12:14:12 -0800 | [diff] [blame] | 581 | std::string& path) |
| 582 | { |
Ed Tanous | eb1c47d | 2022-02-09 11:47:27 -0800 | [diff] [blame] | 583 | boost::urls::result<boost::urls::url_view> url = |
Ed Tanous | 079360a | 2022-06-29 10:05:19 -0700 | [diff] [blame] | 584 | boost::urls::parse_uri(destUrl); |
Ed Tanous | eb1c47d | 2022-02-09 11:47:27 -0800 | [diff] [blame] | 585 | if (!url) |
| 586 | { |
| 587 | return false; |
| 588 | } |
| 589 | urlProto = setProtocolDefaults(url.value()); |
| 590 | if (urlProto.empty()) |
Ed Tanous | 11baefe | 2022-02-09 12:14:12 -0800 | [diff] [blame] | 591 | { |
| 592 | return false; |
| 593 | } |
| 594 | |
Ed Tanous | eb1c47d | 2022-02-09 11:47:27 -0800 | [diff] [blame] | 595 | port = setPortDefaults(url.value()); |
Ed Tanous | 11baefe | 2022-02-09 12:14:12 -0800 | [diff] [blame] | 596 | |
Ed Tanous | 079360a | 2022-06-29 10:05:19 -0700 | [diff] [blame] | 597 | host = url->encoded_host(); |
Ed Tanous | eb1c47d | 2022-02-09 11:47:27 -0800 | [diff] [blame] | 598 | |
Ed Tanous | 079360a | 2022-06-29 10:05:19 -0700 | [diff] [blame] | 599 | path = url->encoded_path(); |
Ed Tanous | 11baefe | 2022-02-09 12:14:12 -0800 | [diff] [blame] | 600 | if (path.empty()) |
| 601 | { |
| 602 | path = "/"; |
| 603 | } |
Ed Tanous | eb1c47d | 2022-02-09 11:47:27 -0800 | [diff] [blame] | 604 | if (url->has_fragment()) |
| 605 | { |
| 606 | path += '#'; |
Ed Tanous | 079360a | 2022-06-29 10:05:19 -0700 | [diff] [blame] | 607 | path += url->encoded_fragment(); |
Ed Tanous | eb1c47d | 2022-02-09 11:47:27 -0800 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | if (url->has_query()) |
| 611 | { |
| 612 | path += '?'; |
Ed Tanous | 079360a | 2022-06-29 10:05:19 -0700 | [diff] [blame] | 613 | path += url->encoded_query(); |
Ed Tanous | eb1c47d | 2022-02-09 11:47:27 -0800 | [diff] [blame] | 614 | } |
| 615 | |
Ed Tanous | 11baefe | 2022-02-09 12:14:12 -0800 | [diff] [blame] | 616 | return true; |
| 617 | } |
| 618 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 619 | } // namespace utility |
| 620 | } // namespace crow |
Ed Tanous | 71f2db7 | 2022-05-25 12:28:09 -0700 | [diff] [blame] | 621 | |
| 622 | namespace nlohmann |
| 623 | { |
| 624 | template <> |
| 625 | struct adl_serializer<boost::urls::url> |
| 626 | { |
| 627 | // nlohmann requires a specific casing to look these up in adl |
| 628 | // NOLINTNEXTLINE(readability-identifier-naming) |
| 629 | static void to_json(json& j, const boost::urls::url& url) |
| 630 | { |
Ed Tanous | 079360a | 2022-06-29 10:05:19 -0700 | [diff] [blame] | 631 | j = url.buffer(); |
Ed Tanous | 71f2db7 | 2022-05-25 12:28:09 -0700 | [diff] [blame] | 632 | } |
| 633 | }; |
| 634 | |
| 635 | template <> |
| 636 | struct adl_serializer<boost::urls::url_view> |
| 637 | { |
| 638 | // NOLINTNEXTLINE(readability-identifier-naming) |
Ed Tanous | d9f466b | 2023-03-06 15:04:25 -0800 | [diff] [blame] | 639 | static void to_json(json& j, boost::urls::url_view url) |
Ed Tanous | 71f2db7 | 2022-05-25 12:28:09 -0700 | [diff] [blame] | 640 | { |
Ed Tanous | 079360a | 2022-06-29 10:05:19 -0700 | [diff] [blame] | 641 | j = url.buffer(); |
Ed Tanous | 71f2db7 | 2022-05-25 12:28:09 -0700 | [diff] [blame] | 642 | } |
| 643 | }; |
| 644 | } // namespace nlohmann |