diff options
author | jacobkeeler <jacob.keeler@livioradio.com> | 2019-02-25 11:33:34 -0500 |
---|---|---|
committer | jacobkeeler <jacob.keeler@livioradio.com> | 2019-02-26 10:41:15 -0500 |
commit | 146aa7a46a540cfd85a30f82bcec2783c9801ba7 (patch) | |
tree | 395136f7d4cf245c65d00b97e435e8fd41371376 | |
parent | 1f4a99fa5c7f8ad10645dc4c1a76469b83d53011 (diff) | |
download | sdl_core-146aa7a46a540cfd85a30f82bcec2783c9801ba7.tar.gz |
Add auth_token to StartServiceACK for cloud apps
21 files changed, 216 insertions, 19 deletions
diff --git a/src/appMain/life_cycle_impl.cc b/src/appMain/life_cycle_impl.cc index b87191d937..efc627f33a 100644 --- a/src/appMain/life_cycle_impl.cc +++ b/src/appMain/life_cycle_impl.cc @@ -111,6 +111,7 @@ bool LifeCycleImpl::StartComponents() { media_manager_ = new media_manager::MediaManagerImpl(*app_manager_, profile_); app_manager_->set_connection_handler(connection_handler_); + app_manager_->AddPolicyObserver(protocol_handler_); if (!app_manager_->Init(*last_state_, media_manager_)) { LOG4CXX_ERROR(logger_, "Application manager init failed."); return false; @@ -134,7 +135,6 @@ bool LifeCycleImpl::StartComponents() { security_manager_->AddListener(app_manager_); app_manager_->AddPolicyObserver(security_manager_); - app_manager_->AddPolicyObserver(protocol_handler_); if (!crypto_manager_->Init()) { LOG4CXX_ERROR(logger_, "CryptoManager initialization fail."); return false; 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 8ee5ff64f6..1cc5fc0156 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 @@ -455,6 +455,9 @@ class PolicyHandler : public PolicyHandlerInterface, #ifdef EXTERNAL_PROPRIETARY_MODE void OnCertificateDecrypted(bool is_succeeded) OVERRIDE; #endif // EXTERNAL_PROPRIETARY_MODE + void OnAuthTokenUpdated(const std::string& policy_app_id, + const std::string& auth_token); + virtual bool CanUpdate() OVERRIDE; virtual void OnDeviceConsentChanged(const std::string& device_id, diff --git a/src/components/application_manager/include/application_manager/policies/regular/policy_handler_observer.h b/src/components/application_manager/include/application_manager/policies/regular/policy_handler_observer.h index 07d234f036..68e7511b43 100644 --- a/src/components/application_manager/include/application_manager/policies/regular/policy_handler_observer.h +++ b/src/components/application_manager/include/application_manager/policies/regular/policy_handler_observer.h @@ -48,6 +48,9 @@ class PolicyHandlerObserver { return false; } + virtual void OnAuthTokenUpdated(const std::string& policy_app_id, + const std::string& auth_token) {} + virtual void OnPTUFinished(const bool ptu_result) {} virtual ~PolicyHandlerObserver() {} diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index 3be3ef0da7..02b848d9c6 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -1771,6 +1771,17 @@ void PolicyHandler::OnCertificateUpdated(const std::string& certificate_data) { } #endif // EXTERNAL_PROPRIETARY_MODE +void PolicyHandler::OnAuthTokenUpdated(const std::string& policy_app_id, + const std::string& auth_token) { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(listeners_lock_); + HandlersCollection::const_iterator it = listeners_.begin(); + for (; it != listeners_.end(); ++it) { + PolicyHandlerObserver* observer = *it; + observer->OnAuthTokenUpdated(policy_app_id, auth_token); + } +} + void PolicyHandler::OnPTUFinished(const bool ptu_result) { LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock lock(listeners_lock_); @@ -1909,15 +1920,18 @@ void PolicyHandler::OnSetCloudAppProperties( policy_manager_->InitCloudApp(policy_app_id); + bool auth_token_update = false; if (msg_params.keyExists(strings::enabled)) { - policy_manager_->SetCloudAppEnabled(policy_app_id, - msg_params[strings::enabled].asBool()); - + bool enabled = msg_params[strings::enabled].asBool(); + policy_manager_->SetCloudAppEnabled(policy_app_id, enabled); + auth_token_update = enabled; application_manager_.RefreshCloudAppInformation(); } if (msg_params.keyExists(strings::cloud_app_auth_token)) { - policy_manager_->SetAppAuthToken( - policy_app_id, msg_params[strings::cloud_app_auth_token].asString()); + std::string auth_token = + msg_params[strings::cloud_app_auth_token].asString(); + policy_manager_->SetAppAuthToken(policy_app_id, auth_token); + auth_token_update = true; } if (msg_params.keyExists(strings::cloud_transport_type)) { policy_manager_->SetAppCloudTransportType( @@ -1935,6 +1949,16 @@ void PolicyHandler::OnSetCloudAppProperties( policy_manager_->SetHybridAppPreference(policy_app_id, hybrid_app_preference); } + + if (auth_token_update) { + bool enabled; + std::string end, cert, ctt, hap; + std::string auth_token; + + policy_manager_->GetCloudAppParameters( + policy_app_id, enabled, end, cert, auth_token, ctt, hap); + OnAuthTokenUpdated(policy_app_id, auth_token); + } } uint32_t PolicyHandler::HeartBeatTimeout(const std::string& app_id) const { diff --git a/src/components/connection_handler/include/connection_handler/connection_handler_impl.h b/src/components/connection_handler/include/connection_handler/connection_handler_impl.h index e9e7ba47a3..16a3190315 100644 --- a/src/components/connection_handler/include/connection_handler/connection_handler_impl.h +++ b/src/components/connection_handler/include/connection_handler/connection_handler_impl.h @@ -378,6 +378,15 @@ class ConnectionHandlerImpl const protocol_handler::ServiceType& service_type) const OVERRIDE; /** + * @brief Get cloud app id by connection id + * @param connection_id unique connection id + * @return the policy app id of the cloud app if the connection is tied to a + * cloud app, an empty string otherwise. + */ + std::string GetCloudAppID( + const transport_manager::ConnectionUID connection_id) const OVERRIDE; + + /** * \brief Get device handle by mac address * \param mac_address uniq address * \param device_handle @@ -655,6 +664,12 @@ class ConnectionHandlerImpl std::map<uint32_t, protocol_handler::SessionContext> start_service_context_map_; + // Map app id -> (cloud_app_endpoint, connection_uid) + mutable sync_primitives::Lock cloud_app_id_map_lock_; + std::map<std::string, + std::pair<std::string, transport_manager::ConnectionUID> > + cloud_app_id_map_; + /** * @brief connection object as it's being closed */ diff --git a/src/components/connection_handler/src/connection_handler_impl.cc b/src/components/connection_handler/src/connection_handler_impl.cc index 41d6e1dd54..8afc3e885f 100644 --- a/src/components/connection_handler/src/connection_handler_impl.cc +++ b/src/components/connection_handler/src/connection_handler_impl.cc @@ -270,6 +270,17 @@ void ConnectionHandlerImpl::OnConnectionPending( LOG4CXX_DEBUG(logger_, "Add Pending Connection #" << connection_id << " to the list."); + std::string endpoint = device_info.mac_address(); + cloud_app_id_map_lock_.Acquire(); + for (auto it = cloud_app_id_map_.begin(); it != cloud_app_id_map_.end(); + ++it) { + if (endpoint == it->second.first) { + it->second.second = connection_id; + break; + } + } + cloud_app_id_map_lock_.Release(); + sync_primitives::AutoWriteLock lock(connection_list_lock_); if (connection_list_.find(connection_id) == connection_list_.end()) { Connection* connection = @@ -1111,6 +1122,18 @@ const uint8_t ConnectionHandlerImpl::GetSessionIdFromSecondaryTransport( return 0; } +std::string ConnectionHandlerImpl::GetCloudAppID( + const transport_manager::ConnectionUID connection_id) const { + sync_primitives::AutoLock auto_lock(cloud_app_id_map_lock_); + for (auto it = cloud_app_id_map_.begin(); it != cloud_app_id_map_.end(); + ++it) { + if (connection_id == it->second.second) { + return it->first; + } + } + return std::string(); +} + struct CompareMAC { explicit CompareMAC(const std::string& mac) : mac_(mac) {} bool operator()(const DeviceMap::value_type& device) { @@ -1330,6 +1353,9 @@ void ConnectionHandlerImpl::AddCloudAppDevice( const std::string& policy_app_id, const std::string& endpoint, const std::string& cloud_transport_type) { + cloud_app_id_map_lock_.Acquire(); + cloud_app_id_map_[policy_app_id] = std::make_pair(endpoint, 0); + cloud_app_id_map_lock_.Release(); transport_manager_.AddCloudDevice(endpoint, cloud_transport_type); } diff --git a/src/components/include/application_manager/policies/policy_handler_observer.h b/src/components/include/application_manager/policies/policy_handler_observer.h index 1c32102184..c13846dff2 100644 --- a/src/components/include/application_manager/policies/policy_handler_observer.h +++ b/src/components/include/application_manager/policies/policy_handler_observer.h @@ -48,6 +48,9 @@ class PolicyHandlerObserver { return false; } + virtual void OnAuthTokenUpdated(const std::string& policy_app_id, + const std::string& auth_token) {} + virtual void OnPTUFinished(const bool ptu_result) {} virtual ~PolicyHandlerObserver() {} diff --git a/src/components/include/connection_handler/connection_handler.h b/src/components/include/connection_handler/connection_handler.h index a4058c7078..234a7c1b76 100644 --- a/src/components/include/connection_handler/connection_handler.h +++ b/src/components/include/connection_handler/connection_handler.h @@ -128,6 +128,15 @@ class ConnectionHandler { virtual uint32_t GetConnectionSessionsCount(uint32_t connection_key) = 0; /** + * @brief Get cloud app id by connection id + * @param connection_id unique connection id + * @return the policy app id of the cloud app if the connection is tied to a + * cloud app, an empty string otherwise. + */ + virtual std::string GetCloudAppID( + const transport_manager::ConnectionUID connection_id) const = 0; + + /** * Gets device id by mac address * @param mac_address * @return true if successfully diff --git a/src/components/include/policy/policy_external/policy/policy_listener.h b/src/components/include/policy/policy_external/policy/policy_listener.h index c446c87d1b..8299d019f5 100644 --- a/src/components/include/policy/policy_external/policy/policy_listener.h +++ b/src/components/include/policy/policy_external/policy/policy_listener.h @@ -115,6 +115,16 @@ class PolicyListener { virtual void OnCertificateUpdated(const std::string& certificate_data) = 0; /** + * @brief OnAuthTokenUpdated the callback which signals if an app's auth token + * field has been updated during a PTU + * + * @param policy_app_id the policy app id tied to the updated field. + * @param auth_token the value of the updated field. + */ + virtual void OnAuthTokenUpdated(const std::string& policy_app_id, + const std::string& auth_token) = 0; + + /** * @brief OnPTUFinishedd the callback which signals PTU has finished * * @param ptu_result the result from the PTU - true if successful, diff --git a/src/components/include/policy/policy_regular/policy/policy_listener.h b/src/components/include/policy/policy_regular/policy/policy_listener.h index 3f6f555bcc..56e674e81b 100644 --- a/src/components/include/policy/policy_regular/policy/policy_listener.h +++ b/src/components/include/policy/policy_regular/policy/policy_listener.h @@ -113,6 +113,16 @@ class PolicyListener { virtual void OnCertificateUpdated(const std::string& certificate_data) = 0; /** + * @brief OnAuthTokenUpdated the callback which signals if an app's auth token + * field has been updated during a PTU + * + * @param policy_app_id the policy app id tied to the updated field. + * @param auth_token the value of the updated field. + */ + virtual void OnAuthTokenUpdated(const std::string& policy_app_id, + const std::string& auth_token) = 0; + + /** * Gets devices ids by policy application id * @param policy_app_id * @return list devices ids diff --git a/src/components/include/protocol/bson_object_keys.h b/src/components/include/protocol/bson_object_keys.h index 56bd5cebd6..f81de4cc81 100644 --- a/src/components/include/protocol/bson_object_keys.h +++ b/src/components/include/protocol/bson_object_keys.h @@ -48,6 +48,7 @@ extern const char* video_service_transports; extern const char* tcp_ip_address; extern const char* tcp_port; extern const char* reason; +extern const char* auth_token; } // namespace strings diff --git a/src/components/include/test/connection_handler/mock_connection_handler.h b/src/components/include/test/connection_handler/mock_connection_handler.h index 219ee7b561..3027fd5cb4 100644 --- a/src/components/include/test/connection_handler/mock_connection_handler.h +++ b/src/components/include/test/connection_handler/mock_connection_handler.h @@ -74,6 +74,9 @@ class MockConnectionHandler : public connection_handler::ConnectionHandler { MOCK_METHOD1(CloseRevokedConnection, void(uint32_t connection_key)); MOCK_METHOD1(CloseConnection, void(ConnectionHandle connection_handle)); MOCK_METHOD1(GetConnectionSessionsCount, uint32_t(uint32_t connection_key)); + MOCK_CONST_METHOD1( + GetCloudAppID, + std::string(const transport_manager::ConnectionUID connection_id)); MOCK_METHOD2(GetDeviceID, bool(const std::string& mac_address, DeviceHandle* device_handle)); diff --git a/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h b/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h index 1f570d8699..720a81862a 100644 --- a/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h +++ b/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h @@ -81,6 +81,9 @@ class MockPolicyListener : public ::policy::PolicyListener { uint32_t timeout_exceed)); MOCK_METHOD0(CanUpdate, bool()); MOCK_METHOD1(OnCertificateUpdated, void(const std::string&)); + MOCK_METHOD2(OnAuthTokenUpdated, + void(const std::string& policy_app_id, + const std::string& auth_token)); MOCK_METHOD1(OnPTUFinished, void(const bool ptu_result)); MOCK_CONST_METHOD2(SendOnAppPermissionsChanged, void(const policy::AppPermissions&, const std::string&)); diff --git a/src/components/include/test/policy/policy_regular/policy/mock_policy_listener.h b/src/components/include/test/policy/policy_regular/policy/mock_policy_listener.h index 3b0c1a925e..045d4f4e4f 100644 --- a/src/components/include/test/policy/policy_regular/policy/mock_policy_listener.h +++ b/src/components/include/test/policy/policy_regular/policy/mock_policy_listener.h @@ -75,6 +75,9 @@ class MockPolicyListener : public ::policy::PolicyListener { MOCK_METHOD1(OnSnapshotCreated, void(const policy::BinaryMessage& pt_string)); MOCK_METHOD0(CanUpdate, bool()); MOCK_METHOD1(OnCertificateUpdated, void(const std::string&)); + MOCK_METHOD2(OnAuthTokenUpdated, + void(const std::string& policy_app_id, + const std::string& auth_token)); MOCK_CONST_METHOD2(SendOnAppPermissionsChanged, void(const policy::AppPermissions&, const std::string&)); MOCK_METHOD3(OnUpdateHMILevel, diff --git a/src/components/policy/policy_external/include/policy/policy_manager_impl.h b/src/components/policy/policy_external/include/policy/policy_manager_impl.h index 399c95170d..2802af1706 100644 --- a/src/components/policy/policy_external/include/policy/policy_manager_impl.h +++ b/src/components/policy/policy_external/include/policy/policy_manager_impl.h @@ -961,6 +961,12 @@ class PolicyManagerImpl : public PolicyManager { const std::string& application_id) OVERRIDE; /** + * @brief notify listener of updated auth token for a given policy id + * @param policy_app_id the app id that has an updated auth token + */ + void SendAuthTokenUpdated(const std::string policy_app_id); + + /** * @brief Gets all allowed module types * @param policy_app_id unique identifier of application * @param modules list of allowed module types diff --git a/src/components/policy/policy_external/src/policy_manager_impl.cc b/src/components/policy/policy_external/src/policy_manager_impl.cc index 0844edd8eb..bd7746d720 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -497,6 +497,12 @@ bool PolicyManagerImpl::LoadPT(const std::string& file, } else { LOG4CXX_INFO(logger_, "app_hmi_types empty"); } + + std::vector<std::string> enabled_apps; + cache_->GetEnabledCloudApps(enabled_apps); + for (auto it = enabled_apps.begin(); it != enabled_apps.end(); ++it) { + SendAuthTokenUpdated(*it); + } } // If there was a user request for policy table update, it should be started @@ -2080,6 +2086,11 @@ bool PolicyManagerImpl::InitPT(const std::string& file_name, const bool ret = cache_->Init(file_name, settings); if (ret) { RefreshRetrySequence(); + std::vector<std::string> enabled_apps; + cache_->GetEnabledCloudApps(enabled_apps); + for (auto it = enabled_apps.begin(); it != enabled_apps.end(); ++it) { + SendAuthTokenUpdated(*it); + } } return ret; } @@ -2188,6 +2199,15 @@ void PolicyManagerImpl::SendAppPermissionsChanged( listener()->OnPermissionsUpdated(application_id, notification_data); } +void PolicyManagerImpl::SendAuthTokenUpdated(const std::string policy_app_id) { + bool enabled = false; + std::string end, cert, ctt, hap; + std::string auth_token; + cache_->GetCloudAppParameters( + policy_app_id, enabled, end, cert, auth_token, ctt, hap); + listener_->OnAuthTokenUpdated(policy_app_id, auth_token); +} + void PolicyManagerImpl::OnPrimaryGroupsChanged( const std::string& application_id) { const std::vector<std::string> devices = 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 20a37717a7..fea8bbe0b3 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 @@ -910,6 +910,12 @@ class PolicyManagerImpl : public PolicyManager { const std::string& application_id) OVERRIDE; /** + * @brief notify listener of updated auth token for a given policy id + * @param policy_app_id the app id that has an updated auth token + */ + void SendAuthTokenUpdated(const std::string policy_app_id); + + /** * @brief Gets all allowed module types * @param policy_app_id unique identifier of application * @param modules list of allowed module types 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 9b2392a015..a7e206b51b 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -368,6 +368,12 @@ bool PolicyManagerImpl::LoadPT(const std::string& file, } else { LOG4CXX_INFO(logger_, "app_hmi_types empty" << pt_content.size()); } + + std::vector<std::string> enabled_apps; + cache_->GetEnabledCloudApps(enabled_apps); + for (auto it = enabled_apps.begin(); it != enabled_apps.end(); ++it) { + SendAuthTokenUpdated(*it); + } } // If there was a user request for policy table update, it should be started @@ -1341,6 +1347,11 @@ bool PolicyManagerImpl::InitPT(const std::string& file_name, if (!certificate_data.empty()) { listener_->OnCertificateUpdated(certificate_data); } + std::vector<std::string> enabled_apps; + cache_->GetEnabledCloudApps(enabled_apps); + for (auto it = enabled_apps.begin(); it != enabled_apps.end(); ++it) { + SendAuthTokenUpdated(*it); + } } return ret; } @@ -1456,6 +1467,15 @@ void PolicyManagerImpl::SendAppPermissionsChanged( listener()->OnPermissionsUpdated(application_id, notification_data); } +void PolicyManagerImpl::SendAuthTokenUpdated(const std::string policy_app_id) { + bool enabled = false; + std::string end, cert, ctt, hap; + std::string auth_token; + cache_->GetCloudAppParameters( + policy_app_id, enabled, end, cert, auth_token, ctt, hap); + listener_->OnAuthTokenUpdated(policy_app_id, auth_token); +} + void PolicyManagerImpl::OnPrimaryGroupsChanged( const std::string& application_id) { const std::vector<std::string> devices = diff --git a/src/components/protocol/src/bson_object_keys.cc b/src/components/protocol/src/bson_object_keys.cc index 11160d7082..acafd3dbd2 100644 --- a/src/components/protocol/src/bson_object_keys.cc +++ b/src/components/protocol/src/bson_object_keys.cc @@ -18,6 +18,7 @@ const char* video_service_transports = "videoServiceTransports"; const char* tcp_ip_address = "tcpIpAddress"; const char* tcp_port = "tcpPort"; const char* reason = "reason"; +const char* auth_token = "authToken"; } // namespace strings diff --git a/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h b/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h index ccf6082a18..89800037b5 100644 --- a/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h +++ b/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h @@ -428,6 +428,9 @@ class ProtocolHandlerImpl void NotifySessionStarted(const SessionContext& context, std::vector<std::string>& rejected_params) OVERRIDE; + void OnAuthTokenUpdated(const std::string& policy_app_id, + const std::string& auth_token) OVERRIDE; + #ifdef BUILD_TESTS const impl::FromMobileQueue& get_from_mobile_queue() const { return raw_ford_messages_from_mobile_; @@ -777,6 +780,10 @@ class ProtocolHandlerImpl sync_primitives::Lock start_session_frame_map_lock_; StartSessionFrameMap start_session_frame_map_; + // Map policy app id -> auth token + sync_primitives::Lock auth_token_map_lock_; + std::map<std::string, std::string> auth_token_map_; + bool tcp_enabled_; std::string tcp_port_; std::string tcp_ip_address_; diff --git a/src/components/protocol_handler/src/protocol_handler_impl.cc b/src/components/protocol_handler/src/protocol_handler_impl.cc index ee2dc73780..c09fbfe0d8 100644 --- a/src/components/protocol_handler/src/protocol_handler_impl.cc +++ b/src/components/protocol_handler/src/protocol_handler_impl.cc @@ -61,8 +61,9 @@ std::string ConvertPacketDataToString(const uint8_t* data, const size_t kStackSize = 65536; -utils::SemanticVersion defaultProtocolVersion(5, 1, 0); -utils::SemanticVersion minMultipleTransportsVersion(5, 1, 0); +utils::SemanticVersion default_protocol_version(5, 2, 0); +utils::SemanticVersion min_multiple_transports_version(5, 1, 0); +utils::SemanticVersion min_cloud_app_version(5, 2, 0); ProtocolHandlerImpl::ProtocolHandlerImpl( const ProtocolHandlerSettings& settings, @@ -309,16 +310,16 @@ void ProtocolHandlerImpl::SendStartSessionAck( ¶ms, strings::hash_id))); // Minimum protocol version supported by both - utils::SemanticVersion* minVersion = + utils::SemanticVersion* min_version = (full_version.major_version_ < PROTOCOL_VERSION_5) - ? &defaultProtocolVersion + ? &default_protocol_version : utils::SemanticVersion::min(full_version, - defaultProtocolVersion); - char protocolVersionString[256]; - strncpy(protocolVersionString, (*minVersion).toString().c_str(), 255); + default_protocol_version); + char protocol_version_string[256]; + strncpy(protocol_version_string, (*min_version).toString().c_str(), 255); const bool protocol_ver_written = bson_object_put_string( - ¶ms, strings::protocol_version, protocolVersionString); + ¶ms, strings::protocol_version, protocol_version_string); UNUSED(protocol_ver_written); LOG4CXX_DEBUG( logger_, @@ -327,12 +328,12 @@ void ProtocolHandlerImpl::SendStartSessionAck( << bson_object_get_string(¶ms, strings::protocol_version)); LOG4CXX_INFO(logger_, - "Protocol Version String " << protocolVersionString); + "Protocol Version String " << protocol_version_string); std::vector<std::string> secondaryTransports; std::vector<int32_t> audioServiceTransports; std::vector<int32_t> videoServiceTransports; - if (*minVersion >= minMultipleTransportsVersion) { + if (*min_version >= min_multiple_transports_version) { if (ParseSecondaryTransportConfiguration(connection_id, secondaryTransports, audioServiceTransports, @@ -410,10 +411,22 @@ void ProtocolHandlerImpl::SendStartSessionAck( connection_handler_.SetSecondaryTransportID(session_id, kDisabledSecondary); } + + std::string policy_app_id = + connection_handler_.GetCloudAppID(connection_id); + if (*min_version >= min_cloud_app_version && !policy_app_id.empty()) { + sync_primitives::AutoLock lock(auth_token_map_lock_); + auto it = auth_token_map_.find(policy_app_id); + if (it != auth_token_map_.end()) { + char auth_token[256]; + strncpy(auth_token, it->second.c_str(), 255); + bson_object_put_string(¶ms, strings::auth_token, auth_token); + } + } } - uint8_t* payloadBytes = bson_object_to_bytes(¶ms); - ptr->set_data(payloadBytes, bson_object_size(¶ms)); - free(payloadBytes); + uint8_t* payload_bytes = bson_object_to_bytes(¶ms); + ptr->set_data(payload_bytes, bson_object_size(¶ms)); + free(payload_bytes); } else { set_hash_id(hash_id, *ptr); } @@ -1185,6 +1198,17 @@ void ProtocolHandlerImpl::OnTransportConfigUpdated( } } +void ProtocolHandlerImpl::OnAuthTokenUpdated(const std::string& policy_app_id, + const std::string& auth_token) { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(auth_token_map_lock_); + if (auth_token.empty()) { + auth_token_map_.erase(policy_app_id); + } else { + auth_token_map_[policy_app_id] = auth_token; + } +} + RESULT_CODE ProtocolHandlerImpl::SendFrame(const ProtocolFramePtr packet) { LOG4CXX_AUTO_TRACE(logger_); if (!packet) { |