summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Kutsan <akutsan@luxoft.com>2018-02-06 11:36:44 +0200
committerAlexander <akutsan@luxoft.com>2018-09-10 14:01:34 +0300
commit2dd7e2a810de7b15ebc5eaa947e47170bfbcef2a (patch)
tree058c83c57d9811cdaeea2a0b239fb193f5434ea0
parent28235f88a6733106a7e8a0d490dfb16a5f374a33 (diff)
downloadsdl_core-2dd7e2a810de7b15ebc5eaa947e47170bfbcef2a.tar.gz
Add function to filter invalid parametres and RPCs
-rw-r--r--src/components/policy/policy_external/src/policy_manager_impl.cc47
-rw-r--r--src/components/policy/policy_regular/src/policy_manager_impl.cc46
2 files changed, 92 insertions, 1 deletions
diff --git a/src/components/policy/policy_external/src/policy_manager_impl.cc b/src/components/policy/policy_external/src/policy_manager_impl.cc
index e2b0d6524f..9dffaf52e3 100644
--- a/src/components/policy/policy_external/src/policy_manager_impl.cc
+++ b/src/components/policy/policy_external/src/policy_manager_impl.cc
@@ -271,6 +271,51 @@ std::string PolicyManagerImpl::GetLockScreenIconUrl() const {
return cache_->GetLockScreenIconUrl();
}
+/**
+ * @brief FilterInvalidFunctions filter functions that are absent in schema
+ * @param rpcs list of functions to filter
+ */
+void FilterInvalidFunctions(policy_table::Rpc& rpcs) {
+ policy_table::Rpc valid_rpcs;
+ for (const auto& rpc : rpcs) {
+ const std::string& rpc_name = rpc.first;
+ policy_table::FunctionID function_id;
+ if (policy_table::EnumFromJsonString(rpc_name, &function_id)) {
+ valid_rpcs.insert(rpc);
+ }
+ }
+ rpcs.swap(valid_rpcs);
+}
+
+/**
+ * @brief FilterInvalidParameters filter parameters that not present in schema
+ * @param rpc_parameters parameters to filter
+ */
+void FilterInvalidParameters(policy_table::RpcParameters& rpc_parameters) {
+ policy_table::Parameters valid_params;
+ for (auto& param : *(rpc_parameters.parameters)) {
+ if (param.is_valid()) {
+ valid_params.push_back(param);
+ }
+ }
+ rpc_parameters.parameters->swap(valid_params);
+}
+
+/**
+ * @brief FilterPolicyTable filter values that not present in schema
+ * @param pt policy table to filter
+ */
+void FilterPolicyTable(policy_table::PolicyTable& pt) {
+ for (auto& group : pt.functional_groupings) {
+ policy_table::Rpc& rpcs = group.second.rpcs;
+ FilterInvalidFunctions(rpcs);
+
+ for (auto& func : rpcs) {
+ FilterInvalidParameters(func.second);
+ }
+ }
+}
+
bool PolicyManagerImpl::LoadPT(const std::string& file,
const BinaryMessage& pt_content) {
LOG4CXX_INFO(logger_, "LoadPT of size " << pt_content.size());
@@ -287,7 +332,7 @@ bool PolicyManagerImpl::LoadPT(const std::string& file,
}
file_system::DeleteFile(file);
-
+ FilterPolicyTable(pt_update->policy_table);
if (!IsPTValid(pt_update, policy_table::PT_UPDATE)) {
wrong_ptu_update_received_ = true;
update_status_manager_.OnWrongUpdateReceived();
diff --git a/src/components/policy/policy_regular/src/policy_manager_impl.cc b/src/components/policy/policy_regular/src/policy_manager_impl.cc
index f4b6f0ae03..8c70437bfc 100644
--- a/src/components/policy/policy_regular/src/policy_manager_impl.cc
+++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc
@@ -143,6 +143,51 @@ void PolicyManagerImpl::CheckTriggers() {
}
}
+/**
+ * @brief FilterInvalidFunctions filter functions that are not present in schema
+ * @param rpcs list of functions to filter
+ */
+void FilterInvalidFunctions(policy_table::Rpc& rpcs) {
+ policy_table::Rpc valid_rpcs;
+ for (const auto& rpc : rpcs) {
+ const std::string& rpc_name = rpc.first;
+ policy_table::FunctionID function_id;
+ if (policy_table::EnumFromJsonString(rpc_name, &function_id)) {
+ valid_rpcs.insert(rpc);
+ }
+ }
+ rpcs.swap(valid_rpcs);
+}
+
+/**
+ * @brief FilterInvalidParameters filter parameters that not present in schema
+ * @param rpc_parameters parameters to filter
+ */
+void FilterInvalidParameters(policy_table::RpcParameters& rpc_parameters) {
+ policy_table::Parameters valid_params;
+ for (auto& param : *(rpc_parameters.parameters)) {
+ if (param.is_valid()) {
+ valid_params.push_back(param);
+ }
+ }
+ rpc_parameters.parameters->swap(valid_params);
+}
+
+/**
+ * @brief FilterPolicyTable filter values that not present in schema
+ * @param pt policy table to filter
+ */
+void FilterPolicyTable(policy_table::PolicyTable& pt) {
+ for (auto& group : pt.functional_groupings) {
+ policy_table::Rpc& rpcs = group.second.rpcs;
+ FilterInvalidFunctions(rpcs);
+
+ for (auto& func : rpcs) {
+ FilterInvalidParameters(func.second);
+ }
+ }
+}
+
bool PolicyManagerImpl::LoadPT(const std::string& file,
const BinaryMessage& pt_content) {
LOG4CXX_INFO(logger_, "LoadPT of size " << pt_content.size());
@@ -168,6 +213,7 @@ bool PolicyManagerImpl::LoadPT(const std::string& file,
file_system::DeleteFile(file);
+ FilterPolicyTable(pt_update->policy_table);
if (!IsPTValid(pt_update, policy_table::PT_UPDATE)) {
wrong_ptu_update_received_ = true;
update_status_manager_.OnWrongUpdateReceived();