mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
removed old unused serialization code
This commit is contained in:
parent
861dc165f7
commit
4bee52c406
15 changed files with 0 additions and 6310 deletions
|
@ -57,143 +57,5 @@ void RsBwCtrlAllowedItem::serial_process(RsGenericSerializer::SerializeJob j,RsG
|
|||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,TLV_TYPE_UINT32_BW,allowedBw,"allowedBw") ;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
/* serialise the data to the buffer */
|
||||
bool RsBwCtrlSerialiser::serialiseAllowed(RsBwCtrlAllowedItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
uint32_t tlvsize = sizeAllowed(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (*pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsBwCtrlSerialiser::serialiseRoute() Header: " << ok << std::endl;
|
||||
std::cerr << "RsBwCtrlSerialiser::serialiseRoute() Size: " << tlvsize << std::endl;
|
||||
#endif
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= SetTlvUInt32(data, tlvsize, &offset, TLV_TYPE_UINT32_BW, item->allowedBw);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsBwCtrlSerialiser::serialiseRoute() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsBwCtrlAllowedItem *RsBwCtrlSerialiser::deserialiseAllowed(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t tlvsize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_BWCTRL != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_BWCTRL_ALLOWED_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*pktsize < tlvsize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsBwCtrlAllowedItem *item = new RsBwCtrlAllowedItem();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* get mandatory parts first */
|
||||
ok &= GetTlvUInt32(data, tlvsize, &offset, TLV_TYPE_UINT32_BW, &(item->allowedBw));
|
||||
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
uint32_t RsBwCtrlSerialiser::size(RsItem *i)
|
||||
{
|
||||
RsBwCtrlAllowedItem *dri;
|
||||
|
||||
if (NULL != (dri = dynamic_cast<RsBwCtrlAllowedItem *>(i)))
|
||||
{
|
||||
return sizeAllowed(dri);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool RsBwCtrlSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
|
||||
{
|
||||
RsBwCtrlAllowedItem *dri;
|
||||
|
||||
if (NULL != (dri = dynamic_cast<RsBwCtrlAllowedItem *>(i)))
|
||||
{
|
||||
return serialiseAllowed(dri, data, pktsize);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem *RsBwCtrlSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_BWCTRL != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
case RS_PKT_SUBTYPE_BWCTRL_ALLOWED_ITEM:
|
||||
return deserialiseAllowed(data, pktsize);
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -140,30 +140,6 @@ class RsPeerBandwidthLimitsItem : public RsItem
|
|||
std::map<RsPgpId,PeerBandwidthLimits> peers ;
|
||||
};
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
class RsPeerGroupItem_deprecated : public RsItem
|
||||
{
|
||||
public:
|
||||
RsPeerGroupItem_deprecated();
|
||||
virtual ~RsPeerGroupItem_deprecated();
|
||||
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
/* set data from RsGroupInfo to RsPeerGroupItem */
|
||||
void set(RsGroupInfo &groupInfo);
|
||||
/* get data from RsGroupInfo to RsPeerGroupItem */
|
||||
void get(RsGroupInfo &groupInfo);
|
||||
|
||||
/* Mandatory */
|
||||
std::string id;
|
||||
std::string name;
|
||||
uint32_t flag;
|
||||
|
||||
RsTlvPgpIdSet pgpList;
|
||||
};
|
||||
#endif
|
||||
|
||||
class RsNodeGroupItem: public RsItem
|
||||
{
|
||||
public:
|
||||
|
@ -216,51 +192,6 @@ class RsPeerConfigSerialiser: public RsConfigSerializer
|
|||
|
||||
/**************************************************************************/
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
class RsCacheConfig: public RsItem
|
||||
{
|
||||
public:
|
||||
RsCacheConfig()
|
||||
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
|
||||
RS_PKT_TYPE_CACHE_CONFIG,
|
||||
RS_PKT_SUBTYPE_DEFAULT)
|
||||
{ return; }
|
||||
virtual ~RsCacheConfig();
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
RsPeerId pid; /* Mandatory */
|
||||
uint16_t cachetypeid; /* Mandatory */
|
||||
uint16_t cachesubid; /* Mandatory */
|
||||
|
||||
std::string path; /* Mandatory */
|
||||
std::string name; /* Mandatory */
|
||||
RsFileHash hash; /* Mandatory */
|
||||
uint64_t size; /* Mandatory */
|
||||
|
||||
uint32_t recvd; /* Mandatory */
|
||||
};
|
||||
|
||||
|
||||
class RsCacheConfigSerialiser: public RsSerialType
|
||||
{
|
||||
public:
|
||||
RsCacheConfigSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
|
||||
RS_PKT_TYPE_CACHE_CONFIG)
|
||||
{ return; }
|
||||
|
||||
virtual ~RsCacheConfigSerialiser();
|
||||
|
||||
virtual uint32_t size(RsItem *);
|
||||
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
|
||||
virtual RsItem * deserialise(void *data, uint32_t *size);
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
class RsFileTransfer: public RsItem
|
||||
{
|
||||
public:
|
||||
|
@ -306,26 +237,6 @@ class RsFileTransfer: public RsItem
|
|||
|
||||
const uint32_t RS_FILE_CONFIG_CLEANUP_DELETE = 0x0001;
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
/* Used by ft / extralist / configdirs / anyone who wants a basic file */
|
||||
class RsFileConfigItem_deprecated: public RsItem
|
||||
{
|
||||
public:
|
||||
RsFileConfigItem_deprecated()
|
||||
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
|
||||
RS_PKT_TYPE_FILE_CONFIG,
|
||||
RS_PKT_SUBTYPE_FILE_ITEM_deprecated)
|
||||
{}
|
||||
virtual ~RsFileConfigItem_deprecated() {}
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
RsTlvFileItem file;
|
||||
uint32_t flags;
|
||||
std::list<std::string> parent_groups ;
|
||||
};
|
||||
#endif
|
||||
|
||||
class RsFileConfigItem: public RsItem
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -46,403 +46,14 @@ RsItem *RsGxsCommentSerialiser::create_item(uint16_t service_id,uint8_t item_sub
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
|
||||
uint32_t RsGxsCommentSerialiser::size(RsItem *item)
|
||||
{
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
std::cerr << "RsGxsCommentSerialiser::size()" << std::endl;
|
||||
#endif
|
||||
|
||||
RsGxsCommentItem* com_item = NULL;
|
||||
RsGxsVoteItem* vote_item = NULL;
|
||||
|
||||
if((com_item = dynamic_cast<RsGxsCommentItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsCommentItem(com_item);
|
||||
}
|
||||
else if((vote_item = dynamic_cast<RsGxsVoteItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsVoteItem(vote_item);
|
||||
}
|
||||
std::cerr << "RsGxsCommentSerialiser::size() ERROR invalid item" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool RsGxsCommentSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
std::cerr << "RsGxsCommentSerialiser::serialise()" << std::endl;
|
||||
#endif
|
||||
|
||||
RsGxsCommentItem* com_item = NULL;
|
||||
RsGxsVoteItem* vote_item = NULL;
|
||||
|
||||
if((com_item = dynamic_cast<RsGxsCommentItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsCommentItem(com_item, data, size);
|
||||
}
|
||||
else if((vote_item = dynamic_cast<RsGxsVoteItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsVoteItem(vote_item, data, size);
|
||||
}
|
||||
std::cerr << "RsGxsCommentSerialiser::serialise() ERROR invalid item" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem* RsGxsCommentSerialiser::deserialise(void* data, uint32_t* size)
|
||||
{
|
||||
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
std::cerr << "RsGxsCommentSerialiser::deserialise()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(getRsItemService(PacketId()) != getRsItemService(rstype)))
|
||||
{
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
std::cerr << "RsGxsCommentSerialiser::deserialise() ERROR Wrong Type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
|
||||
case RS_PKT_SUBTYPE_GXSCOMMENT_COMMENT_ITEM:
|
||||
return deserialiseGxsCommentItem(data, size);
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_GXSCOMMENT_VOTE_ITEM:
|
||||
return deserialiseGxsVoteItem(data, size);
|
||||
break;
|
||||
default:
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
std::cerr << "RsGxsCommentSerialiser::deserialise(): unknown subtype";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
|
||||
void RsGxsCommentItem::clear()
|
||||
{
|
||||
mMsg.mComment.clear();
|
||||
}
|
||||
|
||||
std::ostream& RsGxsCommentItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsCommentItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Comment: " << mMsg.mComment << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsCommentItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsCommentSerialiser::sizeGxsCommentItem(RsGxsCommentItem *item)
|
||||
{
|
||||
|
||||
const RsGxsComment& msg = item->mMsg;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(msg.mComment); // mMsg.
|
||||
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
std::cerr << "RsGxsCommentSerialiser::sizeGxsCommentItem() is: " << s << std::endl;
|
||||
msg.print(std::cerr);
|
||||
#endif
|
||||
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void RsGxsCommentItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,1,mMsg.mComment,"mMsg.mComment") ;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
bool RsGxsCommentSerialiser::serialiseGxsCommentItem(RsGxsCommentItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
std::cerr << "RsGxsCommentSerialiser::serialiseGxsCommentItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsCommentItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize)
|
||||
{
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
std::cerr << "RsGxsCommentSerialiser::serialiseGxsCommentItem() Failed size too small" << std::endl;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsCommentItem */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mMsg.mComment);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
std::cerr << "RsGxsCommentSerialiser::serialiseGxsCommentItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsCommentSerialiser::serialiseGxsCommentItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsCommentItem* RsGxsCommentSerialiser::deserialiseGxsCommentItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
std::cerr << "RsGxsCommentSerialiser::deserialiseGxsCommentItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(getRsItemService(PacketId()) != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSCOMMENT_COMMENT_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
std::cerr << "RsGxsCommentSerialiser::deserialiseGxsCommentItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
std::cerr << "RsGxsCommentSerialiser::deserialiseGxsCommentItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsCommentItem* item = new RsGxsCommentItem(getRsItemService(PacketId()));
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->mMsg.mComment);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
std::cerr << "RsGxsCommentSerialiser::deserialiseGxsCommentItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
std::cerr << "RsGxsCommentSerialiser::deserialiseGxsCommentItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
|
||||
void RsGxsVoteItem::clear()
|
||||
{
|
||||
mMsg.mVoteType = 0;
|
||||
}
|
||||
|
||||
std::ostream& RsGxsVoteItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsVoteItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "VoteType: " << mMsg.mVoteType << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsVoteItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsCommentSerialiser::sizeGxsVoteItem(RsGxsVoteItem */*item*/)
|
||||
{
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += 4; // vote flags.
|
||||
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
|
||||
void RsGxsVoteItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mMsg.mVoteType,"mMsg.mVoteType") ;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
bool RsGxsCommentSerialiser::serialiseGxsVoteItem(RsGxsVoteItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
std::cerr << "RsGxsCommentSerialiser::serialiseGxsVoteItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsVoteItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize)
|
||||
{
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
std::cerr << "RsGxsCommentSerialiser::serialiseGxsVoteItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsVoteItem */
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->mMsg.mVoteType);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
std::cerr << "RsGxsCommentSerialiser::serialiseGxsVoteItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsCommentSerialiser::serialiseGxsVoteItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsVoteItem* RsGxsCommentSerialiser::deserialiseGxsVoteItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
std::cerr << "RsGxsCommentSerialiser::deserialiseGxsVoteItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(getRsItemService(PacketId()) != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSCOMMENT_VOTE_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
std::cerr << "RsGxsCommentSerialiser::deserialiseGxsVoteItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
std::cerr << "RsGxsCommentSerialiser::deserialiseGxsVoteItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsVoteItem* item = new RsGxsVoteItem(getRsItemService(PacketId()));
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->mMsg.mVoteType));
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
std::cerr << "RsGxsCommentSerialiser::deserialiseGxsVoteItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXSCOMMENT_DEBUG
|
||||
std::cerr << "RsGxsCommentSerialiser::deserialiseGxsVoteItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
#endif
|
||||
|
|
|
@ -60,172 +60,12 @@ void RsGxsIdGroupItem::clear()
|
|||
mRecognTags.clear();
|
||||
mImage.TlvClear();
|
||||
}
|
||||
#ifdef TO_REMOVE
|
||||
RsItem* RsGxsIdSerialiser::deserialise(void* data, uint32_t* size)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype)))
|
||||
return NULL; /* wrong type */
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
case RS_PKT_SUBTYPE_GXSID_GROUP_ITEM: return deserialise_GxsIdGroupItem(data, size);
|
||||
case RS_PKT_SUBTYPE_GXSID_LOCAL_INFO_ITEM: return deserialise_GxsIdLocalInfoItem(data, size);
|
||||
#if 0
|
||||
case RS_PKT_SUBTYPE_GXSID_OPINION_ITEM: return deserialise_GxsIdOpinionItem(data, size);
|
||||
case RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM: return deserialise_GxsIdCommentItem(data, size);
|
||||
#endif
|
||||
default:
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialise(): unknown subtype";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool RsGxsIdItem::serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsize, uint32_t& offset)
|
||||
{
|
||||
tlvsize = serial_size() ;
|
||||
offset = 0;
|
||||
|
||||
if (pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
pktsize = tlvsize;
|
||||
|
||||
if(!setRsItemHeader(data, tlvsize, PacketId(), tlvsize))
|
||||
{
|
||||
std::cerr << "RsItem::serialise_header(): ERROR. Not enough size!" << std::endl;
|
||||
return false ;
|
||||
}
|
||||
offset += 8;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
uint32_t RsGxsIdLocalInfoItem::serial_size()
|
||||
{
|
||||
uint32_t s = 8 ; // header
|
||||
s += 4 ; // number of items
|
||||
s += mTimeStamps.size() * (RsGxsId::SIZE_IN_BYTES + 8) ;
|
||||
s += 4 ; // number of contacts
|
||||
s += mContacts.size() * RsGxsId::SIZE_IN_BYTES ;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
std::ostream& RsGxsIdLocalInfoItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsIdLocalInfoItem", indent);
|
||||
|
||||
// convert from binary to hex.
|
||||
for(std::map<RsGxsId,time_t>::const_iterator it(mTimeStamps.begin());it!=mTimeStamps.end();++it)
|
||||
out << it->first << " : " << it->second << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsIdLocalInfoItem", indent);
|
||||
return out;
|
||||
}
|
||||
std::ostream& RsGxsIdGroupItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsIdGroupItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "MetaData: " << meta << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "PgpIdHash: " << mPgpIdHash << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
|
||||
std::string signhex;
|
||||
// convert from binary to hex.
|
||||
for(unsigned int i = 0; i < mPgpIdSign.length(); i++)
|
||||
{
|
||||
rs_sprintf_append(signhex, "%02x", (uint32_t) ((uint8_t) mPgpIdSign[i]));
|
||||
}
|
||||
out << "PgpIdSign: " << signhex << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "RecognTags:" << std::endl;
|
||||
|
||||
RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, mRecognTags);
|
||||
set.print(out, int_Indent + 2);
|
||||
|
||||
printRsItemEnd(out ,"RsGxsIdGroupItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsIdGroupItem::serial_size()
|
||||
{
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += Sha1CheckSum::SIZE_IN_BYTES;
|
||||
s += GetTlvStringSize(mPgpIdSign);
|
||||
|
||||
RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, mRecognTags);
|
||||
s += set.TlvSize();
|
||||
s += mImage.TlvSize() ;
|
||||
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
|
||||
void RsGxsIdLocalInfoItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,mTimeStamps,"mTimeStamps") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,mContacts,"mContacts") ;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
bool RsGxsIdLocalInfoItem::serialise(void *data, uint32_t& size)
|
||||
{
|
||||
uint32_t tlvsize,offset=0;
|
||||
bool ok = true;
|
||||
|
||||
if(!serialise_header(data,size,tlvsize,offset))
|
||||
return false ;
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mTimeStamps.size()) ;
|
||||
|
||||
for(std::map<RsGxsId,time_t>::const_iterator it = mTimeStamps.begin();it!=mTimeStamps.end();++it)
|
||||
{
|
||||
ok &= it->first.serialise(data,tlvsize,offset) ;
|
||||
ok &= setRawTimeT(data,tlvsize,&offset,it->second) ;
|
||||
}
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mContacts.size()) ;
|
||||
|
||||
for(std::set<RsGxsId>::const_iterator it(mContacts.begin());it!=mContacts.end();++it)
|
||||
ok &= (*it).serialise(data,tlvsize,offset) ;
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdGroupItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
#endif
|
||||
|
||||
void RsGxsIdGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,mPgpIdHash,"mPgpIdHash") ;
|
||||
|
@ -243,43 +83,6 @@ void RsGxsIdGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGene
|
|||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,mImage,"mImage") ;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
bool RsGxsIdGroupItem::serialise(void *data, uint32_t& size)
|
||||
{
|
||||
uint32_t tlvsize,offset=0;
|
||||
bool ok = true;
|
||||
|
||||
if(!serialise_header(data,size,tlvsize,offset))
|
||||
return false ;
|
||||
|
||||
/* GxsIdGroupItem */
|
||||
ok &= mPgpIdHash.serialise(data, tlvsize, offset);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_SIGN, mPgpIdSign);
|
||||
|
||||
RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, mRecognTags);
|
||||
ok &= set.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
ok &= mImage.SetTlv(data,tlvsize,&offset) ;
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdGroupItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool RsGxsIdGroupItem::fromGxsIdGroup(RsGxsIdGroup &group, bool moveImage)
|
||||
{
|
||||
clear();
|
||||
|
@ -320,422 +123,3 @@ bool RsGxsIdGroupItem::toGxsIdGroup(RsGxsIdGroup &group, bool moveImage)
|
|||
return true ;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
RsGxsIdGroupItem* RsGxsIdSerialiser::deserialise_GxsIdGroupItem(void *data, uint32_t *size)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSID_GROUP_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsIdGroupItem* item = new RsGxsIdGroupItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= item->mPgpIdHash.deserialise(data, rssize, offset);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_SIGN, item->mPgpIdSign);
|
||||
|
||||
RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, item->mRecognTags);
|
||||
ok &= set.GetTlv(data, rssize, &offset);
|
||||
|
||||
// image is optional,so that we can continue reading old items.
|
||||
if(offset < rssize)
|
||||
ok &= item->mImage.GetTlv(data,rssize,&offset) ;
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
RsGxsIdLocalInfoItem *RsGxsIdSerialiser::deserialise_GxsIdLocalInfoItem(void *data, uint32_t *size)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSID_LOCAL_INFO_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsIdLocalInfoItem* item = new RsGxsIdLocalInfoItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
uint32_t n=0 ;
|
||||
ok &= getRawUInt32(data, rssize, &offset, &n) ;
|
||||
|
||||
for(uint32_t i=0;ok && i<n;++i)
|
||||
{
|
||||
RsGxsId gxsid ;
|
||||
time_t TS ;
|
||||
|
||||
ok &= gxsid.deserialise(data,rssize,offset) ;
|
||||
ok &= getRawTimeT(data,rssize,&offset,TS) ;
|
||||
|
||||
item->mTimeStamps[gxsid] = TS ;
|
||||
}
|
||||
|
||||
if (offset < rssize) // backward compatibility, making that section optional.
|
||||
{
|
||||
ok &= getRawUInt32(data, rssize, &offset, &n) ;
|
||||
RsGxsId gxsid ;
|
||||
|
||||
for(uint32_t i=0;ok && i<n;++i)
|
||||
{
|
||||
ok &= gxsid.deserialise(data,rssize,offset) ;
|
||||
|
||||
item->mContacts.insert(gxsid) ;
|
||||
}
|
||||
}
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
#if 0
|
||||
|
||||
void RsGxsIdOpinionItem::clear()
|
||||
{
|
||||
opinion.mOpinion = 0;
|
||||
opinion.mReputation = 0;
|
||||
opinion.mComment = "";
|
||||
}
|
||||
|
||||
std::ostream& RsGxsIdOpinionItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsIdOpinionItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Opinion: " << opinion.mOpinion << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "Reputation: " << opinion.mReputation << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "Comment: " << opinion.mComment << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsIdOpinionItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsIdOpinionItem::serial_size()
|
||||
{
|
||||
|
||||
const RsGxsIdOpinion& opinion = item->opinion;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += 4; // mOpinion.
|
||||
s += 4; // mReputation.
|
||||
s += GetTlvStringSize(opinion.mComment);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsIdOpinionItem::serialise(void *data, uint32_t *size)
|
||||
{
|
||||
uint32_t tlvsize,offset=0;
|
||||
bool ok = true;
|
||||
|
||||
if(!serialise_header(data,size,tlvsize,offset))
|
||||
return false ;
|
||||
|
||||
/* GxsIdOpinionItem */
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->opinion.mOpinion);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->opinion.mReputation);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_COMMENT, item->opinion.mComment);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdOpinionItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsIdOpinionItem* RsGxsIdSerialiser::deserialise_GxsIdOpinionItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSID_OPINION_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsIdOpinionItem* item = new RsGxsIdOpinionItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->opinion.mOpinion));
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->opinion.mReputation));
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_COMMENT, item->opinion.mComment);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
|
||||
void RsGxsIdCommentItem::clear()
|
||||
{
|
||||
comment.mComment.clear();
|
||||
}
|
||||
|
||||
std::ostream& RsGxsIdCommentItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsIdCommentItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Comment: " << comment.mComment << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsIdCommentItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsIdCommentItem::serial_size()
|
||||
{
|
||||
|
||||
const RsGxsIdComment& comment = item->comment;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(comment.mComment);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsIdCommentItem::serialise(void *data, uint32_t *size)
|
||||
{
|
||||
uint32_t tlvsize,offset=0;
|
||||
bool ok = true;
|
||||
|
||||
if(!serialise_header(data,size,tlvsize,offset))
|
||||
return false ;
|
||||
|
||||
/* GxsIdCommentItem */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_COMMENT, item->comment.mComment);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdCommentItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsIdCommentItem* RsGxsIdSerialiser::deserialise_GxsIdCommentItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsIdCommentItem* item = new RsGxsIdCommentItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_COMMENT, item->comment.mComment);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -63,65 +63,6 @@ void RsGxsRecognReqItem::clear()
|
|||
sign.TlvClear();
|
||||
|
||||
}
|
||||
#ifdef TO_REMOVE
|
||||
RsGxsRecognReqItem::~RsGxsRecognReqItem()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
std::ostream &RsGxsRecognReqItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsRecognReqItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "issued_at: " << issued_at << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "period: " << period << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "tag_class: " << tag_class << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "tag_type: " << tag_type << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "identity: " << identity << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "nickname: " << nickname << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "comment: " << comment << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "signature: " << std::endl;
|
||||
sign.print(out, int_Indent + 2);
|
||||
|
||||
printRsItemEnd(out, "RsGxsRecognReqItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsRecognSerialiser::sizeReq(RsGxsRecognReqItem *item)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += 4; // issued_at;
|
||||
s += 4; // period;
|
||||
s += 2; // tag_class;
|
||||
s += 2; // tag_type;
|
||||
s += item->identity.serial_size();
|
||||
s += GetTlvStringSize(item->nickname);
|
||||
s += GetTlvStringSize(item->comment);
|
||||
s += item->sign.TlvSize();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void RsGxsRecognReqItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,issued_at ,"issued_at") ;
|
||||
|
@ -134,122 +75,6 @@ void RsGxsRecognReqItem::serial_process(RsGenericSerializer::SerializeJob j,RsGe
|
|||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,sign ,"sign") ;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
/* serialise the data to the buffer */
|
||||
bool RsGxsRecognSerialiser::serialiseReq(RsGxsRecognReqItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
uint32_t tlvsize = sizeReq(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (*pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsRecognSerialiser::serialiseReq() Header: " << ok << std::endl;
|
||||
std::cerr << "RsGxsRecognSerialiser::serialiseReq() Size: " << tlvsize << std::endl;
|
||||
#endif
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->issued_at);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->period);
|
||||
ok &= setRawUInt16(data, tlvsize, &offset, item->tag_class);
|
||||
ok &= setRawUInt16(data, tlvsize, &offset, item->tag_type);
|
||||
|
||||
|
||||
ok &= item->identity.serialise(data, tlvsize, offset);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->nickname);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->comment);
|
||||
|
||||
ok &= item->sign.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsRecognSerialiser::serialiseReq() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsRecognReqItem *RsGxsRecognSerialiser::deserialiseReq(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t tlvsize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_GXS_RECOGN != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_RECOGN_REQ != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*pktsize < tlvsize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsGxsRecognReqItem *item = new RsGxsRecognReqItem();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &(item->issued_at));
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &(item->period));
|
||||
ok &= getRawUInt16(data, tlvsize, &offset, &(item->tag_class));
|
||||
ok &= getRawUInt16(data, tlvsize, &offset, &(item->tag_type));
|
||||
|
||||
|
||||
ok &= item->identity.serialise(data, tlvsize, offset);
|
||||
ok &= GetTlvString(data, tlvsize, &offset, 1, item->nickname);
|
||||
ok &= GetTlvString(data, tlvsize, &offset, 1, item->comment);
|
||||
ok &= item->sign.GetTlv(data, tlvsize, &offset);
|
||||
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsGxsRecognTagItem::~RsGxsRecognTagItem()
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
void RsGxsRecognTagItem::clear()
|
||||
{
|
||||
valid_from = 0;
|
||||
|
@ -264,56 +89,6 @@ void RsGxsRecognTagItem::clear()
|
|||
sign.TlvClear();
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
std::ostream &RsGxsRecognTagItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsRecognTagItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "valid_from: " << valid_from << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "valid_to: " << valid_to << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "tag_class: " << tag_class << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "tag_type: " << tag_type << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "identity: " << identity << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "nickname: " << nickname << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "signature: " << std::endl;
|
||||
sign.print(out, int_Indent + 2);
|
||||
|
||||
printRsItemEnd(out, "RsGxsRecognTagItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsRecognSerialiser::sizeTag(RsGxsRecognTagItem *item)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += 4; // valid_from;
|
||||
s += 4; // valid_to;
|
||||
s += 2; // tag_class;
|
||||
s += 2; // tag_type;
|
||||
|
||||
s += item->identity.serial_size();
|
||||
s += GetTlvStringSize(item->nickname);
|
||||
|
||||
s += item->sign.TlvSize();
|
||||
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
|
||||
void RsGxsRecognTagItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,valid_from ,"valid_from") ;
|
||||
|
@ -325,122 +100,6 @@ void RsGxsRecognTagItem::serial_process(RsGenericSerializer::SerializeJob j,RsGe
|
|||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,sign ,"sign") ;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
/* serialise the data to the buffer */
|
||||
bool RsGxsRecognSerialiser::serialiseTag(RsGxsRecognTagItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
uint32_t tlvsize = sizeTag(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (*pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsRecognSerialiser::serialiseTag() Header: " << ok << std::endl;
|
||||
std::cerr << "RsGxsRecognSerialiser::serialiseTag() Size: " << tlvsize << std::endl;
|
||||
#endif
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->valid_from);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->valid_to);
|
||||
|
||||
ok &= setRawUInt16(data, tlvsize, &offset, item->tag_class);
|
||||
ok &= setRawUInt16(data, tlvsize, &offset, item->tag_type);
|
||||
|
||||
|
||||
ok &= item->identity.serialise(data, tlvsize, offset);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->nickname);
|
||||
|
||||
ok &= item->sign.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsRecognSerialiser::serialiseTag() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsRecognTagItem *RsGxsRecognSerialiser::deserialiseTag(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t tlvsize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_GXS_RECOGN != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_RECOGN_TAG != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*pktsize < tlvsize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsGxsRecognTagItem *item = new RsGxsRecognTagItem();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &(item->valid_from));
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &(item->valid_to));
|
||||
|
||||
ok &= getRawUInt16(data, tlvsize, &offset, &(item->tag_class));
|
||||
ok &= getRawUInt16(data, tlvsize, &offset, &(item->tag_type));
|
||||
|
||||
|
||||
ok &= item->identity.deserialise(data, tlvsize, offset);
|
||||
ok &= GetTlvString(data, tlvsize, &offset, 1, item->nickname);
|
||||
ok &= item->sign.GetTlv(data, tlvsize, &offset);
|
||||
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsGxsRecognSignerItem::~RsGxsRecognSignerItem()
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
void RsGxsRecognSignerItem::clear()
|
||||
{
|
||||
signing_classes.TlvClear();
|
||||
|
@ -448,43 +107,6 @@ void RsGxsRecognSignerItem::clear()
|
|||
sign.TlvClear();
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
std::ostream &RsGxsRecognSignerItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsRecognSignerItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "signing_classes: " << std::endl;
|
||||
signing_classes.print(out, int_Indent + 2);
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "key: " << std::endl;
|
||||
key.print(out, int_Indent + 2);
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "signature: " << std::endl;
|
||||
sign.print(out, int_Indent + 2);
|
||||
|
||||
|
||||
printRsItemEnd(out, "RsGxsRecognSignerItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
uint32_t RsGxsRecognSerialiser::sizeSigner(RsGxsRecognSignerItem *item)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += item->signing_classes.TlvSize();
|
||||
s += item->key.TlvSize();
|
||||
s += item->sign.TlvSize();
|
||||
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
|
||||
void RsGxsRecognSignerItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,signing_classes ,"signing_classes") ;
|
||||
|
@ -492,175 +114,5 @@ void RsGxsRecognSignerItem::serial_process(RsGenericSerializer::SerializeJob j,R
|
|||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,sign ,"sign") ;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
/* serialise the data to the buffer */
|
||||
bool RsGxsRecognSerialiser::serialiseSigner(RsGxsRecognSignerItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
uint32_t tlvsize = sizeSigner(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (*pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsRecognSerialiser::serialiseSigner() Header: " << ok << std::endl;
|
||||
std::cerr << "RsGxsRecognSerialiser::serialiseSigner() Size: " << tlvsize << std::endl;
|
||||
#endif
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= item->signing_classes.SetTlv(data, tlvsize, &offset);
|
||||
ok &= item->key.SetTlv(data, tlvsize, &offset);
|
||||
ok &= item->sign.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsRecognSerialiser::serialiseSigner() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsRecognSignerItem *RsGxsRecognSerialiser::deserialiseSigner(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t tlvsize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_GXS_RECOGN != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_RECOGN_SIGNER != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*pktsize < tlvsize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsGxsRecognSignerItem *item = new RsGxsRecognSignerItem();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= item->signing_classes.GetTlv(data, tlvsize, &offset);
|
||||
ok &= item->key.GetTlv(data, tlvsize, &offset);
|
||||
ok &= item->sign.GetTlv(data, tlvsize, &offset);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
uint32_t RsGxsRecognSerialiser::size(RsItem *i)
|
||||
{
|
||||
RsGxsRecognReqItem *rqi;
|
||||
RsGxsRecognTagItem *rti;
|
||||
RsGxsRecognSignerItem *rsi;
|
||||
|
||||
if (NULL != (rqi = dynamic_cast<RsGxsRecognReqItem *>(i)))
|
||||
{
|
||||
return sizeReq(rqi);
|
||||
}
|
||||
if (NULL != (rti = dynamic_cast<RsGxsRecognTagItem *>(i)))
|
||||
{
|
||||
return sizeTag(rti);
|
||||
}
|
||||
if (NULL != (rsi = dynamic_cast<RsGxsRecognSignerItem *>(i)))
|
||||
{
|
||||
return sizeSigner(rsi);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool RsGxsRecognSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
|
||||
{
|
||||
RsGxsRecognReqItem *rri;
|
||||
RsGxsRecognTagItem *rti;
|
||||
RsGxsRecognSignerItem *rsi;
|
||||
|
||||
if (NULL != (rri = dynamic_cast<RsGxsRecognReqItem *>(i)))
|
||||
{
|
||||
return serialiseReq(rri, data, pktsize);
|
||||
}
|
||||
if (NULL != (rti = dynamic_cast<RsGxsRecognTagItem *>(i)))
|
||||
{
|
||||
return serialiseTag(rti, data, pktsize);
|
||||
}
|
||||
if (NULL != (rsi = dynamic_cast<RsGxsRecognSignerItem *>(i)))
|
||||
{
|
||||
return serialiseSigner(rsi, data, pktsize);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem *RsGxsRecognSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
{
|
||||
if (*pktsize < getRsPktBaseSize())
|
||||
return NULL ;
|
||||
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_GXS_RECOGN != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
case RS_PKT_SUBTYPE_RECOGN_REQ:
|
||||
return deserialiseReq(data, pktsize);
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_RECOGN_TAG:
|
||||
return deserialiseTag(data, pktsize);
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_RECOGN_SIGNER:
|
||||
return deserialiseSigner(data, pktsize);
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -88,525 +88,6 @@ void RsGxsReputationRequestItem::serial_process(RsGenericSerializer::SerializeJo
|
|||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLastUpdate,"mLastUpdate") ;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
// re-defined here, in order to avoid cross-includes
|
||||
#define REPUTATION_IDENTITY_FLAG_NEEDS_UPDATE 0x0100
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
std::ostream& RsGxsReputationConfigItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsReputationConfigItem", indent);
|
||||
|
||||
out << "mPeerId: " << mPeerId << std::endl;
|
||||
out << "last update: " << time(NULL) - mLatestUpdate << " secs ago." << std::endl;
|
||||
out << "last query : " << time(NULL) - mLastQuery << " secs ago." << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsReputationConfigItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream& RsGxsReputationSetItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsReputationSetItem", indent);
|
||||
|
||||
out << "GxsId: " << mGxsId << std::endl;
|
||||
out << "Owner: " << mOwnerNodeId << std::endl;
|
||||
out << "mOwnOpinion: " << mOwnOpinion << std::endl;
|
||||
out << "mOwnOpinionTS : " << time(NULL) - mOwnOpinionTS << " secs ago." << std::endl;
|
||||
out << "Opinions from neighbors: " << std::endl;
|
||||
|
||||
for(std::map<RsPeerId,uint32_t>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
|
||||
out << " " << it->first << ": " << it->second << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsReputationSetItem", indent);
|
||||
return out;
|
||||
}
|
||||
std::ostream& RsGxsReputationUpdateItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsReputationUpdateItem", indent);
|
||||
|
||||
out << "from: " << PeerId() << std::endl;
|
||||
out << "last update: " << time(NULL) - mLatestUpdate << " secs ago." << std::endl;
|
||||
|
||||
for(std::map<RsGxsId,uint32_t>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
|
||||
out << " " << it->first << ": " << it->second << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsReputationUpdateItem", indent);
|
||||
return out;
|
||||
}
|
||||
std::ostream& RsGxsReputationRequestItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsReputationRequestItem", indent);
|
||||
|
||||
out << "last update: " << time(NULL) - mLastUpdate << " secs ago." << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsReputationRequestItem", indent);
|
||||
return out;
|
||||
}
|
||||
std::ostream& RsGxsReputationBannedNodeSetItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsReputationBannedNodeSetItem", indent);
|
||||
|
||||
out << "last update: " << time(NULL) - mLastActivityTS << " secs ago." << std::endl;
|
||||
out << "PGP id: " << mPgpId << std::endl;
|
||||
out << "Known ids: " << mKnownIdentities.ids.size() << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsReputationRequestItem", indent);
|
||||
return out;
|
||||
}
|
||||
/*************************************************************************/
|
||||
|
||||
uint32_t RsGxsReputationConfigItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
|
||||
s += mPeerId.serial_size() ; // PeerId
|
||||
s += 4 ; // mLatestUpdate
|
||||
s += 4 ; // mLastQuery
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsGxsReputationSetItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
|
||||
s += mGxsId.serial_size() ;
|
||||
s += 4 ; // mOwnOpinion
|
||||
s += 4 ; // mOwnOpinionTS
|
||||
s += 4 ; // mIdentityFlags
|
||||
s += 4 ; // mLastUsedTS
|
||||
s += mOwnerNodeId.serial_size() ;
|
||||
|
||||
s += 4 ; // mOpinions.size()
|
||||
|
||||
s += (4+RsPeerId::serial_size()) * mOpinions.size() ;
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsGxsReputationBannedNodeSetItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
|
||||
s += RsPgpId::serial_size() ; // mPgpId
|
||||
s += 4 ; // mLastActivityTS;
|
||||
s += mKnownIdentities.TlvSize(); // mKnownIdentities
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsGxsReputationUpdateItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
|
||||
s += 4 ; // mLatestUpdate
|
||||
s += 4 ; // mOpinions.size();
|
||||
|
||||
s += (RsGxsId::serial_size() + 4) * mOpinions.size() ;
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsGxsReputationRequestItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
|
||||
s += 4 ; // mLastUpdate
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
bool RsGxsReputationConfigItem::serialise(void *data, uint32_t& pktsize) const
|
||||
{
|
||||
uint32_t tlvsize ;
|
||||
uint32_t offset=0;
|
||||
|
||||
if(!serialise_header(data,pktsize,tlvsize,offset))
|
||||
return false ;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= mPeerId.serialise(data,tlvsize,offset) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mLatestUpdate);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mLastQuery);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsGxsReputationConfigItem::serialisedata() size error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsGxsReputationSetItem::serialise(void *data, uint32_t& pktsize) const
|
||||
{
|
||||
uint32_t tlvsize ;
|
||||
uint32_t offset=0;
|
||||
|
||||
if(!serialise_header(data,pktsize,tlvsize,offset))
|
||||
return false ;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= mGxsId.serialise(data,tlvsize,offset) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mOwnOpinion);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mOwnOpinionTS);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mIdentityFlags) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mLastUsedTS) ;
|
||||
ok &= mOwnerNodeId.serialise(data,tlvsize,offset) ;
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mOpinions.size());
|
||||
|
||||
for(std::map<RsPeerId,uint32_t>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
|
||||
{
|
||||
ok &= it->first.serialise(data,tlvsize,offset) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, it->second) ;
|
||||
}
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsGxsReputationSetItem::serialisedata() size error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsGxsReputationBannedNodeSetItem::serialise(void *data, uint32_t& pktsize) const
|
||||
{
|
||||
uint32_t tlvsize ;
|
||||
uint32_t offset=0;
|
||||
|
||||
if(!serialise_header(data,pktsize,tlvsize,offset))
|
||||
return false ;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= mPgpId.serialise(data, tlvsize, offset) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mLastActivityTS);
|
||||
ok &= mKnownIdentities.SetTlv(data, tlvsize, &offset) ;
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsGxsReputationSetItem::serialisedata() size error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
bool RsGxsReputationUpdateItem::serialise(void *data, uint32_t& pktsize) const
|
||||
{
|
||||
uint32_t tlvsize ;
|
||||
uint32_t offset=0;
|
||||
|
||||
if(!serialise_header(data,pktsize,tlvsize,offset))
|
||||
return false ;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mLatestUpdate);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mOpinions.size());
|
||||
|
||||
for(std::map<RsGxsId,uint32_t>::const_iterator it(mOpinions.begin());ok && it!=mOpinions.end();++it)
|
||||
{
|
||||
ok &= it->first.serialise(data, tlvsize, offset) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, it->second) ;
|
||||
}
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsGxsReputationUpdateItem::serialisedata() size error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
/* serialise the data to the buffer */
|
||||
bool RsGxsReputationRequestItem::serialise(void *data, uint32_t& pktsize) const
|
||||
{
|
||||
uint32_t tlvsize ;
|
||||
uint32_t offset=0;
|
||||
|
||||
if(!serialise_header(data,pktsize,tlvsize,offset))
|
||||
return false ;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mLastUpdate);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsGxsReputationRequestItem::serialisedata() size error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
/*************************************************************************/
|
||||
|
||||
RsGxsReputationConfigItem *RsGxsReputationSerialiser::deserialiseReputationConfigItem(void *data,uint32_t size)
|
||||
{
|
||||
uint32_t offset = 8; // skip the header
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
bool ok = true ;
|
||||
|
||||
RsGxsReputationConfigItem *item = new RsGxsReputationConfigItem() ;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= item->mPeerId.deserialise(data, size, offset) ;
|
||||
ok &= getRawUInt32(data, size, &offset, &item->mLatestUpdate);
|
||||
ok &= getRawUInt32(data, size, &offset, &item->mLastQuery);
|
||||
|
||||
if (offset != rssize || !ok)
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
||||
delete item;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
RsGxsReputationBannedNodeSetItem *RsGxsReputationSerialiser::deserialiseReputationBannedNodeSetItem(void *data,uint32_t size)
|
||||
{
|
||||
uint32_t offset = 8; // skip the header
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
bool ok = true ;
|
||||
|
||||
RsGxsReputationBannedNodeSetItem *item = new RsGxsReputationBannedNodeSetItem() ;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= item->mPgpId.deserialise(data, size, offset) ;
|
||||
ok &= getRawUInt32(data, size, &offset, &item->mLastActivityTS);
|
||||
ok &= item->mKnownIdentities.GetTlv(data,size,&offset) ;
|
||||
|
||||
if (offset != rssize || !ok)
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
||||
delete item;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem_deprecated(void *data,uint32_t tlvsize)
|
||||
{
|
||||
uint32_t offset = 8; // skip the header
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
bool ok = true ;
|
||||
|
||||
RsGxsReputationSetItem *item = new RsGxsReputationSetItem() ;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= item->mGxsId.deserialise(data, tlvsize, offset) ;
|
||||
|
||||
item->mOwnerNodeId.clear(); // clears up, for backward compat.
|
||||
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinion);
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinionTS);
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mIdentityFlags);
|
||||
|
||||
uint32_t S ;
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &S);
|
||||
|
||||
for(uint32_t i = 0; ok && (i < S); ++i)
|
||||
{
|
||||
RsPeerId pid ;
|
||||
uint32_t op ;
|
||||
|
||||
ok &= pid.deserialise(data, tlvsize, offset) ;
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &op);
|
||||
|
||||
if(ok)
|
||||
item->mOpinions[pid] = op ;
|
||||
}
|
||||
|
||||
if (offset != rssize || !ok)
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
||||
delete item;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
RsGxsReputationSetItem_deprecated3 *RsGxsReputationSerialiser::deserialiseReputationSetItem_deprecated3(void *data,uint32_t tlvsize)
|
||||
{
|
||||
uint32_t offset = 8; // skip the header
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
bool ok = true ;
|
||||
|
||||
RsGxsReputationSetItem_deprecated3 *item = new RsGxsReputationSetItem_deprecated3() ;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= item->mGxsId.deserialise(data, tlvsize, offset) ;
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinion);
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinionTS);
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mIdentityFlags);
|
||||
ok &= item->mOwnerNodeId.deserialise(data, tlvsize, offset) ;
|
||||
|
||||
uint32_t S ;
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &S);
|
||||
|
||||
for(uint32_t i = 0; ok && (i < S); ++i)
|
||||
{
|
||||
RsPeerId pid ;
|
||||
uint32_t op ;
|
||||
|
||||
ok &= pid.deserialise(data, tlvsize, offset) ;
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &op);
|
||||
|
||||
if(ok)
|
||||
item->mOpinions[pid] = op ;
|
||||
}
|
||||
|
||||
if (offset != rssize || !ok)
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
||||
delete item;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem(void *data,uint32_t tlvsize)
|
||||
{
|
||||
uint32_t offset = 8; // skip the header
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
bool ok = true ;
|
||||
|
||||
RsGxsReputationSetItem *item = new RsGxsReputationSetItem() ;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= item->mGxsId.deserialise(data, tlvsize, offset) ;
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinion);
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinionTS);
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mIdentityFlags);
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mLastUsedTS);
|
||||
ok &= item->mOwnerNodeId.deserialise(data, tlvsize, offset) ;
|
||||
|
||||
uint32_t S ;
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &S);
|
||||
|
||||
for(uint32_t i = 0; ok && (i < S); ++i)
|
||||
{
|
||||
RsPeerId pid ;
|
||||
uint32_t op ;
|
||||
|
||||
ok &= pid.deserialise(data, tlvsize, offset) ;
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &op);
|
||||
|
||||
if(ok)
|
||||
item->mOpinions[pid] = op ;
|
||||
}
|
||||
|
||||
if (offset != rssize || !ok)
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
||||
delete item;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
RsGxsReputationUpdateItem *RsGxsReputationSerialiser::deserialiseReputationUpdateItem(void *data,uint32_t tlvsize)
|
||||
{
|
||||
uint32_t offset = 8; // skip the header
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
bool ok = true ;
|
||||
|
||||
RsGxsReputationUpdateItem *item = new RsGxsReputationUpdateItem() ;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mLatestUpdate);
|
||||
|
||||
uint32_t S ;
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &S) ;
|
||||
|
||||
for(uint32_t i=0;ok && i<S;++i)
|
||||
{
|
||||
RsGxsId gid ;
|
||||
uint32_t op ;
|
||||
|
||||
ok &= gid.deserialise(data, tlvsize, offset) ;
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &op);
|
||||
|
||||
if(ok)
|
||||
item->mOpinions[gid] = op ;
|
||||
|
||||
}
|
||||
|
||||
if (offset != rssize || !ok)
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
||||
delete item;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
RsGxsReputationRequestItem *RsGxsReputationSerialiser::deserialiseReputationRequestItem(void *data,uint32_t tlvsize)
|
||||
{
|
||||
uint32_t offset = 8; // skip the header
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
bool ok = true ;
|
||||
|
||||
RsGxsReputationRequestItem *item = new RsGxsReputationRequestItem() ;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mLastUpdate);
|
||||
|
||||
if (offset != rssize || !ok)
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
||||
delete item;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsItem *RsGxsReputationSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_GXS_TYPE_REPUTATION != getRsItemService(rstype)))
|
||||
{
|
||||
std::cerr << "RsReputationSerialiser::deserialise(): wrong item type " << std::hex << rstype << std::dec << std::endl;
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM : return deserialiseReputationSetItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated3: return deserialiseReputationSetItem_deprecated3(data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_BANNED_NODE_SET_ITEM: return deserialiseReputationBannedNodeSetItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM : return deserialiseReputationUpdateItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM : return deserialiseReputationRequestItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM : return deserialiseReputationConfigItem (data, *pktsize);
|
||||
|
||||
default:
|
||||
std::cerr << "RsGxsReputationSerialiser::deserialise(): unknown item subtype " << std::hex<< rstype << std::dec << std::endl;
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsItem *RsGxsReputationSerialiser::create_item(uint16_t service,uint8_t subtype) const
|
||||
|
|
|
@ -72,225 +72,4 @@ RsHistoryMsgItem::RsHistoryMsgItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONF
|
|||
saveToDisc = true;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
|
||||
/*************************************************************************/
|
||||
RsHistoryMsgItem::~RsHistoryMsgItem()
|
||||
{
|
||||
}
|
||||
|
||||
void RsHistoryMsgItem::clear()
|
||||
{
|
||||
incoming = false;
|
||||
peerId.clear();
|
||||
peerName.clear();
|
||||
sendTime = 0;
|
||||
recvTime = 0;
|
||||
message.clear();
|
||||
msgId = 0;
|
||||
saveToDisc = true;
|
||||
}
|
||||
|
||||
std::ostream& RsHistoryMsgItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsHistoryMsgItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "chatPeerid: " << chatPeerId << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "incoming: " << (incoming ? "1" : "0") << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "peerId: " << peerId << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "peerName: " << peerName << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "sendTime: " << sendTime << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "recvTime: " << recvTime << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
std::string cnv_message(message.begin(), message.end());
|
||||
out << "message: " << cnv_message << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsHistoryMsgItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
RsHistorySerialiser::~RsHistorySerialiser()
|
||||
{
|
||||
}
|
||||
|
||||
uint32_t RsHistorySerialiser::sizeHistoryMsgItem(RsHistoryMsgItem* item)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += 2; /* version */
|
||||
s += item->chatPeerId.serial_size();
|
||||
s += 1; /* incoming */
|
||||
s += item->peerId.serial_size();
|
||||
s += GetTlvStringSize(item->peerName);
|
||||
s += 4; /* sendTime */
|
||||
s += 4; /* recvTime */
|
||||
s += GetTlvStringSize(item->message);
|
||||
|
||||
return s;
|
||||
}
|
||||
/* serialise the data to the buffer */
|
||||
bool RsHistorySerialiser::serialiseHistoryMsgItem(RsHistoryMsgItem* item, void* data, uint32_t* pktsize)
|
||||
{
|
||||
uint32_t tlvsize = sizeHistoryMsgItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (*pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsHistorySerialiser::serialiseItem() Header: " << ok << std::endl;
|
||||
std::cerr << "RsHistorySerialiser::serialiseItem() Size: " << tlvsize << std::endl;
|
||||
#endif
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= setRawUInt16(data, tlvsize, &offset, 0); // version
|
||||
ok &= item->chatPeerId.serialise(data, tlvsize, offset) ;
|
||||
uint8_t dummy = item->incoming ? 1 : 0;
|
||||
ok &= setRawUInt8(data, tlvsize, &offset, dummy);
|
||||
ok &= item->peerId.serialise(data, tlvsize, offset) ;
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->peerName);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->sendTime);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->recvTime);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, item->message);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsHistorySerialiser::serialiseItem() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsHistoryMsgItem *RsHistorySerialiser::deserialiseHistoryMsgItem(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
|
||||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
|
||||
(RS_PKT_TYPE_HISTORY_CONFIG != getRsItemType(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_DEFAULT != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*pktsize < rssize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*pktsize = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsHistoryMsgItem *item = new RsHistoryMsgItem();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* get mandatory parts first */
|
||||
uint16_t version = 0;
|
||||
ok &= getRawUInt16(data, rssize, &offset, &version);
|
||||
ok &= item->chatPeerId.deserialise(data, rssize, offset) ;
|
||||
uint8_t dummy;
|
||||
ok &= getRawUInt8(data, rssize, &offset, &dummy);
|
||||
item->incoming = (dummy == 1);
|
||||
ok &= item->peerId.deserialise(data, rssize, offset) ;
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->peerName);
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->sendTime));
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->recvTime));
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, item->message);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
uint32_t RsHistorySerialiser::size(RsItem *item)
|
||||
{
|
||||
RsHistoryMsgItem* hi;
|
||||
|
||||
if (NULL != (hi = dynamic_cast<RsHistoryMsgItem*>(item)))
|
||||
{
|
||||
return sizeHistoryMsgItem(hi);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool RsHistorySerialiser::serialise(RsItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
RsHistoryMsgItem* hi;
|
||||
|
||||
if (NULL != (hi = dynamic_cast<RsHistoryMsgItem*>(item)))
|
||||
{
|
||||
return serialiseHistoryMsgItem(hi, data, pktsize);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem* RsHistorySerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
|
||||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
|
||||
(RS_PKT_TYPE_HISTORY_CONFIG != getRsItemType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
case RS_PKT_SUBTYPE_DEFAULT:
|
||||
return deserialiseHistoryMsgItem(data, pktsize);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
#endif
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -63,339 +63,5 @@ void RsRttPongItem::serial_process(RsGenericSerializer::SerializeJob j,RsGeneric
|
|||
RsTypeSerializer::serial_process<uint64_t>(j,ctx,mPongTS,"mPongTS") ;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
RsRttPingItem::~RsRttPingItem()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void RsRttPingItem::clear()
|
||||
{
|
||||
mSeqNo = 0;
|
||||
mPingTS = 0;
|
||||
}
|
||||
|
||||
std::ostream& RsRttPingItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsRttPingItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
printIndent(out, int_Indent);
|
||||
out << "SeqNo: " << mSeqNo << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "PingTS: " << std::hex << mPingTS << std::dec << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsRttPingItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
RsRttPongItem::~RsRttPongItem()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void RsRttPongItem::clear()
|
||||
{
|
||||
mSeqNo = 0;
|
||||
mPingTS = 0;
|
||||
mPongTS = 0;
|
||||
}
|
||||
|
||||
|
||||
std::ostream& RsRttPongItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsRttPongItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
printIndent(out, int_Indent);
|
||||
out << "SeqNo: " << mSeqNo << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "PingTS: " << std::hex << mPingTS << std::dec << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "PongTS: " << std::hex << mPongTS << std::dec << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsRttPongItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
|
||||
uint32_t RsRttSerialiser::sizeRttPingItem(RsRttPingItem */*item*/)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += 4; /* seqno */
|
||||
s += 8; /* pingTS */
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* serialise the data to the buffer */
|
||||
bool RsRttSerialiser::serialiseRttPingItem(RsRttPingItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
uint32_t tlvsize = sizeRttPingItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (*pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsRttSerialiser::serialiseRttPingItem() Header: " << ok << std::endl;
|
||||
std::cerr << "RsRttSerialiser::serialiseRttPingItem() Size: " << tlvsize << std::endl;
|
||||
#endif
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->mSeqNo);
|
||||
ok &= setRawUInt64(data, tlvsize, &offset, item->mPingTS);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsRttSerialiser::serialiseRttPingItem() Size Error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsRttPingItem *RsRttSerialiser::deserialiseRttPingItem(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_RTT != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_RTT_PING != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*pktsize < rssize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*pktsize = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsRttPingItem *item = new RsRttPingItem();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* get mandatory parts first */
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->mSeqNo));
|
||||
ok &= getRawUInt64(data, rssize, &offset, &(item->mPingTS));
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
|
||||
uint32_t RsRttSerialiser::sizeRttPongItem(RsRttPongItem */*item*/)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += 4; /* seqno */
|
||||
s += 8; /* pingTS */
|
||||
s += 8; /* pongTS */
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* serialise the data to the buffer */
|
||||
bool RsRttSerialiser::serialiseRttPongItem(RsRttPongItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
uint32_t tlvsize = sizeRttPongItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (*pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsRttSerialiser::serialiseRttPongItem() Header: " << ok << std::endl;
|
||||
std::cerr << "RsRttSerialiser::serialiseRttPongItem() Size: " << tlvsize << std::endl;
|
||||
#endif
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->mSeqNo);
|
||||
ok &= setRawUInt64(data, tlvsize, &offset, item->mPingTS);
|
||||
ok &= setRawUInt64(data, tlvsize, &offset, item->mPongTS);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsRttSerialiser::serialiseRttPongItem() Size Error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsRttPongItem *RsRttSerialiser::deserialiseRttPongItem(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_RTT != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_RTT_PONG != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*pktsize < rssize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*pktsize = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsRttPongItem *item = new RsRttPongItem();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* get mandatory parts first */
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->mSeqNo));
|
||||
ok &= getRawUInt64(data, rssize, &offset, &(item->mPingTS));
|
||||
ok &= getRawUInt64(data, rssize, &offset, &(item->mPongTS));
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
uint32_t RsRttSerialiser::size(RsItem *i)
|
||||
{
|
||||
RsRttPingItem *ping;
|
||||
RsRttPongItem *pong;
|
||||
|
||||
if (NULL != (ping = dynamic_cast<RsRttPingItem *>(i)))
|
||||
{
|
||||
return sizeRttPingItem(ping);
|
||||
}
|
||||
else if (NULL != (pong = dynamic_cast<RsRttPongItem *>(i)))
|
||||
{
|
||||
return sizeRttPongItem(pong);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool RsRttSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsMsgSerialiser::serialise()" << std::endl;
|
||||
#endif
|
||||
|
||||
RsRttPingItem *ping;
|
||||
RsRttPongItem *pong;
|
||||
|
||||
if (NULL != (ping = dynamic_cast<RsRttPingItem *>(i)))
|
||||
{
|
||||
return serialiseRttPingItem(ping, data, pktsize);
|
||||
}
|
||||
else if (NULL != (pong = dynamic_cast<RsRttPongItem *>(i)))
|
||||
{
|
||||
return serialiseRttPongItem(pong, data, pktsize);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem* RsRttSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsRttSerialiser::deserialise()" << std::endl;
|
||||
#endif
|
||||
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_RTT != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
case RS_PKT_SUBTYPE_RTT_PING:
|
||||
return deserialiseRttPingItem(data, pktsize);
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_RTT_PONG:
|
||||
return deserialiseRttPongItem(data, pktsize);
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
#endif
|
||||
|
||||
|
|
|
@ -46,94 +46,6 @@ RsItem *RsGxsWikiSerialiser::create_item(uint16_t service, uint8_t item_sub_id)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
uint32_t RsGxsWikiSerialiser::size(RsItem *item)
|
||||
{
|
||||
RsGxsWikiCollectionItem* grp_item = NULL;
|
||||
RsGxsWikiSnapshotItem* snap_item = NULL;
|
||||
RsGxsWikiCommentItem* com_item = NULL;
|
||||
|
||||
if((grp_item = dynamic_cast<RsGxsWikiCollectionItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsWikiCollectionItem(grp_item);
|
||||
}
|
||||
else if((snap_item = dynamic_cast<RsGxsWikiSnapshotItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsWikiSnapshotItem(snap_item);
|
||||
}
|
||||
else if((com_item = dynamic_cast<RsGxsWikiCommentItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsWikiCommentItem(com_item);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool RsGxsWikiSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
RsGxsWikiCollectionItem* grp_item = NULL;
|
||||
RsGxsWikiSnapshotItem* snap_item = NULL;
|
||||
RsGxsWikiCommentItem* com_item = NULL;
|
||||
|
||||
if((grp_item = dynamic_cast<RsGxsWikiCollectionItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsWikiCollectionItem(grp_item, data, size);
|
||||
}
|
||||
else if((snap_item = dynamic_cast<RsGxsWikiSnapshotItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsWikiSnapshotItem(snap_item, data, size);
|
||||
}
|
||||
else if((com_item = dynamic_cast<RsGxsWikiCommentItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsWikiCommentItem(com_item, data, size);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem* RsGxsWikiSerialiser::deserialise(void* data, uint32_t* size)
|
||||
{
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialise()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_WIKI != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
|
||||
case RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM:
|
||||
return deserialiseGxsWikiCollectionItem(data, size);
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM:
|
||||
return deserialiseGxsWikiSnapshotItem(data, size);
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM:
|
||||
return deserialiseGxsWikiCommentItem(data, size);
|
||||
break;
|
||||
default:
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialise(): unknown subtype";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
#endif
|
||||
|
||||
void RsGxsWikiCollectionItem::clear()
|
||||
{
|
||||
collection.mDescription.clear();
|
||||
|
@ -141,38 +53,6 @@ void RsGxsWikiCollectionItem::clear()
|
|||
collection.mHashTags.clear();
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
std::ostream& RsGxsWikiCollectionItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsWikiCollectionItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Description: " << collection.mDescription << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "Category: " << collection.mCategory << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "HashTags: " << collection.mHashTags << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsWikiCollectionItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsWikiSerialiser::sizeGxsWikiCollectionItem(RsGxsWikiCollectionItem *item)
|
||||
{
|
||||
|
||||
const RsWikiCollection& collection = item->collection;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(collection.mDescription);
|
||||
s += GetTlvStringSize(collection.mCategory);
|
||||
s += GetTlvStringSize(collection.mHashTags);
|
||||
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
|
||||
void RsGxsWikiCollectionItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR ,collection.mDescription,"collection.mDescription") ;
|
||||
|
@ -180,448 +60,25 @@ void RsGxsWikiCollectionItem::serial_process(RsGenericSerializer::SerializeJob j
|
|||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG,collection.mHashTags ,"collection.mHashTags") ;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
bool RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem(RsGxsWikiCollectionItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsWikiCollectionItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsWikiCollectionItem */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DESCR, item->collection.mDescription);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_CATEGORY, item->collection.mCategory);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_HASH_TAG, item->collection.mHashTags);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsWikiCollectionItem* RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_WIKI != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsWikiCollectionItem* item = new RsGxsWikiCollectionItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DESCR, item->collection.mDescription);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_CATEGORY, item->collection.mCategory);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_HASH_TAG, item->collection.mHashTags);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
#endif
|
||||
|
||||
void RsGxsWikiSnapshotItem::clear()
|
||||
{
|
||||
snapshot.mPage.clear();
|
||||
snapshot.mHashTags.clear();
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
std::ostream& RsGxsWikiSnapshotItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsWikiSnapshotItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Page: " << snapshot.mPage << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "HashTags: " << snapshot.mHashTags << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsWikiSnapshotItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsWikiSerialiser::sizeGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *item)
|
||||
{
|
||||
|
||||
const RsWikiSnapshot& snapshot = item->snapshot;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(snapshot.mPage);
|
||||
s += GetTlvStringSize(snapshot.mHashTags);
|
||||
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
|
||||
void RsGxsWikiSnapshotItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_WIKI_PAGE,snapshot.mPage,"snapshot.mPage") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG ,snapshot.mPage,"snapshot.mHashTags") ;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
bool RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsWikiSnapshotItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsWikiSnapshotItem */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_WIKI_PAGE, item->snapshot.mPage);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_HASH_TAG, item->snapshot.mHashTags);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsWikiSnapshotItem* RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_WIKI != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsWikiSnapshotItem* item = new RsGxsWikiSnapshotItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_WIKI_PAGE, item->snapshot.mPage);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_HASH_TAG, item->snapshot.mHashTags);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
#endif
|
||||
|
||||
void RsGxsWikiCommentItem::clear()
|
||||
{
|
||||
comment.mComment.clear();
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
std::ostream& RsGxsWikiCommentItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsWikiCommentItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Comment: " << comment.mComment << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsWikiCommentItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsWikiSerialiser::sizeGxsWikiCommentItem(RsGxsWikiCommentItem *item)
|
||||
{
|
||||
|
||||
const RsWikiComment& comment = item->comment;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(comment.mComment);
|
||||
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
|
||||
void RsGxsWikiCommentItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_COMMENT,comment.mComment,"comment.mComment") ;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
bool RsGxsWikiSerialiser::serialiseGxsWikiCommentItem(RsGxsWikiCommentItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsWikiCommentItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsWikiCommentItem */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_COMMENT, item->comment.mComment);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsWikiCommentItem* RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_WIKI != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsWikiCommentItem* item = new RsGxsWikiCommentItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_COMMENT, item->comment.mComment);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -46,398 +46,19 @@ RsItem *RsGxsWireSerialiser::create_item(uint16_t service,uint8_t item_subtype)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
uint32_t RsGxsWireSerialiser::size(RsItem *item)
|
||||
{
|
||||
RsGxsWireGroupItem* grp_item = NULL;
|
||||
RsGxsWirePulseItem* snap_item = NULL;
|
||||
|
||||
if((grp_item = dynamic_cast<RsGxsWireGroupItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsWireGroupItem(grp_item);
|
||||
}
|
||||
else if((snap_item = dynamic_cast<RsGxsWirePulseItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsWirePulseItem(snap_item);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool RsGxsWireSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
RsGxsWireGroupItem* grp_item = NULL;
|
||||
RsGxsWirePulseItem* snap_item = NULL;
|
||||
|
||||
if((grp_item = dynamic_cast<RsGxsWireGroupItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsWireGroupItem(grp_item, data, size);
|
||||
}
|
||||
else if((snap_item = dynamic_cast<RsGxsWirePulseItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsWirePulseItem(snap_item, data, size);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem* RsGxsWireSerialiser::deserialise(void* data, uint32_t* size)
|
||||
{
|
||||
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialise()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_WIRE != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
|
||||
case RS_PKT_SUBTYPE_WIRE_GROUP_ITEM:
|
||||
return deserialiseGxsWireGroupItem(data, size);
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_WIRE_PULSE_ITEM:
|
||||
return deserialiseGxsWirePulseItem(data, size);
|
||||
break;
|
||||
default:
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialise(): unknown subtype";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
#endif
|
||||
|
||||
void RsGxsWireGroupItem::clear()
|
||||
{
|
||||
group.mDescription.clear();
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
std::ostream& RsGxsWireGroupItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsWireGroupItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Description: " << group.mDescription << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsWireGroupItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsWireSerialiser::sizeGxsWireGroupItem(RsGxsWireGroupItem *item)
|
||||
{
|
||||
|
||||
const RsWireGroup& group = item->group;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(group.mDescription);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void RsGxsWireGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR,group.mDescription,"group.mDescription") ;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
bool RsGxsWireSerialiser::serialiseGxsWireGroupItem(RsGxsWireGroupItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsWireGroupItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize)
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsWireGroupItem */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DESCR, item->group.mDescription);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef WIRE_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsWireGroupItem* RsGxsWireSerialiser::deserialiseGxsWireGroupItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_WIRE != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_WIRE_GROUP_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsWireGroupItem* item = new RsGxsWireGroupItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DESCR, item->group.mDescription);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
|
||||
void RsGxsWirePulseItem::clear()
|
||||
{
|
||||
pulse.mPulseText.clear();
|
||||
pulse.mHashTags.clear();
|
||||
}
|
||||
|
||||
std::ostream& RsGxsWirePulseItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsWirePulseItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Page: " << pulse.mPulseText << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "HashTags: " << pulse.mHashTags << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsWirePulseItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsWireSerialiser::sizeGxsWirePulseItem(RsGxsWirePulseItem *item)
|
||||
{
|
||||
|
||||
const RsWirePulse& pulse = item->pulse;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(pulse.mPulseText);
|
||||
s += GetTlvStringSize(pulse.mHashTags);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void RsGxsWirePulseItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,pulse.mPulseText,"pulse.mPulseText") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG,pulse.mHashTags,"pulse.mHashTags") ;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
bool RsGxsWireSerialiser::serialiseGxsWirePulseItem(RsGxsWirePulseItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsWirePulseItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize)
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsWirePulseItem */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, item->pulse.mPulseText);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_HASH_TAG, item->pulse.mHashTags);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef WIRE_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsWirePulseItem* RsGxsWireSerialiser::deserialiseGxsWirePulseItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_WIRE != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_WIRE_PULSE_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsWirePulseItem* item = new RsGxsWirePulseItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, item->pulse.mPulseText);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_HASH_TAG, item->pulse.mHashTags);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue