mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-28 16:17:28 -04:00
Adding start of new Mail Service.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7723 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
6d32524837
commit
6588eafb99
14 changed files with 1321 additions and 1 deletions
|
@ -84,7 +84,8 @@ const uint8_t QOS_PRIORITY_RS_HEARTBEAT_PULSE = 8 ;
|
|||
//
|
||||
const uint8_t QOS_PRIORITY_RS_CHAT_ITEM = 7 ;
|
||||
const uint8_t QOS_PRIORITY_RS_CHAT_AVATAR_ITEM = 2 ;
|
||||
const uint8_t QOS_PRIORITY_RS_MSG_ITEM = 2 ;
|
||||
const uint8_t QOS_PRIORITY_RS_MSG_ITEM = 2 ; // depreciated.
|
||||
const uint8_t QOS_PRIORITY_RS_MAIL_ITEM = 2 ; // new mail service
|
||||
const uint8_t QOS_PRIORITY_RS_STATUS_ITEM = 2 ;
|
||||
|
||||
// RTT
|
||||
|
|
345
libretroshare/src/serialiser/rsmailtransportitems.cc
Normal file
345
libretroshare/src/serialiser/rsmailtransportitems.cc
Normal file
|
@ -0,0 +1,345 @@
|
|||
|
||||
/*
|
||||
* 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 <time.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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
145
libretroshare/src/serialiser/rsmailtransportitems.h
Normal file
145
libretroshare/src/serialiser/rsmailtransportitems.h
Normal file
|
@ -0,0 +1,145 @@
|
|||
#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 */
|
||||
|
||||
|
|
@ -175,6 +175,11 @@ uint16_t RsItem::PacketService() const
|
|||
return (type >> 8) & 0xFFFF;
|
||||
}
|
||||
|
||||
void RsItem::setPacketService(uint16_t service)
|
||||
{
|
||||
type &= 0xFF0000FF;
|
||||
type |= (uint32_t) (service << 8);
|
||||
}
|
||||
|
||||
|
||||
RsSerialType::RsSerialType(uint32_t t)
|
||||
|
|
|
@ -101,6 +101,7 @@ class RsItem: public RsMemoryManagement::SmallObject
|
|||
/* For Service Packets */
|
||||
RsItem(uint8_t ver, uint16_t service, uint8_t subtype);
|
||||
uint16_t PacketService() const; /* combined Packet class/type (mid 16bits) */
|
||||
void setPacketService(uint16_t service);
|
||||
|
||||
inline uint8_t priority_level() const { return _priority_level ;}
|
||||
inline void setPriorityLevel(uint8_t l) { _priority_level = l ;}
|
||||
|
|
|
@ -53,6 +53,11 @@ const uint16_t RS_SERVICE_TYPE_GROUTER = 0x0018;
|
|||
const uint16_t RS_SERVICE_TYPE_SERVICEINFO = 0x0020;
|
||||
/* Bandwidth Control */
|
||||
const uint16_t RS_SERVICE_TYPE_BWCTRL = 0x0021;
|
||||
// New Mail Service (replace old Msg Service)
|
||||
const uint16_t RS_SERVICE_TYPE_MAIL = 0x0022;
|
||||
const uint16_t RS_SERVICE_TYPE_DIRECT_MAIL = 0x0023;
|
||||
const uint16_t RS_SERVICE_TYPE_DISTANT_MAIL = 0x0024;
|
||||
const uint16_t RS_SERVICE_TYPE_GWEMAIL_MAIL = 0x0025;
|
||||
|
||||
// Non essential services.
|
||||
const uint16_t RS_SERVICE_TYPE_BANLIST = 0x0101;
|
||||
|
|
|
@ -229,6 +229,8 @@ const uint16_t TLV_TYPE_DSDV_ENTRY_SET= 0x1082;
|
|||
const uint16_t TLV_TYPE_BAN_ENTRY = 0x1090;
|
||||
const uint16_t TLV_TYPE_BAN_LIST = 0x1091;
|
||||
|
||||
const uint16_t TLV_TYPE_MSG_ADDRESS = 0x10A0;
|
||||
const uint16_t TLV_TYPE_MSG_ID = 0x10A1;
|
||||
|
||||
|
||||
const uint32_t RSTLV_IMAGE_TYPE_PNG = 0x0001;
|
||||
|
|
265
libretroshare/src/serialiser/rstlvmail.cc
Normal file
265
libretroshare/src/serialiser/rstlvmail.cc
Normal file
|
@ -0,0 +1,265 @@
|
|||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
71
libretroshare/src/serialiser/rstlvmail.h
Normal file
71
libretroshare/src/serialiser/rstlvmail.h
Normal file
|
@ -0,0 +1,71 @@
|
|||
#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;
|
||||
};
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue