MCPcopy Create free account
hub / github.com/ComodoSecurity/openedr / HandleMethodCall

Method HandleMethodCall

edrav2/iprj/libcore/src/jsonrpcserver.cpp:45–86  ·  view source on GitHub ↗

Method calls handler

Source from the content-addressed store, hash-verified

43 // Method calls handler
44 //
45 void HandleMethodCall(const std::string& name, const Json::Value& input, Json::Value& output) override
46 {
47 ChannelMode eCallChannelMode = ChannelMode::Plain;
48 CMD_TRY
49 {
50 Variant vParams;
51 Variant vCommand;
52
53 if (name == c_sEncryptedFieldName)
54 {
55 if ((m_eChannelMode != ChannelMode::Encrypted) && (m_eChannelMode != ChannelMode::Both))
56 error::OperationNotSupported(SL, "Encrypted commands are not supported").throwException();
57 eCallChannelMode = ChannelMode::Encrypted;
58 auto vData = decryptJsonValue(input);
59 vCommand = vData["command"];
60 vParams = vData["params"];
61 }
62 else
63 {
64 vCommand = name;
65 vParams = convertJsonValueToVariant(input);
66 }
67
68 if ((m_eChannelMode != ChannelMode::Both) && (m_eChannelMode != eCallChannelMode))
69 error::OperationNotSupported(SL, FMT("Wrong RPC channel mode <" <<
70 getChannelModeString(eCallChannelMode) << ">")).throwException();
71
72 if (vParams.isEmpty())
73 LOGLVL(Debug, "Process request <" << vCommand << ">");
74 else
75 LOGLVL(Debug, "Process request <" << vCommand << ">, params:\n" << vParams);
76 Variant vResult = createCommand(m_vProcessor, vCommand, vParams)->execute();
77 if (vResult.isEmpty())
78 LOGLVL(Debug, "Send empty response");
79 else
80 LOGLVL(Debug, "Send response:\n" << vResult);
81
82 if (eCallChannelMode == ChannelMode::Encrypted)
83 encryptJsonValue(vResult, output, m_vSerializeConfig);
84 else
85 output = convertVariantToJsonValue(vResult);
86 }
87 CMD_PREPARE_CATCH
88 catch (error::TypeError& ex)
89 {

Callers

nothing calls this directly

Calls 11

decryptJsonValueFunction · 0.85
getChannelModeStringFunction · 0.85
createCommandFunction · 0.85
encryptJsonValueFunction · 0.85
throwExceptionMethod · 0.80
VariantClass · 0.50
ifFunction · 0.50
isEmptyMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected