diff options
Diffstat (limited to 'src/components/application_manager/src/commands/mobile/system_request.cc')
-rw-r--r-- | src/components/application_manager/src/commands/mobile/system_request.cc | 231 |
1 files changed, 126 insertions, 105 deletions
diff --git a/src/components/application_manager/src/commands/mobile/system_request.cc b/src/components/application_manager/src/commands/mobile/system_request.cc index c0b8b0ebf7..b9acf5e930 100644 --- a/src/components/application_manager/src/commands/mobile/system_request.cc +++ b/src/components/application_manager/src/commands/mobile/system_request.cc @@ -31,26 +31,26 @@ Copyright (c) 2013, Ford Motor Company POSSIBILITY OF SUCH DAMAGE. */ +#include "application_manager/commands/mobile/system_request.h" + #include <vector> #include <string> -#include <map> -#include <set> -#include "application_manager/commands/mobile/system_request.h" -#include "application_manager/application_manager_impl.h" -#include "application_manager/application_impl.h" -#include "application_manager/policies/policy_handler.h" +#include <stdio.h> +#include <algorithm> +#include <sstream> +#include "application_manager/policies/policy_handler_interface.h" #include "interfaces/MOBILE_API.h" -#include "config_profile/profile.h" #include "utils/file_system.h" -#include "formatters/CFormatterJsonBase.hpp" +#include "formatters/CFormatterJsonBase.h" #include "json/json.h" #include "utils/helpers.h" +#include "utils/custom_string.h" namespace application_manager { +CREATE_LOGGERPTR_LOCAL(logger_, "ApplicationManager") namespace { -CREATE_LOGGERPTR_LOCAL(logger_, "ApplicationManager") #ifdef ENABLE_LOG const char* kQueryAppsValidationFailedPrefix = ":QUERY_APPS_VALIDATION_FAILED: "; @@ -72,11 +72,11 @@ class QueryAppsDataValidator { typedef std::set<std::string> SynonymsSet; typedef std::map<std::string, SynonymsSet> SynonymsMap; - QueryAppsDataValidator(const smart_objects::SmartObject& object, - const ApplicationManagerImpl& manager) + QueryAppsDataValidator(smart_objects::SmartObject& object, + const ApplicationManager& manager) : data_(object), manager_(manager) {} - bool Validate() const { + bool Validate() { LOG4CXX_AUTO_TRACE(logger_); if (!data_.isValid()) { LOG4CXX_ERROR(logger_, @@ -102,19 +102,25 @@ class QueryAppsDataValidator { return true; } - bool ValidateAppDataAndOsAndLanguagesData() const { - const smart_objects::SmartArray* objects_array = - data_[json::response].asArray(); + bool ValidateAppDataAndOsAndLanguagesData() { + smart_objects::SmartArray* objects_array = data_[json::response].asArray(); + if (!objects_array) { LOG4CXX_WARN(logger_, kQueryAppsValidationFailedPrefix << "QueryApps response is not array."); return false; } - const std::size_t arr_size(objects_array->size()); + SynonymsMap synonyms_map; - for (std::size_t idx = 0; idx < arr_size; ++idx) { - const smart_objects::SmartObject& app_data = (*objects_array)[idx]; + bool has_response_valid_application = false; + + smart_objects::SmartArray::iterator applications_iterator = + objects_array->begin(); + + for (; applications_iterator != objects_array->end(); + ++applications_iterator) { + const smart_objects::SmartObject& app_data = *applications_iterator; if (!app_data.isValid()) { LOG4CXX_WARN(logger_, @@ -122,59 +128,50 @@ class QueryAppsDataValidator { << "Wrong application data in json file."); return false; } - std::set<std::string> app_ids_set; - if (!ValidateAppIdAndAppName(app_data, app_ids_set)) { + + if (!CheckMandatoryParametersPresent(app_data)) { + LOG4CXX_WARN(logger_, + "Application hasn`t some of mandatory parameters. " + "Application will be skipped."); + objects_array->erase(applications_iterator); + continue; + } + + if (!ValidateAppIdAndAppName(app_data)) { return false; } + + // If we dont have any of android/ios field + // we skip this json in CheckMandatoryParametersPresent + const std::string os_type = + (app_data.keyExists(json::android)) ? json::android : json::ios; + // Verify os and dependent languages data - std::string os_type; - if (app_data.keyExists(json::ios)) { - os_type = json::ios; - if (!app_data[os_type].keyExists(json::urlScheme)) { - LOG4CXX_WARN(logger_, - kQueryAppsValidationFailedPrefix - << "Can't find URL scheme in json file."); - return false; - } - if (app_data[os_type][json::urlScheme].asString().length() > + if (json::ios == os_type) { + if (app_data[json::ios][json::urlScheme].asString().length() > kUrlSchemaLengthMax) { LOG4CXX_WARN( logger_, kQueryAppsValidationFailedPrefix << "An urlscheme length exceeds maximum allowed [" - << app_data[os_type][json::urlScheme].asString().length() + << app_data[json::ios][json::urlScheme].asString().length() << "]>[" << kUrlSchemaLengthMax << "]"); return false; } } - if (os_type.empty()) { - if (app_data.keyExists(json::android)) { - os_type = json::android; - if (!app_data[os_type].keyExists(json::packageName)) { - LOG4CXX_WARN(logger_, - kQueryAppsValidationFailedPrefix - << "Can't find package name in json file."); - return false; - } - if (app_data[json::android][json::packageName].asString().length() > - kPackageNameLengthMax) { - LOG4CXX_WARN(logger_, - kQueryAppsValidationFailedPrefix - << "Package name length [" - << app_data[json::android][json::packageName] - .asString() - .length() << "] exceeds max length [" - << kPackageNameLengthMax << "]in json file."); - return false; - } - } - } - if (os_type.empty()) { - LOG4CXX_WARN(logger_, - kQueryAppsValidationFailedPrefix - << "Can't find mobile OS type in json file."); - return false; + if (json::android == os_type) { + if (app_data[json::android][json::packageName].asString().length() > + kPackageNameLengthMax) { + LOG4CXX_WARN(logger_, + kQueryAppsValidationFailedPrefix + << "Package name length [" + << app_data[json::android][json::packageName] + .asString() + .length() << "] exceeds max length [" + << kPackageNameLengthMax << "]in json file."); + return false; + } } // Languages verification @@ -188,19 +185,12 @@ class QueryAppsDataValidator { synonyms_map)) { return false; } + has_response_valid_application = true; } - return true; + return has_response_valid_application; } - bool ValidateAppIdAndAppName(const smart_objects::SmartObject& app_data, - std::set<std::string>& app_ids_set) const { - // Verify appid - if (!app_data.keyExists(json::appId)) { - LOG4CXX_WARN(logger_, - kQueryAppsValidationFailedPrefix - << "Can't find app ID in json file."); - return false; - } + bool ValidateAppIdAndAppName(const smart_objects::SmartObject& app_data) { // Verify appid length const std::string app_id(app_data[json::appId].asString()); if (app_id.length() > kAppIdLengthMax) { @@ -212,30 +202,21 @@ class QueryAppsDataValidator { } // Verify that appid is unique - if (app_ids_set.find(app_id) != app_ids_set.end()) { + if (applications_id_set_.find(app_id) != applications_id_set_.end()) { LOG4CXX_WARN(logger_, kQueryAppsValidationFailedPrefix << "An Object ID is not unigue [" << app_id << "]"); return false; } - app_ids_set.insert(app_id); + applications_id_set_.insert(app_id); // Verify that app is not registered yet ApplicationSharedPtr registered_app = manager_.application_by_policy_id(app_id); if (registered_app) { - LOG4CXX_WARN(logger_, - kQueryAppsValidationFailedPrefix - << "Application with the same id: " << app_id - << " is registered already."); - return false; - } - // Verify app name exist - if (!app_data.keyExists(json::name)) { - LOG4CXX_WARN(logger_, - kQueryAppsValidationFailedPrefix - << "Can't find app name in json file."); - return false; + LOG4CXX_INFO(logger_, + "Application with the id: " << app_id + << " is already registered."); } // And app name length const std::string appName(app_data[json::name].asString()); @@ -404,8 +385,36 @@ class QueryAppsDataValidator { return true; } - const smart_objects::SmartObject& data_; - const ApplicationManagerImpl& manager_; + bool CheckMandatoryParametersPresent( + const smart_objects::SmartObject& app_data) const { + if (!app_data.keyExists(json::android) && !app_data.keyExists(json::ios)) { + return false; + } + + if (app_data.keyExists(json::android) && + !app_data[json::android].keyExists(json::packageName)) { + return false; + } + + if (app_data.keyExists(json::ios) && + !app_data[json::ios].keyExists(json::urlScheme)) { + return false; + } + + if (!app_data.keyExists(json::appId)) { + return false; + } + + if (!app_data.keyExists(json::name)) { + return false; + } + + return true; + } + + smart_objects::SmartObject& data_; + std::set<std::string> applications_id_set_; + const ApplicationManager& manager_; DISALLOW_COPY_AND_ASSIGN(QueryAppsDataValidator); }; @@ -413,23 +422,24 @@ class QueryAppsDataValidator { namespace commands { +namespace custom_str = utils::custom_string; + uint32_t SystemRequest::index = 0; const std::string kSYNC = "SYNC"; const std::string kIVSU = "IVSU"; -SystemRequest::SystemRequest(const MessageSharedPtr& message) - : CommandRequestImpl(message) { -} +SystemRequest::SystemRequest(const MessageSharedPtr& message, + ApplicationManager& application_manager) + : CommandRequestImpl(message, application_manager) {} -SystemRequest::~SystemRequest() { -} +SystemRequest::~SystemRequest() {} void SystemRequest::Run() { LOG4CXX_AUTO_TRACE(logger_); ApplicationSharedPtr application = - ApplicationManagerImpl::instance()->application(connection_key()); + application_manager_.application(connection_key()); if (!(application.valid())) { LOG4CXX_ERROR(logger_, "NULL pointer"); @@ -441,8 +451,10 @@ void SystemRequest::Run() { static_cast<mobile_apis::RequestType::eType>( (*message_)[strings::msg_params][strings::request_type].asInt()); - if (!policy::PolicyHandler::instance()->IsRequestTypeAllowed( - application->mobile_app_id(), request_type)) { + const policy::PolicyHandlerInterface& policy_handler = + application_manager_.GetPolicyHandler(); + if (!policy_handler.IsRequestTypeAllowed(application->policy_app_id(), + request_type)) { SendResponse(false, mobile_apis::Result::DISALLOWED); return; } @@ -469,15 +481,18 @@ void SystemRequest::Run() { std::string binary_data_folder; if ((*message_)[strings::params].keyExists(strings::binary_data)) { binary_data = (*message_)[strings::params][strings::binary_data].asBinary(); - binary_data_folder = profile::Profile::instance()->system_files_path(); + binary_data_folder = + application_manager_.get_settings().system_files_path(); } else { - binary_data_folder = profile::Profile::instance()->app_storage_folder(); + binary_data_folder = + application_manager_.get_settings().app_storage_folder(); binary_data_folder += "/"; binary_data_folder += application->folder_name(); binary_data_folder += "/"; } - std::string file_dst_path = profile::Profile::instance()->system_files_path(); + std::string file_dst_path = + application_manager_.get_settings().system_files_path(); file_dst_path += "/"; file_dst_path += file_name; @@ -486,7 +501,7 @@ void SystemRequest::Run() { logger_, "Binary data is present. Trying to save it to: " << binary_data_folder); if (mobile_apis::Result::SUCCESS != - (ApplicationManagerImpl::instance()->SaveBinary( + (application_manager_.SaveBinary( binary_data, binary_data_folder, file_name, 0))) { LOG4CXX_DEBUG(logger_, "Binary data can't be saved."); SendResponse(false, mobile_apis::Result::GENERIC_ERROR); @@ -524,7 +539,15 @@ void SystemRequest::Run() { LOG4CXX_DEBUG(logger_, "Binary data ok."); - if (mobile_apis::RequestType::QUERY_APPS == request_type) { + if (mobile_apis::RequestType::HTTP == request_type && + (*message_)[strings::msg_params].keyExists(strings::file_name)) { + const std::string& file = + (*message_)[strings::msg_params][strings::file_name].asString(); + application_manager_.GetPolicyHandler().ReceiveMessageFromSDK(file, + binary_data); + SendResponse(true, mobile_apis::Result::SUCCESS); + return; + } else if (mobile_apis::RequestType::QUERY_APPS == request_type) { using namespace NsSmartDeviceLink::NsJSONHandler::Formatters; smart_objects::SmartObject sm_object; @@ -542,8 +565,7 @@ void SystemRequest::Run() { return; } - ApplicationManagerImpl::instance()->ProcessQueryApp(sm_object, - connection_key()); + application_manager_.ProcessQueryApp(sm_object, connection_key()); SendResponse(true, mobile_apis::Result::SUCCESS); return; } @@ -557,7 +579,7 @@ void SystemRequest::Run() { } if (mobile_apis::RequestType::PROPRIETARY != request_type) { - msg_params[strings::app_id] = (application->mobile_app_id()); + msg_params[strings::app_id] = (application->policy_app_id()); } msg_params[strings::request_type] = (*message_)[strings::msg_params][strings::request_type]; @@ -584,7 +606,7 @@ void SystemRequest::on_event(const event_engine::Event& event) { mobile_api::Result::WARNINGS); ApplicationSharedPtr application = - ApplicationManagerImpl::instance()->application(connection_key()); + application_manager_.application(connection_key()); if (!(application.valid())) { LOG4CXX_ERROR(logger_, "NULL pointer"); @@ -595,6 +617,7 @@ void SystemRequest::on_event(const event_engine::Event& event) { file_system::DeleteFile(processing_file_); processing_file_.clear(); } + SendResponse(result, result_code, NULL, &(message[strings::msg_params])); break; } @@ -606,7 +629,7 @@ void SystemRequest::on_event(const event_engine::Event& event) { } bool SystemRequest::ValidateQueryAppData( - const smart_objects::SmartObject& data) const { + smart_objects::SmartObject& data) const { if (!data.isValid()) { LOG4CXX_ERROR(logger_, kQueryAppsValidationFailedPrefix @@ -620,10 +643,8 @@ bool SystemRequest::ValidateQueryAppData( << json::response << "' parameter."); return false; } - ApplicationManagerImpl* manager = ApplicationManagerImpl::instance(); - DCHECK(manager); - QueryAppsDataValidator validator(data, *manager); + QueryAppsDataValidator validator(data, application_manager_); return validator.Validate(); } |