2007-11-15 23:45:00 -05:00
|
|
|
#ifndef RS_BASE_ITEMS_H
|
|
|
|
#define RS_BASE_ITEMS_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* libretroshare/src/serialiser: rsbaseitems.h
|
|
|
|
*
|
|
|
|
* RetroShare Serialiser.
|
|
|
|
*
|
|
|
|
* 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 <map>
|
|
|
|
|
|
|
|
#include "serialiser/rsserial.h"
|
|
|
|
#include "serialiser/rstlvtypes.h"
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
const uint8_t RS_PKT_TYPE_FILE = 0x01;
|
|
|
|
const uint8_t RS_PKT_TYPE_CACHE = 0x02;
|
|
|
|
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_FI_REQUEST = 0x01;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_FI_DATA = 0x02;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_FI_TRANSFER = 0x03;
|
|
|
|
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_CACHE_ITEM = 0x01;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_CACHE_REQUEST = 0x02;
|
2007-11-15 23:45:00 -05:00
|
|
|
|
|
|
|
/**************************************************************************/
|
2007-12-11 19:54:42 -05:00
|
|
|
|
|
|
|
class RsFileRequest: public RsItem
|
2007-11-15 23:45:00 -05:00
|
|
|
{
|
|
|
|
public:
|
2007-12-11 19:54:42 -05:00
|
|
|
RsFileRequest()
|
2007-11-15 23:45:00 -05:00
|
|
|
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE,
|
2007-12-11 19:54:42 -05:00
|
|
|
RS_PKT_TYPE_FILE,
|
|
|
|
RS_PKT_SUBTYPE_FI_REQUEST)
|
2007-11-15 23:45:00 -05:00
|
|
|
{ return; }
|
2007-12-11 19:54:42 -05:00
|
|
|
virtual ~RsFileRequest();
|
2007-11-15 23:45:00 -05:00
|
|
|
virtual void clear();
|
2007-12-11 19:54:42 -05:00
|
|
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
2007-11-15 23:45:00 -05:00
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
uint64_t fileoffset; /* start of data requested */
|
|
|
|
uint32_t chunksize; /* size of data requested */
|
2007-11-15 23:45:00 -05:00
|
|
|
RsTlvFileItem file; /* file information */
|
|
|
|
};
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
class RsFileData: public RsItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RsFileData()
|
|
|
|
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE,
|
2007-12-11 19:54:42 -05:00
|
|
|
RS_PKT_TYPE_FILE,
|
|
|
|
RS_PKT_SUBTYPE_FI_DATA)
|
2007-11-15 23:45:00 -05:00
|
|
|
{ return; }
|
|
|
|
virtual ~RsFileData();
|
|
|
|
virtual void clear();
|
2007-12-11 19:54:42 -05:00
|
|
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
2007-11-15 23:45:00 -05:00
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
RsTlvFileData fd;
|
2007-11-15 23:45:00 -05:00
|
|
|
};
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
class RsFileItemSerialiser: public RsSerialType
|
2007-11-15 23:45:00 -05:00
|
|
|
{
|
|
|
|
public:
|
2007-12-11 19:54:42 -05:00
|
|
|
RsFileItemSerialiser()
|
2007-11-15 23:45:00 -05:00
|
|
|
:RsSerialType(RS_PKT_VERSION1, RS_PKT_CLASS_BASE,
|
2007-12-11 19:54:42 -05:00
|
|
|
RS_PKT_TYPE_FILE)
|
2007-11-15 23:45:00 -05:00
|
|
|
{ return; }
|
2007-12-11 19:54:42 -05:00
|
|
|
virtual ~RsFileItemSerialiser() { return; }
|
2007-11-15 23:45:00 -05:00
|
|
|
|
|
|
|
virtual uint32_t size(RsItem *);
|
|
|
|
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
|
|
|
|
virtual RsItem * deserialise(void *data, uint32_t *size);
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
private:
|
|
|
|
|
|
|
|
/* sub types */
|
|
|
|
virtual uint32_t sizeReq(RsFileRequest *);
|
|
|
|
virtual bool serialiseReq (RsFileRequest *item, void *data, uint32_t *size);
|
|
|
|
virtual RsFileRequest * deserialiseReq(void *data, uint32_t *size);
|
|
|
|
|
|
|
|
virtual uint32_t sizeData(RsFileData *);
|
|
|
|
virtual bool serialiseData (RsFileData *item, void *data, uint32_t *size);
|
|
|
|
virtual RsFileData * deserialiseData(void *data, uint32_t *size);
|
|
|
|
|
2007-11-15 23:45:00 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
class RsCacheRequest: public RsItem
|
2007-11-15 23:45:00 -05:00
|
|
|
{
|
|
|
|
public:
|
2007-12-11 19:54:42 -05:00
|
|
|
RsCacheRequest()
|
2007-11-15 23:45:00 -05:00
|
|
|
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE,
|
2007-12-11 19:54:42 -05:00
|
|
|
RS_PKT_TYPE_CACHE,
|
|
|
|
RS_PKT_SUBTYPE_CACHE_REQUEST)
|
2007-11-15 23:45:00 -05:00
|
|
|
{ return; }
|
2007-12-11 19:54:42 -05:00
|
|
|
virtual ~RsCacheRequest();
|
2007-11-15 23:45:00 -05:00
|
|
|
virtual void clear();
|
2007-12-11 19:54:42 -05:00
|
|
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
2007-11-15 23:45:00 -05:00
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
uint16_t cacheType;
|
|
|
|
uint16_t cacheSubId;
|
|
|
|
RsTlvFileItem file; /* file information */
|
2007-11-15 23:45:00 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
class RsCacheItem: public RsItem
|
2007-11-15 23:45:00 -05:00
|
|
|
{
|
|
|
|
public:
|
2007-12-11 19:54:42 -05:00
|
|
|
RsCacheItem()
|
2007-11-15 23:45:00 -05:00
|
|
|
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE,
|
2007-12-11 19:54:42 -05:00
|
|
|
RS_PKT_TYPE_CACHE,
|
|
|
|
RS_PKT_SUBTYPE_CACHE_ITEM)
|
2007-11-15 23:45:00 -05:00
|
|
|
{ return; }
|
2007-12-11 19:54:42 -05:00
|
|
|
virtual ~RsCacheItem();
|
2007-11-15 23:45:00 -05:00
|
|
|
virtual void clear();
|
2007-12-11 19:54:42 -05:00
|
|
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
2007-11-15 23:45:00 -05:00
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
uint16_t cacheType;
|
|
|
|
uint16_t cacheSubId;
|
|
|
|
RsTlvFileItem file; /* file information */
|
2007-11-15 23:45:00 -05:00
|
|
|
};
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
class RsCacheItemSerialiser: public RsSerialType
|
2007-11-15 23:45:00 -05:00
|
|
|
{
|
|
|
|
public:
|
2007-12-11 19:54:42 -05:00
|
|
|
RsCacheItemSerialiser()
|
2007-11-15 23:45:00 -05:00
|
|
|
:RsSerialType(RS_PKT_VERSION1, RS_PKT_CLASS_BASE,
|
2007-12-11 19:54:42 -05:00
|
|
|
RS_PKT_TYPE_CACHE)
|
2007-11-15 23:45:00 -05:00
|
|
|
{ return; }
|
2007-12-11 19:54:42 -05:00
|
|
|
virtual ~RsCacheItemSerialiser() { return; }
|
2007-11-15 23:45:00 -05:00
|
|
|
|
|
|
|
virtual uint32_t size(RsItem *);
|
|
|
|
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
|
|
|
|
virtual RsItem * deserialise(void *data, uint32_t *size);
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
private:
|
2007-11-15 23:45:00 -05:00
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
/* sub types */
|
|
|
|
virtual uint32_t sizeReq(RsCacheRequest *);
|
|
|
|
virtual bool serialiseReq (RsCacheRequest *item, void *data, uint32_t *size);
|
|
|
|
virtual RsCacheRequest * deserialiseReq(void *data, uint32_t *size);
|
2007-11-15 23:45:00 -05:00
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
virtual uint32_t sizeItem(RsCacheItem *);
|
|
|
|
virtual bool serialiseItem (RsCacheItem *item, void *data, uint32_t *size);
|
|
|
|
virtual RsCacheItem * deserialiseItem(void *data, uint32_t *size);
|
2007-11-15 23:45:00 -05:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
class RsServiceSerialiser: public RsSerialType
|
2007-11-15 23:45:00 -05:00
|
|
|
{
|
|
|
|
public:
|
2007-12-11 19:54:42 -05:00
|
|
|
RsServiceSerialiser()
|
|
|
|
:RsSerialType(RS_PKT_VERSION_SERVICE, 0, 0)
|
|
|
|
{ return; }
|
|
|
|
virtual ~RsServiceSerialiser()
|
2007-11-15 23:45:00 -05:00
|
|
|
{ return; }
|
|
|
|
|
|
|
|
virtual uint32_t size(RsItem *);
|
|
|
|
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
|
|
|
|
virtual RsItem * deserialise(void *data, uint32_t *size);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|