mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@730 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
50f956a148
commit
a52c34a551
@ -26,9 +26,9 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "serialiser/rsbaseserial.h"
|
#include "../serialiser/rsbaseserial.h"
|
||||||
#include "serialiser/rsqblogitems.h"
|
#include "../serialiser/rsqblogitems.h"
|
||||||
#include "serialiser/rstlvbase.h"
|
#include "../serialiser/rstlvbase.h"
|
||||||
|
|
||||||
|
|
||||||
/************************************************************/
|
/************************************************************/
|
||||||
@ -57,159 +57,3 @@ std::ostream &RsQblogMsg::print(std::ostream &out, uint16_t indent)
|
|||||||
printIndent(out, int_Indent);
|
printIndent(out, int_Indent);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/********************************************* RsQblogProfile section ***********************************/
|
|
||||||
/********************************************* RsQblogProfile section ***********************************/
|
|
||||||
/********************************************* RsQblogProfile section ***********************************/
|
|
||||||
|
|
||||||
RsQblogProfile::~RsQblogProfile(void)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RsQblogProfile::clear()
|
|
||||||
{
|
|
||||||
timeStamp = 0;
|
|
||||||
openProfile.TlvClear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::ostream &RsQblogProfile::print(std::ostream &out, uint16_t indent)
|
|
||||||
{
|
|
||||||
printRsItemBase(out, "RsQblogProfile", indent);
|
|
||||||
uint16_t int_Indent = indent + 2;
|
|
||||||
out << "RsQblogProfile::print() : timeStamp" << timeStamp;
|
|
||||||
out << std::endl;
|
|
||||||
openProfile.print(out, int_Indent);
|
|
||||||
printRsItemEnd(out, "RsQblogProfile", indent);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t RsQblogProfileSerialiser::sizeItem(RsQblogProfile *item)
|
|
||||||
{
|
|
||||||
uint32_t s = 8; // for header size
|
|
||||||
s += 4; // time stamp
|
|
||||||
s += item->openProfile.TlvSize();
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************************/
|
|
||||||
|
|
||||||
bool RsQblogProfileSerialiser::serialiseItem(RsQblogProfile* item, void* data, uint32_t *size)
|
|
||||||
{
|
|
||||||
uint32_t tlvsize = sizeItem(item);
|
|
||||||
uint32_t offset = 0;
|
|
||||||
|
|
||||||
if (*size < tlvsize)
|
|
||||||
return false; /* not enough space */
|
|
||||||
|
|
||||||
*size = tlvsize;
|
|
||||||
|
|
||||||
bool ok = true;
|
|
||||||
|
|
||||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
|
||||||
|
|
||||||
#ifdef RSSERIAL_DEBUG
|
|
||||||
std::cerr << "RsQblogSerialiser::serialiseItem() Header: " << ok << std::endl;
|
|
||||||
std::cerr << "RsQblogSerialiser::serialiseItem() Size: " << tlvsize << std::endl;
|
|
||||||
#endif
|
|
||||||
/* skip the header */
|
|
||||||
offset += 8;
|
|
||||||
|
|
||||||
/* add mandatory part */
|
|
||||||
ok &= setRawUInt32(data, tlvsize, &offset, item->timeStamp);
|
|
||||||
ok &= item->openProfile.SetTlv(data, *size, &offset);
|
|
||||||
|
|
||||||
if (offset != tlvsize)
|
|
||||||
{
|
|
||||||
ok = false;
|
|
||||||
#ifdef RSSERIAL_DEBUG
|
|
||||||
std::cerr << "RsQblogSerialiser::serialiseItem() Size Error! " << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
return ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
RsQblogProfile* RsQblogProfileSerialiser::deserialiseItem(void * data, uint32_t *size)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* 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)) ||
|
|
||||||
(RS_SERVICE_TYPE_QBLOG != getRsItemService(rstype)) ||
|
|
||||||
(RS_PKT_SUBTYPE_QBLOG_PROFILE != getRsItemSubType(rstype)))
|
|
||||||
{
|
|
||||||
return NULL; /* wrong type */
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*size < rssize) /* check size */
|
|
||||||
return NULL; /* not enough data */
|
|
||||||
|
|
||||||
/* set the packet length */
|
|
||||||
*size = rssize;
|
|
||||||
|
|
||||||
bool ok = true;
|
|
||||||
|
|
||||||
/* ready to load */
|
|
||||||
RsQblogProfile *item = new RsQblogProfile();
|
|
||||||
item->clear();
|
|
||||||
|
|
||||||
/* skip the header */
|
|
||||||
offset += 8;
|
|
||||||
|
|
||||||
/* get mandatory parts first */
|
|
||||||
RsTlvKeyValueWideSet* kvSetOpen;
|
|
||||||
|
|
||||||
ok &= getRawUInt32(data, rssize, &offset, &(item->timeStamp));
|
|
||||||
ok &= kvSetOpen->GetTlv(data, *size, &offset);
|
|
||||||
|
|
||||||
/* copy over deserialised files */
|
|
||||||
|
|
||||||
item->openProfile = *kvSetOpen;
|
|
||||||
|
|
||||||
if (offset != rssize)
|
|
||||||
{
|
|
||||||
/* error, improper item */
|
|
||||||
delete item;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ok)
|
|
||||||
{
|
|
||||||
delete item;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*********************************************************************/
|
|
||||||
|
|
||||||
bool RsQblogProfileSerialiser::serialise(RsItem *item, void* data, uint32_t* size)
|
|
||||||
{
|
|
||||||
return serialiseItem((RsQblogProfile *) item, data, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
RsItem* RsQblogProfileSerialiser::deserialise(void* data, uint32_t* size)
|
|
||||||
{
|
|
||||||
return deserialiseItem(data, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t RsQblogProfileSerialiser::size(RsItem *item)
|
|
||||||
{
|
|
||||||
return sizeItem((RsQblogProfile *) item);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,13 +30,10 @@
|
|||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "serialiser/rsserviceids.h"
|
#include "../serialiser/rsserviceids.h"
|
||||||
#include "serialiser/rsserial.h"
|
#include "../serialiser/rsserial.h"
|
||||||
#include "serialiser/rsmsgitems.h"
|
#include "../serialiser/rsmsgitems.h"
|
||||||
#include "serialiser/rstlvkvwide.h"
|
#include "../serialiser/rstlvkvwide.h"
|
||||||
|
|
||||||
|
|
||||||
const uint8_t RS_PKT_SUBTYPE_QBLOG_PROFILE = 0x01;
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -56,29 +53,6 @@ std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
|
||||||
* retroshare qblog profile item for storing received and sent profile info
|
|
||||||
* designed in an open ended way to accomodate multiple fields
|
|
||||||
*/
|
|
||||||
class RsQblogProfile: public RsItem
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
RsQblogProfile()
|
|
||||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_QBLOG, // add profile id type
|
|
||||||
RS_PKT_SUBTYPE_QBLOG_PROFILE)
|
|
||||||
{ return; }
|
|
||||||
virtual ~RsQblogProfile();
|
|
||||||
virtual void clear();
|
|
||||||
|
|
||||||
/// inherited method from RsItem
|
|
||||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
|
||||||
|
|
||||||
uint32_t timeStamp;
|
|
||||||
|
|
||||||
/// contains various profile information set by user, this and below use an open ended format
|
|
||||||
RsTlvKeyValueWideSet openProfile;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* to serialise rsQblogItems: method names are self explanatory
|
* to serialise rsQblogItems: method names are self explanatory
|
||||||
@ -95,47 +69,5 @@ virtual ~RsQblogMsgSerialiser()
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
|
||||||
* to serialise rsQblogProfile items, method names are self explanatory
|
|
||||||
*/
|
|
||||||
class RsQblogProfileSerialiser : public RsSerialType
|
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
RsQblogProfileSerialiser()
|
|
||||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_QBLOG)
|
|
||||||
{ return; }
|
|
||||||
virtual ~RsQblogProfileSerialiser()
|
|
||||||
{ return; }
|
|
||||||
/**
|
|
||||||
* check size of RsItem to be serialised
|
|
||||||
* @param RsItem RsItem which is going to be serilised
|
|
||||||
* @return size of the RsItem
|
|
||||||
*/
|
|
||||||
virtual uint32_t size(RsItem *);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* serialise contents of item to data
|
|
||||||
* @param item RsItem which is going to be serilised
|
|
||||||
* @param data where contents will be serialised into
|
|
||||||
* @return size of the RsItem in bytes
|
|
||||||
*/
|
|
||||||
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* serialise contents of item to data
|
|
||||||
* @param data where contents will be deserialisedout of
|
|
||||||
* @return size of the RsItem in bytes
|
|
||||||
*/
|
|
||||||
virtual RsItem * deserialise(void *data, uint32_t *size);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
|
|
||||||
virtual uint32_t sizeItem(RsQblogProfile *);
|
|
||||||
virtual bool serialiseItem (RsQblogProfile *item, void *data, uint32_t *size);
|
|
||||||
virtual RsQblogProfile *deserialiseItem(void *data, uint32_t *size);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /*RSQBLOGITEM_H_*/
|
#endif /*RSQBLOGITEM_H_*/
|
||||||
|
Loading…
Reference in New Issue
Block a user