diff options
author | JackLivio <jack@livio.io> | 2019-01-23 23:17:25 -0500 |
---|---|---|
committer | JackLivio <jack@livio.io> | 2019-01-23 23:17:25 -0500 |
commit | f27fe0bc5980ea19baf89791d45414854fa91325 (patch) | |
tree | 224982ede63470ab7dbe14b8b58faad99cd9b476 /src/components/application_manager | |
parent | 1057d6f4fc933c681ec52365c51268a8f3418a07 (diff) | |
download | sdl_core-f27fe0bc5980ea19baf89791d45414854fa91325.tar.gz |
Add policy handler CheckAppServiceParameters
Diffstat (limited to 'src/components/application_manager')
3 files changed, 37 insertions, 21 deletions
diff --git a/src/components/application_manager/include/application_manager/policies/policy_handler.h b/src/components/application_manager/include/application_manager/policies/policy_handler.h index 1dff9e348c..fbceef3d6c 100644 --- a/src/components/application_manager/include/application_manager/policies/policy_handler.h +++ b/src/components/application_manager/include/application_manager/policies/policy_handler.h @@ -450,7 +450,12 @@ class PolicyHandler : public PolicyHandlerInterface, void GetAppServiceParameters(const std::string& policy_app_id, std::string& service_name, std::string& service_type, - std::vector<uint32_t>& handled_rpcs) const; + std::vector<uint32_t>& handled_rpcs) const OVERRIDE; + + bool CheckAppServiceParameters(const std::string& policy_app_id, + const std::string& requested_service_name, + const std::string& requested_service_type, + smart_objects::SmartArray* requested_handled_rpcs) const OVERRIDE; virtual void OnUpdateHMIAppType( std::map<std::string, StringArray> app_hmi_types) OVERRIDE; diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_request.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_request.cc index b48f844263..d2cc165656 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_request.cc +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_request.cc @@ -88,32 +88,15 @@ void PublishAppServiceRequest::Run() { (*message_)[strings::msg_params][strings::app_service_manifest] [strings::handled_rpcs].asArray(); - std::string service_name = std::string(); - std::string service_type = std::string(); - std::vector<uint32_t> handled_rpcs = {}; ApplicationSharedPtr app = application_manager_.application(connection_key()); - policy_handler_.GetAppServiceParameters( - app->policy_app_id(), service_name, service_type, handled_rpcs); + bool result = policy_handler_.CheckAppServiceParameters( + app->policy_app_id(), requested_service_name, requested_service_type, requested_handled_rpcs); - if (service_name != requested_service_name) { + if (!result) { SendResponse(false, mobile_apis::Result::DISALLOWED, NULL, NULL); } - if (service_type != requested_service_type) { - SendResponse(false, mobile_apis::Result::DISALLOWED, NULL, NULL); - } - - for (auto requested_it = requested_handled_rpcs->begin(); - requested_it != requested_handled_rpcs->end(); - ++requested_it) { - auto find_result = std::find( - handled_rpcs.begin(), handled_rpcs.end(), requested_it->asUInt()); - if (find_result == handled_rpcs.end()) { - SendResponse(false, mobile_apis::Result::DISALLOWED, NULL, NULL); - } - } - response_params[strings::app_service_record] = service_record; SendResponse(true, mobile_apis::Result::SUCCESS, NULL, &response_params); diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index 6034e34b18..d6caaec410 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -1947,6 +1947,34 @@ void PolicyHandler::GetAppServiceParameters( policy_app_id, service_name, service_type, handled_rpcs); } +bool PolicyHandler::CheckAppServiceParameters(const std::string& policy_app_id, + const std::string& requested_service_name, + const std::string& requested_service_type, + smart_objects::SmartArray* requested_handled_rpcs) const { + std::string service_name = std::string(); + std::string service_type = std::string(); + std::vector<uint32_t> handled_rpcs = {}; + this->GetAppServiceParameters(policy_app_id, service_name, service_type, handled_rpcs); + if (service_name != requested_service_name) { + return false; + } + + if (service_type != requested_service_type) { + return false; + } + + for (auto requested_it = requested_handled_rpcs->begin(); + requested_it != requested_handled_rpcs->end(); + ++requested_it) { + auto find_result = std::find( + handled_rpcs.begin(), handled_rpcs.end(), requested_it->asUInt()); + if (find_result == handled_rpcs.end()) { + return false; + } + } + return true; +} + uint32_t PolicyHandler::HeartBeatTimeout(const std::string& app_id) const { POLICY_LIB_CHECK(0); return policy_manager_->HeartBeatTimeout(app_id); |