diff options
Diffstat (limited to 'src/components/policy/policy_external/src/sql_pt_representation.cc')
-rw-r--r-- | src/components/policy/policy_external/src/sql_pt_representation.cc | 379 |
1 files changed, 377 insertions, 2 deletions
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 1732f3c774..1960fb6e03 100644 --- a/src/components/policy/policy_external/src/sql_pt_representation.cc +++ b/src/components/policy/policy_external/src/sql_pt_representation.cc @@ -552,6 +552,12 @@ void SQLPTRepresentation::GatherModuleConfig( *config->vehicle_year = query.GetString(7); *config->preloaded_date = query.GetString(8); *config->certificate = query.GetString(9); +#ifdef SDL_REMOTE_CONTROL + *config->user_consent_passengersRC = + query.IsNull(8) ? true : query.GetBoolean(10); + *config->country_consent_passengersRC = + query.IsNull(9) ? true : query.GetBoolean(11); +#endif // SDL_REMOTE_CONTROL } utils::dbms::SQLQuery endpoints(db()); @@ -764,6 +770,25 @@ bool SQLPTRepresentation::GatherApplicationPoliciesSection( if (!GatherAppGroup(app_id, ¶ms.groups)) { return false; } + +#ifdef SDL_REMOTE_CONTROL + if (!GatherAppGroupPrimary(app_id, &*params.groups_primaryRC)) { + return false; + } + if (!GatherAppGroupNonPrimary(app_id, &*params.groups_nonPrimaryRC)) { + return false; + } + bool denied = false; + if (!GatherRemoteControlDenied(app_id, &denied)) { + return false; + } + if (!denied) { + if (!GatherModuleType(app_id, &*params.moduleType)) { + return false; + } + } +#endif // SDL_REMOTE_CONTROL + if (!GatherNickName(app_id, &*params.nicknames)) { return false; } @@ -953,6 +978,22 @@ bool SQLPTRepresentation::SaveApplicationPoliciesSection( LOG4CXX_WARN(logger_, "Incorrect delete from app_group."); return false; } + +#ifdef SDL_REMOTE_CONTROL + if (!query_delete.Exec(sql_pt::kDeleteAppGroupPrimary)) { + LOG4CXX_WARN(logger_, "Incorrect delete from app_group_primary."); + return false; + } + if (!query_delete.Exec(sql_pt::kDeleteAppGroupNonPrimary)) { + LOG4CXX_WARN(logger_, "Incorrect delete from app_group_non_primary."); + return false; + } + if (!query_delete.Exec(sql_pt::kDeleteModuleTypes)) { + LOG4CXX_WARN(logger_, "Incorrect delete from module_type."); + return false; + } +#endif // SDL_REMOTE_CONTROL + if (!query_delete.Exec(sql_pt::kDeleteApplication)) { LOG4CXX_WARN(logger_, "Incorrect delete from application."); return false; @@ -1033,6 +1074,22 @@ bool SQLPTRepresentation::SaveSpecificAppPolicy( if (!SaveAppGroup(app.first, app.second.groups)) { return false; } + +#ifdef SDL_REMOTE_CONTROL + if (!SaveAppGroupPrimary(app.first, *app.second.groups_primaryRC)) { + return false; + } + if (!SaveAppGroupNonPrimary(app.first, *app.second.groups_nonPrimaryRC)) { + return false; + } + + bool denied = !app.second.moduleType->is_initialized(); + if (!SaveRemoteControlDenied(app.first, denied) || + !SaveModuleType(app.first, *app.second.moduleType)) { + return false; + } +#endif // SDL_REMOTE_CONTROL + if (!SaveNickname(app.first, *app.second.nicknames)) { return false; } @@ -1195,6 +1252,14 @@ bool SQLPTRepresentation::SaveModuleConfig( : query.Bind(8); config.certificate.is_initialized() ? query.Bind(9, *(config.certificate)) : query.Bind(9); +#ifdef SDL_REMOTE_CONTROL + config.user_consent_passengersRC.is_initialized() + ? query.Bind(10, *(config.user_consent_passengersRC)) + : query.Bind(10); + config.country_consent_passengersRC.is_initialized() + ? query.Bind(11, *(config.country_consent_passengersRC)) + : query.Bind(11); +#endif // SDL_REMOTE_CONTROL if (!query.Exec()) { LOG4CXX_WARN(logger_, "Incorrect update module config"); @@ -1596,6 +1661,280 @@ bool SQLPTRepresentation::GatherAppGroup( return true; } +#ifdef SDL_REMOTE_CONTROL +bool SQLPTRepresentation::GatherAppGroupPrimary( + const std::string& app_id, policy_table::Strings* app_groups) const { + dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kSelectAppGroupsPrimary)) { + LOG4CXX_WARN(logger_, "Incorrect select from app groups for primary RC"); + return false; + } + + query.Bind(0, app_id); + while (query.Next()) { + app_groups->push_back(query.GetString(0)); + } + return true; +} + +bool SQLPTRepresentation::GatherAppGroupNonPrimary( + const std::string& app_id, policy_table::Strings* app_groups) const { + dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kSelectAppGroupsNonPrimary)) { + LOG4CXX_WARN(logger_, + "Incorrect select from app groups for non primary RC"); + return false; + } + + query.Bind(0, app_id); + while (query.Next()) { + app_groups->push_back(query.GetString(0)); + } + return true; +} + +bool SQLPTRepresentation::GatherRemoteControlDenied(const std::string& app_id, + bool* denied) const { + LOG4CXX_AUTO_TRACE(logger_); + dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kSelectRemoteControlDenied)) { + LOG4CXX_WARN(logger_, "Incorrect select remote control flag"); + return false; + } + query.Bind(0, app_id); + if (query.Next()) { + *denied = query.GetBoolean(0); + } else { + return false; + } + return true; +} + +bool SQLPTRepresentation::GatherModuleType( + const std::string& app_id, policy_table::ModuleTypes* app_types) const { + dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kSelectModuleTypes)) { + LOG4CXX_WARN(logger_, "Incorrect select from app types"); + return false; + } + + query.Bind(0, app_id); + while (query.Next()) { + policy_table::ModuleType type; + if (!policy_table::EnumFromJsonString(query.GetString(0), &type)) { + return false; + } + app_types->push_back(type); + } + return true; +} + +bool SQLPTRepresentation::SaveAppGroupPrimary( + const std::string& app_id, const policy_table::Strings& app_groups) { + LOG4CXX_AUTO_TRACE(logger_); + dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kInsertAppGroupPrimary)) { + LOG4CXX_WARN(logger_, "Incorrect insert statement for app group primary"); + return false; + } + policy_table::Strings::const_iterator it; + for (it = app_groups.begin(); it != app_groups.end(); ++it) { + std::string ssss = *it; + LOG4CXX_INFO(logger_, "Group: " << ssss); + query.Bind(0, app_id); + query.Bind(1, *it); + if (!query.Exec() || !query.Reset()) { + LOG4CXX_WARN(logger_, + "Incorrect insert into app group primary." + << query.LastError().text()); + return false; + } + } + + return true; +} + +bool SQLPTRepresentation::SaveAppGroupNonPrimary( + const std::string& app_id, const policy_table::Strings& app_groups) { + LOG4CXX_AUTO_TRACE(logger_); + dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kInsertAppGroupNonPrimary)) { + LOG4CXX_WARN(logger_, + "Incorrect insert statement for app group non primary"); + return false; + } + policy_table::Strings::const_iterator it; + for (it = app_groups.begin(); it != app_groups.end(); ++it) { + std::string ssss = *it; + LOG4CXX_INFO(logger_, "Group: " << ssss); + query.Bind(0, app_id); + query.Bind(1, *it); + if (!query.Exec() || !query.Reset()) { + LOG4CXX_WARN(logger_, + "Incorrect insert into app group non primary." + << query.LastError().text()); + return false; + } + } + + return true; +} + +bool SQLPTRepresentation::SaveRemoteControlDenied(const std::string& app_id, + bool deny) { + LOG4CXX_AUTO_TRACE(logger_); + dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kUpdateRemoteControlDenied)) { + LOG4CXX_WARN(logger_, "Incorrect update statement for remote control flag"); + return false; + } + LOG4CXX_DEBUG(logger_, "App: " << app_id << std::boolalpha << " - " << deny); + query.Bind(0, deny); + query.Bind(1, app_id); + if (!query.Exec()) { + LOG4CXX_WARN(logger_, "Incorrect update remote control flag."); + return false; + } + return true; +} + +bool SQLPTRepresentation::SaveModuleType( + const std::string& app_id, const policy_table::ModuleTypes& types) { + dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kInsertModuleType)) { + LOG4CXX_WARN(logger_, "Incorrect insert statement for module type"); + return false; + } + + policy_table::ModuleTypes::const_iterator it; + for (it = types.begin(); it != types.end(); ++it) { + query.Bind(0, app_id); + std::string module(policy_table::EnumToJsonString(*it)); + query.Bind(1, module); + LOG4CXX_DEBUG(logger_, + "Module(app: " << app_id << ", type: " << module << ")"); + if (!query.Exec() || !query.Reset()) { + LOG4CXX_WARN(logger_, "Incorrect insert into module type."); + return false; + } + } + + return true; +} + +bool SQLPTRepresentation::SaveAccessModule( + TypeAccess access, const policy_table::AccessModules& modules) { + LOG4CXX_AUTO_TRACE(logger_); + dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kInsertAccessModule)) { + LOG4CXX_WARN(logger_, "Incorrect insert statement for access module"); + return false; + } + + policy_table::AccessModules::const_iterator i; + for (i = modules.begin(); i != modules.end(); ++i) { + const std::string& name = i->first; + const policy_table::RemoteRpcs& rpcs = i->second; + query.Bind(0, name); + query.Bind(1, access); + if (!query.Exec()) { + LOG4CXX_WARN(logger_, "Incorrect insert into access module."); + return false; + } + int id = query.LastInsertId(); + if (!query.Reset()) { + LOG4CXX_WARN(logger_, "Couldn't reset query access module."); + return false; + } + if (!SaveRemoteRpc(id, rpcs)) { + return false; + } + } + return true; +} + +bool SQLPTRepresentation::GatherAccessModule( + TypeAccess access, policy_table::AccessModules* modules) const { + LOG4CXX_AUTO_TRACE(logger_); + dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kSelectAccessModules)) { + LOG4CXX_WARN(logger_, "Incorrect select from access module"); + return false; + } + + query.Bind(0, access); + while (query.Next()) { + int id = query.GetInteger(0); + std::string name = query.GetString(1); + policy_table::RemoteRpcs rpcs; + if (!GatherRemoteRpc(id, &rpcs)) { + return false; + } + modules->insert(std::make_pair(name, rpcs)); + } + return true; +} + +bool SQLPTRepresentation::SaveRemoteRpc(int module_id, + const policy_table::RemoteRpcs& rpcs) { + LOG4CXX_AUTO_TRACE(logger_); + dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kInsertRemoteRpc)) { + LOG4CXX_WARN(logger_, "Incorrect insert statement for remote rpc"); + return false; + } + policy_table::RemoteRpcs::const_iterator i; + for (i = rpcs.begin(); i != rpcs.end(); ++i) { + const std::string& name = i->first; + const policy_table::Strings& params = i->second; + policy_table::Strings::const_iterator j; + if (params.empty()) { + query.Bind(0, module_id); + query.Bind(1, name); + query.Bind(2); + if (!query.Exec() || !query.Reset()) { + LOG4CXX_WARN(logger_, "Incorrect insert into remote rpc."); + return false; + } + } else { + for (j = params.begin(); j != params.end(); ++j) { + const std::string& param = *j; + query.Bind(0, module_id); + query.Bind(1, name); + query.Bind(2, param); + if (!query.Exec() || !query.Reset()) { + LOG4CXX_WARN(logger_, "Incorrect insert into remote rpc."); + return false; + } + } + } + } + return true; +} + +bool SQLPTRepresentation::GatherRemoteRpc( + int module_id, policy_table::RemoteRpcs* rpcs) const { + LOG4CXX_AUTO_TRACE(logger_); + dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kSelectRemoteRpcs)) { + LOG4CXX_WARN(logger_, "Incorrect select from remote rpc"); + return false; + } + + query.Bind(0, module_id); + while (query.Next()) { + std::string name = query.GetString(0); + if (!query.IsNull(1)) { + std::string parameter = query.GetString(1); + (*rpcs)[name].push_back(parameter); + } else { + rpcs->insert(std::make_pair(name, policy_table::Strings())); + } + } + return true; +} +#endif // SDL_REMOTE_CONTROL + bool SQLPTRepresentation::SaveApplicationCustomData(const std::string& app_id, bool is_revoked, bool is_default, @@ -1681,6 +2020,32 @@ bool SQLPTRepresentation::SetDefaultPolicy(const std::string& app_id) { return false; } +#ifdef SDL_REMOTE_CONTROL + dbms::SQLQuery query_p(db()); + if (!query_p.Prepare(sql_pt::kDeleteAppGroupPrimaryByApplicationId)) { + LOG4CXX_ERROR(logger_, + "Incorrect statement to delete from app_group_primary."); + return false; + } + query_p.Bind(0, app_id); + if (!query_p.Exec()) { + LOG4CXX_ERROR(logger_, "Failed deleting from app_group_primary."); + return false; + } + + dbms::SQLQuery query_np(db()); + if (!query_np.Prepare(sql_pt::kDeleteAppGroupNonPrimaryByApplicationId)) { + LOG4CXX_ERROR(logger_, + "Incorrect statement to delete from app_group_non_primary."); + return false; + } + query_np.Bind(0, app_id); + if (!query_np.Exec()) { + LOG4CXX_ERROR(logger_, "Failed deleting from app_group_non_primary."); + return false; + } +#endif // SDL_REMOTE_CONTROL + if (!CopyApplication(kDefaultId, app_id)) { return false; } @@ -1699,8 +2064,18 @@ bool SQLPTRepresentation::SetDefaultPolicy(const std::string& app_id) { } policy_table::Strings default_groups; - if (GatherAppGroup(kDefaultId, &default_groups) && - SaveAppGroup(app_id, default_groups)) { + bool ret = (GatherAppGroup(kDefaultId, &default_groups) && + SaveAppGroup(app_id, default_groups)); +#ifdef SDL_REMOTE_CONTROL + policy_table::Strings groups_primary; + ret = ret && (GatherAppGroupPrimary(kDefaultId, &groups_primary) && + SaveAppGroupPrimary(app_id, groups_primary)); + policy_table::Strings groups_non_primary; + ret = ret && (GatherAppGroupNonPrimary(kDefaultId, &groups_non_primary) && + SaveAppGroupNonPrimary(app_id, groups_non_primary)); +#endif // SDL_REMOTE_CONTROL + + if (ret) { return SetIsDefault(app_id, true); } return false; |