Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 3 | #include "async_resp.hpp" |
Ed Tanous | 04e438c | 2020-10-03 08:06:26 -0700 | [diff] [blame] | 4 | #include "common.hpp" |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 5 | #include "dbus_utility.hpp" |
Joseph Reynolds | 3bf4e63 | 2020-02-06 14:44:32 -0600 | [diff] [blame] | 6 | #include "error_messages.hpp" |
Ed Tanous | 04e438c | 2020-10-03 08:06:26 -0700 | [diff] [blame] | 7 | #include "http_request.hpp" |
| 8 | #include "http_response.hpp" |
| 9 | #include "logging.hpp" |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 10 | #include "privileges.hpp" |
Ratan Gupta | 6f35956 | 2019-04-03 10:39:08 +0530 | [diff] [blame] | 11 | #include "sessions.hpp" |
Ed Tanous | 04e438c | 2020-10-03 08:06:26 -0700 | [diff] [blame] | 12 | #include "utility.hpp" |
Ed Tanous | 3d18320 | 2023-03-10 09:21:58 -0800 | [diff] [blame] | 13 | #include "utils/dbus_utils.hpp" |
Ed Tanous | 2c9efc3 | 2022-07-31 22:08:26 -0700 | [diff] [blame] | 14 | #include "verb.hpp" |
Ed Tanous | 04e438c | 2020-10-03 08:06:26 -0700 | [diff] [blame] | 15 | #include "websocket.hpp" |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 16 | |
Ed Tanous | 88a03c5 | 2022-03-14 10:16:07 -0700 | [diff] [blame] | 17 | #include <boost/beast/ssl/ssl_stream.hpp> |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 18 | #include <boost/container/flat_map.hpp> |
Ed Tanous | 3d18320 | 2023-03-10 09:21:58 -0800 | [diff] [blame] | 19 | #include <sdbusplus/unpack_properties.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 20 | |
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 21 | #include <cerrno> |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 22 | #include <cstdint> |
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 23 | #include <cstdlib> |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 24 | #include <limits> |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 25 | #include <memory> |
Ed Tanous | 2c9efc3 | 2022-07-31 22:08:26 -0700 | [diff] [blame] | 26 | #include <optional> |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 27 | #include <tuple> |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 28 | #include <utility> |
| 29 | #include <vector> |
Ed Tanous | 9140a67 | 2017-04-24 17:01:32 -0700 | [diff] [blame] | 30 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 31 | namespace crow |
| 32 | { |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 33 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 34 | class BaseRule |
| 35 | { |
| 36 | public: |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 37 | explicit BaseRule(const std::string& thisRule) : rule(thisRule) {} |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 38 | |
Ed Tanous | 0c0084a | 2019-10-24 15:57:51 -0700 | [diff] [blame] | 39 | virtual ~BaseRule() = default; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 40 | |
Ed Tanous | ecd6a3a | 2022-01-07 09:18:40 -0800 | [diff] [blame] | 41 | BaseRule(const BaseRule&) = delete; |
| 42 | BaseRule(BaseRule&&) = delete; |
| 43 | BaseRule& operator=(const BaseRule&) = delete; |
| 44 | BaseRule& operator=(const BaseRule&&) = delete; |
| 45 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 46 | virtual void validate() = 0; |
| 47 | std::unique_ptr<BaseRule> upgrade() |
| 48 | { |
| 49 | if (ruleToUpgrade) |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 50 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 51 | return std::move(ruleToUpgrade); |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 52 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 53 | return {}; |
| 54 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 55 | |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 56 | virtual void handle(const Request& /*req*/, |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 57 | const std::shared_ptr<bmcweb::AsyncResp>&, |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 58 | const std::vector<std::string>&) = 0; |
P Dheeraj Srujan Kumar | 7e9093e | 2021-09-18 01:19:04 +0530 | [diff] [blame] | 59 | #ifndef BMCWEB_ENABLE_SSL |
P Dheeraj Srujan Kumar | a9f076e | 2021-10-18 22:45:37 +0530 | [diff] [blame] | 60 | virtual void |
| 61 | handleUpgrade(const Request& /*req*/, |
| 62 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 63 | boost::asio::ip::tcp::socket&& /*adaptor*/) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 64 | { |
P Dheeraj Srujan Kumar | a9f076e | 2021-10-18 22:45:37 +0530 | [diff] [blame] | 65 | asyncResp->res.result(boost::beast::http::status::not_found); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 66 | } |
P Dheeraj Srujan Kumar | 7e9093e | 2021-09-18 01:19:04 +0530 | [diff] [blame] | 67 | #else |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 68 | virtual void handleUpgrade( |
P Dheeraj Srujan Kumar | a9f076e | 2021-10-18 22:45:37 +0530 | [diff] [blame] | 69 | const Request& /*req*/, |
| 70 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 71 | boost::beast::ssl_stream<boost::asio::ip::tcp::socket>&& /*adaptor*/) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 72 | { |
P Dheeraj Srujan Kumar | a9f076e | 2021-10-18 22:45:37 +0530 | [diff] [blame] | 73 | asyncResp->res.result(boost::beast::http::status::not_found); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 74 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 75 | #endif |
| 76 | |
Ed Tanous | 9eb808c | 2022-01-25 10:19:23 -0800 | [diff] [blame] | 77 | size_t getMethods() const |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 78 | { |
| 79 | return methodsBitfield; |
| 80 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 81 | |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 82 | bool checkPrivileges(const redfish::Privileges& userPrivileges) |
| 83 | { |
| 84 | // If there are no privileges assigned, assume no privileges |
| 85 | // required |
| 86 | if (privilegesSet.empty()) |
| 87 | { |
| 88 | return true; |
| 89 | } |
| 90 | |
| 91 | for (const redfish::Privileges& requiredPrivileges : privilegesSet) |
| 92 | { |
| 93 | if (userPrivileges.isSupersetOf(requiredPrivileges)) |
| 94 | { |
| 95 | return true; |
| 96 | } |
| 97 | } |
| 98 | return false; |
| 99 | } |
| 100 | |
Ed Tanous | 2c9efc3 | 2022-07-31 22:08:26 -0700 | [diff] [blame] | 101 | size_t methodsBitfield{1 << static_cast<size_t>(HttpVerb::Get)}; |
Ed Tanous | 44e4518 | 2022-07-26 16:47:23 -0700 | [diff] [blame] | 102 | static_assert(std::numeric_limits<decltype(methodsBitfield)>::digits > |
Ed Tanous | 759cf10 | 2022-07-31 16:36:52 -0700 | [diff] [blame] | 103 | methodNotAllowedIndex, |
Ed Tanous | 44e4518 | 2022-07-26 16:47:23 -0700 | [diff] [blame] | 104 | "Not enough bits to store bitfield"); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 105 | |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 106 | std::vector<redfish::Privileges> privilegesSet; |
| 107 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 108 | std::string rule; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 109 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 110 | std::unique_ptr<BaseRule> ruleToUpgrade; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 111 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 112 | friend class Router; |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 113 | template <typename T> |
| 114 | friend struct RuleParameterTraits; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 117 | namespace detail |
| 118 | { |
| 119 | namespace routing_handler_call_helper |
| 120 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 121 | template <typename T, int Pos> |
| 122 | struct CallPair |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 123 | { |
| 124 | using type = T; |
| 125 | static const int pos = Pos; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 126 | }; |
| 127 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 128 | template <typename H1> |
| 129 | struct CallParams |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 130 | { |
| 131 | H1& handler; |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 132 | const std::vector<std::string>& params; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 133 | const Request& req; |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 134 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 135 | }; |
| 136 | |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 137 | template <typename F, int NString, typename S1, typename S2> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 138 | struct Call |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 139 | {}; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 140 | |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 141 | template <typename F, int NString, typename... Args1, typename... Args2> |
| 142 | struct Call<F, NString, black_magic::S<std::string, Args1...>, |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 143 | black_magic::S<Args2...>> |
| 144 | { |
| 145 | void operator()(F cparams) |
| 146 | { |
| 147 | using pushed = typename black_magic::S<Args2...>::template push_back< |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 148 | CallPair<std::string, NString>>; |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 149 | Call<F, NString + 1, black_magic::S<Args1...>, pushed>()(cparams); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 150 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 151 | }; |
| 152 | |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 153 | template <typename F, int NString, typename... Args1> |
| 154 | struct Call<F, NString, black_magic::S<>, black_magic::S<Args1...>> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 155 | { |
| 156 | void operator()(F cparams) |
| 157 | { |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 158 | cparams.handler(cparams.req, cparams.asyncResp, |
| 159 | cparams.params[Args1::pos]...); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 160 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 161 | }; |
| 162 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 163 | template <typename Func, typename... ArgsWrapped> |
| 164 | struct Wrapped |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 165 | { |
| 166 | template <typename... Args> |
| 167 | void set( |
| 168 | Func f, |
| 169 | typename std::enable_if< |
| 170 | !std::is_same< |
| 171 | typename std::tuple_element<0, std::tuple<Args..., void>>::type, |
| 172 | const Request&>::value, |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 173 | int>::type /*enable*/ |
| 174 | = 0) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 175 | { |
Ed Tanous | f94c4ec | 2022-01-06 12:44:41 -0800 | [diff] [blame] | 176 | handler = [f = std::forward<Func>(f)]( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 177 | const Request&, |
| 178 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 179 | Args... args) { asyncResp->res.result(f(args...)); }; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 182 | template <typename Req, typename... Args> |
| 183 | struct ReqHandlerWrapper |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 184 | { |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 185 | explicit ReqHandlerWrapper(Func fIn) : f(std::move(fIn)) {} |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 186 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 187 | void operator()(const Request& req, |
| 188 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 189 | Args... args) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 190 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 191 | asyncResp->res.result(f(req, args...)); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 192 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 193 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 194 | Func f; |
| 195 | }; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 196 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 197 | template <typename... Args> |
| 198 | void set( |
| 199 | Func f, |
| 200 | typename std::enable_if< |
| 201 | std::is_same< |
| 202 | typename std::tuple_element<0, std::tuple<Args..., void>>::type, |
| 203 | const Request&>::value && |
| 204 | !std::is_same<typename std::tuple_element< |
| 205 | 1, std::tuple<Args..., void, void>>::type, |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 206 | const std::shared_ptr<bmcweb::AsyncResp>&>::value, |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 207 | int>::type /*enable*/ |
| 208 | = 0) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 209 | { |
| 210 | handler = ReqHandlerWrapper<Args...>(std::move(f)); |
| 211 | /*handler = ( |
| 212 | [f = std::move(f)] |
| 213 | (const Request& req, Response& res, Args... args){ |
Ed Tanous | de5c9f3 | 2019-03-26 09:17:55 -0700 | [diff] [blame] | 214 | res.result(f(req, args...)); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 215 | res.end(); |
| 216 | });*/ |
| 217 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 218 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 219 | template <typename... Args> |
| 220 | void set( |
| 221 | Func f, |
| 222 | typename std::enable_if< |
| 223 | std::is_same< |
| 224 | typename std::tuple_element<0, std::tuple<Args..., void>>::type, |
| 225 | const Request&>::value && |
| 226 | std::is_same<typename std::tuple_element< |
| 227 | 1, std::tuple<Args..., void, void>>::type, |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 228 | const std::shared_ptr<bmcweb::AsyncResp>&>::value, |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 229 | int>::type /*enable*/ |
| 230 | = 0) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 231 | { |
| 232 | handler = std::move(f); |
| 233 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 234 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 235 | template <typename... Args> |
| 236 | struct HandlerTypeHelper |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 237 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 238 | using type = std::function<void( |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 239 | const crow::Request& /*req*/, |
| 240 | const std::shared_ptr<bmcweb::AsyncResp>&, Args...)>; |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 241 | using args_type = black_magic::S<Args...>; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 242 | }; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 243 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 244 | template <typename... Args> |
| 245 | struct HandlerTypeHelper<const Request&, Args...> |
| 246 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 247 | using type = std::function<void( |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 248 | const crow::Request& /*req*/, |
| 249 | const std::shared_ptr<bmcweb::AsyncResp>&, Args...)>; |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 250 | using args_type = black_magic::S<Args...>; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 251 | }; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 252 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 253 | template <typename... Args> |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 254 | struct HandlerTypeHelper<const Request&, |
| 255 | const std::shared_ptr<bmcweb::AsyncResp>&, Args...> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 256 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 257 | using type = std::function<void( |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 258 | const crow::Request& /*req*/, |
| 259 | const std::shared_ptr<bmcweb::AsyncResp>&, Args...)>; |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 260 | using args_type = black_magic::S<Args...>; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 261 | }; |
| 262 | |
| 263 | typename HandlerTypeHelper<ArgsWrapped...>::type handler; |
| 264 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 265 | void operator()(const Request& req, |
| 266 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 267 | const std::vector<std::string>& params) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 268 | { |
| 269 | detail::routing_handler_call_helper::Call< |
| 270 | detail::routing_handler_call_helper::CallParams<decltype(handler)>, |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 271 | 0, typename HandlerTypeHelper<ArgsWrapped...>::args_type, |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 272 | black_magic::S<>>()( |
| 273 | detail::routing_handler_call_helper::CallParams<decltype(handler)>{ |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 274 | handler, params, req, asyncResp}); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 275 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 276 | }; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 277 | } // namespace routing_handler_call_helper |
| 278 | } // namespace detail |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 279 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 280 | class WebSocketRule : public BaseRule |
| 281 | { |
| 282 | using self_t = WebSocketRule; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 283 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 284 | public: |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 285 | explicit WebSocketRule(const std::string& ruleIn) : BaseRule(ruleIn) {} |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 286 | |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 287 | void validate() override {} |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 288 | |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 289 | void handle(const Request& /*req*/, |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 290 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 291 | const std::vector<std::string>& /*params*/) override |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 292 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 293 | asyncResp->res.result(boost::beast::http::status::not_found); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 294 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 295 | |
P Dheeraj Srujan Kumar | 7e9093e | 2021-09-18 01:19:04 +0530 | [diff] [blame] | 296 | #ifndef BMCWEB_ENABLE_SSL |
P Dheeraj Srujan Kumar | a9f076e | 2021-10-18 22:45:37 +0530 | [diff] [blame] | 297 | void handleUpgrade(const Request& req, |
| 298 | const std::shared_ptr<bmcweb::AsyncResp>& /*asyncResp*/, |
Ed Tanous | ceac6f7 | 2018-12-02 11:58:47 -0800 | [diff] [blame] | 299 | boost::asio::ip::tcp::socket&& adaptor) override |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 300 | { |
Nan Zhou | 93c0202 | 2022-02-24 18:21:07 -0800 | [diff] [blame] | 301 | BMCWEB_LOG_DEBUG << "Websocket handles upgrade"; |
Ratan Gupta | 02453b1 | 2019-10-22 14:43:36 +0530 | [diff] [blame] | 302 | std::shared_ptr< |
| 303 | crow::websocket::ConnectionImpl<boost::asio::ip::tcp::socket>> |
| 304 | myConnection = std::make_shared< |
| 305 | crow::websocket::ConnectionImpl<boost::asio::ip::tcp::socket>>( |
Jan Sowinski | ee52ae1 | 2020-01-09 16:28:32 +0000 | [diff] [blame] | 306 | req, std::move(adaptor), openHandler, messageHandler, |
Ed Tanous | 863c1c2 | 2022-02-21 21:33:06 -0800 | [diff] [blame] | 307 | messageExHandler, closeHandler, errorHandler); |
Ratan Gupta | 02453b1 | 2019-10-22 14:43:36 +0530 | [diff] [blame] | 308 | myConnection->start(); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 309 | } |
P Dheeraj Srujan Kumar | 7e9093e | 2021-09-18 01:19:04 +0530 | [diff] [blame] | 310 | #else |
P Dheeraj Srujan Kumar | a9f076e | 2021-10-18 22:45:37 +0530 | [diff] [blame] | 311 | void handleUpgrade(const Request& req, |
| 312 | const std::shared_ptr<bmcweb::AsyncResp>& /*asyncResp*/, |
Ed Tanous | ceac6f7 | 2018-12-02 11:58:47 -0800 | [diff] [blame] | 313 | boost::beast::ssl_stream<boost::asio::ip::tcp::socket>&& |
| 314 | adaptor) override |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 315 | { |
Nan Zhou | 93c0202 | 2022-02-24 18:21:07 -0800 | [diff] [blame] | 316 | BMCWEB_LOG_DEBUG << "Websocket handles upgrade"; |
Ed Tanous | ceac6f7 | 2018-12-02 11:58:47 -0800 | [diff] [blame] | 317 | std::shared_ptr<crow::websocket::ConnectionImpl< |
| 318 | boost::beast::ssl_stream<boost::asio::ip::tcp::socket>>> |
| 319 | myConnection = std::make_shared<crow::websocket::ConnectionImpl< |
| 320 | boost::beast::ssl_stream<boost::asio::ip::tcp::socket>>>( |
Jan Sowinski | ee52ae1 | 2020-01-09 16:28:32 +0000 | [diff] [blame] | 321 | req, std::move(adaptor), openHandler, messageHandler, |
Ed Tanous | 863c1c2 | 2022-02-21 21:33:06 -0800 | [diff] [blame] | 322 | messageExHandler, closeHandler, errorHandler); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 323 | myConnection->start(); |
| 324 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 325 | #endif |
| 326 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 327 | template <typename Func> |
| 328 | self_t& onopen(Func f) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 329 | { |
| 330 | openHandler = f; |
| 331 | return *this; |
| 332 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 333 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 334 | template <typename Func> |
| 335 | self_t& onmessage(Func f) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 336 | { |
| 337 | messageHandler = f; |
| 338 | return *this; |
| 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 Func> |
Ed Tanous | 863c1c2 | 2022-02-21 21:33:06 -0800 | [diff] [blame] | 342 | self_t& onmessageex(Func f) |
| 343 | { |
| 344 | messageExHandler = f; |
| 345 | return *this; |
| 346 | } |
| 347 | |
| 348 | template <typename Func> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 349 | self_t& onclose(Func f) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 350 | { |
| 351 | closeHandler = f; |
| 352 | return *this; |
| 353 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 354 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 355 | template <typename Func> |
| 356 | self_t& onerror(Func f) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 357 | { |
| 358 | errorHandler = f; |
| 359 | return *this; |
| 360 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 361 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 362 | protected: |
zhanghch05 | 7772638 | 2021-10-21 14:07:57 +0800 | [diff] [blame] | 363 | std::function<void(crow::websocket::Connection&)> openHandler; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 364 | std::function<void(crow::websocket::Connection&, const std::string&, bool)> |
| 365 | messageHandler; |
Ed Tanous | 863c1c2 | 2022-02-21 21:33:06 -0800 | [diff] [blame] | 366 | std::function<void(crow::websocket::Connection&, std::string_view, |
| 367 | crow::websocket::MessageType type, |
| 368 | std::function<void()>&& whenComplete)> |
| 369 | messageExHandler; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 370 | std::function<void(crow::websocket::Connection&, const std::string&)> |
| 371 | closeHandler; |
| 372 | std::function<void(crow::websocket::Connection&)> errorHandler; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 373 | }; |
| 374 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 375 | template <typename T> |
| 376 | struct RuleParameterTraits |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 377 | { |
| 378 | using self_t = T; |
| 379 | WebSocketRule& websocket() |
| 380 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 381 | self_t* self = static_cast<self_t*>(this); |
| 382 | WebSocketRule* p = new WebSocketRule(self->rule); |
Ed Tanous | 9d192c7 | 2023-04-10 10:20:13 -0700 | [diff] [blame] | 383 | p->privilegesSet = self->privilegesSet; |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 384 | self->ruleToUpgrade.reset(p); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 385 | return *p; |
| 386 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 387 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 388 | self_t& methods(boost::beast::http::verb method) |
| 389 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 390 | self_t* self = static_cast<self_t*>(this); |
Ed Tanous | 2c9efc3 | 2022-07-31 22:08:26 -0700 | [diff] [blame] | 391 | std::optional<HttpVerb> verb = httpVerbFromBoost(method); |
| 392 | if (verb) |
| 393 | { |
| 394 | self->methodsBitfield = 1U << static_cast<size_t>(*verb); |
| 395 | } |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 396 | return *self; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 397 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 398 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 399 | template <typename... MethodArgs> |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 400 | self_t& methods(boost::beast::http::verb method, MethodArgs... argsMethod) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 401 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 402 | self_t* self = static_cast<self_t*>(this); |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 403 | methods(argsMethod...); |
Ed Tanous | 2c9efc3 | 2022-07-31 22:08:26 -0700 | [diff] [blame] | 404 | std::optional<HttpVerb> verb = httpVerbFromBoost(method); |
| 405 | if (verb) |
| 406 | { |
| 407 | self->methodsBitfield |= 1U << static_cast<size_t>(*verb); |
| 408 | } |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 409 | return *self; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 410 | } |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 411 | |
Ed Tanous | 44e4518 | 2022-07-26 16:47:23 -0700 | [diff] [blame] | 412 | self_t& notFound() |
| 413 | { |
| 414 | self_t* self = static_cast<self_t*>(this); |
| 415 | self->methodsBitfield = 1U << notFoundIndex; |
| 416 | return *self; |
| 417 | } |
| 418 | |
Ed Tanous | 759cf10 | 2022-07-31 16:36:52 -0700 | [diff] [blame] | 419 | self_t& methodNotAllowed() |
| 420 | { |
| 421 | self_t* self = static_cast<self_t*>(this); |
| 422 | self->methodsBitfield = 1U << methodNotAllowedIndex; |
| 423 | return *self; |
| 424 | } |
| 425 | |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 426 | self_t& privileges( |
| 427 | const std::initializer_list<std::initializer_list<const char*>>& p) |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 428 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 429 | self_t* self = static_cast<self_t*>(this); |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 430 | for (const std::initializer_list<const char*>& privilege : p) |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 431 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 432 | self->privilegesSet.emplace_back(privilege); |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 433 | } |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 434 | return *self; |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 435 | } |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 436 | |
| 437 | template <size_t N, typename... MethodArgs> |
| 438 | self_t& privileges(const std::array<redfish::Privileges, N>& p) |
| 439 | { |
| 440 | self_t* self = static_cast<self_t*>(this); |
| 441 | for (const redfish::Privileges& privilege : p) |
| 442 | { |
| 443 | self->privilegesSet.emplace_back(privilege); |
| 444 | } |
| 445 | return *self; |
| 446 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 447 | }; |
| 448 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 449 | class DynamicRule : public BaseRule, public RuleParameterTraits<DynamicRule> |
| 450 | { |
| 451 | public: |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 452 | explicit DynamicRule(const std::string& ruleIn) : BaseRule(ruleIn) {} |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 453 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 454 | void validate() override |
| 455 | { |
| 456 | if (!erasedHandler) |
| 457 | { |
Ed Tanous | 28f4b38 | 2023-04-10 10:20:56 -0700 | [diff] [blame] | 458 | throw std::runtime_error("no handler for url " + rule); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 459 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 460 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 461 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 462 | void handle(const Request& req, |
| 463 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 464 | const std::vector<std::string>& params) override |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 465 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 466 | erasedHandler(req, asyncResp, params); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 467 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 468 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 469 | template <typename Func> |
| 470 | void operator()(Func f) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 471 | { |
Ed Tanous | c867a83 | 2022-03-10 14:17:00 -0800 | [diff] [blame] | 472 | using boost::callable_traits::args_t; |
| 473 | constexpr size_t arity = std::tuple_size<args_t<Func>>::value; |
| 474 | constexpr auto is = std::make_integer_sequence<unsigned, arity>{}; |
| 475 | erasedHandler = wrap(std::move(f), is); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | // enable_if Arg1 == request && Arg2 == Response |
Gunnar Mills | 6be0e40 | 2020-07-08 13:21:51 -0500 | [diff] [blame] | 479 | // enable_if Arg1 == request && Arg2 != response |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 480 | // enable_if Arg1 != request |
| 481 | |
| 482 | template <typename Func, unsigned... Indices> |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 483 | std::function<void(const Request&, |
| 484 | const std::shared_ptr<bmcweb::AsyncResp>&, |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 485 | const std::vector<std::string>&)> |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 486 | wrap(Func f, std::integer_sequence<unsigned, Indices...> /*is*/) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 487 | { |
Ed Tanous | c867a83 | 2022-03-10 14:17:00 -0800 | [diff] [blame] | 488 | using function_t = crow::utility::FunctionTraits<Func>; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 489 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 490 | auto ret = detail::routing_handler_call_helper::Wrapped< |
| 491 | Func, typename function_t::template arg<Indices>...>(); |
| 492 | ret.template set<typename function_t::template arg<Indices>...>( |
| 493 | std::move(f)); |
| 494 | return ret; |
| 495 | } |
| 496 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 497 | private: |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 498 | std::function<void(const Request&, |
| 499 | const std::shared_ptr<bmcweb::AsyncResp>&, |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 500 | const std::vector<std::string>&)> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 501 | erasedHandler; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 502 | }; |
| 503 | |
| 504 | template <typename... Args> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 505 | class TaggedRule : |
| 506 | public BaseRule, |
| 507 | public RuleParameterTraits<TaggedRule<Args...>> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 508 | { |
| 509 | public: |
| 510 | using self_t = TaggedRule<Args...>; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 511 | |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 512 | explicit TaggedRule(const std::string& ruleIn) : BaseRule(ruleIn) {} |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 513 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 514 | void validate() override |
| 515 | { |
| 516 | if (!handler) |
| 517 | { |
Ed Tanous | 28f4b38 | 2023-04-10 10:20:56 -0700 | [diff] [blame] | 518 | throw std::runtime_error("no handler for url " + rule); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 519 | } |
| 520 | } |
| 521 | |
| 522 | template <typename Func> |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 523 | void operator()(Func&& f) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 524 | { |
| 525 | static_assert( |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 526 | black_magic::CallHelper< |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 527 | Func, black_magic::S<crow::Request, |
| 528 | std::shared_ptr<bmcweb::AsyncResp>&, |
| 529 | Args...>>::value, |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 530 | "Handler type is mismatched with URL parameters"); |
| 531 | static_assert( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 532 | std::is_same< |
| 533 | void, |
| 534 | decltype(f(std::declval<crow::Request>(), |
| 535 | std::declval<std::shared_ptr<bmcweb::AsyncResp>&>(), |
| 536 | std::declval<Args>()...))>::value, |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 537 | "Handler function with response argument should have void return type"); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 538 | |
Ed Tanous | f94c4ec | 2022-01-06 12:44:41 -0800 | [diff] [blame] | 539 | handler = std::forward<Func>(f); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 540 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 541 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 542 | void handle(const Request& req, |
| 543 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 544 | const std::vector<std::string>& params) override |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 545 | { |
| 546 | detail::routing_handler_call_helper::Call< |
| 547 | detail::routing_handler_call_helper::CallParams<decltype(handler)>, |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 548 | 0, black_magic::S<Args...>, black_magic::S<>>()( |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 549 | detail::routing_handler_call_helper::CallParams<decltype(handler)>{ |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 550 | handler, params, req, asyncResp}); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 551 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 552 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 553 | private: |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 554 | std::function<void(const crow::Request&, |
| 555 | const std::shared_ptr<bmcweb::AsyncResp>&, Args...)> |
| 556 | handler; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 557 | }; |
| 558 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 559 | class Trie |
| 560 | { |
| 561 | public: |
| 562 | struct Node |
| 563 | { |
| 564 | unsigned ruleIndex{}; |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 565 | std::array<size_t, static_cast<size_t>(ParamType::MAX)> |
| 566 | paramChildrens{}; |
Ed Tanous | a94ac61 | 2022-02-22 11:13:24 -0800 | [diff] [blame] | 567 | using ChildMap = boost::container::flat_map< |
| 568 | std::string, unsigned, std::less<>, |
| 569 | std::vector<std::pair<std::string, unsigned>>>; |
| 570 | ChildMap children; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 571 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 572 | bool isSimpleNode() const |
| 573 | { |
Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 574 | return ruleIndex == 0 && |
| 575 | std::all_of(std::begin(paramChildrens), |
| 576 | std::end(paramChildrens), |
| 577 | [](size_t x) { return x == 0U; }); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 578 | } |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame] | 579 | }; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 580 | |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 581 | Trie() : nodes(1) {} |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 582 | |
| 583 | private: |
| 584 | void optimizeNode(Node* node) |
| 585 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 586 | for (size_t x : node->paramChildrens) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 587 | { |
Ed Tanous | dbb59d4 | 2022-01-25 11:09:55 -0800 | [diff] [blame] | 588 | if (x == 0U) |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 589 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 590 | continue; |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 591 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 592 | Node* child = &nodes[x]; |
| 593 | optimizeNode(child); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 594 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 595 | if (node->children.empty()) |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 596 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 597 | return; |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 598 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 599 | bool mergeWithChild = true; |
Ed Tanous | a94ac61 | 2022-02-22 11:13:24 -0800 | [diff] [blame] | 600 | for (const Node::ChildMap::value_type& kv : node->children) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 601 | { |
| 602 | Node* child = &nodes[kv.second]; |
| 603 | if (!child->isSimpleNode()) |
| 604 | { |
| 605 | mergeWithChild = false; |
| 606 | break; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 607 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 608 | } |
| 609 | if (mergeWithChild) |
| 610 | { |
Ed Tanous | a94ac61 | 2022-02-22 11:13:24 -0800 | [diff] [blame] | 611 | Node::ChildMap merged; |
| 612 | for (const Node::ChildMap::value_type& kv : node->children) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 613 | { |
| 614 | Node* child = &nodes[kv.second]; |
Ed Tanous | a94ac61 | 2022-02-22 11:13:24 -0800 | [diff] [blame] | 615 | for (const Node::ChildMap::value_type& childKv : |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 616 | child->children) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 617 | { |
| 618 | merged[kv.first + childKv.first] = childKv.second; |
| 619 | } |
| 620 | } |
| 621 | node->children = std::move(merged); |
| 622 | optimizeNode(node); |
| 623 | } |
| 624 | else |
| 625 | { |
Ed Tanous | a94ac61 | 2022-02-22 11:13:24 -0800 | [diff] [blame] | 626 | for (const Node::ChildMap::value_type& kv : node->children) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 627 | { |
| 628 | Node* child = &nodes[kv.second]; |
| 629 | optimizeNode(child); |
| 630 | } |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | void optimize() |
| 635 | { |
| 636 | optimizeNode(head()); |
| 637 | } |
| 638 | |
| 639 | public: |
| 640 | void validate() |
| 641 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 642 | optimize(); |
| 643 | } |
| 644 | |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 645 | void findRouteIndexes(const std::string& reqUrl, |
| 646 | std::vector<unsigned>& routeIndexes, |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 647 | const Node* node = nullptr, unsigned pos = 0) const |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 648 | { |
| 649 | if (node == nullptr) |
| 650 | { |
| 651 | node = head(); |
| 652 | } |
Ed Tanous | a94ac61 | 2022-02-22 11:13:24 -0800 | [diff] [blame] | 653 | for (const Node::ChildMap::value_type& kv : node->children) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 654 | { |
| 655 | const std::string& fragment = kv.first; |
| 656 | const Node* child = &nodes[kv.second]; |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 657 | if (pos >= reqUrl.size()) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 658 | { |
| 659 | if (child->ruleIndex != 0 && fragment != "/") |
| 660 | { |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 661 | routeIndexes.push_back(child->ruleIndex); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 662 | } |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 663 | findRouteIndexes(reqUrl, routeIndexes, child, |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 664 | static_cast<unsigned>(pos + fragment.size())); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 665 | } |
| 666 | else |
| 667 | { |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 668 | if (reqUrl.compare(pos, fragment.size(), fragment) == 0) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 669 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 670 | findRouteIndexes( |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 671 | reqUrl, routeIndexes, child, |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 672 | static_cast<unsigned>(pos + fragment.size())); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 673 | } |
| 674 | } |
| 675 | } |
| 676 | } |
| 677 | |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 678 | std::pair<unsigned, std::vector<std::string>> |
| 679 | find(const std::string_view reqUrl, const Node* node = nullptr, |
| 680 | size_t pos = 0, std::vector<std::string>* params = nullptr) const |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 681 | { |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 682 | std::vector<std::string> empty; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 683 | if (params == nullptr) |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 684 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 685 | params = ∅ |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 686 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 687 | |
| 688 | unsigned found{}; |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 689 | std::vector<std::string> matchParams; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 690 | |
| 691 | if (node == nullptr) |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 692 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 693 | node = head(); |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 694 | } |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 695 | if (pos == reqUrl.size()) |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 696 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 697 | return {node->ruleIndex, *params}; |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 698 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 699 | |
| 700 | auto updateFound = |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 701 | [&found, |
| 702 | &matchParams](std::pair<unsigned, std::vector<std::string>>& ret) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 703 | if (ret.first != 0U && (found == 0U || found > ret.first)) |
| 704 | { |
| 705 | found = ret.first; |
| 706 | matchParams = std::move(ret.second); |
| 707 | } |
| 708 | }; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 709 | |
Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 710 | if (node->paramChildrens[static_cast<size_t>(ParamType::STRING)] != 0U) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 711 | { |
Ed Tanous | b01bf29 | 2019-03-25 19:25:26 +0000 | [diff] [blame] | 712 | size_t epos = pos; |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 713 | for (; epos < reqUrl.size(); epos++) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 714 | { |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 715 | if (reqUrl[epos] == '/') |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 716 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 717 | break; |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 718 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | if (epos != pos) |
| 722 | { |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 723 | params->emplace_back(reqUrl.substr(pos, epos - pos)); |
| 724 | std::pair<unsigned, std::vector<std::string>> ret = |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 725 | find(reqUrl, |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 726 | &nodes[node->paramChildrens[static_cast<size_t>( |
| 727 | ParamType::STRING)]], |
Ed Tanous | b01bf29 | 2019-03-25 19:25:26 +0000 | [diff] [blame] | 728 | epos, params); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 729 | updateFound(ret); |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 730 | params->pop_back(); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 731 | } |
| 732 | } |
| 733 | |
Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 734 | if (node->paramChildrens[static_cast<size_t>(ParamType::PATH)] != 0U) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 735 | { |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 736 | size_t epos = reqUrl.size(); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 737 | |
| 738 | if (epos != pos) |
| 739 | { |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 740 | params->emplace_back(reqUrl.substr(pos, epos - pos)); |
| 741 | std::pair<unsigned, std::vector<std::string>> ret = |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 742 | find(reqUrl, |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 743 | &nodes[node->paramChildrens[static_cast<size_t>( |
| 744 | ParamType::PATH)]], |
| 745 | epos, params); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 746 | updateFound(ret); |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 747 | params->pop_back(); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 748 | } |
| 749 | } |
| 750 | |
Ed Tanous | a94ac61 | 2022-02-22 11:13:24 -0800 | [diff] [blame] | 751 | for (const Node::ChildMap::value_type& kv : node->children) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 752 | { |
| 753 | const std::string& fragment = kv.first; |
| 754 | const Node* child = &nodes[kv.second]; |
| 755 | |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 756 | if (reqUrl.compare(pos, fragment.size(), fragment) == 0) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 757 | { |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 758 | std::pair<unsigned, std::vector<std::string>> ret = |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 759 | find(reqUrl, child, pos + fragment.size(), params); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 760 | updateFound(ret); |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | return {found, matchParams}; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 765 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 766 | |
| 767 | void add(const std::string& url, unsigned ruleIndex) |
| 768 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 769 | size_t idx = 0; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 770 | |
| 771 | for (unsigned i = 0; i < url.size(); i++) |
| 772 | { |
| 773 | char c = url[i]; |
| 774 | if (c == '<') |
| 775 | { |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 776 | constexpr static std::array< |
| 777 | std::pair<ParamType, std::string_view>, 3> |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 778 | paramTraits = {{ |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 779 | {ParamType::STRING, "<str>"}, |
| 780 | {ParamType::STRING, "<string>"}, |
| 781 | {ParamType::PATH, "<path>"}, |
| 782 | }}; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 783 | |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 784 | for (const std::pair<ParamType, std::string_view>& x : |
| 785 | paramTraits) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 786 | { |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 787 | if (url.compare(i, x.second.size(), x.second) == 0) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 788 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 789 | size_t index = static_cast<size_t>(x.first); |
Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 790 | if (nodes[idx].paramChildrens[index] == 0U) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 791 | { |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 792 | unsigned newNodeIdx = newNode(); |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 793 | nodes[idx].paramChildrens[index] = newNodeIdx; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 794 | } |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 795 | idx = nodes[idx].paramChildrens[index]; |
| 796 | i += static_cast<unsigned>(x.second.size()); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 797 | break; |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | i--; |
| 802 | } |
| 803 | else |
| 804 | { |
| 805 | std::string piece(&c, 1); |
Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 806 | if (nodes[idx].children.count(piece) == 0U) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 807 | { |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 808 | unsigned newNodeIdx = newNode(); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 809 | nodes[idx].children.emplace(piece, newNodeIdx); |
| 810 | } |
| 811 | idx = nodes[idx].children[piece]; |
| 812 | } |
| 813 | } |
Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 814 | if (nodes[idx].ruleIndex != 0U) |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 815 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 816 | throw std::runtime_error("handler already exists for " + url); |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 817 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 818 | nodes[idx].ruleIndex = ruleIndex; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 819 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 820 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 821 | private: |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 822 | void debugNodePrint(Node* n, size_t level) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 823 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 824 | for (size_t i = 0; i < static_cast<size_t>(ParamType::MAX); i++) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 825 | { |
Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 826 | if (n->paramChildrens[i] != 0U) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 827 | { |
| 828 | BMCWEB_LOG_DEBUG << std::string( |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 829 | 2U * level, ' ') /*<< "("<<n->paramChildrens[i]<<") "*/; |
| 830 | switch (static_cast<ParamType>(i)) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 831 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 832 | case ParamType::STRING: |
| 833 | BMCWEB_LOG_DEBUG << "<str>"; |
| 834 | break; |
| 835 | case ParamType::PATH: |
| 836 | BMCWEB_LOG_DEBUG << "<path>"; |
| 837 | break; |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 838 | case ParamType::MAX: |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 839 | BMCWEB_LOG_DEBUG << "<ERROR>"; |
| 840 | break; |
| 841 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 842 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 843 | debugNodePrint(&nodes[n->paramChildrens[i]], level + 1); |
| 844 | } |
| 845 | } |
Ed Tanous | a94ac61 | 2022-02-22 11:13:24 -0800 | [diff] [blame] | 846 | for (const Node::ChildMap::value_type& kv : n->children) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 847 | { |
| 848 | BMCWEB_LOG_DEBUG |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 849 | << std::string(2U * level, ' ') /*<< "(" << kv.second << ") "*/ |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 850 | << kv.first; |
| 851 | debugNodePrint(&nodes[kv.second], level + 1); |
| 852 | } |
| 853 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 854 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 855 | public: |
| 856 | void debugPrint() |
| 857 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 858 | debugNodePrint(head(), 0U); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 859 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 860 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 861 | private: |
| 862 | const Node* head() const |
| 863 | { |
| 864 | return &nodes.front(); |
| 865 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 866 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 867 | Node* head() |
| 868 | { |
| 869 | return &nodes.front(); |
| 870 | } |
| 871 | |
| 872 | unsigned newNode() |
| 873 | { |
| 874 | nodes.resize(nodes.size() + 1); |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 875 | return static_cast<unsigned>(nodes.size() - 1); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | std::vector<Node> nodes; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 879 | }; |
| 880 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 881 | class Router |
| 882 | { |
| 883 | public: |
Ed Tanous | 0c0084a | 2019-10-24 15:57:51 -0700 | [diff] [blame] | 884 | Router() = default; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 885 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 886 | DynamicRule& newRuleDynamic(const std::string& rule) |
| 887 | { |
| 888 | std::unique_ptr<DynamicRule> ruleObject = |
| 889 | std::make_unique<DynamicRule>(rule); |
| 890 | DynamicRule* ptr = ruleObject.get(); |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 891 | allRules.emplace_back(std::move(ruleObject)); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 892 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 893 | return *ptr; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 894 | } |
| 895 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 896 | template <uint64_t N> |
| 897 | typename black_magic::Arguments<N>::type::template rebind<TaggedRule>& |
| 898 | newRuleTagged(const std::string& rule) |
| 899 | { |
| 900 | using RuleT = typename black_magic::Arguments<N>::type::template rebind< |
| 901 | TaggedRule>; |
| 902 | std::unique_ptr<RuleT> ruleObject = std::make_unique<RuleT>(rule); |
| 903 | RuleT* ptr = ruleObject.get(); |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 904 | allRules.emplace_back(std::move(ruleObject)); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 905 | |
| 906 | return *ptr; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 907 | } |
| 908 | |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 909 | void internalAddRuleObject(const std::string& rule, BaseRule* ruleObject) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 910 | { |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 911 | if (ruleObject == nullptr) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 912 | { |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 913 | return; |
| 914 | } |
Ed Tanous | 759cf10 | 2022-07-31 16:36:52 -0700 | [diff] [blame] | 915 | for (size_t method = 0, methodBit = 1; method <= methodNotAllowedIndex; |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 916 | method++, methodBit <<= 1) |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 917 | { |
Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 918 | if ((ruleObject->methodsBitfield & methodBit) > 0U) |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 919 | { |
| 920 | perMethods[method].rules.emplace_back(ruleObject); |
| 921 | perMethods[method].trie.add( |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 922 | rule, static_cast<unsigned>( |
| 923 | perMethods[method].rules.size() - 1U)); |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 924 | // directory case: |
| 925 | // request to `/about' url matches `/about/' rule |
| 926 | if (rule.size() > 2 && rule.back() == '/') |
| 927 | { |
| 928 | perMethods[method].trie.add( |
| 929 | rule.substr(0, rule.size() - 1), |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 930 | static_cast<unsigned>(perMethods[method].rules.size() - |
| 931 | 1)); |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 932 | } |
| 933 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 934 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 935 | } |
| 936 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 937 | void validate() |
| 938 | { |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 939 | for (std::unique_ptr<BaseRule>& rule : allRules) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 940 | { |
| 941 | if (rule) |
| 942 | { |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 943 | std::unique_ptr<BaseRule> upgraded = rule->upgrade(); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 944 | if (upgraded) |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 945 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 946 | rule = std::move(upgraded); |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 947 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 948 | rule->validate(); |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 949 | internalAddRuleObject(rule->rule, rule.get()); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 950 | } |
| 951 | } |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 952 | for (PerMethod& perMethod : perMethods) |
| 953 | { |
| 954 | perMethod.trie.validate(); |
| 955 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 956 | } |
| 957 | |
Ed Tanous | 44e4518 | 2022-07-26 16:47:23 -0700 | [diff] [blame] | 958 | struct FindRoute |
| 959 | { |
| 960 | BaseRule* rule = nullptr; |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 961 | std::vector<std::string> params; |
Ed Tanous | 44e4518 | 2022-07-26 16:47:23 -0700 | [diff] [blame] | 962 | }; |
| 963 | |
| 964 | struct FindRouteResponse |
| 965 | { |
| 966 | std::string allowHeader; |
| 967 | FindRoute route; |
| 968 | }; |
| 969 | |
Ed Tanous | 759cf10 | 2022-07-31 16:36:52 -0700 | [diff] [blame] | 970 | FindRoute findRouteByIndex(std::string_view url, size_t index) const |
| 971 | { |
| 972 | FindRoute route; |
| 973 | if (index >= perMethods.size()) |
| 974 | { |
| 975 | BMCWEB_LOG_CRITICAL << "Bad index???"; |
| 976 | return route; |
| 977 | } |
| 978 | const PerMethod& perMethod = perMethods[index]; |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 979 | std::pair<unsigned, std::vector<std::string>> found = |
| 980 | perMethod.trie.find(url); |
Ed Tanous | 759cf10 | 2022-07-31 16:36:52 -0700 | [diff] [blame] | 981 | if (found.first >= perMethod.rules.size()) |
| 982 | { |
| 983 | throw std::runtime_error("Trie internal structure corrupted!"); |
| 984 | } |
| 985 | // Found a 404 route, switch that in |
| 986 | if (found.first != 0U) |
| 987 | { |
| 988 | route.rule = perMethod.rules[found.first]; |
| 989 | route.params = std::move(found.second); |
| 990 | } |
| 991 | return route; |
| 992 | } |
| 993 | |
| 994 | FindRouteResponse findRoute(Request& req) const |
Ed Tanous | 44e4518 | 2022-07-26 16:47:23 -0700 | [diff] [blame] | 995 | { |
| 996 | FindRouteResponse findRoute; |
| 997 | |
Ed Tanous | 2c9efc3 | 2022-07-31 22:08:26 -0700 | [diff] [blame] | 998 | std::optional<HttpVerb> verb = httpVerbFromBoost(req.method()); |
| 999 | if (!verb) |
| 1000 | { |
| 1001 | return findRoute; |
| 1002 | } |
| 1003 | size_t reqMethodIndex = static_cast<size_t>(*verb); |
Ed Tanous | 44e4518 | 2022-07-26 16:47:23 -0700 | [diff] [blame] | 1004 | // Check to see if this url exists at any verb |
| 1005 | for (size_t perMethodIndex = 0; perMethodIndex <= maxVerbIndex; |
| 1006 | perMethodIndex++) |
| 1007 | { |
| 1008 | // Make sure it's safe to deference the array at that index |
| 1009 | static_assert(maxVerbIndex < |
| 1010 | std::tuple_size_v<decltype(perMethods)>); |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 1011 | FindRoute route = findRouteByIndex(req.url().encoded_path(), |
| 1012 | perMethodIndex); |
Ed Tanous | 759cf10 | 2022-07-31 16:36:52 -0700 | [diff] [blame] | 1013 | if (route.rule == nullptr) |
Ed Tanous | 44e4518 | 2022-07-26 16:47:23 -0700 | [diff] [blame] | 1014 | { |
| 1015 | continue; |
| 1016 | } |
| 1017 | if (!findRoute.allowHeader.empty()) |
| 1018 | { |
| 1019 | findRoute.allowHeader += ", "; |
| 1020 | } |
Ed Tanous | 2c9efc3 | 2022-07-31 22:08:26 -0700 | [diff] [blame] | 1021 | HttpVerb thisVerb = static_cast<HttpVerb>(perMethodIndex); |
| 1022 | findRoute.allowHeader += httpVerbToString(thisVerb); |
Ed Tanous | 44e4518 | 2022-07-26 16:47:23 -0700 | [diff] [blame] | 1023 | if (perMethodIndex == reqMethodIndex) |
| 1024 | { |
Ed Tanous | 759cf10 | 2022-07-31 16:36:52 -0700 | [diff] [blame] | 1025 | findRoute.route = route; |
Ed Tanous | 44e4518 | 2022-07-26 16:47:23 -0700 | [diff] [blame] | 1026 | } |
| 1027 | } |
| 1028 | return findRoute; |
| 1029 | } |
| 1030 | |
P Dheeraj Srujan Kumar | 7e9093e | 2021-09-18 01:19:04 +0530 | [diff] [blame] | 1031 | static bool isUserPrivileged( |
| 1032 | Request& req, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1033 | BaseRule& rule, const dbus::utility::DBusPropertiesMap& userInfoMap) |
Ed Tanous | e1f5c16 | 2023-03-10 09:02:51 -0800 | [diff] [blame] | 1034 | { |
Ed Tanous | 3d18320 | 2023-03-10 09:21:58 -0800 | [diff] [blame] | 1035 | std::string userRole{}; |
| 1036 | const std::string* userRolePtr = nullptr; |
| 1037 | const bool* remoteUser = nullptr; |
| 1038 | const bool* passwordExpired = nullptr; |
| 1039 | |
| 1040 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 1041 | redfish::dbus_utils::UnpackErrorPrinter(), userInfoMap, |
| 1042 | "UserPrivilege", userRolePtr, "RemoteUser", remoteUser, |
| 1043 | "UserPasswordExpired", passwordExpired); |
| 1044 | |
| 1045 | if (!success) |
Ed Tanous | e1f5c16 | 2023-03-10 09:02:51 -0800 | [diff] [blame] | 1046 | { |
Ed Tanous | 3d18320 | 2023-03-10 09:21:58 -0800 | [diff] [blame] | 1047 | asyncResp->res.result( |
| 1048 | boost::beast::http::status::internal_server_error); |
P Dheeraj Srujan Kumar | 7e9093e | 2021-09-18 01:19:04 +0530 | [diff] [blame] | 1049 | return false; |
Ed Tanous | 3d18320 | 2023-03-10 09:21:58 -0800 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | if (userRolePtr != nullptr) |
| 1053 | { |
| 1054 | userRole = *userRolePtr; |
| 1055 | BMCWEB_LOG_DEBUG << "userName = " << req.session->username |
| 1056 | << " userRole = " << *userRolePtr; |
Ed Tanous | e1f5c16 | 2023-03-10 09:02:51 -0800 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | if (remoteUser == nullptr) |
| 1060 | { |
| 1061 | BMCWEB_LOG_ERROR << "RemoteUser property missing or wrong type"; |
| 1062 | asyncResp->res.result( |
| 1063 | boost::beast::http::status::internal_server_error); |
P Dheeraj Srujan Kumar | 7e9093e | 2021-09-18 01:19:04 +0530 | [diff] [blame] | 1064 | return false; |
Ed Tanous | e1f5c16 | 2023-03-10 09:02:51 -0800 | [diff] [blame] | 1065 | } |
Ed Tanous | 3d18320 | 2023-03-10 09:21:58 -0800 | [diff] [blame] | 1066 | bool expired = false; |
| 1067 | if (passwordExpired == nullptr) |
Ed Tanous | e1f5c16 | 2023-03-10 09:02:51 -0800 | [diff] [blame] | 1068 | { |
| 1069 | if (!*remoteUser) |
| 1070 | { |
| 1071 | BMCWEB_LOG_ERROR |
| 1072 | << "UserPasswordExpired property is expected for" |
| 1073 | " local user but is missing or wrong type"; |
| 1074 | asyncResp->res.result( |
| 1075 | boost::beast::http::status::internal_server_error); |
P Dheeraj Srujan Kumar | 7e9093e | 2021-09-18 01:19:04 +0530 | [diff] [blame] | 1076 | return false; |
Ed Tanous | e1f5c16 | 2023-03-10 09:02:51 -0800 | [diff] [blame] | 1077 | } |
Ed Tanous | 3d18320 | 2023-03-10 09:21:58 -0800 | [diff] [blame] | 1078 | } |
| 1079 | else |
| 1080 | { |
| 1081 | expired = *passwordExpired; |
Ed Tanous | e1f5c16 | 2023-03-10 09:02:51 -0800 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | // Get the user's privileges from the role |
| 1085 | redfish::Privileges userPrivileges = |
| 1086 | redfish::getUserPrivileges(userRole); |
| 1087 | |
| 1088 | // Set isConfigureSelfOnly based on D-Bus results. This |
| 1089 | // ignores the results from both pamAuthenticateUser and the |
| 1090 | // value from any previous use of this session. |
Ed Tanous | 3d18320 | 2023-03-10 09:21:58 -0800 | [diff] [blame] | 1091 | req.session->isConfigureSelfOnly = expired; |
Ed Tanous | e1f5c16 | 2023-03-10 09:02:51 -0800 | [diff] [blame] | 1092 | |
| 1093 | // Modify privileges if isConfigureSelfOnly. |
| 1094 | if (req.session->isConfigureSelfOnly) |
| 1095 | { |
| 1096 | // Remove all privileges except ConfigureSelf |
| 1097 | userPrivileges = userPrivileges.intersection( |
| 1098 | redfish::Privileges{"ConfigureSelf"}); |
| 1099 | BMCWEB_LOG_DEBUG << "Operation limited to ConfigureSelf"; |
| 1100 | } |
| 1101 | |
| 1102 | if (!rule.checkPrivileges(userPrivileges)) |
| 1103 | { |
| 1104 | asyncResp->res.result(boost::beast::http::status::forbidden); |
| 1105 | if (req.session->isConfigureSelfOnly) |
| 1106 | { |
| 1107 | redfish::messages::passwordChangeRequired( |
| 1108 | asyncResp->res, crow::utility::urlFromPieces( |
| 1109 | "redfish", "v1", "AccountService", |
| 1110 | "Accounts", req.session->username)); |
| 1111 | } |
P Dheeraj Srujan Kumar | 7e9093e | 2021-09-18 01:19:04 +0530 | [diff] [blame] | 1112 | return false; |
Ed Tanous | e1f5c16 | 2023-03-10 09:02:51 -0800 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | req.userRole = userRole; |
P Dheeraj Srujan Kumar | 7e9093e | 2021-09-18 01:19:04 +0530 | [diff] [blame] | 1116 | |
| 1117 | return true; |
| 1118 | } |
| 1119 | |
| 1120 | template <typename CallbackFn> |
Jonathan Doman | d3c8ce6 | 2023-03-21 18:17:06 -0700 | [diff] [blame] | 1121 | void afterGetUserInfo(Request& req, |
P Dheeraj Srujan Kumar | 7e9093e | 2021-09-18 01:19:04 +0530 | [diff] [blame] | 1122 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1123 | BaseRule& rule, CallbackFn&& callback, |
| 1124 | const boost::system::error_code& ec, |
| 1125 | const dbus::utility::DBusPropertiesMap& userInfoMap) |
| 1126 | { |
| 1127 | if (ec) |
| 1128 | { |
| 1129 | BMCWEB_LOG_ERROR << "GetUserInfo failed..."; |
| 1130 | asyncResp->res.result( |
| 1131 | boost::beast::http::status::internal_server_error); |
| 1132 | return; |
| 1133 | } |
| 1134 | |
| 1135 | if (!Router::isUserPrivileged(req, asyncResp, rule, userInfoMap)) |
| 1136 | { |
| 1137 | // User is not privileged |
| 1138 | BMCWEB_LOG_ERROR << "Insufficient Privilege"; |
| 1139 | asyncResp->res.result(boost::beast::http::status::forbidden); |
| 1140 | return; |
| 1141 | } |
Jonathan Doman | d3c8ce6 | 2023-03-21 18:17:06 -0700 | [diff] [blame] | 1142 | callback(req); |
P Dheeraj Srujan Kumar | 7e9093e | 2021-09-18 01:19:04 +0530 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | template <typename CallbackFn> |
Jonathan Doman | d3c8ce6 | 2023-03-21 18:17:06 -0700 | [diff] [blame] | 1146 | void validatePrivilege(Request& req, |
P Dheeraj Srujan Kumar | 7e9093e | 2021-09-18 01:19:04 +0530 | [diff] [blame] | 1147 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1148 | BaseRule& rule, CallbackFn&& callback) |
| 1149 | { |
Ed Tanous | 915d2d4 | 2023-03-15 13:09:34 -0700 | [diff] [blame] | 1150 | if (req.session == nullptr) |
| 1151 | { |
| 1152 | return; |
| 1153 | } |
| 1154 | std::string username = req.session->username; |
P Dheeraj Srujan Kumar | 7e9093e | 2021-09-18 01:19:04 +0530 | [diff] [blame] | 1155 | crow::connections::systemBus->async_method_call( |
Jonathan Doman | d3c8ce6 | 2023-03-21 18:17:06 -0700 | [diff] [blame] | 1156 | [this, &req, asyncResp, &rule, |
P Dheeraj Srujan Kumar | 7e9093e | 2021-09-18 01:19:04 +0530 | [diff] [blame] | 1157 | callback(std::forward<CallbackFn>(callback))]( |
| 1158 | const boost::system::error_code& ec, |
| 1159 | const dbus::utility::DBusPropertiesMap& userInfoMap) mutable { |
Jonathan Doman | d3c8ce6 | 2023-03-21 18:17:06 -0700 | [diff] [blame] | 1160 | afterGetUserInfo(req, asyncResp, rule, |
P Dheeraj Srujan Kumar | 7e9093e | 2021-09-18 01:19:04 +0530 | [diff] [blame] | 1161 | std::forward<CallbackFn>(callback), ec, |
| 1162 | userInfoMap); |
| 1163 | }, |
| 1164 | "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", |
Ed Tanous | 915d2d4 | 2023-03-15 13:09:34 -0700 | [diff] [blame] | 1165 | "xyz.openbmc_project.User.Manager", "GetUserInfo", username); |
Ed Tanous | e1f5c16 | 2023-03-10 09:02:51 -0800 | [diff] [blame] | 1166 | } |
| 1167 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1168 | template <typename Adaptor> |
P Dheeraj Srujan Kumar | 7e9093e | 2021-09-18 01:19:04 +0530 | [diff] [blame] | 1169 | void handleUpgrade(Request& req, |
P Dheeraj Srujan Kumar | a9f076e | 2021-10-18 22:45:37 +0530 | [diff] [blame] | 1170 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1171 | Adaptor&& adaptor) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1172 | { |
Ed Tanous | 2c9efc3 | 2022-07-31 22:08:26 -0700 | [diff] [blame] | 1173 | std::optional<HttpVerb> verb = httpVerbFromBoost(req.method()); |
| 1174 | if (!verb || static_cast<size_t>(*verb) >= perMethods.size()) |
Ed Tanous | 888880a | 2020-08-24 13:48:50 -0700 | [diff] [blame] | 1175 | { |
P Dheeraj Srujan Kumar | a9f076e | 2021-10-18 22:45:37 +0530 | [diff] [blame] | 1176 | asyncResp->res.result(boost::beast::http::status::not_found); |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 1177 | return; |
Ed Tanous | 888880a | 2020-08-24 13:48:50 -0700 | [diff] [blame] | 1178 | } |
Ed Tanous | 2c9efc3 | 2022-07-31 22:08:26 -0700 | [diff] [blame] | 1179 | PerMethod& perMethod = perMethods[static_cast<size_t>(*verb)]; |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 1180 | Trie& trie = perMethod.trie; |
| 1181 | std::vector<BaseRule*>& rules = perMethod.rules; |
| 1182 | |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 1183 | const std::pair<unsigned, std::vector<std::string>>& found = |
Ed Tanous | 39662a3 | 2023-02-06 15:09:46 -0800 | [diff] [blame] | 1184 | trie.find(req.url().encoded_path()); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1185 | unsigned ruleIndex = found.first; |
Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 1186 | if (ruleIndex == 0U) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1187 | { |
Ed Tanous | 39662a3 | 2023-02-06 15:09:46 -0800 | [diff] [blame] | 1188 | BMCWEB_LOG_DEBUG << "Cannot match rules " |
| 1189 | << req.url().encoded_path(); |
P Dheeraj Srujan Kumar | a9f076e | 2021-10-18 22:45:37 +0530 | [diff] [blame] | 1190 | asyncResp->res.result(boost::beast::http::status::not_found); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1191 | return; |
| 1192 | } |
| 1193 | |
| 1194 | if (ruleIndex >= rules.size()) |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 1195 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1196 | throw std::runtime_error("Trie internal structure corrupted!"); |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 1197 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1198 | |
P Dheeraj Srujan Kumar | 7e9093e | 2021-09-18 01:19:04 +0530 | [diff] [blame] | 1199 | BaseRule& rule = *rules[ruleIndex]; |
| 1200 | size_t methods = rule.getMethods(); |
| 1201 | if ((methods & (1U << static_cast<size_t>(*verb))) == 0) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1202 | { |
P Dheeraj Srujan Kumar | 7e9093e | 2021-09-18 01:19:04 +0530 | [diff] [blame] | 1203 | BMCWEB_LOG_DEBUG |
| 1204 | << "Rule found but method mismatch: " |
| 1205 | << req.url().encoded_path() << " with " << req.methodString() |
| 1206 | << "(" << static_cast<uint32_t>(*verb) << ") / " << methods; |
P Dheeraj Srujan Kumar | a9f076e | 2021-10-18 22:45:37 +0530 | [diff] [blame] | 1207 | asyncResp->res.result(boost::beast::http::status::not_found); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1208 | return; |
| 1209 | } |
| 1210 | |
P Dheeraj Srujan Kumar | 7e9093e | 2021-09-18 01:19:04 +0530 | [diff] [blame] | 1211 | BMCWEB_LOG_DEBUG << "Matched rule (upgrade) '" << rule.rule << "' " |
| 1212 | << static_cast<uint32_t>(*verb) << " / " << methods; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1213 | |
P Dheeraj Srujan Kumar | 7e9093e | 2021-09-18 01:19:04 +0530 | [diff] [blame] | 1214 | // TODO(ed) This should be able to use std::bind_front, but it doesn't |
| 1215 | // appear to work with the std::move on adaptor. |
Ed Tanous | 915d2d4 | 2023-03-15 13:09:34 -0700 | [diff] [blame] | 1216 | validatePrivilege( |
Jonathan Doman | d3c8ce6 | 2023-03-21 18:17:06 -0700 | [diff] [blame] | 1217 | req, asyncResp, rule, |
Ed Tanous | 915d2d4 | 2023-03-15 13:09:34 -0700 | [diff] [blame] | 1218 | [&rule, asyncResp, adaptor(std::forward<Adaptor>(adaptor))]( |
Jonathan Doman | d3c8ce6 | 2023-03-21 18:17:06 -0700 | [diff] [blame] | 1219 | Request& thisReq) mutable { |
Ed Tanous | 915d2d4 | 2023-03-15 13:09:34 -0700 | [diff] [blame] | 1220 | rule.handleUpgrade(thisReq, asyncResp, std::move(adaptor)); |
| 1221 | }); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 1222 | } |
| 1223 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 1224 | void handle(Request& req, |
| 1225 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1226 | { |
Ed Tanous | 2c9efc3 | 2022-07-31 22:08:26 -0700 | [diff] [blame] | 1227 | std::optional<HttpVerb> verb = httpVerbFromBoost(req.method()); |
| 1228 | if (!verb || static_cast<size_t>(*verb) >= perMethods.size()) |
Ed Tanous | 888880a | 2020-08-24 13:48:50 -0700 | [diff] [blame] | 1229 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 1230 | asyncResp->res.result(boost::beast::http::status::not_found); |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 1231 | return; |
Ed Tanous | 888880a | 2020-08-24 13:48:50 -0700 | [diff] [blame] | 1232 | } |
Ed Tanous | 44e4518 | 2022-07-26 16:47:23 -0700 | [diff] [blame] | 1233 | |
| 1234 | FindRouteResponse foundRoute = findRoute(req); |
| 1235 | |
Ed Tanous | 759cf10 | 2022-07-31 16:36:52 -0700 | [diff] [blame] | 1236 | if (foundRoute.route.rule == nullptr) |
Ed Tanous | 88a03c5 | 2022-03-14 10:16:07 -0700 | [diff] [blame] | 1237 | { |
Ed Tanous | 759cf10 | 2022-07-31 16:36:52 -0700 | [diff] [blame] | 1238 | // Couldn't find a normal route with any verb, try looking for a 404 |
| 1239 | // route |
| 1240 | if (foundRoute.allowHeader.empty()) |
Ed Tanous | 44e4518 | 2022-07-26 16:47:23 -0700 | [diff] [blame] | 1241 | { |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 1242 | foundRoute.route = findRouteByIndex(req.url().encoded_path(), |
| 1243 | notFoundIndex); |
Ed Tanous | 759cf10 | 2022-07-31 16:36:52 -0700 | [diff] [blame] | 1244 | } |
| 1245 | else |
| 1246 | { |
| 1247 | // See if we have a method not allowed (405) handler |
Ed Tanous | 39662a3 | 2023-02-06 15:09:46 -0800 | [diff] [blame] | 1248 | foundRoute.route = findRouteByIndex(req.url().encoded_path(), |
| 1249 | methodNotAllowedIndex); |
Ed Tanous | 44e4518 | 2022-07-26 16:47:23 -0700 | [diff] [blame] | 1250 | } |
| 1251 | } |
Ed Tanous | 759cf10 | 2022-07-31 16:36:52 -0700 | [diff] [blame] | 1252 | |
| 1253 | // Fill in the allow header if it's valid |
| 1254 | if (!foundRoute.allowHeader.empty()) |
Ed Tanous | 44e4518 | 2022-07-26 16:47:23 -0700 | [diff] [blame] | 1255 | { |
Ed Tanous | 88a03c5 | 2022-03-14 10:16:07 -0700 | [diff] [blame] | 1256 | asyncResp->res.addHeader(boost::beast::http::field::allow, |
Ed Tanous | 44e4518 | 2022-07-26 16:47:23 -0700 | [diff] [blame] | 1257 | foundRoute.allowHeader); |
Ed Tanous | 88a03c5 | 2022-03-14 10:16:07 -0700 | [diff] [blame] | 1258 | } |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 1259 | |
Ed Tanous | 44e4518 | 2022-07-26 16:47:23 -0700 | [diff] [blame] | 1260 | // If we couldn't find a real route or a 404 route, return a generic |
| 1261 | // response |
| 1262 | if (foundRoute.route.rule == nullptr) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1263 | { |
Ed Tanous | 44e4518 | 2022-07-26 16:47:23 -0700 | [diff] [blame] | 1264 | if (foundRoute.allowHeader.empty()) |
| 1265 | { |
| 1266 | asyncResp->res.result(boost::beast::http::status::not_found); |
| 1267 | } |
| 1268 | else |
Ed Tanous | 2634dcd | 2019-03-26 09:28:06 -0700 | [diff] [blame] | 1269 | { |
Ed Tanous | 88a03c5 | 2022-03-14 10:16:07 -0700 | [diff] [blame] | 1270 | asyncResp->res.result( |
| 1271 | boost::beast::http::status::method_not_allowed); |
Ed Tanous | 2634dcd | 2019-03-26 09:28:06 -0700 | [diff] [blame] | 1272 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1273 | return; |
| 1274 | } |
| 1275 | |
Ed Tanous | 44e4518 | 2022-07-26 16:47:23 -0700 | [diff] [blame] | 1276 | BaseRule& rule = *foundRoute.route.rule; |
Ed Tanous | 15a42df | 2023-02-09 18:08:23 -0800 | [diff] [blame] | 1277 | std::vector<std::string> params = std::move(foundRoute.route.params); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1278 | |
Ed Tanous | 44e4518 | 2022-07-26 16:47:23 -0700 | [diff] [blame] | 1279 | BMCWEB_LOG_DEBUG << "Matched rule '" << rule.rule << "' " |
Snehalatha Venkatesh | 1c99da0 | 2022-12-27 06:45:35 +0000 | [diff] [blame] | 1280 | << static_cast<uint32_t>(*verb) << " / " |
Ed Tanous | 44e4518 | 2022-07-26 16:47:23 -0700 | [diff] [blame] | 1281 | << rule.getMethods(); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1282 | |
RAJESWARAN THILLAIGOVINDAN | 61dbeef | 2019-12-13 04:26:54 -0600 | [diff] [blame] | 1283 | if (req.session == nullptr) |
James Feist | 7166bf0 | 2019-12-10 16:52:14 +0000 | [diff] [blame] | 1284 | { |
Ed Tanous | 44e4518 | 2022-07-26 16:47:23 -0700 | [diff] [blame] | 1285 | rule.handle(req, asyncResp, params); |
James Feist | 7166bf0 | 2019-12-10 16:52:14 +0000 | [diff] [blame] | 1286 | return; |
| 1287 | } |
Jonathan Doman | d3c8ce6 | 2023-03-21 18:17:06 -0700 | [diff] [blame] | 1288 | validatePrivilege(req, asyncResp, rule, |
| 1289 | [&rule, asyncResp, params](Request& thisReq) mutable { |
Ed Tanous | 915d2d4 | 2023-03-15 13:09:34 -0700 | [diff] [blame] | 1290 | rule.handle(thisReq, asyncResp, params); |
Jonathan Doman | d3c8ce6 | 2023-03-21 18:17:06 -0700 | [diff] [blame] | 1291 | }); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 1292 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 1293 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1294 | void debugPrint() |
| 1295 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 1296 | for (size_t i = 0; i < perMethods.size(); i++) |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 1297 | { |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 1298 | BMCWEB_LOG_DEBUG << boost::beast::http::to_string( |
| 1299 | static_cast<boost::beast::http::verb>(i)); |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 1300 | perMethods[i].trie.debugPrint(); |
| 1301 | } |
Ed Tanous | 3dac749 | 2017-08-02 13:46:20 -0700 | [diff] [blame] | 1302 | } |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 1303 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1304 | std::vector<const std::string*> getRoutes(const std::string& parent) |
| 1305 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1306 | std::vector<const std::string*> ret; |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 1307 | |
| 1308 | for (const PerMethod& pm : perMethods) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1309 | { |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 1310 | std::vector<unsigned> x; |
| 1311 | pm.trie.findRouteIndexes(parent, x); |
| 1312 | for (unsigned index : x) |
| 1313 | { |
| 1314 | ret.push_back(&pm.rules[index]->rule); |
| 1315 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1316 | } |
| 1317 | return ret; |
| 1318 | } |
| 1319 | |
| 1320 | private: |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 1321 | struct PerMethod |
| 1322 | { |
| 1323 | std::vector<BaseRule*> rules; |
| 1324 | Trie trie; |
Ed Tanous | 313a3c2 | 2022-03-14 09:27:38 -0700 | [diff] [blame] | 1325 | // rule index 0 has special meaning; preallocate it to avoid |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 1326 | // duplication. |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 1327 | PerMethod() : rules(1) {} |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 1328 | }; |
Ed Tanous | 888880a | 2020-08-24 13:48:50 -0700 | [diff] [blame] | 1329 | |
Ed Tanous | 759cf10 | 2022-07-31 16:36:52 -0700 | [diff] [blame] | 1330 | std::array<PerMethod, methodNotAllowedIndex + 1> perMethods; |
Tanous | f00032d | 2018-11-05 01:18:10 -0300 | [diff] [blame] | 1331 | std::vector<std::unique_ptr<BaseRule>> allRules; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 1332 | }; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1333 | } // namespace crow |