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 | 51dae67 | 2018-09-05 16:07:32 -0700 | [diff] [blame] | 3 | #include <openssl/crypto.h> |
| 4 | |
Nan Zhou | 1d8782e | 2021-11-29 22:23:18 -0800 | [diff] [blame] | 5 | #include <boost/date_time/posix_time/posix_time.hpp> |
Ed Tanous | eae855c | 2021-10-26 11:26:02 -0700 | [diff] [blame] | 6 | #include <boost/url/url.hpp> |
Nan Zhou | 1d8782e | 2021-11-29 22:23:18 -0800 | [diff] [blame] | 7 | |
Ed Tanous | 9ea15c3 | 2022-01-04 14:18:22 -0800 | [diff] [blame] | 8 | #include <array> |
Ed Tanous | 74849be | 2021-02-05 09:47:47 -0800 | [diff] [blame] | 9 | #include <chrono> |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 10 | #include <cstdint> |
Ed Tanous | 9ea15c3 | 2022-01-04 14:18:22 -0800 | [diff] [blame] | 11 | #include <ctime> |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 12 | #include <functional> |
Ed Tanous | 9ea15c3 | 2022-01-04 14:18:22 -0800 | [diff] [blame] | 13 | #include <limits> |
Ed Tanous | 11baefe | 2022-02-09 12:14:12 -0800 | [diff] [blame] | 14 | #include <regex> |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 15 | #include <stdexcept> |
| 16 | #include <string> |
Ed Tanous | 9ea15c3 | 2022-01-04 14:18:22 -0800 | [diff] [blame] | 17 | #include <string_view> |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 18 | #include <tuple> |
Ed Tanous | 9ea15c3 | 2022-01-04 14:18:22 -0800 | [diff] [blame] | 19 | #include <type_traits> |
| 20 | #include <utility> |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 21 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 22 | namespace crow |
| 23 | { |
| 24 | namespace black_magic |
| 25 | { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 26 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 27 | template <typename T> |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 28 | constexpr uint64_t getParameterTag() |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 29 | { |
Ed Tanous | 6950901 | 2019-10-24 16:53:05 -0700 | [diff] [blame] | 30 | if constexpr (std::is_same_v<int, T>) |
| 31 | { |
| 32 | return 1; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 33 | } |
Ed Tanous | 6950901 | 2019-10-24 16:53:05 -0700 | [diff] [blame] | 34 | if constexpr (std::is_same_v<char, T>) |
| 35 | { |
| 36 | return 1; |
| 37 | } |
| 38 | if constexpr (std::is_same_v<short, T>) |
| 39 | { |
| 40 | return 1; |
| 41 | } |
| 42 | if constexpr (std::is_same_v<long, T>) |
| 43 | { |
| 44 | return 1; |
| 45 | } |
| 46 | if constexpr (std::is_same_v<long long, T>) |
| 47 | { |
| 48 | return 1; |
| 49 | } |
| 50 | if constexpr (std::is_same_v<unsigned int, T>) |
| 51 | { |
| 52 | return 2; |
| 53 | } |
| 54 | if constexpr (std::is_same_v<unsigned char, T>) |
| 55 | { |
| 56 | return 2; |
| 57 | } |
| 58 | if constexpr (std::is_same_v<unsigned short, T>) |
| 59 | { |
| 60 | return 2; |
| 61 | } |
| 62 | if constexpr (std::is_same_v<unsigned long, T>) |
| 63 | { |
| 64 | return 2; |
| 65 | } |
| 66 | if constexpr (std::is_same_v<unsigned long long, T>) |
| 67 | { |
| 68 | return 2; |
| 69 | } |
| 70 | if constexpr (std::is_same_v<double, T>) |
| 71 | { |
| 72 | return 3; |
| 73 | } |
| 74 | if constexpr (std::is_same_v<std::string, T>) |
| 75 | { |
| 76 | return 4; |
| 77 | } |
| 78 | return 0; |
| 79 | } |
| 80 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 81 | template <typename... Args> |
Ed Tanous | 988403c | 2020-08-24 11:29:49 -0700 | [diff] [blame] | 82 | struct computeParameterTagFromArgsList; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 83 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 84 | template <> |
Ed Tanous | 988403c | 2020-08-24 11:29:49 -0700 | [diff] [blame] | 85 | struct computeParameterTagFromArgsList<> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 86 | { |
Ed Tanous | 6950901 | 2019-10-24 16:53:05 -0700 | [diff] [blame] | 87 | static constexpr int value = 0; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | template <typename Arg, typename... Args> |
Ed Tanous | 988403c | 2020-08-24 11:29:49 -0700 | [diff] [blame] | 91 | struct computeParameterTagFromArgsList<Arg, Args...> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 92 | { |
Ed Tanous | 6950901 | 2019-10-24 16:53:05 -0700 | [diff] [blame] | 93 | static constexpr int subValue = |
Ed Tanous | 988403c | 2020-08-24 11:29:49 -0700 | [diff] [blame] | 94 | computeParameterTagFromArgsList<Args...>::value; |
Ed Tanous | 6950901 | 2019-10-24 16:53:05 -0700 | [diff] [blame] | 95 | static constexpr int value = |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 96 | getParameterTag<typename std::decay<Arg>::type>() != 0 |
Ed Tanous | 6950901 | 2019-10-24 16:53:05 -0700 | [diff] [blame] | 97 | ? subValue * 6 + getParameterTag<typename std::decay<Arg>::type>() |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 98 | : subValue; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
Ed Tanous | 988403c | 2020-08-24 11:29:49 -0700 | [diff] [blame] | 101 | inline bool isParameterTagCompatible(uint64_t a, uint64_t b) |
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 | while (true) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 104 | { |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 105 | if (a == 0) |
| 106 | { |
| 107 | return b == 0; |
| 108 | } |
| 109 | if (b == 0) |
| 110 | { |
| 111 | return a == 0; |
| 112 | } |
| 113 | uint64_t sa = a % 6; |
| 114 | uint64_t sb = a % 6; |
| 115 | if (sa == 5) |
| 116 | { |
| 117 | sa = 4; |
| 118 | } |
| 119 | if (sb == 5) |
| 120 | { |
| 121 | sb = 4; |
| 122 | } |
| 123 | if (sa != sb) |
| 124 | { |
| 125 | return false; |
| 126 | } |
| 127 | a /= 6; |
| 128 | b /= 6; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 129 | } |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 130 | return false; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 133 | constexpr inline uint64_t getParameterTag(std::string_view url) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 134 | { |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 135 | uint64_t tagValue = 0; |
| 136 | size_t urlSegmentIndex = std::string_view::npos; |
Ed Tanous | b00dcc2 | 2021-02-23 12:52:50 -0800 | [diff] [blame] | 137 | |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 138 | size_t paramIndex = 0; |
| 139 | |
| 140 | for (size_t urlIndex = 0; urlIndex < url.size(); urlIndex++) |
| 141 | { |
| 142 | char character = url[urlIndex]; |
| 143 | if (character == '<') |
| 144 | { |
| 145 | if (urlSegmentIndex != std::string_view::npos) |
| 146 | { |
| 147 | return 0; |
| 148 | } |
| 149 | urlSegmentIndex = urlIndex; |
| 150 | } |
| 151 | if (character == '>') |
| 152 | { |
| 153 | if (urlSegmentIndex == std::string_view::npos) |
| 154 | { |
| 155 | return 0; |
| 156 | } |
| 157 | std::string_view tag = |
| 158 | url.substr(urlSegmentIndex, urlIndex + 1 - urlSegmentIndex); |
| 159 | |
| 160 | // Note, this is a really lame way to do std::pow(6, paramIndex) |
| 161 | // std::pow doesn't work in constexpr in clang. |
| 162 | // Ideally in the future we'd move this to use a power of 2 packing |
| 163 | // (probably 8 instead of 6) so that these just become bit shifts |
| 164 | uint64_t insertIndex = 1; |
| 165 | for (size_t unused = 0; unused < paramIndex; unused++) |
| 166 | { |
| 167 | insertIndex *= 6; |
| 168 | } |
| 169 | |
| 170 | if (tag == "<int>") |
| 171 | { |
| 172 | tagValue += insertIndex * 1; |
| 173 | } |
| 174 | if (tag == "<uint>") |
| 175 | { |
| 176 | tagValue += insertIndex * 2; |
| 177 | } |
| 178 | if (tag == "<float>" || tag == "<double>") |
| 179 | { |
| 180 | tagValue += insertIndex * 3; |
| 181 | } |
| 182 | if (tag == "<str>" || tag == "<string>") |
| 183 | { |
| 184 | tagValue += insertIndex * 4; |
| 185 | } |
| 186 | if (tag == "<path>") |
| 187 | { |
| 188 | tagValue += insertIndex * 5; |
| 189 | } |
| 190 | paramIndex++; |
| 191 | urlSegmentIndex = std::string_view::npos; |
| 192 | } |
| 193 | } |
| 194 | if (urlSegmentIndex != std::string_view::npos) |
Ed Tanous | 988403c | 2020-08-24 11:29:49 -0700 | [diff] [blame] | 195 | { |
| 196 | return 0; |
| 197 | } |
Ed Tanous | 1c30e50 | 2022-03-08 18:02:24 -0800 | [diff] [blame] | 198 | return tagValue; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 199 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 200 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 201 | template <typename... T> |
| 202 | struct S |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 203 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 204 | template <typename U> |
| 205 | using push = S<U, T...>; |
| 206 | template <typename U> |
| 207 | using push_back = S<T..., U>; |
| 208 | template <template <typename... Args> class U> |
| 209 | using rebind = U<T...>; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 210 | }; |
Ed Tanous | 988403c | 2020-08-24 11:29:49 -0700 | [diff] [blame] | 211 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 212 | template <typename F, typename Set> |
| 213 | struct CallHelper; |
Ed Tanous | 988403c | 2020-08-24 11:29:49 -0700 | [diff] [blame] | 214 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 215 | template <typename F, typename... Args> |
| 216 | struct CallHelper<F, S<Args...>> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 217 | { |
| 218 | template <typename F1, typename... Args1, |
| 219 | typename = decltype(std::declval<F1>()(std::declval<Args1>()...))> |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 220 | static char test(int); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 221 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 222 | template <typename...> |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 223 | static int test(...); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 224 | |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 225 | static constexpr bool value = sizeof(test<F, Args...>(0)) == sizeof(char); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 226 | }; |
| 227 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 228 | template <uint64_t N> |
| 229 | struct SingleTagToType |
| 230 | {}; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 231 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 232 | template <> |
| 233 | struct SingleTagToType<1> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 234 | { |
| 235 | using type = int64_t; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 236 | }; |
| 237 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 238 | template <> |
| 239 | struct SingleTagToType<2> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 240 | { |
| 241 | using type = uint64_t; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 242 | }; |
| 243 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 244 | template <> |
| 245 | struct SingleTagToType<3> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 246 | { |
| 247 | using type = double; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 248 | }; |
| 249 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 250 | template <> |
| 251 | struct SingleTagToType<4> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 252 | { |
| 253 | using type = std::string; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 254 | }; |
| 255 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 256 | template <> |
| 257 | struct SingleTagToType<5> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 258 | { |
| 259 | using type = std::string; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 260 | }; |
| 261 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 262 | template <uint64_t Tag> |
| 263 | struct Arguments |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 264 | { |
| 265 | using subarguments = typename Arguments<Tag / 6>::type; |
| 266 | using type = typename subarguments::template push< |
| 267 | typename SingleTagToType<Tag % 6>::type>; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 268 | }; |
| 269 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 270 | template <> |
| 271 | struct Arguments<0> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 272 | { |
| 273 | using type = S<>; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 274 | }; |
| 275 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 276 | template <typename T> |
Ed Tanous | 988403c | 2020-08-24 11:29:49 -0700 | [diff] [blame] | 277 | struct Promote |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 278 | { |
| 279 | using type = T; |
| 280 | }; |
| 281 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 282 | template <typename T> |
Ed Tanous | 988403c | 2020-08-24 11:29:49 -0700 | [diff] [blame] | 283 | using PromoteT = typename Promote<T>::type; |
| 284 | |
| 285 | template <> |
| 286 | struct Promote<char> |
| 287 | { |
| 288 | using type = int64_t; |
| 289 | }; |
| 290 | template <> |
| 291 | struct Promote<short> |
| 292 | { |
| 293 | using type = int64_t; |
| 294 | }; |
| 295 | template <> |
| 296 | struct Promote<int> |
| 297 | { |
| 298 | using type = int64_t; |
| 299 | }; |
| 300 | template <> |
| 301 | struct Promote<long> |
| 302 | { |
| 303 | using type = int64_t; |
| 304 | }; |
| 305 | template <> |
| 306 | struct Promote<long long> |
| 307 | { |
| 308 | using type = int64_t; |
| 309 | }; |
| 310 | template <> |
| 311 | struct Promote<unsigned char> |
| 312 | { |
| 313 | using type = uint64_t; |
| 314 | }; |
| 315 | template <> |
| 316 | struct Promote<unsigned short> |
| 317 | { |
| 318 | using type = uint64_t; |
| 319 | }; |
| 320 | template <> |
| 321 | struct Promote<unsigned int> |
| 322 | { |
| 323 | using type = uint64_t; |
| 324 | }; |
| 325 | template <> |
| 326 | struct Promote<unsigned long> |
| 327 | { |
| 328 | using type = uint64_t; |
| 329 | }; |
| 330 | template <> |
| 331 | struct Promote<unsigned long long> |
| 332 | { |
| 333 | using type = uint64_t; |
| 334 | }; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 335 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 336 | } // namespace black_magic |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 337 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 338 | namespace utility |
| 339 | { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 340 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 341 | template <typename T> |
| 342 | struct function_traits; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 343 | |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 344 | template <typename T> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 345 | struct function_traits : public function_traits<decltype(&T::operator())> |
| 346 | { |
| 347 | using parent_t = function_traits<decltype(&T::operator())>; |
| 348 | static const size_t arity = parent_t::arity; |
| 349 | using result_type = typename parent_t::result_type; |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 350 | template <size_t i> |
| 351 | using arg = typename parent_t::template arg<i>; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 352 | }; |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 353 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame] | 354 | template <typename ClassType, typename r, typename... Args> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 355 | struct function_traits<r (ClassType::*)(Args...) const> |
| 356 | { |
| 357 | static const size_t arity = sizeof...(Args); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 358 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 359 | using result_type = r; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 360 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 361 | template <size_t i> |
| 362 | using arg = typename std::tuple_element<i, std::tuple<Args...>>::type; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 363 | }; |
| 364 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame] | 365 | template <typename ClassType, typename r, typename... Args> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 366 | struct function_traits<r (ClassType::*)(Args...)> |
| 367 | { |
| 368 | static const size_t arity = sizeof...(Args); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 369 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 370 | using result_type = r; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 371 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 372 | template <size_t i> |
| 373 | using arg = typename std::tuple_element<i, std::tuple<Args...>>::type; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 374 | }; |
| 375 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame] | 376 | template <typename r, typename... Args> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 377 | struct function_traits<std::function<r(Args...)>> |
| 378 | { |
| 379 | static const size_t arity = sizeof...(Args); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 380 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 381 | using result_type = r; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 382 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 383 | template <size_t i> |
| 384 | using arg = typename std::tuple_element<i, std::tuple<Args...>>::type; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 385 | }; |
| 386 | |
Adriana Kobylak | d830ff5 | 2021-01-27 14:15:27 -0600 | [diff] [blame] | 387 | inline std::string base64encode(const std::string_view data) |
| 388 | { |
| 389 | const std::array<char, 64> key = { |
| 390 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', |
| 391 | 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', |
| 392 | 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', |
| 393 | 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', |
| 394 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'}; |
| 395 | |
| 396 | size_t size = data.size(); |
| 397 | std::string ret; |
| 398 | ret.resize((size + 2) / 3 * 4); |
| 399 | auto it = ret.begin(); |
| 400 | |
| 401 | size_t i = 0; |
| 402 | while (i < size) |
| 403 | { |
Ed Tanous | 543f440 | 2022-01-06 13:12:53 -0800 | [diff] [blame] | 404 | size_t keyIndex = 0; |
Adriana Kobylak | d830ff5 | 2021-01-27 14:15:27 -0600 | [diff] [blame] | 405 | |
| 406 | keyIndex = static_cast<size_t>(data[i] & 0xFC) >> 2; |
| 407 | *it++ = key[keyIndex]; |
| 408 | |
| 409 | if (i + 1 < size) |
| 410 | { |
| 411 | keyIndex = static_cast<size_t>(data[i] & 0x03) << 4; |
| 412 | keyIndex += static_cast<size_t>(data[i + 1] & 0xF0) >> 4; |
| 413 | *it++ = key[keyIndex]; |
| 414 | |
| 415 | if (i + 2 < size) |
| 416 | { |
| 417 | keyIndex = static_cast<size_t>(data[i + 1] & 0x0F) << 2; |
| 418 | keyIndex += static_cast<size_t>(data[i + 2] & 0xC0) >> 6; |
| 419 | *it++ = key[keyIndex]; |
| 420 | |
| 421 | keyIndex = static_cast<size_t>(data[i + 2] & 0x3F); |
| 422 | *it++ = key[keyIndex]; |
| 423 | } |
| 424 | else |
| 425 | { |
| 426 | keyIndex = static_cast<size_t>(data[i + 1] & 0x0F) << 2; |
| 427 | *it++ = key[keyIndex]; |
| 428 | *it++ = '='; |
| 429 | } |
| 430 | } |
| 431 | else |
| 432 | { |
| 433 | keyIndex = static_cast<size_t>(data[i] & 0x03) << 4; |
| 434 | *it++ = key[keyIndex]; |
| 435 | *it++ = '='; |
| 436 | *it++ = '='; |
| 437 | } |
| 438 | |
| 439 | i += 3; |
| 440 | } |
| 441 | |
| 442 | return ret; |
| 443 | } |
| 444 | |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 445 | // TODO this is temporary and should be deleted once base64 is refactored out of |
| 446 | // crow |
Ed Tanous | 39e7750 | 2019-03-04 17:35:53 -0800 | [diff] [blame] | 447 | inline bool base64Decode(const std::string_view input, std::string& output) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 448 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 449 | static const char nop = static_cast<char>(-1); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 450 | // See note on encoding_data[] in above function |
Jonathan Doman | 5beaf84 | 2020-08-14 11:23:33 -0700 | [diff] [blame] | 451 | static const std::array<char, 256> decodingData = { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 452 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 453 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 454 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 455 | nop, 62, nop, nop, nop, 63, 52, 53, 54, 55, 56, 57, 58, 59, |
| 456 | 60, 61, nop, nop, nop, nop, nop, nop, nop, 0, 1, 2, 3, 4, |
| 457 | 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, |
| 458 | 19, 20, 21, 22, 23, 24, 25, nop, nop, nop, nop, nop, nop, 26, |
| 459 | 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, |
| 460 | 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, nop, nop, nop, |
| 461 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 462 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 463 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 464 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 465 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 466 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 467 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 468 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 469 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 470 | nop, nop, nop, nop}; |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 471 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 472 | size_t inputLength = input.size(); |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 473 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 474 | // allocate space for output string |
| 475 | output.clear(); |
| 476 | output.reserve(((inputLength + 2) / 3) * 4); |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 477 | |
Jonathan Doman | 5beaf84 | 2020-08-14 11:23:33 -0700 | [diff] [blame] | 478 | auto getCodeValue = [](char c) { |
| 479 | auto code = static_cast<unsigned char>(c); |
| 480 | // Ensure we cannot index outside the bounds of the decoding array |
| 481 | static_assert(std::numeric_limits<decltype(code)>::max() < |
| 482 | decodingData.size()); |
| 483 | return decodingData[code]; |
| 484 | }; |
| 485 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 486 | // 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] | 487 | // dropping first two bits |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 488 | // and regenerate into 3 8-bits sequences |
James Feist | 5a80664 | 2020-07-31 16:40:33 +0000 | [diff] [blame] | 489 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 490 | for (size_t i = 0; i < inputLength; i++) |
| 491 | { |
Ed Tanous | 543f440 | 2022-01-06 13:12:53 -0800 | [diff] [blame] | 492 | char base64code0 = 0; |
| 493 | char base64code1 = 0; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 494 | char base64code2 = 0; // initialized to 0 to suppress warnings |
Ed Tanous | 543f440 | 2022-01-06 13:12:53 -0800 | [diff] [blame] | 495 | char base64code3 = 0; |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 496 | |
Jonathan Doman | 5beaf84 | 2020-08-14 11:23:33 -0700 | [diff] [blame] | 497 | base64code0 = getCodeValue(input[i]); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 498 | if (base64code0 == nop) |
| 499 | { // non base64 character |
| 500 | return false; |
| 501 | } |
| 502 | if (!(++i < inputLength)) |
| 503 | { // we need at least two input bytes for first |
| 504 | // byte output |
| 505 | return false; |
| 506 | } |
Jonathan Doman | 5beaf84 | 2020-08-14 11:23:33 -0700 | [diff] [blame] | 507 | base64code1 = getCodeValue(input[i]); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 508 | if (base64code1 == nop) |
| 509 | { // non base64 character |
| 510 | return false; |
| 511 | } |
| 512 | output += |
| 513 | static_cast<char>((base64code0 << 2) | ((base64code1 >> 4) & 0x3)); |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 514 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 515 | if (++i < inputLength) |
| 516 | { |
| 517 | char c = input[i]; |
| 518 | if (c == '=') |
| 519 | { // padding , end of input |
| 520 | return (base64code1 & 0x0f) == 0; |
| 521 | } |
Jonathan Doman | 5beaf84 | 2020-08-14 11:23:33 -0700 | [diff] [blame] | 522 | base64code2 = getCodeValue(input[i]); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 523 | if (base64code2 == nop) |
| 524 | { // non base64 character |
| 525 | return false; |
| 526 | } |
| 527 | output += static_cast<char>(((base64code1 << 4) & 0xf0) | |
| 528 | ((base64code2 >> 2) & 0x0f)); |
| 529 | } |
| 530 | |
| 531 | if (++i < inputLength) |
| 532 | { |
| 533 | char c = input[i]; |
| 534 | if (c == '=') |
| 535 | { // padding , end of input |
| 536 | return (base64code2 & 0x03) == 0; |
| 537 | } |
Jonathan Doman | 5beaf84 | 2020-08-14 11:23:33 -0700 | [diff] [blame] | 538 | base64code3 = getCodeValue(input[i]); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 539 | if (base64code3 == nop) |
| 540 | { // non base64 character |
| 541 | return false; |
| 542 | } |
| 543 | output += |
| 544 | static_cast<char>((((base64code2 << 6) & 0xc0) | base64code3)); |
| 545 | } |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 546 | } |
| 547 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 548 | return true; |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 549 | } |
| 550 | |
Krzysztof Grobelny | 45c367e | 2021-12-29 10:28:53 +0100 | [diff] [blame] | 551 | namespace details |
| 552 | { |
Ed Tanous | 22ce545 | 2022-01-11 10:50:23 -0800 | [diff] [blame] | 553 | constexpr uint64_t maxMilliSeconds = 253402300799999; |
| 554 | constexpr uint64_t maxSeconds = 253402300799; |
Krzysztof Grobelny | 45c367e | 2021-12-29 10:28:53 +0100 | [diff] [blame] | 555 | inline std::string getDateTime(boost::posix_time::milliseconds timeSinceEpoch) |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 556 | { |
Nan Zhou | 1d8782e | 2021-11-29 22:23:18 -0800 | [diff] [blame] | 557 | boost::posix_time::ptime epoch(boost::gregorian::date(1970, 1, 1)); |
Krzysztof Grobelny | 45c367e | 2021-12-29 10:28:53 +0100 | [diff] [blame] | 558 | boost::posix_time::ptime time = epoch + timeSinceEpoch; |
Nan Zhou | 1d8782e | 2021-11-29 22:23:18 -0800 | [diff] [blame] | 559 | // append zero offset to the end according to the Redfish spec for Date-Time |
Nan Zhou | 5ae4b69 | 2021-12-14 13:30:37 -0800 | [diff] [blame] | 560 | return boost::posix_time::to_iso_extended_string(time) + "+00:00"; |
Nan Zhou | 1d8782e | 2021-11-29 22:23:18 -0800 | [diff] [blame] | 561 | } |
Krzysztof Grobelny | 45c367e | 2021-12-29 10:28:53 +0100 | [diff] [blame] | 562 | } // namespace details |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 563 | |
Ed Tanous | 22ce545 | 2022-01-11 10:50:23 -0800 | [diff] [blame] | 564 | // Returns the formatted date time string. |
| 565 | // Note that the maximum supported date is 9999-12-31T23:59:59+00:00, if |
| 566 | // the given |secondsSinceEpoch| is too large, we return the maximum supported |
| 567 | // date. This behavior is to avoid exceptions throwed by Boost. |
Nan Zhou | 1d8782e | 2021-11-29 22:23:18 -0800 | [diff] [blame] | 568 | inline std::string getDateTimeUint(uint64_t secondsSinceEpoch) |
| 569 | { |
Nan Zhou | 665479d | 2022-01-26 12:12:59 -0800 | [diff] [blame] | 570 | secondsSinceEpoch = std::min(secondsSinceEpoch, details::maxSeconds); |
| 571 | boost::posix_time::seconds boostSeconds(secondsSinceEpoch); |
Krzysztof Grobelny | 45c367e | 2021-12-29 10:28:53 +0100 | [diff] [blame] | 572 | return details::getDateTime( |
| 573 | boost::posix_time::milliseconds(boostSeconds.total_milliseconds())); |
| 574 | } |
| 575 | |
Ed Tanous | 22ce545 | 2022-01-11 10:50:23 -0800 | [diff] [blame] | 576 | // Returns the formatted date time string. |
| 577 | // Note that the maximum supported date is 9999-12-31T23:59:59.999+00:00, if |
| 578 | // the given |millisSecondsSinceEpoch| is too large, we return the maximum |
| 579 | // supported date. |
| 580 | inline std::string getDateTimeUintMs(uint64_t milliSecondsSinceEpoch) |
Krzysztof Grobelny | 45c367e | 2021-12-29 10:28:53 +0100 | [diff] [blame] | 581 | { |
Nan Zhou | 665479d | 2022-01-26 12:12:59 -0800 | [diff] [blame] | 582 | milliSecondsSinceEpoch = |
| 583 | std::min(details::maxMilliSeconds, milliSecondsSinceEpoch); |
| 584 | return details::getDateTime( |
| 585 | boost::posix_time::milliseconds(milliSecondsSinceEpoch)); |
Nan Zhou | 1d8782e | 2021-11-29 22:23:18 -0800 | [diff] [blame] | 586 | } |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 587 | |
Nan Zhou | 1d8782e | 2021-11-29 22:23:18 -0800 | [diff] [blame] | 588 | inline std::string getDateTimeStdtime(std::time_t secondsSinceEpoch) |
| 589 | { |
Ed Tanous | 46666f3 | 2022-03-03 14:55:16 -0800 | [diff] [blame] | 590 | // secondsSinceEpoch >= maxSeconds |
| 591 | if constexpr (std::cmp_less_equal(details::maxSeconds, |
| 592 | std::numeric_limits<std::time_t>::max())) |
Nan Zhou | 665479d | 2022-01-26 12:12:59 -0800 | [diff] [blame] | 593 | { |
Ed Tanous | 46666f3 | 2022-03-03 14:55:16 -0800 | [diff] [blame] | 594 | if (std::cmp_greater_equal(secondsSinceEpoch, details::maxSeconds)) |
| 595 | { |
| 596 | secondsSinceEpoch = details::maxSeconds; |
| 597 | } |
Nan Zhou | 665479d | 2022-01-26 12:12:59 -0800 | [diff] [blame] | 598 | } |
| 599 | boost::posix_time::ptime time = |
| 600 | boost::posix_time::from_time_t(secondsSinceEpoch); |
Krzysztof Grobelny | 45c367e | 2021-12-29 10:28:53 +0100 | [diff] [blame] | 601 | return boost::posix_time::to_iso_extended_string(time) + "+00:00"; |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Tejas Patil | 7c8c405 | 2021-06-04 17:43:14 +0530 | [diff] [blame] | 604 | /** |
| 605 | * Returns the current Date, Time & the local Time Offset |
| 606 | * infromation in a pair |
| 607 | * |
| 608 | * @param[in] None |
| 609 | * |
| 610 | * @return std::pair<std::string, std::string>, which consist |
| 611 | * of current DateTime & the TimeOffset strings respectively. |
| 612 | */ |
| 613 | inline std::pair<std::string, std::string> getDateTimeOffsetNow() |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 614 | { |
| 615 | std::time_t time = std::time(nullptr); |
Nan Zhou | 1d8782e | 2021-11-29 22:23:18 -0800 | [diff] [blame] | 616 | std::string dateTime = getDateTimeStdtime(time); |
Tejas Patil | 7c8c405 | 2021-06-04 17:43:14 +0530 | [diff] [blame] | 617 | |
| 618 | /* extract the local Time Offset value from the |
| 619 | * recevied dateTime string. |
| 620 | */ |
| 621 | std::string timeOffset("Z00:00"); |
| 622 | std::size_t lastPos = dateTime.size(); |
| 623 | std::size_t len = timeOffset.size(); |
| 624 | if (lastPos > len) |
| 625 | { |
| 626 | timeOffset = dateTime.substr(lastPos - len); |
| 627 | } |
| 628 | |
| 629 | return std::make_pair(dateTime, timeOffset); |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 630 | } |
| 631 | |
Ed Tanous | 51dae67 | 2018-09-05 16:07:32 -0700 | [diff] [blame] | 632 | inline bool constantTimeStringCompare(const std::string_view a, |
| 633 | const std::string_view b) |
| 634 | { |
| 635 | // Important note, this function is ONLY constant time if the two input |
| 636 | // sizes are the same |
| 637 | if (a.size() != b.size()) |
| 638 | { |
| 639 | return false; |
| 640 | } |
| 641 | return CRYPTO_memcmp(a.data(), b.data(), a.size()) == 0; |
| 642 | } |
| 643 | |
| 644 | struct ConstantTimeCompare |
| 645 | { |
| 646 | bool operator()(const std::string_view a, const std::string_view b) const |
| 647 | { |
| 648 | return constantTimeStringCompare(a, b); |
| 649 | } |
| 650 | }; |
| 651 | |
Ed Tanous | eae855c | 2021-10-26 11:26:02 -0700 | [diff] [blame] | 652 | namespace details |
| 653 | { |
| 654 | inline boost::urls::url |
| 655 | urlFromPiecesDetail(const std::initializer_list<std::string_view> args) |
| 656 | { |
| 657 | boost::urls::url url("/"); |
| 658 | for (const std::string_view& arg : args) |
| 659 | { |
| 660 | url.segments().push_back(arg); |
| 661 | } |
| 662 | return url; |
| 663 | } |
| 664 | } // namespace details |
| 665 | |
| 666 | template <typename... AV> |
| 667 | inline boost::urls::url urlFromPieces(const AV... args) |
| 668 | { |
| 669 | return details::urlFromPiecesDetail({args...}); |
| 670 | } |
| 671 | |
Ed Tanous | 11baefe | 2022-02-09 12:14:12 -0800 | [diff] [blame] | 672 | inline bool validateAndSplitUrl(std::string_view destUrl, std::string& urlProto, |
| 673 | std::string& host, std::string& port, |
| 674 | std::string& path) |
| 675 | { |
| 676 | // Validate URL using regex expression |
| 677 | // Format: <protocol>://<host>:<port>/<path> |
| 678 | // protocol: http/https |
| 679 | const std::regex urlRegex( |
| 680 | "(http|https)://([^/\\x20\\x3f\\x23\\x3a]+):?([0-9]*)(/" |
| 681 | "([^\\x20\\x23\\x3f]*\\x3f?([^\\x20\\x23\\x3f])*)?)"); |
| 682 | std::cmatch match; |
| 683 | if (!std::regex_match(destUrl.begin(), destUrl.end(), match, urlRegex)) |
| 684 | { |
| 685 | return false; |
| 686 | } |
| 687 | |
| 688 | urlProto = std::string(match[1].first, match[1].second); |
| 689 | if (urlProto == "http") |
| 690 | { |
| 691 | #ifndef BMCWEB_INSECURE_ENABLE_HTTP_PUSH_STYLE_EVENTING |
| 692 | return false; |
| 693 | #endif |
| 694 | } |
| 695 | |
| 696 | host = std::string(match[2].first, match[2].second); |
| 697 | port = std::string(match[3].first, match[3].second); |
| 698 | path = std::string(match[4].first, match[4].second); |
| 699 | if (port.empty()) |
| 700 | { |
| 701 | if (urlProto == "http") |
| 702 | { |
| 703 | port = "80"; |
| 704 | } |
| 705 | else |
| 706 | { |
| 707 | port = "443"; |
| 708 | } |
| 709 | } |
| 710 | if (path.empty()) |
| 711 | { |
| 712 | path = "/"; |
| 713 | } |
| 714 | return true; |
| 715 | } |
| 716 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 717 | } // namespace utility |
| 718 | } // namespace crow |