mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-28 08:07:31 -04:00
Added ServiceControl + ServiceInfo. Basics are working, but still a lot to do!
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7196 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
a4b54e1021
commit
83a78bcaee
71 changed files with 3168 additions and 209 deletions
|
@ -109,3 +109,7 @@ const uint8_t QOS_PRIORITY_RS_DSDV_DATA = 2 ;
|
|||
const uint8_t QOS_PRIORITY_RS_GXS_NET = 3 ;
|
||||
// GXS Reputation.
|
||||
const uint8_t QOS_PRIORITY_RS_GXSREPUTATION_ITEM = 2;
|
||||
|
||||
// Service Info / Control.
|
||||
const uint8_t QOS_PRIORITY_RS_SERVICE_INFO_ITEM = 7;
|
||||
|
||||
|
|
|
@ -215,6 +215,12 @@ bool setRawUFloat32(void *data,uint32_t size,uint32_t *offset,float f)
|
|||
return setRawUInt32(data, size, offset, n);
|
||||
}
|
||||
|
||||
|
||||
uint32_t getRawStringSize(const std::string &outStr)
|
||||
{
|
||||
return outStr.length() + 4;
|
||||
}
|
||||
|
||||
bool getRawString(void *data, uint32_t size, uint32_t *offset, std::string &outStr)
|
||||
{
|
||||
uint32_t len = 0;
|
||||
|
|
|
@ -63,6 +63,7 @@ bool setRawUInt64(void *data, uint32_t size, uint32_t *offset, uint64_t in);
|
|||
bool getRawUFloat32(void *data, uint32_t size, uint32_t *offset, float& out);
|
||||
bool setRawUFloat32(void *data, uint32_t size, uint32_t *offset, float in);
|
||||
|
||||
uint32_t getRawStringSize(const std::string &outStr);
|
||||
bool getRawString(void *data, uint32_t size, uint32_t *offset, std::string &outStr);
|
||||
bool setRawString(void *data, uint32_t size, uint32_t *offset, const std::string &inStr);
|
||||
|
||||
|
|
|
@ -52,6 +52,8 @@ const uint16_t RS_SERVICE_TYPE_FILE_TRANSFER = 0x0017;
|
|||
/* BanList Still Testing at the moment - Service Only */
|
||||
const uint16_t RS_SERVICE_TYPE_BANLIST = 0x0101;
|
||||
|
||||
const uint16_t RS_SERVICE_TYPE_SERVICEINFO = 0x0201;
|
||||
|
||||
/* Caches based on p3distrib (Cache Only)
|
||||
* Unfortunately, noone changed the DUMMY IDS... so we are stuck with them!
|
||||
*/
|
||||
|
|
445
libretroshare/src/serialiser/rsserviceinfoitems.cc
Normal file
445
libretroshare/src/serialiser/rsserviceinfoitems.cc
Normal file
|
@ -0,0 +1,445 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsserviceinfoitems.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.1 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/rsbaseserial.h"
|
||||
#include "serialiser/rsserviceinfoitems.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
/*************************************************************************/
|
||||
/***** RsServiceInfo ****/
|
||||
|
||||
template<>
|
||||
std::ostream &RsTlvParamRef<RsServiceInfo>::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
out << "RsServiceInfo: " << mParam.mServiceType << " name " << mParam.mServiceName;
|
||||
out << std::endl;
|
||||
out << "Version(" << mParam.mVersionMajor << "," << mParam.mVersionMinor << ")";
|
||||
out << " MinVersion(" << mParam.mMinVersionMajor << "," << mParam.mMinVersionMinor << ")";
|
||||
out << std::endl;
|
||||
return out;
|
||||
}
|
||||
|
||||
template<>
|
||||
uint32_t RsTlvParamRef<RsServiceInfo>::TlvSize()
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header + 4 for size */
|
||||
|
||||
s += getRawStringSize(mParam.mServiceName);
|
||||
s += 4; // type.
|
||||
s += 4; // version.
|
||||
s += 4; // min version.
|
||||
return s;
|
||||
}
|
||||
|
||||
template<>
|
||||
void RsTlvParamRef<RsServiceInfo>::TlvClear()
|
||||
{
|
||||
mParam = RsServiceInfo();
|
||||
mParam.mServiceName.clear();
|
||||
}
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<RsServiceInfo>::SetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
{
|
||||
return false; /* not enough space */
|
||||
}
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= SetTlvBase(data, tlvend, offset, mParamType, tlvsize);
|
||||
ok &= setRawString(data, tlvend, offset, mParam.mServiceName);
|
||||
ok &= setRawUInt32(data, tlvend, offset, mParam.mServiceType);
|
||||
ok &= setRawUInt16(data, tlvend, offset, mParam.mVersionMajor);
|
||||
ok &= setRawUInt16(data, tlvend, offset, mParam.mVersionMinor);
|
||||
ok &= setRawUInt16(data, tlvend, offset, mParam.mMinVersionMajor);
|
||||
ok &= setRawUInt16(data, tlvend, offset, mParam.mMinVersionMinor);
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsTlvParamRef<RsServiceInfo>::SetTlv() Failed";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<RsServiceInfo>::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 != mParamType) /* check type */
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
ok &= getRawString(data, tlvend, offset, mParam.mServiceName);
|
||||
ok &= getRawUInt32(data, tlvend, offset, &(mParam.mServiceType));
|
||||
ok &= getRawUInt16(data, tlvend, offset, &(mParam.mVersionMajor));
|
||||
ok &= getRawUInt16(data, tlvend, offset, &(mParam.mVersionMinor));
|
||||
ok &= getRawUInt16(data, tlvend, offset, &(mParam.mMinVersionMajor));
|
||||
ok &= getRawUInt16(data, tlvend, offset, &(mParam.mMinVersionMinor));
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
template class RsTlvParamRef<RsServiceInfo>;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsServiceInfoListItem::~RsServiceInfoListItem()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void RsServiceInfoListItem::clear()
|
||||
{
|
||||
mServiceInfo.clear();
|
||||
}
|
||||
|
||||
std::ostream &RsServiceInfoListItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsServiceInfoListItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
RsTlvServiceInfoMapRef map(mServiceInfo);
|
||||
map.print(out, int_Indent);
|
||||
out << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsServiceInfoListItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsServiceInfoSerialiser::sizeInfo(RsServiceInfoListItem *item)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
RsTlvServiceInfoMapRef map(item->mServiceInfo);
|
||||
s += map.TlvSize();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* serialise the data to the buffer */
|
||||
bool RsServiceInfoSerialiser::serialiseInfo(RsServiceInfoListItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
uint32_t tlvsize = sizeInfo(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (*pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsServiceInfoSerialiser::serialiseInfo() Header: " << ok << std::endl;
|
||||
std::cerr << "RsServiceInfoSerialiser::serialiseInfo() Size: " << tlvsize << std::endl;
|
||||
#endif
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
RsTlvServiceInfoMapRef map(item->mServiceInfo);
|
||||
ok &= map.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsServiceInfoSerialiser::serialiseInfo() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsServiceInfoListItem *RsServiceInfoSerialiser::deserialiseInfo(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t tlvsize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_SERVICEINFO != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_SERVICELIST_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*pktsize < tlvsize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsServiceInfoListItem *item = new RsServiceInfoListItem();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* get mandatory parts first */
|
||||
RsTlvServiceInfoMapRef map(item->mServiceInfo);
|
||||
ok &= map.GetTlv(data, tlvsize, &offset);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
RsServiceInfoPermissionsItem::~RsServiceInfoPermissionsItem()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void RsServiceInfoPermissionsItem::clear()
|
||||
{
|
||||
allowedBw = 0;
|
||||
}
|
||||
|
||||
std::ostream &RsServiceInfoPermissionsItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsServiceInfoPermissionsItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
printIndent(out, int_Indent);
|
||||
out << "AllowedBw: " << allowedBw;
|
||||
out << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsServiceInfoPermissionsItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsServiceInfoSerialiser::sizePermissions(RsServiceInfoPermissionsItem * /*item*/)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += GetTlvUInt32Size();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* serialise the data to the buffer */
|
||||
bool RsServiceInfoSerialiser::serialisePermissions(RsServiceInfoPermissionsItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
uint32_t tlvsize = sizePermissions(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (*pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsServiceInfoSerialiser::serialisePermissions() Header: " << ok << std::endl;
|
||||
std::cerr << "RsServiceInfoSerialiser::serialisePermissions() Size: " << tlvsize << std::endl;
|
||||
#endif
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= SetTlvUInt32(data, tlvsize, &offset, TLV_TYPE_UINT32_BW, item->allowedBw);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsServiceInfoSerialiser::serialisePermissions() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsServiceInfoPermissionsItem *RsServiceInfoSerialiser::deserialisePermissions(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t tlvsize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_SERVICEINFO != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_SERVICEPERMISSIONS_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*pktsize < tlvsize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsServiceInfoPermissionsItem *item = new RsServiceInfoPermissionsItem();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* get mandatory parts first */
|
||||
ok &= GetTlvUInt32(data, tlvsize, &offset, TLV_TYPE_UINT32_BW, &(item->allowedBw));
|
||||
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
uint32_t RsServiceInfoSerialiser::size(RsItem *i)
|
||||
{
|
||||
RsServiceInfoListItem *sli;
|
||||
RsServiceInfoPermissionsItem *spi;
|
||||
|
||||
if (NULL != (sli = dynamic_cast<RsServiceInfoListItem *>(i)))
|
||||
{
|
||||
return sizeInfo(sli);
|
||||
}
|
||||
if (NULL != (spi = dynamic_cast<RsServiceInfoPermissionsItem *>(i)))
|
||||
{
|
||||
return sizePermissions(spi);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool RsServiceInfoSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
|
||||
{
|
||||
RsServiceInfoListItem *sli;
|
||||
RsServiceInfoPermissionsItem *spi;
|
||||
|
||||
if (NULL != (sli = dynamic_cast<RsServiceInfoListItem *>(i)))
|
||||
{
|
||||
return serialiseInfo(sli, data, pktsize);
|
||||
}
|
||||
if (NULL != (spi = dynamic_cast<RsServiceInfoPermissionsItem *>(i)))
|
||||
{
|
||||
return serialisePermissions(spi, data, pktsize);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem *RsServiceInfoSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_SERVICEINFO != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
case RS_PKT_SUBTYPE_SERVICELIST_ITEM:
|
||||
return deserialiseInfo(data, pktsize);
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_SERVICEPERMISSIONS_ITEM:
|
||||
return deserialisePermissions(data, pktsize);
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
|
||||
|
133
libretroshare/src/serialiser/rsserviceinfoitems.h
Normal file
133
libretroshare/src/serialiser/rsserviceinfoitems.h
Normal file
|
@ -0,0 +1,133 @@
|
|||
#ifndef RS_SERVICE_INFO_ITEMS_H
|
||||
#define RS_SERVICE_INFO_ITEMS_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsserviceinfoitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2012 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.1 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".
|
||||
*
|
||||
*/
|
||||
|
||||
// Provides serialiser for p3ServiceControl & p3ServiceInfo.
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvgenericmap.h"
|
||||
#include "retroshare/rsservicecontrol.h"
|
||||
|
||||
#define RS_PKT_SUBTYPE_SERVICELIST_ITEM 0x01
|
||||
#define RS_PKT_SUBTYPE_SERVICEPERMISSIONS_ITEM 0x02
|
||||
|
||||
/**************************************************************************/
|
||||
#define SERVICE_INFO_MAP 0x01
|
||||
#define SERVICE_INFO_KEY 0x01
|
||||
#define SERVICE_ID 0x01
|
||||
#define SERVICE_INFO 0x01
|
||||
|
||||
class RsTlvServiceInfoMapRef: public RsTlvGenericMapRef<uint32_t, RsServiceInfo>
|
||||
{
|
||||
public:
|
||||
RsTlvServiceInfoMapRef(std::map<uint32_t, RsServiceInfo> &refmap)
|
||||
:RsTlvGenericMapRef<uint32_t, RsServiceInfo>(
|
||||
SERVICE_INFO_MAP,
|
||||
SERVICE_INFO_KEY,
|
||||
SERVICE_ID,
|
||||
SERVICE_INFO,
|
||||
refmap)
|
||||
{
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class RsServiceInfoListItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsServiceInfoListItem()
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_SERVICEINFO,
|
||||
RS_PKT_SUBTYPE_SERVICELIST_ITEM)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_SERVICE_INFO_ITEM);
|
||||
return;
|
||||
}
|
||||
|
||||
virtual ~RsServiceInfoListItem();
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
std::map<uint32_t, RsServiceInfo> mServiceInfo;
|
||||
};
|
||||
|
||||
|
||||
class RsServiceInfoPermissionsItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsServiceInfoPermissionsItem()
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_SERVICEINFO,
|
||||
RS_PKT_SUBTYPE_SERVICEPERMISSIONS_ITEM)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_SERVICE_INFO_ITEM);
|
||||
return;
|
||||
}
|
||||
|
||||
virtual ~RsServiceInfoPermissionsItem();
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
uint32_t allowedBw; // Units are bytes/sec => 4Gb/s;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class RsServiceInfoSerialiser: public RsSerialType
|
||||
{
|
||||
public:
|
||||
RsServiceInfoSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_SERVICEINFO)
|
||||
{ return; }
|
||||
virtual ~RsServiceInfoSerialiser()
|
||||
{ return; }
|
||||
|
||||
virtual uint32_t size(RsItem *);
|
||||
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
|
||||
virtual RsItem * deserialise(void *data, uint32_t *size);
|
||||
|
||||
private:
|
||||
|
||||
virtual uint32_t sizeInfo(RsServiceInfoListItem *);
|
||||
virtual bool serialiseInfo(RsServiceInfoListItem *item, void *data, uint32_t *size);
|
||||
virtual RsServiceInfoListItem *deserialiseInfo(void *data, uint32_t *size);
|
||||
|
||||
|
||||
virtual uint32_t sizePermissions(RsServiceInfoPermissionsItem *);
|
||||
virtual bool serialisePermissions(RsServiceInfoPermissionsItem *item, void *data, uint32_t *size);
|
||||
virtual RsServiceInfoPermissionsItem *deserialisePermissions(void *data, uint32_t *size);
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#endif /* RS_SERVICE_INFO_ITEMS_H */
|
|
@ -259,6 +259,98 @@ bool GetTlvUInt32(void *data, uint32_t size, uint32_t *offset,
|
|||
return ok;
|
||||
}
|
||||
|
||||
// UInt16
|
||||
bool SetTlvUInt16(void *data, uint32_t size, uint32_t *offset, uint16_t type,
|
||||
uint16_t out)
|
||||
{
|
||||
if (!data)
|
||||
return false;
|
||||
uint32_t tlvsize = GetTlvUInt16Size(); /* this will always be 8 bytes */
|
||||
uint32_t tlvend = *offset + tlvsize; /* where the data will extend to */
|
||||
if (size < tlvend)
|
||||
{
|
||||
#ifdef TLV_BASE_DEBUG
|
||||
std::cerr << "SetTlvUInt16() FAILED - not enough space. (or earlier)" << std::endl;
|
||||
std::cerr << "SetTlvUInt16() size: " << size << std::endl;
|
||||
std::cerr << "SetTlvUInt16() tlvsize: " << tlvsize << std::endl;
|
||||
std::cerr << "SetTlvUInt16() tlvend: " << tlvend << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* Now use the function we got to set the TlvHeader */
|
||||
/* function shifts offset to the new start for the next data */
|
||||
ok &= SetTlvBase(data, tlvend, offset, type, tlvsize);
|
||||
|
||||
#ifdef TLV_BASE_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "SetTlvUInt16() SetTlvBase FAILED (or earlier)" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* now set the UInt16 ( in rsbaseserial.h???) */
|
||||
ok &= setRawUInt16(data, tlvend, offset, out);
|
||||
|
||||
#ifdef TLV_BASE_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "SetTlvUInt16() setRawUInt16 FAILED (or earlier)" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
bool GetTlvUInt16(void *data, uint32_t size, uint32_t *offset,
|
||||
uint16_t type, uint16_t *in)
|
||||
{
|
||||
if (!data)
|
||||
return false;
|
||||
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
|
||||
/* extract the type and size */
|
||||
void *tlvstart = right_shift_void_pointer(data, *offset);
|
||||
uint16_t tlvtype = GetTlvType(tlvstart);
|
||||
uint32_t tlvsize = GetTlvSize(tlvstart);
|
||||
|
||||
/* check that there is size */
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
if (size < tlvend)
|
||||
{
|
||||
#ifdef TLV_BASE_DEBUG
|
||||
std::cerr << "GetTlvUInt16() FAILED - not enough space." << std::endl;
|
||||
std::cerr << "GetTlvUInt16() size: " << size << std::endl;
|
||||
std::cerr << "GetTlvUInt16() tlvsize: " << tlvsize << std::endl;
|
||||
std::cerr << "GetTlvUInt16() tlvend: " << tlvend << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type != tlvtype)
|
||||
{
|
||||
#ifdef TLV_BASE_DEBUG
|
||||
std::cerr << "GetTlvUInt16() FAILED - Type mismatch" << std::endl;
|
||||
std::cerr << "GetTlvUInt16() type: " << type << std::endl;
|
||||
std::cerr << "GetTlvUInt16() tlvtype: " << tlvtype << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*offset += TLV_HEADER_SIZE; /* step past header */
|
||||
|
||||
bool ok = true;
|
||||
ok &= getRawUInt16(data, tlvend, offset, in);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
uint32_t GetTlvUInt64Size() {
|
||||
return TLV_HEADER_SIZE + 8;
|
||||
|
|
|
@ -32,28 +32,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
/**** TLV *****
|
||||
* Generic Parameters / Maps.
|
||||
*/
|
||||
|
||||
|
||||
template<class T>
|
||||
class RsTlvParamRef: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvParamRef(uint16_t param_type, T &p): mParamType(param_type), mParam(p) {}
|
||||
virtual ~RsTlvParamRef() { 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);
|
||||
|
||||
uint16_t mParamType;
|
||||
T &mParam;
|
||||
};
|
||||
|
||||
#include "serialiser/rstlvgenericparam.h"
|
||||
|
||||
/*********************************** RsTlvGenericPairRef ***********************************/
|
||||
|
||||
|
@ -107,5 +86,7 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
|||
};
|
||||
|
||||
|
||||
#include "rstlvgenericmap.inl"
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvgenericmap.cc
|
||||
* libretroshare/src/serialiser: rstlvgenericmap.inl
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
|
@ -36,89 +36,6 @@
|
|||
|
||||
#define TLV_DEBUG 1
|
||||
|
||||
/* generic print */
|
||||
template<class T>
|
||||
std::ostream & RsTlvParamRef<T>::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printIndent(out, indent);
|
||||
out << "Type: " << mParamType << "Param: " << mParam;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
uint32_t RsTlvParamRef<uint32_t>::TlvSize()
|
||||
{
|
||||
return GetTlvUInt32Size();
|
||||
}
|
||||
|
||||
template<>
|
||||
void RsTlvParamRef<uint32_t>::TlvClear()
|
||||
{
|
||||
mParam = 0;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<uint32_t>::SetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
return SetTlvUInt32(data, size, offset, mParamType, mParam);
|
||||
}
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<uint32_t>::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
return GetTlvUInt32(data, size, offset, mParamType, &mParam);
|
||||
}
|
||||
|
||||
#if 0
|
||||
template<>
|
||||
std::ostream & RsTlvParamRef<uint32_t>::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printIndent(out, indent);
|
||||
out << mParam;
|
||||
return out;
|
||||
}
|
||||
#endif
|
||||
|
||||
/***** std::string ****/
|
||||
template<>
|
||||
uint32_t RsTlvParamRef<std::string>::TlvSize()
|
||||
{
|
||||
return GetTlvStringSize(mParam);
|
||||
}
|
||||
|
||||
template<>
|
||||
void RsTlvParamRef<std::string>::TlvClear()
|
||||
{
|
||||
mParam.clear();
|
||||
}
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<std::string>::SetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
return SetTlvString(data, size, offset, mParamType, mParam);
|
||||
}
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<std::string>::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
return GetTlvString(data, size, offset, mParamType, mParam);
|
||||
}
|
||||
|
||||
#if 0
|
||||
template<>
|
||||
std::ostream & RsTlvParamRef<std::string>::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printIndent(out, indent);
|
||||
out << "Type: " << mParamType << "Param: " << mParam;
|
||||
return out;
|
||||
}
|
||||
#endif
|
||||
|
||||
// declare likely combinations.
|
||||
template class RsTlvParamRef<uint32_t>;
|
||||
template class RsTlvParamRef<std::string>;
|
||||
|
||||
/*********************************** RsTlvGenericPairRef ***********************************/
|
||||
|
||||
template<class K, class V>
|
||||
|
@ -163,6 +80,16 @@ bool RsTlvGenericPairRef<K, V>::SetTlv(void *data, uint32_t size, uint32_t *off
|
|||
ok &= key.SetTlv(data, tlvend, offset);
|
||||
ok &= value.SetTlv(data, tlvend, offset);
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsTlvGenericPairRef<>::SetTlv() Failed";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "RsTlvGenericPairRef<>::SetTlv() Ok";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
@ -187,6 +114,9 @@ bool RsTlvGenericPairRef<K, V>::GetTlv(void *data, uint32_t size, uint32_t *off
|
|||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
RsTlvParamRef<K> key(mKeyType, mKey);
|
||||
RsTlvParamRef<V> value(mValueType, mValue);
|
||||
ok &= key.GetTlv(data, tlvend, offset);
|
||||
|
@ -213,7 +143,7 @@ bool RsTlvGenericPairRef<K, V>::GetTlv(void *data, uint32_t size, uint32_t *off
|
|||
template<class K, class V>
|
||||
std::ostream &RsTlvGenericPairRef<K, V>::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printBase(out, "RsTlvGenericPairRef", indent);
|
||||
//printBase(out, "RsTlvGenericPairRef", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
RsTlvParamRef<K> key(mKeyType, mKey);
|
||||
|
@ -229,7 +159,7 @@ std::ostream &RsTlvGenericPairRef<K, V>::print(std::ostream &out, uint16_t inden
|
|||
value.print(out, 0);
|
||||
out << std::endl;
|
||||
|
||||
printEnd(out, "RsTlvGenericPairRef", indent);
|
||||
//printEnd(out, "RsTlvGenericPairRef", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -285,6 +215,12 @@ bool RsTlvGenericMapRef<K, V>::SetTlv(void *data, uint32_t size, uint32_t *offs
|
|||
ok &= pair.SetTlv(data, size, offset);
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsTlvGenericMapRef<>::SetTlv() Failed";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
@ -322,7 +258,7 @@ bool RsTlvGenericMapRef<K, V>::GetTlv(void *data, uint32_t size, uint32_t *offs
|
|||
{
|
||||
K k;
|
||||
V v;
|
||||
RsTlvGenericPairRef<const K, V> pair(mPairType, mKeyType, mValueType, k, v);
|
||||
RsTlvGenericPairRef<K, V> pair(mPairType, mKeyType, mValueType, k, v);
|
||||
ok &= pair.GetTlv(data, size, offset);
|
||||
if (ok)
|
||||
{
|
||||
|
@ -360,7 +296,7 @@ bool RsTlvGenericMapRef<K, V>::GetTlv(void *data, uint32_t size, uint32_t *offs
|
|||
template<class K, class V>
|
||||
std::ostream &RsTlvGenericMapRef<K, V>::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printBase(out, "RsTlvGenericMapRef", indent);
|
||||
//printBase(out, "RsTlvGenericMapRef", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
|
@ -373,15 +309,15 @@ std::ostream &RsTlvGenericMapRef<K, V>::print(std::ostream &out, uint16_t indent
|
|||
pair.print(out, int_Indent);
|
||||
}
|
||||
|
||||
printEnd(out, "RsTlvGenericMapRef", indent);
|
||||
//printEnd(out, "RsTlvGenericMapRef", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
// declare likely combinations.
|
||||
template class RsTlvGenericMapRef<uint32_t, uint32_t>;
|
||||
template class RsTlvGenericMapRef<uint32_t, std::string>;
|
||||
template class RsTlvGenericMapRef<std::string, uint32_t>;
|
||||
template class RsTlvGenericMapRef<std::string, std::string>;
|
||||
//template class RsTlvGenericMapRef<uint32_t, uint32_t>;
|
||||
//template class RsTlvGenericMapRef<uint32_t, std::string>;
|
||||
//template class RsTlvGenericMapRef<std::string, uint32_t>;
|
||||
//template class RsTlvGenericMapRef<std::string, std::string>;
|
||||
|
||||
|
||||
|
235
libretroshare/src/serialiser/rstlvgenericparam.cc
Normal file
235
libretroshare/src/serialiser/rstlvgenericparam.cc
Normal file
|
@ -0,0 +1,235 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvgenericparam.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.1 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 "rstlvbase.h"
|
||||
#include "rstlvtypes.h"
|
||||
#include "rstlvgenericmap.h"
|
||||
#include "rsbaseserial.h"
|
||||
#include "util/rsprint.h"
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
#define TLV_DEBUG 1
|
||||
|
||||
/* generic print */
|
||||
template<class T>
|
||||
std::ostream & RsTlvParamRef<T>::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printIndent(out, indent);
|
||||
out << "Type: " << mParamType << " Param: " << mParam;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
/***** uint16_t ****/
|
||||
template<>
|
||||
uint32_t RsTlvParamRef<uint16_t>::TlvSize()
|
||||
{
|
||||
return GetTlvUInt16Size();
|
||||
}
|
||||
|
||||
template<>
|
||||
void RsTlvParamRef<uint16_t>::TlvClear()
|
||||
{
|
||||
mParam = 0;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<uint16_t>::SetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
uint16_t param = mParam;
|
||||
return SetTlvUInt16(data, size, offset, mParamType, mParam);
|
||||
}
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<uint16_t>::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
uint16_t param;
|
||||
bool retval = GetTlvUInt16(data, size, offset, mParamType, ¶m);
|
||||
mParam = param;
|
||||
return retval;
|
||||
}
|
||||
|
||||
template<>
|
||||
std::ostream & RsTlvParamRef<uint16_t>::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printIndent(out, indent);
|
||||
out << "Type: " << mParamType << "Param: " << mParam;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
/***** const uint16_t ****/
|
||||
|
||||
template<>
|
||||
uint32_t RsTlvParamRef<const uint16_t>::TlvSize()
|
||||
{
|
||||
return GetTlvUInt16Size();
|
||||
}
|
||||
|
||||
template<>
|
||||
void RsTlvParamRef<const uint16_t>::TlvClear()
|
||||
{
|
||||
//mParam = 0;
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<const uint16_t>::SetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
return SetTlvUInt16(data, size, offset, mParamType, mParam);
|
||||
}
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<const uint16_t>::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
return false; //GetTlvUInt16(data, size, offset, mParamType, &mParam);
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
std::ostream & RsTlvParamRef<const uint16_t>::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printIndent(out, indent);
|
||||
out << "Type: " << mParamType << "Param: " << mParam;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
/***** uint32_t ****/
|
||||
template<>
|
||||
uint32_t RsTlvParamRef<uint32_t>::TlvSize()
|
||||
{
|
||||
return GetTlvUInt32Size();
|
||||
}
|
||||
|
||||
template<>
|
||||
void RsTlvParamRef<uint32_t>::TlvClear()
|
||||
{
|
||||
mParam = 0;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<uint32_t>::SetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
return SetTlvUInt32(data, size, offset, mParamType, mParam);
|
||||
}
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<uint32_t>::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
return GetTlvUInt32(data, size, offset, mParamType, &mParam);
|
||||
}
|
||||
|
||||
template<>
|
||||
std::ostream & RsTlvParamRef<uint32_t>::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printIndent(out, indent);
|
||||
out << "Type: " << mParamType << "Param: " << mParam;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***** const uint32_t ****/
|
||||
template<>
|
||||
uint32_t RsTlvParamRef<const uint32_t>::TlvSize()
|
||||
{
|
||||
return GetTlvUInt32Size();
|
||||
}
|
||||
|
||||
template<>
|
||||
void RsTlvParamRef<const uint32_t>::TlvClear()
|
||||
{
|
||||
//mParam = 0;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<const uint32_t>::SetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
return SetTlvUInt32(data, size, offset, mParamType, mParam);
|
||||
}
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<const uint32_t>::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
return false;
|
||||
//GetTlvUInt32(data, size, offset, mParamType, &mParam);
|
||||
}
|
||||
|
||||
template<>
|
||||
std::ostream & RsTlvParamRef<const uint32_t>::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printIndent(out, indent);
|
||||
out << "Type: " << mParamType << "Param: " << mParam;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
/***** std::string ****/
|
||||
template<>
|
||||
uint32_t RsTlvParamRef<std::string>::TlvSize()
|
||||
{
|
||||
return GetTlvStringSize(mParam);
|
||||
}
|
||||
|
||||
template<>
|
||||
void RsTlvParamRef<std::string>::TlvClear()
|
||||
{
|
||||
mParam.clear();
|
||||
}
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<std::string>::SetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
return SetTlvString(data, size, offset, mParamType, mParam);
|
||||
}
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<std::string>::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
return GetTlvString(data, size, offset, mParamType, mParam);
|
||||
}
|
||||
|
||||
template<>
|
||||
std::ostream & RsTlvParamRef<std::string>::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printIndent(out, indent);
|
||||
out << "Type: " << mParamType << "Param: " << mParam;
|
||||
return out;
|
||||
}
|
||||
|
||||
// declare likely combinations.
|
||||
//template class RsTlvParamRef<uint16_t>;
|
||||
//template class RsTlvParamRef<uint32_t>;
|
||||
//template class RsTlvParamRef<std::string>;
|
||||
|
||||
//template class RsTlvParamRef<const uint16_t>;
|
||||
//template class RsTlvParamRef<const uint32_t>;
|
||||
//template class RsTlvParamRef<const std::string>;
|
||||
|
59
libretroshare/src/serialiser/rstlvgenericparam.h
Normal file
59
libretroshare/src/serialiser/rstlvgenericparam.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
#ifndef RS_TLV_GENERIC_PARAM_H
|
||||
#define RS_TLV_GENERIC_PARAM_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvgenericparam.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.1 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/rstlvtypes.h"
|
||||
#include <map>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
/**** TLV *****
|
||||
* Generic Parameters / Maps.
|
||||
*/
|
||||
|
||||
|
||||
template<class T>
|
||||
class RsTlvParamRef: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvParamRef(uint16_t param_type, T &p): mParamType(param_type), mParam(p) {}
|
||||
virtual ~RsTlvParamRef() { 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);
|
||||
|
||||
uint16_t mParamType;
|
||||
T &mParam;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -64,6 +64,7 @@ std::ostream &printEnd(std::ostream &out, std::string clsName, uint16_t indent);
|
|||
|
||||
std::ostream &printIndent(std::ostream &out, uint16_t indent);
|
||||
|
||||
|
||||
//! GENERIC Binary Data TLV
|
||||
/*! Use to serialise and deserialise binary data, usually included in other compound tlvs
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue