@@ -1596,6 +1596,56 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageEndSession(
15961596 return RESULT_OK;
15971597}
15981598
1599+ const ServiceStatus ProtocolHandlerImpl::ServiceDisallowedBySettings (
1600+ const ServiceType service_type,
1601+ const ConnectionID connection_id,
1602+ const uint8_t session_id,
1603+ const bool protection) const {
1604+ const std::string& transport =
1605+ session_observer_.TransportTypeProfileStringFromConnHandle (connection_id);
1606+
1607+ const auto video_transports = settings_.video_service_transports ();
1608+ const bool is_video_allowed =
1609+ video_transports.empty () ||
1610+ std::find (video_transports.begin (), video_transports.end (), transport) !=
1611+ video_transports.end ();
1612+
1613+ const auto audio_transports = settings_.audio_service_transports ();
1614+ const bool is_audio_allowed =
1615+ audio_transports.empty () ||
1616+ std::find (audio_transports.begin (), audio_transports.end (), transport) !=
1617+ audio_transports.end ();
1618+
1619+ const auto & force_protected = get_settings ().force_protected_service ();
1620+
1621+ const auto & force_unprotected = get_settings ().force_unprotected_service ();
1622+
1623+ const bool is_force_protected =
1624+ (helpers::in_range (force_protected, service_type));
1625+
1626+ const bool is_force_unprotected =
1627+ (helpers::in_range (force_unprotected, service_type));
1628+
1629+ const bool can_start_protected = is_force_protected && protection;
1630+
1631+ const bool can_start_unprotected = is_force_unprotected && !protection;
1632+
1633+ if ((ServiceType::kMobileNav == service_type && !is_video_allowed) ||
1634+ (ServiceType::kAudio == service_type && !is_audio_allowed)) {
1635+ return ServiceStatus::SERVICE_START_FAILED;
1636+ }
1637+
1638+ if (is_force_protected && !can_start_protected) {
1639+ return ServiceStatus::PROTECTION_ENFORCED;
1640+ }
1641+
1642+ if (is_force_unprotected && !can_start_unprotected) {
1643+ return ServiceStatus::UNSECURE_START_FAILED;
1644+ }
1645+
1646+ return ServiceStatus::INVALID_ENUM;
1647+ }
1648+
15991649RESULT_CODE ProtocolHandlerImpl::HandleControlMessageEndServiceACK (
16001650 const ProtocolPacket& packet) {
16011651 LOG4CXX_AUTO_TRACE (logger_);
@@ -1636,43 +1686,21 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageStartSession(
16361686
16371687 const ConnectionID connection_id = packet->connection_id ();
16381688 const uint8_t session_id = packet->session_id ();
1639- const std::string& transport =
1640- session_observer_.TransportTypeProfileStringFromConnHandle (connection_id);
1641-
1642- const auto video_transports = settings_.video_service_transports ();
1643- const bool is_video_allowed =
1644- video_transports.empty () ||
1645- std::find (video_transports.begin (), video_transports.end (), transport) !=
1646- video_transports.end ();
1647-
1648- const auto audio_transports = settings_.audio_service_transports ();
1649- const bool is_audio_allowed =
1650- audio_transports.empty () ||
1651- std::find (audio_transports.begin (), audio_transports.end (), transport) !=
1652- audio_transports.end ();
1653-
1654- const uint32_t connection_key = session_observer_.KeyFromPair (
1655- packet->connection_id (), packet->session_id ());
1656-
1657- const auto & force_protected = get_settings ().force_protected_service ();
1658-
1659- const bool is_force_protected =
1660- (helpers::in_range (force_protected, service_type));
1661-
1662- const bool can_start_unprotected = is_force_protected && protection;
1689+ const uint32_t connection_key =
1690+ session_observer_.KeyFromPair (connection_id, session_id);
16631691
16641692 service_status_update_handler_->OnServiceUpdate (
16651693 connection_key, service_type, ServiceStatus::SERVICE_RECEIVED);
16661694
1667- if ((ServiceType::kMobileNav == service_type && !is_video_allowed) ||
1668- (ServiceType::kAudio == service_type && !is_audio_allowed) ||
1669- (is_force_protected && !can_start_unprotected)) {
1695+ const auto settings_check = ServiceDisallowedBySettings (
1696+ service_type, connection_id, session_id, protection);
1697+
1698+ if (ServiceStatus::INVALID_ENUM != settings_check) {
16701699 LOG4CXX_DEBUG (logger_,
16711700 " Rejecting StartService for service:"
1672- << service_type << " , over transport: " << transport
1673- << " , disallowed by settings." );
1701+ << service_type << " , disallowed by settings." );
16741702 service_status_update_handler_->OnServiceUpdate (
1675- connection_key, service_type, ServiceStatus::PROTECTION_ENFORCED );
1703+ connection_key, service_type, settings_check );
16761704 SendStartSessionNAck (
16771705 connection_id, session_id, protocol_version, service_type);
16781706 return RESULT_OK;
0 commit comments