moved some files to unfinished and deleted soem unused files

This commit is contained in:
csoler 2018-11-10 17:40:13 +01:00
parent 602bc36eec
commit ddca91b0c9
No known key found for this signature in database
GPG key ID: 7BCA522266C0804C
16 changed files with 0 additions and 1206 deletions

View file

@ -1,345 +0,0 @@
/*
* libretroshare/src/serialiser: rsmailtransportitems.cc
*
* RetroShare Serialiser.
*
* Copyright 2014 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 "util/rstime.h"
#include "serialiser/rsbaseserial.h"
#include "serialiser/rsmailtransportitems.h"
#include "serialiser/rstlvbase.h"
/***
#define RSSERIAL_DEBUG 1
***/
#include <iostream>
/*************************************************************************/
// RsMailMimeItem
bool RsMailChunkItem::isPartial()
{
return (mPartCount != 1);
}
void RsMailChunkItem::clear()
{
mMailId.TlvClear();
mPartCount = 0;
mMailIndex = 0;
mWholeMailId.clear();
mMessage.clear();
}
std::ostream &RsMailChunkItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsMailChunkItem", indent);
uint16_t int_Indent = indent + 2;
mMailId.print(out, int_Indent);
printIndent(out, int_Indent);
out << "PartCount: " << mPartCount << std::endl;
printIndent(out, int_Indent);
out << "MailIndex: " << mMailIndex << std::endl;
printIndent(out, int_Indent);
out << "WholeMailId: " << mWholeMailId.toStdString() << std::endl;
printIndent(out, int_Indent);
out << "mMessage: " << mMessage << std::endl;
printRsItemEnd(out, "RsMailChunkItem", indent);
return out;
}
uint32_t RsMailChunkItem::serial_size()
{
uint32_t s = 8; /* header */
s += mMailId.TlvSize(); /* mMailId */
s += 2; /* mPartCount */
s += 2; /* mMailIndex */
s += mWholeMailId.serial_size(); /* mRecvTime */
s += GetTlvStringSize(mMessage);
return s;
}
/* serialise the data to the buffer */
bool RsMailChunkItem::serialise(void *data, uint32_t& pktsize)
{
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);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsMailChunkItem::serialise() Header: " << ok << std::endl;
std::cerr << "RsMailChunkItem::serialise() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= mMailId.SetTlv(data, tlvsize, &offset);
ok &= setRawUInt16(data, tlvsize, &offset, mPartCount);
ok &= setRawUInt16(data, tlvsize, &offset, mMailIndex);
ok &= mWholeMailId.serialise(data, tlvsize, offset);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, mMessage);
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsMailMimeSerialiser::serialiseItem() Size Error! " << std::endl;
}
return ok;
}
RsMailChunkItem *RsMailTransportSerialiser::deserialiseChunkItem(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)) ||
(mServiceType != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_MAIL_TRANSPORT_CHUNK != 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 */
RsMailChunkItem *item = new RsMailChunkItem(mServiceType);
item->clear();
/* skip the header */
offset += 8;
/* get mandatory parts first */
ok &= item->mMailId.GetTlv(data, rssize, &offset);
ok &= getRawUInt16(data, rssize, &offset, &(item->mPartCount));
ok &= getRawUInt16(data, rssize, &offset, &(item->mMailIndex));
ok &= item->mWholeMailId.deserialise(data, rssize, offset);
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, item->mMessage);
if (offset != rssize)
{
/* error */
delete item;
return NULL;
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
void RsMailAckItem::clear()
{
mMailId.TlvClear();
}
std::ostream& RsMailAckItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsMailAckItem", indent);
uint16_t int_Indent = indent + 2;
mMailId.print(out, int_Indent);
printRsItemEnd(out, "RsMailAckItem", indent);
return out;
}
uint32_t RsMailAckItem::serial_size()
{
uint32_t s = 8; /* header */
s += mMailId.TlvSize();
return s;
}
bool RsMailAckItem::serialise(void *data, uint32_t& pktsize)
{
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);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsMailAckItem::serialise() Header: " << ok << std::endl;
std::cerr << "RsMailAckItem::serialise() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= mMailId.SetTlv(data, tlvsize, &offset);
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsMailAckItem::serialise() Size Error! " << std::endl;
}
return ok;
}
RsMailAckItem* RsMailTransportSerialiser::deserialiseAckItem(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)) ||
(mServiceType != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_MAIL_TRANSPORT_ACK != 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 */
RsMailAckItem *item = new RsMailAckItem(mServiceType);
item->clear();
/* skip the header */
offset += 8;
/* get mandatory parts first */
ok &= item->mMailId.GetTlv(data, rssize, &offset);
if (offset != rssize)
{
/* error */
delete item;
return NULL;
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
/**************************/
RsItem* RsMailTransportSerialiser::deserialise(void *data, uint32_t *pktsize)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsMailTransportSerialiser::deserialise()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(mServiceType != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_MAIL_TRANSPORT_CHUNK:
return deserialiseChunkItem(data, pktsize);
break;
case RS_PKT_SUBTYPE_MAIL_TRANSPORT_ACK:
return deserialiseAckItem(data, pktsize);
break;
default:
return NULL;
break;
}
return NULL;
}
bool RsMailTransportSerialiser::serialise(RsItem *item, void *data, uint32_t *size){
if (item->PacketService() != mServiceType)
{
return false;
}
return dynamic_cast<RsMailTransportItem*>(item)->serialise(data,*size);
}
/*************************************************************************/

View file

@ -1,145 +0,0 @@
#ifndef RS_MAIL_TRANSPORT_ITEMS_H
#define RS_MAIL_TRANSPORT_ITEMS_H
/*
* libretroshare/src/serialiser: rsmailtransportitems.h
*
* RetroShare Serialiser.
*
* Copyright 2014-2014 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 <map>
#include "retroshare/rstypes.h"
#include "serialiser/rsserviceids.h"
#include "serialiser/rsserial.h"
#include "serialiser/rstlvmail.h"
/**************************************************************************/
// for defining tags themselves and msg tags
const uint8_t RS_PKT_SUBTYPE_MAIL_TRANSPORT_CHUNK = 0x01;
const uint8_t RS_PKT_SUBTYPE_MAIL_TRANSPORT_ACK = 0x02;
/**************************************************************************/
// These Types are generic - and usable by all MailTransport services.
// However they must be tweaked to indicate the Service ID before sending.
class RsMailTransportItem: public RsItem
{
public:
RsMailTransportItem(uint16_t service_type, uint8_t msg_subtype) : RsItem(RS_PKT_VERSION_SERVICE,service_type,msg_subtype)
{
setPriorityLevel(QOS_PRIORITY_RS_MAIL_ITEM) ;
}
RsMailTransportItem(uint8_t msg_subtype) : RsItem(RS_PKT_VERSION_SERVICE,0,msg_subtype)
{
setPriorityLevel(QOS_PRIORITY_RS_MAIL_ITEM) ;
}
virtual ~RsMailTransportItem() {}
virtual void clear() {}
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) = 0 ;
virtual bool serialise(void *data,uint32_t& size) = 0 ;
virtual uint32_t serial_size() = 0 ;
};
class RsMailChunkItem: public RsMailTransportItem
{
public:
RsMailChunkItem() :RsMailTransportItem(RS_PKT_SUBTYPE_MAIL_TRANSPORT_CHUNK) {}
RsMailChunkItem(uint16_t service_type) :RsMailTransportItem(service_type, RS_PKT_SUBTYPE_MAIL_TRANSPORT_CHUNK) {}
virtual ~RsMailChunkItem() {}
virtual void clear();
virtual bool serialise(void *data,uint32_t& size) ;
virtual uint32_t serial_size() ;
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
// extra functions.
bool isPartial();
// Serialised.
RsTlvMailId mMailId;
uint16_t mPartCount;
uint16_t mMailIndex;
RsMessageId mWholeMailId;
std::string mMessage;
};
class RsMailAckItem : public RsMailTransportItem
{
public:
RsMailAckItem() :RsMailTransportItem(RS_PKT_SUBTYPE_MAIL_TRANSPORT_ACK) {}
RsMailAckItem(uint16_t service_type) :RsMailTransportItem(service_type, RS_PKT_SUBTYPE_MAIL_TRANSPORT_ACK) {}
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
virtual bool serialise(void *data,uint32_t& size) ;
virtual uint32_t serial_size() ;
virtual ~RsMailAckItem() {}
virtual void clear();
// serialised
RsTlvMailId mMailId;
};
class RsMailTransportSerialiser: public RsSerialType
{
public:
RsMailTransportSerialiser(uint16_t service_type)
:RsSerialType(RS_PKT_VERSION_SERVICE, service_type),
mServiceType(service_type) {}
virtual ~RsMailTransportSerialiser() {}
virtual uint32_t size(RsItem *item)
{
return dynamic_cast<RsMailTransportItem*>(item)->serial_size() ;
}
virtual bool serialise(RsItem *i, void *d, uint32_t *s);
virtual RsItem * deserialise(void *data, uint32_t *size);
private:
virtual RsMailChunkItem *deserialiseChunkItem(void *data, uint32_t *size);
virtual RsMailAckItem *deserialiseAckItem(void *data, uint32_t *size);
uint16_t mServiceType;
};
/**************************************************************************/
#endif /* RS_MAIL_TRANSPORT_ITEMS_H */

