mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-06 21:58:57 -04:00
Major commit of progress on new GxsServices (Channels and Posted). These are not complete yet!
- Reorganisation of p3posted, stripped out lots of previous stuff. - Converted p3posted to use GxsComment system. - Disabled much of the DummyData - switch it on manually when testing. - Added Basics of ChannelPost processing for AutoDownload. (incomplete). - Added GxsCommon backend for RsGxsImage and RsGxsFile. - Completed Serialiser for GxsChannels. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6207 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
4b9087b60d
commit
123d4a630b
16 changed files with 1927 additions and 2179 deletions
|
@ -122,7 +122,8 @@ RsItem* RsGxsChannelSerialiser::deserialise(void* data, uint32_t* size)
|
|||
|
||||
void RsGxsChannelGroupItem::clear()
|
||||
{
|
||||
mGroup.mDescription.clear();
|
||||
mDescription.clear();
|
||||
mImage.TlvClear();
|
||||
}
|
||||
|
||||
std::ostream& RsGxsChannelGroupItem::print(std::ostream& out, uint16_t indent)
|
||||
|
@ -131,20 +132,61 @@ std::ostream& RsGxsChannelGroupItem::print(std::ostream& out, uint16_t indent)
|
|||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Description: " << mGroup.mDescription << std::endl;
|
||||
out << "Description: " << mDescription << std::endl;
|
||||
|
||||
out << "Image: " << std::endl;
|
||||
mImage.print(out, int_Indent);
|
||||
|
||||
printRsItemEnd(out ,"RsGxsChannelGroupItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool RsGxsChannelGroupItem::fromChannelGroup(RsGxsChannelGroup &group, bool moveImage)
|
||||
{
|
||||
clear();
|
||||
meta = group.mMeta;
|
||||
mDescription = group.mDescription;
|
||||
|
||||
if (moveImage)
|
||||
{
|
||||
mImage.binData.bin_data = group.mImage.mData;
|
||||
mImage.binData.bin_len = group.mImage.mSize;
|
||||
group.mImage.shallowClear();
|
||||
}
|
||||
else
|
||||
{
|
||||
mImage.binData.setBinData(group.mImage.mData, group.mImage.mSize);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool RsGxsChannelGroupItem::toChannelGroup(RsGxsChannelGroup &group, bool moveImage)
|
||||
{
|
||||
group.mMeta = meta;
|
||||
group.mDescription = mDescription;
|
||||
if (moveImage)
|
||||
{
|
||||
group.mImage.take((uint8_t *) mImage.binData.bin_data, mImage.binData.bin_len);
|
||||
mImage.TlvShallowClear();
|
||||
}
|
||||
else
|
||||
{
|
||||
group.mImage.copy((uint8_t *) mImage.binData.bin_data, mImage.binData.bin_len);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsChannelSerialiser::sizeGxsChannelGroupItem(RsGxsChannelGroupItem *item)
|
||||
{
|
||||
|
||||
const RsGxsChannelGroup& group = item->mGroup;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(group.mDescription);
|
||||
s += GetTlvStringSize(item->mDescription);
|
||||
s += item->mImage.TlvSize();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
@ -177,7 +219,8 @@ bool RsGxsChannelSerialiser::serialiseGxsChannelGroupItem(RsGxsChannelGroupItem
|
|||
offset += 8;
|
||||
|
||||
/* GxsChannelGroupItem */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mGroup.mDescription);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mDescription);
|
||||
item->mImage.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
|
@ -237,7 +280,8 @@ RsGxsChannelGroupItem* RsGxsChannelSerialiser::deserialiseGxsChannelGroupItem(vo
|
|||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->mGroup.mDescription);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->mDescription);
|
||||
item->mImage.GetTlv(data, rssize, &offset);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
|
@ -270,7 +314,9 @@ RsGxsChannelGroupItem* RsGxsChannelSerialiser::deserialiseGxsChannelGroupItem(vo
|
|||
|
||||
void RsGxsChannelPostItem::clear()
|
||||
{
|
||||
mMsg.mMsg.clear();
|
||||
mMsg.clear();
|
||||
mAttachment.TlvClear();
|
||||
mThumbnail.TlvClear();
|
||||
}
|
||||
|
||||
std::ostream& RsGxsChannelPostItem::print(std::ostream& out, uint16_t indent)
|
||||
|
@ -279,20 +325,90 @@ std::ostream& RsGxsChannelPostItem::print(std::ostream& out, uint16_t indent)
|
|||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Msg: " << mMsg.mMsg << std::endl;
|
||||
out << "Msg: " << mMsg << std::endl;
|
||||
|
||||
out << "Attachment: " << std::endl;
|
||||
mAttachment.print(out, int_Indent);
|
||||
|
||||
out << "Thumbnail: " << std::endl;
|
||||
mThumbnail.print(out, int_Indent);
|
||||
|
||||
printRsItemEnd(out ,"RsGxsChannelPostItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
bool RsGxsChannelPostItem::fromChannelPost(RsGxsChannelPost &post, bool moveImage)
|
||||
{
|
||||
clear();
|
||||
meta = post.mMeta;
|
||||
mMsg = post.mMsg;
|
||||
|
||||
if (moveImage)
|
||||
{
|
||||
mThumbnail.binData.bin_data = post.mThumbnail.mData;
|
||||
mThumbnail.binData.bin_len = post.mThumbnail.mSize;
|
||||
post.mThumbnail.shallowClear();
|
||||
}
|
||||
else
|
||||
{
|
||||
mThumbnail.binData.setBinData(post.mThumbnail.mData, post.mThumbnail.mSize);
|
||||
}
|
||||
|
||||
std::list<RsGxsFile>::iterator fit;
|
||||
for(fit = post.mFiles.begin(); fit != post.mFiles.end(); fit++)
|
||||
{
|
||||
RsTlvFileItem fi;
|
||||
fi.name = fit->mName;
|
||||
fi.filesize = fit->mSize;
|
||||
fi.hash = fit->mHash;
|
||||
mAttachment.items.push_back(fi);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool RsGxsChannelPostItem::toChannelPost(RsGxsChannelPost &post, bool moveImage)
|
||||
{
|
||||
post.mMeta = meta;
|
||||
post.mMsg = mMsg;
|
||||
if (moveImage)
|
||||
{
|
||||
post.mThumbnail.take((uint8_t *) mThumbnail.binData.bin_data, mThumbnail.binData.bin_len);
|
||||
mThumbnail.TlvShallowClear();
|
||||
}
|
||||
else
|
||||
{
|
||||
post.mThumbnail.copy((uint8_t *) mThumbnail.binData.bin_data, mThumbnail.binData.bin_len);
|
||||
}
|
||||
|
||||
post.mCount = 0;
|
||||
post.mSize = 0;
|
||||
std::list<RsTlvFileItem>::iterator fit;
|
||||
for(fit = mAttachment.items.begin(); fit != mAttachment.items.end(); fit++)
|
||||
{
|
||||
RsGxsFile fi;
|
||||
fi.mName = RsDirUtil::getTopDir(fit->name);
|
||||
fi.mSize = fit->filesize;
|
||||
fi.mHash = fit->hash;
|
||||
fi.mPath = fit->path;
|
||||
|
||||
post.mFiles.push_back(fi);
|
||||
post.mCount++;
|
||||
post.mSize += fi.mSize;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsChannelSerialiser::sizeGxsChannelPostItem(RsGxsChannelPostItem *item)
|
||||
{
|
||||
|
||||
const RsGxsChannelPost& msg = item->mMsg;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(msg.mMsg); // mMsg.
|
||||
s += GetTlvStringSize(item->mMsg); // mMsg.
|
||||
s += item->mAttachment.TlvSize();
|
||||
s += item->mThumbnail.TlvSize();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
@ -325,7 +441,9 @@ bool RsGxsChannelSerialiser::serialiseGxsChannelPostItem(RsGxsChannelPostItem *i
|
|||
offset += 8;
|
||||
|
||||
/* GxsChannelPostItem */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mMsg.mMsg);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mMsg);
|
||||
item->mAttachment.SetTlv(data, tlvsize, &offset);
|
||||
item->mThumbnail.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
|
@ -385,7 +503,9 @@ RsGxsChannelPostItem* RsGxsChannelSerialiser::deserialiseGxsChannelPostItem(void
|
|||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->mMsg.mMsg);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->mMsg);
|
||||
item->mAttachment.GetTlv(data, rssize, &offset);
|
||||
item->mThumbnail.GetTlv(data, rssize, &offset);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
#include "rsgxsitems.h"
|
||||
#include "retroshare/rsgxschannels.h"
|
||||
|
||||
#include "util/rsdir.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSCHANNEL_GROUP_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM = 0x03;
|
||||
|
||||
|
@ -52,8 +54,12 @@ public:
|
|||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
// use conversion functions to transform:
|
||||
bool fromChannelGroup(RsGxsChannelGroup &group, bool moveImage);
|
||||
bool toChannelGroup(RsGxsChannelGroup &group, bool moveImage);
|
||||
|
||||
RsGxsChannelGroup mGroup;
|
||||
std::string mDescription;
|
||||
RsTlvImage mImage;
|
||||
};
|
||||
|
||||
class RsGxsChannelPostItem : public RsGxsMsgItem
|
||||
|
@ -66,7 +72,14 @@ public:
|
|||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
RsGxsChannelPost mMsg;
|
||||
// Slightly unusual structure.
|
||||
// use conversion functions to transform:
|
||||
bool fromChannelPost(RsGxsChannelPost &post, bool moveImage);
|
||||
bool toChannelPost(RsGxsChannelPost &post, bool moveImage);
|
||||
|
||||
std::string mMsg;
|
||||
RsTlvFileSet mAttachment;
|
||||
RsTlvImage mThumbnail;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2012 by Christopher Evi-Parker
|
||||
* Copyright 2012-2013 by Robert Fernie, 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.
|
||||
* 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
|
||||
|
@ -31,627 +31,363 @@
|
|||
|
||||
uint32_t RsGxsPostedSerialiser::size(RsItem *item)
|
||||
{
|
||||
RsGxsPostedPostItem* ppItem = NULL;
|
||||
RsGxsPostedCommentItem* pcItem = NULL;
|
||||
RsGxsPostedVoteItem* pvItem = NULL;
|
||||
RsGxsPostedGroupItem* pgItem = NULL;
|
||||
|
||||
if((ppItem = dynamic_cast<RsGxsPostedPostItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsPostedPostItem(ppItem);
|
||||
}
|
||||
else if((pcItem = dynamic_cast<RsGxsPostedCommentItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsPostedCommentItem(pcItem);
|
||||
}else if((pvItem = dynamic_cast<RsGxsPostedVoteItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsPostedVoteItem(pvItem);
|
||||
}else if((pgItem = dynamic_cast<RsGxsPostedGroupItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsPostedGroupItem(pgItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::size() Failed" << std::endl;
|
||||
#ifdef POSTED_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::size()" << std::endl;
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RsGxsPostedGroupItem* pgItem = NULL;
|
||||
RsGxsPostedPostItem* ppItem = NULL;
|
||||
|
||||
if ((pgItem = dynamic_cast<RsGxsPostedGroupItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsPostedGroupItem(pgItem);
|
||||
}
|
||||
else if ((ppItem = dynamic_cast<RsGxsPostedPostItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsPostedPostItem(ppItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
return RsGxsCommentSerialiser::size(item);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool RsGxsPostedSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
RsGxsPostedPostItem* ppItem = NULL;
|
||||
RsGxsPostedCommentItem* pcItem = NULL;
|
||||
RsGxsPostedVoteItem* pvItem = NULL;
|
||||
RsGxsPostedGroupItem* pgItem = NULL;
|
||||
|
||||
if((ppItem = dynamic_cast<RsGxsPostedPostItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsPostedPostItem(ppItem, data, size);
|
||||
}
|
||||
else if((pcItem = dynamic_cast<RsGxsPostedCommentItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsPostedCommentItem(pcItem, data, size);
|
||||
}else if((pvItem = dynamic_cast<RsGxsPostedVoteItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsPostedVoteItem(pvItem, data, size);
|
||||
}else if((pgItem = dynamic_cast<RsGxsPostedGroupItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsPostedGroupItem(pgItem, data, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialise() FAILED" << std::endl;
|
||||
#ifdef POSTED_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialise()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
RsGxsPostedPostItem* ppItem = NULL;
|
||||
RsGxsPostedGroupItem* pgItem = NULL;
|
||||
|
||||
if ((pgItem = dynamic_cast<RsGxsPostedGroupItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsPostedGroupItem(pgItem, data, size);
|
||||
}
|
||||
else if ((ppItem = dynamic_cast<RsGxsPostedPostItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsPostedPostItem(ppItem, data, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
return RsGxsCommentSerialiser::serialise(item, data, size);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem* RsGxsPostedSerialiser::deserialise(void *data, uint32_t *size)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialise()" << std::endl;
|
||||
#ifdef POSTED_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialise()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)))
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialise() ERROR Wrong Type";
|
||||
std::cerr << std::endl;
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
|
||||
case RS_PKT_SUBTYPE_POSTED_COMMENT_ITEM:
|
||||
return deserialiseGxsPostedCommentItem(data, size);
|
||||
case RS_PKT_SUBTYPE_POSTED_GRP_ITEM:
|
||||
return deserialiseGxsPostedGroupItem(data, size);
|
||||
case RS_PKT_SUBTYPE_POSTED_POST_ITEM:
|
||||
return deserialiseGxsPostedPostItem(data, size);
|
||||
case RS_PKT_SUBTYPE_POSTED_VOTE_ITEM:
|
||||
return deserialiseGxsPostedVoteItem(data, size);
|
||||
default:
|
||||
{
|
||||
#ifdef RS_SSERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialise(): subtype could not be dealt with"
|
||||
<< std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
case RS_PKT_SUBTYPE_POSTED_GRP_ITEM:
|
||||
return deserialiseGxsPostedGroupItem(data, size);
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_POSTED_POST_ITEM:
|
||||
return deserialiseGxsPostedPostItem(data, size);
|
||||
break;
|
||||
default:
|
||||
return RsGxsCommentSerialiser::deserialise(data, size);
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
void RsGxsPostedPostItem::clear()
|
||||
{
|
||||
mPost.mLink.clear();
|
||||
mPost.mNotes.clear();
|
||||
}
|
||||
|
||||
std::ostream & RsGxsPostedPostItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsPostedPostItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Link: " << mPost.mLink << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "Notes: " << mPost.mNotes << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsPostedPostItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
uint32_t RsGxsPostedSerialiser::sizeGxsPostedPostItem(RsGxsPostedPostItem* item)
|
||||
{
|
||||
RsPostedPost& p = item->mPost;
|
||||
RsPostedPost& p = item->mPost;
|
||||
|
||||
uint32_t s = 8;
|
||||
uint32_t s = 8;
|
||||
|
||||
s += GetTlvStringSize(p.mLink);
|
||||
s += GetTlvStringSize(p.mNotes);
|
||||
s += GetTlvStringSize(p.mLink);
|
||||
s += GetTlvStringSize(p.mNotes);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
uint32_t RsGxsPostedSerialiser::sizeGxsPostedCommentItem(RsGxsPostedCommentItem* item)
|
||||
{
|
||||
RsPostedComment& c = item->mComment;
|
||||
|
||||
uint32_t s = 8;
|
||||
|
||||
s += GetTlvStringSize(c.mComment);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
uint32_t RsGxsPostedSerialiser::sizeGxsPostedVoteItem(RsGxsPostedVoteItem* item)
|
||||
{
|
||||
RsPostedVote& v = item->mVote;
|
||||
|
||||
uint32_t s = 8;
|
||||
s += 1; // for vote direction
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
uint32_t RsGxsPostedSerialiser::sizeGxsPostedGroupItem(RsGxsPostedGroupItem* item)
|
||||
{
|
||||
RsPostedGroup& g = item->mGroup;
|
||||
|
||||
uint32_t s = 8;
|
||||
return s;
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsPostedSerialiser::serialiseGxsPostedPostItem(RsGxsPostedPostItem* item, void* data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem()" << std::endl;
|
||||
#ifdef POSTED_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsPostedPostItem(item);
|
||||
uint32_t offset = 0;
|
||||
uint32_t tlvsize = sizeGxsPostedPostItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize){
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem()()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
if(*size < tlvsize){
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem() Size too small" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsPhotoAlbumItem */
|
||||
/* RsPostedPost */
|
||||
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mPost.mLink);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mPost.mNotes);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mPost.mLink);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mPost.mNotes);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem() FAIL Size Error! " << std::endl;
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem() NOK" << std::endl;
|
||||
}
|
||||
#ifdef POSTED_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsGxsPostedSerialiser::serialiseGxsPostedCommentItem(RsGxsPostedCommentItem* item, void* data, uint32_t *size)
|
||||
|
||||
|
||||
|
||||
RsGxsPostedPostItem* RsGxsPostedSerialiser::deserialiseGxsPostedPostItem(void *data, uint32_t *size)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedCommentItem()" << std::endl;
|
||||
|
||||
#ifdef POSTED_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t tlvsize = sizeGxsPostedCommentItem(item);
|
||||
uint32_t offset = 0;
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize){
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedCommentItem()" << std::endl;
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_POSTED_POST_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() FAIL wrong type" << std::endl;
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() FAIL wrong size" << std::endl;
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsPostedPostItem* item = new RsGxsPostedPostItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->mPost.mLink);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->mPost.mNotes);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() FAIL size mismatch" << std::endl;
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef POSTED_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() NOK" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsPhotoAlbumItem */
|
||||
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mComment.mComment);
|
||||
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedCommentItem()() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedCommentItem()() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
return item;
|
||||
}
|
||||
|
||||
bool RsGxsPostedSerialiser::serialiseGxsPostedVoteItem(RsGxsPostedVoteItem* item, void* data, uint32_t *size)
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
void RsGxsPostedGroupItem::clear()
|
||||
{
|
||||
mGroup.mDescription.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedVoteItem()" << std::endl;
|
||||
#endif
|
||||
std::ostream & RsGxsPostedGroupItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsPostedGroupItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
uint32_t tlvsize = sizeGxsPostedVoteItem(item);
|
||||
uint32_t offset = 0;
|
||||
printIndent(out, int_Indent);
|
||||
out << "Description: " << mGroup.mDescription << std::endl;
|
||||
|
||||
if(*size < tlvsize){
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedVoteItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
printRsItemEnd(out ,"RsGxsPostedGroupItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
uint32_t RsGxsPostedSerialiser::sizeGxsPostedGroupItem(RsGxsPostedGroupItem* item)
|
||||
{
|
||||
RsPostedGroup& g = item->mGroup;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
s += GetTlvStringSize(g.mDescription);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= setRawUInt8(data, tlvsize, &offset, item->mVote.mDirection);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedVoteItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedVoteItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsPostedSerialiser::serialiseGxsPostedGroupItem(RsGxsPostedGroupItem* item, void* data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem()" << std::endl;
|
||||
#ifdef POSTED_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsPostedGroupItem(item);
|
||||
uint32_t offset = 0;
|
||||
uint32_t tlvsize = sizeGxsPostedGroupItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize){
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem()" << std::endl;
|
||||
if(*size < tlvsize){
|
||||
#ifdef POSTED_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsPhotoAlbumItem */
|
||||
/* PostedGroupItem */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mGroup.mDescription);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem() FAIL Size Error! " << std::endl;
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef POSTED_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem() NOK" << std::endl;
|
||||
}
|
||||
#ifdef POSTED_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsPostedPostItem* RsGxsPostedSerialiser::deserialiseGxsPostedPostItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem()" << 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_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_POSTED_POST_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsPostedPostItem* item = new RsGxsPostedPostItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->mPost.mLink);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->mPost.mNotes);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
RsGxsPostedCommentItem* RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem(void *data, uint32_t *size)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem()" << 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_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_POSTED_COMMENT_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsPostedCommentItem* item = new RsGxsPostedCommentItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->mComment.mComment);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
RsGxsPostedVoteItem* RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem()" << 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_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_POSTED_VOTE_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsPostedVoteItem* item = new RsGxsPostedVoteItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= getRawUInt8(data, rssize, &offset, &(item->mVote.mDirection));
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
RsGxsPostedGroupItem* RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem()" << std::endl;
|
||||
#ifdef POSTED_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_POSTED_VOTE_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL wrong type" << std::endl;
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_POSTED_GRP_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL wrong type" << std::endl;
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL wrong size" << std::endl;
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsPostedGroupItem* item = new RsGxsPostedGroupItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->mGroup.mDescription);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL size mismatch" << std::endl;
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef POSTED_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() NOK" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsPostedGroupItem* item = new RsGxsPostedGroupItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
void RsGxsPostedPostItem::clear()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::ostream & RsGxsPostedPostItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
return out;
|
||||
}
|
||||
|
||||
void RsGxsPostedVoteItem::clear()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::ostream & RsGxsPostedVoteItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
return out;
|
||||
}
|
||||
|
||||
void RsGxsPostedCommentItem::clear()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::ostream & RsGxsPostedCommentItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
return out;
|
||||
}
|
||||
|
||||
void RsGxsPostedGroupItem::clear()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::ostream & RsGxsPostedGroupItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
return out;
|
||||
|
||||
}
|
||||
|
|
|
@ -5,98 +5,64 @@
|
|||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
|
||||
#include "serialiser/rsgxscommentitems.h"
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
#include "retroshare/rsposted.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_POSTED_GRP_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_POSTED_POST_ITEM = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_POSTED_VOTE_ITEM = 0x04;
|
||||
const uint8_t RS_PKT_SUBTYPE_POSTED_COMMENT_ITEM = 0x05;
|
||||
|
||||
class RsGxsPostedPostItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
RsGxsPostedPostItem() : RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_POSTED,
|
||||
RS_PKT_SUBTYPE_POSTED_POST_ITEM)
|
||||
{return ; }
|
||||
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
RsPostedPost mPost;
|
||||
};
|
||||
|
||||
class RsGxsPostedVoteItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
RsGxsPostedVoteItem() : RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_POSTED,
|
||||
RS_PKT_SUBTYPE_POSTED_VOTE_ITEM)
|
||||
{return ;}
|
||||
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
RsPostedVote mVote;
|
||||
};
|
||||
|
||||
class RsGxsPostedCommentItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
RsGxsPostedCommentItem() : RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_POSTED,
|
||||
RS_PKT_SUBTYPE_POSTED_COMMENT_ITEM)
|
||||
{ return; }
|
||||
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
RsPostedComment mComment;
|
||||
};
|
||||
|
||||
class RsGxsPostedGroupItem : public RsGxsGrpItem
|
||||
{
|
||||
public:
|
||||
RsGxsPostedGroupItem() : RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_POSTED,
|
||||
RS_PKT_SUBTYPE_POSTED_GRP_ITEM)
|
||||
{ return; }
|
||||
RsGxsPostedGroupItem() : RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_POSTED,
|
||||
RS_PKT_SUBTYPE_POSTED_GRP_ITEM) { return; }
|
||||
virtual ~RsGxsPostedGroupItem() { return; }
|
||||
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
RsPostedGroup mGroup;
|
||||
RsPostedGroup mGroup;
|
||||
};
|
||||
|
||||
class RsGxsPostedSerialiser : public RsSerialType
|
||||
class RsGxsPostedPostItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
RsGxsPostedPostItem() : RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_POSTED,
|
||||
RS_PKT_SUBTYPE_POSTED_POST_ITEM) {return ; }
|
||||
virtual ~RsGxsPostedPostItem() { return; }
|
||||
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
RsPostedPost mPost;
|
||||
};
|
||||
|
||||
class RsGxsPostedSerialiser : public RsGxsCommentSerialiser
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsGxsPostedSerialiser()
|
||||
: RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_PHOTO)
|
||||
{ return; }
|
||||
RsGxsPostedSerialiser()
|
||||
:RsGxsCommentSerialiser(RS_SERVICE_GXSV1_TYPE_POSTED)
|
||||
{ return; }
|
||||
|
||||
virtual ~RsGxsPostedSerialiser() { return; }
|
||||
virtual ~RsGxsPostedSerialiser() { return; }
|
||||
|
||||
uint32_t size(RsItem *item);
|
||||
bool serialise(RsItem *item, void *data, uint32_t *size);
|
||||
RsItem* deserialise(void *data, uint32_t *size);
|
||||
uint32_t size(RsItem *item);
|
||||
bool serialise(RsItem *item, void *data, uint32_t *size);
|
||||
RsItem* deserialise(void *data, uint32_t *size);
|
||||
|
||||
private:
|
||||
|
||||
uint32_t sizeGxsPostedPostItem(RsGxsPostedPostItem* item);
|
||||
bool serialiseGxsPostedPostItem(RsGxsPostedPostItem* item, void* data, uint32_t *size);
|
||||
RsGxsPostedPostItem* deserialiseGxsPostedPostItem(void *data, uint32_t *size);
|
||||
uint32_t sizeGxsPostedGroupItem(RsGxsPostedGroupItem* item);
|
||||
bool serialiseGxsPostedGroupItem(RsGxsPostedGroupItem* item, void* data, uint32_t *size);
|
||||
RsGxsPostedGroupItem* deserialiseGxsPostedGroupItem(void *data, uint32_t *size);
|
||||
|
||||
uint32_t sizeGxsPostedCommentItem(RsGxsPostedCommentItem* item);
|
||||
bool serialiseGxsPostedCommentItem(RsGxsPostedCommentItem* item, void* data, uint32_t *size);
|
||||
RsGxsPostedCommentItem* deserialiseGxsPostedCommentItem(void *data, uint32_t *size);
|
||||
|
||||
uint32_t sizeGxsPostedVoteItem(RsGxsPostedVoteItem* item);
|
||||
bool serialiseGxsPostedVoteItem(RsGxsPostedVoteItem* item, void* data, uint32_t *size);
|
||||
RsGxsPostedVoteItem* deserialiseGxsPostedVoteItem(void *data, uint32_t *size);
|
||||
|
||||
uint32_t sizeGxsPostedGroupItem(RsGxsPostedGroupItem* item);
|
||||
bool serialiseGxsPostedGroupItem(RsGxsPostedGroupItem* item, void* data, uint32_t *size);
|
||||
RsGxsPostedGroupItem* deserialiseGxsPostedGroupItem(void *data, uint32_t *size);
|
||||
uint32_t sizeGxsPostedPostItem(RsGxsPostedPostItem* item);
|
||||
bool serialiseGxsPostedPostItem(RsGxsPostedPostItem* item, void* data, uint32_t *size);
|
||||
RsGxsPostedPostItem* deserialiseGxsPostedPostItem(void *data, uint32_t *size);
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue