2016-08-22 01:49:45 -04:00
|
|
|
#include "serialiser/rsbaseserial.h"
|
|
|
|
|
2016-08-20 10:23:11 -04:00
|
|
|
#include "file_sharing/rsfilelistitems.h"
|
|
|
|
|
|
|
|
RsItem* RsFileListsSerialiser::deserialise(void *data, uint32_t *size)
|
|
|
|
{
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsFileListsSerialiser::deserialise()" << std::endl;
|
|
|
|
#endif
|
|
|
|
/* get the type and size */
|
|
|
|
uint32_t rstype = getRsItemId(data);
|
|
|
|
|
2016-08-22 01:49:45 -04:00
|
|
|
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (getRsItemService(rstype) != RS_SERVICE_TYPE_FILE_DATABASE))
|
|
|
|
return NULL; /* wrong type */
|
2016-08-20 10:23:11 -04:00
|
|
|
|
|
|
|
switch(getRsItemSubType(rstype))
|
|
|
|
{
|
2016-08-23 15:23:58 -04:00
|
|
|
case RS_PKT_SUBTYPE_FILELISTS_SYNC_REQ_ITEM: return deserialFileListsSyncRequestItem(data, size);
|
|
|
|
case RS_PKT_SUBTYPE_FILELISTS_SYNC_RSP_ITEM: return deserialFileListsSyncResponseItem(data, size);
|
2016-08-26 10:29:02 -04:00
|
|
|
// case RS_PKT_SUBTYPE_FILELISTS_CONFIG_ITEM: return deserialFileListsConfigItem (data, size);
|
2016-08-20 10:23:11 -04:00
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
std::cerr << "(WW) RsFileListsSerialiser::deserialise() : unhandled item type " << getRsItemSubType(rstype) << std::endl;
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t RsFileListsSerialiser::size(RsItem *item)
|
|
|
|
{
|
2016-08-22 01:49:45 -04:00
|
|
|
RsFileListsItem *flst_item = dynamic_cast<RsFileListsItem*>(item) ;
|
2016-08-20 10:23:11 -04:00
|
|
|
|
2016-08-22 01:49:45 -04:00
|
|
|
if(flst_item != NULL)
|
|
|
|
return flst_item->serial_size() ;
|
2016-08-20 10:23:11 -04:00
|
|
|
else
|
|
|
|
{
|
2016-08-22 01:49:45 -04:00
|
|
|
std::cerr << "RsFileListsSerialiser::serialise(): Not an RsFileListsItem!" << std::endl;
|
2016-08-20 10:23:11 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RsFileListsSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
|
|
|
|
{
|
2016-08-22 01:49:45 -04:00
|
|
|
RsFileListsItem *flst_item = dynamic_cast<RsFileListsItem*>(item) ;
|
2016-08-20 10:23:11 -04:00
|
|
|
|
2016-08-22 01:49:45 -04:00
|
|
|
if(flst_item != NULL)
|
|
|
|
return flst_item->serialise(data,*size) ;
|
2016-08-20 10:23:11 -04:00
|
|
|
else
|
|
|
|
{
|
2016-08-22 01:49:45 -04:00
|
|
|
std::cerr << "RsFileListsSerialiser::serialise(): Not an RsFileListsItem!" << std::endl;
|
2016-08-20 10:23:11 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RsFileListsItem::serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsize, uint32_t& offset) const
|
|
|
|
{
|
|
|
|
tlvsize = serial_size() ;
|
|
|
|
offset = 0;
|
|
|
|
|
|
|
|
if (pktsize < tlvsize)
|
|
|
|
return false; /* not enough space */
|
|
|
|
|
|
|
|
pktsize = tlvsize;
|
|
|
|
|
|
|
|
if(!setRsItemHeader(data, tlvsize, PacketId(), tlvsize))
|
|
|
|
{
|
|
|
|
std::cerr << "RsFileTransferItem::serialise_header(): ERROR. Not enough size!" << std::endl;
|
|
|
|
return false ;
|
|
|
|
}
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsFileItemSerialiser::serialiseData() Header: " << ok << std::endl;
|
|
|
|
#endif
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
|
2016-08-23 15:23:58 -04:00
|
|
|
bool RsFileListsSyncRequestItem::serialise(void *data, uint32_t& size) const
|
2016-08-20 10:23:11 -04:00
|
|
|
{
|
|
|
|
uint32_t tlvsize,offset=0;
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
if(!serialise_header(data,size,tlvsize,offset))
|
|
|
|
return false ;
|
|
|
|
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsFileListsSerialiser::serialiseFileListsSyncReqItem()" << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* RsFileListsSyncMsgItem */
|
|
|
|
|
|
|
|
ok &= setRawUInt32(data, size, &offset, entry_index);
|
|
|
|
ok &= setRawUInt32(data, size, &offset, flags );
|
|
|
|
ok &= setRawUInt32(data, size, &offset, last_known_recurs_modf_TS);
|
|
|
|
ok &= setRawUInt64(data, size, &offset, request_id);
|
|
|
|
|
|
|
|
if(offset != tlvsize){
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsFileListsSerialiser::serialiseNxsSynMsgItem() FAIL Size Error! " << std::endl;
|
|
|
|
#endif
|
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
std::cerr << "RsFileListsSerialiser::serialiseNxsSynMsgItem() NOK" << std::endl;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2016-08-23 15:23:58 -04:00
|
|
|
bool RsFileListsSyncResponseItem::serialise(void *data, uint32_t& size) const
|
2016-08-20 10:23:11 -04:00
|
|
|
{
|
|
|
|
uint32_t tlvsize,offset=0;
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
if(!serialise_header(data,size,tlvsize,offset))
|
|
|
|
return false ;
|
|
|
|
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsFileListsSerialiser::serialiseFileListsSyncReqItem()" << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* RsFileListsSyncMsgItem */
|
|
|
|
|
|
|
|
ok &= setRawUInt32(data, size, &offset, entry_index);
|
|
|
|
ok &= setRawUInt32(data, size, &offset, flags );
|
|
|
|
ok &= setRawUInt32(data, size, &offset, last_known_recurs_modf_TS);
|
|
|
|
ok &= setRawUInt64(data, size, &offset, request_id);
|
|
|
|
ok &= directory_content_data.SetTlv(data,size,&offset) ;
|
|
|
|
|
|
|
|
if(offset != tlvsize){
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsFileListsSerialiser::serialiseNxsSynMsgItem() FAIL Size Error! " << std::endl;
|
|
|
|
#endif
|
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
std::cerr << "RsFileListsSerialiser::serialiseNxsSynMsgItem() NOK" << std::endl;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================================================================//
|
|
|
|
// Deserialisation //
|
|
|
|
//============================================================================================================================//
|
|
|
|
|
2016-08-26 10:29:02 -04:00
|
|
|
//RsFileListsConfigItem* RsFileListsSerialiser::deserialFileListsConfigItem(void *data, uint32_t *size)
|
|
|
|
//{
|
|
|
|
// NOT_IMPLEMENTED();
|
|
|
|
//
|
|
|
|
// return NULL ;
|
|
|
|
//}
|
|
|
|
|
2016-08-23 15:23:58 -04:00
|
|
|
RsFileListsSyncRequestItem* RsFileListsSerialiser::deserialFileListsSyncRequestItem(void *data, uint32_t *size)
|
2016-08-20 10:23:11 -04:00
|
|
|
{
|
|
|
|
bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_FILELISTS_SYNC_REQ_ITEM);
|
|
|
|
uint32_t offset = 8;
|
|
|
|
|
2016-08-23 15:23:58 -04:00
|
|
|
RsFileListsSyncRequestItem* item = new RsFileListsSyncRequestItem();
|
2016-08-20 10:23:11 -04:00
|
|
|
|
|
|
|
ok &= getRawUInt32(data, *size, &offset, &item->entry_index);
|
|
|
|
ok &= getRawUInt32(data, *size, &offset, &item->flags);
|
|
|
|
ok &= getRawUInt32(data, *size, &offset, &item->last_known_recurs_modf_TS);
|
|
|
|
ok &= getRawUInt64(data, *size, &offset, &item->request_id);
|
|
|
|
|
|
|
|
if (offset != *size)
|
|
|
|
{
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsFileListsSerialiser::deserialNxsGrp() FAIL size mismatch" << std::endl;
|
|
|
|
#endif
|
|
|
|
/* error */
|
|
|
|
delete item;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsFileListsSerialiser::deserialNxsGrp() NOK" << std::endl;
|
|
|
|
#endif
|
|
|
|
delete item;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
2016-08-23 15:23:58 -04:00
|
|
|
RsFileListsSyncResponseItem* RsFileListsSerialiser::deserialFileListsSyncResponseItem(void *data, uint32_t *size)
|
2016-08-20 10:23:11 -04:00
|
|
|
{
|
2016-08-27 10:38:15 -04:00
|
|
|
bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_FILELISTS_SYNC_RSP_ITEM);
|
2016-08-20 10:23:11 -04:00
|
|
|
uint32_t offset = 8;
|
|
|
|
|
2016-08-23 15:23:58 -04:00
|
|
|
RsFileListsSyncResponseItem* item = new RsFileListsSyncResponseItem();
|
2016-08-20 10:23:11 -04:00
|
|
|
|
|
|
|
uint32_t entry_index ; // index of the directory to sync
|
|
|
|
uint32_t flags; // used to say that it's a request or a response, say that the directory has been removed, ask for further update, etc.
|
|
|
|
uint32_t last_known_recurs_modf_TS; // time of last modification, computed over all files+directories below.
|
|
|
|
uint64_t request_id; // use to determine if changes that have occured since last hash
|
|
|
|
|
|
|
|
ok &= getRawUInt32(data, *size, &offset, &item->entry_index);
|
|
|
|
ok &= getRawUInt32(data, *size, &offset, &item->flags);
|
|
|
|
ok &= getRawUInt32(data, *size, &offset, &item->last_known_recurs_modf_TS);
|
|
|
|
ok &= getRawUInt64(data, *size, &offset, &item->request_id);
|
|
|
|
|
|
|
|
ok &= item->directory_content_data.GetTlv(data,*size,&offset) ;
|
|
|
|
|
|
|
|
if (offset != *size)
|
|
|
|
{
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsFileListsSerialiser::deserialNxsGrp() FAIL size mismatch" << std::endl;
|
|
|
|
#endif
|
|
|
|
/* error */
|
|
|
|
delete item;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsFileListsSerialiser::deserialNxsGrp() NOK" << std::endl;
|
|
|
|
#endif
|
|
|
|
delete item;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
bool RsFileListsSerialiser::checkItemHeader(void *data,uint32_t *size,uint8_t subservice_type)
|
|
|
|
{
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsFileListsSerialiser::checkItemHeader()" << std::endl;
|
|
|
|
#endif
|
|
|
|
/* get the type and size */
|
|
|
|
uint32_t rstype = getRsItemId(data);
|
|
|
|
uint32_t rssize = getRsItemSize(data);
|
|
|
|
|
2016-08-22 01:49:45 -04:00
|
|
|
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_FILE_DATABASE != getRsItemService(rstype)) || (subservice_type != getRsItemSubType(rstype)))
|
2016-08-20 10:23:11 -04:00
|
|
|
{
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsFileListsSerialiser::checkItemHeader() FAIL wrong type" << std::endl;
|
|
|
|
#endif
|
|
|
|
return false; /* wrong type */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*size < rssize) /* check size */
|
|
|
|
{
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsFileListsSerialiser::checkItemHeader() FAIL wrong size" << std::endl;
|
|
|
|
#endif
|
|
|
|
return false; /* not enough data */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set the packet length */
|
|
|
|
*size = rssize;
|
|
|
|
|
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================================================================//
|
|
|
|
// Sizes //
|
|
|
|
//============================================================================================================================//
|
|
|
|
|
2016-08-23 15:23:58 -04:00
|
|
|
uint32_t RsFileListsSyncRequestItem::serial_size()const
|
2016-08-20 10:23:11 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
uint32_t s = 8; //header size
|
|
|
|
|
|
|
|
s += 4; // entry index
|
|
|
|
s += 4; // flags
|
|
|
|
s += 4; // last_known_recurs_modf_TS
|
|
|
|
s += 8; // request_id
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2016-08-23 15:23:58 -04:00
|
|
|
uint32_t RsFileListsSyncResponseItem::serial_size()const
|
2016-08-20 10:23:11 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
uint32_t s = 8; //header size
|
|
|
|
|
|
|
|
s += 4; // entry index
|
|
|
|
s += 4; // flags
|
|
|
|
s += 4; // last_known_recurs_modf_TS
|
|
|
|
s += 8; // request_id
|
|
|
|
s += directory_content_data.TlvSize();
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2016-08-23 15:23:58 -04:00
|
|
|
void RsFileListsSyncRequestItem::clear()
|
2016-08-20 10:23:11 -04:00
|
|
|
{
|
|
|
|
}
|
2016-08-23 15:23:58 -04:00
|
|
|
void RsFileListsSyncResponseItem::clear()
|
2016-08-20 10:23:11 -04:00
|
|
|
{
|
|
|
|
directory_content_data.TlvClear();
|
|
|
|
}
|
2016-08-23 15:23:58 -04:00
|
|
|
std::ostream& RsFileListsSyncRequestItem::print(std::ostream &out, uint16_t indent)
|
2016-08-20 10:23:11 -04:00
|
|
|
{
|
|
|
|
printRsItemBase(out, "RsFileListsSyncReqItem", indent);
|
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
|
|
|
|
printIndent(out , int_Indent); out << "Entry index: " << entry_index << std::endl;
|
|
|
|
printIndent(out , int_Indent); out << "Flags: " << (uint32_t) flags << std::endl;
|
|
|
|
printIndent(out , int_Indent); out << "Last modf TS: " << last_known_recurs_modf_TS << std::endl;
|
|
|
|
printIndent(out , int_Indent); out << "request id: " << std::hex << request_id << std::dec << std::endl;
|
|
|
|
|
|
|
|
printRsItemEnd(out ,"RsFileListsSyncReqItem", indent);
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2016-08-23 15:23:58 -04:00
|
|
|
std::ostream& RsFileListsSyncResponseItem::print(std::ostream &out, uint16_t indent)
|
2016-08-20 10:23:11 -04:00
|
|
|
{
|
|
|
|
printRsItemBase(out, "RsFileListsSyncDirItem", indent);
|
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
|
|
|
|
printIndent(out , int_Indent); out << "Entry index: " << entry_index << std::endl;
|
|
|
|
printIndent(out , int_Indent); out << "Flags: " << (uint32_t) flags << std::endl;
|
|
|
|
printIndent(out , int_Indent); out << "Last modf TS: " << last_known_recurs_modf_TS << std::endl;
|
|
|
|
printIndent(out , int_Indent); out << "request id: " << std::hex << request_id << std::dec << std::endl;
|
|
|
|
printIndent(out , int_Indent); out << "Data size: " << directory_content_data.bin_len << std::endl;
|
|
|
|
|
|
|
|
printRsItemEnd(out ,"RsFileListsSyncDirItem", indent);
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|