Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Initial implementation of expanded mobile PutFile #2128

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ extern const char* sync_file_name;
extern const char* file_name;
extern const char* file_type;
extern const char* file_size;
extern const char* crc32_check_sum;
extern const char* request_type;
extern const char* persistent_file;
extern const char* file_data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@
#include "application_manager/application_impl.h"

#include "utils/file_system.h"
#include <boost/crc.hpp>

namespace {
/**
* Calculates CRC32 checksum
* @param binary_data - input data for which CRC32 should be calculated
* @return calculated CRC32 checksum
*/
uint32_t GetCrc32CheckSum(const std::vector<uint8_t>& binary_data) {
const std::size_t file_size = binary_data.size();
boost::crc_32_type result;
result.process_bytes(&binary_data[0], file_size);
return result.checksum();
}

} // namespace

namespace application_manager {

Expand Down Expand Up @@ -137,7 +153,7 @@ void PutFileRequest::Run() {
is_persistent_file_ = false;
bool is_system_file = false;
length_ = binary_data.size();
bool is_download_compleate = true;
bool is_download_complete = true;
bool offset_exist =
(*message_)[strings::msg_params].keyExists(strings::offset);

Expand Down Expand Up @@ -187,11 +203,29 @@ void PutFileRequest::Run() {
return;
}
const std::string full_path = file_path + "/" + sync_file_name_;
UNUSED(full_path);
const size_t bin_data_size = binary_data.size();

if ((*message_)[strings::msg_params].keyExists(strings::crc32_check_sum)) {
LOG4CXX_TRACE(logger_, "Binary Data Size: " << bin_data_size);
const uint32_t crc_received =
(*message_)[strings::msg_params][strings::crc32_check_sum].asUInt();
LOG4CXX_TRACE(logger_, "CRC32 SUM Received: " << crc_received);
const uint32_t crc_calculated = GetCrc32CheckSum(binary_data);
LOG4CXX_TRACE(logger_, "CRC32 SUM Calculated: " << crc_calculated);
if (crc_calculated != crc_received) {
SendResponse(false,
mobile_apis::Result::CORRUPTED_DATA,
"CRC Check on file failed. File upload has been cancelled, "
"please retry.",
&response_params);
return;
}
}

LOG4CXX_DEBUG(logger_,
"Wrtiting " << binary_data.size() << "bytes to " << full_path
<< " (current size is"
<< file_system::FileSize(full_path) << ")");
"Writing " << bin_data_size << " bytes to " << full_path
<< " (current size is"
<< file_system::FileSize(full_path) << ")");

mobile_apis::Result::eType save_result = application_manager_.SaveBinary(
binary_data, file_path, sync_file_name_, offset_);
Expand All @@ -211,7 +245,7 @@ void PutFileRequest::Run() {
if (!is_system_file) {
AppFile file(sync_file_name_,
is_persistent_file_,
is_download_compleate,
is_download_complete,
file_type_);

if (0 == offset_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ const char* sync_file_name = "syncFileName";
const char* file_name = "fileName";
const char* file_type = "fileType";
const char* file_size = "fileSize";
const char* crc32_check_sum = "crc";
const char* request_type = "requestType";
const char* persistent_file = "persistentFile";
const char* file_data = "fileData";
Expand Down
7 changes: 7 additions & 0 deletions src/components/interfaces/MOBILE_API.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@
<element name="READ_ONLY">
<description>The value being set is read only</description>
</element>
<element name="CORRUPTED_DATA">
<description>The data sent failed to pass CRC check in receiver end</description>
</element>
</enum>

<enum name="ButtonPressMode">
Expand Down Expand Up @@ -5073,6 +5076,9 @@
If offset is set to 0, then length is the total length of the file to be downloaded
</description>
</param>
<param name="crc" type="Integer" minvalue="0" maxvalue="4294967295" mandatory="false">
<description> Additional CRC32 checksum to protect data integrity up to 512 Mbits . </description>
</param>
</function>

<function name="PutFile" functionID="PutFileID" messagetype="response">
Expand All @@ -5092,6 +5098,7 @@
<element name="GENERIC_ERROR"/>
<element name="REJECTED"/>
<element name="UNSUPPORTED_REQUEST"/>
<element name="CORRUPTED_DATA"/>
</param>

<param name="spaceAvailable" type="Integer" minvalue="0" maxvalue="2000000000" mandatory="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "smart_objects/default_shema_item.h"
#include "smart_objects/schema_item_parameter.h"
#include "utils/convert_utils.h"
#include "utils/helpers.h"

namespace NsSmartDeviceLink {
namespace NsSmartObjects {
Expand Down Expand Up @@ -123,15 +124,16 @@ bool TNumberSchemaItem<NumberType>::isValidNumberType(SmartType type) {
NumberType value(0);
if ((SmartType_Double == type) && (typeid(double) == typeid(value))) {
return true;
} else if ((SmartType_Integer == type) &&
(typeid(int32_t) == typeid(value) ||
typeid(uint32_t) == typeid(value) ||
typeid(int64_t) == typeid(value) ||
typeid(double) == typeid(value))) {
} else if (((SmartType_Integer == type) || (SmartType_UInteger == type)) &&
helpers::Compare<const std::type_info&, helpers::EQ, helpers::ONE>(
typeid(value),
typeid(int32_t),
typeid(uint32_t),
typeid(int64_t),
typeid(double))) {
return true;
} else {
return false;
}
return false;
}

template <typename NumberType>
Expand Down
2 changes: 1 addition & 1 deletion src/components/smart_objects/src/number_schema_item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ SmartType TNumberSchemaItem<int32_t>::getSmartType() const {

template <>
SmartType TNumberSchemaItem<uint32_t>::getSmartType() const {
return SmartType_Integer;
return SmartType_UInteger;
}

template <>
Expand Down