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,143 +0,0 @@
/*
* libretroshare/src/rsserver: p3photo.cc
*
* RetroShare C++ Interface.
*
* 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 "rsserver/p3photo.h"
#include "services/p3photoservice.h"
RsPhoto *rsPhoto = NULL;
RsPhotoDetails::RsPhotoDetails()
{
return;
}
RsPhotoShowDetails::RsPhotoShowDetails()
{
return;
}
p3Photo::p3Photo(p3PhotoService *p3ps)
:mPhoto(p3ps)
{
return;
}
p3Photo::~p3Photo()
{
return;
}
/* needs update? */
bool p3Photo::updated()
{
return mPhoto->updated();
}
/* access data */
bool p3Photo::getPhotoList(std::string id, std::list<std::string> &hashs)
{
return mPhoto->getPhotoList(id, hashs);
}
bool p3Photo::getShowList(std::string id, std::list<std::string> &showIds)
{
return mPhoto -> getShowList(id, showIds);
}
bool p3Photo::getShowDetails(std::string id, std::string showId, RsPhotoShowDetails &detail)
{
return mPhoto -> getShowDetails(id, showId, detail);
}
bool p3Photo::getPhotoDetails(std::string id, std::string photoId, RsPhotoDetails &detail)
{
return mPhoto -> getPhotoDetails(id, photoId, detail);
}
/* add / delete */
std::string p3Photo::createShow(std::string name)
{
return mPhoto -> createShow(name);
}
bool p3Photo::deleteShow(std::string showId)
{
return mPhoto -> deleteShow(showId);
}
bool p3Photo::addPhotoToShow(std::string showId, std::string photoId, int16_t index)
{
return mPhoto -> addPhotoToShow(showId, photoId, index);
}
bool p3Photo::movePhotoInShow(std::string showId, std::string photoId, int16_t index)
{
return mPhoto -> movePhotoInShow(showId, photoId, index);
}
bool p3Photo::removePhotoFromShow(std::string showId, std::string photoId)
{
return mPhoto -> removePhotoFromShow(showId, photoId);
}
std::string p3Photo::addPhoto(std::string path) /* add from file */
{
return mPhoto -> addPhoto(path); /* add from file */
}
bool p3Photo::addPhoto(std::string srcId, std::string photoId) /* add from peers photos */
{
return mPhoto -> addPhoto(srcId, photoId); /* add from peers photos */
}
bool p3Photo::deletePhoto(std::string photoId)
{
return mPhoto -> deletePhoto(photoId);
}
/* modify properties (TODO) */
bool p3Photo::modifyShow(std::string showId, std::wstring name, std::wstring comment)
{
return mPhoto -> modifyShow(showId, name, comment);
}
bool p3Photo::modifyPhoto(std::string photoId, std::wstring name, std::wstring comment)
{
return mPhoto -> modifyPhoto(photoId, name, comment);
}
bool p3Photo::modifyShowComment(std::string showId, std::string photoId, std::wstring comment)
{
return mPhoto -> modifyShowComment(showId, photoId, comment);
}

View File

@ -1,69 +0,0 @@
#ifndef RETROSHARE_P3_PHOTO_INTERFACE_H
#define RETROSHARE_P3_PHOTO_INTERFACE_H
/*
* libretroshare/src/rsserver: p3photo.h
*
* RetroShare C++ Interface.
*
* 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 "retroshare/rsphoto.h"
#include "services/p3photoservice.h"
class p3Photo: public RsPhoto
{
public:
p3Photo(p3PhotoService *p3ps);
virtual ~p3Photo();
/* changed? */
virtual bool updated();
/* access data */
virtual bool getPhotoList(std::string id, std::list<std::string> &hashs);
virtual bool getShowList(std::string id, std::list<std::string> &showIds);
virtual bool getShowDetails(std::string id, std::string showId, RsPhotoShowDetails &detail);
virtual bool getPhotoDetails(std::string id, std::string photoId, RsPhotoDetails &detail);
/* add / delete */
virtual std::string createShow(std::string name);
virtual bool deleteShow(std::string showId);
virtual bool addPhotoToShow(std::string showId, std::string photoId, int16_t index);
virtual bool movePhotoInShow(std::string showId, std::string photoId, int16_t index);
virtual bool removePhotoFromShow(std::string showId, std::string photoId);
virtual std::string addPhoto(std::string path); /* add from file */
virtual bool addPhoto(std::string srcId, std::string photoId); /* add from peers photos */
virtual bool deletePhoto(std::string photoId);
/* modify properties (TODO) */
virtual bool modifyShow(std::string showId, std::wstring name, std::wstring comment);
virtual bool modifyPhoto(std::string photoId, std::wstring name, std::wstring comment);
virtual bool modifyShowComment(std::string showId, std::string photoId, std::wstring comment);
private:
p3PhotoService *mPhoto;
};
#endif