View file

@ -1,419 +0,0 @@
/*
* libretroshare/src/serialiser: rstlvtypes.cc
*
* RetroShare Serialiser.
*
* Copyright 2007-2008 by Robert Fernie, Chris 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 "rstlvdsdv.h"
#include "rsbaseserial.h"
/************************************* RsTlvDsdvEndPoint ************************************/
RsTlvDsdvEndPoint::RsTlvDsdvEndPoint()
:RsTlvItem(), idType(0)
{
return;
}
void RsTlvDsdvEndPoint::TlvClear()
{
idType = 0;
anonChunk.clear();
serviceId.clear();
}
uint32_t RsTlvDsdvEndPoint::TlvSize() const
{
uint32_t s = TLV_HEADER_SIZE; /* header + 4 + str + str */
s += 4; // idType;
s += GetTlvStringSize(anonChunk);
s += GetTlvStringSize(serviceId);
return s;
}
bool RsTlvDsdvEndPoint::SetTlv(void *data, uint32_t size, uint32_t *offset) const
{
/* must check sizes */
uint32_t tlvsize = TlvSize();
uint32_t tlvend = *offset + tlvsize;
if (size < tlvend)
return false; /* not enough space */
bool ok = true;
/* start at data[offset] */
/* add mandatory parts first */
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_DSDV_ENDPOINT, tlvsize);
ok &= setRawUInt32(data, tlvend, offset, idType);
ok &= SetTlvString(data, tlvend, offset, TLV_TYPE_STR_GENID, anonChunk);
ok &= SetTlvString(data, tlvend, offset, TLV_TYPE_STR_HASH_SHA1, serviceId);
return ok;
}
bool RsTlvDsdvEndPoint::GetTlv(void *data, uint32_t size, uint32_t *offset)
{
if (size < *offset + TLV_HEADER_SIZE)
return false;
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
uint32_t tlvend = *offset + tlvsize;
if (size < tlvend) /* check size */
return false; /* not enough space */
if (tlvtype != TLV_TYPE_DSDV_ENDPOINT) /* check type */
return false;
bool ok = true;
/* ready to load */
TlvClear();
/* skip the header */
(*offset) += TLV_HEADER_SIZE;
ok &= getRawUInt32(data, tlvend, offset, &(idType));
ok &= GetTlvString(data, tlvend, offset, TLV_TYPE_STR_GENID, anonChunk);
ok &= GetTlvString(data, tlvend, offset, TLV_TYPE_STR_HASH_SHA1, serviceId);
/***************************************************************************
* NB: extra components could be added (for future expansion of the type).
* or be present (if this code is reading an extended version).
*
* We must chew up the extra characters to conform with TLV specifications
***************************************************************************/
if (*offset != tlvend)
{
#ifdef TLV_DEBUG
std::cerr << "RsTlvDsdvEndPoint::GetTlv() Warning extra bytes at end of item";
std::cerr << std::endl;
#endif
*offset = tlvend;
}
return ok;
}
std::ostream &RsTlvDsdvEndPoint::print(std::ostream &out, uint16_t indent) const
{
printBase(out, "RsTlvDsdvEndPoint", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "idType:" << idType;
out << std::endl;
printIndent(out, int_Indent);
out << "AnonChunk:" << anonChunk;
out << std::endl;
printIndent(out, int_Indent);
out << "ServiceId:" << serviceId;
out << std::endl;
printEnd(out, "RsTlvDsdvEndPoint", indent);
return out;
}
/************************************* RsTlvDsdvEntry ************************************/
RsTlvDsdvEntry::RsTlvDsdvEntry()
:RsTlvItem(), sequence(0), distance(0)
{
return;
}
void RsTlvDsdvEntry::TlvClear()
{
endPoint.TlvClear();
sequence = 0;
distance = 0;
}
uint32_t RsTlvDsdvEntry::TlvSize() const
{
uint32_t s = TLV_HEADER_SIZE; /* header + EndPoint.Size + 4 + 4 */
s += endPoint.TlvSize();
s += 4; // sequence;
s += 4; // distance;
return s;
}
bool RsTlvDsdvEntry::SetTlv(void *data, uint32_t size, uint32_t *offset) const
{
/* must check sizes */
uint32_t tlvsize = TlvSize();
uint32_t tlvend = *offset + tlvsize;
if (size < tlvend)
return false; /* not enough space */
bool ok = true;
/* start at data[offset] */
/* add mandatory parts first */
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_DSDV_ENTRY, tlvsize);
ok &= endPoint.SetTlv(data, size, offset);
ok &= setRawUInt32(data, tlvend, offset, sequence);
ok &= setRawUInt32(data, tlvend, offset, distance);
return ok;
}
bool RsTlvDsdvEntry::GetTlv(void *data, uint32_t size, uint32_t *offset)
{
if (size < *offset + TLV_HEADER_SIZE)
return false;
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
uint32_t tlvend = *offset + tlvsize;
if (size < tlvend) /* check size */
return false; /* not enough space */
if (tlvtype != TLV_TYPE_DSDV_ENTRY) /* check type */
return false;
bool ok = true;
/* ready to load */
TlvClear();
/* skip the header */
(*offset) += TLV_HEADER_SIZE;
ok &= endPoint.GetTlv(data, size, offset);
ok &= getRawUInt32(data, tlvend, offset, &(sequence));
ok &= getRawUInt32(data, tlvend, offset, &(distance));
/***************************************************************************
* NB: extra components could be added (for future expansion of the type).
* or be present (if this code is reading an extended version).
*
* We must chew up the extra characters to conform with TLV specifications
***************************************************************************/
if (*offset != tlvend)
{
#ifdef TLV_DEBUG
std::cerr << "RsTlvDsdvEntry::GetTlv() Warning extra bytes at end of item";
std::cerr << std::endl;
#endif
*offset = tlvend;
}
return ok;
}
std::ostream &RsTlvDsdvEntry::print(std::ostream &out, uint16_t indent) const
{
printBase(out, "RsTlvDsdvEntry", indent);
uint16_t int_Indent = indent + 2;
endPoint.print(out, int_Indent);
printIndent(out, int_Indent);
out << "Sequence:" << sequence;
out << std::endl;
printIndent(out, int_Indent);
out << "Distance:" << distance;
out << std::endl;
printEnd(out, "RsTlvDsdvEntry", indent);
return out;
}
/************************************* RsTlvDsdvEntrySet ************************************/
#if 0
RsTlvDsdvEntrySet::RsTlvDsdvEntrySet()
{
}
void RsTlvDsdvEntrySet::TlvClear()
{
entries.clear();
}
uint32_t RsTlvDsdvEntrySet::TlvSize()
{
uint32_t s = TLV_HEADER_SIZE; /* header */
std::list<RsTlvDsdvEntry>::iterator it;
if(!entries.empty())
{
for(it = entries.begin(); it != entries.end() ; ++it)
s += it->TlvSize();
}
return s;
}
bool RsTlvDsdvEntrySet::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
{
/* must check sizes */
uint32_t tlvsize = TlvSize();
uint32_t tlvend = *offset + tlvsize;
if (size < tlvend)
return false; /* not enough space */
bool ok = true;
/* start at data[offset] */
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_DSDV_ENTRY_SET , tlvsize);
if(!entries.empty())
{
std::list<RsTlvDsdvEntry>::iterator it;
for(it = entries.begin(); it != entries.end() ; ++it)
ok &= it->SetTlv(data, size, offset);
}
return ok;
}
bool RsTlvDsdvEntrySet::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
{
if (size < *offset + TLV_HEADER_SIZE)
return false;
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
uint32_t tlvend = *offset + tlvsize;
if (size < tlvend) /* check size */
return false; /* not enough space */
if (tlvtype != TLV_TYPE_DSDV_ENTRY_SET) /* check type */
return false;
bool ok = true;
/* ready to load */
TlvClear();
/* skip the header */
(*offset) += TLV_HEADER_SIZE;
/* while there is TLV */
while((*offset) + 2 < tlvend)
{
/* get the next type */
uint16_t tlvsubtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
switch(tlvsubtype)
{
case TLV_TYPE_DSDV_ENTRY:
{
RsTlvDsdvEntry entry;
ok &= entry.GetTlv(data, size, offset);
if (ok)
{
entries.push_back(entry);
}
}
break;
default:
ok &= SkipUnknownTlv(data, tlvend, offset);
break;
}
if (!ok)
break;
}
/***************************************************************************
* NB: extra components could be added (for future expansion of the type).
* or be present (if this code is reading an extended version).
*
* We must chew up the extra characters to conform with TLV specifications
***************************************************************************/
if (*offset != tlvend)
{
#ifdef TLV_DEBUG
std::cerr << "RsTlvDsdvEntrySet::GetTlv() Warning extra bytes at end of item";
std::cerr << std::endl;
#endif
*offset = tlvend;
}
return ok;
}
// prints out contents of RsTlvDsdvEntrySet
std::ostream &RsTlvDsdvEntrySet::print(std::ostream &out, uint16_t indent)
{
printBase(out, "RsTlvDsdvEntrySet", indent);
uint16_t int_Indent = indent + 2;
std::list<RsTlvDsdvEntry>::iterator it;
for(it = entries.begin(); it != entries.end() ; ++it)
it->print(out, int_Indent);
printEnd(out, "RsTlvDsdvEntrySet", indent);
return out;
}
#endif

