2013-11-10 17:27:50 -05:00
|
|
|
/*
|
|
|
|
* 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"
|
2013-11-16 08:40:04 -05:00
|
|
|
#include "rsbaseserial.h"
|
2013-11-10 17:27:50 -05:00
|
|
|
|
|
|
|
void RsGxsGrpUpdateItem::clear()
|
|
|
|
{
|
|
|
|
grpUpdateTS = 0;
|
|
|
|
peerId.clear();
|
|
|
|
}
|
|
|
|
std::ostream& RsGxsGrpUpdateItem::print(std::ostream& out, uint16_t indent)
|
|
|
|
{
|
2014-03-23 08:13:44 -04:00
|
|
|
printRsItemBase(out, "RsGxsGrpUpdateItem", indent);
|
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
out << "peerId: " << peerId << std::endl;
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "grpUpdateTS: " << grpUpdateTS << std::endl;
|
|
|
|
printIndent(out, int_Indent);
|
2015-01-31 13:06:37 -05:00
|
|
|
return out ;
|
2013-11-10 17:27:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RsGxsMsgUpdateItem::clear()
|
|
|
|
{
|
2015-01-31 13:06:37 -05:00
|
|
|
msgUpdateInfos.clear();
|
2013-11-10 17:27:50 -05:00
|
|
|
peerId.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream& RsGxsMsgUpdateItem::print(std::ostream& out, uint16_t indent)
|
|
|
|
{
|
2014-03-23 08:13:44 -04:00
|
|
|
RsPeerId peerId;
|
|
|
|
std::map<RsGxsGroupId, uint32_t> msgUpdateTS;
|
|
|
|
|
|
|
|
printRsItemBase(out, "RsGxsMsgUpdateItem", indent);
|
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
out << "peerId: " << peerId << std::endl;
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
|
2015-01-31 13:06:37 -05:00
|
|
|
std::map<RsGxsGroupId, MsgUpdateInfo>::const_iterator cit = msgUpdateInfos.begin();
|
2014-03-23 08:13:44 -04:00
|
|
|
out << "msgUpdateTS map:" << std::endl;
|
|
|
|
int_Indent += 2;
|
2015-01-31 13:06:37 -05:00
|
|
|
for(; cit != msgUpdateInfos.end(); ++cit)
|
2014-03-23 08:13:44 -04:00
|
|
|
{
|
2015-01-31 13:06:37 -05:00
|
|
|
out << "grpId: " << cit->first << std::endl;
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "Msg time stamp: " << cit->second.time_stamp << std::endl;
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "posts available: " << cit->second.message_count << std::endl;
|
|
|
|
printIndent(out, int_Indent);
|
2014-03-23 08:13:44 -04:00
|
|
|
}
|
|
|
|
|
2014-01-20 06:42:27 -05:00
|
|
|
return out;
|
2013-11-17 18:15:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RsGxsServerMsgUpdateItem::clear()
|
|
|
|
{
|
|
|
|
msgUpdateTS = 0;
|
|
|
|
grpId.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream& RsGxsServerMsgUpdateItem::print(std::ostream& out, uint16_t indent)
|
|
|
|
{
|
2014-03-23 08:13:44 -04:00
|
|
|
printRsItemBase(out, "RsGxsServerMsgUpdateItem", indent);
|
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
out << "grpId: " << grpId << std::endl;
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "msgUpdateTS: " << msgUpdateTS << std::endl;
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
return out;
|
2013-11-10 17:27:50 -05:00
|
|
|
}
|
|
|
|
|
2013-11-17 18:15:39 -05:00
|
|
|
|
|
|
|
void RsGxsServerGrpUpdateItem::clear()
|
|
|
|
{
|
|
|
|
grpUpdateTS = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream& RsGxsServerGrpUpdateItem::print(std::ostream& out, uint16_t indent)
|
|
|
|
{
|
2014-03-23 08:13:44 -04:00
|
|
|
printRsItemBase(out, "RsGxsServerGrpUpdateItem", indent);
|
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
out << "grpUpdateTS: " << grpUpdateTS << std::endl;
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
|
2014-01-20 06:42:27 -05:00
|
|
|
return out;
|
2013-11-17 18:15:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-10 17:27:50 -05:00
|
|
|
uint32_t RsGxsUpdateSerialiser::size(RsItem* item)
|
|
|
|
{
|
|
|
|
RsGxsMsgUpdateItem* mui = NULL;
|
|
|
|
RsGxsGrpUpdateItem* gui = NULL;
|
2013-11-16 08:40:04 -05:00
|
|
|
RsGxsServerGrpUpdateItem* gsui = NULL;
|
|
|
|
RsGxsServerMsgUpdateItem* msui = NULL;
|
2013-11-10 17:27:50 -05:00
|
|
|
|
|
|
|
if((mui = dynamic_cast<RsGxsMsgUpdateItem*>(item)) != NULL)
|
|
|
|
{
|
|
|
|
return sizeGxsMsgUpdate(mui);
|
|
|
|
}else if(( gui = dynamic_cast<RsGxsGrpUpdateItem*>(item)) != NULL){
|
|
|
|
return sizeGxsGrpUpdate(gui);
|
2013-11-16 08:40:04 -05:00
|
|
|
}else if((gsui = dynamic_cast<RsGxsServerGrpUpdateItem*>(item)) != NULL)
|
|
|
|
{
|
|
|
|
return sizeGxsServerGrpUpdate(gsui);
|
|
|
|
}else if((msui = dynamic_cast<RsGxsServerMsgUpdateItem*>(item)) != NULL)
|
|
|
|
{
|
|
|
|
return sizeGxsServerMsgUpdate(msui);
|
2013-11-10 17:27:50 -05:00
|
|
|
}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)
|
|
|
|
{
|
2013-11-16 08:40:04 -05:00
|
|
|
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;
|
|
|
|
}
|
2013-11-10 17:27:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
RsItem* RsGxsUpdateSerialiser::deserialise(void* data, uint32_t* size)
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
2013-11-16 08:40:04 -05:00
|
|
|
std::cerr << "RsGxsUpdateSerialiser::deserialise()" << std::endl;
|
2013-11-10 17:27:50 -05:00
|
|
|
#endif
|
|
|
|
/* get the type and size */
|
|
|
|
uint32_t rstype = getRsItemId(data);
|
|
|
|
|
|
|
|
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
2013-11-16 08:40:04 -05:00
|
|
|
(SERVICE_TYPE != getRsItemService(rstype)))
|
2013-11-10 17:27:50 -05:00
|
|
|
{
|
|
|
|
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);
|
2013-11-16 08:40:04 -05:00
|
|
|
case RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE:
|
|
|
|
return deserialGxsServerGrpUpddate(data, size);
|
|
|
|
case RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE:
|
|
|
|
return deserialGxsServerMsgUpdate(data, size);
|
2013-11-10 17:27:50 -05:00
|
|
|
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
|
2014-03-17 16:56:06 -04:00
|
|
|
s += item->peerId.serial_size();
|
2015-01-31 13:06:37 -05:00
|
|
|
s += 4; // mUpdateTS
|
|
|
|
return s;
|
2013-11-10 17:27:50 -05:00
|
|
|
}
|
|
|
|
|
2014-03-23 08:13:44 -04:00
|
|
|
uint32_t RsGxsUpdateSerialiser::sizeGxsServerGrpUpdate(RsGxsServerGrpUpdateItem* /* item */)
|
2013-11-16 08:40:04 -05:00
|
|
|
{
|
|
|
|
uint32_t s = 8; // header size
|
|
|
|
s += 4; // time stamp
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2013-11-10 17:27:50 -05:00
|
|
|
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;
|
|
|
|
|
2013-11-16 08:40:04 -05:00
|
|
|
/* RsGxsGrpUpdateItem */
|
2013-11-10 17:27:50 -05:00
|
|
|
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
ok &= item->peerId.serialise(data, *size, offset) ;
|
2013-11-10 17:27:50 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-11-16 08:40:04 -05:00
|
|
|
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;
|
|
|
|
}
|
2015-01-31 13:06:37 -05:00
|
|
|
RsGxsGrpUpdateItem* RsGxsUpdateSerialiser::deserialGxsGrpUpddate(void* data, uint32_t* size)
|
2013-11-10 17:27:50 -05:00
|
|
|
{
|
2013-11-16 08:40:04 -05:00
|
|
|
#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;
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
ok &= item->peerId.deserialise(data, *size, offset) ;
|
2013-12-15 15:11:39 -05:00
|
|
|
ok &= getRawUInt32(data, *size, &offset, &(item->grpUpdateTS));
|
2013-11-16 08:40:04 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2013-11-10 17:27:50 -05:00
|
|
|
|
2013-11-16 08:40:04 -05:00
|
|
|
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;
|
2013-11-10 17:27:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t RsGxsUpdateSerialiser::sizeGxsMsgUpdate(RsGxsMsgUpdateItem* item)
|
|
|
|
{
|
2015-01-31 13:06:37 -05:00
|
|
|
uint32_t s = 8; // header size
|
2014-03-17 16:56:06 -04:00
|
|
|
s += item->peerId.serial_size() ;//GetTlvStringSize(item->peerId);
|
2013-11-10 17:27:50 -05:00
|
|
|
|
2015-01-31 13:06:37 -05:00
|
|
|
s += item->msgUpdateInfos.size() * (4 + 4 + RsGxsGroupId::serial_size());
|
|
|
|
s += 4; // number of map items
|
2013-11-10 17:27:50 -05:00
|
|
|
|
2015-01-31 13:06:37 -05:00
|
|
|
return s;
|
2013-11-10 17:27:50 -05:00
|
|
|
}
|
|
|
|
|
2013-11-16 08:40:04 -05:00
|
|
|
uint32_t RsGxsUpdateSerialiser::sizeGxsServerMsgUpdate(RsGxsServerMsgUpdateItem* item)
|
|
|
|
{
|
|
|
|
uint32_t s = 8; // header size
|
2014-03-17 16:56:06 -04:00
|
|
|
s += item->grpId.serial_size();
|
2013-11-16 08:40:04 -05:00
|
|
|
s += 4; // grp TS
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2013-11-10 17:27:50 -05:00
|
|
|
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;
|
|
|
|
|
2013-11-16 08:40:04 -05:00
|
|
|
/* RsGxsMsgUpdateItem */
|
2013-11-10 17:27:50 -05:00
|
|
|
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
ok &= item->peerId.serialise(data, *size, offset) ;
|
2013-11-10 17:27:50 -05:00
|
|
|
|
2015-01-31 13:06:37 -05:00
|
|
|
std::map<RsGxsGroupId, RsGxsMsgUpdateItem::MsgUpdateInfo>::const_iterator cit(item->msgUpdateInfos.begin());
|
2013-11-10 17:27:50 -05:00
|
|
|
|
2015-01-31 13:06:37 -05:00
|
|
|
uint32_t numItems = item->msgUpdateInfos.size();
|
2013-11-10 17:27:50 -05:00
|
|
|
ok &= setRawUInt32(data, *size, &offset, numItems);
|
|
|
|
|
2015-01-31 13:06:37 -05:00
|
|
|
for(; cit != item->msgUpdateInfos.end(); ++cit)
|
2013-11-10 17:27:50 -05:00
|
|
|
{
|
2014-03-17 16:56:06 -04:00
|
|
|
ok &= cit->first.serialise(data, *size, offset);
|
2015-01-31 13:06:37 -05:00
|
|
|
ok &= setRawUInt32(data, *size, &offset, cit->second.time_stamp);
|
|
|
|
ok &= setRawUInt32(data, *size, &offset, cit->second.message_count);
|
2013-11-10 17:27:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-11-16 08:40:04 -05:00
|
|
|
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 */
|
|
|
|
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
ok &= item->grpId.serialise(data, *size, offset) ;
|
2013-11-16 08:40:04 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-11-10 17:27:50 -05:00
|
|
|
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)) ||
|
2013-11-16 08:40:04 -05:00
|
|
|
(RS_PKT_SUBTYPE_GXS_MSG_UPDATE != getRsItemSubType(rstype)))
|
2013-11-10 17:27:50 -05:00
|
|
|
{
|
|
|
|
#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;
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
ok &= item->peerId.deserialise(data, *size, offset) ;
|
2013-11-10 17:27:50 -05:00
|
|
|
uint32_t numUpdateItems;
|
|
|
|
ok &= getRawUInt32(data, *size, &offset, &(numUpdateItems));
|
2015-01-31 13:06:37 -05:00
|
|
|
std::map<RsGxsGroupId, RsGxsMsgUpdateItem::MsgUpdateInfo>& msgUpdateInfos = item->msgUpdateInfos;
|
2014-03-17 16:56:06 -04:00
|
|
|
RsGxsGroupId pId;
|
2015-01-31 13:06:37 -05:00
|
|
|
|
|
|
|
RsGxsMsgUpdateItem::MsgUpdateInfo info ;
|
|
|
|
|
2013-12-15 15:11:39 -05:00
|
|
|
for(uint32_t i = 0; i < numUpdateItems; i++)
|
2013-11-10 17:27:50 -05:00
|
|
|
{
|
2014-03-17 16:56:06 -04:00
|
|
|
ok &= pId.deserialise(data, *size, offset);
|
2013-11-10 17:27:50 -05:00
|
|
|
|
|
|
|
if(!ok)
|
|
|
|
break;
|
|
|
|
|
2015-01-31 13:06:37 -05:00
|
|
|
ok &= getRawUInt32(data, *size, &offset, &(info.time_stamp));
|
|
|
|
ok &= getRawUInt32(data, *size, &offset, &(info.message_count));
|
2013-11-10 17:27:50 -05:00
|
|
|
|
|
|
|
if(!ok)
|
|
|
|
break;
|
|
|
|
|
2015-01-31 13:06:37 -05:00
|
|
|
msgUpdateInfos.insert(std::make_pair(pId, info));
|
2013-11-10 17:27:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2013-11-16 08:40:04 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
ok &= item->grpId.deserialise(data, *size, offset) ;
|
2013-11-16 08:40:04 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|