View File

@ -1,104 +0,0 @@
/*
* libretroshare/src/rsserver: p3rank.cc
*
* RetroShare C++ Interface.
*
* 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 "rsserver/p3rank.h"
RsRanks *rsRanks = NULL;
p3Rank::p3Rank(p3Ranking *ranking)
:mRank(ranking)
{
return;
}
p3Rank::~p3Rank()
{
return;
}
/* needs update? */
bool p3Rank::updated()
{
return mRank->updated();
}
/* Set Sort Methods */
bool p3Rank::setSortPeriod(uint32_t period)
{
return mRank->setSortPeriod(period);
}
bool p3Rank::setSortMethod(uint32_t type)
{
return mRank->setSortMethod(type);
}
bool p3Rank::clearPeerFilter()
{
return mRank->clearPeerFilter();
}
bool p3Rank::setPeerFilter(std::list<std::string> peers)
{
return mRank->setPeerFilter(peers);
}
/* get Ids */
uint32_t p3Rank::getRankingsCount()
{
return mRank->getRankingsCount();
}
float p3Rank::getMaxRank()
{
return mRank->getMaxRank();
}
bool p3Rank::getRankings(uint32_t first, uint32_t count, std::list<std::string> &rids)
{
return mRank->getRankings(first, count, rids);
}
bool p3Rank::getRankDetails(std::string rid, RsRankDetails &details)
{
return mRank->getRankDetails(rid, details);
}
/* Add New Comment / Msg */
std::string p3Rank::newRankMsg(std::wstring link, std::wstring title, std::wstring comment, int32_t score)
{
return mRank->newRankMsg(link, title, comment, score);
}
bool p3Rank::updateComment(std::string rid, std::wstring comment, int32_t score)
{
return mRank->updateComment(rid, comment, score);
}
std::string p3Rank::anonRankMsg(std::string rid, std::wstring link, std::wstring title)
{
return mRank->anonRankMsg(rid, link, title);
}

View File

@ -1,64 +0,0 @@
#ifndef RETROSHARE_P3_RANKING_INTERFACE_H
#define RETROSHARE_P3_RANKING_INTERFACE_H
/*
* libretroshare/src/rsserver: p3rank.h
*
* RetroShare C++ Interface.
*
* 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 "retroshare/rsrank.h"
#include "services/p3ranking.h"
class p3Rank: public RsRanks
{
public:
p3Rank(p3Ranking *ranking);
virtual ~p3Rank();
/* needs update? */
virtual bool updated();
/* Set Sort Methods */
virtual bool setSortPeriod(uint32_t period);
virtual bool setSortMethod(uint32_t type);
virtual bool clearPeerFilter();
virtual bool setPeerFilter(std::list<std::string> peers);
/* get Ids */
virtual uint32_t getRankingsCount();
virtual float getMaxRank();
virtual bool getRankings(uint32_t first, uint32_t count, std::list<std::string> &rids);
virtual bool getRankDetails(std::string rid, RsRankDetails &details);
/* Add New Comment / Msg */
virtual std::string newRankMsg(std::wstring link, std::wstring title, std::wstring comment, int32_t score);
virtual bool updateComment(std::string rid, std::wstring comment, int32_t score);
virtual std::string anonRankMsg(std::string rid, std::wstring link, std::wstring title);
private:
p3Ranking *mRank;
};
#endif

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,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;
};