View file

@ -1,88 +0,0 @@
#pragma once
/*
* libretroshare/src/serialiser: rstlvdsdv.h
*
* RetroShare Serialiser.
*
* Copyright 2011 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".
*
*/
/*******************************************************************
* These are the Compound TLV structures that must be (un)packed.
******************************************************************/
#include "serialiser/rstlvitem.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rstlvlist.h"
#define RSDSDV_MAX_ROUTE_TABLE 1000
class RsTlvDsdvEndPoint: public RsTlvItem
{
public:
RsTlvDsdvEndPoint();
virtual ~RsTlvDsdvEndPoint() { return; }
virtual uint32_t TlvSize() const;
virtual void TlvClear();
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
uint32_t idType;
std::string anonChunk;
std::string serviceId;
};
class RsTlvDsdvEntry: public RsTlvItem
{
public:
RsTlvDsdvEntry();
virtual ~RsTlvDsdvEntry() { return; }
virtual uint32_t TlvSize() const;
virtual void TlvClear();
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
RsTlvDsdvEndPoint endPoint;
uint32_t sequence;
uint32_t distance;
};
typedef t_RsTlvList<RsTlvDsdvEntry,TLV_TYPE_DSDV_ENTRY_SET> RsTlvDsdvEntrySet;
#if 0
class RsTlvDsdvEntrySet: public RsTlvItem
{
public:
RsTlvDsdvEntrySet();
virtual ~RsTlvDsdvEntrySet() { return; }
virtual uint32_t TlvSize();
virtual void TlvClear();
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
virtual std::ostream &print(std::ostream &out, uint16_t indent);
std::list<RsTlvDsdvEntry> entries;
};
#endif

