2015-11-17 18:11:00 -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".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <time.h>
|
|
|
|
#include "serialiser/rsbaseserial.h"
|
|
|
|
#include "serialiser/rstlvbase.h"
|
2015-11-27 23:37:39 -05:00
|
|
|
#include "util/rsprint.h"
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
#include "gxstunnel/rsgxstunnelitems.h"
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-28 18:02:57 -05:00
|
|
|
#define GXS_TUNNEL_ITEM_DEBUG 1
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
std::ostream& RsGxsTunnelDHPublicKeyItem::print(std::ostream &out, uint16_t indent)
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
2015-11-27 23:37:39 -05:00
|
|
|
printRsItemBase(out, "RsGxsTunnelDHPublicKeyItem", indent);
|
2015-11-17 18:11:00 -05:00
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << " Signature Key ID: " << signature.keyId << std::endl ;
|
|
|
|
out << " Public Key ID: " << gxs_key.keyId << std::endl ;
|
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
printRsItemEnd(out, "RsGxsTunnelMsgItem", indent);
|
2015-11-17 18:11:00 -05:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
std::ostream& RsGxsTunnelDataItem::print(std::ostream &out, uint16_t indent)
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
2015-11-27 23:37:39 -05:00
|
|
|
printRsItemBase(out, "RsGxsTunnelDataItem", indent);
|
2015-11-17 18:11:00 -05:00
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
2015-11-27 23:37:39 -05:00
|
|
|
out << " message id : " << std::hex << unique_item_counter << std::dec << std::endl ;
|
|
|
|
out << " service id : " << std::hex << service_id << std::dec << std::endl ;
|
|
|
|
out << " flags : " << std::hex << flags << std::dec << std::endl ;
|
|
|
|
out << " size : " << data_size << std::endl ;
|
|
|
|
out << " data : " << RsUtil::BinToHex(data,std::min(50u,data_size)) << ((data_size>50u)?"...":"") << std::endl ;
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
printRsItemEnd(out, "RsGxsTunnelDataItem", indent);
|
2015-11-17 18:11:00 -05:00
|
|
|
return out;
|
|
|
|
}
|
2015-11-27 23:37:39 -05:00
|
|
|
std::ostream& RsGxsTunnelDataAckItem::print(std::ostream &out, uint16_t indent)
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
2015-11-27 23:37:39 -05:00
|
|
|
printRsItemBase(out, "RsGxsTunnelDataItem", indent);
|
2015-11-17 18:11:00 -05:00
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
2015-11-27 23:37:39 -05:00
|
|
|
out << " message id : " << std::hex << unique_item_counter << std::dec << std::endl ;
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
printRsItemEnd(out, "RsGxsTunnelDataAckItem", indent);
|
2015-11-17 18:11:00 -05:00
|
|
|
return out;
|
|
|
|
}
|
2015-11-27 23:37:39 -05:00
|
|
|
std::ostream& RsGxsTunnelStatusItem::print(std::ostream &out, uint16_t indent)
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
2015-11-27 23:37:39 -05:00
|
|
|
printRsItemBase(out, "RsGxsTunnelDataItem", indent);
|
2015-11-17 18:11:00 -05:00
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
2015-11-27 23:37:39 -05:00
|
|
|
out << " flags : " << std::hex << flags << std::dec << std::endl ;
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
printRsItemEnd(out, "RsGxsTunnelStatusItem", indent);
|
2015-11-17 18:11:00 -05:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
/*************************************************************************/
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-26 20:40:06 -05:00
|
|
|
RsGxsTunnelDHPublicKeyItem::~RsGxsTunnelDHPublicKeyItem()
|
|
|
|
{
|
|
|
|
BN_free(public_key) ;
|
|
|
|
}
|
2015-11-27 23:37:39 -05:00
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
RsItem *RsGxsTunnelSerialiser::deserialise(void *data, uint32_t *pktsize)
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
2015-11-27 23:37:39 -05:00
|
|
|
uint32_t rstype = getRsItemId(data);
|
|
|
|
uint32_t rssize = getRsItemSize(data);
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
#ifdef GXS_TUNNEL_ITEM_DEBUG
|
|
|
|
std::cerr << "deserializing packet..."<< std::endl ;
|
2015-11-17 18:11:00 -05:00
|
|
|
#endif
|
2015-11-27 23:37:39 -05:00
|
|
|
// look what we have...
|
|
|
|
if (*pktsize < rssize) /* check size */
|
|
|
|
{
|
|
|
|
std::cerr << "GxsTunnel deserialisation: not enough size: pktsize=" << *pktsize << ", rssize=" << rssize << std::endl ;
|
|
|
|
return NULL; /* not enough data */
|
|
|
|
}
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
/* set the packet length */
|
|
|
|
*pktsize = rssize;
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
/* ready to load */
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_GXS_TUNNEL != getRsItemService(rstype)))
|
|
|
|
{
|
|
|
|
#ifdef GXS_TUNNEL_ITEM_DEBUG
|
|
|
|
std::cerr << "GxsTunnel deserialisation: wrong type !" << std::endl ;
|
2015-11-17 18:11:00 -05:00
|
|
|
#endif
|
2015-11-27 23:37:39 -05:00
|
|
|
return NULL; /* wrong type */
|
|
|
|
}
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
switch(getRsItemSubType(rstype))
|
|
|
|
{
|
|
|
|
case RS_PKT_SUBTYPE_GXS_TUNNEL_DH_PUBLIC_KEY: return deserialise_RsGxsTunnelDHPublicKeyItem(data,*pktsize) ;
|
|
|
|
case RS_PKT_SUBTYPE_GXS_TUNNEL_DATA: return deserialise_RsGxsTunnelDataItem (data,*pktsize) ;
|
|
|
|
case RS_PKT_SUBTYPE_GXS_TUNNEL_DATA_ACK: return deserialise_RsGxsTunnelDataAckItem (data,*pktsize) ;
|
|
|
|
case RS_PKT_SUBTYPE_GXS_TUNNEL_STATUS: return deserialise_RsGxsTunnelStatusItem (data,*pktsize) ;
|
|
|
|
default:
|
|
|
|
std::cerr << "Unknown packet type in chat!" << std::endl ;
|
|
|
|
return NULL ;
|
|
|
|
}
|
2015-11-17 18:11:00 -05:00
|
|
|
}
|
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
/*************************************************************************/
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
uint32_t RsGxsTunnelDHPublicKeyItem::serial_size()
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
2015-11-27 23:37:39 -05:00
|
|
|
uint32_t s = 8 ; // header
|
|
|
|
s += 4 ; // BN size
|
|
|
|
s += BN_num_bytes(public_key) ; // public_key
|
|
|
|
s += signature.TlvSize() ; // signature
|
|
|
|
s += gxs_key.TlvSize() ; // gxs_key
|
2015-11-17 18:11:00 -05:00
|
|
|
|
|
|
|
return s ;
|
|
|
|
}
|
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
uint32_t RsGxsTunnelDataItem::serial_size()
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
2015-11-27 23:37:39 -05:00
|
|
|
uint32_t s = 8 ; // header
|
|
|
|
s += 8 ; // counter
|
|
|
|
s += 4 ; // flags
|
|
|
|
s += 4 ; // service id
|
|
|
|
s += 4 ; // data_size
|
|
|
|
s += data_size; // data
|
2015-11-17 18:11:00 -05:00
|
|
|
|
|
|
|
return s ;
|
|
|
|
}
|
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
uint32_t RsGxsTunnelDataAckItem::serial_size()
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
2015-11-27 23:37:39 -05:00
|
|
|
uint32_t s = 8 ; // header
|
|
|
|
s += 8 ; // counter
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
return s ;
|
2015-11-17 18:11:00 -05:00
|
|
|
}
|
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
uint32_t RsGxsTunnelStatusItem::serial_size()
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
2015-11-27 23:37:39 -05:00
|
|
|
uint32_t s = 8 ; // header
|
|
|
|
s += 4 ; // flags
|
2015-11-17 18:11:00 -05:00
|
|
|
|
|
|
|
return s ;
|
|
|
|
}
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
bool RsGxsTunnelDHPublicKeyItem::serialise(void *data,uint32_t& pktsize)
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
|
|
|
uint32_t tlvsize = serial_size() ;
|
|
|
|
uint32_t offset = 0;
|
|
|
|
|
|
|
|
if (pktsize < tlvsize)
|
|
|
|
return false; /* not enough space */
|
|
|
|
|
|
|
|
pktsize = tlvsize;
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
uint32_t s = BN_num_bytes(public_key) ;
|
|
|
|
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, s);
|
|
|
|
|
|
|
|
BN_bn2bin(public_key,&((unsigned char *)data)[offset]) ;
|
|
|
|
offset += s ;
|
|
|
|
|
|
|
|
ok &= signature.SetTlv(data, tlvsize, &offset);
|
|
|
|
ok &= gxs_key.SetTlv(data, tlvsize, &offset);
|
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
2015-11-27 23:37:39 -05:00
|
|
|
std::cerr << "RsGxsTunnelDHPublicKeyItem::serialiseItem() Size Error! offset=" << offset << ", tlvsize=" << tlvsize << std::endl;
|
2015-11-17 18:11:00 -05:00
|
|
|
}
|
|
|
|
return ok ;
|
|
|
|
}
|
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
bool RsGxsTunnelStatusItem::serialise(void *data, uint32_t& pktsize)
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
2015-11-27 23:37:39 -05:00
|
|
|
uint32_t tlvsize = serial_size() ;
|
2015-11-17 18:11:00 -05:00
|
|
|
uint32_t offset = 0;
|
|
|
|
|
|
|
|
if (pktsize < tlvsize)
|
|
|
|
return false; /* not enough space */
|
|
|
|
|
|
|
|
pktsize = tlvsize;
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
|
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
#ifdef GXS_TUNNEL_ITEM_DEBUG
|
|
|
|
std::cerr << "RsGxsTunnelSerialiser serialising chat status item." << std::endl;
|
|
|
|
std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Header: " << ok << std::endl;
|
|
|
|
std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size: " << tlvsize << std::endl;
|
2015-11-17 18:11:00 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
/* add mandatory parts first */
|
2015-11-27 23:37:39 -05:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, flags);
|
2015-11-17 18:11:00 -05:00
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
2015-11-27 23:37:39 -05:00
|
|
|
std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size Error! " << std::endl;
|
2015-11-17 18:11:00 -05:00
|
|
|
}
|
2015-11-27 23:37:39 -05:00
|
|
|
#ifdef GXS_TUNNEL_ITEM_DEBUG
|
2015-11-17 18:11:00 -05:00
|
|
|
std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
bool RsGxsTunnelDataItem::serialise(void *data, uint32_t& pktsize)
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
|
|
|
uint32_t tlvsize = serial_size() ;
|
|
|
|
uint32_t offset = 0;
|
|
|
|
|
|
|
|
if (pktsize < tlvsize)
|
|
|
|
return false; /* not enough space */
|
|
|
|
|
|
|
|
pktsize = tlvsize;
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
|
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
#ifdef GXS_TUNNEL_ITEM_DEBUG
|
|
|
|
std::cerr << "RsGxsTunnelSerialiser serialising chat status item." << std::endl;
|
|
|
|
std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Header: " << ok << std::endl;
|
|
|
|
std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size: " << tlvsize << std::endl;
|
2015-11-17 18:11:00 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
/* add mandatory parts first */
|
2015-11-27 23:37:39 -05:00
|
|
|
ok &= setRawUInt64(data, tlvsize, &offset, unique_item_counter);
|
2015-11-17 18:11:00 -05:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, flags);
|
2015-11-27 23:37:39 -05:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, service_id);
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, data_size);
|
|
|
|
|
|
|
|
if(offset + data_size <= tlvsize)
|
|
|
|
{
|
|
|
|
memcpy(&((uint8_t*)data)[offset],data,data_size) ;
|
|
|
|
offset += data_size ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ok = false ;
|
2015-11-17 18:11:00 -05:00
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
2015-11-27 23:37:39 -05:00
|
|
|
std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size Error! " << std::endl;
|
2015-11-17 18:11:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
2015-11-27 23:37:39 -05:00
|
|
|
bool RsGxsTunnelDataAckItem::serialise(void *data, uint32_t& pktsize)
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
|
|
|
uint32_t tlvsize = serial_size() ;
|
|
|
|
uint32_t offset = 0;
|
|
|
|
|
|
|
|
if (pktsize < tlvsize)
|
|
|
|
return false; /* not enough space */
|
|
|
|
|
|
|
|
pktsize = tlvsize;
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
|
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
#ifdef GXS_TUNNEL_ITEM_DEBUG
|
|
|
|
std::cerr << "RsGxsTunnelSerialiser serialising chat status item." << std::endl;
|
|
|
|
std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Header: " << ok << std::endl;
|
|
|
|
std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size: " << tlvsize << std::endl;
|
2015-11-17 18:11:00 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
/* add mandatory parts first */
|
2015-11-27 23:37:39 -05:00
|
|
|
ok &= setRawUInt64(data, tlvsize, &offset, unique_item_counter);
|
|
|
|
|
2015-11-17 18:11:00 -05:00
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
2015-11-27 23:37:39 -05:00
|
|
|
std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size Error! " << std::endl;
|
2015-11-17 18:11:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
/*************************************************************************/
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-28 14:55:56 -05:00
|
|
|
RsGxsTunnelDHPublicKeyItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelDHPublicKeyItem(void *data,uint32_t /*size*/)
|
2015-11-27 23:37:39 -05:00
|
|
|
{
|
|
|
|
uint32_t offset = 8; // skip the header
|
|
|
|
uint32_t rssize = getRsItemSize(data);
|
|
|
|
bool ok = true ;
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
RsGxsTunnelDHPublicKeyItem *item = new RsGxsTunnelDHPublicKeyItem() ;
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
uint32_t s=0 ;
|
|
|
|
/* get mandatory parts first */
|
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &s);
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
item->public_key = BN_bin2bn(&((unsigned char *)data)[offset],s,NULL) ;
|
|
|
|
offset += s ;
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
ok &= item->signature.GetTlv(data, rssize, &offset) ;
|
|
|
|
ok &= item->gxs_key.GetTlv(data, rssize, &offset) ;
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
if (offset != rssize)
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
2015-11-27 23:37:39 -05:00
|
|
|
std::cerr << "RsGxsTunnelDHPublicKeyItem::() Size error while deserializing." << std::endl ;
|
|
|
|
delete item ;
|
|
|
|
return NULL ;
|
|
|
|
}
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
std::cerr << "RsGxsTunnelDHPublicKeyItem::() Unknown error while deserializing." << std::endl ;
|
|
|
|
delete item ;
|
|
|
|
return NULL ;
|
2015-11-17 18:11:00 -05:00
|
|
|
}
|
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
return item ;
|
2015-11-17 18:11:00 -05:00
|
|
|
}
|
|
|
|
|
2015-11-28 14:55:56 -05:00
|
|
|
RsGxsTunnelDataItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelDataItem(void *dat,uint32_t size)
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
2015-11-27 23:37:39 -05:00
|
|
|
uint32_t offset = 8; // skip the header
|
|
|
|
uint32_t rssize = getRsItemSize(dat);
|
|
|
|
bool ok = true ;
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
RsGxsTunnelDataItem *item = new RsGxsTunnelDataItem();
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
/* get mandatory parts first */
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
ok &= getRawUInt64(dat, rssize, &offset, &item->unique_item_counter);
|
|
|
|
ok &= getRawUInt32(dat, rssize, &offset, &item->flags);
|
|
|
|
ok &= getRawUInt32(dat, rssize, &offset, &item->service_id);
|
|
|
|
ok &= getRawUInt32(dat, rssize, &offset, &item->data_size);
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
if(offset + item->data_size <= size)
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
2015-11-27 23:37:39 -05:00
|
|
|
item->data = (unsigned char*)malloc(item->data_size) ;
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
if(dat == NULL)
|
|
|
|
{
|
|
|
|
delete item ;
|
|
|
|
return NULL ;
|
|
|
|
}
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
memcpy(item->data,&((uint8_t*)dat)[offset],item->data_size) ;
|
|
|
|
offset += item->data_size ;
|
2015-11-17 18:11:00 -05:00
|
|
|
}
|
2015-11-27 23:37:39 -05:00
|
|
|
else
|
|
|
|
ok = false ;
|
2015-11-17 18:11:00 -05:00
|
|
|
|
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
if (offset != rssize)
|
|
|
|
{
|
|
|
|
std::cerr << "RsGxsTunnelDHPublicKeyItem::() Size error while deserializing." << std::endl ;
|
|
|
|
delete item ;
|
|
|
|
return NULL ;
|
|
|
|
}
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
std::cerr << "RsGxsTunnelDHPublicKeyItem::() Unknown error while deserializing." << std::endl ;
|
|
|
|
delete item ;
|
|
|
|
return NULL ;
|
|
|
|
}
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
return item ;
|
2015-11-17 18:11:00 -05:00
|
|
|
}
|
|
|
|
|
2015-11-28 14:55:56 -05:00
|
|
|
RsGxsTunnelDataAckItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelDataAckItem(void *dat,uint32_t /* size */)
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
2015-11-27 23:37:39 -05:00
|
|
|
uint32_t offset = 8; // skip the header
|
|
|
|
uint32_t rssize = getRsItemSize(dat);
|
|
|
|
bool ok = true ;
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
RsGxsTunnelDataAckItem *item = new RsGxsTunnelDataAckItem();
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
/* get mandatory parts first */
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
ok &= getRawUInt64(dat, rssize, &offset, &item->unique_item_counter);
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
if (offset != rssize)
|
|
|
|
{
|
|
|
|
std::cerr << "RsGxsTunnelDHPublicKeyItem::() Size error while deserializing." << std::endl ;
|
|
|
|
delete item ;
|
|
|
|
return NULL ;
|
|
|
|
}
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
std::cerr << "RsGxsTunnelDHPublicKeyItem::() Unknown error while deserializing." << std::endl ;
|
|
|
|
delete item ;
|
|
|
|
return NULL ;
|
|
|
|
}
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
return item ;
|
2015-11-17 18:11:00 -05:00
|
|
|
}
|
|
|
|
|
2015-11-28 14:55:56 -05:00
|
|
|
RsGxsTunnelStatusItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelStatusItem(void *dat,uint32_t size)
|
2015-11-17 18:11:00 -05:00
|
|
|
{
|
2015-11-27 23:37:39 -05:00
|
|
|
uint32_t offset = 8; // skip the header
|
|
|
|
uint32_t rssize = getRsItemSize(dat);
|
|
|
|
bool ok = true ;
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
RsGxsTunnelStatusItem *item = new RsGxsTunnelStatusItem();
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
/* get mandatory parts first */
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
ok &= getRawUInt32(dat, rssize, &offset, &item->flags);
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
if (offset != rssize)
|
|
|
|
{
|
|
|
|
std::cerr << "RsGxsTunnelDHPublicKeyItem::() Size error while deserializing." << std::endl ;
|
|
|
|
delete item ;
|
|
|
|
return NULL ;
|
|
|
|
}
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
std::cerr << "RsGxsTunnelDHPublicKeyItem::() Unknown error while deserializing." << std::endl ;
|
|
|
|
delete item ;
|
|
|
|
return NULL ;
|
|
|
|
}
|
2015-11-17 18:11:00 -05:00
|
|
|
|
2015-11-27 23:37:39 -05:00
|
|
|
return item ;
|
2015-11-17 18:11:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|