summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackLivio <jack@livio.io>2019-01-26 20:33:29 -0500
committerJackLivio <jack@livio.io>2019-01-26 20:33:29 -0500
commita811be5a47658fc162357c9982bae789bcb53b6e (patch)
tree4e564c4ff4d23f149dacfda3c7e12ab633e9a007
parentcb01cd11870ce4642ba49f7b86d4bd45562f2f1d (diff)
downloadsdl_core-a811be5a47658fc162357c9982bae789bcb53b6e.tar.gz
Update app service structure in policies
-rw-r--r--src/components/application_manager/include/application_manager/policies/policy_handler.h8
-rw-r--r--src/components/application_manager/src/policies/policy_handler.cc38
-rw-r--r--src/components/include/application_manager/policies/policy_handler_interface.h4
-rw-r--r--src/components/include/policy/policy_regular/policy/policy_manager.h4
-rw-r--r--src/components/policy/policy_regular/include/policy/cache_manager.h4
-rw-r--r--src/components/policy/policy_regular/include/policy/cache_manager_interface.h4
-rw-r--r--src/components/policy/policy_regular/include/policy/policy_manager_impl.h8
-rw-r--r--src/components/policy/policy_regular/include/policy/policy_table/types.h30
-rw-r--r--src/components/policy/policy_regular/include/policy/sql_pt_queries.h12
-rw-r--r--src/components/policy/policy_regular/include/policy/sql_pt_representation.h11
-rw-r--r--src/components/policy/policy_regular/src/cache_manager.cc17
-rw-r--r--src/components/policy/policy_regular/src/policy_manager_impl.cc7
-rw-r--r--src/components/policy/policy_regular/src/policy_table/types.cc100
-rw-r--r--src/components/policy/policy_regular/src/policy_table/validation.cc4
-rw-r--r--src/components/policy/policy_regular/src/sql_pt_queries.cc82
-rw-r--r--src/components/policy/policy_regular/src/sql_pt_representation.cc153
16 files changed, 331 insertions, 155 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 3aae747542..097a0ac563 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
@@ -447,11 +447,9 @@ class PolicyHandler : public PolicyHandlerInterface,
void OnSetCloudAppProperties(
const smart_objects::SmartObject& message) OVERRIDE;
- void GetAppServiceParameters(
- const std::string& policy_app_id,
- std::string& service_name,
- std::string& service_type,
- std::vector<uint32_t>& handled_rpcs) const OVERRIDE;
+ void GetAppServiceParameters(const std::string& policy_app_id,
+ policy_table::AppServiceParameters*
+ app_service_parameters) const OVERRIDE;
bool CheckAppServiceParameters(
const std::string& policy_app_id,
diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc
index cbe9dd6812..22e4cc1131 100644
--- a/src/components/application_manager/src/policies/policy_handler.cc
+++ b/src/components/application_manager/src/policies/policy_handler.cc
@@ -1939,12 +1939,10 @@ void PolicyHandler::OnSetCloudAppProperties(
void PolicyHandler::GetAppServiceParameters(
const std::string& policy_app_id,
- std::string& service_name,
- std::string& service_type,
- std::vector<uint32_t>& handled_rpcs) const {
+ policy_table::AppServiceParameters* app_service_parameters) const {
POLICY_LIB_CHECK_VOID();
- policy_manager_->GetAppServiceParameters(
- policy_app_id, service_name, service_type, handled_rpcs);
+ policy_manager_->GetAppServiceParameters(policy_app_id,
+ app_service_parameters);
}
bool PolicyHandler::CheckAppServiceParameters(
@@ -1955,18 +1953,32 @@ bool PolicyHandler::CheckAppServiceParameters(
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 (!requested_service_name.empty() &&
- service_name != requested_service_name) {
+
+ policy_table::AppServiceParameters app_service_parameters =
+ policy_table::AppServiceParameters();
+ this->GetAppServiceParameters(policy_app_id, &app_service_parameters);
+
+ if (app_service_parameters.find(requested_service_type) ==
+ app_service_parameters.end()) {
+ LOG4CXX_DEBUG(logger_,
+ "Disallowed service type: " << requested_service_type);
return false;
}
- if (service_type != requested_service_type) {
- return false;
+ if (!requested_service_name.empty()) {
+ auto service_names =
+ *(app_service_parameters[requested_service_type].service_names);
+ 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()) {
+ return false;
+ }
}
- if (requested_handled_rpcs) {
+ // todo handled rpcs check
+ /*if (requested_handled_rpcs) {
for (auto requested_it = requested_handled_rpcs->begin();
requested_it != requested_handled_rpcs->end();
++requested_it) {
@@ -1976,7 +1988,7 @@ bool PolicyHandler::CheckAppServiceParameters(
return false;
}
}
- }
+ }*/
return true;
}
diff --git a/src/components/include/application_manager/policies/policy_handler_interface.h b/src/components/include/application_manager/policies/policy_handler_interface.h
index 29776aa926..39118e9acc 100644
--- a/src/components/include/application_manager/policies/policy_handler_interface.h
+++ b/src/components/include/application_manager/policies/policy_handler_interface.h
@@ -490,9 +490,7 @@ class PolicyHandlerInterface {
virtual void GetAppServiceParameters(
const std::string& policy_app_id,
- std::string& service_name,
- std::string& service_type,
- std::vector<uint32_t>& handled_rpcs) const = 0;
+ policy_table::AppServiceParameters* app_service_parameters) const = 0;
virtual bool CheckAppServiceParameters(
const std::string& policy_app_id,
diff --git a/src/components/include/policy/policy_regular/policy/policy_manager.h b/src/components/include/policy/policy_regular/policy/policy_manager.h
index e62d12cd03..14f10c2036 100644
--- a/src/components/include/policy/policy_regular/policy/policy_manager.h
+++ b/src/components/include/policy/policy_regular/policy/policy_manager.h
@@ -583,9 +583,7 @@ class PolicyManager : public usage_statistics::StatisticsManager {
*/
virtual void GetAppServiceParameters(
const std::string& policy_app_id,
- std::string& service_name,
- std::string& service_type,
- std::vector<uint32_t>& handled_rpcs) const = 0;
+ policy_table::AppServiceParameters* app_service_parameters) const = 0;
/**
* @brief OnAppRegisteredOnMobile allows to handle event when application were
diff --git a/src/components/policy/policy_regular/include/policy/cache_manager.h b/src/components/policy/policy_regular/include/policy/cache_manager.h
index 6d042f6ac3..e8d4e1782e 100644
--- a/src/components/policy/policy_regular/include/policy/cache_manager.h
+++ b/src/components/policy/policy_regular/include/policy/cache_manager.h
@@ -226,9 +226,7 @@ class CacheManager : public CacheManagerInterface {
*/
virtual void GetAppServiceParameters(
const std::string& policy_app_id,
- std::string& service_name,
- std::string& service_type,
- std::vector<uint32_t>& handled_rpcs) const;
+ policy_table::AppServiceParameters* app_service_parameters) const;
/**
* @brief Allows to update 'vin' field in module_meta table.
diff --git a/src/components/policy/policy_regular/include/policy/cache_manager_interface.h b/src/components/policy/policy_regular/include/policy/cache_manager_interface.h
index 3973eca581..4345244e76 100644
--- a/src/components/policy/policy_regular/include/policy/cache_manager_interface.h
+++ b/src/components/policy/policy_regular/include/policy/cache_manager_interface.h
@@ -233,9 +233,7 @@ class CacheManagerInterface {
*/
virtual void GetAppServiceParameters(
const std::string& policy_app_id,
- std::string& service_name,
- std::string& service_type,
- std::vector<uint32_t>& handled_rpcs) const = 0;
+ policy_table::AppServiceParameters* app_service_parameters) const = 0;
/**
* @brief Allows to update 'vin' field in module_meta table.
diff --git a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h
index f4dd5d0870..8628b1a8a0 100644
--- a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h
+++ b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h
@@ -642,11 +642,9 @@ class PolicyManagerImpl : public PolicyManager {
* @param handled_rpcs Vector of allowed function ids an app service provider
* can handle
*/
- void GetAppServiceParameters(
- const std::string& policy_app_id,
- std::string& service_name,
- std::string& service_type,
- std::vector<uint32_t>& handled_rpcs) const OVERRIDE;
+ void GetAppServiceParameters(const std::string& policy_app_id,
+ policy_table::AppServiceParameters*
+ app_service_parameters) const OVERRIDE;
/**
* @brief OnAppRegisteredOnMobile allows to handle event when application were
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 f2f99003e2..4b379ee7b6 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
@@ -50,6 +50,7 @@ struct MessageLanguages;
struct MessageString;
struct RpcParameters;
struct Rpcs;
+struct AppServiceInfo;
} // namespace policy_table_interface_base
} // namespace rpc
@@ -98,7 +99,12 @@ typedef Array<Enum<RequestType>, 0, 255> RequestTypes;
typedef Strings RequestSubTypes;
-typedef Array<Integer<uint32_t, 0, UINT32_MAX>, 0, 255> HandledRpcs;
+typedef String<0, 255> AppServiceType;
+typedef String<0, 255> AppServiceName;
+typedef Array<AppServiceName, 0, 255> AppServiceNames;
+typedef Array<Integer<uint32_t, 0, UINT32_MAX>, 0, 255> AppServiceHandledRpcs;
+
+typedef Map<AppServiceInfo, 0, 255> AppServiceParameters;
typedef Map<Strings, 0, 255> RemoteRpcs;
typedef Map<RemoteRpcs, 0, 255> AccessModules;
@@ -107,6 +113,24 @@ typedef Array<Enum<ModuleType>, 0, 255> ModuleTypes;
typedef AppHMIType AppHmiType;
typedef std::vector<AppHMIType> AppHmiTypes;
+struct AppServiceInfo : CompositeType {
+ public:
+ Optional<AppServiceNames> service_names;
+ Optional<AppServiceHandledRpcs> handled_rpcs;
+ AppServiceInfo();
+ ~AppServiceInfo();
+ AppServiceInfo(const Json::Value* value__);
+ Json::Value ToJsonValue() const;
+ bool is_valid() const;
+ bool is_initialized() const;
+ bool struct_empty() const;
+ virtual void SetPolicyTableType(PolicyTableType pt_type);
+ void ReportErrors(rpc::ValidationReport* report__) const;
+
+ private:
+ bool Validate() const;
+};
+
struct PolicyBase : CompositeType {
public:
Enum<Priority> priority;
@@ -154,9 +178,7 @@ struct ApplicationParams : PolicyBase {
Optional<String<0, 255> > cloud_transport_type;
// App Service Params
- Optional<String<0, 255> > service_name;
- Optional<String<0, 255> > service_type;
- Optional<HandledRpcs> handled_rpcs;
+ Optional<AppServiceParameters> app_service_parameters;
public:
ApplicationParams();
diff --git a/src/components/policy/policy_regular/include/policy/sql_pt_queries.h b/src/components/policy/policy_regular/include/policy/sql_pt_queries.h
index c910fbb3df..bada9a003a 100644
--- a/src/components/policy/policy_regular/include/policy/sql_pt_queries.h
+++ b/src/components/policy/policy_regular/include/policy/sql_pt_queries.h
@@ -66,7 +66,9 @@ extern const std::string kSelectNicknames;
extern const std::string kSelectAppTypes;
extern const std::string kSelectRequestTypes;
extern const std::string kSelectRequestSubTypes;
-extern const std::string kSelectHandledRpcs;
+extern const std::string kSelectAppServiceTypes;
+extern const std::string kSelectAppServiceNames;
+extern const std::string kSelectAppServiceHandledRpcs;
extern const std::string kSelectSecondsBetweenRetries;
extern const std::string kSelectIgnitionCycles;
extern const std::string kSelectKilometers;
@@ -81,7 +83,9 @@ extern const std::string kInsertNickname;
extern const std::string kInsertAppType;
extern const std::string kInsertRequestType;
extern const std::string kInsertRequestSubType;
-extern const std::string kInsertHandledRpcs;
+extern const std::string kInsertAppServiceTypes;
+extern const std::string kInsertAppServiceNames;
+extern const std::string kInsertAppServiceHandledRpcs;
extern const std::string kInsertMessageType;
extern const std::string kInsertLanguage;
extern const std::string kInsertMessageString;
@@ -102,7 +106,9 @@ extern const std::string kDeleteAppGroup;
extern const std::string kDeleteApplication;
extern const std::string kDeleteRequestType;
extern const std::string kDeleteRequestSubType;
-extern const std::string kDeleteHandledRpcs;
+extern const std::string kDeleteAppServiceTypes;
+extern const std::string kDeleteAppServiceNames;
+extern const std::string kDeleteAppServiceHandledRpcs;
extern const std::string kDeleteDevice;
extern const std::string kIncrementIgnitionCycles;
extern const std::string kResetIgnitionCycles;
diff --git a/src/components/policy/policy_regular/include/policy/sql_pt_representation.h b/src/components/policy/policy_regular/include/policy/sql_pt_representation.h
index f3167d252a..dfa318454b 100644
--- a/src/components/policy/policy_regular/include/policy/sql_pt_representation.h
+++ b/src/components/policy/policy_regular/include/policy/sql_pt_representation.h
@@ -133,8 +133,10 @@ class SQLPTRepresentation : public virtual PTRepresentation {
bool GatherRequestSubType(
const std::string& app_id,
policy_table::RequestSubTypes* request_subtypes) const;
- bool GatherHandledRpcs(const std::string& app_id,
- policy_table::HandledRpcs* handled_rpcs) const;
+ bool GatherAppServiceParameters(
+ const std::string& app_id,
+ policy_table::AppServiceParameters* app_service_parameters) const;
+
bool GatherNickName(const std::string& app_id,
policy_table::Strings* nicknames) const;
@@ -173,8 +175,9 @@ class SQLPTRepresentation : public virtual PTRepresentation {
bool SaveRequestSubType(
const std::string& app_id,
const policy_table::RequestSubTypes& request_subtypes);
- bool SaveHandledRpcs(const std::string& app_id,
- const policy_table::HandledRpcs& handled_rpcs);
+ bool SaveAppServiceParameters(
+ const std::string& app_id,
+ const policy_table::AppServiceParameters& app_service_parameters);
public:
bool UpdateRequired() const;
diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc
index 9396534677..5abe4158f1 100644
--- a/src/components/policy/policy_regular/src/cache_manager.cc
+++ b/src/components/policy/policy_regular/src/cache_manager.cc
@@ -798,9 +798,7 @@ void CacheManager::SetHybridAppPreference(
void CacheManager::GetAppServiceParameters(
const std::string& policy_app_id,
- std::string& service_name,
- std::string& service_type,
- std::vector<uint32_t>& handled_rpcs) const {
+ policy_table::AppServiceParameters* app_service_parameters) const {
LOG4CXX_AUTO_TRACE(logger_);
const policy_table::ApplicationPolicies& policies =
pt_->policy_table.app_policies_section.apps;
@@ -808,17 +806,8 @@ void CacheManager::GetAppServiceParameters(
policies.find(policy_app_id);
if (policies.end() != policy_iter) {
auto app_policy = (*policy_iter).second;
- service_name = app_policy.service_name.is_initialized()
- ? *app_policy.service_name
- : std::string();
- service_type = app_policy.service_type.is_initialized()
- ? *app_policy.service_type
- : std::string();
- if (!app_policy.handled_rpcs.is_initialized()) {
- return;
- }
- for (const auto& rpc : *(app_policy.handled_rpcs)) {
- handled_rpcs.push_back(rpc);
+ if (app_policy.app_service_parameters.is_initialized()) {
+ *app_service_parameters = *(app_policy.app_service_parameters);
}
}
}
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 12dd322e6c..5f09d166b1 100644
--- a/src/components/policy/policy_regular/src/policy_manager_impl.cc
+++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc
@@ -593,11 +593,8 @@ void PolicyManagerImpl::SetHybridAppPreference(
void PolicyManagerImpl::GetAppServiceParameters(
const std::string& policy_app_id,
- std::string& service_name,
- std::string& service_type,
- std::vector<uint32_t>& handled_rpcs) const {
- cache_->GetAppServiceParameters(
- policy_app_id, service_name, service_type, handled_rpcs);
+ policy_table::AppServiceParameters* app_service_parameters) const {
+ cache_->GetAppServiceParameters(policy_app_id, app_service_parameters);
}
void PolicyManagerImpl::CheckPermissions(const PTString& device_id,
diff --git a/src/components/policy/policy_regular/src/policy_table/types.cc b/src/components/policy/policy_regular/src/policy_table/types.cc
index e28b260f5f..ed8b5c58ac 100644
--- a/src/components/policy/policy_regular/src/policy_table/types.cc
+++ b/src/components/policy/policy_regular/src/policy_table/types.cc
@@ -150,6 +150,65 @@ void ApplicationPoliciesSection::SetPolicyTableType(PolicyTableType pt_type) {
apps.SetPolicyTableType(pt_type);
}
+// AppServiceInfo methods
+AppServiceInfo::AppServiceInfo() : CompositeType(kUninitialized) {}
+
+AppServiceInfo::~AppServiceInfo() {}
+
+AppServiceInfo::AppServiceInfo(const Json::Value* value__)
+ : CompositeType(InitHelper(value__, &Json::Value::isObject))
+ , service_names(impl::ValueMember(value__, "service_names"))
+ , handled_rpcs(impl::ValueMember(value__, "handled_rpcs")) {
+} // todo handled_rpcs struct
+
+Json::Value AppServiceInfo::ToJsonValue() const {
+ Json::Value result__(Json::objectValue);
+ impl::WriteJsonField("service_names", service_names, &result__);
+ impl::WriteJsonField("parameters", handled_rpcs, &result__);
+ return result__;
+}
+
+bool AppServiceInfo::is_valid() const {
+ if (!service_names.is_valid()) {
+ return false;
+ }
+ if (!handled_rpcs.is_valid()) {
+ return false;
+ }
+ return Validate();
+}
+
+bool AppServiceInfo::is_initialized() const {
+ return (initialization_state__ != kUninitialized) || (!struct_empty());
+}
+
+bool AppServiceInfo::struct_empty() const {
+ if (service_names.is_initialized()) {
+ return false;
+ }
+ if (handled_rpcs.is_initialized()) {
+ return false;
+ }
+ return true;
+}
+
+void AppServiceInfo::SetPolicyTableType(PolicyTableType pt_type) {
+ service_names.SetPolicyTableType(pt_type);
+ handled_rpcs.SetPolicyTableType(pt_type);
+}
+
+void AppServiceInfo::ReportErrors(rpc::ValidationReport* report__) const {
+ if (struct_empty()) {
+ rpc::CompositeType::ReportErrors(report__);
+ }
+ if (!service_names.is_valid()) {
+ service_names.ReportErrors(&report__->ReportSubobject("service_names"));
+ }
+ if (!handled_rpcs.is_valid()) {
+ handled_rpcs.ReportErrors(&report__->ReportSubobject("handled_rpcs"));
+ }
+}
+
// ApplicationParams methods
ApplicationParams::ApplicationParams() : PolicyBase(), groups() {}
@@ -174,9 +233,8 @@ ApplicationParams::ApplicationParams(const Json::Value* value__)
, enabled(impl::ValueMember(value__, "enabled"))
, auth_token(impl::ValueMember(value__, "auth_token"))
, cloud_transport_type(impl::ValueMember(value__, "cloud_transport_type"))
- , service_name(impl::ValueMember(value__, "service_name"))
- , service_type(impl::ValueMember(value__, "service_type"))
- , handled_rpcs(impl::ValueMember(value__, "handled_rpcs")) {}
+ , app_service_parameters(
+ impl::ValueMember(value__, "app_service_parameters")) {}
Json::Value ApplicationParams::ToJsonValue() const {
Json::Value result__(PolicyBase::ToJsonValue());
@@ -196,9 +254,8 @@ Json::Value ApplicationParams::ToJsonValue() const {
impl::WriteJsonField("enabled", enabled, &result__);
impl::WriteJsonField("auth_token", auth_token, &result__);
impl::WriteJsonField("cloud_transport_type", cloud_transport_type, &result__);
- impl::WriteJsonField("service_name", service_name, &result__);
- impl::WriteJsonField("service_type", service_type, &result__);
- impl::WriteJsonField("handled_rpcs", handled_rpcs, &result__);
+ impl::WriteJsonField(
+ "app_service_parameters", app_service_parameters, &result__);
return result__;
}
@@ -245,13 +302,7 @@ bool ApplicationParams::is_valid() const {
if (!hybrid_app_preference.is_valid()) {
return false;
}
- if (!service_name.is_valid()) {
- return false;
- }
- if (!service_type.is_valid()) {
- return false;
- }
- if (!handled_rpcs.is_valid()) {
+ if (!app_service_parameters.is_valid()) {
return false;
}
return Validate();
@@ -307,13 +358,7 @@ bool ApplicationParams::struct_empty() const {
if (hybrid_app_preference.is_initialized()) {
return false;
}
- if (service_name.is_initialized()) {
- return false;
- }
- if (service_type.is_initialized()) {
- return false;
- }
- if (handled_rpcs.is_initialized()) {
+ if (app_service_parameters.is_initialized()) {
return false;
}
return true;
@@ -370,14 +415,9 @@ void ApplicationParams::ReportErrors(rpc::ValidationReport* report__) const {
moduleType.ReportErrors(
&report__->ReportSubobject("hybrid_app_preference"));
}
- if (!service_name.is_valid()) {
- service_name.ReportErrors(&report__->ReportSubobject("service_name"));
- }
- if (!service_type.is_valid()) {
- service_type.ReportErrors(&report__->ReportSubobject("service_type"));
- }
- if (!handled_rpcs.is_valid()) {
- handled_rpcs.ReportErrors(&report__->ReportSubobject("handled_rpcs"));
+ if (!app_service_parameters.is_valid()) {
+ app_service_parameters.ReportErrors(
+ &report__->ReportSubobject("app_service_parameters"));
}
}
@@ -395,9 +435,7 @@ void ApplicationParams::SetPolicyTableType(PolicyTableType pt_type) {
enabled.SetPolicyTableType(pt_type);
cloud_transport_type.SetPolicyTableType(pt_type);
hybrid_app_preference.SetPolicyTableType(pt_type);
- service_name.SetPolicyTableType(pt_type);
- service_type.SetPolicyTableType(pt_type);
- handled_rpcs.SetPolicyTableType(pt_type);
+ app_service_parameters.SetPolicyTableType(pt_type);
}
// RpcParameters methods
diff --git a/src/components/policy/policy_regular/src/policy_table/validation.cc b/src/components/policy/policy_regular/src/policy_table/validation.cc
index 714dfaae5a..6804b1266f 100644
--- a/src/components/policy/policy_regular/src/policy_table/validation.cc
+++ b/src/components/policy/policy_regular/src/policy_table/validation.cc
@@ -177,6 +177,10 @@ bool ApplicationParams::ValidateModuleTypes() const {
return true;
}
+bool AppServiceInfo::Validate() const {
+ return true; // todo add validation
+}
+
bool ApplicationParams::Validate() const {
return ValidateModuleTypes();
}
diff --git a/src/components/policy/policy_regular/src/sql_pt_queries.cc b/src/components/policy/policy_regular/src/sql_pt_queries.cc
index 9027863e22..b467ae824a 100644
--- a/src/components/policy/policy_regular/src/sql_pt_queries.cc
+++ b/src/components/policy/policy_regular/src/sql_pt_queries.cc
@@ -142,8 +142,6 @@ const std::string kCreateSchema =
" `enabled` BOOLEAN, "
" `auth_token` VARCHAR(65535), "
" `cloud_transport_type` VARCHAR(255), "
- " `service_name` VARCHAR(255), "
- " `service_type` VARCHAR(255), "
" `remote_control_denied` BOOLEAN NOT NULL DEFAULT 0, "
" CONSTRAINT `fk_application_hmi_level1` "
" FOREIGN KEY(`default_hmi`) "
@@ -289,14 +287,30 @@ const std::string kCreateSchema =
" FOREIGN KEY(`application_id`) "
" REFERENCES `application`(`id`) "
"); "
- "CREATE TABLE IF NOT EXISTS `handled_rpcs`( "
- " `handled_rpcs` INTEGER, "
+ "CREATE TABLE IF NOT EXISTS `app_service_types`( "
+ " `id` INTEGER PRIMARY KEY NOT NULL, "
+ " `service_type` VARCHAR(50), "
" `application_id` VARCHAR(45) NOT NULL COLLATE NOCASE, "
- " PRIMARY KEY(`handled_rpcs`,`application_id`), "
- " CONSTRAINT `fk_handled_rpcs_app_id` "
+ " CONSTRAINT `fk_service_type_app_id` "
" FOREIGN KEY(`application_id`) "
" REFERENCES `application`(`id`) "
"); "
+ "CREATE TABLE IF NOT EXISTS `app_service_names`( "
+ " `service_type_id` INTEGER NOT NULL, "
+ " `service_name` VARCHAR(45), "
+ " PRIMARY KEY(`service_name`,`service_type_id`), "
+ " CONSTRAINT `fk_service_name_service_type_id` "
+ " FOREIGN KEY(`service_type_id`) "
+ " REFERENCES `app_service_types`(`id`) "
+ "); "
+ "CREATE TABLE IF NOT EXISTS `app_service_handled_rpcs`( "
+ " `service_type_id` INTEGER NOT NULL, "
+ " `function_id` INTEGER, "
+ " PRIMARY KEY(`function_id`,`service_type_id`), "
+ " CONSTRAINT `fk_function_id_service_type_id` "
+ " FOREIGN KEY(`service_type_id`) "
+ " REFERENCES `app_service_types`(`id`) "
+ "); "
"CREATE INDEX IF NOT EXISTS `app_type.fk_app_type_application1_idx` "
" ON `app_type`(`application_id` COLLATE NOCASE); "
"CREATE TABLE IF NOT EXISTS `consent_group`( "
@@ -477,7 +491,9 @@ const std::string kDropSchema =
"DROP TABLE IF EXISTS `app_type`; "
"DROP TABLE IF EXISTS `request_type`; "
"DROP TABLE IF EXISTS `request_subtype`; "
- "DROP TABLE IF EXISTS `handled_rpcs`; "
+ "DROP TABLE IF EXISTS `app_service_types`; "
+ "DROP TABLE IF EXISTS `app_service_names`; "
+ "DROP TABLE IF EXISTS `app_service_handled_rpcs`; "
"DROP INDEX IF EXISTS `nickname.fk_nickname_application1_idx`; "
"DROP TABLE IF EXISTS `nickname`; "
"DROP INDEX IF EXISTS `app_level.fk_app_level_language2_idx`; "
@@ -609,8 +625,8 @@ const std::string kInsertApplication =
"INSERT OR IGNORE INTO `application` (`id`, `priority_value`, "
"`is_revoked`, `memory_kb`, `heart_beat_timeout_ms`, `certificate`, "
"`hybrid_app_preference_value`, `endpoint`, `enabled`, `auth_token`, "
- "`cloud_transport_type`, `service_name`, `service_type`) VALUES "
- "(?,?,?,?,?,?,?,?,?,?,?,?,?)";
+ "`cloud_transport_type`) VALUES "
+ "(?,?,?,?,?,?,?,?,?,?,?)";
const std::string kInsertAppGroup =
"INSERT INTO `app_group` (`application_id`, `functional_group_id`)"
@@ -631,9 +647,19 @@ const std::string kInsertRequestSubType =
"`request_subtype`) "
"VALUES (?, ?)";
-const std::string kInsertHandledRpcs =
- "INSERT INTO `handled_rpcs` (`application_id`, "
- "`handled_rpcs`) "
+const std::string kInsertAppServiceTypes =
+ "INSERT INTO `app_service_types` (`id`, "
+ "`service_type`, `application_id`) "
+ "VALUES (?, ?, ?)";
+
+const std::string kInsertAppServiceNames =
+ "INSERT INTO `app_service_names` (`service_type_id`, "
+ "`service_name`) "
+ "VALUES (?, ?)";
+
+const std::string kInsertAppServiceHandledRpcs =
+ "INSERT INTO `app_service_handled_rpcs` (`service_type_id`, "
+ "`function_id`) "
"VALUES (?, ?)";
const std::string kUpdateVersion = "UPDATE `version` SET `number`= ?";
@@ -725,8 +751,7 @@ const std::string kSelectUserMsgsVersion =
const std::string kSelectAppPolicies =
"SELECT `id`, `priority_value`, `memory_kb`, "
" `heart_beat_timeout_ms`, `certificate`, `hybrid_app_preference_value`, "
- " `endpoint`, `enabled`, `auth_token`, `cloud_transport_type`, "
- "`service_name`, `service_type` FROM "
+ " `endpoint`, `enabled`, `auth_token`, `cloud_transport_type` FROM "
" `application`";
const std::string kCollectFriendlyMsg = "SELECT * FROM `message`";
@@ -754,11 +779,21 @@ const std::string kSelectRequestSubTypes =
"`application_id` "
"= ?";
-const std::string kSelectHandledRpcs =
- "SELECT DISTINCT `handled_rpcs` FROM `handled_rpcs` WHERE "
+const std::string kSelectAppServiceTypes =
+ "SELECT `id`, `service_type`` FROM `app_service_types` WHERE "
"`application_id` "
"= ?";
+const std::string kSelectAppServiceNames =
+ "SELECT DISTINCT `service_name` FROM `app_service_names` WHERE "
+ "`service_type_id` "
+ "= ?";
+
+const std::string kSelectAppServiceHandledRpcs =
+ "SELECT DISTINCT `function_id` FROM `app_service_handled_rpcs` WHERE "
+ "`service_type_id` "
+ "= ?";
+
const std::string kSelectSecondsBetweenRetries =
"SELECT `value` FROM `seconds_between_retry` ORDER BY `index`";
@@ -806,7 +841,12 @@ const std::string kDeleteRequestType = "DELETE FROM `request_type`";
const std::string kDeleteRequestSubType = "DELETE FROM `request_subtype`";
-const std::string kDeleteHandledRpcs = "DELETE FROM `handled_rpcs`";
+const std::string kDeleteAppServiceTypes = "DELETE FROM `app_service_types`";
+
+const std::string kDeleteAppServiceNames = "DELETE FROM `app_service_names`";
+
+const std::string kDeleteAppServiceHandledRpcs =
+ "DELETE FROM `app_service_handled_rpcs`";
const std::string kSelectApplicationRevoked =
"SELECT `is_revoked` FROM `application` WHERE `id` = ?";
@@ -834,16 +874,14 @@ const std::string kInsertApplicationFull =
" `default_hmi`, `priority_value`, `is_revoked`, `is_default`, "
" `is_predata`, `memory_kb`, `heart_beat_timeout_ms`, "
" `certificate`, `hybrid_app_preference_value`, `endpoint`, `enabled`, "
- " `auth_token`, `cloud_transport_type`, `service_name`, "
- "`service_type`) "
- " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+ " `auth_token`, `cloud_transport_type`) "
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
const std::string kSelectApplicationFull =
"SELECT `keep_context`, `steal_focus`, `default_hmi`, `priority_value`, "
" `is_revoked`, `is_default`, `is_predata`, `memory_kb`,"
" `heart_beat_timeout_ms`, `certificate`, `hybrid_app_preference_value`, "
- " `endpoint`, `enabled`, `auth_token`, `cloud_transport_type`, "
- "`service_name`, `service_type` "
+ " `endpoint`, `enabled`, `auth_token`, `cloud_transport_type` "
"FROM `application` "
"WHERE `id` = "
"?";
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 4e144d4e69..6656bb3162 100644
--- a/src/components/policy/policy_regular/src/sql_pt_representation.cc
+++ b/src/components/policy/policy_regular/src/sql_pt_representation.cc
@@ -734,10 +734,6 @@ bool SQLPTRepresentation::GatherApplicationPoliciesSection(
*params.auth_token = query.GetString(8);
*params.cloud_transport_type = query.GetString(9);
- // AppService Parameters
- *params.service_name = query.GetString(10);
- *params.service_type = query.GetString(11);
-
const auto& gather_app_id = ((*policies).apps[app_id].is_string())
? (*policies).apps[app_id].get_string()
: app_id;
@@ -770,7 +766,8 @@ bool SQLPTRepresentation::GatherApplicationPoliciesSection(
return false;
}
- if (!GatherHandledRpcs(gather_app_id, &*params.handled_rpcs)) {
+ if (!GatherAppServiceParameters(gather_app_id,
+ &*params.app_service_parameters)) {
return false;
}
@@ -950,6 +947,21 @@ bool SQLPTRepresentation::SaveApplicationPoliciesSection(
return false;
}
+ if (!query_delete.Exec(sql_pt::kDeleteAppServiceHandledRpcs)) {
+ LOG4CXX_WARN(logger_, "Incorrect delete from handled rpcs.");
+ return false;
+ }
+
+ if (!query_delete.Exec(sql_pt::kDeleteAppServiceNames)) {
+ LOG4CXX_WARN(logger_, "Incorrect delete from service names.");
+ return false;
+ }
+
+ if (!query_delete.Exec(sql_pt::kDeleteAppServiceTypes)) {
+ LOG4CXX_WARN(logger_, "Incorrect delete from handled service types.");
+ return false;
+ }
+
// All predefined apps (e.g. default, pre_DataConsent) should be saved first,
// otherwise another app with the predefined permissions can get incorrect
// permissions
@@ -1019,12 +1031,6 @@ bool SQLPTRepresentation::SaveSpecificAppPolicy(
app.second.cloud_transport_type.is_initialized()
? app_query.Bind(10, *app.second.cloud_transport_type)
: app_query.Bind(10);
- app.second.service_name.is_initialized()
- ? app_query.Bind(11, *app.second.service_name)
- : app_query.Bind(11);
- app.second.service_type.is_initialized()
- ? app_query.Bind(12, *app.second.service_type)
- : app_query.Bind(12);
if (!app_query.Exec() || !app_query.Reset()) {
LOG4CXX_WARN(logger_, "Incorrect insert into application.");
@@ -1064,7 +1070,8 @@ bool SQLPTRepresentation::SaveSpecificAppPolicy(
return false;
}
- if (!SaveHandledRpcs(app.first, *app.second.handled_rpcs)) {
+ if (!SaveAppServiceParameters(app.first,
+ *app.second.app_service_parameters)) {
return false;
}
@@ -1227,25 +1234,66 @@ bool SQLPTRepresentation::SaveRequestSubType(
return true;
}
-bool SQLPTRepresentation::SaveHandledRpcs(
- const std::string& app_id, const policy_table::HandledRpcs& handled_rpcs) {
+bool SQLPTRepresentation::SaveAppServiceParameters(
+ const std::string& app_id,
+ const policy_table::AppServiceParameters& app_service_parameters) {
+ LOG4CXX_INFO(logger_, "Save app service parameters");
utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt::kInsertHandledRpcs)) {
- LOG4CXX_WARN(logger_, "Incorrect insert statement for handled rpcs.");
+
+ if (!query.Prepare(sql_pt::kInsertAppServiceTypes)) {
+ LOG4CXX_WARN(logger_, "Incorrect insert statement for app service types");
return false;
}
+ policy_table::AppServiceParameters::const_iterator it;
+ for (it = app_service_parameters.begin(); it != app_service_parameters.end();
+ ++it) {
+ // Create service type id from hashing app_id and service_type
+ std::string str_to_hash = std::string(app_id + it->first);
+ const long int id = abs(CacheManager::GenerateHash(str_to_hash));
+ query.Bind(0, static_cast<int64_t>(id));
+ query.Bind(1, it->first);
+ query.Bind(2, app_id);
+ if (!query.Exec() || !query.Reset()) {
+ LOG4CXX_WARN(logger_, "Insert execute failed for into app service types");
+ return false;
+ }
- policy_table::HandledRpcs::const_iterator it;
- if (!handled_rpcs.empty()) {
- LOG4CXX_TRACE(logger_, "Handled Rpcs are not empty.");
- for (it = handled_rpcs.begin(); it != handled_rpcs.end(); ++it) {
- query.Bind(0, app_id);
+ // Insert app names array into db
+ utils::dbms::SQLQuery service_name_query(db());
+ if (!service_name_query.Prepare(sql_pt::kInsertAppServiceNames)) {
+ LOG4CXX_WARN(logger_, "Incorrect insert statement for app service names");
+ return false;
+ }
- // TODO: Bind does not like uint64_t. Only takes ints? Not sure why this
- // is broken since seconds between retries is able to handle
- query.Bind(1, static_cast<int>(*it));
- if (!query.Exec() || !query.Reset()) {
- LOG4CXX_WARN(logger_, "Incorrect insert into handled rpcs.");
+ 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) {
+ 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
+ utils::dbms::SQLQuery handled_rpcs_query(db());
+ if (!handled_rpcs_query.Prepare(sql_pt::kInsertAppServiceHandledRpcs)) {
+ LOG4CXX_WARN(logger_,
+ "Incorrect insert statement for app service handled rpcs");
+ return false;
+ }
+
+ 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();
+ ++rpc_it) {
+ handled_rpcs_query.Bind(0, static_cast<int64_t>(id));
+ handled_rpcs_query.Bind(1, static_cast<int64_t>(*rpc_it));
+ if (!handled_rpcs_query.Exec() || !handled_rpcs_query.Reset()) {
+ LOG4CXX_WARN(logger_, "Incorrect insert into app service handled rpcs");
return false;
}
}
@@ -1691,19 +1739,50 @@ bool SQLPTRepresentation::GatherRequestSubType(
return true;
}
-bool SQLPTRepresentation::GatherHandledRpcs(
- const std::string& app_id, policy_table::HandledRpcs* handled_rpcs) const {
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt::kSelectHandledRpcs)) {
- LOG4CXX_WARN(logger_, "Incorrect select from handled rpcs.");
+bool SQLPTRepresentation::GatherAppServiceParameters(
+ const std::string& app_id,
+ policy_table::AppServiceParameters* app_service_parameters) const {
+ LOG4CXX_INFO(logger_, "Gather app service info");
+ utils::dbms::SQLQuery service_type_query(db());
+ if (!service_type_query.Prepare(sql_pt::kSelectAppServiceTypes)) {
+ LOG4CXX_WARN(logger_, "Incorrect select from service_types");
return false;
}
- query.Bind(0, app_id);
- while (query.Next()) {
- const uint64_t rpc_id = query.GetInteger(0);
- handled_rpcs->push_back(rpc_id);
+ utils::dbms::SQLQuery service_name_query(db());
+ if (!service_name_query.Prepare(sql_pt::kSelectAppServiceNames)) {
+ LOG4CXX_WARN(logger_, "Incorrect select all from app_service_names");
+ return false;
}
+
+ utils::dbms::SQLQuery handled_rpcs_query(db());
+ if (!handled_rpcs_query.Prepare(sql_pt::kSelectAppServiceHandledRpcs)) {
+ LOG4CXX_WARN(logger_, "Incorrect select all from app_service_handled_rpcs");
+ return false;
+ }
+
+ service_type_query.Bind(2, app_id);
+ while (service_type_query.Next()) {
+ const int service_type_id = service_type_query.GetInteger(0);
+ std::string service_type = service_type_query.GetString(1);
+ (*app_service_parameters)[service_type] = policy_table::AppServiceInfo();
+
+ service_name_query.Bind(0, service_type_id);
+ while (service_name_query.Next()) {
+ (*app_service_parameters)[service_type].service_names->push_back(
+ service_name_query.GetString(0));
+ }
+
+ handled_rpcs_query.Bind(0, service_type_id);
+ while (handled_rpcs_query.Next()) {
+ (*app_service_parameters)[service_type].handled_rpcs->push_back(
+ handled_rpcs_query.GetInteger(0));
+ }
+
+ service_name_query.Reset();
+ handled_rpcs_query.Reset();
+ }
+
return true;
}
@@ -2058,8 +2137,8 @@ bool SQLPTRepresentation::SetDefaultPolicy(const std::string& app_id) {
}
policy_table::HandledRpcs handled_rpcs;
- if (!GatherHandledRpcs(kDefaultId, &handled_rpcs) ||
- !SaveHandledRpcs(app_id, handled_rpcs)) {
+ if (!GatherAppServiceParameters(kDefaultId, &handled_rpcs) ||
+ !SaveAppServiceParameters(app_id, handled_rpcs)) {
return false;
}