View file

@ -1,265 +0,0 @@
/*
* libretroshare/src/serialiser: rstlvmsgs.cc
*
* RetroShare Serialiser.
*
* Copyright 2014 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 "serialiser/rstlvbase.h"
#include "serialiser/rstlvmail.h"
#include "serialiser/rsbaseserial.h"
/************************************* RsTlvIpAddress ************************************/
RsTlvMailAddress::RsTlvMailAddress()
:RsTlvItem()
{
return;
}
void RsTlvMailAddress::TlvClear()
{
mAddressType = 0;
mAddress.clear();
}
uint32_t RsTlvMailAddress::TlvSize() const
{
uint32_t s = TLV_HEADER_SIZE;
s += 4; // TYPE.
s += GetTlvStringSize(mAddress);
return s;
}
bool RsTlvMailAddress::SetTlv(void *data, uint32_t size, uint32_t *offset) const
{
/* must check sizes */
uint32_t tlvsize = TlvSize();
uint32_t tlvend = *offset + tlvsize;
if (size < tlvend)
return false; /* not enough space */
bool ok = true;
/* start at data[offset] */
/* add mandatory parts first */
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_MSG_ADDRESS, tlvsize);
ok &= setRawUInt32(data, tlvend, offset, mAddressType);
ok &= SetTlvString(data, tlvend, offset, TLV_TYPE_STR_MSG, mAddress);
return ok;
}
bool RsTlvMailAddress::GetTlv(void *data, uint32_t size, uint32_t *offset)
{
if (size < *offset + TLV_HEADER_SIZE)
return false;
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
uint32_t tlvend = *offset + tlvsize;
if (size < tlvend) /* check size */
return false; /* not enough space */
if (tlvtype != TLV_TYPE_MSG_ADDRESS) /* check type */
return false;
bool ok = true;
/* ready to load */
TlvClear();
/* skip the header */
(*offset) += TLV_HEADER_SIZE;
ok &= getRawUInt32(data, tlvend, offset, &(mAddressType));
ok &= GetTlvString(data, tlvend, offset, TLV_TYPE_STR_MSG, mAddress);
/***************************************************************************
* NB: extra components could be added (for future expansion of the type).
* or be present (if this code is reading an extended version).
*
* We must chew up the extra characters to conform with TLV specifications
***************************************************************************/
if (*offset != tlvend)
{
#ifdef TLV_DEBUG
std::cerr << "RsTlvIpAddress::GetTlv() Warning extra bytes at end of item";
std::cerr << std::endl;
#endif
*offset = tlvend;
}
return ok;
}
std::ostream &RsTlvMailAddress::print(std::ostream &out, uint16_t indent) const
{
printBase(out, "RsTlvMailAddress", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "AddressType:" << mAddressType << std::endl;
printIndent(out, int_Indent);
out << "Address:" << mAddress << std::endl;
printEnd(out, "RsTlvMailAddress", indent);
return out;
}
/************************************* RsTlvIpAddressInfo ************************************/
RsTlvMailId::RsTlvMailId()
:RsTlvItem(), mSentTime(0)
{
mMailFrom.TlvClear();
mMailDest.TlvClear();
mMailId.clear();
return;
}
void RsTlvMailId::TlvClear()
{
mMailFrom.TlvClear();
mMailDest.TlvClear();
mSentTime = 0;
mMailId.clear();
}
uint32_t RsTlvMailId::TlvSize() const
{
uint32_t s = TLV_HEADER_SIZE;
s += mMailFrom.TlvSize();
s += mMailDest.TlvSize();
s += 4; // SentTime
s += mMailId.serial_size();
return s;
}
bool RsTlvMailId::SetTlv(void *data, uint32_t size, uint32_t *offset) const
{
/* must check sizes */
uint32_t tlvsize = TlvSize();
uint32_t tlvend = *offset + tlvsize;
if (size < tlvend)
return false; /* not enough space */
bool ok = true;
/* start at data[offset] */
/* add mandatory parts first */
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_MSG_ID, tlvsize);
ok &= mMailFrom.SetTlv(data, tlvend, offset);
ok &= mMailDest.SetTlv(data, tlvend, offset);
ok &= setRawUInt32(data, tlvend, offset, mSentTime);
ok &= mMailId.serialise(data, tlvend, *offset);
return ok;
}
bool RsTlvMailId::GetTlv(void *data, uint32_t size, uint32_t *offset)
{
if (size < *offset + TLV_HEADER_SIZE)
return false;
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
uint32_t tlvend = *offset + tlvsize;
if (size < tlvend) /* check size */
return false; /* not enough space */
if (tlvtype != TLV_TYPE_MSG_ID) /* check type */
return false;
bool ok = true;
/* ready to load */
TlvClear();
/* skip the header */
(*offset) += TLV_HEADER_SIZE;
ok &= mMailFrom.GetTlv(data, tlvend, offset);
ok &= mMailDest.GetTlv(data, tlvend, offset);
ok &= getRawUInt32(data, tlvend, offset, &(mSentTime));
ok &= mMailId.deserialise(data, tlvend, *offset);
/***************************************************************************
* NB: extra components could be added (for future expansion of the type).
* or be present (if this code is reading an extended version).
*
* We must chew up the extra characters to conform with TLV specifications
***************************************************************************/
if (*offset != tlvend)
{
#ifdef TLV_DEBUG
std::cerr << "RsTlvMailId::GetTlv() Warning extra bytes at end of item";
std::cerr << std::endl;
#endif
*offset = tlvend;
}
return ok;
}
std::ostream &RsTlvMailId::print(std::ostream &out, uint16_t indent) const
{
printBase(out, "RsTlvMailId", indent);
uint16_t int_Indent = indent + 2;
mMailFrom.print(out, int_Indent);
mMailDest.print(out, int_Indent);
printIndent(out, int_Indent);
out << "SentTime:" << mSentTime;
out << std::endl;
printIndent(out, int_Indent);
out << "mMailId:" << mMailId.toStdString();
out << std::endl;
printEnd(out, "RsTlvMailId", indent);
return out;
}

View file

@ -1,71 +0,0 @@
#pragma once
/*
* libretroshare/src/serialiser: rstlvmail.h
*
* RetroShare Serialiser.
*
* Copyright 2014 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".
*
*/
/*******************************************************************
* These are the Compound TLV structures that must be (un)packed.
******************************************************************/
#include <retroshare/rstypes.h>
#include "serialiser/rstlvitem.h"
#include "util/rsnet.h"
#include <list>
class RsTlvMailAddress: public RsTlvItem
{
public:
RsTlvMailAddress();
virtual ~RsTlvMailAddress() { return; }
virtual uint32_t TlvSize() const;
virtual void TlvClear();
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
uint32_t mAddressType;
std::string mAddress;
};
class RsTlvMailId: public RsTlvItem
{
public:
RsTlvMailId();
virtual ~RsTlvMailId() { return; }
virtual uint32_t TlvSize() const;
virtual void TlvClear();
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
RsTlvMailAddress mMailFrom;
RsTlvMailAddress mMailDest;
uint32_t mSentTime;
RsMessageId mMailId;
};