2007-12-11 19:54:42 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* libretroshare/src/serialiser: rsbaseitems.cc
|
|
|
|
*
|
|
|
|
* RetroShare Serialiser.
|
|
|
|
*
|
|
|
|
* Copyright 2007-2008 by Robert Fernie.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2 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".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-05-05 09:18:53 -04:00
|
|
|
#include <stdexcept>
|
2013-10-21 07:00:49 -04:00
|
|
|
#include <time.h>
|
2007-12-11 19:54:42 -05:00
|
|
|
#include "serialiser/rsbaseserial.h"
|
|
|
|
#include "serialiser/rsmsgitems.h"
|
|
|
|
#include "serialiser/rstlvbase.h"
|
|
|
|
|
2008-03-31 10:06:59 -04:00
|
|
|
/***
|
2007-12-11 19:54:42 -05:00
|
|
|
#define RSSERIAL_DEBUG 1
|
2008-03-31 10:06:59 -04:00
|
|
|
***/
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
void RsMsgItem::clear()
|
|
|
|
{
|
|
|
|
msgId = 0;
|
|
|
|
msgFlags = 0;
|
|
|
|
sendTime = 0;
|
|
|
|
recvTime = 0;
|
2008-01-26 08:00:57 -05:00
|
|
|
subject.clear();
|
|
|
|
message.clear();
|
2007-12-11 19:54:42 -05:00
|
|
|
|
2014-03-29 10:18:05 -04:00
|
|
|
rspeerid_msgto.TlvClear();
|
|
|
|
rspeerid_msgcc.TlvClear();
|
|
|
|
rspeerid_msgbcc.TlvClear();
|
|
|
|
|
|
|
|
rsgxsid_msgto.TlvClear();
|
|
|
|
rsgxsid_msgcc.TlvClear();
|
|
|
|
rsgxsid_msgbcc.TlvClear();
|
2007-12-11 19:54:42 -05:00
|
|
|
|
|
|
|
attachment.TlvClear();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream &RsMsgItem::print(std::ostream &out, uint16_t indent)
|
|
|
|
{
|
|
|
|
printRsItemBase(out, "RsMsgItem", indent);
|
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "msgId (not serialised): " << msgId << std::endl;
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "msgFlags: " << msgFlags << std::endl;
|
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "sendTime: " << sendTime << std::endl;
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "recvTime: " << recvTime << std::endl;
|
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "Message To: " << std::endl;
|
2014-03-29 10:18:05 -04:00
|
|
|
rspeerid_msgto.print(out, int_Indent);
|
|
|
|
rsgxsid_msgto.print(out, int_Indent);
|
2007-12-11 19:54:42 -05:00
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "Message CC: " << std::endl;
|
2014-03-29 10:18:05 -04:00
|
|
|
rspeerid_msgcc.print(out, int_Indent);
|
|
|
|
rsgxsid_msgcc.print(out, int_Indent);
|
2007-12-11 19:54:42 -05:00
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "Message BCC: " << std::endl;
|
2014-03-29 10:18:05 -04:00
|
|
|
rspeerid_msgbcc.print(out, int_Indent);
|
|
|
|
rsgxsid_msgbcc.print(out, int_Indent);
|
2007-12-11 19:54:42 -05:00
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
2008-01-26 08:00:57 -05:00
|
|
|
std::string cnv_subject(subject.begin(), subject.end());
|
|
|
|
out << "subject: " << cnv_subject << std::endl;
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
printIndent(out, int_Indent);
|
2008-01-26 08:00:57 -05:00
|
|
|
std::string cnv_message(message.begin(), message.end());
|
|
|
|
out << "msg: " << cnv_message << std::endl;
|
2007-12-11 19:54:42 -05:00
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "Attachment: " << std::endl;
|
|
|
|
attachment.print(out, int_Indent);
|
|
|
|
|
|
|
|
printRsItemEnd(out, "RsMsgItem", indent);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2010-08-19 17:47:26 -04:00
|
|
|
void RsMsgTagType::clear()
|
|
|
|
{
|
|
|
|
text.clear();
|
|
|
|
tagId = 0;
|
|
|
|
rgb_color = 0;
|
|
|
|
}
|
|
|
|
|
2013-05-05 15:13:27 -04:00
|
|
|
void RsPublicMsgInviteConfigItem::clear()
|
|
|
|
{
|
|
|
|
hash.clear() ;
|
|
|
|
time_stamp = 0 ;
|
|
|
|
}
|
|
|
|
std::ostream& RsPublicMsgInviteConfigItem::print(std::ostream &out, uint16_t indent)
|
|
|
|
{
|
|
|
|
printRsItemBase(out, "RsPublicMsgInviteConfigItem", indent);
|
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "hash : " << hash << std::endl;
|
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "timt : " << time_stamp << std::endl;
|
|
|
|
|
|
|
|
printRsItemEnd(out, "RsPublicMsgInviteConfigItem", indent);
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
2010-08-19 17:47:26 -04:00
|
|
|
void RsMsgTags::clear()
|
|
|
|
{
|
2010-08-22 18:12:26 -04:00
|
|
|
msgId = 0;
|
|
|
|
tagIds.clear();
|
2010-08-19 17:47:26 -04:00
|
|
|
}
|
2007-12-11 19:54:42 -05:00
|
|
|
|
2010-08-19 17:47:26 -04:00
|
|
|
std::ostream& RsMsgTagType::print(std::ostream &out, uint16_t indent)
|
|
|
|
{
|
2010-10-03 07:56:53 -04:00
|
|
|
printRsItemBase(out, "RsMsgTagType", indent);
|
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "rgb_color : " << rgb_color << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "text: " << text << std::endl;
|
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "tagId: " << tagId << std::endl;
|
|
|
|
|
|
|
|
printRsItemEnd(out, "RsMsgTagTypeItem", indent);
|
2010-08-19 17:47:26 -04:00
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream& RsMsgTags::print(std::ostream &out, uint16_t indent)
|
|
|
|
{
|
|
|
|
|
2010-10-03 07:56:53 -04:00
|
|
|
printRsItemBase(out, "RsMsgTagsItem", indent);
|
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "msgId : " << msgId << std::endl;
|
|
|
|
|
|
|
|
std::list<uint32_t>::iterator it;
|
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(it=tagIds.begin(); it != tagIds.end(); ++it)
|
2010-10-03 07:56:53 -04:00
|
|
|
{
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "tagId : " << *it << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
printRsItemEnd(out, "RsMsgTags", indent);
|
|
|
|
|
2010-08-19 17:47:26 -04:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
uint32_t RsMsgItem::serial_size(bool m_bConfiguration)
|
2007-12-11 19:54:42 -05:00
|
|
|
{
|
|
|
|
uint32_t s = 8; /* header */
|
|
|
|
s += 4; /* msgFlags */
|
|
|
|
s += 4; /* sendTime */
|
|
|
|
s += 4; /* recvTime */
|
|
|
|
|
2013-10-03 17:41:34 -04:00
|
|
|
s += GetTlvStringSize(subject);
|
|
|
|
s += GetTlvStringSize(message);
|
2007-12-11 19:54:42 -05:00
|
|
|
|
2014-03-29 10:18:05 -04:00
|
|
|
s += rspeerid_msgto.TlvSize();
|
|
|
|
s += rspeerid_msgcc.TlvSize();
|
|
|
|
s += rspeerid_msgbcc.TlvSize();
|
|
|
|
|
|
|
|
s += rsgxsid_msgto.TlvSize();
|
|
|
|
s += rsgxsid_msgcc.TlvSize();
|
|
|
|
s += rsgxsid_msgbcc.TlvSize();
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
s += attachment.TlvSize();
|
2007-12-11 19:54:42 -05:00
|
|
|
|
2010-06-04 19:39:33 -04:00
|
|
|
if (m_bConfiguration) {
|
|
|
|
// serialise msgId too
|
|
|
|
s += 4;
|
|
|
|
}
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* serialise the data to the buffer */
|
2013-08-04 16:09:26 -04:00
|
|
|
bool RsMsgItem::serialise(void *data, uint32_t& pktsize,bool config)
|
2007-12-11 19:54:42 -05:00
|
|
|
{
|
2013-08-04 16:09:26 -04:00
|
|
|
uint32_t tlvsize = serial_size( config) ;
|
2007-12-11 19:54:42 -05:00
|
|
|
uint32_t offset = 0;
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
if (pktsize < tlvsize)
|
2007-12-11 19:54:42 -05:00
|
|
|
return false; /* not enough space */
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
pktsize = tlvsize;
|
2007-12-11 19:54:42 -05:00
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
|
2007-12-11 19:54:42 -05:00
|
|
|
|
2008-03-31 10:06:59 -04:00
|
|
|
#ifdef RSSERIAL_DEBUG
|
2007-12-11 19:54:42 -05:00
|
|
|
std::cerr << "RsMsgSerialiser::serialiseItem() Header: " << ok << std::endl;
|
|
|
|
std::cerr << "RsMsgSerialiser::serialiseItem() Size: " << tlvsize << std::endl;
|
2008-03-31 10:06:59 -04:00
|
|
|
#endif
|
2007-12-11 19:54:42 -05:00
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
/* add mandatory parts first */
|
2013-08-04 16:09:26 -04:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, msgFlags);
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, sendTime);
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, recvTime);
|
2007-12-11 19:54:42 -05:00
|
|
|
|
2013-10-03 17:41:34 -04:00
|
|
|
ok &= SetTlvString(data,tlvsize,&offset,TLV_TYPE_STR_SUBJECT,subject);
|
|
|
|
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, message);
|
2007-12-11 19:54:42 -05:00
|
|
|
|
2014-03-29 10:18:05 -04:00
|
|
|
ok &= rspeerid_msgto.SetTlv(data, tlvsize, &offset);
|
|
|
|
ok &= rspeerid_msgcc.SetTlv(data, tlvsize, &offset);
|
|
|
|
ok &= rspeerid_msgbcc.SetTlv(data, tlvsize, &offset);
|
|
|
|
|
|
|
|
ok &= rsgxsid_msgto.SetTlv(data, tlvsize, &offset);
|
|
|
|
ok &= rsgxsid_msgcc.SetTlv(data, tlvsize, &offset);
|
|
|
|
ok &= rsgxsid_msgbcc.SetTlv(data, tlvsize, &offset);
|
2007-12-11 19:54:42 -05:00
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
ok &= attachment.SetTlv(data, tlvsize, &offset);
|
2010-06-04 19:39:33 -04:00
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
if (config) // serialise msgId too
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, msgId);
|
2010-06-04 19:39:33 -04:00
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
std::cerr << "RsMsgSerialiser::serialiseItem() Size Error! " << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2010-08-19 17:47:26 -04:00
|
|
|
RsMsgItem *RsMsgSerialiser::deserialiseMsgItem(void *data, uint32_t *pktsize)
|
2007-12-11 19:54:42 -05:00
|
|
|
{
|
|
|
|
/* 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_MSG != getRsItemService(rstype)) ||
|
|
|
|
(RS_PKT_SUBTYPE_DEFAULT != 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 */
|
|
|
|
RsMsgItem *item = new RsMsgItem();
|
|
|
|
item->clear();
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
/* get mandatory parts first */
|
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &(item->msgFlags));
|
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &(item->sendTime));
|
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &(item->recvTime));
|
|
|
|
|
2013-10-03 17:41:34 -04:00
|
|
|
ok &= GetTlvString(data,rssize,&offset,TLV_TYPE_STR_SUBJECT,item->subject);
|
|
|
|
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, item->message);
|
2014-03-29 10:18:05 -04:00
|
|
|
|
|
|
|
ok &= item->rspeerid_msgto.GetTlv(data, rssize, &offset);
|
|
|
|
ok &= item->rspeerid_msgcc.GetTlv(data, rssize, &offset);
|
|
|
|
ok &= item->rspeerid_msgbcc.GetTlv(data, rssize, &offset);
|
|
|
|
ok &= item->rsgxsid_msgto.GetTlv(data, rssize, &offset);
|
|
|
|
ok &= item->rsgxsid_msgcc.GetTlv(data, rssize, &offset);
|
|
|
|
ok &= item->rsgxsid_msgbcc.GetTlv(data, rssize, &offset);
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
ok &= item->attachment.GetTlv(data, rssize, &offset);
|
|
|
|
|
2010-06-04 19:39:33 -04:00
|
|
|
if (m_bConfiguration) {
|
|
|
|
// deserialise msgId too
|
|
|
|
// ok &= getRawUInt32(data, rssize, &offset, &(item->msgId));
|
|
|
|
getRawUInt32(data, rssize, &offset, &(item->msgId)); //use this line for backward compatibility
|
|
|
|
}
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
if (offset != rssize)
|
|
|
|
{
|
|
|
|
/* error */
|
|
|
|
delete item;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
delete item;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
2013-08-04 16:09:26 -04:00
|
|
|
uint32_t RsPublicMsgInviteConfigItem::serial_size(bool)
|
2013-05-05 15:13:27 -04:00
|
|
|
{
|
|
|
|
uint32_t s = 8; /* header */
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
s += GetTlvStringSize(hash);
|
2013-05-05 15:13:27 -04:00
|
|
|
s += 4; /* time_stamp */
|
2007-12-11 19:54:42 -05:00
|
|
|
|
2013-05-05 15:13:27 -04:00
|
|
|
return s;
|
|
|
|
}
|
2010-08-19 17:47:26 -04:00
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
uint32_t RsMsgTagType::serial_size(bool)
|
2010-08-19 17:47:26 -04:00
|
|
|
{
|
|
|
|
uint32_t s = 8; /* header */
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
s += GetTlvStringSize(text);
|
2010-08-19 17:47:26 -04:00
|
|
|
s += 4; /* color */
|
|
|
|
s += 4; /* tag id */
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
bool RsPublicMsgInviteConfigItem::serialise(void *data, uint32_t& pktsize,bool config)
|
2013-05-05 15:13:27 -04:00
|
|
|
{
|
2013-08-04 16:09:26 -04:00
|
|
|
uint32_t tlvsize = serial_size(config) ;
|
2013-05-05 15:13:27 -04:00
|
|
|
uint32_t offset = 0;
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
if (pktsize < tlvsize)
|
2013-05-05 15:13:27 -04:00
|
|
|
return false; /* not enough space */
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
pktsize = tlvsize;
|
2013-05-05 15:13:27 -04:00
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
|
2013-05-05 15:13:27 -04:00
|
|
|
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Header: " << ok << std::endl;
|
|
|
|
std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size: " << tlvsize << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
/* add mandatory parts first */
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
ok &= SetTlvString(data,tlvsize,&offset, TLV_TYPE_STR_HASH_SHA1, hash);
|
|
|
|
ok &= setRawUInt32(data,tlvsize,&offset, time_stamp);
|
2013-05-05 15:13:27 -04:00
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size Error! " << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2010-08-19 17:47:26 -04:00
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
bool RsMsgTagType::serialise(void *data, uint32_t& pktsize,bool config)
|
2010-08-19 17:47:26 -04:00
|
|
|
{
|
2013-08-04 16:09:26 -04:00
|
|
|
uint32_t tlvsize = serial_size( config) ;
|
2010-08-19 17:47:26 -04:00
|
|
|
uint32_t offset = 0;
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
if (pktsize < tlvsize)
|
2010-08-19 17:47:26 -04:00
|
|
|
return false; /* not enough space */
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
pktsize = tlvsize;
|
2010-08-19 17:47:26 -04:00
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
|
2010-08-19 17:47:26 -04:00
|
|
|
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Header: " << ok << std::endl;
|
|
|
|
std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size: " << tlvsize << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
/* add mandatory parts first */
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
ok &= SetTlvString(data,tlvsize,&offset, TLV_TYPE_STR_NAME, text);
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, rgb_color);
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, tagId);
|
2010-08-19 17:47:26 -04:00
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size Error! " << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
2013-05-05 15:13:27 -04:00
|
|
|
RsPublicMsgInviteConfigItem* RsMsgSerialiser::deserialisePublicMsgInviteConfigItem(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_MSG != getRsItemService(rstype)) ||
|
|
|
|
(RS_PKT_SUBTYPE_MSG_INVITE != 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 */
|
|
|
|
RsPublicMsgInviteConfigItem *item = new RsPublicMsgInviteConfigItem();
|
|
|
|
item->clear();
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
/* get mandatory parts first */
|
|
|
|
ok &= GetTlvString(data,rssize,&offset,TLV_TYPE_STR_HASH_SHA1,item->hash);
|
|
|
|
|
|
|
|
uint32_t ts ;
|
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &ts) ;
|
|
|
|
item->time_stamp = ts ;
|
|
|
|
|
|
|
|
if (offset != rssize)
|
|
|
|
{
|
|
|
|
/* error */
|
|
|
|
delete item;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
delete item;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2010-08-19 17:47:26 -04:00
|
|
|
|
|
|
|
RsMsgTagType* RsMsgSerialiser::deserialiseTagItem(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_MSG != getRsItemService(rstype)) ||
|
|
|
|
(RS_PKT_SUBTYPE_MSG_TAG_TYPE != 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 */
|
|
|
|
RsMsgTagType *item = new RsMsgTagType();
|
|
|
|
item->clear();
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
|
|
|
|
/* get mandatory parts first */
|
|
|
|
ok &= GetTlvString(data,rssize,&offset,TLV_TYPE_STR_NAME,item->text);
|
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &(item->rgb_color));
|
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &(item->tagId));
|
|
|
|
|
|
|
|
if (offset != rssize)
|
|
|
|
{
|
|
|
|
/* error */
|
|
|
|
delete item;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
delete item;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
uint32_t RsMsgTags::serial_size(bool)
|
2010-08-19 17:47:26 -04:00
|
|
|
{
|
|
|
|
uint32_t s = 8; /* header */
|
|
|
|
|
2010-08-22 18:12:26 -04:00
|
|
|
s += 4; /* msgId */
|
2013-08-04 16:09:26 -04:00
|
|
|
s += tagIds.size() * 4; /* tagIds */
|
2010-08-19 17:47:26 -04:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
bool RsMsgTags::serialise(void *data, uint32_t& pktsize,bool config)
|
2010-08-19 17:47:26 -04:00
|
|
|
{
|
2013-08-04 16:09:26 -04:00
|
|
|
uint32_t tlvsize = serial_size( config) ;
|
2010-08-19 17:47:26 -04:00
|
|
|
uint32_t offset = 0;
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
if (pktsize < tlvsize)
|
2010-08-19 17:47:26 -04:00
|
|
|
return false; /* not enough space */
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
pktsize = tlvsize;
|
2010-08-19 17:47:26 -04:00
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
|
2010-08-19 17:47:26 -04:00
|
|
|
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Header: " << ok << std::endl;
|
|
|
|
std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size: " << tlvsize << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
ok &= setRawUInt32(data,tlvsize,&offset, msgId);
|
2010-08-22 18:12:26 -04:00
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
std::list<uint32_t>::iterator mit = tagIds.begin();
|
2014-10-24 18:07:26 -04:00
|
|
|
for(;mit != tagIds.end(); ++mit)
|
2010-08-22 18:12:26 -04:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, *mit);
|
2010-08-19 17:47:26 -04:00
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size Error! " << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
RsMsgTags* RsMsgSerialiser::deserialiseMsgTagItem(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_MSG != getRsItemService(rstype)) ||
|
|
|
|
(RS_PKT_SUBTYPE_MSG_TAGS != 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 */
|
|
|
|
RsMsgTags *item = new RsMsgTags();
|
|
|
|
item->clear();
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
|
|
|
|
/* get mandatory parts first */
|
2010-08-22 18:12:26 -04:00
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &item->msgId);
|
|
|
|
|
|
|
|
uint32_t tagId;
|
|
|
|
while (offset != rssize)
|
|
|
|
{
|
|
|
|
tagId = 0;
|
|
|
|
|
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &tagId);
|
|
|
|
|
|
|
|
item->tagIds.push_back(tagId);
|
|
|
|
}
|
2010-08-19 17:47:26 -04:00
|
|
|
|
|
|
|
if (offset != rssize)
|
|
|
|
{
|
|
|
|
/* error */
|
|
|
|
delete item;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
delete item;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2010-10-03 07:56:53 -04:00
|
|
|
|
|
|
|
/************************************** Message SrcId **********************/
|
|
|
|
|
|
|
|
std::ostream& RsMsgSrcId::print(std::ostream& out, uint16_t indent)
|
|
|
|
{
|
|
|
|
printRsItemBase(out, "RsMsgSrcIdItem", indent);
|
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "msgId : " << msgId << std::endl;
|
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "SrcId: " << srcId << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
printRsItemEnd(out, "RsMsgItem", indent);
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RsMsgSrcId::clear()
|
|
|
|
{
|
|
|
|
msgId = 0;
|
|
|
|
srcId.clear();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
uint32_t RsMsgSrcId::serial_size(bool)
|
2010-10-03 07:56:53 -04:00
|
|
|
{
|
|
|
|
uint32_t s = 8; /* header */
|
|
|
|
|
|
|
|
s += 4;
|
2014-03-17 16:56:06 -04:00
|
|
|
s += srcId.serial_size() ;
|
2010-10-03 07:56:53 -04:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
bool RsMsgSrcId::serialise(void *data, uint32_t& pktsize,bool config)
|
2010-10-03 07:56:53 -04:00
|
|
|
{
|
2013-08-04 16:09:26 -04:00
|
|
|
uint32_t tlvsize = serial_size(config) ;
|
2010-10-03 07:56:53 -04:00
|
|
|
uint32_t offset = 0;
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
if (pktsize < tlvsize)
|
2010-10-03 07:56:53 -04:00
|
|
|
return false; /* not enough space */
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
pktsize = tlvsize;
|
2010-10-03 07:56:53 -04:00
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
|
2010-10-03 07:56:53 -04:00
|
|
|
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsMsgSerialiser::serialiseMsgSrcIdItem() Header: " << ok << std::endl;
|
|
|
|
std::cerr << "RsMsgSerialiser::serialiseMsgSrcIdItem() Size: " << tlvsize << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, msgId);
|
2014-03-17 16:56:06 -04:00
|
|
|
ok &= srcId.serialise(data, tlvsize, offset) ;
|
2010-10-03 07:56:53 -04:00
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
std::cerr << "RsMsgSerialiser::serialiseMsgSrcIdItem() Size Error! " << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
RsMsgSrcId* RsMsgSerialiser::deserialiseMsgSrcIdItem(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_MSG != getRsItemService(rstype)) ||
|
|
|
|
(RS_PKT_SUBTYPE_MSG_SRC_TAG != 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 */
|
|
|
|
RsMsgSrcId *item = new RsMsgSrcId();
|
|
|
|
item->clear();
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
|
|
|
|
/* get mandatory parts first */
|
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &(item->msgId));
|
2014-03-17 16:56:06 -04:00
|
|
|
ok &= item->srcId.deserialise(data, rssize, offset);
|
2010-10-03 07:56:53 -04:00
|
|
|
|
|
|
|
if (offset != rssize)
|
|
|
|
{
|
|
|
|
/* error */
|
|
|
|
delete item;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
delete item;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************* end of definition of msgSrcId serialisation functions ************************/
|
2010-11-02 17:11:11 -04:00
|
|
|
|
2015-04-28 17:46:10 -04:00
|
|
|
std::ostream& RsMsgGRouterMap::print(std::ostream& out, uint16_t indent)
|
|
|
|
{
|
|
|
|
printRsItemBase(out, "RsMsgGRouterMap", indent);
|
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
|
|
|
|
for(std::map<GRouterMsgPropagationId,uint32_t>::const_iterator it(ongoing_msgs.begin());it!=ongoing_msgs.end();++it)
|
|
|
|
{
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << " " << std::hex << it->first << std::dec << " : " << it->second << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
printRsItemEnd(out, "RsMsgGRouterMap", indent);
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RsMsgGRouterMap::clear()
|
|
|
|
{
|
|
|
|
ongoing_msgs.clear() ;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t RsMsgGRouterMap::serial_size(bool)
|
|
|
|
{
|
|
|
|
uint32_t s = 8; /* header */
|
|
|
|
|
|
|
|
s += 4; // number of entries
|
|
|
|
s += (8+4)*ongoing_msgs.size(); // entries
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RsMsgGRouterMap::serialise(void *data, uint32_t& pktsize,bool config)
|
|
|
|
{
|
|
|
|
uint32_t tlvsize = serial_size( config) ;
|
|
|
|
uint32_t offset = 0;
|
|
|
|
|
|
|
|
if (pktsize < tlvsize)
|
|
|
|
return false; /* not enough space */
|
|
|
|
|
|
|
|
pktsize = tlvsize;
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
|
|
|
|
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsMsgSerialiser::serialiseMsgParentIdItem() Header: " << ok << std::endl;
|
|
|
|
std::cerr << "RsMsgSerialiser::serialiseMsgParentIdItem() Size: " << tlvsize << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, ongoing_msgs.size());
|
|
|
|
|
|
|
|
for(std::map<GRouterMsgPropagationId,uint32_t>::const_iterator it=ongoing_msgs.begin();ok && it!=ongoing_msgs.end();++it)
|
|
|
|
{
|
|
|
|
ok &= setRawUInt64(data, tlvsize, &offset, it->first);
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, it->second);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
std::cerr << "RsMsgSerialiser::serialiseMsgGRouterMap() Size Error! " << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
RsMsgGRouterMap* RsMsgSerialiser::deserialiseMsgGRouterMap(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_MSG != getRsItemService(rstype)) ||
|
|
|
|
(RS_PKT_SUBTYPE_MSG_GROUTER_MAP != 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 */
|
|
|
|
RsMsgGRouterMap *item = new RsMsgGRouterMap();
|
|
|
|
item->clear();
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
uint32_t s=0 ;
|
|
|
|
|
|
|
|
/* get mandatory parts first */
|
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &s);
|
|
|
|
|
|
|
|
for(uint32_t i=0;i<s && ok;++i)
|
|
|
|
{
|
|
|
|
uint32_t mid;
|
|
|
|
uint64_t routing_id;
|
|
|
|
|
|
|
|
ok &= getRawUInt64(data, rssize, &offset, &routing_id);
|
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &mid);
|
|
|
|
|
|
|
|
item->ongoing_msgs.insert(std::make_pair(routing_id,mid)) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset != rssize)
|
|
|
|
{
|
|
|
|
/* error */
|
|
|
|
delete item;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
delete item;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************* end of definition of msgGRouterMap serialisation functions ************************/
|
|
|
|
|
2016-01-07 22:22:05 -05:00
|
|
|
/************************* definition of msgDistantMessageMap serialisation functions ************************/
|
2015-04-28 17:46:10 -04:00
|
|
|
|
2016-01-07 22:22:05 -05:00
|
|
|
std::ostream& RsMsgDistantMessagesHashMap::print(std::ostream& out, uint16_t indent)
|
|
|
|
{
|
|
|
|
printRsItemBase(out, "RsMsgDistantMessagesHashMap", indent);
|
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
|
|
|
|
for(std::map<Sha1CheckSum,uint32_t>::const_iterator it(hash_map.begin());it!=hash_map.end();++it)
|
|
|
|
{
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << " " << std::hex << it->first << std::dec << " : " << it->second << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
printRsItemEnd(out, "RsMsgDistantMessagesHashMap", indent);
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RsMsgDistantMessagesHashMap::clear()
|
|
|
|
{
|
|
|
|
hash_map.clear() ;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t RsMsgDistantMessagesHashMap::serial_size(bool)
|
|
|
|
{
|
|
|
|
uint32_t s = 8; /* header */
|
|
|
|
|
|
|
|
s += 4; // number of entries
|
|
|
|
s += (Sha1CheckSum::SIZE_IN_BYTES+4)*hash_map.size(); // entries
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RsMsgDistantMessagesHashMap::serialise(void *data, uint32_t& pktsize,bool config)
|
|
|
|
{
|
|
|
|
uint32_t tlvsize = serial_size(config) ;
|
|
|
|
uint32_t offset = 0;
|
|
|
|
|
|
|
|
if (pktsize < tlvsize)
|
|
|
|
return false; /* not enough space */
|
|
|
|
|
|
|
|
pktsize = tlvsize;
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
|
|
|
|
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsMsgSerialiser::serialiseMsgDistantMessagesHashMap() Header: " << ok << std::endl;
|
|
|
|
std::cerr << "RsMsgSerialiser::serialiseMsgDistantMessagesHashMap() Size: " << tlvsize << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, hash_map.size());
|
|
|
|
|
|
|
|
for(std::map<Sha1CheckSum,uint32_t>::const_iterator it=hash_map.begin();ok && it!=hash_map.end();++it)
|
|
|
|
{
|
|
|
|
ok &= it->first.serialise(data, tlvsize, offset) ;
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, it->second);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
std::cerr << "RsMsgSerialiser::serialiseMsgDistantMessagesHashMap() Size Error! " << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
RsMsgDistantMessagesHashMap* RsMsgSerialiser::deserialiseMsgDistantMessageHashMap(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_MSG != getRsItemService(rstype)) ||
|
|
|
|
(RS_PKT_SUBTYPE_MSG_DISTANT_MSG_MAP != 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 */
|
|
|
|
RsMsgDistantMessagesHashMap *item = new RsMsgDistantMessagesHashMap();
|
|
|
|
item->clear();
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
uint32_t s=0 ;
|
|
|
|
|
|
|
|
/* get mandatory parts first */
|
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &s);
|
|
|
|
|
|
|
|
for(uint32_t i=0;i<s && ok;++i)
|
|
|
|
{
|
|
|
|
Sha1CheckSum s ;
|
|
|
|
uint32_t tm ;
|
|
|
|
|
|
|
|
ok &= s.deserialise(data, rssize, offset) ;
|
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &tm);
|
|
|
|
|
|
|
|
item->hash_map.insert(std::make_pair(s,tm)) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset != rssize)
|
|
|
|
{
|
|
|
|
/* error */
|
2016-01-09 10:58:49 -05:00
|
|
|
std::cerr << "(EE) size error in packet deserialisation: p3MsgItem, subtype " << getRsItemSubType(rstype) << ". offset=" << offset << " != rssize=" << rssize << std::endl;
|
2016-01-07 22:22:05 -05:00
|
|
|
delete item;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
{
|
2016-01-09 10:58:49 -05:00
|
|
|
std::cerr << "(EE) size error in packet deserialisation: p3MsgItem, subtype " << getRsItemSubType(rstype) << std::endl;
|
2016-01-07 22:22:05 -05:00
|
|
|
delete item;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
2010-11-02 17:11:11 -04:00
|
|
|
/************************************** Message ParentId **********************/
|
|
|
|
|
|
|
|
std::ostream& RsMsgParentId::print(std::ostream& out, uint16_t indent)
|
|
|
|
{
|
|
|
|
printRsItemBase(out, "RsMsgParentIdItem", indent);
|
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "msgId : " << msgId << std::endl;
|
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "msgParentId: " << msgParentId << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
printRsItemEnd(out, "RsMsgParentId", indent);
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RsMsgParentId::clear()
|
|
|
|
{
|
|
|
|
msgId = 0;
|
|
|
|
msgParentId = 0;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
uint32_t RsMsgParentId::serial_size(bool)
|
2010-11-02 17:11:11 -04:00
|
|
|
{
|
|
|
|
uint32_t s = 8; /* header */
|
|
|
|
|
|
|
|
s += 4; // srcId
|
|
|
|
s += 4; // msgParentId
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
bool RsMsgParentId::serialise(void *data, uint32_t& pktsize,bool config)
|
2010-11-02 17:11:11 -04:00
|
|
|
{
|
2013-08-04 16:09:26 -04:00
|
|
|
uint32_t tlvsize = serial_size( config) ;
|
2010-11-02 17:11:11 -04:00
|
|
|
uint32_t offset = 0;
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
if (pktsize < tlvsize)
|
2010-11-02 17:11:11 -04:00
|
|
|
return false; /* not enough space */
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
pktsize = tlvsize;
|
2010-11-02 17:11:11 -04:00
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
|
2010-11-02 17:11:11 -04:00
|
|
|
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsMsgSerialiser::serialiseMsgParentIdItem() Header: " << ok << std::endl;
|
|
|
|
std::cerr << "RsMsgSerialiser::serialiseMsgParentIdItem() Size: " << tlvsize << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
2013-08-04 16:09:26 -04:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, msgId);
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, msgParentId);
|
2010-11-02 17:11:11 -04:00
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
std::cerr << "RsMsgSerialiser::serialiseMsgParentIdItem() Size Error! " << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
RsMsgParentId* RsMsgSerialiser::deserialiseMsgParentIdItem(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_MSG != getRsItemService(rstype)) ||
|
|
|
|
(RS_PKT_SUBTYPE_MSG_PARENT_TAG != 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 */
|
|
|
|
RsMsgParentId *item = new RsMsgParentId();
|
|
|
|
item->clear();
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
|
|
|
|
/* get mandatory parts first */
|
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &(item->msgId));
|
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &(item->msgParentId));
|
|
|
|
|
|
|
|
if (offset != rssize)
|
|
|
|
{
|
|
|
|
/* error */
|
|
|
|
delete item;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
delete item;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************* end of definition of msgParentId serialisation functions ************************/
|
|
|
|
|
2010-08-19 17:47:26 -04:00
|
|
|
RsItem* RsMsgSerialiser::deserialise(void *data, uint32_t *pktsize)
|
2007-12-11 19:54:42 -05:00
|
|
|
{
|
2010-08-19 17:47:26 -04:00
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsMsgSerialiser::deserialise()" << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get the type and size */
|
|
|
|
uint32_t rstype = getRsItemId(data);
|
|
|
|
|
|
|
|
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
|
|
|
(RS_SERVICE_TYPE_MSG != getRsItemService(rstype)))
|
|
|
|
{
|
|
|
|
return NULL; /* wrong type */
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(getRsItemSubType(rstype))
|
|
|
|
{
|
2016-01-09 10:58:49 -05:00
|
|
|
case RS_PKT_SUBTYPE_DEFAULT: return deserialiseMsgItem(data, pktsize);
|
|
|
|
case RS_PKT_SUBTYPE_MSG_SRC_TAG: return deserialiseMsgSrcIdItem(data, pktsize);
|
|
|
|
case RS_PKT_SUBTYPE_MSG_PARENT_TAG: return deserialiseMsgParentIdItem(data, pktsize);
|
|
|
|
case RS_PKT_SUBTYPE_MSG_TAG_TYPE: return deserialiseTagItem(data, pktsize);
|
|
|
|
case RS_PKT_SUBTYPE_MSG_INVITE: return deserialisePublicMsgInviteConfigItem(data, pktsize);
|
|
|
|
case RS_PKT_SUBTYPE_MSG_TAGS: return deserialiseMsgTagItem(data, pktsize);
|
|
|
|
case RS_PKT_SUBTYPE_MSG_GROUTER_MAP: return deserialiseMsgGRouterMap(data, pktsize);
|
|
|
|
case RS_PKT_SUBTYPE_MSG_DISTANT_MSG_MAP: return deserialiseMsgDistantMessageHashMap(data, pktsize);
|
2015-04-28 17:46:10 -04:00
|
|
|
default:
|
2010-08-19 17:47:26 -04:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2007-12-11 19:54:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|