diff options
Diffstat (limited to 'src/components/application_manager/src/commands/mobile/on_system_request_notification.cc')
-rw-r--r-- | src/components/application_manager/src/commands/mobile/on_system_request_notification.cc | 95 |
1 files changed, 75 insertions, 20 deletions
diff --git a/src/components/application_manager/src/commands/mobile/on_system_request_notification.cc b/src/components/application_manager/src/commands/mobile/on_system_request_notification.cc index 4e7354776f..2ac96e61b0 100644 --- a/src/components/application_manager/src/commands/mobile/on_system_request_notification.cc +++ b/src/components/application_manager/src/commands/mobile/on_system_request_notification.cc @@ -1,6 +1,5 @@ /* - - Copyright (c) 2013, Ford Motor Company + Copyright (c) 2016, Ford Motor Company All rights reserved. Redistribution and use in source and binary forms, with or without @@ -31,6 +30,9 @@ POSSIBILITY OF SUCH DAMAGE. */ +#include <cstring> +#include <cstdio> +#include <string> #include "application_manager/commands/mobile/on_system_request_notification.h" #include "interfaces/MOBILE_API.h" #include "utils/file_system.h" @@ -45,43 +47,52 @@ namespace mobile { OnSystemRequestNotification::OnSystemRequestNotification( const MessageSharedPtr& message) - : CommandNotificationImpl(message) { -} + : CommandNotificationImpl(message) {} -OnSystemRequestNotification::~OnSystemRequestNotification() { -} +OnSystemRequestNotification::~OnSystemRequestNotification() {} void OnSystemRequestNotification::Run() { LOG4CXX_AUTO_TRACE(logger_); using namespace application_manager; using namespace mobile_apis; - ApplicationSharedPtr app = ApplicationManagerImpl::instance()-> - application(connection_key()); + ApplicationSharedPtr app = + ApplicationManagerImpl::instance()->application(connection_key()); if (!app.valid()) { - LOG4CXX_ERROR(logger_, "Application with connection key " - << connection_key() << " is not registered."); + LOG4CXX_ERROR(logger_, + "Application with connection key " << connection_key() + << " is not registered."); return; } - RequestType::eType request_type = static_cast<RequestType::eType> - ((*message_)[strings::msg_params][strings::request_type].asInt()); + RequestType::eType request_type = static_cast<RequestType::eType>( + (*message_)[strings::msg_params][strings::request_type].asInt()); if (!policy::PolicyHandler::instance()->IsRequestTypeAllowed( - app->mobile_app_id(), request_type)) { - LOG4CXX_WARN(logger_, "Request type " << request_type - <<" is not allowed by policies"); + app->mobile_app_id(), request_type)) { + LOG4CXX_WARN(logger_, + "Request type " << request_type + << " is not allowed by policies"); return; } if (RequestType::PROPRIETARY == request_type) { - std::string filename = - (*message_)[strings::msg_params][strings::file_name].asString(); - - std::vector<uint8_t> binary_data; - file_system::ReadBinaryFile(filename, binary_data); +/* According to requirements: + "If the requestType = PROPRIETARY, add to mobile API fileType = JSON + If the requestType = HTTP, add to mobile API fileType = BINARY" + Also in Genivi SDL we don't save the PT to file - we put it directly in + binary_data */ + +#ifdef EXTENDED_POLICY + const std::string filename = + (*message_)[strings::msg_params][strings::file_name].asString(); + + BinaryMessage binary_data; + file_system::ReadBinaryFile(filename, binary_data); + AddHeader(binary_data); (*message_)[strings::params][strings::binary_data] = binary_data; +#endif (*message_)[strings::msg_params][strings::file_type] = FileType::JSON; } else if (RequestType::HTTP == request_type) { (*message_)[strings::msg_params][strings::file_type] = FileType::BINARY; @@ -90,6 +101,50 @@ void OnSystemRequestNotification::Run() { SendNotification(); } +#ifdef EXTENDED_POLICY +void OnSystemRequestNotification::AddHeader(BinaryMessage& message) const { + LOG4CXX_AUTO_TRACE(logger_); + const int timeout = policy::PolicyHandler::instance()->TimeoutExchange(); + + char size_str[24]; + + if (0 > sprintf(size_str, "%lu", message.size())) { + memset(size_str, 0, sizeof(size_str)); + } + + char timeout_str[24]; + if (0 > sprintf(timeout_str, "%d", timeout)) { + memset(timeout_str, 0, sizeof(timeout_str)); + } + + const std::string header = + + "{" + " \"HTTPRequest\": {" + "\"headers\": {" + "\"ContentType\": \"application/json\"," + "\"ConnectTimeout\": " + std::string(timeout_str) + "," + "\"DoOutput\": true," + "\"DoInput\": true," + "\"UseCaches\": false," + "\"RequestMethod\": \"POST\"," + "\"ReadTimeout\":" + std::string(timeout_str) + "," + "\"InstanceFollowRedirects\": false," + "\"charset\": \"utf-8\"," + "\"Content_Length\": " + std::string(size_str) + + "}," + "\"body\": \"" + std::string(message.begin(), message.end()) + "\"" + "}" + "}"; + + message.clear(); + message.assign(header.begin(), header.end()); + + LOG4CXX_DEBUG( + logger_, "Header added: " << std::string(message.begin(), message.end())); +} +#endif + } //namespace mobile } // namespace commands |