summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Keeler <jacob.keeler@livioradio.com>2019-04-29 10:08:03 -0400
committerGitHub <noreply@github.com>2019-04-29 10:08:03 -0400
commit05016a055abfd7e52ab3dd1ab2ae33b337c989f7 (patch)
tree015a899c5dc847319b0ae549007e77b4324a0a2d
parent7e62579567d389cfe2b39d0e32e42f5f98580069 (diff)
parente134f54fb755e31711306c491a988894cc71afd5 (diff)
downloadsdl_core-05016a055abfd7e52ab3dd1ab2ae33b337c989f7.tar.gz
Merge pull request #2898 from smartdevicelink/hotfix/reject_duplicate_service_names
Add check for duplicate service names
-rw-r--r--src/components/application_manager/include/application_manager/app_service_manager.h1
-rw-r--r--src/components/application_manager/src/app_service_manager.cc36
-rw-r--r--src/components/application_manager/test/app_service_manager_test.cc9
3 files changed, 32 insertions, 14 deletions
diff --git a/src/components/application_manager/include/application_manager/app_service_manager.h b/src/components/application_manager/include/application_manager/app_service_manager.h
index 4c661cae0a..5080748f17 100644
--- a/src/components/application_manager/include/application_manager/app_service_manager.h
+++ b/src/components/application_manager/include/application_manager/app_service_manager.h
@@ -257,6 +257,7 @@ class AppServiceManager {
*/
AppService* FindServiceByProvider(const uint32_t connection_key,
const std::string service_type);
+ AppService* FindServiceByName(std::string name);
std::string GetPolicyAppID(AppService service);
};
diff --git a/src/components/application_manager/src/app_service_manager.cc b/src/components/application_manager/src/app_service_manager.cc
index e2ec1d7dd4..bab8147d9f 100644
--- a/src/components/application_manager/src/app_service_manager.cc
+++ b/src/components/application_manager/src/app_service_manager.cc
@@ -72,11 +72,15 @@ smart_objects::SmartObject AppServiceManager::PublishAppService(
std::string service_type = manifest[strings::service_type].asString();
- AppService* existing_service =
- FindServiceByProvider(connection_key, service_type);
- if (existing_service) {
- LOG4CXX_DEBUG(logger_,
- "Service already exists for this provider, rejecting");
+ if (FindServiceByProvider(connection_key, service_type)) {
+ LOG4CXX_WARN(logger_,
+ "Service already exists for this provider, rejecting");
+ return smart_objects::SmartObject();
+ }
+
+ if (manifest.keyExists(strings::service_name) &&
+ FindServiceByName(manifest[strings::service_name].asString())) {
+ LOG4CXX_WARN(logger_, "A service already exists with this name, rejecting");
return smart_objects::SmartObject();
}
@@ -468,13 +472,23 @@ AppService* AppServiceManager::FindServiceByProvider(
const uint32_t connection_key, const std::string service_type) {
LOG4CXX_AUTO_TRACE(logger_);
sync_primitives::AutoLock lock(published_services_lock_);
-
- for (auto it = published_services_.begin(); it != published_services_.end();
- ++it) {
- if (it->second.connection_key == connection_key &&
- it->second.record[strings::service_manifest][strings::service_type]
+ for (auto& service : published_services_) {
+ if (service.second.connection_key == connection_key &&
+ service.second.record[strings::service_manifest][strings::service_type]
.asString() == service_type) {
- return &(it->second);
+ return &(service.second);
+ }
+ }
+ return NULL;
+}
+
+AppService* AppServiceManager::FindServiceByName(std::string name) {
+ LOG4CXX_AUTO_TRACE(logger_);
+ sync_primitives::AutoLock lock(published_services_lock_);
+ for (auto& service : published_services_) {
+ if (service.second.record[strings::service_manifest][strings::service_name]
+ .asString() == name) {
+ return &(service.second);
}
}
return NULL;
diff --git a/src/components/application_manager/test/app_service_manager_test.cc b/src/components/application_manager/test/app_service_manager_test.cc
index 960e8e31f6..526bbbdb7d 100644
--- a/src/components/application_manager/test/app_service_manager_test.cc
+++ b/src/components/application_manager/test/app_service_manager_test.cc
@@ -120,8 +120,11 @@ class AppServiceManagerTest : public testing::Test {
}
smart_objects::SmartObject PublishService(
- uint32_t connection_key = kConnectionKey, bool first_run = true) {
- smart_objects::SmartObject manifest = GenerateMediaManifest(true);
+ uint32_t connection_key = kConnectionKey,
+ std::string service_name = kServiceName,
+ bool first_run = true) {
+ smart_objects::SmartObject manifest =
+ GenerateMediaManifest(true, service_name);
Json::Value empty_json;
EXPECT_CALL(mock_last_state_, get_dictionary())
@@ -326,7 +329,7 @@ TEST_F(AppServiceManagerTest, ActivateAppService_TwoApps_SUCCESS) {
// Register two services with the same service type, the first is activated
// automatically
auto record = PublishService();
- auto record2 = PublishService(kConnectionKey + 1, false);
+ auto record2 = PublishService(kConnectionKey + 1, kServiceName + "2", false);
// No capability update
smart_objects::SmartObject syscap_update_activated;