2012-10-28 19:13:15 -04:00
|
|
|
/*
|
|
|
|
* libretroshare/src/serialiser: rsgxsiditems.cc
|
|
|
|
*
|
|
|
|
* RetroShare C++ Interface.
|
|
|
|
*
|
|
|
|
* Copyright 2012-2012 by Robert Fernie
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2.1 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "rsgxsiditems.h"
|
|
|
|
#include "serialiser/rstlvbase.h"
|
|
|
|
#include "serialiser/rsbaseserial.h"
|
|
|
|
|
|
|
|
#define GXSID_DEBUG 1
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t RsGxsIdSerialiser::size(RsItem *item)
|
|
|
|
{
|
|
|
|
RsGxsIdGroupItem* grp_item = NULL;
|
|
|
|
RsGxsIdOpinionItem* op_item = NULL;
|
|
|
|
RsGxsIdCommentItem* com_item = NULL;
|
|
|
|
|
|
|
|
if((grp_item = dynamic_cast<RsGxsIdGroupItem*>(item)) != NULL)
|
|
|
|
{
|
|
|
|
return sizeGxsIdGroupItem(grp_item);
|
|
|
|
}
|
|
|
|
else if((op_item = dynamic_cast<RsGxsIdOpinionItem*>(item)) != NULL)
|
|
|
|
{
|
|
|
|
return sizeGxsIdOpinionItem(op_item);
|
|
|
|
}
|
|
|
|
else if((com_item = dynamic_cast<RsGxsIdCommentItem*>(item)) != NULL)
|
|
|
|
{
|
|
|
|
return sizeGxsIdCommentItem(com_item);
|
|
|
|
}
|
2012-11-08 19:56:07 -05:00
|
|
|
std::cerr << "RsGxsIdSerialiser::size() ERROR invalid item" << std::endl;
|
|
|
|
return 0;
|
2012-10-28 19:13:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RsGxsIdSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
|
|
|
|
{
|
|
|
|
RsGxsIdGroupItem* grp_item = NULL;
|
|
|
|
RsGxsIdOpinionItem* op_item = NULL;
|
|
|
|
RsGxsIdCommentItem* com_item = NULL;
|
|
|
|
|
|
|
|
if((grp_item = dynamic_cast<RsGxsIdGroupItem*>(item)) != NULL)
|
|
|
|
{
|
|
|
|
return serialiseGxsIdGroupItem(grp_item, data, size);
|
|
|
|
}
|
|
|
|
else if((op_item = dynamic_cast<RsGxsIdOpinionItem*>(item)) != NULL)
|
|
|
|
{
|
2012-10-31 18:43:23 -04:00
|
|
|
return serialiseGxsIdOpinionItem(op_item, data, size);
|
2012-10-28 19:13:15 -04:00
|
|
|
}
|
|
|
|
else if((com_item = dynamic_cast<RsGxsIdCommentItem*>(item)) != NULL)
|
|
|
|
{
|
|
|
|
return serialiseGxsIdCommentItem(com_item, data, size);
|
|
|
|
}
|
2012-11-08 19:56:07 -05:00
|
|
|
std::cerr << "RsGxsIdSerialiser::serialise() ERROR invalid item" << std::endl;
|
2012-10-28 19:13:15 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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)) ||
|
2013-06-04 17:00:43 -04:00
|
|
|
(RS_SERVICE_GXSV2_TYPE_GXSID != getRsItemService(rstype)))
|
2012-10-28 19:13:15 -04:00
|
|
|
{
|
|
|
|
return NULL; /* wrong type */
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(getRsItemSubType(rstype))
|
|
|
|
{
|
|
|
|
|
|
|
|
case RS_PKT_SUBTYPE_GXSID_GROUP_ITEM:
|
|
|
|
return deserialiseGxsIdGroupItem(data, size);
|
|
|
|
break;
|
|
|
|
case RS_PKT_SUBTYPE_GXSID_OPINION_ITEM:
|
|
|
|
return deserialiseGxsIdOpinionItem(data, size);
|
|
|
|
break;
|
|
|
|
case RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM:
|
|
|
|
return deserialiseGxsIdCommentItem(data, size);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#ifdef GXSID_DEBUG
|
|
|
|
std::cerr << "RsGxsIdSerialiser::deserialise(): unknown subtype";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************************/
|
|
|
|
/*****************************************************************************************/
|
|
|
|
/*****************************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
void RsGxsIdGroupItem::clear()
|
|
|
|
{
|
2012-11-05 17:28:08 -05:00
|
|
|
group.mPgpIdHash.clear();
|
|
|
|
group.mPgpIdSign.clear();
|
2012-11-06 14:18:11 -05:00
|
|
|
|
2013-10-20 05:43:30 -04:00
|
|
|
group.mRecognTags.clear();
|
|
|
|
|
2012-11-06 14:18:11 -05:00
|
|
|
group.mPgpKnown = false;
|
|
|
|
group.mPgpId.clear();
|
|
|
|
|
2012-10-28 19:13:15 -04:00
|
|
|
}
|
|
|
|
|
2013-10-20 05:43:30 -04:00
|
|
|
|
2012-10-28 19:13:15 -04:00
|
|
|
std::ostream& RsGxsIdGroupItem::print(std::ostream& out, uint16_t indent)
|
|
|
|
{
|
|
|
|
printRsItemBase(out, "RsGxsIdGroupItem", indent);
|
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
|
2013-10-20 05:43:30 -04:00
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "MetaData: " << meta << std::endl;
|
2012-10-28 19:13:15 -04:00
|
|
|
printIndent(out, int_Indent);
|
2012-11-05 17:28:08 -05:00
|
|
|
out << "PgpIdHash: " << group.mPgpIdHash << std::endl;
|
2012-10-28 19:13:15 -04:00
|
|
|
printIndent(out, int_Indent);
|
2012-11-05 17:28:08 -05:00
|
|
|
out << "PgpIdSign: " << group.mPgpIdSign << std::endl;
|
2013-10-20 05:43:30 -04:00
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "RecognTags:" << std::endl;
|
|
|
|
|
|
|
|
RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, group.mRecognTags);
|
|
|
|
set.print(out, int_Indent + 2);
|
2012-10-28 19:13:15 -04:00
|
|
|
|
|
|
|
printRsItemEnd(out ,"RsGxsIdGroupItem", indent);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t RsGxsIdSerialiser::sizeGxsIdGroupItem(RsGxsIdGroupItem *item)
|
|
|
|
{
|
|
|
|
|
|
|
|
const RsGxsIdGroup& group = item->group;
|
|
|
|
uint32_t s = 8; // header
|
|
|
|
|
2012-11-05 17:28:08 -05:00
|
|
|
s += GetTlvStringSize(group.mPgpIdHash);
|
|
|
|
s += GetTlvStringSize(group.mPgpIdSign);
|
2012-10-28 19:13:15 -04:00
|
|
|
|
2013-10-20 05:43:30 -04:00
|
|
|
RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, item->group.mRecognTags);
|
|
|
|
s += set.TlvSize();
|
|
|
|
|
2012-10-28 19:13:15 -04:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RsGxsIdSerialiser::serialiseGxsIdGroupItem(RsGxsIdGroupItem *item, void *data, uint32_t *size)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t tlvsize = sizeGxsIdGroupItem(item);
|
|
|
|
uint32_t offset = 0;
|
|
|
|
|
|
|
|
if(*size < tlvsize)
|
|
|
|
{
|
|
|
|
#ifdef GXSID_DEBUG
|
2012-11-08 19:56:07 -05:00
|
|
|
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdGroupItem() Size too small" << std::endl;
|
2012-10-28 19:13:15 -04:00
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*size = tlvsize;
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
/* GxsIdGroupItem */
|
2014-02-08 06:13:10 -05:00
|
|
|
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_HASH_SHA1, item->group.mPgpIdHash);
|
|
|
|
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_SIGN, item->group.mPgpIdSign);
|
2013-10-20 05:43:30 -04:00
|
|
|
|
|
|
|
RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, item->group.mRecognTags);
|
|
|
|
ok &= set.SetTlv(data, tlvsize, &offset);
|
2012-10-28 19:13:15 -04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
RsGxsIdGroupItem* RsGxsIdSerialiser::deserialiseGxsIdGroupItem(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)) ||
|
2013-06-04 17:00:43 -04:00
|
|
|
(RS_SERVICE_GXSV2_TYPE_GXSID != getRsItemService(rstype)) ||
|
2012-10-28 19:13:15 -04:00
|
|
|
(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;
|
|
|
|
|
2014-02-08 06:13:10 -05:00
|
|
|
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_HASH_SHA1, item->group.mPgpIdHash);
|
|
|
|
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_SIGN, item->group.mPgpIdSign);
|
2013-10-20 05:43:30 -04:00
|
|
|
|
|
|
|
RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, item->group.mRecognTags);
|
|
|
|
ok &= set.GetTlv(data, rssize, &offset);
|
|
|
|
|
2012-10-28 19:13:15 -04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************************/
|
|
|
|
/*****************************************************************************************/
|
|
|
|
/*****************************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
void RsGxsIdOpinionItem::clear()
|
|
|
|
{
|
|
|
|
opinion.mOpinion = 0;
|
|
|
|
opinion.mReputation = 0;
|
2013-06-04 17:00:43 -04:00
|
|
|
opinion.mComment = "";
|
2012-10-28 19:13:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2013-06-04 17:00:43 -04:00
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "Reputation: " << opinion.mReputation << std::endl;
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "Comment: " << opinion.mComment << std::endl;
|
2012-10-28 19:13:15 -04:00
|
|
|
|
|
|
|
printRsItemEnd(out ,"RsGxsIdOpinionItem", indent);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t RsGxsIdSerialiser::sizeGxsIdOpinionItem(RsGxsIdOpinionItem *item)
|
|
|
|
{
|
|
|
|
|
|
|
|
const RsGxsIdOpinion& opinion = item->opinion;
|
|
|
|
uint32_t s = 8; // header
|
|
|
|
|
|
|
|
s += 4; // mOpinion.
|
2013-06-04 17:00:43 -04:00
|
|
|
s += 4; // mReputation.
|
|
|
|
s += GetTlvStringSize(opinion.mComment);
|
2012-10-28 19:13:15 -04:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RsGxsIdSerialiser::serialiseGxsIdOpinionItem(RsGxsIdOpinionItem *item, void *data, uint32_t *size)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t tlvsize = sizeGxsIdOpinionItem(item);
|
|
|
|
uint32_t offset = 0;
|
|
|
|
|
|
|
|
if(*size < tlvsize)
|
|
|
|
{
|
|
|
|
#ifdef GXSID_DEBUG
|
|
|
|
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdOpinionItem()" << std::endl;
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*size = tlvsize;
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
/* GxsIdOpinionItem */
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, item->opinion.mOpinion);
|
2013-06-04 17:00:43 -04:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, item->opinion.mReputation);
|
2014-02-08 06:13:10 -05:00
|
|
|
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_COMMENT, item->opinion.mComment);
|
2012-10-28 19:13:15 -04:00
|
|
|
|
|
|
|
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::deserialiseGxsIdOpinionItem(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)) ||
|
2013-06-04 17:00:43 -04:00
|
|
|
(RS_SERVICE_GXSV2_TYPE_GXSID != getRsItemService(rstype)) ||
|
2012-10-28 19:13:15 -04:00
|
|
|
(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));
|
2013-06-04 17:00:43 -04:00
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &(item->opinion.mReputation));
|
2014-02-08 06:13:10 -05:00
|
|
|
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_COMMENT, item->opinion.mComment);
|
2012-10-28 19:13:15 -04:00
|
|
|
|
|
|
|
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 RsGxsIdSerialiser::sizeGxsIdCommentItem(RsGxsIdCommentItem *item)
|
|
|
|
{
|
|
|
|
|
|
|
|
const RsGxsIdComment& comment = item->comment;
|
|
|
|
uint32_t s = 8; // header
|
|
|
|
|
|
|
|
s += GetTlvStringSize(comment.mComment);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RsGxsIdSerialiser::serialiseGxsIdCommentItem(RsGxsIdCommentItem *item, void *data, uint32_t *size)
|
|
|
|
{
|
|
|
|
|
|
|
|
uint32_t tlvsize = sizeGxsIdCommentItem(item);
|
|
|
|
uint32_t offset = 0;
|
|
|
|
|
|
|
|
if(*size < tlvsize)
|
|
|
|
{
|
|
|
|
#ifdef GXSID_DEBUG
|
2013-03-04 15:26:48 -05:00
|
|
|
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdCommentItem() Not enough space" << std::endl;
|
2012-10-28 19:13:15 -04:00
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*size = tlvsize;
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
/* GxsIdCommentItem */
|
2014-02-08 06:13:10 -05:00
|
|
|
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_COMMENT, item->comment.mComment);
|
2012-10-28 19:13:15 -04:00
|
|
|
|
|
|
|
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;
|
2013-03-04 15:26:48 -05:00
|
|
|
}
|
2012-10-28 19:13:15 -04:00
|
|
|
|
|
|
|
RsGxsIdCommentItem* RsGxsIdSerialiser::deserialiseGxsIdCommentItem(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)) ||
|
2013-06-04 17:00:43 -04:00
|
|
|
(RS_SERVICE_GXSV2_TYPE_GXSID != getRsItemService(rstype)) ||
|
2012-10-28 19:13:15 -04:00
|
|
|
(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;
|
|
|
|
|
2014-02-08 06:13:10 -05:00
|
|
|
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_COMMENT, item->comment.mComment);
|
2012-10-28 19:13:15 -04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************************/
|
|
|
|
/*****************************************************************************************/
|
|
|
|
/*****************************************************************************************/
|
|
|
|
|