summaryrefslogtreecommitdiff
path: root/include/openbmc_dbus_rest.hpp
diff options
context:
space:
mode:
authorMatt Spinler <spinler@us.ibm.com>2019-01-15 18:59:20 +0300
committerMatt Spinler <spinler@us.ibm.com>2019-01-15 18:59:20 +0300
commit318bd892a6d283319002b96216b1b746864089d9 (patch)
tree3e032ecf57cb59d9a485c1267d0cdd16547d112a /include/openbmc_dbus_rest.hpp
parent127ea5461b72a2e19d08fbfd47121ca8f7964c30 (diff)
downloadbmcweb-318bd892a6d283319002b96216b1b746864089d9.tar.xz
REST: Return on error in findActionOnInterface
All of the useful code in this function is in an else leg after an error check. Add a return statement in the error check so the else statement can be removed, to reduce the level of indent as the code already indents several additional levels. Change-Id: Ia664ae2af31a5d72e322dd6c3c83ea8961931e22 Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Diffstat (limited to 'include/openbmc_dbus_rest.hpp')
-rw-r--r--include/openbmc_dbus_rest.hpp197
1 files changed, 95 insertions, 102 deletions
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index f1dbdafd12..7eae73bfce 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -767,123 +767,116 @@ void findActionOnInterface(std::shared_ptr<InProgressActionData> transaction,
BMCWEB_LOG_ERROR
<< "Introspect call failed with error: " << ec.message()
<< " on process: " << connectionName << "\n";
+ return;
}
- else
- {
- tinyxml2::XMLDocument doc;
+ tinyxml2::XMLDocument doc;
- doc.Parse(introspect_xml.data(), introspect_xml.size());
- tinyxml2::XMLNode *pRoot = doc.FirstChildElement("node");
- if (pRoot == nullptr)
- {
- BMCWEB_LOG_ERROR << "XML document failed to parse "
- << connectionName << "\n";
- return;
- }
- tinyxml2::XMLElement *interfaceNode =
- pRoot->FirstChildElement("interface");
- while (interfaceNode != nullptr)
+ doc.Parse(introspect_xml.data(), introspect_xml.size());
+ tinyxml2::XMLNode *pRoot = doc.FirstChildElement("node");
+ if (pRoot == nullptr)
+ {
+ BMCWEB_LOG_ERROR << "XML document failed to parse "
+ << connectionName << "\n";
+ return;
+ }
+ tinyxml2::XMLElement *interfaceNode =
+ pRoot->FirstChildElement("interface");
+ while (interfaceNode != nullptr)
+ {
+ const char *thisInterfaceName =
+ interfaceNode->Attribute("name");
+ if (thisInterfaceName != nullptr)
{
- const char *thisInterfaceName =
- interfaceNode->Attribute("name");
- if (thisInterfaceName != nullptr)
+ if (!transaction->interfaceName.empty() &&
+ (transaction->interfaceName != thisInterfaceName))
{
- if (!transaction->interfaceName.empty() &&
- (transaction->interfaceName != thisInterfaceName))
- {
- interfaceNode =
- interfaceNode->NextSiblingElement("interface");
- continue;
- }
+ interfaceNode =
+ interfaceNode->NextSiblingElement("interface");
+ continue;
+ }
- tinyxml2::XMLElement *methodNode =
- interfaceNode->FirstChildElement("method");
- while (methodNode != nullptr)
+ tinyxml2::XMLElement *methodNode =
+ interfaceNode->FirstChildElement("method");
+ while (methodNode != nullptr)
+ {
+ const char *thisMethodName =
+ methodNode->Attribute("name");
+ BMCWEB_LOG_DEBUG << "Found method: " << thisMethodName;
+ if (thisMethodName != nullptr &&
+ thisMethodName == transaction->methodName)
{
- const char *thisMethodName =
- methodNode->Attribute("name");
- BMCWEB_LOG_DEBUG << "Found method: "
- << thisMethodName;
- if (thisMethodName != nullptr &&
- thisMethodName == transaction->methodName)
+ BMCWEB_LOG_DEBUG
+ << "Found method named " << thisMethodName
+ << " on interface " << thisInterfaceName;
+ sdbusplus::message::message m =
+ crow::connections::systemBus->new_method_call(
+ connectionName.c_str(),
+ transaction->path.c_str(),
+ thisInterfaceName,
+ transaction->methodName.c_str());
+
+ tinyxml2::XMLElement *argumentNode =
+ methodNode->FirstChildElement("arg");
+
+ nlohmann::json::const_iterator argIt =
+ transaction->arguments.begin();
+
+ while (argumentNode != nullptr)
{
- BMCWEB_LOG_DEBUG
- << "Found method named " << thisMethodName
- << " on interface " << thisInterfaceName;
- sdbusplus::message::message m =
- crow::connections::systemBus
- ->new_method_call(
- connectionName.c_str(),
- transaction->path.c_str(),
- thisInterfaceName,
- transaction->methodName.c_str());
-
- tinyxml2::XMLElement *argumentNode =
- methodNode->FirstChildElement("arg");
-
- nlohmann::json::const_iterator argIt =
- transaction->arguments.begin();
-
- while (argumentNode != nullptr)
+ const char *argDirection =
+ argumentNode->Attribute("direction");
+ const char *argType =
+ argumentNode->Attribute("type");
+ if (argDirection != nullptr &&
+ argType != nullptr &&
+ std::string(argDirection) == "in")
{
- const char *argDirection =
- argumentNode->Attribute("direction");
- const char *argType =
- argumentNode->Attribute("type");
- if (argDirection != nullptr &&
- argType != nullptr &&
- std::string(argDirection) == "in")
+ if (argIt == transaction->arguments.end())
{
- if (argIt ==
- transaction->arguments.end())
- {
- transaction->setErrorStatus(
- "Invalid method args");
- return;
- }
- if (convertJsonToDbus(
- m.get(), std::string(argType),
- *argIt) < 0)
- {
- transaction->setErrorStatus(
- "Invalid method arg type");
- return;
- }
-
- argIt++;
+ transaction->setErrorStatus(
+ "Invalid method args");
+ return;
+ }
+ if (convertJsonToDbus(m.get(),
+ std::string(argType),
+ *argIt) < 0)
+ {
+ transaction->setErrorStatus(
+ "Invalid method arg type");
+ return;
}
- argumentNode =
- argumentNode->NextSiblingElement("arg");
- }
- crow::connections::systemBus->async_send(
- m, [transaction](
- boost::system::error_code ec,
- sdbusplus::message::message &m) {
- if (ec)
- {
- setErrorResponse(
- transaction->res,
- boost::beast::http::status::
- internal_server_error,
- "Method call failed",
- methodFailedMsg);
- return;
- }
- transaction->res.jsonValue = {
- {"status", "ok"},
- {"message", "200 OK"},
- {"data", nullptr}};
- });
- break;
+ argIt++;
+ }
+ argumentNode =
+ argumentNode->NextSiblingElement("arg");
}
- methodNode =
- methodNode->NextSiblingElement("method");
+
+ crow::connections::systemBus->async_send(
+ m,
+ [transaction](boost::system::error_code ec,
+ sdbusplus::message::message &m) {
+ if (ec)
+ {
+ setErrorResponse(
+ transaction->res,
+ boost::beast::http::status::
+ internal_server_error,
+ "Method call failed",
+ methodFailedMsg);
+ return;
+ }
+ transaction->res.jsonValue = {
+ {"status", "ok"},
+ {"message", "200 OK"},
+ {"data", nullptr}};
+ });
+ break;
}
+ methodNode = methodNode->NextSiblingElement("method");
}
- interfaceNode =
- interfaceNode->NextSiblingElement("interface");
}
+ interfaceNode = interfaceNode->NextSiblingElement("interface");
}
},
connectionName, transaction->path,