xref: /openbmc/bmcweb/features/redfish/lib/redfish_v1.hpp (revision 8c623a96b43d69a4cfe95f9eac81be084d0a59b6)
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 
22*8c623a96SEd Tanous inline void redfish404(App& app, const crow::Request& req,
23*8c623a96SEd Tanous                        const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
24*8c623a96SEd Tanous                        const std::string& path)
25*8c623a96SEd Tanous {
26*8c623a96SEd Tanous     asyncResp->res.addHeader(boost::beast::http::field::allow, "");
27*8c623a96SEd Tanous 
28*8c623a96SEd Tanous     // If we fall to this route, we didn't have a more specific route, so return
29*8c623a96SEd Tanous     // 404
30*8c623a96SEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
31*8c623a96SEd Tanous     {
32*8c623a96SEd Tanous         return;
33*8c623a96SEd Tanous     }
34*8c623a96SEd Tanous 
35*8c623a96SEd Tanous     BMCWEB_LOG_ERROR << "404 on path " << path;
36*8c623a96SEd Tanous 
37*8c623a96SEd Tanous     boost::urls::string_value name = req.urlView.segments().back();
38*8c623a96SEd Tanous     std::string_view nameStr(name.data(), name.size());
39*8c623a96SEd Tanous     // Note, if we hit the wildcard route, we don't know the "type" the user was
40*8c623a96SEd Tanous     // actually requesting, but giving them a return with an empty string is
41*8c623a96SEd Tanous     // still better than nothing.
42*8c623a96SEd Tanous     messages::resourceNotFound(asyncResp->res, "", nameStr);
43*8c623a96SEd Tanous }
44*8c623a96SEd 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)));
50*8c623a96SEd Tanous 
51*8c623a96SEd Tanous     BMCWEB_ROUTE(app, "/redfish/<path>")
52*8c623a96SEd Tanous     (std::bind_front(redfish404, std::ref(app)));
534c25d66eSEd Tanous }
54f65fca6aSEd Tanous 
554c25d66eSEd Tanous } // namespace redfish
56