in src/modules/firewall/src/lib/Firewall.cpp [90:180]
int FirewallModuleBase::Get(const char* componentName, const char* objectName, MMI_JSON_STRING* payload, int* payloadSizeBytes)
{
int status = MMI_OK;
if (nullptr == componentName)
{
OsConfigLogError(FirewallLog::Get(), "Invalid (null) component name");
status = EINVAL;
}
else if (nullptr == objectName)
{
OsConfigLogError(FirewallLog::Get(), "Invalid (null) object name");
status = EINVAL;
}
else if (nullptr == payload)
{
OsConfigLogError(FirewallLog::Get(), "Invalid (null) payload");
status = EINVAL;
}
else if (nullptr == payloadSizeBytes)
{
OsConfigLogError(FirewallLog::Get(), "Invalid (null) payload size");
status = EINVAL;
}
else if (0 != m_firewallComponent.compare(componentName))
{
OsConfigLogError(FirewallLog::Get(), "Invalid component name: %s", componentName);
status = EINVAL;
}
else
{
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
*payloadSizeBytes = 0;
*payload = nullptr;
if (0 == m_reportedState.compare(objectName))
{
status = GetState(writer);
}
else if (0 == m_reportedFingerprint.compare(objectName))
{
status = GetFingerprint(writer);
}
else if (0 == m_reportedDefaultPolicies.compare(objectName))
{
status = GetDefaultPolicies(writer);
}
else if (0 == m_reportedConfigurationStatus.compare(objectName))
{
status = GetConfigurationStatus(writer);
}
else if (0 == m_reportedConfigurationStatusDetail.compare(objectName))
{
status = GetConfigurationStatusDetail(writer);
}
else
{
OsConfigLogError(FirewallLog::Get(), "Invalid object name: %s", objectName);
status = EINVAL;
}
if (MMI_OK == status)
{
if ((m_maxPayloadSizeBytes > 0) && (buffer.GetSize() > m_maxPayloadSizeBytes))
{
OsConfigLogError(FirewallLog::Get(), "Payload size exceeds maximum payload size: %d > %d", static_cast<int>(buffer.GetSize()), m_maxPayloadSizeBytes);
status = E2BIG;
}
else
{
*payloadSizeBytes = buffer.GetSize();
*payload = new (std::nothrow) char[*payloadSizeBytes];
if (*payload != nullptr)
{
std::fill(*payload, *payload + *payloadSizeBytes, 0);
std::memcpy(*payload, buffer.GetString(), *payloadSizeBytes);
}
else
{
*payloadSizeBytes = 0;
status = ENOMEM;
}
}
}
}
return status;
}