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