mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 08:29:26 -05:00
serialiser updates for distrib config saving
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3315 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
e40c469aa4
commit
8b3af9143f
@ -75,6 +75,38 @@ std::ostream &RsDistribMsg::print(std::ostream &out, uint16_t indent)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RsDistribChildConfig::clear()
|
||||||
|
{
|
||||||
|
save_type = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& RsDistribChildConfig::print(std::ostream &out, uint16_t indent)
|
||||||
|
{
|
||||||
|
printRsItemBase(out, "RsDistribChildConfig", indent);
|
||||||
|
uint16_t int_Indent = indent + 2;
|
||||||
|
|
||||||
|
printIndent(out, int_Indent);
|
||||||
|
out << "save_type: " << save_type << std::endl;
|
||||||
|
|
||||||
|
printRsItemEnd(out, "RsDistribChildConfig", indent);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RsDistribConfigData::clear()
|
||||||
|
{
|
||||||
|
service_data.TlvClear();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& RsDistribConfigData::print(std::ostream &out, uint16_t indent)
|
||||||
|
{
|
||||||
|
printRsItemBase(out, "RsDistribConfigData", indent);
|
||||||
|
uint16_t int_Indent = indent + 2;
|
||||||
|
|
||||||
|
service_data.print(out, int_Indent);
|
||||||
|
|
||||||
|
printRsItemEnd(out, "RsDistribChildConfig", indent);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
void RsDistribSignedMsg::clear()
|
void RsDistribSignedMsg::clear()
|
||||||
{
|
{
|
||||||
@ -697,6 +729,136 @@ RsDistribSignedMsg *RsDistribSerialiser::deserialiseSignedMsg(void *data, uint32
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*********************** save data *******************************/
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t RsDistribSerialiser::sizeConfigData(RsDistribConfigData *item)
|
||||||
|
{
|
||||||
|
uint32_t s = 8; /* header */
|
||||||
|
|
||||||
|
/* RsDistribSignedMsg stuff */
|
||||||
|
s += item->service_data.TlvSize();
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* serialise the data to the buffer */
|
||||||
|
bool RsDistribSerialiser::serialiseConfigData(RsDistribConfigData *item, void *data, uint32_t *pktsize)
|
||||||
|
{
|
||||||
|
#ifdef RSSERIAL_DEBUG
|
||||||
|
std::cerr << "RsDistribSerialiser::serialiseConfigData()" << std::endl;
|
||||||
|
#endif
|
||||||
|
uint32_t tlvsize = sizeConfigData(item);
|
||||||
|
uint32_t offset = 0;
|
||||||
|
|
||||||
|
if (*pktsize < tlvsize)
|
||||||
|
{
|
||||||
|
#ifdef RSSERIAL_DEBUG
|
||||||
|
std::cerr << "RsDistribSerialiser::serialiseConfigData() FAIL no space" << std::endl;
|
||||||
|
#endif
|
||||||
|
return false; /* not enough space */
|
||||||
|
}
|
||||||
|
|
||||||
|
*pktsize = tlvsize;
|
||||||
|
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||||
|
|
||||||
|
/* skip the header */
|
||||||
|
offset += 8;
|
||||||
|
|
||||||
|
/* RsDistribSignedMsg */
|
||||||
|
ok &= item->service_data.SetTlv(data, tlvsize, &offset);
|
||||||
|
|
||||||
|
if (offset != tlvsize)
|
||||||
|
{
|
||||||
|
#ifdef RSSERIAL_DEBUG
|
||||||
|
std::cerr << "RsDistribSerialiser::serialiseConfigData() FAIL Size Error! " << std::endl;
|
||||||
|
#endif
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef RSSERIAL_DEBUG
|
||||||
|
if (!ok)
|
||||||
|
{
|
||||||
|
std::cerr << "RsDistribSerialiser::serialiseConfigData() NOK" << std::endl;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RsDistribConfigData *RsDistribSerialiser::deserialiseConfigData(void *data, uint32_t *pktsize)
|
||||||
|
{
|
||||||
|
#ifdef RSSERIAL_DEBUG
|
||||||
|
std::cerr << "RsDistribSerialiser::deserialiseConfigData()" << 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_DISTRIB_CONFIG_DATA != getRsItemSubType(rstype)))
|
||||||
|
{
|
||||||
|
#ifdef RSSERIAL_DEBUG
|
||||||
|
std::cerr << "RsDistribSerialiser::deserialiseSignedMsg() Wrong Type" << std::endl;
|
||||||
|
#endif
|
||||||
|
return NULL; /* wrong type */
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*pktsize < rssize) /* check size */
|
||||||
|
{
|
||||||
|
#ifdef RSSERIAL_DEBUG
|
||||||
|
std::cerr << "RsDistribSerialiser::deserialiseSignedMsg() Wrong Size" << std::endl;
|
||||||
|
#endif
|
||||||
|
return NULL; /* not enough data */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set the packet length */
|
||||||
|
*pktsize = rssize;
|
||||||
|
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
/* ready to load */
|
||||||
|
RsDistribConfigData *item = new RsDistribConfigData();
|
||||||
|
item->clear();
|
||||||
|
|
||||||
|
/* skip the header */
|
||||||
|
offset += 8;
|
||||||
|
|
||||||
|
/* RsDistribGrp */
|
||||||
|
ok &= item->service_data.GetTlv(data, rssize, &offset);
|
||||||
|
|
||||||
|
if (offset != rssize)
|
||||||
|
{
|
||||||
|
#ifdef RSSERIAL_DEBUG
|
||||||
|
std::cerr << "RsDistribSerialiser::deserialiseSignedMsg() size mismatch" << std::endl;
|
||||||
|
#endif
|
||||||
|
/* error */
|
||||||
|
delete item;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ok)
|
||||||
|
{
|
||||||
|
#ifdef RSSERIAL_DEBUG
|
||||||
|
std::cerr << "RsDistribSerialiser::deserialiseSignedMsg() NOK" << std::endl;
|
||||||
|
#endif
|
||||||
|
delete item;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t RsDistribSerialiser::size(RsItem *i)
|
uint32_t RsDistribSerialiser::size(RsItem *i)
|
||||||
@ -704,6 +866,7 @@ uint32_t RsDistribSerialiser::size(RsItem *i)
|
|||||||
RsDistribGrp *dg;
|
RsDistribGrp *dg;
|
||||||
RsDistribGrpKey *dgk;
|
RsDistribGrpKey *dgk;
|
||||||
RsDistribSignedMsg *dsm;
|
RsDistribSignedMsg *dsm;
|
||||||
|
RsDistribConfigData *dsd;
|
||||||
|
|
||||||
/* in order of frequency */
|
/* in order of frequency */
|
||||||
if (NULL != (dsm = dynamic_cast<RsDistribSignedMsg *>(i)))
|
if (NULL != (dsm = dynamic_cast<RsDistribSignedMsg *>(i)))
|
||||||
@ -718,6 +881,10 @@ uint32_t RsDistribSerialiser::size(RsItem *i)
|
|||||||
{
|
{
|
||||||
return sizeGrpKey(dgk);
|
return sizeGrpKey(dgk);
|
||||||
}
|
}
|
||||||
|
else if(NULL != (dsd = dynamic_cast<RsDistribConfigData *>(i)))
|
||||||
|
{
|
||||||
|
return sizeConfigData(dsd);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -730,6 +897,7 @@ bool RsDistribSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize
|
|||||||
RsDistribGrp *dg;
|
RsDistribGrp *dg;
|
||||||
RsDistribGrpKey *dgk;
|
RsDistribGrpKey *dgk;
|
||||||
RsDistribSignedMsg *dsm;
|
RsDistribSignedMsg *dsm;
|
||||||
|
RsDistribConfigData *dsd;
|
||||||
|
|
||||||
if (NULL != (dsm = dynamic_cast<RsDistribSignedMsg *>(i)))
|
if (NULL != (dsm = dynamic_cast<RsDistribSignedMsg *>(i)))
|
||||||
{
|
{
|
||||||
@ -743,6 +911,10 @@ bool RsDistribSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize
|
|||||||
{
|
{
|
||||||
return serialiseGrpKey(dgk, data, pktsize);
|
return serialiseGrpKey(dgk, data, pktsize);
|
||||||
}
|
}
|
||||||
|
else if(NULL != (dsd = dynamic_cast<RsDistribConfigData *>(i)))
|
||||||
|
{
|
||||||
|
return serialiseConfigData(dsd, data, pktsize);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -771,6 +943,9 @@ RsItem *RsDistribSerialiser::deserialise(void *data, uint32_t *pktsize)
|
|||||||
case RS_PKT_SUBTYPE_DISTRIB_SIGNED_MSG:
|
case RS_PKT_SUBTYPE_DISTRIB_SIGNED_MSG:
|
||||||
return deserialiseSignedMsg(data, pktsize);
|
return deserialiseSignedMsg(data, pktsize);
|
||||||
break;
|
break;
|
||||||
|
case RS_PKT_SUBTYPE_DISTRIB_CONFIG_DATA:
|
||||||
|
return deserialiseConfigData(data, pktsize);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return NULL;
|
return NULL;
|
||||||
break;
|
break;
|
||||||
|
@ -37,10 +37,58 @@
|
|||||||
const uint8_t RS_PKT_SUBTYPE_DISTRIB_GRP = 0x01;
|
const uint8_t RS_PKT_SUBTYPE_DISTRIB_GRP = 0x01;
|
||||||
const uint8_t RS_PKT_SUBTYPE_DISTRIB_GRP_KEY = 0x02;
|
const uint8_t RS_PKT_SUBTYPE_DISTRIB_GRP_KEY = 0x02;
|
||||||
const uint8_t RS_PKT_SUBTYPE_DISTRIB_SIGNED_MSG = 0x03;
|
const uint8_t RS_PKT_SUBTYPE_DISTRIB_SIGNED_MSG = 0x03;
|
||||||
|
const uint8_t RS_PKT_SUBTYPE_DISTRIB_CONFIG_DATA = 0x04;
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* This should be derived from to store RsDistrib child objects
|
||||||
|
* save data
|
||||||
|
*/
|
||||||
|
class RsDistribChildConfig: public RsItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RsDistribChildConfig(uint16_t servtype, uint8_t subtype)
|
||||||
|
: RsItem(RS_PKT_VERSION_SERVICE, servtype, subtype) {return;}
|
||||||
|
|
||||||
|
virtual ~RsDistribChildConfig() { return; }
|
||||||
|
|
||||||
|
virtual void clear();
|
||||||
|
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||||
|
|
||||||
|
/// use this to id the type of data you want to save
|
||||||
|
uint32_t save_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* This should be used to save the service data such as settings
|
||||||
|
*/
|
||||||
|
class RsDistribConfigData: public RsItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RsDistribConfigData()
|
||||||
|
: RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DISTRIB, RS_PKT_SUBTYPE_DISTRIB_CONFIG_DATA), service_data(TLV_TYPE_BIN_SERIALISE)
|
||||||
|
{return;}
|
||||||
|
|
||||||
|
virtual ~RsDistribConfigData() { return; }
|
||||||
|
|
||||||
|
virtual void clear();
|
||||||
|
|
||||||
|
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||||
|
|
||||||
|
// this is where a derived distrib service saves its data
|
||||||
|
RsTlvBinaryData service_data;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* This is used by p3Distrib for storing messages
|
||||||
|
* of derived services, attributes are given for writing
|
||||||
|
* personal signatures (confirms user) and publish signatures (to
|
||||||
|
* confirm consistency source)
|
||||||
|
*/
|
||||||
class RsDistribMsg: public RsItem
|
class RsDistribMsg: public RsItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -53,18 +101,32 @@ virtual void clear();
|
|||||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||||
|
|
||||||
std::string grpId; /* Grp Id */
|
std::string grpId; /* Grp Id */
|
||||||
std::string parentId; /* Parent Msg Id */
|
|
||||||
std::string threadId; /* Thread Msg Id */
|
/// Parent Msg Id, msgs above a thread
|
||||||
|
std::string parentId;
|
||||||
|
|
||||||
|
/// Thread Msg Id: useful identifyingfor responses
|
||||||
|
///to a forum msg and replies in general
|
||||||
|
std::string threadId;
|
||||||
uint32_t timestamp;
|
uint32_t timestamp;
|
||||||
|
|
||||||
/* Not Serialised */
|
/* Not Serialised */
|
||||||
|
|
||||||
std::string msgId; /* Msg Id */
|
std::string msgId; /* Msg Id */
|
||||||
time_t childTS; /* timestamp of most recent child */
|
time_t childTS; /* timestamp of most recent child */
|
||||||
|
|
||||||
|
/// used to confirm the message is from a group author, or someone with valid publish key
|
||||||
RsTlvKeySignature publishSignature;
|
RsTlvKeySignature publishSignature;
|
||||||
|
|
||||||
|
/// used to confirm message is from a particular peer
|
||||||
RsTlvKeySignature personalSignature;
|
RsTlvKeySignature personalSignature;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* This is used as a storage container for messages from a service
|
||||||
|
* via the binary data container (packet)
|
||||||
|
*/
|
||||||
class RsDistribSignedMsg: public RsItem
|
class RsDistribSignedMsg: public RsItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -79,10 +141,13 @@ virtual void clear();
|
|||||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||||
|
|
||||||
std::string grpId;
|
std::string grpId;
|
||||||
std::string msgId; /* from publishSignature */
|
|
||||||
|
/// should be taken publishSignature
|
||||||
|
std::string msgId;
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
uint32_t timestamp;
|
uint32_t timestamp;
|
||||||
|
|
||||||
|
/// in order to tranfer messages from service level to distrib level
|
||||||
RsTlvBinaryData packet;
|
RsTlvBinaryData packet;
|
||||||
RsTlvKeySignature publishSignature;
|
RsTlvKeySignature publishSignature;
|
||||||
RsTlvKeySignature personalSignature;
|
RsTlvKeySignature personalSignature;
|
||||||
@ -178,6 +243,12 @@ virtual uint32_t sizeSignedMsg(RsDistribSignedMsg *);
|
|||||||
virtual bool serialiseSignedMsg (RsDistribSignedMsg *item, void *data, uint32_t *size);
|
virtual bool serialiseSignedMsg (RsDistribSignedMsg *item, void *data, uint32_t *size);
|
||||||
virtual RsDistribSignedMsg *deserialiseSignedMsg(void *data, uint32_t *size);
|
virtual RsDistribSignedMsg *deserialiseSignedMsg(void *data, uint32_t *size);
|
||||||
|
|
||||||
|
/* For RS_PKT_SUBTYPE_DISTRIB_SAVE_DATA */
|
||||||
|
virtual uint32_t sizeConfigData(RsDistribConfigData *);
|
||||||
|
virtual bool serialiseConfigData(RsDistribConfigData *item, void *data, uint32_t *size);
|
||||||
|
virtual RsDistribConfigData *deserialiseConfigData(void* data, uint32_t *size);
|
||||||
|
|
||||||
|
|
||||||
const uint16_t SERVICE_TYPE;
|
const uint16_t SERVICE_TYPE;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -67,6 +67,48 @@ std::ostream &RsForumMsg::print(std::ostream &out, uint16_t indent)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RsForumReadStatus::clear()
|
||||||
|
{
|
||||||
|
|
||||||
|
RsDistribChildConfig::clear();
|
||||||
|
|
||||||
|
forumId.clear();
|
||||||
|
msgReadStatus.clear();
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& RsForumReadStatus::print(std::ostream &out, uint16_t indent = 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
printRsItemBase(out, "RsForumMsg", indent);
|
||||||
|
uint16_t int_Indent = indent + 2;
|
||||||
|
|
||||||
|
RsDistribChildConfig::print(out, int_Indent);
|
||||||
|
|
||||||
|
printIndent(out, int_Indent);
|
||||||
|
out << "ForumId: " << forumId << std::endl;
|
||||||
|
|
||||||
|
printIndent(out, int_Indent);
|
||||||
|
out << "ForumId: " << forumId << std::endl;
|
||||||
|
|
||||||
|
std::map<std::string, uint32_t>::iterator mit = msgReadStatus.begin();
|
||||||
|
|
||||||
|
for(; mit != msgReadStatus.end(); mit++)
|
||||||
|
{
|
||||||
|
|
||||||
|
printIndent(out, int_Indent);
|
||||||
|
out << "msgId : " << mit->first << std::endl;
|
||||||
|
|
||||||
|
printIndent(out, int_Indent);
|
||||||
|
out << " status : " << mit->second << std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
printRsItemEnd(out, "RsForumMsg", indent);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
@ -88,6 +130,7 @@ uint32_t RsForumSerialiser::sizeMsg(RsForumMsg *item)
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* serialise the data to the buffer */
|
/* serialise the data to the buffer */
|
||||||
bool RsForumSerialiser::serialiseMsg(RsForumMsg *item, void *data, uint32_t *pktsize)
|
bool RsForumSerialiser::serialiseMsg(RsForumMsg *item, void *data, uint32_t *pktsize)
|
||||||
{
|
{
|
||||||
@ -199,19 +242,224 @@ RsForumMsg *RsForumSerialiser::deserialiseMsg(void *data, uint32_t *pktsize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*************************************************************************/
|
||||||
|
/*************************************************************************/
|
||||||
|
|
||||||
|
uint32_t RsForumSerialiser::sizeReadStatus(RsForumReadStatus *item)
|
||||||
|
{
|
||||||
|
uint32_t s = 8; /* header */
|
||||||
|
/* RsDistribChildConfig stuff */
|
||||||
|
|
||||||
|
s += GetTlvUInt32Size(); /* save_type */
|
||||||
|
|
||||||
|
/* RsForumReadStatus stuff */
|
||||||
|
|
||||||
|
GetTlvStringSize(item->forumId);
|
||||||
|
|
||||||
|
std::map<std::string, uint32_t>::iterator mit = item->msgReadStatus.begin();
|
||||||
|
|
||||||
|
for(; mit != item->msgReadStatus.end(); mit++)
|
||||||
|
{
|
||||||
|
GetTlvStringSize(mit->first); /* key */
|
||||||
|
s += GetTlvUInt32Size(); /* value */
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* serialise the data to the buffer */
|
||||||
|
bool RsForumSerialiser::serialiseReadStatus(RsForumReadStatus *item, void *data, uint32_t *pktsize)
|
||||||
|
{
|
||||||
|
uint32_t tlvsize = sizeReadStatus(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);
|
||||||
|
|
||||||
|
std::cerr << "RsForumSerialiser::serialiseReadStatus() Header: " << ok << std::endl;
|
||||||
|
std::cerr << "RsForumSerialiser::serialiseReadStatus() Size: " << tlvsize << std::endl;
|
||||||
|
|
||||||
|
/* skip the header */
|
||||||
|
offset += 8;
|
||||||
|
|
||||||
|
/* RsDistribMsg first */
|
||||||
|
|
||||||
|
ok &= setRawUInt32(data, tlvsize, &offset, item->save_type);
|
||||||
|
std::cerr << "RsForumSerialiser::serialiseReadStatus() save_type: " << ok << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* RsForumMsg */
|
||||||
|
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GROUPID, item->forumId);
|
||||||
|
std::cerr << "RsForumSerialiser::serialiseReadStatus() forumId: " << ok << std::endl;
|
||||||
|
|
||||||
|
std::map<std::string, uint32_t>::iterator mit = item->msgReadStatus.begin();
|
||||||
|
|
||||||
|
for(; mit != item->msgReadStatus.end(); mit++)
|
||||||
|
{
|
||||||
|
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSGID, mit->first); /* key */
|
||||||
|
ok &= setRawUInt32(data, tlvsize, &offset, mit->second); /* value */
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cerr << "RsForumSerialiser::serialiseReadStatus() msgReadStatus: " << ok << std::endl;
|
||||||
|
|
||||||
|
if (offset != tlvsize)
|
||||||
|
{
|
||||||
|
ok = false;
|
||||||
|
std::cerr << "RsForumSerialiser::serialiseReadStatus() Size Error! " << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
RsForumReadStatus *RsForumSerialiser::deserialiseReadStatus(void *data, uint32_t *pktsize)
|
||||||
|
{
|
||||||
|
/* get the type and size */
|
||||||
|
uint32_t rstype = getRsItemId(data);
|
||||||
|
uint32_t rssize = getRsItemSize(data);
|
||||||
|
|
||||||
|
uint32_t offset = 0;
|
||||||
|
|
||||||
|
|
||||||
|
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||||
|
(RS_SERVICE_TYPE_FORUM != getRsItemService(rstype)) ||
|
||||||
|
(RS_PKT_SUBTYPE_FORUM_READ_STATUS != getRsItemSubType(rstype)))
|
||||||
|
{
|
||||||
|
return NULL; /* wrong type */
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*pktsize < rssize) /* check size */
|
||||||
|
return NULL; /* not enough data */
|
||||||
|
|
||||||
|
/* set the packet length */
|
||||||
|
*pktsize = rssize;
|
||||||
|
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
/* ready to load */
|
||||||
|
RsForumReadStatus *item = new RsForumReadStatus();
|
||||||
|
item->clear();
|
||||||
|
|
||||||
|
/* skip the header */
|
||||||
|
offset += 8;
|
||||||
|
|
||||||
|
/* RsDistribMsg first */
|
||||||
|
ok &= getRawUInt32(data, rssize, &offset, &(item->save_type));
|
||||||
|
|
||||||
|
/* RsForumMsg */
|
||||||
|
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_GROUPID, item->forumId);
|
||||||
|
|
||||||
|
std::string key;
|
||||||
|
uint32_t value;
|
||||||
|
|
||||||
|
while(offset != rssize)
|
||||||
|
{
|
||||||
|
key.clear();
|
||||||
|
value = 0;
|
||||||
|
|
||||||
|
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSGID, key); /* key */
|
||||||
|
|
||||||
|
/* incomplete key value pair? then fail*/
|
||||||
|
if(offset == rssize)
|
||||||
|
{
|
||||||
|
delete item;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ok &= getRawUInt32(data, rssize, &offset, &value); /* value */
|
||||||
|
|
||||||
|
item->msgReadStatus.insert(std::pair<std::string, uint32_t>(key, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ok)
|
||||||
|
{
|
||||||
|
delete item;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************/
|
||||||
|
|
||||||
uint32_t RsForumSerialiser::size(RsItem *item)
|
uint32_t RsForumSerialiser::size(RsItem *item)
|
||||||
{
|
{
|
||||||
return sizeMsg((RsForumMsg *) item);
|
RsForumMsg* dfm;
|
||||||
|
RsForumReadStatus* drs;
|
||||||
|
|
||||||
|
if( NULL != ( dfm = dynamic_cast<RsForumMsg*>(item)))
|
||||||
|
{
|
||||||
|
return sizeMsg(dfm);
|
||||||
}
|
}
|
||||||
|
else if(NULL != (drs = dynamic_cast<RsForumReadStatus* >(item)))
|
||||||
|
{
|
||||||
|
return sizeReadStatus(drs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool RsForumSerialiser::serialise(RsItem *item, void *data, uint32_t *pktsize)
|
bool RsForumSerialiser::serialise(RsItem *item, void *data, uint32_t *pktsize)
|
||||||
{
|
{
|
||||||
return serialiseMsg((RsForumMsg *) item, data, pktsize);
|
|
||||||
|
#ifdef RSSERIAL_DEBUG
|
||||||
|
std::cerr << "RsForumSerialiser::serialise()" << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
RsForumMsg* dfm;
|
||||||
|
RsForumReadStatus* drs;
|
||||||
|
|
||||||
|
if( NULL != ( dfm = dynamic_cast<RsForumMsg*>(item)))
|
||||||
|
{
|
||||||
|
return serialiseMsg(dfm, data, pktsize);
|
||||||
|
}
|
||||||
|
else if(NULL != (drs = dynamic_cast<RsForumReadStatus* >(item)))
|
||||||
|
{
|
||||||
|
return serialiseReadStatus(drs, data, pktsize);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
RsItem *RsForumSerialiser::deserialise(void *data, uint32_t *pktsize)
|
RsItem *RsForumSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#ifdef RSSERIAL_DEBUG
|
||||||
|
std::cerr << "RsForumSerialiser::deserialise()" << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* get the type and size */
|
||||||
|
uint32_t rstype = getRsItemId(data);
|
||||||
|
|
||||||
|
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||||
|
(RS_SERVICE_TYPE_FORUM != getRsItemService(rstype)))
|
||||||
|
{
|
||||||
|
return NULL; /* wrong type */
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(getRsItemSubType(rstype))
|
||||||
|
{
|
||||||
|
case RS_PKT_SUBTYPE_FORUM_MSG:
|
||||||
return deserialiseMsg(data, pktsize);
|
return deserialiseMsg(data, pktsize);
|
||||||
|
break;
|
||||||
|
case RS_PKT_SUBTYPE_FORUM_READ_STATUS:
|
||||||
|
return deserialiseReadStatus(data, pktsize);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
const uint8_t RS_PKT_SUBTYPE_FORUM_GRP = 0x01;
|
const uint8_t RS_PKT_SUBTYPE_FORUM_GRP = 0x01;
|
||||||
const uint8_t RS_PKT_SUBTYPE_FORUM_MSG = 0x02;
|
const uint8_t RS_PKT_SUBTYPE_FORUM_MSG = 0x02;
|
||||||
|
const uint8_t RS_PKT_SUBTYPE_FORUM_READ_STATUS = 0x03;
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|
||||||
@ -62,6 +63,27 @@ virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* This is used to keep track of whether a message has been read
|
||||||
|
* by client
|
||||||
|
*/
|
||||||
|
class RsForumReadStatus : public RsDistribChildConfig
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RsForumReadStatus()
|
||||||
|
: RsDistribChildConfig(RS_SERVICE_TYPE_FORUM, RS_PKT_SUBTYPE_FORUM_READ_STATUS)
|
||||||
|
{ return; }
|
||||||
|
|
||||||
|
virtual void clear();
|
||||||
|
virtual std::ostream& print(std::ostream &out, uint16_t indent);
|
||||||
|
|
||||||
|
std::string forumId;
|
||||||
|
|
||||||
|
/// a map which contains the read for messages within a forum
|
||||||
|
std::map<std::string, uint32_t> msgReadStatus;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
class RsForumSerialiser: public RsSerialType
|
class RsForumSerialiser: public RsSerialType
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -87,6 +109,10 @@ virtual uint32_t sizeMsg(RsForumMsg *);
|
|||||||
virtual bool serialiseMsg(RsForumMsg *item, void *data, uint32_t *size);
|
virtual bool serialiseMsg(RsForumMsg *item, void *data, uint32_t *size);
|
||||||
virtual RsForumMsg *deserialiseMsg(void *data, uint32_t *size);
|
virtual RsForumMsg *deserialiseMsg(void *data, uint32_t *size);
|
||||||
|
|
||||||
|
virtual uint32_t sizeReadStatus(RsForumReadStatus* );
|
||||||
|
virtual bool serialiseReadStatus(RsForumReadStatus* item, void* data, uint32_t *size);
|
||||||
|
virtual RsForumReadStatus *deserialiseReadStatus(void* data, uint32_t *size);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
@ -173,36 +173,6 @@ virtual RsItem * deserialise(void *data, uint32_t *size);
|
|||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|
||||||
class RsBlogMsg: public RsItem
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
RsBlogMsg()
|
|
||||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_QBLOG,
|
|
||||||
RS_PKT_SUBTYPE_DEFAULT)
|
|
||||||
{ return; }
|
|
||||||
virtual ~RsBlogMsg();
|
|
||||||
virtual void clear();
|
|
||||||
|
|
||||||
RsTlvBinaryData cert; /* Mandatory */
|
|
||||||
RsTlvFileSet files; /* Mandatory */
|
|
||||||
RsTlvBinaryData sign; /* Mandatory */
|
|
||||||
};
|
|
||||||
|
|
||||||
class RsBlogMsgSerialiser: public RsSerialType
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
RsBlogMsgSerialiser()
|
|
||||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_QBLOG)
|
|
||||||
{ return; }
|
|
||||||
|
|
||||||
virtual ~RsBlogMsgSerialiser();
|
|
||||||
|
|
||||||
virtual uint32_t size(RsItem *);
|
|
||||||
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
|
|
||||||
virtual RsItem * deserialise(void *data, uint32_t *size);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|
||||||
#endif /* RS_SERVICE_ITEMS_H */
|
#endif /* RS_SERVICE_ITEMS_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user