Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <cstdint> |
| 4 | #include <cstring> |
| 5 | #include <functional> |
| 6 | #include <stdexcept> |
| 7 | #include <string> |
| 8 | #include <tuple> |
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 9 | #include "nlohmann/json.hpp" |
Ed Tanous | 1e43987 | 2018-05-18 11:48:52 -0700 | [diff] [blame] | 10 | #include <boost/utility/string_view.hpp> |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 11 | |
| 12 | namespace crow { |
| 13 | namespace black_magic { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 14 | struct OutOfRange { |
| 15 | OutOfRange(unsigned /*pos*/, unsigned /*length*/) {} |
| 16 | }; |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 17 | constexpr unsigned requiresInRange(unsigned i, unsigned len) { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 18 | return i >= len ? throw OutOfRange(i, len) : i; |
| 19 | } |
| 20 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 21 | class ConstStr { |
| 22 | const char* const beginPtr; |
| 23 | unsigned sizeUint; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 24 | |
| 25 | public: |
| 26 | template <unsigned N> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 27 | constexpr ConstStr(const char (&arr)[N]) : beginPtr(arr), sizeUint(N - 1) { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 28 | static_assert(N >= 1, "not a string literal"); |
| 29 | } |
| 30 | constexpr char operator[](unsigned i) const { |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 31 | return requiresInRange(i, sizeUint), beginPtr[i]; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 34 | constexpr operator const char*() const { return beginPtr; } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 35 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 36 | constexpr const char* begin() const { return beginPtr; } |
| 37 | constexpr const char* end() const { return beginPtr + sizeUint; } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 38 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 39 | constexpr unsigned size() const { return sizeUint; } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 42 | constexpr unsigned findClosingTag(ConstStr s, unsigned p) { |
| 43 | return s[p] == '>' ? p : findClosingTag(s, p + 1); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 46 | constexpr bool isValid(ConstStr s, unsigned i = 0, int f = 0) { |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 47 | return i == s.size() |
| 48 | ? f == 0 |
| 49 | : f < 0 || f >= 2 |
| 50 | ? false |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 51 | : s[i] == '<' ? isValid(s, i + 1, f + 1) |
| 52 | : s[i] == '>' ? isValid(s, i + 1, f - 1) |
| 53 | : isValid(s, i + 1, f); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 56 | constexpr bool isEquP(const char* a, const char* b, unsigned n) { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 57 | return *a == 0 && *b == 0 && n == 0 |
| 58 | ? true |
| 59 | : (*a == 0 || *b == 0) |
| 60 | ? false |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 61 | : n == 0 ? true |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 62 | : *a != *b ? false : isEquP(a + 1, b + 1, n - 1); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 65 | constexpr bool isEquN(ConstStr a, unsigned ai, ConstStr b, unsigned bi, |
| 66 | unsigned n) { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 67 | return ai + n > a.size() || bi + n > b.size() |
| 68 | ? false |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 69 | : n == 0 ? true |
| 70 | : a[ai] != b[bi] ? false |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 71 | : isEquN(a, ai + 1, b, bi + 1, n - 1); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 74 | constexpr bool isInt(ConstStr s, unsigned i) { |
| 75 | return isEquN(s, i, "<int>", 0, 5); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 78 | constexpr bool isUint(ConstStr s, unsigned i) { |
| 79 | return isEquN(s, i, "<uint>", 0, 6); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 82 | constexpr bool isFloat(ConstStr s, unsigned i) { |
| 83 | return isEquN(s, i, "<float>", 0, 7) || isEquN(s, i, "<double>", 0, 8); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 86 | constexpr bool isStr(ConstStr s, unsigned i) { |
| 87 | return isEquN(s, i, "<str>", 0, 5) || isEquN(s, i, "<string>", 0, 8); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 90 | constexpr bool isPath(ConstStr s, unsigned i) { |
| 91 | return isEquN(s, i, "<path>", 0, 6); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 92 | } |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 93 | |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 94 | template <typename T> |
| 95 | struct parameter_tag { |
| 96 | static const int value = 0; |
| 97 | }; |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 98 | #define BMCWEB_INTERNAL_PARAMETER_TAG(t, i) \ |
| 99 | template <> \ |
| 100 | struct parameter_tag<t> { \ |
| 101 | static const int value = i; \ |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 102 | } |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 103 | BMCWEB_INTERNAL_PARAMETER_TAG(int, 1); |
| 104 | BMCWEB_INTERNAL_PARAMETER_TAG(char, 1); |
| 105 | BMCWEB_INTERNAL_PARAMETER_TAG(short, 1); |
| 106 | BMCWEB_INTERNAL_PARAMETER_TAG(long, 1); |
| 107 | BMCWEB_INTERNAL_PARAMETER_TAG(long long, 1); |
| 108 | BMCWEB_INTERNAL_PARAMETER_TAG(unsigned int, 2); |
| 109 | BMCWEB_INTERNAL_PARAMETER_TAG(unsigned char, 2); |
| 110 | BMCWEB_INTERNAL_PARAMETER_TAG(unsigned short, 2); |
| 111 | BMCWEB_INTERNAL_PARAMETER_TAG(unsigned long, 2); |
| 112 | BMCWEB_INTERNAL_PARAMETER_TAG(unsigned long long, 2); |
| 113 | BMCWEB_INTERNAL_PARAMETER_TAG(double, 3); |
| 114 | BMCWEB_INTERNAL_PARAMETER_TAG(std::string, 4); |
| 115 | #undef BMCWEB_INTERNAL_PARAMETER_TAG |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 116 | template <typename... Args> |
| 117 | struct compute_parameter_tag_from_args_list; |
| 118 | |
| 119 | template <> |
| 120 | struct compute_parameter_tag_from_args_list<> { |
| 121 | static const int value = 0; |
| 122 | }; |
| 123 | |
| 124 | template <typename Arg, typename... Args> |
| 125 | struct compute_parameter_tag_from_args_list<Arg, Args...> { |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 126 | static const int subValue = |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 127 | compute_parameter_tag_from_args_list<Args...>::value; |
| 128 | static const int value = |
| 129 | parameter_tag<typename std::decay<Arg>::type>::value |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 130 | ? subValue * 6 + parameter_tag<typename std::decay<Arg>::type>::value |
| 131 | : subValue; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 132 | }; |
| 133 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 134 | static inline bool isParameterTagCompatible(uint64_t a, uint64_t b) { |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 135 | if (a == 0) { |
| 136 | return b == 0; |
| 137 | } |
| 138 | if (b == 0) { |
| 139 | return a == 0; |
| 140 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 141 | int sa = a % 6; |
| 142 | int sb = a % 6; |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 143 | if (sa == 5) { |
| 144 | sa = 4; |
| 145 | } |
| 146 | if (sb == 5) { |
| 147 | sb = 4; |
| 148 | } |
| 149 | if (sa != sb) { |
| 150 | return false; |
| 151 | } |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 152 | return isParameterTagCompatible(a / 6, b / 6); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 155 | static inline unsigned findClosingTagRuntime(const char* s, unsigned p) { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 156 | return s[p] == 0 ? throw std::runtime_error("unmatched tag <") |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 157 | : s[p] == '>' ? p : findClosingTagRuntime(s, p + 1); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 160 | static inline uint64_t getParameterTagRuntime(const char* s, unsigned p = 0) { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 161 | return s[p] == 0 |
| 162 | ? 0 |
| 163 | : s[p] == '<' |
| 164 | ? (std::strncmp(s + p, "<int>", 5) == 0 |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 165 | ? getParameterTagRuntime( |
| 166 | s, findClosingTagRuntime(s, p)) * |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 167 | 6 + |
| 168 | 1 |
| 169 | : std::strncmp(s + p, "<uint>", 6) == 0 |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 170 | ? getParameterTagRuntime( |
| 171 | s, findClosingTagRuntime(s, p)) * |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 172 | 6 + |
| 173 | 2 |
| 174 | : (std::strncmp(s + p, "<float>", 7) == 0 || |
| 175 | std::strncmp(s + p, "<double>", 8) == 0) |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 176 | ? getParameterTagRuntime( |
| 177 | s, findClosingTagRuntime(s, p)) * |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 178 | 6 + |
| 179 | 3 |
| 180 | : (std::strncmp(s + p, "<str>", 5) == 0 || |
| 181 | std::strncmp(s + p, "<string>", 8) == |
| 182 | 0) |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 183 | ? getParameterTagRuntime( |
| 184 | s, |
| 185 | findClosingTagRuntime(s, p)) * |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 186 | 6 + |
| 187 | 4 |
| 188 | : std::strncmp(s + p, "<path>", |
| 189 | 6) == 0 |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 190 | ? getParameterTagRuntime( |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 191 | s, |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 192 | findClosingTagRuntime( |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 193 | s, p)) * |
| 194 | 6 + |
| 195 | 5 |
| 196 | : throw std::runtime_error( |
| 197 | "invalid parameter " |
| 198 | "type")) |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 199 | : getParameterTagRuntime(s, p + 1); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 200 | } |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 201 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 202 | constexpr uint64_t get_parameter_tag(ConstStr s, unsigned p = 0) { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 203 | return p == s.size() |
| 204 | ? 0 |
| 205 | : s[p] == '<' |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 206 | ? (isInt(s, p) |
| 207 | ? get_parameter_tag(s, findClosingTag(s, p)) * 6 + 1 |
| 208 | : isUint(s, p) |
| 209 | ? get_parameter_tag(s, findClosingTag(s, p)) * |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 210 | 6 + |
| 211 | 2 |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 212 | : isFloat(s, p) |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 213 | ? get_parameter_tag( |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 214 | s, findClosingTag(s, p)) * |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 215 | 6 + |
| 216 | 3 |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 217 | : isStr(s, p) |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 218 | ? get_parameter_tag( |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 219 | s, findClosingTag(s, p)) * |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 220 | 6 + |
| 221 | 4 |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 222 | : isPath(s, p) |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 223 | ? get_parameter_tag( |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 224 | s, |
| 225 | findClosingTag(s, p)) * |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 226 | 6 + |
| 227 | 5 |
| 228 | : throw std::runtime_error( |
| 229 | "invalid parameter " |
| 230 | "type")) |
| 231 | : get_parameter_tag(s, p + 1); |
| 232 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 233 | |
| 234 | template <typename... T> |
| 235 | struct S { |
| 236 | template <typename U> |
| 237 | using push = S<U, T...>; |
| 238 | template <typename U> |
| 239 | using push_back = S<T..., U>; |
| 240 | template <template <typename... Args> class U> |
| 241 | using rebind = U<T...>; |
| 242 | }; |
| 243 | template <typename F, typename Set> |
| 244 | struct CallHelper; |
| 245 | template <typename F, typename... Args> |
| 246 | struct CallHelper<F, S<Args...>> { |
| 247 | template <typename F1, typename... Args1, |
| 248 | typename = decltype(std::declval<F1>()(std::declval<Args1>()...))> |
| 249 | static char __test(int); |
| 250 | |
| 251 | template <typename...> |
| 252 | static int __test(...); |
| 253 | |
| 254 | static constexpr bool value = sizeof(__test<F, Args...>(0)) == sizeof(char); |
| 255 | }; |
| 256 | |
| 257 | template <int N> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 258 | struct SingleTagToType {}; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 259 | |
| 260 | template <> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 261 | struct SingleTagToType<1> { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 262 | using type = int64_t; |
| 263 | }; |
| 264 | |
| 265 | template <> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 266 | struct SingleTagToType<2> { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 267 | using type = uint64_t; |
| 268 | }; |
| 269 | |
| 270 | template <> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 271 | struct SingleTagToType<3> { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 272 | using type = double; |
| 273 | }; |
| 274 | |
| 275 | template <> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 276 | struct SingleTagToType<4> { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 277 | using type = std::string; |
| 278 | }; |
| 279 | |
| 280 | template <> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 281 | struct SingleTagToType<5> { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 282 | using type = std::string; |
| 283 | }; |
| 284 | |
| 285 | template <uint64_t Tag> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 286 | struct Arguments { |
| 287 | using subarguments = typename Arguments<Tag / 6>::type; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 288 | using type = typename subarguments::template push< |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 289 | typename SingleTagToType<Tag % 6>::type>; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 290 | }; |
| 291 | |
| 292 | template <> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 293 | struct Arguments<0> { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 294 | using type = S<>; |
| 295 | }; |
| 296 | |
| 297 | template <typename... T> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 298 | struct LastElementType { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 299 | using type = |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 300 | typename std::tuple_element<sizeof...(T) - 1, std::tuple<T...>>::type; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 301 | }; |
| 302 | |
| 303 | template <> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 304 | struct LastElementType<> {}; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 305 | |
| 306 | // from |
| 307 | // http://stackoverflow.com/questions/13072359/c11-compile-time-array-with-logarithmic-evaluation-depth |
| 308 | template <class T> |
| 309 | using Invoke = typename T::type; |
| 310 | |
| 311 | template <unsigned...> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 312 | struct Seq { |
| 313 | using type = Seq; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 314 | }; |
| 315 | |
| 316 | template <class S1, class S2> |
| 317 | struct concat; |
| 318 | |
| 319 | template <unsigned... I1, unsigned... I2> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 320 | struct concat<Seq<I1...>, Seq<I2...>> : Seq<I1..., (sizeof...(I1) + I2)...> {}; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 321 | |
| 322 | template <class S1, class S2> |
| 323 | using Concat = Invoke<concat<S1, S2>>; |
| 324 | |
| 325 | template <unsigned N> |
| 326 | struct gen_seq; |
| 327 | template <unsigned N> |
| 328 | using GenSeq = Invoke<gen_seq<N>>; |
| 329 | |
| 330 | template <unsigned N> |
| 331 | struct gen_seq : Concat<GenSeq<N / 2>, GenSeq<N - N / 2>> {}; |
| 332 | |
| 333 | template <> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 334 | struct gen_seq<0> : Seq<> {}; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 335 | template <> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 336 | struct gen_seq<1> : Seq<0> {}; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 337 | |
| 338 | template <typename Seq, typename Tuple> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 339 | struct PopBackHelper; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 340 | |
| 341 | template <unsigned... N, typename Tuple> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 342 | struct PopBackHelper<Seq<N...>, Tuple> { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 343 | template <template <typename... Args> class U> |
| 344 | using rebind = U<typename std::tuple_element<N, Tuple>::type...>; |
| 345 | }; |
| 346 | |
| 347 | template <typename... T> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 348 | struct PopBack //: public PopBackHelper<typename |
| 349 | // gen_seq<sizeof...(T)-1>::type, std::tuple<T...>> |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 350 | { |
| 351 | template <template <typename... Args> class U> |
| 352 | using rebind = |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 353 | typename PopBackHelper<typename gen_seq<sizeof...(T) - 1>::type, |
| 354 | std::tuple<T...>>::template rebind<U>; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 355 | }; |
| 356 | |
| 357 | template <> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 358 | struct PopBack<> { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 359 | template <template <typename... Args> class U> |
| 360 | using rebind = U<>; |
| 361 | }; |
| 362 | |
| 363 | // from |
| 364 | // http://stackoverflow.com/questions/2118541/check-if-c0x-parameter-pack-contains-a-type |
| 365 | template <typename Tp, typename... List> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 366 | struct Contains : std::true_type {}; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 367 | |
| 368 | template <typename Tp, typename Head, typename... Rest> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 369 | struct Contains<Tp, Head, Rest...> |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 370 | : std::conditional<std::is_same<Tp, Head>::value, std::true_type, |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 371 | Contains<Tp, Rest...>>::type {}; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 372 | |
| 373 | template <typename Tp> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 374 | struct Contains<Tp> : std::false_type {}; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 375 | |
| 376 | template <typename T> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 377 | struct EmptyContext {}; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 378 | |
| 379 | template <typename T> |
| 380 | struct promote { |
| 381 | using type = T; |
| 382 | }; |
| 383 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 384 | #define BMCWEB_INTERNAL_PROMOTE_TYPE(t1, t2) \ |
| 385 | template <> \ |
| 386 | struct promote<t1> { \ |
| 387 | using type = t2; \ |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 390 | BMCWEB_INTERNAL_PROMOTE_TYPE(char, int64_t); |
| 391 | BMCWEB_INTERNAL_PROMOTE_TYPE(short, int64_t); |
| 392 | BMCWEB_INTERNAL_PROMOTE_TYPE(int, int64_t); |
| 393 | BMCWEB_INTERNAL_PROMOTE_TYPE(long, int64_t); |
| 394 | BMCWEB_INTERNAL_PROMOTE_TYPE(long long, int64_t); |
| 395 | BMCWEB_INTERNAL_PROMOTE_TYPE(unsigned char, uint64_t); |
| 396 | BMCWEB_INTERNAL_PROMOTE_TYPE(unsigned short, uint64_t); |
| 397 | BMCWEB_INTERNAL_PROMOTE_TYPE(unsigned int, uint64_t); |
| 398 | BMCWEB_INTERNAL_PROMOTE_TYPE(unsigned long, uint64_t); |
| 399 | BMCWEB_INTERNAL_PROMOTE_TYPE(unsigned long long, uint64_t); |
| 400 | BMCWEB_INTERNAL_PROMOTE_TYPE(float, double); |
| 401 | #undef BMCWEB_INTERNAL_PROMOTE_TYPE |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 402 | |
| 403 | template <typename T> |
| 404 | using promote_t = typename promote<T>::type; |
| 405 | |
| 406 | } // namespace black_magic |
| 407 | |
| 408 | namespace detail { |
| 409 | |
| 410 | template <class T, std::size_t N, class... Args> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 411 | struct GetIndexOfElementFromTupleByTypeImpl { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 412 | static constexpr auto value = N; |
| 413 | }; |
| 414 | |
| 415 | template <class T, std::size_t N, class... Args> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 416 | struct GetIndexOfElementFromTupleByTypeImpl<T, N, T, Args...> { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 417 | static constexpr auto value = N; |
| 418 | }; |
| 419 | |
| 420 | template <class T, std::size_t N, class U, class... Args> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 421 | struct GetIndexOfElementFromTupleByTypeImpl<T, N, U, Args...> { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 422 | static constexpr auto value = |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 423 | GetIndexOfElementFromTupleByTypeImpl<T, N + 1, Args...>::value; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 424 | }; |
| 425 | |
| 426 | } // namespace detail |
| 427 | |
| 428 | namespace utility { |
| 429 | template <class T, class... Args> |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 430 | T& getElementByType(std::tuple<Args...>& t) { |
| 431 | return std::get< |
| 432 | detail::GetIndexOfElementFromTupleByTypeImpl<T, 0, Args...>::value>(t); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | template <typename T> |
| 436 | struct function_traits; |
| 437 | |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 438 | template <typename T> |
| 439 | struct function_traits : public function_traits<decltype(&T::operator())> { |
| 440 | using parent_t = function_traits<decltype(&T::operator())>; |
| 441 | static const size_t arity = parent_t::arity; |
| 442 | using result_type = typename parent_t::result_type; |
| 443 | template <size_t i> |
| 444 | using arg = typename parent_t::template arg<i>; |
| 445 | }; |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 446 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 447 | template <typename ClassType, typename r, typename... Args> |
| 448 | struct function_traits<r (ClassType::*)(Args...) const> { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 449 | static const size_t arity = sizeof...(Args); |
| 450 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 451 | using result_type = r; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 452 | |
| 453 | template <size_t i> |
| 454 | using arg = typename std::tuple_element<i, std::tuple<Args...>>::type; |
| 455 | }; |
| 456 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 457 | template <typename ClassType, typename r, typename... Args> |
| 458 | struct function_traits<r (ClassType::*)(Args...)> { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 459 | static const size_t arity = sizeof...(Args); |
| 460 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 461 | using result_type = r; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 462 | |
| 463 | template <size_t i> |
| 464 | using arg = typename std::tuple_element<i, std::tuple<Args...>>::type; |
| 465 | }; |
| 466 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 467 | template <typename r, typename... Args> |
| 468 | struct function_traits<std::function<r(Args...)>> { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 469 | static const size_t arity = sizeof...(Args); |
| 470 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 471 | using result_type = r; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 472 | |
| 473 | template <size_t i> |
| 474 | using arg = typename std::tuple_element<i, std::tuple<Args...>>::type; |
| 475 | }; |
| 476 | |
| 477 | inline static std::string base64encode( |
| 478 | const char* data, size_t size, |
| 479 | const char* key = |
| 480 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/") { |
| 481 | std::string ret; |
| 482 | ret.resize((size + 2) / 3 * 4); |
| 483 | auto it = ret.begin(); |
| 484 | while (size >= 3) { |
| 485 | *it++ = key[(((unsigned char)*data) & 0xFC) >> 2]; |
| 486 | unsigned char h = (((unsigned char)*data++) & 0x03) << 4; |
| 487 | *it++ = key[h | ((((unsigned char)*data) & 0xF0) >> 4)]; |
| 488 | h = (((unsigned char)*data++) & 0x0F) << 2; |
| 489 | *it++ = key[h | ((((unsigned char)*data) & 0xC0) >> 6)]; |
| 490 | *it++ = key[((unsigned char)*data++) & 0x3F]; |
| 491 | |
| 492 | size -= 3; |
| 493 | } |
| 494 | if (size == 1) { |
| 495 | *it++ = key[(((unsigned char)*data) & 0xFC) >> 2]; |
| 496 | unsigned char h = (((unsigned char)*data++) & 0x03) << 4; |
| 497 | *it++ = key[h]; |
| 498 | *it++ = '='; |
| 499 | *it++ = '='; |
| 500 | } else if (size == 2) { |
| 501 | *it++ = key[(((unsigned char)*data) & 0xFC) >> 2]; |
| 502 | unsigned char h = (((unsigned char)*data++) & 0x03) << 4; |
| 503 | *it++ = key[h | ((((unsigned char)*data) & 0xF0) >> 4)]; |
| 504 | h = (((unsigned char)*data++) & 0x0F) << 2; |
| 505 | *it++ = key[h]; |
| 506 | *it++ = '='; |
| 507 | } |
| 508 | return ret; |
| 509 | } |
| 510 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 511 | inline static std::string base64encodeUrlsafe(const char* data, size_t size) { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 512 | return base64encode( |
| 513 | data, size, |
| 514 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"); |
| 515 | } |
| 516 | |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 517 | // TODO this is temporary and should be deleted once base64 is refactored out of |
| 518 | // crow |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 519 | inline bool base64Decode(const boost::string_view input, std::string& output) { |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 520 | static const char nop = -1; |
| 521 | // See note on encoding_data[] in above function |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 522 | static const char decodingData[] = { |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 523 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 524 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 525 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, 62, nop, |
| 526 | nop, nop, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, nop, nop, |
| 527 | nop, nop, nop, nop, nop, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, |
| 528 | 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
| 529 | 25, nop, nop, nop, nop, nop, nop, 26, 27, 28, 29, 30, 31, 32, 33, |
| 530 | 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, |
| 531 | 49, 50, 51, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 532 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 533 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 534 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 535 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 536 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 537 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 538 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 539 | nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, |
| 540 | nop}; |
| 541 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 542 | size_t inputLength = input.size(); |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 543 | |
| 544 | // allocate space for output string |
| 545 | output.clear(); |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 546 | output.reserve(((inputLength + 2) / 3) * 4); |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 547 | |
| 548 | // for each 4-bytes sequence from the input, extract 4 6-bits sequences by |
| 549 | // droping first two bits |
| 550 | // and regenerate into 3 8-bits sequences |
| 551 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 552 | for (size_t i = 0; i < inputLength; i++) { |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 553 | char base64code0; |
| 554 | char base64code1; |
| 555 | char base64code2 = 0; // initialized to 0 to suppress warnings |
| 556 | char base64code3; |
| 557 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 558 | base64code0 = decodingData[static_cast<int>(input[i])]; // NOLINT |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 559 | if (base64code0 == nop) { // non base64 character |
| 560 | return false; |
| 561 | } |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 562 | if (!(++i < inputLength)) { // we need at least two input bytes for first |
| 563 | // byte output |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 564 | return false; |
| 565 | } |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 566 | base64code1 = decodingData[static_cast<int>(input[i])]; // NOLINT |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 567 | if (base64code1 == nop) { // non base64 character |
| 568 | return false; |
| 569 | } |
| 570 | output += |
| 571 | static_cast<char>((base64code0 << 2) | ((base64code1 >> 4) & 0x3)); |
| 572 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 573 | if (++i < inputLength) { |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 574 | char c = input[i]; |
| 575 | if (c == '=') { // padding , end of input |
| 576 | return (base64code1 & 0x0f) == 0; |
| 577 | } |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 578 | base64code2 = decodingData[static_cast<int>(input[i])]; // NOLINT |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 579 | if (base64code2 == nop) { // non base64 character |
| 580 | return false; |
| 581 | } |
| 582 | output += static_cast<char>(((base64code1 << 4) & 0xf0) | |
| 583 | ((base64code2 >> 2) & 0x0f)); |
| 584 | } |
| 585 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 586 | if (++i < inputLength) { |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 587 | char c = input[i]; |
| 588 | if (c == '=') { // padding , end of input |
| 589 | return (base64code2 & 0x03) == 0; |
| 590 | } |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 591 | base64code3 = decodingData[static_cast<int>(input[i])]; // NOLINT |
Borawski.Lukasz | 9d8fd30 | 2018-01-05 14:56:09 +0100 | [diff] [blame] | 592 | if (base64code3 == nop) { // non base64 character |
| 593 | return false; |
| 594 | } |
| 595 | output += static_cast<char>((((base64code2 << 6) & 0xc0) | base64code3)); |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | return true; |
| 600 | } |
| 601 | |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 602 | } // namespace utility |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 603 | } // namespace crow |