xref: /openbmc/bmcweb/features/redfish/lib/redfish_v1.hpp (revision 686b7093f35d22fc6435f2ac21a16879ac27b8c0)
14c25d66eSEd Tanous #pragma once
24c25d66eSEd Tanous 
34c25d66eSEd Tanous #include <app.hpp>
44c25d66eSEd Tanous #include <http_request.hpp>
54c25d66eSEd Tanous #include <http_response.hpp>
64c25d66eSEd Tanous 
74c25d66eSEd Tanous #include <string>
84c25d66eSEd Tanous 
94c25d66eSEd Tanous namespace redfish
104c25d66eSEd Tanous {
114c25d66eSEd Tanous 
12d3355c5cSEd Tanous inline void redfishGet(App& app, const crow::Request& req,
13d3355c5cSEd Tanous                        const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
144c25d66eSEd Tanous {
153ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
161e925c84SEd Tanous     {
171e925c84SEd Tanous         return;
181e925c84SEd Tanous     }
191476687dSEd Tanous     asyncResp->res.jsonValue["v1"] = "/redfish/v1/";
20d3355c5cSEd Tanous }
21d3355c5cSEd Tanous 
228c623a96SEd Tanous inline void redfish404(App& app, const crow::Request& req,
238c623a96SEd Tanous                        const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
248c623a96SEd Tanous                        const std::string& path)
258c623a96SEd Tanous {
268c623a96SEd Tanous     asyncResp->res.addHeader(boost::beast::http::field::allow, "");
278c623a96SEd Tanous 
288c623a96SEd Tanous     // If we fall to this route, we didn't have a more specific route, so return
298c623a96SEd Tanous     // 404
30*686b7093SNan Zhou     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
318c623a96SEd Tanous     {
328c623a96SEd Tanous         return;
338c623a96SEd Tanous     }
348c623a96SEd Tanous 
358c623a96SEd Tanous     BMCWEB_LOG_ERROR << "404 on path " << path;
368c623a96SEd Tanous 
378c623a96SEd Tanous     boost::urls::string_value name = req.urlView.segments().back();
388c623a96SEd Tanous     std::string_view nameStr(name.data(), name.size());
398c623a96SEd Tanous     // Note, if we hit the wildcard route, we don't know the "type" the user was
408c623a96SEd Tanous     // actually requesting, but giving them a return with an empty string is
418c623a96SEd Tanous     // still better than nothing.
428c623a96SEd Tanous     messages::resourceNotFound(asyncResp->res, "", nameStr);
438c623a96SEd Tanous }
448c623a96SEd Tanous 
45f65fca6aSEd Tanous inline void requestRoutesRedfish(App& app)
46d3355c5cSEd Tanous {
47d3355c5cSEd Tanous     BMCWEB_ROUTE(app, "/redfish/")
48d3355c5cSEd Tanous         .methods(boost::beast::http::verb::get)(
49d3355c5cSEd Tanous             std::bind_front(redfishGet, std::ref(app)));
508c623a96SEd Tanous 
518c623a96SEd Tanous     BMCWEB_ROUTE(app, "/redfish/<path>")
528c623a96SEd Tanous     (std::bind_front(redfish404, std::ref(app)));
534c25d66eSEd Tanous }
54f65fca6aSEd Tanous 
554c25d66eSEd Tanous } // namespace redfish
56