///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
| 28 | |
| 29 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 30 | void FSecure::C3::Core::Profiler::HandleActionsPacket(ByteView actionsPacket) |
| 31 | { |
| 32 | std::scoped_lock lock(m_AccessMutex); |
| 33 | |
| 34 | try |
| 35 | { |
| 36 | auto actions = json::parse(std::string{ actionsPacket }); |
| 37 | auto jActions = actions.find("Command"); |
| 38 | if (jActions == actions.end()) |
| 39 | throw std::runtime_error{ "Command object is missing" }; |
| 40 | |
| 41 | (*jActions)["ByteForm"] = base64::encode(TranslateCommand(*jActions)); |
| 42 | |
| 43 | // Helper lambda that read particular element from actions JSON. |
| 44 | auto ReadJsonElement = [&actions](std::string_view elementName) |
| 45 | { |
| 46 | auto element = actions.find(elementName); |
| 47 | if (element != actions.end()) |
| 48 | return element; |
| 49 | |
| 50 | throw std::runtime_error{ std::string{ elementName } +" is not specified." }; |
| 51 | }; |
| 52 | |
| 53 | // Parse AgentId. |
| 54 | if (auto relayAgentId = ReadJsonElement("relayAgentId"); relayAgentId->is_null()) |
| 55 | m_Gateway->ParseAndRunCommand(actions); |
| 56 | else if (auto agent = m_Gateway->m_Agents.Find(relayAgentId->get<std::string>())) |
| 57 | agent->ParseAndRunCommand(actions); |
| 58 | else |
| 59 | throw std::runtime_error{ "Unknown AgentId." }; |
| 60 | } |
| 61 | catch (std::exception& exception) |
| 62 | { |
| 63 | if (auto gateway = m_Gateway->m_Gateway.lock()) |
| 64 | gateway->Log({ "Caught an exception while parsing Action. "s + exception.what(), FSecure::C3::LogMessage::Severity::Error}); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 69 | FSecure::C3::Core::Profiler::Profile FSecure::C3::Core::Profiler::Get() |
no test coverage detected