diff options
author | JackLivio <jack@livio.io> | 2019-02-23 13:49:50 -0500 |
---|---|---|
committer | JackLivio <jack@livio.io> | 2019-02-23 13:49:50 -0500 |
commit | 7d7af1bc71540dcfefbf669fc27e07f7996c586a (patch) | |
tree | 1114bc570192b3aa23fa4d3b727d77be8e6909b7 | |
parent | 5a0d510affcc77ddf240fc2b3465da6b570b1da1 (diff) | |
download | sdl_core-7d7af1bc71540dcfefbf669fc27e07f7996c586a.tar.gz |
Set behavior for omitted and missing service_names and handled_rpcs
6 files changed, 58 insertions, 25 deletions
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 7ccbe9fecd..81f369a6d8 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 @@ -113,7 +113,7 @@ void PublishAppServiceRequest::Run() { (*message_)[strings::msg_params][strings::app_service_manifest] [strings::service_type].asString(); - smart_objects::SmartArray* requested_handled_rpcs; + smart_objects::SmartArray* requested_handled_rpcs = NULL; if ((*message_)[strings::msg_params][strings::app_service_manifest].keyExists( strings::handled_rpcs)) { requested_handled_rpcs = @@ -121,8 +121,6 @@ void PublishAppServiceRequest::Run() { [strings::handled_rpcs].asArray(); } - ApplicationSharedPtr app = application_manager_.application(connection_key()); - bool result = policy_handler_.CheckAppServiceParameters(app->policy_app_id(), requested_service_name, diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index 9382a8580b..c267ac5de9 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -1965,21 +1965,26 @@ bool PolicyHandler::CheckAppServiceParameters( return false; } - if (!requested_service_name.empty()) { - auto service_names = - *(app_service_parameters[requested_service_type].service_names); + auto service_names = + *(app_service_parameters[requested_service_type].service_names); + if (!service_names.is_initialized()) { + LOG4CXX_DEBUG(logger_, + "Pt Service Name is Null, All service names accepted"); + } else if (!requested_service_name.empty()) { auto find_name_result = std::find(service_names.begin(), service_names.end(), rpc::String<0, 255>(requested_service_name)); if (find_name_result == service_names.end()) { + LOG4CXX_DEBUG(logger_, + "Disallowed service name: " << requested_service_name); return false; } } if (requested_handled_rpcs) { auto temp_rpcs = - *(app_service_parameters[requested_service_type].handled_rpcs); + app_service_parameters[requested_service_type].handled_rpcs; for (auto handled_it = temp_rpcs.begin(); handled_it != temp_rpcs.end(); ++handled_it) { handled_rpcs.push_back(handled_it->function_id); @@ -1991,6 +1996,8 @@ bool PolicyHandler::CheckAppServiceParameters( auto find_result = std::find( handled_rpcs.begin(), handled_rpcs.end(), requested_it->asInt()); if (find_result == handled_rpcs.end()) { + LOG4CXX_DEBUG(logger_, + "Disallowed by handled rpc: " << requested_it->asInt()); return false; } } diff --git a/src/components/policy/policy_external/include/policy/policy_table/types.h b/src/components/policy/policy_external/include/policy/policy_table/types.h index f3d154dd9f..0edfa55ab8 100644 --- a/src/components/policy/policy_external/include/policy/policy_table/types.h +++ b/src/components/policy/policy_external/include/policy/policy_table/types.h @@ -142,7 +142,7 @@ struct AppServiceHandledRpc : CompositeType { struct AppServiceInfo : CompositeType { public: Optional<AppServiceNames> service_names; - Optional<AppServiceHandledRpcs> handled_rpcs; + AppServiceHandledRpcs handled_rpcs; public: AppServiceInfo(); diff --git a/src/components/policy/policy_external/src/sql_pt_representation.cc b/src/components/policy/policy_external/src/sql_pt_representation.cc index 435638ddb7..0b60daa0e1 100644 --- a/src/components/policy/policy_external/src/sql_pt_representation.cc +++ b/src/components/policy/policy_external/src/sql_pt_representation.cc @@ -1325,16 +1325,28 @@ bool SQLPTRepresentation::SaveAppServiceParameters( } auto app_service_names = it->second.service_names; - policy_table::AppServiceNames::const_iterator names_it; - for (names_it = app_service_names->begin(); - names_it != app_service_names->end(); - ++names_it) { + + if (app_service_names.is_initialized() && app_service_names->empty()) { + // App service names is an empty array + LOG4CXX_DEBUG(logger_, "App Service Names is Empty Array"); service_name_query.Bind(0, static_cast<int64_t>(id)); - service_name_query.Bind(1, *names_it); + service_name_query.Bind(1); if (!service_name_query.Exec() || !service_name_query.Reset()) { - LOG4CXX_WARN(logger_, "Incorrect insert into app service names"); + LOG4CXX_WARN(logger_, "Incorrect insert into empty app service names"); return false; } + } else { + policy_table::AppServiceNames::const_iterator names_it; + for (names_it = app_service_names->begin(); + names_it != app_service_names->end(); + ++names_it) { + service_name_query.Bind(0, static_cast<int64_t>(id)); + service_name_query.Bind(1, *names_it); + if (!service_name_query.Exec() || !service_name_query.Reset()) { + LOG4CXX_WARN(logger_, "Incorrect insert into app service names"); + return false; + } + } } // Insert handled rpcs array into db @@ -1347,7 +1359,7 @@ bool SQLPTRepresentation::SaveAppServiceParameters( auto handled_rpcs = it->second.handled_rpcs; policy_table::AppServiceHandledRpcs::const_iterator rpc_it; - for (rpc_it = handled_rpcs->begin(); rpc_it != handled_rpcs->end(); + for (rpc_it = handled_rpcs.begin(); rpc_it != handled_rpcs.end(); ++rpc_it) { handled_rpcs_query.Bind(0, static_cast<int64_t>(id)); handled_rpcs_query.Bind(1, static_cast<int32_t>(rpc_it->function_id)); @@ -1816,15 +1828,17 @@ bool SQLPTRepresentation::GatherAppServiceParameters( service_name_query.Bind(0, service_type_id); while (service_name_query.Next()) { + LOG4CXX_DEBUG(logger_, "Loading service name"); (*app_service_parameters)[service_type].service_names->push_back( service_name_query.GetString(0)); + (*app_service_parameters)[service_type].service_names->mark_initialized(); } handled_rpcs_query.Bind(0, service_type_id); while (handled_rpcs_query.Next()) { policy_table::AppServiceHandledRpc handled_rpc; handled_rpc.function_id = handled_rpcs_query.GetInteger(0); - (*app_service_parameters)[service_type].handled_rpcs->push_back( + (*app_service_parameters)[service_type].handled_rpcs.push_back( handled_rpc); } diff --git a/src/components/policy/policy_regular/include/policy/policy_table/types.h b/src/components/policy/policy_regular/include/policy/policy_table/types.h index b7522065bd..118f98677a 100644 --- a/src/components/policy/policy_regular/include/policy/policy_table/types.h +++ b/src/components/policy/policy_regular/include/policy/policy_table/types.h @@ -136,7 +136,7 @@ struct AppServiceHandledRpc : CompositeType { struct AppServiceInfo : CompositeType { public: Optional<AppServiceNames> service_names; - Optional<AppServiceHandledRpcs> handled_rpcs; + AppServiceHandledRpcs handled_rpcs; public: AppServiceInfo(); diff --git a/src/components/policy/policy_regular/src/sql_pt_representation.cc b/src/components/policy/policy_regular/src/sql_pt_representation.cc index b2981759ab..661be436f0 100644 --- a/src/components/policy/policy_regular/src/sql_pt_representation.cc +++ b/src/components/policy/policy_regular/src/sql_pt_representation.cc @@ -1266,16 +1266,28 @@ bool SQLPTRepresentation::SaveAppServiceParameters( } auto app_service_names = it->second.service_names; - policy_table::AppServiceNames::const_iterator names_it; - for (names_it = app_service_names->begin(); - names_it != app_service_names->end(); - ++names_it) { + + if (app_service_names.is_initialized() && app_service_names->empty()) { + // App service names is an empty array + LOG4CXX_DEBUG(logger_, "App Service Names is Empty Array"); service_name_query.Bind(0, static_cast<int64_t>(id)); - service_name_query.Bind(1, *names_it); + service_name_query.Bind(1); if (!service_name_query.Exec() || !service_name_query.Reset()) { - LOG4CXX_WARN(logger_, "Incorrect insert into app service names"); + LOG4CXX_WARN(logger_, "Incorrect insert into empty app service names"); return false; } + } else { + policy_table::AppServiceNames::const_iterator names_it; + for (names_it = app_service_names->begin(); + names_it != app_service_names->end(); + ++names_it) { + service_name_query.Bind(0, static_cast<int64_t>(id)); + service_name_query.Bind(1, *names_it); + if (!service_name_query.Exec() || !service_name_query.Reset()) { + LOG4CXX_WARN(logger_, "Incorrect insert into app service names"); + return false; + } + } } // Insert handled rpcs array into db @@ -1288,7 +1300,7 @@ bool SQLPTRepresentation::SaveAppServiceParameters( auto handled_rpcs = it->second.handled_rpcs; policy_table::AppServiceHandledRpcs::const_iterator rpc_it; - for (rpc_it = handled_rpcs->begin(); rpc_it != handled_rpcs->end(); + for (rpc_it = handled_rpcs.begin(); rpc_it != handled_rpcs.end(); ++rpc_it) { handled_rpcs_query.Bind(0, static_cast<int64_t>(id)); handled_rpcs_query.Bind(1, static_cast<int32_t>(rpc_it->function_id)); @@ -1770,15 +1782,17 @@ bool SQLPTRepresentation::GatherAppServiceParameters( service_name_query.Bind(0, service_type_id); while (service_name_query.Next()) { + LOG4CXX_DEBUG(logger_, "Loading service name"); (*app_service_parameters)[service_type].service_names->push_back( service_name_query.GetString(0)); + (*app_service_parameters)[service_type].service_names->mark_initialized(); } handled_rpcs_query.Bind(0, service_type_id); while (handled_rpcs_query.Next()) { policy_table::AppServiceHandledRpc handled_rpc; handled_rpc.function_id = handled_rpcs_query.GetInteger(0); - (*app_service_parameters)[service_type].handled_rpcs->push_back( + (*app_service_parameters)[service_type].handled_rpcs.push_back( handled_rpc); } |