mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-28 08:07:31 -04:00
merging rs_gxs-finale to v0.6 branch
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-initdev@6953 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
commit
39909b705f
67 changed files with 5686 additions and 488 deletions
|
@ -122,20 +122,30 @@ void RsGxsIdGroupItem::clear()
|
|||
group.mPgpIdHash.clear();
|
||||
group.mPgpIdSign.clear();
|
||||
|
||||
group.mRecognTags.clear();
|
||||
|
||||
group.mPgpKnown = false;
|
||||
group.mPgpId.clear();
|
||||
|
||||
}
|
||||
|
||||
|
||||
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: " << group.mPgpIdHash << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "PgpIdSign: " << group.mPgpIdSign << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "RecognTags:" << std::endl;
|
||||
|
||||
RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, group.mRecognTags);
|
||||
set.print(out, int_Indent + 2);
|
||||
|
||||
printRsItemEnd(out ,"RsGxsIdGroupItem", indent);
|
||||
return out;
|
||||
|
@ -151,6 +161,9 @@ uint32_t RsGxsIdSerialiser::sizeGxsIdGroupItem(RsGxsIdGroupItem *item)
|
|||
s += GetTlvStringSize(group.mPgpIdHash);
|
||||
s += GetTlvStringSize(group.mPgpIdSign);
|
||||
|
||||
RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, item->group.mRecognTags);
|
||||
s += set.TlvSize();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
@ -181,6 +194,9 @@ bool RsGxsIdSerialiser::serialiseGxsIdGroupItem(RsGxsIdGroupItem *item, void *da
|
|||
/* GxsIdGroupItem */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->group.mPgpIdHash);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->group.mPgpIdSign);
|
||||
|
||||
RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, item->group.mRecognTags);
|
||||
ok &= set.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
|
@ -238,6 +254,10 @@ RsGxsIdGroupItem* RsGxsIdSerialiser::deserialiseGxsIdGroupItem(void *data, uint3
|
|||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->group.mPgpIdHash);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->group.mPgpIdSign);
|
||||
|
||||
RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, item->group.mRecognTags);
|
||||
ok &= set.GetTlv(data, rssize, &offset);
|
||||
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
|
|
|
@ -52,7 +52,8 @@
|
|||
|
||||
std::ostream &operator<<(std::ostream &out, const RsGroupMetaData &meta)
|
||||
{
|
||||
out << "[ GroupId: " << meta.mGroupId << " Name: " << meta.mGroupName << " ]";
|
||||
out << "[ GroupId: " << meta.mGroupId << " Name: " << meta.mGroupName;
|
||||
out << " PublishTs: " << meta.mPublishTs << " ]";
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
600
libretroshare/src/serialiser/rsgxsrecognitems.cc
Normal file
600
libretroshare/src/serialiser/rsgxsrecognitems.cc
Normal file
|
@ -0,0 +1,600 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsgxsrecogitems.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2013-2013 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 "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rsgxsrecognitems.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsGxsRecognReqItem::~RsGxsRecognReqItem()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void RsGxsRecognReqItem::clear()
|
||||
{
|
||||
issued_at = 0;
|
||||
period = 0;
|
||||
tag_class = 0;
|
||||
tag_type = 0;
|
||||
|
||||
identity.clear();
|
||||
nickname.clear();
|
||||
comment.clear();
|
||||
|
||||
sign.TlvClear();
|
||||
|
||||
}
|
||||
|
||||
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 += GetTlvStringSize(item->identity);
|
||||
s += GetTlvStringSize(item->nickname);
|
||||
s += GetTlvStringSize(item->comment);
|
||||
s += item->sign.TlvSize();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* 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 &= SetTlvString(data, tlvsize, &offset, 1, item->identity);
|
||||
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 &= GetTlvString(data, tlvsize, &offset, 1, item->identity);
|
||||
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;
|
||||
}
|
||||
|
||||
void RsGxsRecognTagItem::clear()
|
||||
{
|
||||
valid_from = 0;
|
||||
valid_to = 0;
|
||||
|
||||
tag_class = 0;
|
||||
tag_type = 0;
|
||||
|
||||
identity.clear();
|
||||
nickname.clear();
|
||||
|
||||
sign.TlvClear();
|
||||
}
|
||||
|
||||
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 += GetTlvStringSize(item->identity);
|
||||
s += GetTlvStringSize(item->nickname);
|
||||
|
||||
s += item->sign.TlvSize();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* 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 &= SetTlvString(data, tlvsize, &offset, 1, item->identity);
|
||||
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 &= GetTlvString(data, tlvsize, &offset, 1, item->identity);
|
||||
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;
|
||||
}
|
||||
|
||||
void RsGxsRecognSignerItem::clear()
|
||||
{
|
||||
signing_classes.TlvClear();
|
||||
key.TlvClear();
|
||||
sign.TlvClear();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
|
||||
|
152
libretroshare/src/serialiser/rsgxsrecognitems.h
Normal file
152
libretroshare/src/serialiser/rsgxsrecognitems.h
Normal file
|
@ -0,0 +1,152 @@
|
|||
#ifndef RS_GXS_RECOG_ITEMS_H
|
||||
#define RS_GXS_RECOG_ITEMS_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsgxsrecogitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2013-2013 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 <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#define RS_PKT_SUBTYPE_RECOGN_REQ 0x01
|
||||
#define RS_PKT_SUBTYPE_RECOGN_TAG 0x02
|
||||
#define RS_PKT_SUBTYPE_RECOGN_SIGNER 0x03
|
||||
|
||||
|
||||
class RsGxsRecognReqItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsGxsRecognReqItem()
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_RECOGN,
|
||||
RS_PKT_SUBTYPE_RECOGN_REQ)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_DEFAULT);
|
||||
return;
|
||||
}
|
||||
virtual ~RsGxsRecognReqItem();
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
|
||||
uint32_t issued_at;
|
||||
uint32_t period;
|
||||
uint16_t tag_class;
|
||||
uint16_t tag_type;
|
||||
|
||||
std::string identity;
|
||||
std::string nickname;
|
||||
std::string comment;
|
||||
|
||||
RsTlvKeySignature sign;
|
||||
};
|
||||
|
||||
|
||||
class RsGxsRecognTagItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsGxsRecognTagItem()
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_RECOGN,
|
||||
RS_PKT_SUBTYPE_RECOGN_TAG)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_DEFAULT);
|
||||
return;
|
||||
}
|
||||
virtual ~RsGxsRecognTagItem();
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
uint32_t valid_from;
|
||||
uint32_t valid_to;
|
||||
uint16_t tag_class;
|
||||
uint16_t tag_type;
|
||||
|
||||
std::string identity;
|
||||
std::string nickname;
|
||||
|
||||
RsTlvKeySignature sign;
|
||||
};
|
||||
|
||||
|
||||
class RsGxsRecognSignerItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsGxsRecognSignerItem()
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_RECOGN,
|
||||
RS_PKT_SUBTYPE_RECOGN_SIGNER)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_DEFAULT);
|
||||
return;
|
||||
}
|
||||
virtual ~RsGxsRecognSignerItem();
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
RsTlvServiceIdSet signing_classes;
|
||||
RsTlvSecurityKey key; // has from->to, and flags.
|
||||
RsTlvKeySignature sign;
|
||||
};
|
||||
|
||||
|
||||
class RsGxsRecognSerialiser: public RsSerialType
|
||||
{
|
||||
public:
|
||||
RsGxsRecognSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_RECOGN)
|
||||
{ return; }
|
||||
virtual ~RsGxsRecognSerialiser()
|
||||
{ return; }
|
||||
|
||||
|
||||
virtual uint32_t size(RsItem *);
|
||||
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
|
||||
virtual RsItem * deserialise(void *data, uint32_t *size);
|
||||
|
||||
private:
|
||||
|
||||
virtual uint32_t sizeReq(RsGxsRecognReqItem *);
|
||||
virtual bool serialiseReq(RsGxsRecognReqItem *item, void *data, uint32_t *size);
|
||||
virtual RsGxsRecognReqItem *deserialiseReq(void *data, uint32_t *size);
|
||||
|
||||
virtual uint32_t sizeTag(RsGxsRecognTagItem *);
|
||||
virtual bool serialiseTag(RsGxsRecognTagItem *item, void *data, uint32_t *size);
|
||||
virtual RsGxsRecognTagItem *deserialiseTag(void *data, uint32_t *size);
|
||||
|
||||
virtual uint32_t sizeSigner(RsGxsRecognSignerItem *);
|
||||
virtual bool serialiseSigner(RsGxsRecognSignerItem *item, void *data, uint32_t *size);
|
||||
virtual RsGxsRecognSignerItem *deserialiseSigner(void *data, uint32_t *size);
|
||||
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#endif /* RS_GXS_RECOGN_ITEMS_H */
|
||||
|
||||
|
704
libretroshare/src/serialiser/rsgxsupdateitems.cc
Normal file
704
libretroshare/src/serialiser/rsgxsupdateitems.cc
Normal file
|
@ -0,0 +1,704 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsgxsupdateitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2012 Christopher Evi-Parker
|
||||
*
|
||||
* 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 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 "rsgxsupdateitems.h"
|
||||
#include "rsbaseserial.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void RsGxsGrpUpdateItem::clear()
|
||||
{
|
||||
grpUpdateTS = 0;
|
||||
peerId.clear();
|
||||
}
|
||||
|
||||
std::ostream& RsGxsGrpUpdateItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RsGxsMsgUpdateItem::clear()
|
||||
{
|
||||
msgUpdateTS.clear();
|
||||
peerId.clear();
|
||||
}
|
||||
|
||||
std::ostream& RsGxsMsgUpdateItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RsGxsServerMsgUpdateItem::clear()
|
||||
{
|
||||
msgUpdateTS = 0;
|
||||
grpId.clear();
|
||||
}
|
||||
|
||||
std::ostream& RsGxsServerMsgUpdateItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void RsGxsServerGrpUpdateItem::clear()
|
||||
{
|
||||
grpUpdateTS = 0;
|
||||
}
|
||||
|
||||
std::ostream& RsGxsServerGrpUpdateItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t RsGxsUpdateSerialiser::size(RsItem* item)
|
||||
{
|
||||
RsGxsMsgUpdateItem* mui = NULL;
|
||||
RsGxsGrpUpdateItem* gui = NULL;
|
||||
RsGxsServerGrpUpdateItem* gsui = NULL;
|
||||
RsGxsServerMsgUpdateItem* msui = NULL;
|
||||
|
||||
if((mui = dynamic_cast<RsGxsMsgUpdateItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsMsgUpdate(mui);
|
||||
}else if(( gui = dynamic_cast<RsGxsGrpUpdateItem*>(item)) != NULL){
|
||||
return sizeGxsGrpUpdate(gui);
|
||||
}else if((gsui = dynamic_cast<RsGxsServerGrpUpdateItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsServerGrpUpdate(gsui);
|
||||
}else if((msui = dynamic_cast<RsGxsServerMsgUpdateItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsServerMsgUpdate(msui);
|
||||
}else
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::size(): Could not find appropriate size function"
|
||||
<< std::endl;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool RsGxsUpdateSerialiser::serialise(RsItem* item, void* data,
|
||||
uint32_t* size)
|
||||
{
|
||||
RsGxsMsgUpdateItem* mui;
|
||||
RsGxsGrpUpdateItem* gui;
|
||||
RsGxsServerGrpUpdateItem* gsui;
|
||||
RsGxsServerMsgUpdateItem* msui;
|
||||
|
||||
if((mui = dynamic_cast<RsGxsMsgUpdateItem*>(item)) != NULL)
|
||||
return serialiseGxsMsgUpdate(mui, data, size);
|
||||
else if((gui = dynamic_cast<RsGxsGrpUpdateItem*>(item)) != NULL)
|
||||
return serialiseGxsGrpUpdate(gui, data, size);
|
||||
else if((msui = dynamic_cast<RsGxsServerMsgUpdateItem*>(item)) != NULL)
|
||||
return serialiseGxsServerMsgUpdate(msui, data, size);
|
||||
else if((gsui = dynamic_cast<RsGxsServerGrpUpdateItem*>(item)) != NULL)
|
||||
return serialiseGxsServerGrpUpdate(gsui, data, size);
|
||||
else
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::serialise() item does not caste to known type"
|
||||
<< std::endl;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
RsItem* RsGxsUpdateSerialiser::deserialise(void* data, uint32_t* size)
|
||||
{
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::deserialise()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(SERVICE_TYPE != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
|
||||
case RS_PKT_SUBTYPE_GXS_MSG_UPDATE:
|
||||
return deserialGxsMsgUpdate(data, size);
|
||||
case RS_PKT_SUBTYPE_GXS_GRP_UPDATE:
|
||||
return deserialGxsGrpUpddate(data, size);
|
||||
case RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE:
|
||||
return deserialGxsServerGrpUpddate(data, size);
|
||||
case RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE:
|
||||
return deserialGxsServerMsgUpdate(data, size);
|
||||
default:
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::deserialise() : data has no type"
|
||||
<< std::endl;
|
||||
#endif
|
||||
return NULL;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t RsGxsUpdateSerialiser::sizeGxsGrpUpdate(RsGxsGrpUpdateItem* item)
|
||||
{
|
||||
uint32_t s = 8; // header size
|
||||
s += GetTlvStringSize(item->peerId);
|
||||
s += 4;
|
||||
return s;
|
||||
}
|
||||
|
||||
uint32_t RsGxsUpdateSerialiser::sizeGxsServerGrpUpdate(RsGxsServerGrpUpdateItem* item)
|
||||
{
|
||||
uint32_t s = 8; // header size
|
||||
s += 4; // time stamp
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsUpdateSerialiser::serialiseGxsGrpUpdate(RsGxsGrpUpdateItem* item,
|
||||
void* data, uint32_t* size)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsGrpUpdate()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsGrpUpdate(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize){
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsGrpUpdate() size do not match" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* RsGxsGrpUpdateItem */
|
||||
|
||||
|
||||
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_PEERID, item->peerId);
|
||||
ok &= setRawUInt32(data, *size, &offset, item->grpUpdateTS);
|
||||
|
||||
if(offset != tlvsize){
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsGrpUpdate() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsGrpUpdate() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsGxsUpdateSerialiser::serialiseGxsServerGrpUpdate(RsGxsServerGrpUpdateItem* item,
|
||||
void* data, uint32_t* size)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsServerGrpUpdate()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsServerGrpUpdate(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize){
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsServerGrpUpdate() size do not match" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* RsGxsServerGrpUpdateItem */
|
||||
|
||||
ok &= setRawUInt32(data, *size, &offset, item->grpUpdateTS);
|
||||
|
||||
if(offset != tlvsize){
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsServerGrpUpdate() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsServerGrpUpdate() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsGrpUpdateItem* RsGxsUpdateSerialiser::deserialGxsGrpUpddate(void* data,
|
||||
uint32_t* size)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate()" << 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)) ||
|
||||
(SERVICE_TYPE != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXS_GRP_UPDATE != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::deserialGxsGrpUpdate() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::deserialGxsGrpUpdate() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsGrpUpdateItem* item = new RsGxsGrpUpdateItem(getRsItemService(rstype));
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_PEERID, item->peerId);
|
||||
ok &= getRawUInt32(data, *size, &offset, &(item->grpUpdateTS));
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::deserialGxxGrpUpdate() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::deserialGxsGrpUpdate() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
RsGxsServerGrpUpdateItem* RsGxsUpdateSerialiser::deserialGxsServerGrpUpddate(void* data,
|
||||
uint32_t* size)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate()" << 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)) ||
|
||||
(SERVICE_TYPE != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsServerGrpUpdateItem* item = new RsGxsServerGrpUpdateItem(getRsItemService(rstype));
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= getRawUInt32(data, *size, &offset, &(item->grpUpdateTS));
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
uint32_t RsGxsUpdateSerialiser::sizeGxsMsgUpdate(RsGxsMsgUpdateItem* item)
|
||||
{
|
||||
uint32_t s = 8; // header size
|
||||
s += GetTlvStringSize(item->peerId);
|
||||
|
||||
const std::map<std::string, uint32_t>& msgUpdateTS = item->msgUpdateTS;
|
||||
std::map<std::string, uint32_t>::const_iterator cit = msgUpdateTS.begin();
|
||||
|
||||
for(; cit != msgUpdateTS.end(); cit++)
|
||||
{
|
||||
s += GetTlvStringSize(cit->first);
|
||||
s += 4;
|
||||
}
|
||||
|
||||
s += 4; // number of map items
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
uint32_t RsGxsUpdateSerialiser::sizeGxsServerMsgUpdate(RsGxsServerMsgUpdateItem* item)
|
||||
{
|
||||
uint32_t s = 8; // header size
|
||||
s += GetTlvStringSize(item->grpId);
|
||||
s += 4; // grp TS
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsUpdateSerialiser::serialiseGxsMsgUpdate(RsGxsMsgUpdateItem* item,
|
||||
void* data, uint32_t* size)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsMsgUpdate()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsMsgUpdate(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize){
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsMsgUpdate() size do not match" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* RsGxsMsgUpdateItem */
|
||||
|
||||
|
||||
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_PEERID, item->peerId);
|
||||
|
||||
const std::map<std::string, uint32_t>& msgUpdateTS = item->msgUpdateTS;
|
||||
std::map<std::string, uint32_t>::const_iterator cit = msgUpdateTS.begin();
|
||||
|
||||
uint32_t numItems = msgUpdateTS.size();
|
||||
ok &= setRawUInt32(data, *size, &offset, numItems);
|
||||
|
||||
for(; cit != msgUpdateTS.end(); cit++)
|
||||
{
|
||||
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, cit->first);
|
||||
ok &= setRawUInt32(data, *size, &offset, cit->second);
|
||||
}
|
||||
|
||||
if(offset != tlvsize){
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsMsgUpdate() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsMsgUpdate() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsGxsUpdateSerialiser::serialiseGxsServerMsgUpdate(RsGxsServerMsgUpdateItem* item,
|
||||
void* data, uint32_t* size)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsServerMsgUpdate()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsServerMsgUpdate(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize){
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsServerMsgUpdate() size do not match" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* RsNxsSyncm */
|
||||
|
||||
|
||||
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
|
||||
ok &= setRawUInt32(data, *size, &offset, item->msgUpdateTS);
|
||||
|
||||
if(offset != tlvsize){
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsServerMsgUpdate() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsServerMsgUpdate() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsMsgUpdateItem* RsGxsUpdateSerialiser::deserialGxsMsgUpdate(void* data,
|
||||
uint32_t* size)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::deserialGxsMsgUpdate()" << 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)) ||
|
||||
(SERVICE_TYPE != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXS_MSG_UPDATE != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::deserialGxsMsgUpdate() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::deserialGxsMsgUpdate() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsMsgUpdateItem* item = new RsGxsMsgUpdateItem(getRsItemService(rstype));
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_PEERID, item->peerId);
|
||||
uint32_t numUpdateItems;
|
||||
ok &= getRawUInt32(data, *size, &offset, &(numUpdateItems));
|
||||
std::map<std::string, uint32_t>& msgUpdateItem = item->msgUpdateTS;
|
||||
std::string grpId;
|
||||
uint32_t updateTS;
|
||||
for(uint32_t i = 0; i < numUpdateItems; i++)
|
||||
{
|
||||
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, grpId);
|
||||
|
||||
if(!ok)
|
||||
break;
|
||||
|
||||
ok &= getRawUInt32(data, *size, &offset, &(updateTS));
|
||||
|
||||
if(!ok)
|
||||
break;
|
||||
|
||||
msgUpdateItem.insert(std::make_pair(grpId, updateTS));
|
||||
}
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::deserialGxsMsgUpdate() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::deserialGxsMsgUpdate() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
RsGxsServerMsgUpdateItem* RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate(void* data,
|
||||
uint32_t* size)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate()" << 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)) ||
|
||||
(SERVICE_TYPE != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsServerMsgUpdateItem* item = new RsGxsServerMsgUpdateItem(getRsItemService(rstype));
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
|
||||
ok &= getRawUInt32(data, *size, &offset, &(item->msgUpdateTS));
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
149
libretroshare/src/serialiser/rsgxsupdateitems.h
Normal file
149
libretroshare/src/serialiser/rsgxsupdateitems.h
Normal file
|
@ -0,0 +1,149 @@
|
|||
#ifndef RSGXSUPDATEITEMS_H_
|
||||
#define RSGXSUPDATEITEMS_H_
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsgxsupdateitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2012 Christopher Evi-Parker
|
||||
*
|
||||
* 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 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 <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "gxs/rsgxsdata.h"
|
||||
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_GXS_GRP_UPDATE = 0x0001;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXS_MSG_UPDATE = 0x0002;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE = 0x0004;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE = 0x0008;
|
||||
|
||||
class RsGxsGrpUpdateItem : public RsItem {
|
||||
public:
|
||||
RsGxsGrpUpdateItem(uint16_t servType) : RsItem(RS_PKT_VERSION_SERVICE, servType,
|
||||
RS_PKT_SUBTYPE_GXS_GRP_UPDATE)
|
||||
{clear();}
|
||||
virtual ~RsGxsGrpUpdateItem() {}
|
||||
|
||||
virtual void clear();
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
std::string peerId;
|
||||
uint32_t grpUpdateTS;
|
||||
};
|
||||
|
||||
class RsGxsServerGrpUpdateItem : public RsItem {
|
||||
public:
|
||||
RsGxsServerGrpUpdateItem(uint16_t servType) : RsItem(RS_PKT_VERSION_SERVICE, servType,
|
||||
RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE)
|
||||
{ clear();}
|
||||
virtual ~RsGxsServerGrpUpdateItem() {}
|
||||
|
||||
virtual void clear();
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
uint32_t grpUpdateTS;
|
||||
};
|
||||
|
||||
class RsGxsMsgUpdateItem : public RsItem
|
||||
{
|
||||
public:
|
||||
RsGxsMsgUpdateItem(uint16_t servType) : RsItem(RS_PKT_VERSION_SERVICE, servType, RS_PKT_SUBTYPE_GXS_MSG_UPDATE)
|
||||
{ clear();}
|
||||
virtual ~RsGxsMsgUpdateItem() {}
|
||||
|
||||
virtual void clear();
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
std::string peerId;
|
||||
std::map<std::string, uint32_t> msgUpdateTS;
|
||||
};
|
||||
|
||||
class RsGxsServerMsgUpdateItem : public RsItem
|
||||
{
|
||||
public:
|
||||
RsGxsServerMsgUpdateItem(uint16_t servType) : RsItem(RS_PKT_VERSION_SERVICE,
|
||||
servType, RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE)
|
||||
{ clear();}
|
||||
virtual ~RsGxsServerMsgUpdateItem() {}
|
||||
|
||||
virtual void clear();
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
std::string grpId;
|
||||
uint32_t msgUpdateTS; // the last time this group received a new msg
|
||||
};
|
||||
|
||||
|
||||
class RsGxsUpdateSerialiser : public RsSerialType
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsUpdateSerialiser(uint16_t servtype) :
|
||||
RsSerialType(RS_PKT_VERSION_SERVICE, servtype), SERVICE_TYPE(servtype) { return; }
|
||||
|
||||
virtual ~RsGxsUpdateSerialiser() { return; }
|
||||
|
||||
virtual uint32_t size(RsItem *item);
|
||||
virtual bool serialise(RsItem *item, void *data, uint32_t *size);
|
||||
virtual RsItem* deserialise(void *data, uint32_t *size);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
/* for RS_PKT_SUBTYPE_GRP_UPDATE_ITEM */
|
||||
|
||||
virtual uint32_t sizeGxsGrpUpdate(RsGxsGrpUpdateItem* item);
|
||||
virtual bool serialiseGxsGrpUpdate(RsGxsGrpUpdateItem *item, void *data, uint32_t *size);
|
||||
virtual RsGxsGrpUpdateItem* deserialGxsGrpUpddate(void *data, uint32_t *size);
|
||||
|
||||
/* for RS_PKT_SUBTYPE_GRP_SERVER_UPDATE_ITEM */
|
||||
|
||||
virtual uint32_t sizeGxsServerGrpUpdate(RsGxsServerGrpUpdateItem* item);
|
||||
virtual bool serialiseGxsServerGrpUpdate(RsGxsServerGrpUpdateItem *item, void *data, uint32_t *size);
|
||||
virtual RsGxsServerGrpUpdateItem* deserialGxsServerGrpUpddate(void *data, uint32_t *size);
|
||||
|
||||
/* for RS_PKT_SUBTYPE_GXS_MSG_UPDATE_ITEM */
|
||||
|
||||
virtual uint32_t sizeGxsMsgUpdate(RsGxsMsgUpdateItem* item);
|
||||
virtual bool serialiseGxsMsgUpdate(RsGxsMsgUpdateItem *item, void *data, uint32_t *size);
|
||||
virtual RsGxsMsgUpdateItem* deserialGxsMsgUpdate(void *data, uint32_t *size);
|
||||
|
||||
/* for RS_PKT_SUBTYPE_GXS_SERVER_UPDATE_ITEM */
|
||||
|
||||
virtual uint32_t sizeGxsServerMsgUpdate(RsGxsServerMsgUpdateItem* item);
|
||||
virtual bool serialiseGxsServerMsgUpdate(RsGxsServerMsgUpdateItem *item, void *data, uint32_t *size);
|
||||
virtual RsGxsServerMsgUpdateItem* deserialGxsServerMsgUpdate(void *data, uint32_t *size);
|
||||
|
||||
private:
|
||||
|
||||
const uint16_t SERVICE_TYPE;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* RSGXSUPDATEITEMS_H_ */
|
|
@ -354,8 +354,9 @@ bool RsNxsSerialiser::serialiseNxsSyncGrp(RsNxsSyncGrp *item, void *data, uint32
|
|||
|
||||
ok &= setRawUInt32(data, *size, &offset, item->transactionNumber);
|
||||
ok &= setRawUInt8(data, *size, &offset, item->flag);
|
||||
ok &= setRawUInt32(data, *size, &offset, item->syncAge);
|
||||
ok &= setRawUInt32(data, *size, &offset, item->createdSince);
|
||||
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_HASH_SHA1, item->syncHash);
|
||||
ok &= setRawUInt32(data, *size, &offset, item->updateTS);
|
||||
|
||||
if(offset != tlvsize){
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
|
@ -403,7 +404,7 @@ bool RsNxsSerialiser::serialiseNxsTrans(RsNxsTransac *item, void *data, uint32_t
|
|||
ok &= setRawUInt32(data, *size, &offset, item->transactionNumber);
|
||||
ok &= setRawUInt16(data, *size, &offset, item->transactFlag);
|
||||
ok &= setRawUInt32(data, *size, &offset, item->nItems);
|
||||
ok &= setRawUInt32(data, *size, &offset, item->timestamp);
|
||||
ok &= setRawUInt32(data, *size, &offset, item->updateTS);
|
||||
|
||||
|
||||
|
||||
|
@ -501,9 +502,10 @@ bool RsNxsSerialiser::serialiseNxsSyncMsg(RsNxsSyncMsg *item, void *data, uint32
|
|||
|
||||
ok &= setRawUInt32(data, *size, &offset, item->transactionNumber);
|
||||
ok &= setRawUInt8(data, *size, &offset, item->flag);
|
||||
ok &= setRawUInt32(data, *size, &offset, item->syncAge);
|
||||
ok &= setRawUInt32(data, *size, &offset, item->createdSince);
|
||||
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_HASH_SHA1, item->syncHash);
|
||||
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
|
||||
ok &= setRawUInt32(data, *size, &offset, item->updateTS);
|
||||
|
||||
if(offset != tlvsize){
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
|
@ -710,8 +712,9 @@ RsNxsSyncGrp* RsNxsSerialiser::deserialNxsSyncGrp(void *data, uint32_t *size){
|
|||
|
||||
ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber));
|
||||
ok &= getRawUInt8(data, *size, &offset, &(item->flag));
|
||||
ok &= getRawUInt32(data, *size, &offset, &(item->syncAge));
|
||||
ok &= getRawUInt32(data, *size, &offset, &(item->createdSince));
|
||||
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_HASH_SHA1, item->syncHash);
|
||||
ok &= getRawUInt32(data, *size, &offset, &(item->updateTS));
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
|
@ -846,7 +849,7 @@ RsNxsTransac* RsNxsSerialiser::deserialNxsTrans(void *data, uint32_t *size){
|
|||
ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber));
|
||||
ok &= getRawUInt16(data, *size, &offset, &(item->transactFlag));
|
||||
ok &= getRawUInt32(data, *size, &offset, &(item->nItems));
|
||||
ok &= getRawUInt32(data, *size, &offset, &(item->timestamp));
|
||||
ok &= getRawUInt32(data, *size, &offset, &(item->updateTS));
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
|
@ -984,9 +987,10 @@ RsNxsSyncMsg* RsNxsSerialiser::deserialNxsSyncMsg(void *data, uint32_t *size)
|
|||
|
||||
ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber));
|
||||
ok &= getRawUInt8(data, *size, &offset, &(item->flag));
|
||||
ok &= getRawUInt32(data, *size, &offset, &(item->syncAge));
|
||||
ok &= getRawUInt32(data, *size, &offset, &(item->createdSince));
|
||||
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_HASH_SHA1, item->syncHash);
|
||||
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
|
||||
ok &= getRawUInt32(data, *size, &offset, &(item->updateTS));
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
|
@ -1057,6 +1061,7 @@ uint32_t RsNxsSerialiser::sizeNxsSyncGrp(RsNxsSyncGrp *item)
|
|||
s += 1; // flag
|
||||
s += 4; // sync age
|
||||
s += GetTlvStringSize(item->syncHash);
|
||||
s += 4; // updateTS
|
||||
|
||||
return s;
|
||||
}
|
||||
|
@ -1086,6 +1091,7 @@ uint32_t RsNxsSerialiser::sizeNxsSyncMsg(RsNxsSyncMsg *item)
|
|||
s += 4; // age
|
||||
s += GetTlvStringSize(item->grpId);
|
||||
s += GetTlvStringSize(item->syncHash);
|
||||
s += 4; // updateTS
|
||||
|
||||
return s;
|
||||
}
|
||||
|
@ -1111,7 +1117,7 @@ uint32_t RsNxsSerialiser::sizeNxsTrans(RsNxsTransac *item){
|
|||
s += 4; // transaction number
|
||||
s += 2; // flag
|
||||
s += 4; // nMsgs
|
||||
s += 4; // timeout
|
||||
s += 4; // updateTS
|
||||
|
||||
return s;
|
||||
}
|
||||
|
@ -1141,16 +1147,18 @@ void RsNxsGrp::clear()
|
|||
void RsNxsSyncGrp::clear()
|
||||
{
|
||||
flag = 0;
|
||||
syncAge = 0;
|
||||
createdSince = 0;
|
||||
syncHash.clear();
|
||||
updateTS = 0;
|
||||
}
|
||||
|
||||
void RsNxsSyncMsg::clear()
|
||||
{
|
||||
grpId.clear();
|
||||
flag = 0;
|
||||
syncAge = 0;
|
||||
createdSince = 0;
|
||||
syncHash.clear();
|
||||
updateTS = 0;
|
||||
}
|
||||
|
||||
void RsNxsSyncGrpItem::clear()
|
||||
|
@ -1172,6 +1180,7 @@ void RsNxsSyncMsgItem::clear()
|
|||
void RsNxsTransac::clear(){
|
||||
transactFlag = 0;
|
||||
nItems = 0;
|
||||
updateTS = 0;
|
||||
timestamp = 0;
|
||||
transactionNumber = 0;
|
||||
}
|
||||
|
@ -1185,10 +1194,11 @@ std::ostream& RsNxsSyncGrp::print(std::ostream &out, uint16_t indent)
|
|||
printIndent(out , int_Indent);
|
||||
out << "Hash: " << syncHash << std::endl;
|
||||
printIndent(out , int_Indent);
|
||||
out << "Sync Age: " << syncAge << std::endl;
|
||||
out << "Sync Age: " << createdSince << std::endl;
|
||||
printIndent(out , int_Indent);
|
||||
out << "flag" << flag << std::endl;
|
||||
|
||||
printIndent(out , int_Indent);
|
||||
out << "updateTS" << updateTS << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsNxsSyncGrp", indent);
|
||||
|
||||
|
@ -1217,11 +1227,13 @@ std::ostream& RsNxsSyncMsg::print(std::ostream &out, uint16_t indent)
|
|||
printIndent(out , int_Indent);
|
||||
out << "GrpId: " << grpId << std::endl;
|
||||
printIndent(out , int_Indent);
|
||||
out << "syncAge: " << syncAge << std::endl;
|
||||
out << "createdSince: " << createdSince << std::endl;
|
||||
printIndent(out , int_Indent);
|
||||
out << "syncHash: " << syncHash << std::endl;
|
||||
printIndent(out , int_Indent);
|
||||
out << "flag: " << flag << std::endl;
|
||||
printIndent(out , int_Indent);
|
||||
out << "updateTS: " << updateTS << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsNxsSyncMsg", indent);
|
||||
return out;
|
||||
|
@ -1316,6 +1328,8 @@ std::ostream& RsNxsTransac::print(std::ostream &out, uint16_t indent){
|
|||
printIndent(out , int_Indent);
|
||||
out << "timeout: " << timestamp << std::endl;
|
||||
printIndent(out , int_Indent);
|
||||
out << "updateTS: " << updateTS << std::endl;
|
||||
printIndent(out , int_Indent);
|
||||
out << "transactionNumber: " << transactionNumber << std::endl;
|
||||
printIndent(out , int_Indent);
|
||||
|
||||
|
|
|
@ -100,7 +100,8 @@ public:
|
|||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
uint8_t flag; // advises whether to use sync hash
|
||||
uint32_t syncAge; // how far back to sync data
|
||||
uint32_t createdSince; // how far back to sync data
|
||||
uint32_t updateTS; // time of last group update
|
||||
std::string syncHash; // use to determine if changes that have occured since last hash
|
||||
|
||||
|
||||
|
@ -146,6 +147,9 @@ public:
|
|||
|
||||
uint16_t transactFlag;
|
||||
uint32_t nItems;
|
||||
uint32_t updateTS;
|
||||
|
||||
// not serialised
|
||||
uint32_t timestamp;
|
||||
};
|
||||
|
||||
|
@ -235,7 +239,8 @@ public:
|
|||
|
||||
std::string grpId;
|
||||
uint8_t flag;
|
||||
uint32_t syncAge;
|
||||
uint32_t createdSince;
|
||||
uint32_t updateTS; // time of last update
|
||||
std::string syncHash;
|
||||
};
|
||||
|
||||
|
|
|
@ -154,6 +154,8 @@ const uint16_t RS_SERVICE_GXSV3_TYPE_POSTED = 0xf326;
|
|||
const uint16_t RS_SERVICE_GXSV3_TYPE_CHANNELS = 0xf327;
|
||||
const uint16_t RS_SERVICE_GXSV3_TYPE_GXSCIRCLE = 0xf328;
|
||||
|
||||
const uint16_t RS_SERVICE_TYPE_GXS_RECOGN = 0xf331;
|
||||
|
||||
/***************** IDS ALLOCATED FOR PLUGINS ******************/
|
||||
|
||||
const uint16_t RS_SERVICE_TYPE_PLUGIN_ARADO_TEST_ID1 = 0xf401;
|
||||
|
|
|
@ -429,6 +429,165 @@ std::ostream &RsTlvStringSet::printHex(std::ostream &out, uint16_t indent)
|
|||
}
|
||||
|
||||
|
||||
/************************************* String Set Ref ************************************/
|
||||
/* This is exactly the same as StringSet, but it uses an alternative list.
|
||||
*/
|
||||
RsTlvStringSetRef::RsTlvStringSetRef(uint16_t type, std::list<std::string> &refids)
|
||||
:mType(type), ids(refids)
|
||||
{
|
||||
}
|
||||
|
||||
void RsTlvStringSetRef::TlvClear()
|
||||
{
|
||||
ids.clear();
|
||||
|
||||
}
|
||||
|
||||
uint32_t RsTlvStringSetRef::TlvSize()
|
||||
{
|
||||
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
|
||||
/* determine the total size of ids strings in list */
|
||||
|
||||
std::list<std::string>::iterator it;
|
||||
|
||||
for(it = ids.begin(); it != ids.end() ; ++it)
|
||||
{
|
||||
if (it->length() > 0)
|
||||
s += GetTlvStringSize(*it);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvStringSetRef::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true;
|
||||
|
||||
|
||||
/* start at data[offset] */
|
||||
ok &= SetTlvBase(data, tlvend, offset, mType , tlvsize);
|
||||
|
||||
/* determine the total size of ids strings in list */
|
||||
|
||||
std::list<std::string>::iterator it;
|
||||
|
||||
for(it = ids.begin(); it != ids.end() ; ++it)
|
||||
{
|
||||
if (it->length() > 0)
|
||||
ok &= SetTlvString(data, tlvend, offset, TLV_TYPE_STR_GENID, *it);
|
||||
}
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvStringSetRef::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
|
||||
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
|
||||
|
||||
if (size < tlvend) /* check size */
|
||||
return false; /* not enough space */
|
||||
|
||||
if (tlvtype != mType) /* check type */
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
|
||||
|
||||
/* while there is TLV */
|
||||
while((*offset) + 2 < tlvend)
|
||||
{
|
||||
/* get the next type */
|
||||
uint16_t tlvsubtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
|
||||
if (tlvsubtype == TLV_TYPE_STR_GENID)
|
||||
{
|
||||
std::string newIds;
|
||||
ok &= GetTlvString(data, tlvend, offset, TLV_TYPE_STR_GENID, newIds);
|
||||
if(ok)
|
||||
{
|
||||
ids.push_back(newIds);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Step past unknown TLV TYPE */
|
||||
ok &= SkipUnknownTlv(data, tlvend, offset);
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* NB: extra components could be added (for future expansion of the type).
|
||||
* or be present (if this code is reading an extended version).
|
||||
*
|
||||
* We must chew up the extra characters to conform with TLV specifications
|
||||
***************************************************************************/
|
||||
if (*offset != tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvPeerIdSetRef::GetTlv() Warning extra bytes at end of item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
*offset = tlvend;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/// print to screen RsTlvStringSet contents
|
||||
std::ostream &RsTlvStringSetRef::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printBase(out, "RsTlvStringSetRef", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "type:" << mType;
|
||||
out << std::endl;
|
||||
|
||||
std::list<std::string>::iterator it;
|
||||
for(it = ids.begin(); it != ids.end() ; ++it)
|
||||
{
|
||||
printIndent(out, int_Indent);
|
||||
out << "id:" << *it;
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
printEnd(out, "RsTlvStringSetRef", indent);
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
/************************************* Service Id Set ************************************/
|
||||
|
||||
void RsTlvServiceIdSet::TlvClear()
|
||||
|
|
|
@ -145,6 +145,22 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
|||
};
|
||||
|
||||
|
||||
class RsTlvStringSetRef: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvStringSetRef(uint16_t type, std::list<std::string> &refids);
|
||||
virtual ~RsTlvStringSetRef() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
uint16_t mType;
|
||||
std::list<std::string> &ids; /* Mandatory */
|
||||
};
|
||||
|
||||
|
||||
/**** MORE TLV *****
|
||||
*
|
||||
* File Items/Data.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue