mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-19 11:54:22 -04:00
Merge branch 'master' into gxs_mail_experiments
This commit is contained in:
commit
5159e326c7
335 changed files with 12307 additions and 24670 deletions
121
libretroshare/src/rsitems/itempriorities.h
Normal file
121
libretroshare/src/rsitems/itempriorities.h
Normal file
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: itempriorities.h
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2011-2011 by Cyril Soler
|
||||
*
|
||||
* 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 "csoler@users.sourceforge.net"
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// This file centralises QoS priorities for all transfer RsItems.
|
||||
//
|
||||
const uint8_t QOS_PRIORITY_UNKNOWN = 0 ;
|
||||
const uint8_t QOS_PRIORITY_DEFAULT = 3 ;
|
||||
const uint8_t QOS_PRIORITY_TOP = 9 ;
|
||||
|
||||
// Turtle traffic
|
||||
//
|
||||
const uint8_t QOS_PRIORITY_RS_TURTLE_OPEN_TUNNEL = 6 ;
|
||||
const uint8_t QOS_PRIORITY_RS_TURTLE_TUNNEL_OK = 6 ;
|
||||
const uint8_t QOS_PRIORITY_RS_TURTLE_SEARCH_REQUEST = 6 ;
|
||||
const uint8_t QOS_PRIORITY_RS_TURTLE_FILE_REQUEST = 5 ;
|
||||
const uint8_t QOS_PRIORITY_RS_TURTLE_FILE_CRC_REQUEST = 5 ;
|
||||
const uint8_t QOS_PRIORITY_RS_TURTLE_CHUNK_CRC_REQUEST= 5 ;
|
||||
const uint8_t QOS_PRIORITY_RS_TURTLE_FILE_MAP_REQUEST = 5 ;
|
||||
const uint8_t QOS_PRIORITY_RS_TURTLE_SEARCH_RESULT = 3 ;
|
||||
const uint8_t QOS_PRIORITY_RS_TURTLE_FILE_DATA = 3 ;
|
||||
const uint8_t QOS_PRIORITY_RS_TURTLE_FILE_CRC = 3 ;
|
||||
const uint8_t QOS_PRIORITY_RS_TURTLE_CHUNK_CRC = 5 ;
|
||||
const uint8_t QOS_PRIORITY_RS_TURTLE_FILE_MAP = 3 ;
|
||||
const uint8_t QOS_PRIORITY_RS_TURTLE_GENERIC_ITEM = 3 ;
|
||||
const uint8_t QOS_PRIORITY_RS_TURTLE_FORWARD_FILE_DATA= 3 ;
|
||||
const uint8_t QOS_PRIORITY_RS_TURTLE_GENERIC_DATA = 5 ;
|
||||
|
||||
// File transfer
|
||||
//
|
||||
const uint8_t QOS_PRIORITY_RS_FILE_REQUEST = 5 ;
|
||||
const uint8_t QOS_PRIORITY_RS_FILE_CRC_REQUEST = 5 ;
|
||||
const uint8_t QOS_PRIORITY_RS_CHUNK_CRC_REQUEST = 5 ;
|
||||
const uint8_t QOS_PRIORITY_RS_FILE_MAP_REQUEST = 5 ;
|
||||
const uint8_t QOS_PRIORITY_RS_CACHE_REQUEST = 4 ;
|
||||
const uint8_t QOS_PRIORITY_RS_FILE_DATA = 3 ;
|
||||
const uint8_t QOS_PRIORITY_RS_FILE_CRC = 3 ;
|
||||
const uint8_t QOS_PRIORITY_RS_CHUNK_CRC = 5 ;
|
||||
const uint8_t QOS_PRIORITY_RS_FILE_MAP = 3 ;
|
||||
const uint8_t QOS_PRIORITY_RS_CACHE_ITEM = 3 ;
|
||||
|
||||
// Discovery
|
||||
//
|
||||
const uint8_t QOS_PRIORITY_RS_DISC_HEART_BEAT = 8 ;
|
||||
const uint8_t QOS_PRIORITY_RS_DISC_ASK_INFO = 2 ;
|
||||
const uint8_t QOS_PRIORITY_RS_DISC_REPLY = 1 ;
|
||||
const uint8_t QOS_PRIORITY_RS_DISC_VERSION = 1 ;
|
||||
|
||||
const uint8_t QOS_PRIORITY_RS_DISC_CONTACT = 2 ; // CONTACT and PGPLIST must have
|
||||
const uint8_t QOS_PRIORITY_RS_DISC_PGP_LIST = 2 ; // same priority.
|
||||
const uint8_t QOS_PRIORITY_RS_DISC_SERVICES = 2 ;
|
||||
const uint8_t QOS_PRIORITY_RS_DISC_PGP_CERT = 1 ;
|
||||
|
||||
// File database
|
||||
//
|
||||
const uint8_t QOS_PRIORITY_RS_FAST_SYNC_REQUEST = 7 ;
|
||||
const uint8_t QOS_PRIORITY_RS_SLOW_SYNC_REQUEST = 3 ;
|
||||
|
||||
// Heartbeat.
|
||||
//
|
||||
const uint8_t QOS_PRIORITY_RS_HEARTBEAT_PULSE = 8 ;
|
||||
|
||||
// Chat/Msgs
|
||||
//
|
||||
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 ; // depreciated.
|
||||
const uint8_t QOS_PRIORITY_RS_MAIL_ITEM = 2 ; // new mail service
|
||||
const uint8_t QOS_PRIORITY_RS_STATUS_ITEM = 2 ;
|
||||
|
||||
// RTT
|
||||
//
|
||||
const uint8_t QOS_PRIORITY_RS_RTT_PING = 9 ;
|
||||
|
||||
// BanList
|
||||
//
|
||||
const uint8_t QOS_PRIORITY_RS_BANLIST_ITEM = 2 ;
|
||||
|
||||
// Bandwidth Control.
|
||||
//
|
||||
const uint8_t QOS_PRIORITY_RS_BWCTRL_ALLOWED_ITEM = 9 ;
|
||||
|
||||
// Dsdv Routing
|
||||
//
|
||||
const uint8_t QOS_PRIORITY_RS_DSDV_ROUTE = 4 ;
|
||||
const uint8_t QOS_PRIORITY_RS_DSDV_DATA = 2 ;
|
||||
|
||||
// GXS
|
||||
//
|
||||
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;
|
||||
|
71
libretroshare/src/rsitems/rsbanlistitems.cc
Normal file
71
libretroshare/src/rsitems/rsbanlistitems.cc
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsbanlist.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2011 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/rsbaseserial.h"
|
||||
#include "rsitems/rsbanlistitems.h"
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
void RsBanListItem::clear()
|
||||
{
|
||||
peerList.TlvClear();
|
||||
}
|
||||
|
||||
void RsBanListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,peerList,"peerList") ;
|
||||
}
|
||||
|
||||
void RsBanListConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,type,"type") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ;
|
||||
RsTypeSerializer::serial_process<time_t> (j,ctx,update_time,"update_time") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,banned_peers,"banned_peers") ;
|
||||
}
|
||||
RsItem *RsBanListSerialiser::create_item(uint16_t service_id,uint8_t item_sub_id) const
|
||||
{
|
||||
if(service_id != RS_SERVICE_TYPE_BANLIST)
|
||||
return NULL ;
|
||||
|
||||
switch(item_sub_id)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM: return new RsBanListConfigItem ;
|
||||
case RS_PKT_SUBTYPE_BANLIST_ITEM: return new RsBanListItem ;
|
||||
default:
|
||||
std::cerr << "(EE) unknown item subtype " << (int)item_sub_id << " in RsBanListSerialiser::create_item()" << std::endl;
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
|
89
libretroshare/src/rsitems/rsbanlistitems.h
Normal file
89
libretroshare/src/rsitems/rsbanlistitems.h
Normal file
|
@ -0,0 +1,89 @@
|
|||
#ifndef RS_BANLIST_ITEMS_H
|
||||
#define RS_BANLIST_ITEMS_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsbanlistitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2011 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 "rsitems/rsserviceids.h"
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
#include "serialiser/rstlvbanlist.h"
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
#define RS_PKT_SUBTYPE_BANLIST_ITEM_deprecated 0x01
|
||||
#define RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM_deprecated 0x02
|
||||
#define RS_PKT_SUBTYPE_BANLIST_ITEM 0x03
|
||||
#define RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM 0x04
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
class RsBanListItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsBanListItem() :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_BANLIST, RS_PKT_SUBTYPE_BANLIST_ITEM)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_BANLIST_ITEM);
|
||||
return;
|
||||
}
|
||||
|
||||
virtual ~RsBanListItem(){}
|
||||
virtual void clear();
|
||||
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsTlvBanList peerList;
|
||||
};
|
||||
|
||||
class RsBanListConfigItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsBanListConfigItem()
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_BANLIST, RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM) {}
|
||||
|
||||
virtual ~RsBanListConfigItem(){}
|
||||
virtual void clear() { banned_peers.TlvClear() ; }
|
||||
|
||||
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
uint32_t type ;
|
||||
RsPeerId peerId ;
|
||||
time_t update_time ;
|
||||
RsTlvBanList banned_peers;
|
||||
};
|
||||
|
||||
class RsBanListSerialiser: public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
RsBanListSerialiser() :RsServiceSerializer(RS_SERVICE_TYPE_BANLIST) {}
|
||||
|
||||
virtual RsItem *create_item(uint16_t service_id,uint8_t item_sub_id) const ;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#endif /* RS_BANLIST_ITEMS_H */
|
||||
|
||||
|
61
libretroshare/src/rsitems/rsbwctrlitems.cc
Normal file
61
libretroshare/src/rsitems/rsbwctrlitems.cc
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsbwctrlitems.cc
|
||||
*
|
||||
* 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "rsitems/rsbwctrlitems.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsItem *RsBwCtrlSerialiser::create_item(uint16_t service, uint8_t item_sub_id) const
|
||||
{
|
||||
if(service != RS_SERVICE_TYPE_BWCTRL)
|
||||
return NULL ;
|
||||
|
||||
switch(item_sub_id)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_BWCTRL_ALLOWED_ITEM: return new RsBwCtrlAllowedItem();
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void RsBwCtrlAllowedItem::clear()
|
||||
{
|
||||
allowedBw = 0;
|
||||
}
|
||||
|
||||
void RsBwCtrlAllowedItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,TLV_TYPE_UINT32_BW,allowedBw,"allowedBw") ;
|
||||
}
|
||||
|
||||
|
||||
|
72
libretroshare/src/rsitems/rsbwctrlitems.h
Normal file
72
libretroshare/src/rsitems/rsbwctrlitems.h
Normal file
|
@ -0,0 +1,72 @@
|
|||
#ifndef RS_BANDWIDTH_CONTROL_ITEMS_H
|
||||
#define RS_BANDWIDTH_CONTROL_ITEMS_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsbwctrlitems.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".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
|
||||
#include "serialiser/rsserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
#define RS_PKT_SUBTYPE_BWCTRL_ALLOWED_ITEM 0x01
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
class RsBwCtrlAllowedItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsBwCtrlAllowedItem() :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_BWCTRL, RS_PKT_SUBTYPE_BWCTRL_ALLOWED_ITEM)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_BWCTRL_ALLOWED_ITEM);
|
||||
return;
|
||||
}
|
||||
|
||||
virtual ~RsBwCtrlAllowedItem() {}
|
||||
virtual void clear();
|
||||
|
||||
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
uint32_t allowedBw; // Units are bytes/sec => 4Gb/s;
|
||||
};
|
||||
|
||||
|
||||
class RsBwCtrlSerialiser: public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
RsBwCtrlSerialiser() :RsServiceSerializer(RS_SERVICE_TYPE_BWCTRL) {}
|
||||
virtual ~RsBwCtrlSerialiser() {}
|
||||
|
||||
RsItem *create_item(uint16_t /* service */, uint8_t /* item_sub_id */) const;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#endif /* RS_BANDWIDTH_CONTROL_ITEMS_H */
|
||||
|
268
libretroshare/src/rsitems/rsconfigitems.cc
Normal file
268
libretroshare/src/rsitems/rsconfigitems.cc
Normal file
|
@ -0,0 +1,268 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsconfigitems.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Robert Fernie, Chris Parker.
|
||||
*
|
||||
* 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/rsbaseserial.h"
|
||||
#include "rsitems/rsconfigitems.h"
|
||||
#include "retroshare/rspeers.h" // Needed for RsGroupInfo.
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
/***
|
||||
* #define RSSERIAL_DEBUG 1
|
||||
* #define RSSERIAL_ERROR_DEBUG 1
|
||||
***/
|
||||
|
||||
#define RSSERIAL_ERROR_DEBUG 1
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsItem *RsFileConfigSerialiser::create_item(uint8_t item_type,uint8_t item_subtype) const
|
||||
{
|
||||
if(item_type != RS_PKT_TYPE_FILE_CONFIG)
|
||||
return NULL ;
|
||||
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_FILE_TRANSFER: return new RsFileTransfer() ;
|
||||
case RS_PKT_SUBTYPE_FILE_ITEM: return new RsFileConfigItem() ;
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
void RsFileTransfer::clear()
|
||||
{
|
||||
|
||||
file.TlvClear();
|
||||
allPeerIds.TlvClear();
|
||||
cPeerId.clear() ;
|
||||
state = 0;
|
||||
in = false;
|
||||
transferred = 0;
|
||||
crate = 0;
|
||||
trate = 0;
|
||||
lrate = 0;
|
||||
ltransfer = 0;
|
||||
|
||||
}
|
||||
|
||||
void RsFileTransfer::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,file,"file") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,allPeerIds,"allPeerIds") ;
|
||||
|
||||
RsTypeSerializer::serial_process (j,ctx,cPeerId,"cPeerId") ;
|
||||
|
||||
RsTypeSerializer::serial_process<uint16_t> (j,ctx,state,"state") ;
|
||||
RsTypeSerializer::serial_process<uint16_t> (j,ctx,in,"in") ;
|
||||
|
||||
RsTypeSerializer::serial_process<uint64_t> (j,ctx,transferred,"transferred") ;
|
||||
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,crate,"crate") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,trate,"trate") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,lrate,"lrate") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,ltransfer,"ltransfer") ;
|
||||
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,flags,"flags") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,chunk_strategy,"chunk_strategy") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,compressed_chunk_map,"compressed_chunk_map") ;
|
||||
}
|
||||
|
||||
void RsFileConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,file,"file") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,flags,"flags") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,parent_groups,"parent_groups") ;
|
||||
}
|
||||
|
||||
RsItem *RsGeneralConfigSerialiser::create_item(uint8_t item_type,uint8_t item_subtype) const
|
||||
{
|
||||
if(item_type != RS_PKT_TYPE_GENERAL_CONFIG)
|
||||
return NULL ;
|
||||
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_KEY_VALUE: return new RsConfigKeyValueSet();
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
void RsConfigKeyValueSet::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,tlvkvs,"tlvkvs") ;
|
||||
}
|
||||
|
||||
RsItem *RsPeerConfigSerialiser::create_item(uint8_t item_type,uint8_t item_subtype) const
|
||||
{
|
||||
if(item_type != RS_PKT_TYPE_PEER_CONFIG)
|
||||
return NULL ;
|
||||
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_PEER_NET: return new RsPeerNetItem();
|
||||
case RS_PKT_SUBTYPE_PEER_STUN: return new RsPeerStunItem();
|
||||
case RS_PKT_SUBTYPE_NODE_GROUP: return new RsNodeGroupItem() ;
|
||||
case RS_PKT_SUBTYPE_PEER_PERMISSIONS: return new RsPeerServicePermissionItem();
|
||||
case RS_PKT_SUBTYPE_PEER_BANDLIMITS: return new RsPeerBandwidthLimitsItem();
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
void RsPeerNetItem::clear()
|
||||
{
|
||||
peerId.clear();
|
||||
pgpId.clear();
|
||||
location.clear();
|
||||
netMode = 0;
|
||||
vs_disc = 0;
|
||||
vs_dht = 0;
|
||||
lastContact = 0;
|
||||
|
||||
localAddrV4.TlvClear();
|
||||
extAddrV4.TlvClear();
|
||||
localAddrV6.TlvClear();
|
||||
extAddrV6.TlvClear();
|
||||
|
||||
dyndns.clear();
|
||||
|
||||
localAddrList.TlvClear();
|
||||
extAddrList.TlvClear();
|
||||
|
||||
domain_addr.clear();
|
||||
domain_port = 0;
|
||||
}
|
||||
void RsPeerNetItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,peerId,"peerId") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,pgpId,"pgpId") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_LOCATION,location,"location") ;
|
||||
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,netMode,"netMode") ;
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,vs_disc,"vs_disc") ;
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,vs_dht,"vs_dht") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,lastContact,"lastContact") ;
|
||||
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,localAddrV4,"localAddrV4") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,extAddrV4,"extAddrV4") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,localAddrV6,"localAddrV6") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,extAddrV6,"extAddrV6") ;
|
||||
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DYNDNS,dyndns,"dyndns") ;
|
||||
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,localAddrList,"localAddrList") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,extAddrList,"extAddrList") ;
|
||||
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DOMADDR,domain_addr,"domain_addr") ;
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,domain_port,"domain_port") ;
|
||||
}
|
||||
|
||||
void RsPeerBandwidthLimitsItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,peers,"peers") ;
|
||||
}
|
||||
|
||||
void RsPeerStunItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,stunList,"stunList") ;
|
||||
}
|
||||
|
||||
template<> uint32_t RsTypeSerializer::serial_size(const PeerBandwidthLimits& s)
|
||||
{
|
||||
return 4+4 ;
|
||||
}
|
||||
|
||||
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset,const PeerBandwidthLimits& s)
|
||||
{
|
||||
bool ok = true ;
|
||||
ok = ok && setRawUInt32(data,size,&offset,s.max_up_rate_kbs);
|
||||
ok = ok && setRawUInt32(data,size,&offset,s.max_dl_rate_kbs);
|
||||
return ok;
|
||||
}
|
||||
|
||||
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,PeerBandwidthLimits& s)
|
||||
{
|
||||
bool ok = true ;
|
||||
ok = ok && getRawUInt32(data,size,&offset,&s.max_up_rate_kbs);
|
||||
ok = ok && getRawUInt32(data,size,&offset,&s.max_dl_rate_kbs);
|
||||
return ok;
|
||||
}
|
||||
|
||||
template<> void RsTypeSerializer::print_data(const std::string& n, const PeerBandwidthLimits& s)
|
||||
{
|
||||
std::cerr << " [Peer BW limit] " << s.max_up_rate_kbs << " / " << s.max_dl_rate_kbs << std::endl;
|
||||
}
|
||||
|
||||
RsNodeGroupItem::RsNodeGroupItem(const RsGroupInfo& g)
|
||||
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_NODE_GROUP)
|
||||
{
|
||||
id = g.id ;
|
||||
name = g.name ;
|
||||
flag = g.flag ;
|
||||
pgpList.ids = g.peerIds;
|
||||
}
|
||||
|
||||
void RsNodeGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
uint32_t v=0 ;
|
||||
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,v,"dummy field 0") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,id,"id") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,name,"name") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,flag,"flag") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,pgpList,"pgpList") ;
|
||||
}
|
||||
|
||||
void RsPeerServicePermissionItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
// We need to hack this because of backward compatibility. The correct way to do it would be:
|
||||
//
|
||||
// RsTypeSerializer::serial_process(j,ctx,pgp_ids,"pgp_ids") ;
|
||||
// RsTypeSerializer::serial_process(j,ctx,service_flags,"service_flags") ;
|
||||
|
||||
if(j == RsGenericSerializer::DESERIALIZE)
|
||||
{
|
||||
uint32_t v=0 ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,v,"pgp_ids.size()") ;
|
||||
|
||||
pgp_ids.resize(v) ;
|
||||
service_flags.resize(v) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t s = pgp_ids.size();
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,s,"pgp_ids.size()") ;
|
||||
}
|
||||
|
||||
for(uint32_t i=0;i<pgp_ids.size();++i)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,pgp_ids[i],"pgp_ids[i]") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,service_flags[i],"service_flags[i]") ;
|
||||
}
|
||||
}
|
||||
|
289
libretroshare/src/rsitems/rsconfigitems.h
Normal file
289
libretroshare/src/rsitems/rsconfigitems.h
Normal file
|
@ -0,0 +1,289 @@
|
|||
#ifndef RS_CONFIG_ITEMS_SERIALISER_H
|
||||
#define RS_CONFIG_ITEMS_SERIALISER_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsconfigitems.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 <vector>
|
||||
|
||||
#include "rsitems/rsitem.h"
|
||||
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "serialiser/rstlvfileitem.h"
|
||||
#include "serialiser/rstlvkeyvalue.h"
|
||||
#include "serialiser/rstlvaddrs.h"
|
||||
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
class RsGroupInfo;
|
||||
|
||||
const uint8_t RS_PKT_TYPE_GENERAL_CONFIG = 0x01;
|
||||
const uint8_t RS_PKT_TYPE_PEER_CONFIG = 0x02;
|
||||
const uint8_t RS_PKT_TYPE_CACHE_CONFIG = 0x03;
|
||||
const uint8_t RS_PKT_TYPE_FILE_CONFIG = 0x04;
|
||||
const uint8_t RS_PKT_TYPE_PLUGIN_CONFIG = 0x05;
|
||||
const uint8_t RS_PKT_TYPE_HISTORY_CONFIG = 0x06;
|
||||
|
||||
/* GENERAL CONFIG SUBTYPES */
|
||||
const uint8_t RS_PKT_SUBTYPE_KEY_VALUE = 0x01;
|
||||
|
||||
/* PEER CONFIG SUBTYPES */
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_STUN = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_NET = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_GROUP_deprecated = 0x04;
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_PERMISSIONS = 0x05;
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_BANDLIMITS = 0x06;
|
||||
const uint8_t RS_PKT_SUBTYPE_NODE_GROUP = 0x07;
|
||||
|
||||
/* FILE CONFIG SUBTYPES */
|
||||
const uint8_t RS_PKT_SUBTYPE_FILE_TRANSFER = 0x01;
|
||||
const uint8_t RS_PKT_SUBTYPE_FILE_ITEM_deprecated = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_FILE_ITEM = 0x03;
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
class RsPeerNetItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsPeerNetItem()
|
||||
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
|
||||
RS_PKT_TYPE_PEER_CONFIG,
|
||||
RS_PKT_SUBTYPE_PEER_NET) {}
|
||||
|
||||
virtual ~RsPeerNetItem(){}
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
/* networking information */
|
||||
RsPeerId peerId; /* Mandatory */
|
||||
RsPgpId pgpId; /* Mandatory */
|
||||
std::string location; /* Mandatory */
|
||||
uint32_t netMode; /* Mandatory */
|
||||
uint16_t vs_disc; /* Mandatory */
|
||||
uint16_t vs_dht; /* Mandatory */
|
||||
uint32_t lastContact; /* Mandatory */
|
||||
|
||||
RsTlvIpAddress localAddrV4; /* Mandatory */
|
||||
RsTlvIpAddress extAddrV4; /* Mandatory */
|
||||
RsTlvIpAddress localAddrV6; /* Mandatory */
|
||||
RsTlvIpAddress extAddrV6; /* Mandatory */
|
||||
|
||||
std::string dyndns;
|
||||
|
||||
RsTlvIpAddrSet localAddrList;
|
||||
RsTlvIpAddrSet extAddrList;
|
||||
|
||||
// for proxy connection.
|
||||
std::string domain_addr;
|
||||
uint16_t domain_port;
|
||||
};
|
||||
|
||||
// This item should be merged with the next item, but that is not backward compatible.
|
||||
class RsPeerServicePermissionItem : public RsItem
|
||||
{
|
||||
public:
|
||||
RsPeerServicePermissionItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_PEER_PERMISSIONS) {}
|
||||
virtual ~RsPeerServicePermissionItem() {}
|
||||
|
||||
virtual void clear()
|
||||
{
|
||||
pgp_ids.clear() ;
|
||||
service_flags.clear() ;
|
||||
}
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
|
||||
/* Mandatory */
|
||||
std::vector<RsPgpId> pgp_ids ;
|
||||
std::vector<ServicePermissionFlags> service_flags ;
|
||||
};
|
||||
class RsPeerBandwidthLimitsItem : public RsItem
|
||||
{
|
||||
public:
|
||||
RsPeerBandwidthLimitsItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_PEER_BANDLIMITS) {}
|
||||
virtual ~RsPeerBandwidthLimitsItem() {}
|
||||
|
||||
virtual void clear()
|
||||
{
|
||||
peers.clear() ;
|
||||
}
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
/* Mandatory */
|
||||
std::map<RsPgpId,PeerBandwidthLimits> peers ;
|
||||
};
|
||||
|
||||
class RsNodeGroupItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsNodeGroupItem(): RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_NODE_GROUP){}
|
||||
virtual ~RsNodeGroupItem() {}
|
||||
|
||||
virtual void clear() { pgpList.TlvClear();}
|
||||
|
||||
explicit RsNodeGroupItem(const RsGroupInfo&) ;
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
// /* set data from RsGroupInfo to RsPeerGroupItem */
|
||||
// void set(RsGroupInfo &groupInfo);
|
||||
// /* get data from RsGroupInfo to RsPeerGroupItem */
|
||||
// void get(RsGroupInfo &groupInfo);
|
||||
|
||||
/* Mandatory */
|
||||
RsNodeGroupId id;
|
||||
std::string name;
|
||||
uint32_t flag;
|
||||
|
||||
RsTlvPgpIdSet pgpList;
|
||||
};
|
||||
|
||||
class RsPeerStunItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsPeerStunItem()
|
||||
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
|
||||
RS_PKT_TYPE_PEER_CONFIG,
|
||||
RS_PKT_SUBTYPE_PEER_STUN) {}
|
||||
virtual ~RsPeerStunItem(){}
|
||||
virtual void clear() { stunList.TlvClear() ;}
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsTlvPeerIdSet stunList; /* Mandatory */
|
||||
};
|
||||
|
||||
class RsPeerConfigSerialiser: public RsConfigSerializer
|
||||
{
|
||||
public:
|
||||
RsPeerConfigSerialiser() :RsConfigSerializer(RS_PKT_CLASS_CONFIG,RS_PKT_TYPE_PEER_CONFIG) {}
|
||||
|
||||
virtual ~RsPeerConfigSerialiser(){}
|
||||
|
||||
virtual RsItem *create_item(uint8_t item_type, uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
class RsFileTransfer: public RsItem
|
||||
{
|
||||
public:
|
||||
RsFileTransfer() :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_FILE_CONFIG, RS_PKT_SUBTYPE_FILE_TRANSFER)
|
||||
{
|
||||
state = 0;
|
||||
in = 0;
|
||||
transferred = 0;
|
||||
crate = 0;
|
||||
trate = 0;
|
||||
lrate = 0;
|
||||
ltransfer = 0;
|
||||
flags = 0;
|
||||
chunk_strategy = 0;
|
||||
}
|
||||
virtual ~RsFileTransfer(){}
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsTlvFileItem file;
|
||||
RsTlvPeerIdSet allPeerIds;
|
||||
|
||||
RsPeerId cPeerId;
|
||||
|
||||
uint16_t state;
|
||||
uint16_t in;
|
||||
|
||||
uint64_t transferred;
|
||||
uint32_t crate;
|
||||
uint32_t trate;
|
||||
|
||||
uint32_t lrate;
|
||||
uint32_t ltransfer;
|
||||
|
||||
// chunk information
|
||||
uint32_t flags ;
|
||||
uint32_t chunk_strategy ; // strategy flags for chunks
|
||||
CompressedChunkMap compressed_chunk_map ; // chunk availability (bitwise)
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
const uint32_t RS_FILE_CONFIG_CLEANUP_DELETE = 0x0001;
|
||||
|
||||
class RsFileConfigItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsFileConfigItem() :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_FILE_CONFIG, RS_PKT_SUBTYPE_FILE_ITEM) {}
|
||||
virtual ~RsFileConfigItem() {}
|
||||
virtual void clear() { parent_groups.TlvClear(); }
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsTlvFileItem file;
|
||||
uint32_t flags;
|
||||
RsTlvNodeGroupIdSet parent_groups ;
|
||||
};
|
||||
/**************************************************************************/
|
||||
|
||||
class RsFileConfigSerialiser: public RsConfigSerializer
|
||||
{
|
||||
public:
|
||||
RsFileConfigSerialiser() :RsConfigSerializer(RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_FILE_CONFIG) { }
|
||||
virtual ~RsFileConfigSerialiser() {}
|
||||
|
||||
virtual RsItem *create_item(uint8_t item_type, uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
/* Config items that are used generally */
|
||||
|
||||
class RsConfigKeyValueSet: public RsItem
|
||||
{
|
||||
public:
|
||||
RsConfigKeyValueSet() :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_GENERAL_CONFIG, RS_PKT_SUBTYPE_KEY_VALUE) {}
|
||||
virtual ~RsConfigKeyValueSet(){}
|
||||
virtual void clear() { tlvkvs.TlvClear();}
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsTlvKeyValueSet tlvkvs;
|
||||
};
|
||||
|
||||
|
||||
class RsGeneralConfigSerialiser: public RsConfigSerializer
|
||||
{
|
||||
public:
|
||||
RsGeneralConfigSerialiser() :RsConfigSerializer(RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_GENERAL_CONFIG) {}
|
||||
|
||||
virtual RsItem *create_item(uint8_t item_type, uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
#endif /* RS_CONFIG_ITEMS_SERIALISER_H */
|
293
libretroshare/src/rsitems/rsdiscovery2items.cc
Normal file
293
libretroshare/src/rsitems/rsdiscovery2items.cc
Normal file
|
@ -0,0 +1,293 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsdiscitems.cc
|
||||
*
|
||||
* 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 "rsitems/rsdiscovery2items.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
#if 0
|
||||
|
||||
#include "rsitems/rsserviceids.h"
|
||||
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#endif
|
||||
|
||||
/***
|
||||
* #define RSSERIAL_DEBUG 1
|
||||
* #define RSSERIAL_ERROR_DEBUG 1
|
||||
***/
|
||||
|
||||
#define RSSERIAL_ERROR_DEBUG 1
|
||||
|
||||
#include <iostream>
|
||||
|
||||
RsItem *RsDiscSerialiser::create_item(uint16_t service,uint8_t item_subtype) const
|
||||
{
|
||||
if(service != RS_SERVICE_TYPE_DISC)
|
||||
return NULL ;
|
||||
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_DISC_PGP_LIST : return new RsDiscPgpListItem() ; //= 0x01;
|
||||
case RS_PKT_SUBTYPE_DISC_PGP_CERT : return new RsDiscPgpCertItem() ; //= 0x02;
|
||||
case RS_PKT_SUBTYPE_DISC_CONTACT_deprecated : return NULL ; //= 0x03;
|
||||
#if 0
|
||||
case RS_PKT_SUBTYPE_DISC_SERVICES : return new RsDiscServicesItem(); //= 0x04;
|
||||
#endif
|
||||
case RS_PKT_SUBTYPE_DISC_CONTACT : return new RsDiscContactItem(); //= 0x05;
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
void RsDiscPgpListItem::clear()
|
||||
{
|
||||
mode = DISC_PGP_LIST_MODE_NONE;
|
||||
pgpIdSet.TlvClear();
|
||||
}
|
||||
|
||||
void RsDiscPgpListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mode,"mode") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,pgpIdSet,"pgpIdSet") ;
|
||||
}
|
||||
|
||||
void RsDiscPgpCertItem::clear()
|
||||
{
|
||||
pgpId.clear();
|
||||
pgpCert.clear();
|
||||
}
|
||||
|
||||
|
||||
void RsDiscPgpCertItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,pgpId,"pgpId") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_PGPCERT,pgpCert,"pgpCert") ;
|
||||
}
|
||||
|
||||
void RsDiscContactItem::clear()
|
||||
{
|
||||
pgpId.clear();
|
||||
sslId.clear();
|
||||
|
||||
location.clear();
|
||||
version.clear();
|
||||
|
||||
netMode = 0;
|
||||
vs_disc = 0;
|
||||
vs_dht = 0;
|
||||
lastContact = 0;
|
||||
|
||||
isHidden = false;
|
||||
hiddenAddr.clear();
|
||||
hiddenPort = 0;
|
||||
|
||||
localAddrV4.TlvClear();
|
||||
extAddrV4.TlvClear();
|
||||
localAddrV6.TlvClear();
|
||||
extAddrV6.TlvClear();
|
||||
|
||||
|
||||
dyndns.clear();
|
||||
|
||||
localAddrList.TlvClear();
|
||||
extAddrList.TlvClear();
|
||||
}
|
||||
|
||||
void RsDiscContactItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,pgpId,"pgpId");
|
||||
RsTypeSerializer::serial_process (j,ctx,sslId,"sslId");
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_LOCATION,location,"location");
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_VERSION,version,"version");
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,netMode,"netMode");
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,vs_disc,"vs_disc");
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,vs_dht,"vs_dht");
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,lastContact,"lastContact");
|
||||
|
||||
// This is a hack. Normally we should have to different item types, in order to avoid this nonesense.
|
||||
|
||||
if(j == RsGenericSerializer::DESERIALIZE)
|
||||
isHidden = ( GetTlvType( &(((uint8_t *) ctx.mData)[ctx.mOffset]) )==TLV_TYPE_STR_DOMADDR);
|
||||
|
||||
if(isHidden)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_DOMADDR,hiddenAddr,"hiddenAddr");
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,hiddenPort,"hiddenPort");
|
||||
}
|
||||
else
|
||||
{
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,localAddrV4,"localAddrV4");
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx, extAddrV4,"extAddrV4");
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,localAddrV6,"localAddrV6");
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx, extAddrV6,"extAddrV6");
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,currentConnectAddress,"currentConnectAddress");
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_DYNDNS,dyndns,"dyndns");
|
||||
RsTypeSerializer::serial_process (j,ctx,localAddrList,"localAddrList");
|
||||
RsTypeSerializer::serial_process (j,ctx, extAddrList,"extAddrList");
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
#if 0
|
||||
|
||||
RsDiscServicesItem::~RsDiscServicesItem()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void RsDiscServicesItem::clear()
|
||||
{
|
||||
version.clear();
|
||||
mServiceIdMap.TlvClear();
|
||||
}
|
||||
|
||||
std::ostream &RsDiscServicesItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsDiscServicesItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "version: " << version << std::endl;
|
||||
mServiceIdMap.print(out, int_Indent);
|
||||
|
||||
printRsItemEnd(out, "RsDiscServicesItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsDiscSerialiser::sizeServices(RsDiscServicesItem *item)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += GetTlvStringSize(item->version); /* version */
|
||||
s += item->mServiceIdMap.TlvSize();
|
||||
return s;
|
||||
}
|
||||
|
||||
/* serialise the data to the buffer */
|
||||
bool RsDiscSerialiser::serialiseServices(RsDiscServicesItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
uint32_t tlvsize = sizeServices(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 << "RsDiscSerialiser::serialiseServices() Header: " << ok << std::endl;
|
||||
std::cerr << "RsDiscSerialiser::serialiseServices() Size: " << tlvsize << std::endl;
|
||||
#endif
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VERSION, item->version);
|
||||
ok &= item->mServiceIdMap.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
if (offset != tlvsize) {
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_ERROR_DEBUG
|
||||
std::cerr << "RsDiscSerialiser::serialiseServices() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsDiscServicesItem *RsDiscSerialiser::deserialiseServices(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)) ||
|
||||
(RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_DISC_PGP_LIST != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef RSSERIAL_ERROR_DEBUG
|
||||
std::cerr << "RsDiscSerialiser::deserialiseServices() Wrong Type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*pktsize < rssize) /* check size */
|
||||
{
|
||||
#ifdef RSSERIAL_ERROR_DEBUG
|
||||
std::cerr << "RsDiscSerialiser::deserialiseServices() Not Enough Space" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*pktsize = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsDiscServicesItem *item = new RsDiscServicesItem();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* get mandatory parts first */
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_VERSION, item->version);
|
||||
ok &= item->mServiceIdMap.GetTlv(data, rssize, &offset);
|
||||
|
||||
if (offset != rssize) {
|
||||
#ifdef RSSERIAL_ERROR_DEBUG
|
||||
std::cerr << "RsDiscSerialiser::deserialiseServices() offset != rssize" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
#ifdef RSSERIAL_ERROR_DEBUG
|
||||
std::cerr << "RsDiscSerialiser::deserialiseServices() ok = false" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
#endif
|
183
libretroshare/src/rsitems/rsdiscovery2items.h
Normal file
183
libretroshare/src/rsitems/rsdiscovery2items.h
Normal file
|
@ -0,0 +1,183 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsdiscitems.h
|
||||
*
|
||||
* Serialiser for RetroShare.
|
||||
*
|
||||
* Copyright 2004-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".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef RS_DISC_ITEMS_H
|
||||
#define RS_DISC_ITEMS_H
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "serialiser/rstlvaddrs.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_DISC_PGP_LIST = 0x01;
|
||||
const uint8_t RS_PKT_SUBTYPE_DISC_PGP_CERT = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_DISC_CONTACT_deprecated = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_DISC_SERVICES = 0x04;
|
||||
const uint8_t RS_PKT_SUBTYPE_DISC_CONTACT = 0x05;
|
||||
|
||||
class RsDiscItem: public RsItem
|
||||
{
|
||||
protected:
|
||||
RsDiscItem(uint8_t subtype) :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DISC, subtype) {}
|
||||
};
|
||||
|
||||
|
||||
#define DISC_PGP_LIST_MODE_NONE 0x00
|
||||
#define DISC_PGP_LIST_MODE_FRIENDS 0x01
|
||||
#define DISC_PGP_LIST_MODE_GETCERT 0x02
|
||||
|
||||
class RsDiscPgpListItem: public RsDiscItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsDiscPgpListItem()
|
||||
:RsDiscItem(RS_PKT_SUBTYPE_DISC_PGP_LIST)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_DISC_PGP_LIST);
|
||||
}
|
||||
|
||||
virtual ~RsDiscPgpListItem(){}
|
||||
|
||||
virtual void clear();
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
|
||||
|
||||
uint32_t mode;
|
||||
RsTlvPgpIdSet pgpIdSet;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class RsDiscPgpCertItem: public RsDiscItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsDiscPgpCertItem()
|
||||
:RsDiscItem(RS_PKT_SUBTYPE_DISC_PGP_CERT)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_DISC_PGP_CERT);
|
||||
}
|
||||
|
||||
virtual ~RsDiscPgpCertItem(){}
|
||||
|
||||
virtual void clear();
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
|
||||
|
||||
RsPgpId pgpId;
|
||||
std::string pgpCert;
|
||||
};
|
||||
|
||||
|
||||
class RsDiscContactItem: public RsDiscItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsDiscContactItem()
|
||||
:RsDiscItem(RS_PKT_SUBTYPE_DISC_CONTACT)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_DISC_CONTACT);
|
||||
}
|
||||
|
||||
virtual ~RsDiscContactItem() {}
|
||||
|
||||
virtual void clear();
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
|
||||
|
||||
RsPgpId pgpId;
|
||||
RsPeerId sslId;
|
||||
|
||||
// COMMON
|
||||
std::string location;
|
||||
std::string version;
|
||||
|
||||
uint32_t netMode; /* Mandatory */
|
||||
uint16_t vs_disc; /* Mandatory */
|
||||
uint16_t vs_dht; /* Mandatory */
|
||||
uint32_t lastContact;
|
||||
|
||||
bool isHidden; /* not serialised */
|
||||
|
||||
// HIDDEN.
|
||||
std::string hiddenAddr;
|
||||
uint16_t hiddenPort;
|
||||
|
||||
// STANDARD.
|
||||
|
||||
RsTlvIpAddress currentConnectAddress ; // used to check!
|
||||
|
||||
RsTlvIpAddress localAddrV4; /* Mandatory */
|
||||
RsTlvIpAddress extAddrV4; /* Mandatory */
|
||||
|
||||
RsTlvIpAddress localAddrV6; /* Mandatory */
|
||||
RsTlvIpAddress extAddrV6; /* Mandatory */
|
||||
|
||||
std::string dyndns;
|
||||
|
||||
RsTlvIpAddrSet localAddrList;
|
||||
RsTlvIpAddrSet extAddrList;
|
||||
};
|
||||
|
||||
#if 0
|
||||
class RsDiscServicesItem: public RsDiscItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsDiscServicesItem()
|
||||
:RsDiscItem(RS_PKT_SUBTYPE_DISC_SERVICES)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_DISC_SERVICES);
|
||||
}
|
||||
|
||||
virtual ~RsDiscServicesItem();
|
||||
|
||||
virtual void clear();
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
|
||||
std::string version;
|
||||
RsTlvServiceIdMap mServiceIdMap;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
class RsDiscSerialiser: public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
RsDiscSerialiser() :RsServiceSerializer(RS_SERVICE_TYPE_DISC) {}
|
||||
|
||||
virtual ~RsDiscSerialiser() {}
|
||||
|
||||
RsItem *create_item(uint16_t service,uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
|
||||
#endif // RS_DISC_ITEMS_H
|
||||
|
156
libretroshare/src/rsitems/rsfiletransferitems.cc
Normal file
156
libretroshare/src/rsitems/rsfiletransferitems.cc
Normal file
|
@ -0,0 +1,156 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsbaseitems.cc
|
||||
*
|
||||
* 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 "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "rsitems/rsfiletransferitems.h"
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/***
|
||||
* #define RSSERIAL_DEBUG 1
|
||||
* #define DEBUG_TRANSFERS 1
|
||||
***/
|
||||
|
||||
|
||||
#ifdef DEBUG_TRANSFERS
|
||||
#include "util/rsprint.h"
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void RsFileTransferDataRequestItem::clear()
|
||||
{
|
||||
file.TlvClear();
|
||||
fileoffset = 0;
|
||||
chunksize = 0;
|
||||
}
|
||||
void RsFileTransferDataItem::clear()
|
||||
{
|
||||
fd.TlvClear();
|
||||
}
|
||||
|
||||
void RsFileTransferDataRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint64_t> (j,ctx,fileoffset,"fileoffset") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,chunksize, "chunksize") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,file, "file") ;
|
||||
}
|
||||
|
||||
void RsFileTransferDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,fd,"fd") ;
|
||||
}
|
||||
|
||||
void RsFileTransferChunkMapRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<bool> (j,ctx,is_client,"is_client") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,hash, "hash") ;
|
||||
}
|
||||
|
||||
void RsFileTransferChunkMapItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<bool> (j,ctx,is_client, "is_client") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,hash, "hash") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,compressed_map,"compressed_map") ;
|
||||
}
|
||||
|
||||
void RsFileTransferSingleChunkCrcRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,hash, "hash") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_number,"chunk_number") ;
|
||||
}
|
||||
|
||||
void RsFileTransferSingleChunkCrcItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,hash, "hash") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_number,"chunk_number") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,check_sum, "check_sum") ;
|
||||
}
|
||||
|
||||
//===================================================================================================//
|
||||
// CompressedChunkMap //
|
||||
//===================================================================================================//
|
||||
|
||||
template<> uint32_t RsTypeSerializer::serial_size(const CompressedChunkMap& s)
|
||||
{
|
||||
return 4 + 4*s._map.size() ;
|
||||
}
|
||||
|
||||
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset,const CompressedChunkMap& s)
|
||||
{
|
||||
bool ok = true ;
|
||||
|
||||
ok &= setRawUInt32(data, size, &offset, s._map.size());
|
||||
|
||||
for(uint32_t i=0;i<s._map.size() && ok;++i)
|
||||
ok &= setRawUInt32(data, size, &offset, s._map[i]);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,CompressedChunkMap& s)
|
||||
{
|
||||
uint32_t S =0;
|
||||
bool ok = getRawUInt32(data, size, &offset, &S);
|
||||
|
||||
if(ok)
|
||||
{
|
||||
s._map.resize(S) ;
|
||||
|
||||
for(uint32_t i=0;i<S && ok;++i)
|
||||
ok &= getRawUInt32(data, size, &offset, &(s._map[i]));
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
template<> void RsTypeSerializer::print_data(const std::string& n, const CompressedChunkMap& s)
|
||||
{
|
||||
std::cerr << " [Compressed chunk map] " << n << " : length=" << s._map.size() << std::endl;
|
||||
}
|
||||
|
||||
//===================================================================================================//
|
||||
// Serializer //
|
||||
//===================================================================================================//
|
||||
|
||||
RsItem *RsFileTransferSerialiser::create_item(uint16_t service_type,uint8_t item_type) const
|
||||
{
|
||||
if(service_type != RS_SERVICE_TYPE_FILE_TRANSFER)
|
||||
return NULL ;
|
||||
|
||||
switch(item_type)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_FT_DATA_REQUEST : return new RsFileTransferDataRequestItem();
|
||||
case RS_PKT_SUBTYPE_FT_DATA : return new RsFileTransferDataItem();
|
||||
case RS_PKT_SUBTYPE_FT_CHUNK_MAP_REQUEST : return new RsFileTransferChunkMapRequestItem();
|
||||
case RS_PKT_SUBTYPE_FT_CHUNK_MAP : return new RsFileTransferChunkMapItem();
|
||||
case RS_PKT_SUBTYPE_FT_CHUNK_CRC_REQUEST : return new RsFileTransferSingleChunkCrcRequestItem();
|
||||
case RS_PKT_SUBTYPE_FT_CHUNK_CRC : return new RsFileTransferSingleChunkCrcItem() ;
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
193
libretroshare/src/rsitems/rsfiletransferitems.h
Normal file
193
libretroshare/src/rsitems/rsfiletransferitems.h
Normal file
|
@ -0,0 +1,193 @@
|
|||
#pragma once
|
||||
|
||||
/*
|
||||
* 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 "retroshare/rstypes.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvfileitem.h"
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_FT_DATA_REQUEST = 0x01;
|
||||
const uint8_t RS_PKT_SUBTYPE_FT_DATA = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_FT_CHUNK_MAP_REQUEST = 0x04;
|
||||
const uint8_t RS_PKT_SUBTYPE_FT_CHUNK_MAP = 0x05;
|
||||
const uint8_t RS_PKT_SUBTYPE_FT_CHUNK_CRC_REQUEST = 0x08;
|
||||
const uint8_t RS_PKT_SUBTYPE_FT_CHUNK_CRC = 0x09;
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_FT_CACHE_ITEM = 0x0A;
|
||||
const uint8_t RS_PKT_SUBTYPE_FT_CACHE_REQUEST = 0x0B;
|
||||
|
||||
//const uint8_t RS_PKT_SUBTYPE_FT_TRANSFER = 0x03;
|
||||
//const uint8_t RS_PKT_SUBTYPE_FT_CRC32_MAP_REQUEST = 0x06;
|
||||
//const uint8_t RS_PKT_SUBTYPE_FT_CRC32_MAP = 0x07;
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
class RsFileTransferItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsFileTransferItem(uint8_t ft_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_FILE_TRANSFER,ft_subtype) {}
|
||||
|
||||
virtual ~RsFileTransferItem() {}
|
||||
|
||||
virtual void clear() = 0 ;
|
||||
};
|
||||
|
||||
class RsFileTransferDataRequestItem: public RsFileTransferItem
|
||||
{
|
||||
public:
|
||||
RsFileTransferDataRequestItem() :RsFileTransferItem(RS_PKT_SUBTYPE_FT_DATA_REQUEST)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_FILE_REQUEST) ;
|
||||
}
|
||||
virtual ~RsFileTransferDataRequestItem() {}
|
||||
virtual void clear();
|
||||
|
||||
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
// Private data part.
|
||||
//
|
||||
uint64_t fileoffset; /* start of data requested */
|
||||
uint32_t chunksize; /* size of data requested */
|
||||
RsTlvFileItem file; /* file information */
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
class RsFileTransferDataItem: public RsFileTransferItem
|
||||
{
|
||||
public:
|
||||
RsFileTransferDataItem() :RsFileTransferItem(RS_PKT_SUBTYPE_FT_DATA)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_FILE_DATA) ;
|
||||
}
|
||||
virtual ~RsFileTransferDataItem() { clear() ; }
|
||||
|
||||
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
virtual void clear();
|
||||
|
||||
// Private data part.
|
||||
//
|
||||
RsTlvFileData fd;
|
||||
};
|
||||
|
||||
class RsFileTransferChunkMapRequestItem: public RsFileTransferItem
|
||||
{
|
||||
public:
|
||||
RsFileTransferChunkMapRequestItem() :RsFileTransferItem(RS_PKT_SUBTYPE_FT_CHUNK_MAP_REQUEST)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_FILE_MAP_REQUEST) ;
|
||||
}
|
||||
virtual ~RsFileTransferChunkMapRequestItem() {}
|
||||
virtual void clear() {}
|
||||
|
||||
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
// Private data part.
|
||||
//
|
||||
bool is_client ; // is the request for a client, or a server ?
|
||||
RsFileHash hash ; // hash of the file for which we request the chunk map
|
||||
};
|
||||
|
||||
class RsFileTransferChunkMapItem: public RsFileTransferItem
|
||||
{
|
||||
public:
|
||||
RsFileTransferChunkMapItem()
|
||||
:RsFileTransferItem(RS_PKT_SUBTYPE_FT_CHUNK_MAP)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_FILE_MAP) ;
|
||||
}
|
||||
virtual ~RsFileTransferChunkMapItem() {}
|
||||
|
||||
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
virtual void clear() {}
|
||||
|
||||
// Private data part.
|
||||
//
|
||||
bool is_client ; // is the request for a client, or a server ?
|
||||
RsFileHash hash ; // hash of the file for which we request the chunk map
|
||||
CompressedChunkMap compressed_map ; // Chunk map of the file.
|
||||
};
|
||||
|
||||
class RsFileTransferSingleChunkCrcRequestItem: public RsFileTransferItem
|
||||
{
|
||||
public:
|
||||
RsFileTransferSingleChunkCrcRequestItem() :RsFileTransferItem(RS_PKT_SUBTYPE_FT_CHUNK_CRC_REQUEST)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_CHUNK_CRC_REQUEST) ;
|
||||
}
|
||||
virtual ~RsFileTransferSingleChunkCrcRequestItem() {}
|
||||
|
||||
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
virtual void clear() {}
|
||||
|
||||
// Private data part.
|
||||
//
|
||||
RsFileHash hash ; // hash of the file for which we request the crc
|
||||
uint32_t chunk_number ; // chunk number
|
||||
};
|
||||
|
||||
class RsFileTransferSingleChunkCrcItem: public RsFileTransferItem
|
||||
{
|
||||
public:
|
||||
RsFileTransferSingleChunkCrcItem() :RsFileTransferItem(RS_PKT_SUBTYPE_FT_CHUNK_CRC)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_CHUNK_CRC) ;
|
||||
}
|
||||
virtual ~RsFileTransferSingleChunkCrcItem() {}
|
||||
|
||||
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
virtual void clear() {}
|
||||
|
||||
// Private data part.
|
||||
//
|
||||
RsFileHash hash ; // hash of the file for which we request the chunk map
|
||||
uint32_t chunk_number ;
|
||||
Sha1CheckSum check_sum ; // CRC32 map of the file.
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
class RsFileTransferSerialiser: public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
RsFileTransferSerialiser(): RsServiceSerializer(RS_SERVICE_TYPE_FILE_TRANSFER) {}
|
||||
|
||||
virtual ~RsFileTransferSerialiser() {}
|
||||
|
||||
RsItem *create_item(uint16_t service_type,uint8_t item_type) const ;
|
||||
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
173
libretroshare/src/rsitems/rsgxschannelitems.cc
Normal file
173
libretroshare/src/rsitems/rsgxschannelitems.cc
Normal file
|
@ -0,0 +1,173 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsgxschannelitems.cc
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-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".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "rsgxschannelitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
RsItem *RsGxsChannelSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) const
|
||||
{
|
||||
if(service_id != RS_SERVICE_GXS_TYPE_CHANNELS)
|
||||
return NULL ;
|
||||
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_GXSCHANNEL_GROUP_ITEM: return new RsGxsChannelGroupItem() ;
|
||||
case RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM: return new RsGxsChannelPostItem();
|
||||
default:
|
||||
return RsGxsCommentSerialiser::create_item(service_id,item_subtype) ;
|
||||
}
|
||||
}
|
||||
|
||||
void RsGxsChannelGroupItem::clear()
|
||||
{
|
||||
mDescription.clear();
|
||||
mImage.TlvClear();
|
||||
}
|
||||
|
||||
bool RsGxsChannelGroupItem::fromChannelGroup(RsGxsChannelGroup &group, bool moveImage)
|
||||
{
|
||||
clear();
|
||||
meta = group.mMeta;
|
||||
mDescription = group.mDescription;
|
||||
|
||||
if (moveImage)
|
||||
{
|
||||
mImage.binData.bin_data = group.mImage.mData;
|
||||
mImage.binData.bin_len = group.mImage.mSize;
|
||||
group.mImage.shallowClear();
|
||||
}
|
||||
else
|
||||
{
|
||||
mImage.binData.setBinData(group.mImage.mData, group.mImage.mSize);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool RsGxsChannelGroupItem::toChannelGroup(RsGxsChannelGroup &group, bool moveImage)
|
||||
{
|
||||
group.mMeta = meta;
|
||||
group.mDescription = mDescription;
|
||||
if (moveImage)
|
||||
{
|
||||
group.mImage.take((uint8_t *) mImage.binData.bin_data, mImage.binData.bin_len);
|
||||
// mImage doesn't have a ShallowClear at the moment!
|
||||
mImage.binData.TlvShallowClear();
|
||||
}
|
||||
else
|
||||
{
|
||||
group.mImage.copy((uint8_t *) mImage.binData.bin_data, mImage.binData.bin_len);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void RsGxsChannelGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_DESCR,mDescription,"mDescription") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,mImage,"mImage") ;
|
||||
}
|
||||
|
||||
bool RsGxsChannelPostItem::fromChannelPost(RsGxsChannelPost &post, bool moveImage)
|
||||
{
|
||||
clear();
|
||||
meta = post.mMeta;
|
||||
mMsg = post.mMsg;
|
||||
|
||||
if (moveImage)
|
||||
{
|
||||
mThumbnail.binData.bin_data = post.mThumbnail.mData;
|
||||
mThumbnail.binData.bin_len = post.mThumbnail.mSize;
|
||||
post.mThumbnail.shallowClear();
|
||||
}
|
||||
else
|
||||
{
|
||||
mThumbnail.binData.setBinData(post.mThumbnail.mData, post.mThumbnail.mSize);
|
||||
}
|
||||
|
||||
std::list<RsGxsFile>::iterator fit;
|
||||
for(fit = post.mFiles.begin(); fit != post.mFiles.end(); ++fit)
|
||||
{
|
||||
RsTlvFileItem fi;
|
||||
fi.name = fit->mName;
|
||||
fi.filesize = fit->mSize;
|
||||
fi.hash = fit->mHash;
|
||||
mAttachment.items.push_back(fi);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool RsGxsChannelPostItem::toChannelPost(RsGxsChannelPost &post, bool moveImage)
|
||||
{
|
||||
post.mMeta = meta;
|
||||
post.mMsg = mMsg;
|
||||
if (moveImage)
|
||||
{
|
||||
post.mThumbnail.take((uint8_t *) mThumbnail.binData.bin_data, mThumbnail.binData.bin_len);
|
||||
// mThumbnail doesn't have a ShallowClear at the moment!
|
||||
mThumbnail.binData.TlvShallowClear();
|
||||
}
|
||||
else
|
||||
{
|
||||
post.mThumbnail.copy((uint8_t *) mThumbnail.binData.bin_data, mThumbnail.binData.bin_len);
|
||||
}
|
||||
|
||||
post.mCount = 0;
|
||||
post.mSize = 0;
|
||||
std::list<RsTlvFileItem>::iterator fit;
|
||||
for(fit = mAttachment.items.begin(); fit != mAttachment.items.end(); ++fit)
|
||||
{
|
||||
RsGxsFile fi;
|
||||
fi.mName = RsDirUtil::getTopDir(fit->name);
|
||||
fi.mSize = fit->filesize;
|
||||
fi.mHash = fit->hash;
|
||||
|
||||
post.mFiles.push_back(fi);
|
||||
post.mCount++;
|
||||
post.mSize += fi.mSize;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void RsGxsChannelPostItem::clear()
|
||||
{
|
||||
mMsg.clear();
|
||||
mAttachment.TlvClear();
|
||||
mThumbnail.TlvClear();
|
||||
}
|
||||
|
||||
void RsGxsChannelPostItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_MSG,mMsg,"mMsg") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,mAttachment,"mAttachment") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,mThumbnail,"mThumbnail") ;
|
||||
}
|
97
libretroshare/src/rsitems/rsgxschannelitems.h
Normal file
97
libretroshare/src/rsitems/rsgxschannelitems.h
Normal file
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsgxschannelitems.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-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 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RS_GXS_CHANNEL_ITEMS_H
|
||||
#define RS_GXS_CHANNEL_ITEMS_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/rsgxscommentitems.h"
|
||||
#include "rsitems/rsgxsitems.h"
|
||||
|
||||
#include "serialiser/rstlvfileitem.h"
|
||||
#include "serialiser/rstlvimage.h"
|
||||
|
||||
#include "retroshare/rsgxschannels.h"
|
||||
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
#include "util/rsdir.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSCHANNEL_GROUP_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM = 0x03;
|
||||
|
||||
class RsGxsChannelGroupItem : public RsGxsGrpItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsChannelGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_CHANNELS, RS_PKT_SUBTYPE_GXSCHANNEL_GROUP_ITEM) {}
|
||||
virtual ~RsGxsChannelGroupItem() {}
|
||||
|
||||
void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
// use conversion functions to transform:
|
||||
bool fromChannelGroup(RsGxsChannelGroup &group, bool moveImage);
|
||||
bool toChannelGroup(RsGxsChannelGroup &group, bool moveImage);
|
||||
|
||||
std::string mDescription;
|
||||
RsTlvImage mImage;
|
||||
};
|
||||
|
||||
class RsGxsChannelPostItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsChannelPostItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_CHANNELS, RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM) {}
|
||||
virtual ~RsGxsChannelPostItem() {}
|
||||
void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
// Slightly unusual structure.
|
||||
// use conversion functions to transform:
|
||||
bool fromChannelPost(RsGxsChannelPost &post, bool moveImage);
|
||||
bool toChannelPost(RsGxsChannelPost &post, bool moveImage);
|
||||
|
||||
std::string mMsg;
|
||||
RsTlvFileSet mAttachment;
|
||||
RsTlvImage mThumbnail;
|
||||
};
|
||||
|
||||
|
||||
class RsGxsChannelSerialiser : public RsGxsCommentSerialiser
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsChannelSerialiser() :RsGxsCommentSerialiser(RS_SERVICE_GXS_TYPE_CHANNELS) {}
|
||||
virtual ~RsGxsChannelSerialiser() {}
|
||||
|
||||
virtual RsItem *create_item(uint16_t service_id,uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
#endif /* RS_GXS_CHANNEL_ITEMS_H */
|
124
libretroshare/src/rsitems/rsgxscircleitems.cc
Normal file
124
libretroshare/src/rsitems/rsgxscircleitems.cc
Normal file
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rswikiitems.cc
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-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".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "rsgxscircleitems.h"
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
//#define CIRCLE_DEBUG 1
|
||||
|
||||
RsItem *RsGxsCircleSerialiser::create_item(uint16_t service, uint8_t item_sub_id) const
|
||||
{
|
||||
if(service != RS_SERVICE_GXS_TYPE_GXSCIRCLE)
|
||||
return NULL ;
|
||||
|
||||
switch(item_sub_id)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM: return new RsGxsCircleGroupItem();
|
||||
case RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM: return new RsGxsCircleMsgItem();
|
||||
case RS_PKT_SUBTYPE_GXSCIRCLE_SUBSCRIPTION_REQUEST_ITEM: return new RsGxsCircleSubscriptionRequestItem();
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
void RsGxsCircleSubscriptionRequestItem::clear()
|
||||
{
|
||||
time_stamp = 0 ;
|
||||
time_out = 0 ;
|
||||
subscription_type = SUBSCRIPTION_REQUEST_UNKNOWN;
|
||||
}
|
||||
|
||||
void RsGxsCircleMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,msg.stuff,"msg.stuff") ;
|
||||
}
|
||||
|
||||
void RsGxsCircleSubscriptionRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,time_stamp,"time_stamp") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,time_out ,"time_out") ;
|
||||
RsTypeSerializer::serial_process<uint8_t> (j,ctx,subscription_type ,"subscription_type") ;
|
||||
}
|
||||
|
||||
void RsGxsCircleGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,pgpIdSet,"pgpIdSet") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,gxsIdSet,"gxsIdSet") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,subCircleSet,"subCircleSet") ;
|
||||
}
|
||||
|
||||
void RsGxsCircleMsgItem::clear()
|
||||
{
|
||||
msg.stuff.clear();
|
||||
}
|
||||
|
||||
void RsGxsCircleGroupItem::clear()
|
||||
{
|
||||
pgpIdSet.TlvClear();
|
||||
gxsIdSet.TlvClear();
|
||||
subCircleSet.TlvClear();
|
||||
}
|
||||
|
||||
bool RsGxsCircleGroupItem::convertFrom(const RsGxsCircleGroup &group)
|
||||
{
|
||||
clear();
|
||||
|
||||
meta = group.mMeta;
|
||||
|
||||
// Enforce the local rules.
|
||||
if (meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL)
|
||||
{
|
||||
pgpIdSet.ids = group.mLocalFriends;
|
||||
}
|
||||
else
|
||||
{
|
||||
gxsIdSet.ids = group.mInvitedMembers;
|
||||
}
|
||||
|
||||
subCircleSet.ids = group.mSubCircles;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RsGxsCircleGroupItem::convertTo(RsGxsCircleGroup &group) const
|
||||
{
|
||||
group.mMeta = meta;
|
||||
|
||||
// Enforce the local rules.
|
||||
if (meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL)
|
||||
{
|
||||
group.mLocalFriends = pgpIdSet.ids;
|
||||
}
|
||||
else
|
||||
{
|
||||
group.mInvitedMembers = gxsIdSet.ids;
|
||||
}
|
||||
|
||||
group.mSubCircles = subCircleSet.ids;
|
||||
return true;
|
||||
}
|
||||
|
117
libretroshare/src/rsitems/rsgxscircleitems.h
Normal file
117
libretroshare/src/rsitems/rsgxscircleitems.h
Normal file
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsgxscircleitems.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-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".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RS_GXSCIRCLE_ITEMS_H
|
||||
#define RS_GXSCIRCLE_ITEMS_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "rsitems/rsserviceids.h"
|
||||
|
||||
#include "serialiser/rstlvitem.h"
|
||||
#include "serialiser/rstlvstring.h"
|
||||
#include "serialiser/rstlvidset.h"
|
||||
|
||||
#include "rsitems/rsgxsitems.h"
|
||||
#include "retroshare/rsgxscircles.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSCIRCLE_SUBSCRIPTION_REQUEST_ITEM = 0x04;
|
||||
|
||||
const uint16_t GXSCIRCLE_PGPIDSET = 0x0001;
|
||||
const uint16_t GXSCIRCLE_GXSIDSET = 0x0002;
|
||||
const uint16_t GXSCIRCLE_SUBCIRCLESET = 0x0003;
|
||||
|
||||
// These classes are a mess. Needs proper item serialisation etc.
|
||||
|
||||
class RsGxsCircleGroupItem : public RsGxsGrpItem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsGxsCircleGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_GXSCIRCLE, RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM) {}
|
||||
virtual ~RsGxsCircleGroupItem() {}
|
||||
|
||||
void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
bool convertFrom(const RsGxsCircleGroup &group);
|
||||
bool convertTo(RsGxsCircleGroup &group) const;
|
||||
|
||||
// DIFFERENT FROM OTHER ONES, as stupid serialisation otherwise.
|
||||
RsTlvPgpIdSet pgpIdSet; // For Local Groups.
|
||||
RsTlvGxsIdSet gxsIdSet; // For External Groups.
|
||||
RsTlvGxsCircleIdSet subCircleSet;
|
||||
};
|
||||
|
||||
class RsGxsCircleMsgItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsCircleMsgItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_GXSCIRCLE, RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM) {}
|
||||
virtual ~RsGxsCircleMsgItem() {}
|
||||
void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsGxsCircleMsg msg;
|
||||
};
|
||||
|
||||
class RsGxsCircleSubscriptionRequestItem: public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsCircleSubscriptionRequestItem() : RsGxsMsgItem(RS_SERVICE_GXS_TYPE_GXSCIRCLE, RS_PKT_SUBTYPE_GXSCIRCLE_SUBSCRIPTION_REQUEST_ITEM) { }
|
||||
virtual ~RsGxsCircleSubscriptionRequestItem() {}
|
||||
|
||||
void clear();
|
||||
|
||||
enum {
|
||||
SUBSCRIPTION_REQUEST_UNKNOWN = 0x00,
|
||||
SUBSCRIPTION_REQUEST_SUBSCRIBE = 0x01,
|
||||
SUBSCRIPTION_REQUEST_UNSUBSCRIBE = 0x02
|
||||
};
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
uint32_t time_stamp ;
|
||||
uint32_t time_out ;
|
||||
uint8_t subscription_type ;
|
||||
};
|
||||
|
||||
class RsGxsCircleSerialiser : public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsCircleSerialiser()
|
||||
:RsServiceSerializer(RS_SERVICE_GXS_TYPE_GXSCIRCLE) {}
|
||||
virtual ~RsGxsCircleSerialiser() {}
|
||||
|
||||
virtual RsItem *create_item(uint16_t service, uint8_t item_sub_id) const;
|
||||
};
|
||||
|
||||
#endif /* RS_GXSCIRCLE_ITEMS_H */
|
59
libretroshare/src/rsitems/rsgxscommentitems.cc
Normal file
59
libretroshare/src/rsitems/rsgxscommentitems.cc
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsgxscommentitems.cc
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2013 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 <iostream>
|
||||
|
||||
#include "rsgxscommentitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
//#define GXSCOMMENT_DEBUG 1
|
||||
|
||||
RsItem *RsGxsCommentSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) const
|
||||
{
|
||||
if(service_id != getRsItemService(PacketId()))
|
||||
return NULL ;
|
||||
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_GXSCOMMENT_COMMENT_ITEM: return new RsGxsCommentItem(getRsItemService(PacketId())) ;
|
||||
case RS_PKT_SUBTYPE_GXSCOMMENT_VOTE_ITEM: return new RsGxsVoteItem(getRsItemService(PacketId()));
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RsGxsCommentItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,1,mMsg.mComment,"mMsg.mComment") ;
|
||||
}
|
||||
|
||||
void RsGxsVoteItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mMsg.mVoteType,"mMsg.mVoteType") ;
|
||||
}
|
||||
|
78
libretroshare/src/rsitems/rsgxscommentitems.h
Normal file
78
libretroshare/src/rsitems/rsgxscommentitems.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsgxscommentitems.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-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 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RS_GXS_COMMENT_ITEMS_H
|
||||
#define RS_GXS_COMMENT_ITEMS_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "rsitems/rsserviceids.h"
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
|
||||
#include "retroshare/rsgxscommon.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSCOMMENT_COMMENT_ITEM = 0xf1;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSCOMMENT_VOTE_ITEM = 0xf2;
|
||||
|
||||
class RsGxsCommentItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsCommentItem(uint16_t service_type): RsGxsMsgItem(service_type, RS_PKT_SUBTYPE_GXSCOMMENT_COMMENT_ITEM) {}
|
||||
virtual ~RsGxsCommentItem() {}
|
||||
void clear(){}
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
|
||||
|
||||
RsGxsComment mMsg;
|
||||
};
|
||||
|
||||
|
||||
class RsGxsVoteItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsVoteItem(uint16_t service_type): RsGxsMsgItem(service_type, RS_PKT_SUBTYPE_GXSCOMMENT_VOTE_ITEM) {}
|
||||
virtual ~RsGxsVoteItem() {}
|
||||
void clear(){}
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
|
||||
|
||||
RsGxsVote mMsg;
|
||||
};
|
||||
|
||||
class RsGxsCommentSerialiser : public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsCommentSerialiser(uint16_t service_type) :RsServiceSerializer(service_type) {}
|
||||
virtual ~RsGxsCommentSerialiser() {}
|
||||
|
||||
virtual RsItem *create_item(uint16_t service_id,uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
#endif /* RS_GXS_COMMENT_ITEMS_H */
|
||||
|
67
libretroshare/src/rsitems/rsgxsforumitems.cc
Normal file
67
libretroshare/src/rsitems/rsgxsforumitems.cc
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsgxsforumitems.cc
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-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".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "rsgxsforumitems.h"
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
//#define GXSFORUM_DEBUG 1
|
||||
|
||||
RsItem *RsGxsForumSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) const
|
||||
{
|
||||
if(service_id != RS_SERVICE_GXS_TYPE_FORUMS)
|
||||
return NULL ;
|
||||
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM: return new RsGxsForumGroupItem();
|
||||
case RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM: return new RsGxsForumMsgItem();
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
void RsGxsForumGroupItem::clear()
|
||||
{
|
||||
mGroup.mDescription.clear();
|
||||
}
|
||||
|
||||
void RsGxsForumGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR,mGroup.mDescription,"mGroup.Description");
|
||||
}
|
||||
void RsGxsForumMsgItem::clear()
|
||||
{
|
||||
mMsg.mMsg.clear();
|
||||
}
|
||||
|
||||
void RsGxsForumMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,mMsg.mMsg,"mGroup.Description");
|
||||
}
|
||||
|
||||
|
||||
|
77
libretroshare/src/rsitems/rsgxsforumitems.h
Normal file
77
libretroshare/src/rsitems/rsgxsforumitems.h
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsgxsforumitems.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-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 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RS_GXS_FORUM_ITEMS_H
|
||||
#define RS_GXS_FORUM_ITEMS_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/rsgxsitems.h"
|
||||
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
#include "retroshare/rsgxsforums.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM = 0x03;
|
||||
|
||||
class RsGxsForumGroupItem : public RsGxsGrpItem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsGxsForumGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_FORUMS, RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM) {}
|
||||
virtual ~RsGxsForumGroupItem() {}
|
||||
|
||||
void clear();
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsGxsForumGroup mGroup;
|
||||
};
|
||||
|
||||
class RsGxsForumMsgItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsForumMsgItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_FORUMS, RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM) {}
|
||||
virtual ~RsGxsForumMsgItem() {}
|
||||
void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsGxsForumMsg mMsg;
|
||||
};
|
||||
|
||||
class RsGxsForumSerialiser : public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
RsGxsForumSerialiser() :RsServiceSerializer(RS_SERVICE_GXS_TYPE_FORUMS) {}
|
||||
virtual ~RsGxsForumSerialiser() {}
|
||||
|
||||
virtual RsItem *create_item(uint16_t service_id,uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
#endif /* RS_GXS_FORUM_ITEMS_H */
|
125
libretroshare/src/rsitems/rsgxsiditems.cc
Normal file
125
libretroshare/src/rsitems/rsgxsiditems.cc
Normal file
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsgxsiditems.cc
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-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".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "rsgxsiditems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rstlvstring.h"
|
||||
#include "util/rsstring.h"
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
#define GXSID_DEBUG 1
|
||||
|
||||
RsItem *RsGxsIdSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) const
|
||||
{
|
||||
if(service_id != RS_SERVICE_GXS_TYPE_GXSID)
|
||||
return NULL ;
|
||||
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_GXSID_GROUP_ITEM : return new RsGxsIdGroupItem ();
|
||||
case RS_PKT_SUBTYPE_GXSID_LOCAL_INFO_ITEM: return new RsGxsIdLocalInfoItem() ;
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
void RsGxsIdLocalInfoItem::clear()
|
||||
{
|
||||
mTimeStamps.clear() ;
|
||||
}
|
||||
void RsGxsIdGroupItem::clear()
|
||||
{
|
||||
mPgpIdHash.clear();
|
||||
mPgpIdSign.clear();
|
||||
|
||||
mRecognTags.clear();
|
||||
mImage.TlvClear();
|
||||
}
|
||||
void RsGxsIdLocalInfoItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,mTimeStamps,"mTimeStamps") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,mContacts,"mContacts") ;
|
||||
}
|
||||
|
||||
void RsGxsIdGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,mPgpIdHash,"mPgpIdHash") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_SIGN,mPgpIdSign,"mPgpIdSign") ;
|
||||
|
||||
RsTlvStringSetRef rset(TLV_TYPE_RECOGNSET,mRecognTags) ;
|
||||
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,rset,"mRecognTags") ;
|
||||
|
||||
// image is optional
|
||||
|
||||
if(j == RsGenericSerializer::DESERIALIZE && ctx.mOffset == ctx.mSize)
|
||||
return ;
|
||||
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,mImage,"mImage") ;
|
||||
}
|
||||
|
||||
bool RsGxsIdGroupItem::fromGxsIdGroup(RsGxsIdGroup &group, bool moveImage)
|
||||
{
|
||||
clear();
|
||||
meta = group.mMeta;
|
||||
mPgpIdHash = group.mPgpIdHash;
|
||||
mPgpIdSign = group.mPgpIdSign;
|
||||
mRecognTags = group.mRecognTags;
|
||||
|
||||
if (moveImage)
|
||||
{
|
||||
mImage.binData.bin_data = group.mImage.mData;
|
||||
mImage.binData.bin_len = group.mImage.mSize;
|
||||
group.mImage.shallowClear();
|
||||
}
|
||||
else
|
||||
{
|
||||
mImage.binData.setBinData(group.mImage.mData, group.mImage.mSize);
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
bool RsGxsIdGroupItem::toGxsIdGroup(RsGxsIdGroup &group, bool moveImage)
|
||||
{
|
||||
group.mMeta = meta;
|
||||
group.mPgpIdHash = mPgpIdHash;
|
||||
group.mPgpIdSign = mPgpIdSign;
|
||||
group.mRecognTags = mRecognTags;
|
||||
|
||||
if (moveImage)
|
||||
{
|
||||
group.mImage.take((uint8_t *) mImage.binData.bin_data, mImage.binData.bin_len);
|
||||
// mImage doesn't have a ShallowClear at the moment!
|
||||
mImage.binData.TlvShallowClear();
|
||||
}
|
||||
else
|
||||
{
|
||||
group.mImage.copy((uint8_t *) mImage.binData.bin_data, mImage.binData.bin_len);
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
132
libretroshare/src/rsitems/rsgxsiditems.h
Normal file
132
libretroshare/src/rsitems/rsgxsiditems.h
Normal file
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsgxsiditems.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-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 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RS_GXS_IDENTITY_ITEMS_H
|
||||
#define RS_GXS_IDENTITY_ITEMS_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
#include "retroshare/rsidentity.h"
|
||||
|
||||
//const uint8_t RS_PKT_SUBTYPE_GXSID_GROUP_ITEM_deprecated = 0x02;
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSID_GROUP_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSID_OPINION_ITEM = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM = 0x04;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSID_LOCAL_INFO_ITEM = 0x05;
|
||||
|
||||
class RsGxsIdItem: public RsGxsGrpItem
|
||||
{
|
||||
public:
|
||||
RsGxsIdItem(uint8_t item_subtype) : RsGxsGrpItem(RS_SERVICE_GXS_TYPE_GXSID,item_subtype) {}
|
||||
};
|
||||
|
||||
class RsGxsIdGroupItem : public RsGxsIdItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsIdGroupItem(): RsGxsIdItem(RS_PKT_SUBTYPE_GXSID_GROUP_ITEM) {}
|
||||
virtual ~RsGxsIdGroupItem() {}
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
virtual void clear();
|
||||
|
||||
bool fromGxsIdGroup(RsGxsIdGroup &group, bool moveImage);
|
||||
bool toGxsIdGroup(RsGxsIdGroup &group, bool moveImage);
|
||||
|
||||
Sha1CheckSum mPgpIdHash;
|
||||
// Need a signature as proof - otherwise anyone could add others Hashes.
|
||||
// This is a string, as the length is variable.
|
||||
std::string mPgpIdSign;
|
||||
|
||||
// Recognition Strings. MAX# defined above.
|
||||
std::list<std::string> mRecognTags;
|
||||
|
||||
// Avatar
|
||||
RsTlvImage mImage ;
|
||||
};
|
||||
class RsGxsIdLocalInfoItem : public RsGxsIdItem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsGxsIdLocalInfoItem(): RsGxsIdItem(RS_PKT_SUBTYPE_GXSID_LOCAL_INFO_ITEM) {}
|
||||
virtual ~RsGxsIdLocalInfoItem() {}
|
||||
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
std::map<RsGxsId,time_t> mTimeStamps ;
|
||||
std::set<RsGxsId> mContacts ;
|
||||
};
|
||||
|
||||
#if 0
|
||||
class RsGxsIdOpinionItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsIdOpinionItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_GXSID,
|
||||
RS_PKT_SUBTYPE_GXSID_OPINION_ITEM) {return; }
|
||||
virtual ~RsGxsIdOpinionItem() { return;}
|
||||
void clear();
|
||||
virtual bool serialise(void *data,uint32_t& size) = 0 ;
|
||||
virtual uint32_t serial_size() = 0 ;
|
||||
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
RsGxsIdOpinion opinion;
|
||||
};
|
||||
|
||||
class RsGxsIdCommentItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsIdCommentItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_GXSID,
|
||||
RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM) { return; }
|
||||
virtual ~RsGxsIdCommentItem() { return; }
|
||||
void clear();
|
||||
virtual bool serialise(void *data,uint32_t& size) = 0 ;
|
||||
virtual uint32_t serial_size() = 0 ;
|
||||
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
RsGxsIdComment comment;
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
class RsGxsIdSerialiser : public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
RsGxsIdSerialiser() :RsServiceSerializer(RS_SERVICE_GXS_TYPE_GXSID) {}
|
||||
virtual ~RsGxsIdSerialiser() {}
|
||||
|
||||
virtual RsItem *create_item(uint16_t service_id,uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
#endif /* RS_GXS_IDENTITY_ITEMS_H */
|
73
libretroshare/src/rsitems/rsgxsitems.cc
Normal file
73
libretroshare/src/rsitems/rsgxsitems.cc
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* rsgxsitems.cc
|
||||
*
|
||||
* Created on: 26 Jul 2012
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
#include "gxs/rsgxsdata.h"
|
||||
#include <iostream>
|
||||
|
||||
void RsMsgMetaData::operator =(const RsGxsMsgMetaData& rGxsMeta)
|
||||
{
|
||||
this->mAuthorId = rGxsMeta.mAuthorId;
|
||||
this->mChildTs = rGxsMeta.mChildTs;
|
||||
this->mGroupId = rGxsMeta.mGroupId;
|
||||
this->mMsgFlags = rGxsMeta.mMsgFlags;
|
||||
this->mMsgId = rGxsMeta.mMsgId;
|
||||
this->mMsgName = rGxsMeta.mMsgName;
|
||||
this->mMsgStatus = rGxsMeta.mMsgStatus;
|
||||
this->mOrigMsgId = rGxsMeta.mOrigMsgId;
|
||||
this->mParentId = rGxsMeta.mParentId;
|
||||
this->mPublishTs = rGxsMeta.mPublishTs;
|
||||
this->mThreadId = rGxsMeta.mThreadId;
|
||||
this->mServiceString = rGxsMeta.mServiceString;
|
||||
}
|
||||
|
||||
|
||||
void RsGroupMetaData::operator =(const RsGxsGrpMetaData& rGxsMeta)
|
||||
{
|
||||
this->mAuthorId = rGxsMeta.mAuthorId;
|
||||
this->mGroupFlags = rGxsMeta.mGroupFlags;
|
||||
this->mGroupId = rGxsMeta.mGroupId;
|
||||
this->mGroupStatus = rGxsMeta.mGroupStatus;
|
||||
this->mLastPost = rGxsMeta.mLastPost;
|
||||
this->mVisibleMsgCount = rGxsMeta.mVisibleMsgCount;
|
||||
this->mPop = rGxsMeta.mPop;
|
||||
this->mPublishTs = rGxsMeta.mPublishTs;
|
||||
this->mSubscribeFlags = rGxsMeta.mSubscribeFlags;
|
||||
this->mGroupName = rGxsMeta.mGroupName;
|
||||
this->mServiceString = rGxsMeta.mServiceString;
|
||||
this->mSignFlags = rGxsMeta.mSignFlags;
|
||||
this->mCircleId = rGxsMeta.mCircleId;
|
||||
this->mCircleType = rGxsMeta.mCircleType;
|
||||
this->mInternalCircle = rGxsMeta.mInternalCircle;
|
||||
this->mOriginator = rGxsMeta.mOriginator;
|
||||
this->mAuthenFlags = rGxsMeta.mAuthenFlags;
|
||||
// std::cout << "rGxsMeta.mParentGrpId= " <<rGxsMeta.mParentGrpId<<"\n";
|
||||
// std::cout << "rGxsMeta.mParentGrpId.length()= " <<rGxsMeta.mParentGrpId.length()<<"\n";
|
||||
//std::cout << "this->mParentGrpId= " <<this->mParentGrpId<<"\n";
|
||||
this->mParentGrpId = rGxsMeta.mParentGrpId;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const RsGroupMetaData &meta)
|
||||
{
|
||||
out << "[ GroupId: " << meta.mGroupId << " Name: " << meta.mGroupName << " ]";
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const RsMsgMetaData &meta)
|
||||
{
|
||||
out << "[ GroupId: " << meta.mGroupId << " MsgId: " << meta.mMsgId;
|
||||
out << " Name: " << meta.mMsgName;
|
||||
out << " OrigMsgId: " << meta.mOrigMsgId;
|
||||
out << " ThreadId: " << meta.mThreadId;
|
||||
out << " ParentId: " << meta.mParentId;
|
||||
out << " AuthorId: " << meta.mAuthorId;
|
||||
out << " Name: " << meta.mMsgName << " ]";
|
||||
return out;
|
||||
}
|
||||
|
||||
|
64
libretroshare/src/rsitems/rsgxsitems.h
Normal file
64
libretroshare/src/rsitems/rsgxsitems.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
#ifndef RSGXSITEMS_H
|
||||
#define RSGXSITEMS_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsgxsitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2012 Christopher Evi-Parker, 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 "rsitems/rsitem.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
|
||||
#include "retroshare/rsgxsifacetypes.h"
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const RsGroupMetaData &meta);
|
||||
std::ostream &operator<<(std::ostream &out, const RsMsgMetaData &meta);
|
||||
|
||||
class RsGxsGrpItem : public RsItem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsGxsGrpItem(uint16_t service, uint8_t subtype)
|
||||
: RsItem(RS_PKT_VERSION_SERVICE, service, subtype) { return; }
|
||||
virtual ~RsGxsGrpItem(){}
|
||||
|
||||
RsGroupMetaData meta;
|
||||
};
|
||||
|
||||
class RsGxsMsgItem : public RsItem
|
||||
{
|
||||
|
||||
public:
|
||||
RsGxsMsgItem(uint16_t service, uint8_t subtype)
|
||||
: RsItem(RS_PKT_VERSION_SERVICE, service, subtype) { return; }
|
||||
virtual ~RsGxsMsgItem(){}
|
||||
|
||||
RsMsgMetaData meta;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // RSGXSITEMS_H
|
118
libretroshare/src/rsitems/rsgxsrecognitems.cc
Normal file
118
libretroshare/src/rsitems/rsgxsrecognitems.cc
Normal file
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsgxsrecogitems.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2013-2013 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 "rsitems/rsgxsrecognitems.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsItem *RsGxsRecognSerialiser::create_item(uint16_t service, uint8_t item_sub_id) const
|
||||
{
|
||||
if(service != RS_SERVICE_TYPE_GXS_RECOGN)
|
||||
return NULL ;
|
||||
|
||||
switch(item_sub_id)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_RECOGN_REQ: return new RsGxsRecognReqItem();
|
||||
case RS_PKT_SUBTYPE_RECOGN_SIGNER: return new RsGxsRecognSignerItem();
|
||||
case RS_PKT_SUBTYPE_RECOGN_TAG: return new RsGxsRecognTagItem();
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
void RsGxsRecognReqItem::clear()
|
||||
{
|
||||
issued_at = 0;
|
||||
period = 0;
|
||||
tag_class = 0;
|
||||
tag_type = 0;
|
||||
|
||||
identity.clear();
|
||||
nickname.clear();
|
||||
comment.clear();
|
||||
|
||||
sign.TlvClear();
|
||||
|
||||
}
|
||||
void RsGxsRecognReqItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,issued_at ,"issued_at") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,period ,"period") ;
|
||||
RsTypeSerializer::serial_process<uint16_t> (j,ctx,tag_class ,"tag_class") ;
|
||||
RsTypeSerializer::serial_process<uint16_t> (j,ctx,tag_type ,"tag_type") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,identity ,"identity") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,1,nickname ,"nickname") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,1,comment ,"comment") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,sign ,"sign") ;
|
||||
}
|
||||
|
||||
void RsGxsRecognTagItem::clear()
|
||||
{
|
||||
valid_from = 0;
|
||||
valid_to = 0;
|
||||
|
||||
tag_class = 0;
|
||||
tag_type = 0;
|
||||
|
||||
identity.clear();
|
||||
nickname.clear();
|
||||
|
||||
sign.TlvClear();
|
||||
}
|
||||
|
||||
void RsGxsRecognTagItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,valid_from ,"valid_from") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,valid_to ,"valid_to") ;
|
||||
RsTypeSerializer::serial_process<uint16_t> (j,ctx,tag_class ,"tag_class") ;
|
||||
RsTypeSerializer::serial_process<uint16_t> (j,ctx,tag_type ,"tag_type") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,identity ,"identity");
|
||||
RsTypeSerializer::serial_process (j,ctx,1,nickname ,"nickname") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,sign ,"sign") ;
|
||||
}
|
||||
|
||||
void RsGxsRecognSignerItem::clear()
|
||||
{
|
||||
signing_classes.TlvClear();
|
||||
key.TlvClear();
|
||||
sign.TlvClear();
|
||||
}
|
||||
|
||||
void RsGxsRecognSignerItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,signing_classes ,"signing_classes") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,key ,"key");
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,sign ,"sign") ;
|
||||
}
|
||||
|
||||
|
||||
|
136
libretroshare/src/rsitems/rsgxsrecognitems.h
Normal file
136
libretroshare/src/rsitems/rsgxsrecognitems.h
Normal file
|
@ -0,0 +1,136 @@
|
|||
#ifndef RS_GXS_RECOG_ITEMS_H
|
||||
#define RS_GXS_RECOG_ITEMS_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsgxsrecogitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2013-2013 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 <map>
|
||||
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "serialiser/rstlvidset.h"
|
||||
|
||||
#if 0
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
|
||||
#endif
|
||||
|
||||
#include "retroshare/rsgxsifacetypes.h"
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#define RS_PKT_SUBTYPE_RECOGN_REQ 0x01
|
||||
#define RS_PKT_SUBTYPE_RECOGN_TAG 0x02
|
||||
#define RS_PKT_SUBTYPE_RECOGN_SIGNER 0x03
|
||||
|
||||
|
||||
class RsGxsRecognReqItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsGxsRecognReqItem() :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_RECOGN, RS_PKT_SUBTYPE_RECOGN_REQ)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_DEFAULT);
|
||||
return;
|
||||
}
|
||||
virtual ~RsGxsRecognReqItem(){}
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
uint32_t issued_at;
|
||||
uint32_t period;
|
||||
uint16_t tag_class;
|
||||
uint16_t tag_type;
|
||||
|
||||
RsGxsId identity;
|
||||
std::string nickname;
|
||||
std::string comment;
|
||||
|
||||
RsTlvKeySignature sign;
|
||||
};
|
||||
|
||||
|
||||
class RsGxsRecognTagItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsGxsRecognTagItem() :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_RECOGN, RS_PKT_SUBTYPE_RECOGN_TAG)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_DEFAULT);
|
||||
return;
|
||||
}
|
||||
virtual ~RsGxsRecognTagItem(){}
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
uint32_t valid_from;
|
||||
uint32_t valid_to;
|
||||
uint16_t tag_class;
|
||||
uint16_t tag_type;
|
||||
|
||||
RsGxsId identity;
|
||||
std::string nickname;
|
||||
|
||||
RsTlvKeySignature sign;
|
||||
};
|
||||
|
||||
|
||||
class RsGxsRecognSignerItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsGxsRecognSignerItem() :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_RECOGN, RS_PKT_SUBTYPE_RECOGN_SIGNER)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_DEFAULT);
|
||||
return;
|
||||
}
|
||||
virtual ~RsGxsRecognSignerItem(){}
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsTlvServiceIdSet signing_classes;
|
||||
RsTlvPublicRSAKey key; // has from->to, and flags.
|
||||
RsTlvKeySignature sign;
|
||||
};
|
||||
|
||||
|
||||
class RsGxsRecognSerialiser: public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
RsGxsRecognSerialiser() :RsServiceSerializer(RS_SERVICE_TYPE_GXS_RECOGN) {}
|
||||
virtual ~RsGxsRecognSerialiser() {}
|
||||
|
||||
virtual RsItem *create_item(uint16_t service, uint8_t item_sub_id) const;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#endif /* RS_GXS_RECOGN_ITEMS_H */
|
||||
|
||||
|
110
libretroshare/src/rsitems/rsgxsreputationitems.cc
Normal file
110
libretroshare/src/rsitems/rsgxsreputationitems.cc
Normal file
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsbanlist.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2011 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 <stdio.h>
|
||||
#include <time.h>
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "rsitems/rsgxsreputationitems.h"
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
void RsGxsReputationSetItem::clear()
|
||||
{
|
||||
mOpinions.clear() ;
|
||||
}
|
||||
|
||||
void RsGxsReputationUpdateItem::clear()
|
||||
{
|
||||
mOpinions.clear() ;
|
||||
}
|
||||
|
||||
void RsGxsReputationBannedNodeSetItem::clear()
|
||||
{
|
||||
mKnownIdentities.TlvClear();
|
||||
}
|
||||
|
||||
void RsGxsReputationConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,mPeerId,"mPeerId") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLatestUpdate,"mLatestUpdate") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLastQuery,"mLastQuery") ;
|
||||
}
|
||||
|
||||
void RsGxsReputationBannedNodeSetItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,mPgpId,"mPgpId") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,mLastActivityTS,"mLastActivityTS") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,mKnownIdentities,"mKnownIdentities") ;
|
||||
}
|
||||
|
||||
void RsGxsReputationSetItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,mGxsId,"mGxsId") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mOwnOpinion,"mOwnOpinion") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mOwnOpinionTS,"mOwnOpinionTS") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mIdentityFlags,"mIdentityFlags") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLastUsedTS,"mLastUsedTS") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,mOwnerNodeId,"mOwnerNodeId") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,mOpinions,"mOpinions") ;
|
||||
}
|
||||
|
||||
void RsGxsReputationUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLatestUpdate,"mLatestUpdate") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,mOpinions,"mOpinions") ;
|
||||
}
|
||||
void RsGxsReputationRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLastUpdate,"mLastUpdate") ;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsItem *RsGxsReputationSerialiser::create_item(uint16_t service,uint8_t subtype) const
|
||||
{
|
||||
if(service != RS_SERVICE_GXS_TYPE_REPUTATION)
|
||||
return NULL ;
|
||||
|
||||
switch(subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM : return new RsGxsReputationSetItem() ;
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_BANNED_NODE_SET_ITEM : return new RsGxsReputationBannedNodeSetItem();
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM : return new RsGxsReputationUpdateItem();
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM : return new RsGxsReputationRequestItem() ;
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM : return new RsGxsReputationConfigItem () ;
|
||||
default:
|
||||
std::cerr << "(EE) RsGxsReputationSerialiser::create_item(): unhandled item type " << subtype << std::endl;
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
182
libretroshare/src/rsitems/rsgxsreputationitems.h
Normal file
182
libretroshare/src/rsitems/rsgxsreputationitems.h
Normal file
|
@ -0,0 +1,182 @@
|
|||
#ifndef RS_GXSREPUTATION_ITEMS_H
|
||||
#define RS_GXSREPUTATION_ITEMS_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsgxsreputationitems.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 <map>
|
||||
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "retroshare/rsgxsifacetypes.h"
|
||||
#include "retroshare/rsreputations.h"
|
||||
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM 0x01
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated2 0x02
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM 0x03
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM 0x04
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated1 0x05
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated3 0x06
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_BANNED_NODE_SET_ITEM 0x07
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM 0x08
|
||||
|
||||
/**************************************************************************/
|
||||
class RsReputationItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsReputationItem(uint8_t reputation_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_GXS_TYPE_REPUTATION,reputation_subtype)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_GXSREPUTATION_ITEM);
|
||||
}
|
||||
|
||||
virtual ~RsReputationItem() {}
|
||||
virtual void clear() = 0 ;
|
||||
};
|
||||
|
||||
class RsGxsReputationConfigItem: public RsReputationItem
|
||||
{
|
||||
public:
|
||||
RsGxsReputationConfigItem() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM) {}
|
||||
|
||||
virtual ~RsGxsReputationConfigItem() {}
|
||||
virtual void clear() {}
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ;
|
||||
|
||||
RsPeerId mPeerId;
|
||||
uint32_t mLatestUpdate; // timestamp they returned.
|
||||
uint32_t mLastQuery; // when we sent out.
|
||||
};
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
// This class should disappear. Deprecated since Jan 7, 2017. The class definition is actually not needed,
|
||||
// that is why it's commented out. Kept here in order to explains how the deserialisation works.
|
||||
//
|
||||
class RsGxsReputationSetItem_deprecated3: public RsReputationItem
|
||||
{
|
||||
public:
|
||||
RsGxsReputationSetItem_deprecated3() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated3) {}
|
||||
|
||||
virtual ~RsGxsReputationSetItem_deprecated3() {}
|
||||
virtual void clear() {}
|
||||
|
||||
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) ;
|
||||
|
||||
RsGxsId mGxsId;
|
||||
uint32_t mOwnOpinion;
|
||||
uint32_t mOwnOpinionTS;
|
||||
uint32_t mIdentityFlags ;
|
||||
RsPgpId mOwnerNodeId;
|
||||
std::map<RsPeerId, uint32_t> mOpinions; // RsPeerId -> Opinion.
|
||||
};
|
||||
#endif
|
||||
|
||||
class RsGxsReputationSetItem: public RsReputationItem
|
||||
{
|
||||
public:
|
||||
RsGxsReputationSetItem() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM)
|
||||
{
|
||||
mOwnOpinion = RsReputations::OPINION_NEUTRAL ;
|
||||
mOwnOpinionTS = 0;
|
||||
mIdentityFlags = 0;
|
||||
mLastUsedTS = 0;
|
||||
}
|
||||
|
||||
virtual ~RsGxsReputationSetItem() {}
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ;
|
||||
|
||||
RsGxsId mGxsId;
|
||||
uint32_t mOwnOpinion;
|
||||
uint32_t mOwnOpinionTS;
|
||||
uint32_t mIdentityFlags;
|
||||
uint32_t mLastUsedTS;
|
||||
RsPgpId mOwnerNodeId;
|
||||
std::map<RsPeerId, uint32_t> mOpinions; // RsPeerId -> Opinion.
|
||||
};
|
||||
class RsGxsReputationBannedNodeSetItem: public RsReputationItem
|
||||
{
|
||||
public:
|
||||
RsGxsReputationBannedNodeSetItem() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_BANNED_NODE_SET_ITEM) {}
|
||||
|
||||
virtual ~RsGxsReputationBannedNodeSetItem() {}
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ;
|
||||
|
||||
RsPgpId mPgpId ;
|
||||
uint32_t mLastActivityTS ;
|
||||
RsTlvGxsIdSet mKnownIdentities ;
|
||||
};
|
||||
|
||||
class RsGxsReputationUpdateItem: public RsReputationItem
|
||||
{
|
||||
public:
|
||||
RsGxsReputationUpdateItem() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM) {}
|
||||
|
||||
virtual ~RsGxsReputationUpdateItem() {}
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ;
|
||||
|
||||
uint32_t mLatestUpdate;
|
||||
std::map<RsGxsId, uint32_t> mOpinions; // GxsId -> Opinion.
|
||||
};
|
||||
|
||||
class RsGxsReputationRequestItem: public RsReputationItem
|
||||
{
|
||||
public:
|
||||
RsGxsReputationRequestItem() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM) {}
|
||||
|
||||
virtual ~RsGxsReputationRequestItem() {}
|
||||
virtual void clear() {}
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ;
|
||||
|
||||
uint32_t mLastUpdate;
|
||||
};
|
||||
|
||||
|
||||
class RsGxsReputationSerialiser: public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
RsGxsReputationSerialiser() :RsServiceSerializer(RS_SERVICE_GXS_TYPE_REPUTATION){}
|
||||
virtual ~RsGxsReputationSerialiser(){}
|
||||
|
||||
virtual RsItem *create_item(uint16_t service,uint8_t item_type) const;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#endif /* RS_GXSREPUTATION_ITEMS_H */
|
||||
|
||||
|
138
libretroshare/src/rsitems/rsgxsupdateitems.cc
Normal file
138
libretroshare/src/rsitems/rsgxsupdateitems.cc
Normal file
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsgxsupdateitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2012 Christopher Evi-Parker
|
||||
*
|
||||
* 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/rstypeserializer.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#include "rsgxsupdateitems.h"
|
||||
|
||||
/**********************************************************************************************/
|
||||
/* SERIALIZER */
|
||||
/**********************************************************************************************/
|
||||
|
||||
RsItem* RsGxsUpdateSerialiser::create_item(uint16_t service,uint8_t item_subtype) const
|
||||
{
|
||||
if(service != SERVICE_TYPE)
|
||||
return NULL ;
|
||||
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_GXS_MSG_UPDATE: return new RsGxsMsgUpdateItem(SERVICE_TYPE);
|
||||
case RS_PKT_SUBTYPE_GXS_GRP_UPDATE: return new RsGxsGrpUpdateItem(SERVICE_TYPE);
|
||||
case RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE: return new RsGxsServerGrpUpdateItem(SERVICE_TYPE);
|
||||
case RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE: return new RsGxsServerMsgUpdateItem(SERVICE_TYPE);
|
||||
case RS_PKT_SUBTYPE_GXS_GRP_CONFIG: return new RsGxsGrpConfigItem(SERVICE_TYPE);
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************************************/
|
||||
/* CLEAR */
|
||||
/**********************************************************************************************/
|
||||
|
||||
void RsGxsGrpUpdateItem::clear()
|
||||
{
|
||||
grpUpdateTS = 0;
|
||||
peerID.clear();
|
||||
}
|
||||
|
||||
void RsGxsMsgUpdateItem::clear()
|
||||
{
|
||||
msgUpdateInfos.clear();
|
||||
peerID.clear();
|
||||
}
|
||||
|
||||
void RsGxsServerMsgUpdateItem::clear()
|
||||
{
|
||||
msgUpdateTS = 0;
|
||||
grpId.clear();
|
||||
}
|
||||
|
||||
void RsGxsServerGrpUpdateItem::clear()
|
||||
{
|
||||
grpUpdateTS = 0;
|
||||
}
|
||||
|
||||
/**********************************************************************************************/
|
||||
/* SERIALISER */
|
||||
/**********************************************************************************************/
|
||||
|
||||
void RsGxsGrpUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,peerID,"peerID");
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,grpUpdateTS,"grpUpdateTS");
|
||||
}
|
||||
|
||||
void RsGxsServerGrpUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,grpUpdateTS,"grpUpdateTS");
|
||||
}
|
||||
|
||||
void RsGxsMsgUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,peerID,"peerID");
|
||||
RsTypeSerializer::serial_process(j,ctx,msgUpdateInfos,"msgUpdateInfos");
|
||||
}
|
||||
|
||||
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const RsGxsMsgUpdateItem::MsgUpdateInfo& info)
|
||||
{
|
||||
bool ok = true ;
|
||||
|
||||
ok = ok && setRawUInt32(data,size,&offset,info.time_stamp);
|
||||
ok = ok && setRawUInt32(data,size,&offset,info.message_count);
|
||||
|
||||
return ok;
|
||||
}
|
||||
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, RsGxsMsgUpdateItem::MsgUpdateInfo& info)
|
||||
{
|
||||
bool ok = true ;
|
||||
|
||||
ok = ok && getRawUInt32(data,size,&offset,&info.time_stamp);
|
||||
ok = ok && getRawUInt32(data,size,&offset,&info.message_count);
|
||||
|
||||
return ok;
|
||||
}
|
||||
template<> uint32_t RsTypeSerializer::serial_size(const RsGxsMsgUpdateItem::MsgUpdateInfo& /* info */) { return 8; }
|
||||
|
||||
template<> void RsTypeSerializer::print_data(const std::string& name,const RsGxsMsgUpdateItem::MsgUpdateInfo& info)
|
||||
{
|
||||
std::cerr << "[MsgUpdateInfo]: " << name << ": " << info.time_stamp << ", " << info.message_count << std::endl;
|
||||
}
|
||||
|
||||
void RsGxsServerMsgUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,grpId,"grpId");
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgUpdateTS,"msgUpdateTS");
|
||||
}
|
||||
void RsGxsGrpConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,grpId,"grpId") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msg_keep_delay,"msg_keep_delay") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msg_send_delay,"msg_send_delay") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msg_req_delay,"msg_req_delay") ;
|
||||
}
|
||||
|
||||
|
204
libretroshare/src/rsitems/rsgxsupdateitems.h
Normal file
204
libretroshare/src/rsitems/rsgxsupdateitems.h
Normal file
|
@ -0,0 +1,204 @@
|
|||
#ifndef RSGXSUPDATEITEMS_H_
|
||||
#define RSGXSUPDATEITEMS_H_
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsgxsupdateitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2012 Christopher Evi-Parker
|
||||
*
|
||||
* 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".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
#include <map>
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#endif
|
||||
|
||||
#include "gxs/rsgxs.h"
|
||||
#include "gxs/rsgxsdata.h"
|
||||
#include "serialiser/rstlvidset.h"
|
||||
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_GXS_GRP_UPDATE = 0x01;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXS_MSG_UPDATE_deprecated = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXS_MSG_UPDATE = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE = 0x04;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE = 0x08;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXS_GRP_CONFIG = 0x09;
|
||||
|
||||
class RsGxsNetServiceItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsGxsNetServiceItem(uint16_t serv_type,uint8_t subtype) : RsItem(RS_PKT_VERSION_SERVICE, serv_type, subtype) {}
|
||||
|
||||
virtual ~RsGxsNetServiceItem() {}
|
||||
virtual void clear() = 0 ;
|
||||
};
|
||||
|
||||
class RsGxsGrpConfig
|
||||
{
|
||||
public:
|
||||
RsGxsGrpConfig()
|
||||
{
|
||||
msg_keep_delay = RS_GXS_DEFAULT_MSG_STORE_PERIOD ;
|
||||
msg_send_delay = RS_GXS_DEFAULT_MSG_SEND_PERIOD ;
|
||||
msg_req_delay = RS_GXS_DEFAULT_MSG_REQ_PERIOD ;
|
||||
|
||||
max_visible_count = 0 ;
|
||||
update_TS = 0 ;
|
||||
}
|
||||
|
||||
uint32_t msg_keep_delay ; // delay after which we discard the posts
|
||||
uint32_t msg_send_delay ; // delay after which we dont send the posts anymore
|
||||
uint32_t msg_req_delay ; // delay after which we dont get the posts from friends
|
||||
|
||||
RsTlvPeerIdSet suppliers; // list of friends who feed this group
|
||||
uint32_t max_visible_count ; // max visible count reported by contributing friends
|
||||
time_t update_TS ; // last time the max visible count was updated.
|
||||
};
|
||||
|
||||
class RsGxsGrpConfigItem : public RsGxsNetServiceItem, public RsGxsGrpConfig
|
||||
{
|
||||
public:
|
||||
RsGxsGrpConfigItem(uint16_t servType) : RsGxsNetServiceItem(servType, RS_PKT_SUBTYPE_GXS_GRP_CONFIG) {}
|
||||
RsGxsGrpConfigItem(const RsGxsGrpConfig& m,uint16_t servType) : RsGxsNetServiceItem(servType, RS_PKT_SUBTYPE_GXS_GRP_CONFIG),RsGxsGrpConfig(m) {}
|
||||
virtual ~RsGxsGrpConfigItem() {}
|
||||
|
||||
virtual void clear() {}
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsGxsGroupId grpId ;
|
||||
};
|
||||
|
||||
class RsGxsGrpUpdate
|
||||
{
|
||||
public:
|
||||
RsGxsGrpUpdate() { grpUpdateTS=0;}
|
||||
|
||||
uint32_t grpUpdateTS;
|
||||
};
|
||||
|
||||
class RsGxsGrpUpdateItem : public RsGxsNetServiceItem, public RsGxsGrpUpdate
|
||||
{
|
||||
public:
|
||||
RsGxsGrpUpdateItem(uint16_t servType) : RsGxsNetServiceItem(servType, RS_PKT_SUBTYPE_GXS_GRP_UPDATE) {clear();}
|
||||
RsGxsGrpUpdateItem(const RsGxsGrpUpdate& u,uint16_t serv_type) : RsGxsNetServiceItem(serv_type, RS_PKT_SUBTYPE_GXS_GRP_UPDATE), RsGxsGrpUpdate(u) {}
|
||||
|
||||
virtual ~RsGxsGrpUpdateItem() {}
|
||||
|
||||
virtual void clear();
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsPeerId peerID;
|
||||
};
|
||||
|
||||
class RsGxsServerGrpUpdate
|
||||
{
|
||||
public:
|
||||
RsGxsServerGrpUpdate() { grpUpdateTS = 0 ; }
|
||||
|
||||
uint32_t grpUpdateTS;
|
||||
};
|
||||
|
||||
class RsGxsServerGrpUpdateItem : public RsGxsNetServiceItem, public RsGxsServerGrpUpdate
|
||||
{
|
||||
public:
|
||||
RsGxsServerGrpUpdateItem(uint16_t servType) : RsGxsNetServiceItem(servType, RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE) { clear();}
|
||||
RsGxsServerGrpUpdateItem(const RsGxsServerGrpUpdate& u,uint16_t serv_type) : RsGxsNetServiceItem(serv_type, RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE), RsGxsServerGrpUpdate(u) {}
|
||||
|
||||
virtual ~RsGxsServerGrpUpdateItem() {}
|
||||
|
||||
virtual void clear();
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
};
|
||||
|
||||
class RsGxsMsgUpdate
|
||||
{
|
||||
public:
|
||||
struct MsgUpdateInfo
|
||||
{
|
||||
MsgUpdateInfo(): time_stamp(0), message_count(0) {}
|
||||
|
||||
uint32_t time_stamp ;
|
||||
uint32_t message_count ;
|
||||
};
|
||||
|
||||
std::map<RsGxsGroupId, MsgUpdateInfo> msgUpdateInfos;
|
||||
};
|
||||
|
||||
class RsGxsMsgUpdateItem : public RsGxsNetServiceItem, public RsGxsMsgUpdate
|
||||
{
|
||||
public:
|
||||
RsGxsMsgUpdateItem(uint16_t servType) : RsGxsNetServiceItem(servType, RS_PKT_SUBTYPE_GXS_MSG_UPDATE) { clear();}
|
||||
RsGxsMsgUpdateItem(const RsGxsMsgUpdate& m,uint16_t servType) : RsGxsNetServiceItem(servType, RS_PKT_SUBTYPE_GXS_MSG_UPDATE), RsGxsMsgUpdate(m) {}
|
||||
|
||||
virtual ~RsGxsMsgUpdateItem() {}
|
||||
|
||||
virtual void clear();
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsPeerId peerID;
|
||||
};
|
||||
|
||||
class RsGxsServerMsgUpdate
|
||||
{
|
||||
public:
|
||||
RsGxsServerMsgUpdate() { msgUpdateTS = 0 ;}
|
||||
|
||||
uint32_t msgUpdateTS; // local time stamp this group last received a new msg
|
||||
};
|
||||
|
||||
class RsGxsServerMsgUpdateItem : public RsGxsNetServiceItem, public RsGxsServerMsgUpdate
|
||||
{
|
||||
public:
|
||||
RsGxsServerMsgUpdateItem(uint16_t servType) : RsGxsNetServiceItem(servType, RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE) { clear();}
|
||||
RsGxsServerMsgUpdateItem(const RsGxsServerMsgUpdate& m,uint16_t servType) : RsGxsNetServiceItem(servType, RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE),RsGxsServerMsgUpdate(m) {}
|
||||
virtual ~RsGxsServerMsgUpdateItem() {}
|
||||
|
||||
virtual void clear();
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsGxsGroupId grpId;
|
||||
};
|
||||
|
||||
|
||||
class RsGxsUpdateSerialiser : public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsUpdateSerialiser(uint16_t servtype) : RsServiceSerializer(servtype), SERVICE_TYPE(servtype) {}
|
||||
|
||||
virtual ~RsGxsUpdateSerialiser() {}
|
||||
|
||||
virtual RsItem* create_item(uint16_t service,uint8_t item_subtype) const ;
|
||||
|
||||
const uint16_t SERVICE_TYPE;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* RSGXSUPDATEITEMS_H_ */
|
68
libretroshare/src/rsitems/rsheartbeatitems.h
Normal file
68
libretroshare/src/rsitems/rsheartbeatitems.h
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsheartbeatitems.h
|
||||
*
|
||||
* Serialiser for RetroShare.
|
||||
*
|
||||
* Copyright 2004-2013 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".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef RS_HEARTBEAT_ITEMS_H
|
||||
#define RS_HEARTBEAT_ITEMS_H
|
||||
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_HEARTBEAT_PULSE = 0x01;
|
||||
|
||||
class RsHeartbeatItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsHeartbeatItem() :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_HEARTBEAT, RS_PKT_SUBTYPE_HEARTBEAT_PULSE)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_HEARTBEAT_PULSE) ;
|
||||
}
|
||||
virtual ~RsHeartbeatItem() {}
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) {}
|
||||
|
||||
virtual void clear(){}
|
||||
};
|
||||
|
||||
class RsHeartbeatSerialiser: public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
RsHeartbeatSerialiser() :RsServiceSerializer(RS_SERVICE_TYPE_HEARTBEAT) {}
|
||||
|
||||
virtual ~RsHeartbeatSerialiser() {}
|
||||
|
||||
virtual RsItem *create_item(uint16_t service,uint8_t item_subtype) const
|
||||
{
|
||||
if(service == RS_SERVICE_TYPE_HEARTBEAT && item_subtype == RS_PKT_SUBTYPE_HEARTBEAT_PULSE)
|
||||
return new RsHeartbeatItem() ;
|
||||
else
|
||||
return NULL ;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // RS_DISC_ITEMS_H
|
||||
|
75
libretroshare/src/rsitems/rshistoryitems.cc
Normal file
75
libretroshare/src/rsitems/rshistoryitems.cc
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rshistoryitems.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2011 by Thunder.
|
||||
*
|
||||
* 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 "rsitems/rshistoryitems.h"
|
||||
#include "rsitems/rsconfigitems.h"
|
||||
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void RsHistoryMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
uint16_t version=0;
|
||||
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,version,"version") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,chatPeerId,"chatPeerId") ;
|
||||
RsTypeSerializer::serial_process<bool> (j,ctx,incoming,"incoming") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,peerName,"peerName") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,sendTime,"sendTime") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,recvTime,"recvTime") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_MSG,message,"message") ;
|
||||
}
|
||||
|
||||
RsItem *RsHistorySerialiser::create_item(uint8_t item_type,uint8_t item_subtype) const
|
||||
{
|
||||
if(item_type != RS_PKT_TYPE_HISTORY_CONFIG)
|
||||
return NULL ;
|
||||
|
||||
if(item_subtype == RS_PKT_SUBTYPE_DEFAULT)
|
||||
return new RsHistoryMsgItem();
|
||||
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
|
||||
RsHistoryMsgItem::RsHistoryMsgItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_HISTORY_CONFIG, RS_PKT_SUBTYPE_DEFAULT)
|
||||
{
|
||||
incoming = false;
|
||||
sendTime = 0;
|
||||
recvTime = 0;
|
||||
msgId = 0;
|
||||
saveToDisc = true;
|
||||
}
|
||||
|
||||
|
73
libretroshare/src/rsitems/rshistoryitems.h
Normal file
73
libretroshare/src/rsitems/rshistoryitems.h
Normal file
|
@ -0,0 +1,73 @@
|
|||
#ifndef RS_HISTORY_ITEMS_H
|
||||
#define RS_HISTORY_ITEMS_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rshistoryitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Thunder.
|
||||
*
|
||||
* 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 "rsitems/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "rsitems/rsconfigitems.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
class RsHistoryMsgItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsHistoryMsgItem();
|
||||
virtual ~RsHistoryMsgItem() {}
|
||||
virtual void clear() {}
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsPeerId chatPeerId; // empty for global chat
|
||||
bool incoming;
|
||||
RsPeerId peerId;
|
||||
std::string peerName;
|
||||
uint32_t sendTime;
|
||||
uint32_t recvTime;
|
||||
std::string message;
|
||||
|
||||
/* not serialised */
|
||||
uint32_t msgId;
|
||||
bool saveToDisc;
|
||||
};
|
||||
|
||||
class RsHistorySerialiser: public RsConfigSerializer
|
||||
{
|
||||
public:
|
||||
RsHistorySerialiser() : RsConfigSerializer(RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_HISTORY_CONFIG) {}
|
||||
virtual ~RsHistorySerialiser() {}
|
||||
|
||||
virtual RsItem *create_item(uint8_t item_type,uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#endif /* RS_HISTORY_ITEMS_H */
|
||||
|
||||
|
90
libretroshare/src/rsitems/rsitem.h
Normal file
90
libretroshare/src/rsitems/rsitem.h
Normal file
|
@ -0,0 +1,90 @@
|
|||
#pragma once
|
||||
|
||||
#include "util/smallobject.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
class RsItem: public RsMemoryManagement::SmallObject
|
||||
{
|
||||
public:
|
||||
RsItem(uint32_t t);
|
||||
RsItem(uint8_t ver, uint8_t cls, uint8_t t, uint8_t subtype);
|
||||
#ifdef DO_STATISTICS
|
||||
void *operator new(size_t s) ;
|
||||
void operator delete(void *,size_t s) ;
|
||||
#endif
|
||||
|
||||
virtual ~RsItem();
|
||||
virtual void clear() = 0;
|
||||
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t /* indent */ = 0)
|
||||
{
|
||||
RsGenericSerializer::SerializeContext ctx(NULL,0,RsGenericSerializer::FORMAT_BINARY,RsGenericSerializer::SERIALIZATION_FLAG_NONE);
|
||||
serial_process(RsGenericSerializer::PRINT,ctx) ;
|
||||
return out;
|
||||
}
|
||||
|
||||
void print_string(std::string &out, uint16_t indent = 0);
|
||||
|
||||
/* source / destination id */
|
||||
const RsPeerId& PeerId() const { return peerId; }
|
||||
void PeerId(const RsPeerId& id) { peerId = id; }
|
||||
|
||||
/* complete id */
|
||||
uint32_t PacketId() const;
|
||||
|
||||
/* id parts */
|
||||
uint8_t PacketVersion();
|
||||
uint8_t PacketClass();
|
||||
uint8_t PacketType();
|
||||
uint8_t PacketSubType() const;
|
||||
|
||||
/* 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 ;}
|
||||
|
||||
/**
|
||||
* @brief serialize this object to the given buffer
|
||||
* @param Job to do: serialise or deserialize.
|
||||
* @param data Chunk of memory were to dump the serialized data
|
||||
* @param size Size of memory chunk
|
||||
* @param offset Readed to determine at witch offset start writing data,
|
||||
* written to inform caller were written data ends, the updated value
|
||||
* is usually passed by the caller to serialize of another
|
||||
* RsSerializable so it can write on the same chunk of memory just
|
||||
* after where this RsSerializable has been serialized.
|
||||
* @return true if serialization successed, false otherwise
|
||||
*/
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */)
|
||||
{
|
||||
std::cerr << "(EE) RsItem::serial_process() called by an item using new serialization classes, but not derived! Class is " << typeid(*this).name() << std::endl;
|
||||
}
|
||||
|
||||
protected:
|
||||
uint32_t type;
|
||||
RsPeerId peerId;
|
||||
uint8_t _priority_level ;
|
||||
};
|
||||
|
||||
class RsRawItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsRawItem(uint32_t t, uint32_t size) : RsItem(t), len(size)
|
||||
{ data = rs_malloc(len); }
|
||||
virtual ~RsRawItem() { free(data); }
|
||||
|
||||
uint32_t getRawLength() { return len; }
|
||||
void * getRawData() { return data; }
|
||||
|
||||
virtual void clear() {}
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
private:
|
||||
void *data;
|
||||
uint32_t len;
|
||||
};
|
182
libretroshare/src/rsitems/rsmsgitems.cc
Normal file
182
libretroshare/src/rsitems/rsmsgitems.cc
Normal file
|
@ -0,0 +1,182 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsbaseitems.cc
|
||||
*
|
||||
* 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 <stdexcept>
|
||||
#include <time.h>
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
|
||||
#include "rsitems/rsmsgitems.h"
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
RsItem *RsMsgSerialiser::create_item(uint16_t service,uint8_t type) const
|
||||
{
|
||||
if(service != RS_SERVICE_TYPE_MSG)
|
||||
return NULL ;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_DEFAULT : return new RsMsgItem() ; //= 0x01;
|
||||
case RS_PKT_SUBTYPE_MSG_TAG_TYPE : return new RsMsgTagType() ; //= 0x03;
|
||||
case RS_PKT_SUBTYPE_MSG_TAGS : return new RsMsgTags() ; //= 0x04;
|
||||
case RS_PKT_SUBTYPE_MSG_SRC_TAG : return new RsMsgSrcId(); //= 0x05;
|
||||
case RS_PKT_SUBTYPE_MSG_PARENT_TAG : return new RsMsgParentId() ; //= 0x06;
|
||||
case RS_PKT_SUBTYPE_MSG_INVITE : return new RsPublicMsgInviteConfigItem(); //= 0x07;
|
||||
case RS_PKT_SUBTYPE_MSG_GROUTER_MAP : return new RsMsgGRouterMap(); //= 0x08;
|
||||
case RS_PKT_SUBTYPE_MSG_DISTANT_MSG_MAP : return new RsMsgDistantMessagesHashMap();//= 0x09;
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
void RsMsgItem::clear()
|
||||
{
|
||||
msgId = 0;
|
||||
msgFlags = 0;
|
||||
sendTime = 0;
|
||||
recvTime = 0;
|
||||
subject.clear();
|
||||
message.clear();
|
||||
|
||||
rspeerid_msgto.TlvClear();
|
||||
rspeerid_msgcc.TlvClear();
|
||||
rspeerid_msgbcc.TlvClear();
|
||||
|
||||
rsgxsid_msgto.TlvClear();
|
||||
rsgxsid_msgcc.TlvClear();
|
||||
rsgxsid_msgbcc.TlvClear();
|
||||
|
||||
attachment.TlvClear();
|
||||
}
|
||||
|
||||
void RsPublicMsgInviteConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_SHA1,hash,"hash") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,(uint32_t&)time_stamp,"time_stamp") ;
|
||||
}
|
||||
void RsMsgTagType::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_NAME,text,"text") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,rgb_color,"rgb_color") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,tagId,"tagId") ;
|
||||
}
|
||||
|
||||
void RsMsgTags::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgId,"msgId") ;
|
||||
|
||||
#warning this is not the correct way to serialise here. We should directly call serial_process<std::vector<uint32_t> >() but for backward compatibility, we cannot
|
||||
|
||||
if(j == RsGenericSerializer::DESERIALIZE)
|
||||
while(ctx.mOffset < ctx.mSize)
|
||||
{
|
||||
uint32_t n ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,n,"tagIds element") ;
|
||||
tagIds.push_back(n) ;
|
||||
}
|
||||
else
|
||||
for(std::list<uint32_t>::iterator it(tagIds.begin());it!=tagIds.end();++it)
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,*it,"tagIds element") ;
|
||||
}
|
||||
|
||||
void RsMsgSrcId::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgId,"msgId") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,srcId,"srcId") ;
|
||||
}
|
||||
|
||||
void RsMsgGRouterMap::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,ongoing_msgs,"ongoing_msgs") ;
|
||||
}
|
||||
|
||||
void RsMsgGRouterMap::clear()
|
||||
{
|
||||
ongoing_msgs.clear() ;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void RsMsgDistantMessagesHashMap::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,hash_map,"hash_map") ;
|
||||
}
|
||||
|
||||
void RsMsgParentId::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgId,"msgId") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgParentId,"msgParentId") ;
|
||||
}
|
||||
|
||||
void RsMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgFlags,"msgFlags");
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,sendTime,"sendTime");
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,recvTime,"recvTime");
|
||||
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_SUBJECT,subject,"subject");
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_MSG,message,"message");
|
||||
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,rspeerid_msgto,"rspeerid_msgto");
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,rspeerid_msgcc,"rspeerid_msgcc");
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,rspeerid_msgbcc,"rspeerid_msgbcc");
|
||||
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,rsgxsid_msgto,"rsgxsid_msgto");
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,rsgxsid_msgcc,"rsgxsid_msgcc");
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,rsgxsid_msgbcc,"rsgxsid_msgbcc");
|
||||
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,attachment,"attachment");
|
||||
|
||||
if(ctx.mFlags & RsServiceSerializer::SERIALIZATION_FLAG_CONFIG)
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgId,"msgId");
|
||||
}
|
||||
|
||||
void RsMsgTagType::clear()
|
||||
{
|
||||
text.clear();
|
||||
tagId = 0;
|
||||
rgb_color = 0;
|
||||
}
|
||||
|
||||
void RsPublicMsgInviteConfigItem::clear()
|
||||
{
|
||||
hash.clear() ;
|
||||
time_stamp = 0 ;
|
||||
}
|
||||
void RsMsgTags::clear()
|
||||
{
|
||||
msgId = 0;
|
||||
tagIds.clear();
|
||||
}
|
||||
|
253
libretroshare/src/rsitems/rsmsgitems.h
Normal file
253
libretroshare/src/rsitems/rsmsgitems.h
Normal file
|
@ -0,0 +1,253 @@
|
|||
#ifndef RS_MSG_ITEMS_H
|
||||
#define RS_MSG_ITEMS_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsmsgitems.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 "retroshare/rstypes.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "serialiser/rstlvfileitem.h"
|
||||
#include "grouter/grouteritems.h"
|
||||
|
||||
#if 0
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvfileitem.h"
|
||||
#endif
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
// for defining tags themselves and msg tags
|
||||
const uint8_t RS_PKT_SUBTYPE_MSG_TAG_TYPE = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_MSG_TAGS = 0x04;
|
||||
const uint8_t RS_PKT_SUBTYPE_MSG_SRC_TAG = 0x05;
|
||||
const uint8_t RS_PKT_SUBTYPE_MSG_PARENT_TAG = 0x06;
|
||||
const uint8_t RS_PKT_SUBTYPE_MSG_INVITE = 0x07;
|
||||
const uint8_t RS_PKT_SUBTYPE_MSG_GROUTER_MAP = 0x08;
|
||||
const uint8_t RS_PKT_SUBTYPE_MSG_DISTANT_MSG_MAP = 0x09;
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
const uint32_t RS_MSG_FLAGS_OUTGOING = 0x00000001;
|
||||
const uint32_t RS_MSG_FLAGS_PENDING = 0x00000002;
|
||||
const uint32_t RS_MSG_FLAGS_DRAFT = 0x00000004;
|
||||
const uint32_t RS_MSG_FLAGS_NEW = 0x00000010;
|
||||
const uint32_t RS_MSG_FLAGS_TRASH = 0x00000020;
|
||||
const uint32_t RS_MSG_FLAGS_UNREAD_BY_USER = 0x00000040;
|
||||
const uint32_t RS_MSG_FLAGS_REPLIED = 0x00000080;
|
||||
const uint32_t RS_MSG_FLAGS_FORWARDED = 0x00000100;
|
||||
const uint32_t RS_MSG_FLAGS_STAR = 0x00000200;
|
||||
const uint32_t RS_MSG_FLAGS_PARTIAL = 0x00000400;
|
||||
const uint32_t RS_MSG_FLAGS_USER_REQUEST = 0x00000800;
|
||||
const uint32_t RS_MSG_FLAGS_FRIEND_RECOMMENDATION = 0x00001000;
|
||||
const uint32_t RS_MSG_FLAGS_RETURN_RECEPT = 0x00002000;
|
||||
const uint32_t RS_MSG_FLAGS_ENCRYPTED = 0x00004000;
|
||||
const uint32_t RS_MSG_FLAGS_DISTANT = 0x00008000;
|
||||
const uint32_t RS_MSG_FLAGS_SIGNATURE_CHECKS = 0x00010000;
|
||||
const uint32_t RS_MSG_FLAGS_SIGNED = 0x00020000;
|
||||
const uint32_t RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES = 0x00040000;
|
||||
const uint32_t RS_MSG_FLAGS_DECRYPTED = 0x00080000;
|
||||
const uint32_t RS_MSG_FLAGS_ROUTED = 0x00100000;
|
||||
const uint32_t RS_MSG_FLAGS_PUBLISH_KEY = 0x00200000;
|
||||
|
||||
const uint32_t RS_MSG_FLAGS_SYSTEM = RS_MSG_FLAGS_USER_REQUEST | RS_MSG_FLAGS_FRIEND_RECOMMENDATION | RS_MSG_FLAGS_PUBLISH_KEY;
|
||||
|
||||
class RsMessageItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsMessageItem(uint8_t msg_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_MSG,msg_subtype)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_MSG_ITEM) ;
|
||||
}
|
||||
|
||||
virtual ~RsMessageItem() {}
|
||||
virtual void clear() {}
|
||||
};
|
||||
|
||||
|
||||
class RsMsgItem: public RsMessageItem
|
||||
{
|
||||
public:
|
||||
RsMsgItem() :RsMessageItem(RS_PKT_SUBTYPE_DEFAULT) {}
|
||||
|
||||
virtual ~RsMsgItem() {}
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
|
||||
|
||||
// ----------- Specific fields ------------- //
|
||||
|
||||
uint32_t msgFlags;
|
||||
uint32_t msgId;
|
||||
|
||||
uint32_t sendTime;
|
||||
uint32_t recvTime;
|
||||
|
||||
std::string subject;
|
||||
std::string message;
|
||||
|
||||
RsTlvPeerIdSet rspeerid_msgto;
|
||||
RsTlvPeerIdSet rspeerid_msgcc;
|
||||
RsTlvPeerIdSet rspeerid_msgbcc;
|
||||
|
||||
RsTlvGxsIdSet rsgxsid_msgto;
|
||||
RsTlvGxsIdSet rsgxsid_msgcc;
|
||||
RsTlvGxsIdSet rsgxsid_msgbcc;
|
||||
|
||||
RsTlvFileSet attachment;
|
||||
};
|
||||
|
||||
class RsMsgTagType : public RsMessageItem
|
||||
{
|
||||
public:
|
||||
RsMsgTagType() :RsMessageItem(RS_PKT_SUBTYPE_MSG_TAG_TYPE) {}
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
|
||||
|
||||
virtual ~RsMsgTagType() {}
|
||||
virtual void clear();
|
||||
|
||||
// ----------- Specific fields ------------- //
|
||||
//
|
||||
std::string text;
|
||||
uint32_t rgb_color;
|
||||
uint32_t tagId;
|
||||
};
|
||||
|
||||
class RsMsgTags : public RsMessageItem
|
||||
{
|
||||
public:
|
||||
RsMsgTags()
|
||||
:RsMessageItem(RS_PKT_SUBTYPE_MSG_TAGS) {}
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
|
||||
|
||||
virtual ~RsMsgTags() {}
|
||||
virtual void clear();
|
||||
|
||||
// ----------- Specific fields ------------- //
|
||||
//
|
||||
uint32_t msgId;
|
||||
std::list<uint32_t> tagIds;
|
||||
};
|
||||
|
||||
class RsMsgSrcId : public RsMessageItem
|
||||
{
|
||||
public:
|
||||
RsMsgSrcId() : RsMessageItem(RS_PKT_SUBTYPE_MSG_SRC_TAG) {}
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
|
||||
|
||||
virtual ~RsMsgSrcId() {}
|
||||
virtual void clear(){}
|
||||
|
||||
// ----------- Specific fields ------------- //
|
||||
//
|
||||
|
||||
uint32_t msgId;
|
||||
RsPeerId srcId;
|
||||
};
|
||||
class RsPublicMsgInviteConfigItem : public RsMessageItem
|
||||
{
|
||||
public:
|
||||
RsPublicMsgInviteConfigItem() : RsMessageItem(RS_PKT_SUBTYPE_MSG_INVITE) {}
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
|
||||
|
||||
virtual ~RsPublicMsgInviteConfigItem() {}
|
||||
virtual void clear();
|
||||
|
||||
// ----------- Specific fields ------------- //
|
||||
//
|
||||
std::string hash ;
|
||||
time_t time_stamp ;
|
||||
};
|
||||
|
||||
class RsMsgGRouterMap : public RsMessageItem
|
||||
{
|
||||
public:
|
||||
RsMsgGRouterMap() : RsMessageItem(RS_PKT_SUBTYPE_MSG_GROUTER_MAP) {}
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
|
||||
|
||||
virtual ~RsMsgGRouterMap() {}
|
||||
virtual void clear();
|
||||
|
||||
// ----------- Specific fields ------------- //
|
||||
//
|
||||
std::map<GRouterMsgPropagationId,uint32_t> ongoing_msgs ;
|
||||
};
|
||||
class RsMsgDistantMessagesHashMap : public RsMessageItem
|
||||
{
|
||||
public:
|
||||
RsMsgDistantMessagesHashMap() : RsMessageItem(RS_PKT_SUBTYPE_MSG_DISTANT_MSG_MAP) {}
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
|
||||
|
||||
virtual ~RsMsgDistantMessagesHashMap() {}
|
||||
virtual void clear() { hash_map.clear() ;}
|
||||
|
||||
// ----------- Specific fields ------------- //
|
||||
//
|
||||
std::map<Sha1CheckSum,uint32_t> hash_map ;
|
||||
};
|
||||
class RsMsgParentId : public RsMessageItem
|
||||
{
|
||||
public:
|
||||
RsMsgParentId() : RsMessageItem(RS_PKT_SUBTYPE_MSG_PARENT_TAG) {}
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
|
||||
|
||||
virtual ~RsMsgParentId() {}
|
||||
virtual void clear(){}
|
||||
|
||||
// ----------- Specific fields ------------- //
|
||||
//
|
||||
uint32_t msgId;
|
||||
uint32_t msgParentId;
|
||||
};
|
||||
|
||||
class RsMsgSerialiser: public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
RsMsgSerialiser(SerializationFlags flags)
|
||||
:RsServiceSerializer(RS_SERVICE_TYPE_MSG,RsGenericSerializer::FORMAT_BINARY,flags){}
|
||||
|
||||
virtual ~RsMsgSerialiser() {}
|
||||
|
||||
virtual RsItem *create_item(uint16_t service,uint8_t type) const ;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#endif /* RS_MSG_ITEMS_H */
|
||||
|
||||
|
215
libretroshare/src/rsitems/rsnxsitems.cc
Normal file
215
libretroshare/src/rsitems/rsnxsitems.cc
Normal file
|
@ -0,0 +1,215 @@
|
|||
#include "rsnxsitems.h"
|
||||
#include "util/rsprint.h"
|
||||
#include <iomanip>
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/***
|
||||
* #define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
|
||||
const uint8_t RsNxsSyncGrpItem::FLAG_REQUEST = 0x001;
|
||||
const uint8_t RsNxsSyncGrpItem::FLAG_RESPONSE = 0x002;
|
||||
|
||||
const uint8_t RsNxsSyncMsgItem::FLAG_REQUEST = 0x001;
|
||||
const uint8_t RsNxsSyncMsgItem::FLAG_RESPONSE = 0x002;
|
||||
|
||||
const uint8_t RsNxsSyncGrpItem::FLAG_USE_SYNC_HASH = 0x0001;
|
||||
const uint8_t RsNxsSyncMsgItem::FLAG_USE_SYNC_HASH = 0x0001;
|
||||
|
||||
const uint8_t RsNxsSyncMsgReqItem::FLAG_USE_HASHED_GROUP_ID = 0x02;
|
||||
|
||||
/** transaction state **/
|
||||
const uint16_t RsNxsTransacItem::FLAG_BEGIN_P1 = 0x0001;
|
||||
const uint16_t RsNxsTransacItem::FLAG_BEGIN_P2 = 0x0002;
|
||||
const uint16_t RsNxsTransacItem::FLAG_END_SUCCESS = 0x0004;
|
||||
const uint16_t RsNxsTransacItem::FLAG_CANCEL = 0x0008;
|
||||
const uint16_t RsNxsTransacItem::FLAG_END_FAIL_NUM = 0x0010;
|
||||
const uint16_t RsNxsTransacItem::FLAG_END_FAIL_TIMEOUT = 0x0020;
|
||||
const uint16_t RsNxsTransacItem::FLAG_END_FAIL_FULL = 0x0040;
|
||||
|
||||
|
||||
/** transaction type **/
|
||||
const uint16_t RsNxsTransacItem::FLAG_TYPE_GRP_LIST_RESP = 0x0100;
|
||||
const uint16_t RsNxsTransacItem::FLAG_TYPE_MSG_LIST_RESP = 0x0200;
|
||||
const uint16_t RsNxsTransacItem::FLAG_TYPE_GRP_LIST_REQ = 0x0400;
|
||||
const uint16_t RsNxsTransacItem::FLAG_TYPE_MSG_LIST_REQ = 0x0800;
|
||||
const uint16_t RsNxsTransacItem::FLAG_TYPE_GRPS = 0x1000;
|
||||
const uint16_t RsNxsTransacItem::FLAG_TYPE_MSGS = 0x2000;
|
||||
const uint16_t RsNxsTransacItem::FLAG_TYPE_ENCRYPTED_DATA = 0x4000;
|
||||
|
||||
RsItem *RsNxsSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) const
|
||||
{
|
||||
if(service_id != SERVICE_TYPE)
|
||||
return NULL ;
|
||||
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_NXS_SYNC_GRP_REQ_ITEM: return new RsNxsSyncGrpReqItem(SERVICE_TYPE) ;
|
||||
case RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM: return new RsNxsSyncGrpItem(SERVICE_TYPE) ;
|
||||
case RS_PKT_SUBTYPE_NXS_SYNC_MSG_REQ_ITEM: return new RsNxsSyncMsgReqItem(SERVICE_TYPE) ;
|
||||
case RS_PKT_SUBTYPE_NXS_SYNC_MSG_ITEM: return new RsNxsSyncMsgItem(SERVICE_TYPE) ;
|
||||
case RS_PKT_SUBTYPE_NXS_GRP_ITEM: return new RsNxsGrp(SERVICE_TYPE) ;
|
||||
case RS_PKT_SUBTYPE_NXS_MSG_ITEM: return new RsNxsMsg(SERVICE_TYPE) ;
|
||||
case RS_PKT_SUBTYPE_NXS_TRANSAC_ITEM: return new RsNxsTransacItem(SERVICE_TYPE) ;
|
||||
case RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY_ITEM:return new RsNxsGroupPublishKeyItem(SERVICE_TYPE) ;
|
||||
case RS_PKT_SUBTYPE_NXS_ENCRYPTED_DATA_ITEM: return new RsNxsEncryptedDataItem(SERVICE_TYPE) ;
|
||||
case RS_PKT_SUBTYPE_NXS_SYNC_GRP_STATS_ITEM: return new RsNxsSyncGrpStatsItem(SERVICE_TYPE) ;
|
||||
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void RsNxsSyncMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,transactionNumber,"transactionNumber") ;
|
||||
RsTypeSerializer::serial_process<uint8_t> (j,ctx,flag ,"flag") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,msgId ,"msgId") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,authorId ,"authorId") ;
|
||||
}
|
||||
void RsNxsMsg::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,transactionNumber,"transactionNumber") ;
|
||||
RsTypeSerializer::serial_process<uint8_t> (j,ctx,pos ,"pos") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,msgId ,"msgId") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,msg ,"msg") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,meta ,"meta") ;
|
||||
}
|
||||
void RsNxsGrp::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,transactionNumber,"transactionNumber") ;
|
||||
RsTypeSerializer::serial_process<uint8_t> (j,ctx,pos ,"pos") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,grp ,"grp") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,meta ,"meta") ;
|
||||
}
|
||||
|
||||
void RsNxsSyncGrpStatsItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,request_type ,"request_type") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,number_of_posts,"number_of_posts") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,last_post_TS ,"last_post_TS") ;
|
||||
}
|
||||
|
||||
void RsNxsSyncGrpReqItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,transactionNumber,"transactionNumber") ;
|
||||
RsTypeSerializer::serial_process<uint8_t> (j,ctx,flag ,"flag") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,createdSince ,"createdSince") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_HASH_SHA1,syncHash,"syncHash") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,updateTS ,"updateTS") ;
|
||||
}
|
||||
|
||||
void RsNxsTransacItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,transactionNumber,"transactionNumber") ;
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,transactFlag ,"transactFlag") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,nItems ,"nItems") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,updateTS ,"updateTS") ;
|
||||
}
|
||||
void RsNxsSyncGrpItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,transactionNumber,"transactionNumber") ;
|
||||
RsTypeSerializer::serial_process<uint8_t> (j,ctx,flag ,"flag") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,publishTs ,"publishTs") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,authorId ,"authorId") ;
|
||||
}
|
||||
void RsNxsSyncMsgReqItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,transactionNumber,"transactionNumber") ;
|
||||
RsTypeSerializer::serial_process<uint8_t> (j,ctx,flag ,"flag") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,createdSinceTS ,"createdSinceTS") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_HASH_SHA1,syncHash,"syncHash") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,updateTS ,"updateTS") ;
|
||||
}
|
||||
void RsNxsGroupPublishKeyItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,private_key ,"private_key") ;
|
||||
}
|
||||
void RsNxsEncryptedDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,transactionNumber,"transactionNumber") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,encrypted_data, "encrypted_data") ;
|
||||
}
|
||||
|
||||
int RsNxsGrp::refcount = 0;
|
||||
/** print and clear functions **/
|
||||
int RsNxsMsg::refcount = 0;
|
||||
void RsNxsMsg::clear()
|
||||
{
|
||||
|
||||
msg.TlvClear();
|
||||
meta.TlvClear();
|
||||
}
|
||||
|
||||
void RsNxsGrp::clear()
|
||||
{
|
||||
grpId.clear();
|
||||
grp.TlvClear();
|
||||
meta.TlvClear();
|
||||
}
|
||||
|
||||
void RsNxsSyncGrpReqItem::clear()
|
||||
{
|
||||
flag = 0;
|
||||
createdSince = 0;
|
||||
syncHash.clear();
|
||||
updateTS = 0;
|
||||
}
|
||||
void RsNxsGroupPublishKeyItem::clear()
|
||||
{
|
||||
private_key.TlvClear();
|
||||
}
|
||||
void RsNxsSyncMsgReqItem::clear()
|
||||
{
|
||||
grpId.clear();
|
||||
flag = 0;
|
||||
createdSinceTS = 0;
|
||||
syncHash.clear();
|
||||
updateTS = 0;
|
||||
}
|
||||
void RsNxsSyncGrpItem::clear()
|
||||
{
|
||||
flag = 0;
|
||||
publishTs = 0;
|
||||
grpId.clear();
|
||||
authorId.clear();
|
||||
}
|
||||
|
||||
void RsNxsSyncMsgItem::clear()
|
||||
{
|
||||
flag = 0;
|
||||
msgId.clear();
|
||||
grpId.clear();
|
||||
authorId.clear();
|
||||
}
|
||||
|
||||
void RsNxsTransacItem::clear(){
|
||||
transactFlag = 0;
|
||||
nItems = 0;
|
||||
updateTS = 0;
|
||||
timestamp = 0;
|
||||
transactionNumber = 0;
|
||||
}
|
||||
void RsNxsEncryptedDataItem::clear(){
|
||||
encrypted_data.TlvClear() ;
|
||||
}
|
||||
|
||||
#ifdef SUSPENDED_CODE_27042017
|
||||
void RsNxsSessionKeyItem::clear()
|
||||
{
|
||||
for(std::map<RsGxsId,RsTlvBinaryData>::iterator it(encrypted_session_keys.begin());it!=encrypted_session_keys.end();++it)
|
||||
it->second.TlvClear() ;
|
||||
|
||||
encrypted_session_keys.clear() ;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
511
libretroshare/src/rsitems/rsnxsitems.h
Normal file
511
libretroshare/src/rsitems/rsnxsitems.h
Normal file
|
@ -0,0 +1,511 @@
|
|||
#ifndef RSNXSITEMS_H
|
||||
#define RSNXSITEMS_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsnxssitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2012 Christopher Evi-Parker, 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 <openssl/ssl.h>
|
||||
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvitem.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "gxs/rsgxsdata.h"
|
||||
|
||||
// These items have "flag type" numbers, but this is not used.
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_NXS_SYNC_GRP_REQ_ITEM = 0x01;
|
||||
const uint8_t RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_NXS_SYNC_GRP_STATS_ITEM = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_NXS_GRP_ITEM = 0x04;
|
||||
const uint8_t RS_PKT_SUBTYPE_NXS_ENCRYPTED_DATA_ITEM = 0x05;
|
||||
const uint8_t RS_PKT_SUBTYPE_NXS_SESSION_KEY_ITEM = 0x06;
|
||||
const uint8_t RS_PKT_SUBTYPE_NXS_SYNC_MSG_ITEM = 0x08;
|
||||
const uint8_t RS_PKT_SUBTYPE_NXS_SYNC_MSG_REQ_ITEM = 0x10;
|
||||
const uint8_t RS_PKT_SUBTYPE_NXS_MSG_ITEM = 0x20;
|
||||
const uint8_t RS_PKT_SUBTYPE_NXS_TRANSAC_ITEM = 0x40;
|
||||
const uint8_t RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY_ITEM = 0x80;
|
||||
|
||||
// possibility create second service to deal with this functionality
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_EXT_SEARCH_GRP = 0x0001;
|
||||
const uint8_t RS_PKT_SUBTYPE_EXT_SEARCH_MSG = 0x0002;
|
||||
const uint8_t RS_PKT_SUBTYPE_EXT_DELETE_GRP = 0x0004;
|
||||
const uint8_t RS_PKT_SUBTYPE_EXT_DELETE_MSG = 0x0008;
|
||||
const uint8_t RS_PKT_SUBTYPE_EXT_SEARCH_REQ = 0x0010;
|
||||
|
||||
|
||||
/*!
|
||||
* Base class for Network exchange service
|
||||
* Main purpose is for rtti based routing used in the
|
||||
* serialisation and deserialisation of NXS packets
|
||||
*
|
||||
* Service type is set by plugin service
|
||||
*/
|
||||
class RsNxsItem : public RsItem
|
||||
{
|
||||
|
||||
public:
|
||||
RsNxsItem(uint16_t servtype, uint8_t subtype) : RsItem(RS_PKT_VERSION_SERVICE, servtype, subtype), transactionNumber(0)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_GXS_NET);
|
||||
return;
|
||||
}
|
||||
virtual ~RsNxsItem(){}
|
||||
virtual void clear() = 0;
|
||||
|
||||
uint32_t transactionNumber; // set to zero if this is not a transaction item
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
* Use to request grp list from peer
|
||||
* Server may advise client peer to use sync file
|
||||
* while serving his request. This results
|
||||
*/
|
||||
class RsNxsSyncGrpReqItem : public RsNxsItem
|
||||
{
|
||||
public:
|
||||
|
||||
static const uint8_t FLAG_USE_SYNC_HASH;
|
||||
static const uint8_t FLAG_ONLY_CURRENT; // only send most current version of grps / ignores sync hash
|
||||
|
||||
RsNxsSyncGrpReqItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_GRP_REQ_ITEM) { clear();}
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
uint8_t flag; // advises whether to use sync hash
|
||||
uint32_t createdSince; // how far back to sync data
|
||||
uint32_t updateTS; // time of last group update
|
||||
std::string syncHash; // use to determine if changes that have occured since last hash
|
||||
};
|
||||
|
||||
/*!
|
||||
* Use to request statistics about a particular group
|
||||
*/
|
||||
class RsNxsSyncGrpStatsItem : public RsNxsItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsNxsSyncGrpStatsItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_GRP_STATS_ITEM) {}
|
||||
|
||||
virtual void clear() {}
|
||||
|
||||
static const uint8_t GROUP_INFO_TYPE_REQUEST = 0x01;
|
||||
static const uint8_t GROUP_INFO_TYPE_RESPONSE = 0x02;
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
uint32_t request_type; // used to determine the type of request
|
||||
RsGxsGroupId grpId; // id of the group
|
||||
uint32_t number_of_posts; // number of posts in that group
|
||||
uint32_t last_post_TS; // time_stamp of last post
|
||||
};
|
||||
|
||||
/*!
|
||||
* Use to request grp list from peer
|
||||
* Server may advise client peer to use sync file
|
||||
* while serving his request. This results
|
||||
*/
|
||||
class RsNxsGroupPublishKeyItem : public RsNxsItem
|
||||
{
|
||||
public:
|
||||
RsNxsGroupPublishKeyItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY_ITEM) { clear(); }
|
||||
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsGxsGroupId grpId ;
|
||||
RsTlvPrivateRSAKey private_key ;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
* This RsNxsItem is for use in enabling transactions
|
||||
* in order to guaranttee a collection of item have been
|
||||
* received
|
||||
*/
|
||||
class RsNxsTransacItem: public RsNxsItem {
|
||||
|
||||
public:
|
||||
|
||||
static const uint16_t FLAG_STATE_MASK = 0xff;
|
||||
static const uint16_t FLAG_TYPE_MASK = 0xff00;
|
||||
|
||||
/** transaction state **/
|
||||
static const uint16_t FLAG_BEGIN_P1;
|
||||
static const uint16_t FLAG_BEGIN_P2;
|
||||
static const uint16_t FLAG_END_SUCCESS;
|
||||
static const uint16_t FLAG_CANCEL;
|
||||
static const uint16_t FLAG_END_FAIL_NUM;
|
||||
static const uint16_t FLAG_END_FAIL_TIMEOUT;
|
||||
static const uint16_t FLAG_END_FAIL_FULL;
|
||||
|
||||
|
||||
/** transaction type **/
|
||||
static const uint16_t FLAG_TYPE_GRP_LIST_RESP;
|
||||
static const uint16_t FLAG_TYPE_MSG_LIST_RESP;
|
||||
static const uint16_t FLAG_TYPE_GRP_LIST_REQ;
|
||||
static const uint16_t FLAG_TYPE_MSG_LIST_REQ;
|
||||
static const uint16_t FLAG_TYPE_GRPS;
|
||||
static const uint16_t FLAG_TYPE_MSGS;
|
||||
static const uint16_t FLAG_TYPE_ENCRYPTED_DATA;
|
||||
|
||||
RsNxsTransacItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_TRANSAC_ITEM) { clear(); }
|
||||
virtual ~RsNxsTransacItem() {}
|
||||
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
uint16_t transactFlag;
|
||||
uint32_t nItems;
|
||||
uint32_t updateTS;
|
||||
|
||||
// not serialised
|
||||
uint32_t timestamp;
|
||||
};
|
||||
|
||||
/*!
|
||||
* Use to send to peer list of grps
|
||||
* held by server peer
|
||||
*/
|
||||
class RsNxsSyncGrpItem: public RsNxsItem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
static const uint8_t FLAG_REQUEST;
|
||||
static const uint8_t FLAG_RESPONSE;
|
||||
static const uint8_t FLAG_USE_SYNC_HASH;
|
||||
|
||||
RsNxsSyncGrpItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM) { clear();}
|
||||
virtual ~RsNxsSyncGrpItem() {}
|
||||
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
uint8_t flag; // request or response
|
||||
uint32_t publishTs; // to compare to Ts of receiving peer's grp of same id
|
||||
|
||||
/// grpId of grp held by sending peer
|
||||
RsGxsGroupId grpId;
|
||||
RsGxsId authorId;
|
||||
|
||||
};
|
||||
|
||||
#ifdef SUSPENDED_CODE_27042017
|
||||
/*!
|
||||
* Use to send to peer list of grps
|
||||
* held by server peer
|
||||
*/
|
||||
class RsNxsSessionKeyItem : public RsNxsItem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsNxsSessionKeyItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SESSION_KEY_ITEM) { clear(); }
|
||||
virtual ~RsNxsSessionKeyItem() {}
|
||||
|
||||
virtual void clear();
|
||||
|
||||
/// Session key encrypted for the whole group
|
||||
///
|
||||
uint8_t iv[EVP_MAX_IV_LENGTH] ; // initialisation vector
|
||||
std::map<RsGxsId, RsTlvBinaryData> encrypted_session_keys; // encrypted session keys
|
||||
};
|
||||
#endif
|
||||
/*!
|
||||
* Use to send to peer list of grps
|
||||
* held by server peer
|
||||
*/
|
||||
class RsNxsEncryptedDataItem : public RsNxsItem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsNxsEncryptedDataItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_ENCRYPTED_DATA_ITEM),encrypted_data(servtype)
|
||||
{
|
||||
encrypted_data.tlvtype = TLV_TYPE_BIN_ENCRYPTED ;
|
||||
clear();
|
||||
}
|
||||
virtual ~RsNxsEncryptedDataItem() {}
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
/// grpId of grp held by sending peer
|
||||
///
|
||||
RsTlvBinaryData encrypted_data ;
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
* Contains serialised group items
|
||||
* Each item corresponds to a group which needs to be
|
||||
* deserialised
|
||||
*/
|
||||
class RsNxsGrp : public RsNxsItem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsNxsGrp(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_GRP_ITEM), grp(servtype), meta(servtype),
|
||||
metaData(NULL) { clear();}
|
||||
virtual ~RsNxsGrp() { if(metaData) delete metaData; }
|
||||
|
||||
RsNxsGrp* clone() const;
|
||||
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsGxsGroupId grpId; /// group Id, needed to complete version Id (ncvi)
|
||||
static int refcount;
|
||||
RsTlvBinaryData grp; /// actual group data
|
||||
uint8_t pos; /// used for splitting up grp
|
||||
uint8_t count; /// number of split up messages
|
||||
|
||||
/*!
|
||||
* This should contains all data
|
||||
* which is not specific to the Gxs service data
|
||||
*/
|
||||
// This is the binary data for the group meta that is sent to friends. It *should not* contain any private
|
||||
// key parts. This is ensured in RsGenExchange
|
||||
|
||||
RsTlvBinaryData meta;
|
||||
|
||||
// Deserialised metaData, this is not serialised by the serialize() method. So it may contain private key parts in some cases.
|
||||
RsGxsGrpMetaData* metaData;
|
||||
};
|
||||
|
||||
/*!
|
||||
* Use to request list of msg held by peer
|
||||
* for a given group
|
||||
*/
|
||||
class RsNxsSyncMsgReqItem : public RsNxsItem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
#ifdef UNUSED_CODE
|
||||
static const uint8_t FLAG_USE_SYNC_HASH;
|
||||
#endif
|
||||
static const uint8_t FLAG_USE_HASHED_GROUP_ID;
|
||||
|
||||
RsNxsSyncMsgReqItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_MSG_REQ_ITEM) { clear(); }
|
||||
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsGxsGroupId grpId;
|
||||
uint8_t flag;
|
||||
uint32_t createdSinceTS;
|
||||
uint32_t updateTS; // time of last update
|
||||
std::string syncHash;
|
||||
};
|
||||
|
||||
/*!
|
||||
* Use to send list msgs for a group held by
|
||||
* a peer
|
||||
*/
|
||||
class RsNxsSyncMsgItem : public RsNxsItem
|
||||
{
|
||||
public:
|
||||
|
||||
static const uint8_t FLAG_REQUEST;
|
||||
static const uint8_t FLAG_RESPONSE;
|
||||
static const uint8_t FLAG_USE_SYNC_HASH;
|
||||
RsNxsSyncMsgItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_MSG_ITEM) { clear(); }
|
||||
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
uint8_t flag; // response/req
|
||||
RsGxsGroupId grpId;
|
||||
RsGxsMessageId msgId;
|
||||
RsGxsId authorId;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
* Used to respond to a RsGrpMsgsReq
|
||||
* with message items satisfying request
|
||||
*/
|
||||
struct RsNxsMsg : RsNxsItem
|
||||
{
|
||||
RsNxsMsg(uint16_t servtype) :
|
||||
RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_MSG_ITEM), meta(servtype),
|
||||
msg(servtype), metaData(NULL) { clear(); }
|
||||
virtual ~RsNxsMsg() { delete metaData; }
|
||||
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx );
|
||||
|
||||
virtual void clear();
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
uint8_t pos; /// used for splitting up msg
|
||||
uint8_t count; /// number of split up messages
|
||||
RsGxsGroupId grpId; /// group id, forms part of version id
|
||||
RsGxsMessageId msgId; /// msg id
|
||||
static int refcount;
|
||||
|
||||
/*!
|
||||
* This should contains all the data
|
||||
* which is not specific to the Gxs service data
|
||||
*/
|
||||
RsTlvBinaryData meta;
|
||||
|
||||
/*!
|
||||
* This contains Gxs specific data
|
||||
* only client of API knows how to decode this
|
||||
*/
|
||||
RsTlvBinaryData msg;
|
||||
|
||||
RsGxsMsgMetaData* metaData;
|
||||
};
|
||||
|
||||
/*!
|
||||
* Used to request a search of user data
|
||||
*/
|
||||
class RsNxsSearchReqItem : public RsNxsItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsNxsSearchReqItem(uint16_t servtype): RsNxsItem(servtype, RS_PKT_SUBTYPE_EXT_SEARCH_REQ), serviceSearchItem(servtype) {}
|
||||
virtual ~RsNxsSearchReqItem() {}
|
||||
virtual void clear() {}
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
uint8_t nHops; /// how many peers to jump to
|
||||
uint32_t token; // search token
|
||||
RsTlvBinaryData serviceSearchItem; // service aware of item class
|
||||
uint32_t expiration; // expiration date
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
* Used to respond to a RsGrpSearchReq
|
||||
* with grpId/MsgIds that satisfy search request
|
||||
*/
|
||||
class RsNxsSearchResultMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsNxsSearchResultMsgItem() : context(0) {}
|
||||
|
||||
void clear() {}
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
uint32_t token; // search token to be redeemed
|
||||
RsTlvBinaryData context; // used by client service
|
||||
std::string msgId;
|
||||
std::string grpId;
|
||||
RsTlvKeySignature idSign;
|
||||
|
||||
uint32_t expiration; // expiration date
|
||||
};
|
||||
|
||||
/*!
|
||||
* Used to respond to a RsGrpSearchReq
|
||||
* with grpId/MsgIds that satisfy search request
|
||||
*/
|
||||
class RsNxsSearchResultGrpItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsNxsSearchResultGrpItem();
|
||||
|
||||
void clear() {}
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
uint32_t token; // search token to be redeemed
|
||||
RsTlvBinaryData context; // used by client service
|
||||
|
||||
std::string grpId;
|
||||
RsTlvKeySignature adminSign;
|
||||
|
||||
uint32_t expiration; // expiration date
|
||||
};
|
||||
|
||||
|
||||
#ifndef UNUSED_CODE
|
||||
class RsNxsDeleteMsg
|
||||
{
|
||||
public:
|
||||
|
||||
RsNxsDeleteMsg() { return; }
|
||||
|
||||
std::string msgId;
|
||||
std::string grpId;
|
||||
RsTlvKeySignature deleteSign; // ( msgId + grpId + msg data ) sign //TODO: add warning not to place msgId+grpId in msg!
|
||||
|
||||
};
|
||||
|
||||
class RsNxsDeleteGrp
|
||||
{
|
||||
public:
|
||||
|
||||
RsNxsDeleteGrp() { return;}
|
||||
|
||||
std::string grpId;
|
||||
RsTlvKeySignature idSign;
|
||||
RsTlvKeySignature deleteSign; // (grpId + grp data) sign // TODO: add warning not to place grpId in msg
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
class RsNxsSerialiser : public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
|
||||
RsNxsSerialiser(uint16_t servtype) : RsServiceSerializer(servtype), SERVICE_TYPE(servtype) {}
|
||||
virtual ~RsNxsSerialiser() {}
|
||||
|
||||
|
||||
virtual RsItem *create_item(uint16_t service_id,uint8_t item_subtype) const ;
|
||||
protected:
|
||||
const uint16_t SERVICE_TYPE;
|
||||
};
|
||||
|
||||
|
||||
#endif // RSNXSITEMS_H
|
120
libretroshare/src/rsitems/rsphotoitems.cc
Normal file
120
libretroshare/src/rsitems/rsphotoitems.cc
Normal file
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* libretroshare/src/retroshare: rsphoto.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2012 by Christopher Evi-Parker, 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 <iostream>
|
||||
|
||||
#include "rsitems/rsphotoitems.h"
|
||||
|
||||
#include "serialiser/rstlvbinary.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
#define GXS_PHOTO_SERIAL_DEBUG
|
||||
|
||||
|
||||
RsItem *RsGxsPhotoSerialiser::create_item(uint16_t service, uint8_t item_sub_id) const
|
||||
{
|
||||
if(service != RS_SERVICE_GXS_TYPE_PHOTO)
|
||||
return NULL ;
|
||||
|
||||
switch(item_sub_id)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM: return new RsGxsPhotoCommentItem() ;
|
||||
case RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM: return new RsGxsPhotoAlbumItem() ;
|
||||
case RS_PKT_SUBTYPE_PHOTO_ITEM: return new RsGxsPhotoPhotoItem() ;
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
void RsGxsPhotoAlbumItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_CAPTION, album.mCaption, "mCaption");
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_CATEGORY, album.mCategory, "mCategory");
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR, album.mDescription, "mDescription");
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG, album.mHashTags, "mHashTags");
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG, album.mOther, "mOther");
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_PATH, album.mPhotoPath, "mPhotoPath");
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_NAME, album.mPhotographer, "mPhotographer");
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DATE, album.mWhen, "mWhen");
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_LOCATION, album.mWhere, "mWhere");
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_PIC_TYPE, album.mThumbnail.type,"mThumbnail.type");
|
||||
|
||||
RsTlvBinaryDataRef b(RS_SERVICE_GXS_TYPE_PHOTO, album.mThumbnail.data,album.mThumbnail.size);
|
||||
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,b,"thumbnail binary data") ;
|
||||
}
|
||||
void RsGxsPhotoPhotoItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_CAPTION, photo.mCaption);
|
||||
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_CATEGORY, photo.mCategory);
|
||||
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_DESCR, photo.mDescription);
|
||||
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_HASH_TAG, photo.mHashTags);
|
||||
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_MSG, photo.mOther);
|
||||
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_PIC_AUTH, photo.mPhotographer);
|
||||
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_DATE, photo.mWhen);
|
||||
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_LOCATION, photo.mWhere);
|
||||
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_PIC_TYPE, photo.mThumbnail.type);
|
||||
|
||||
RsTlvBinaryDataRef b(RS_SERVICE_GXS_TYPE_PHOTO,photo.mThumbnail.data, photo.mThumbnail.size);
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx, b, "mThumbnail") ;
|
||||
}
|
||||
void RsGxsPhotoCommentItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_COMMENT,comment.mComment,"mComment");
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,comment.mCommentFlag,"mCommentFlag");
|
||||
}
|
||||
|
||||
void RsGxsPhotoAlbumItem::clear()
|
||||
{
|
||||
album.mCaption.clear();
|
||||
album.mCategory.clear();
|
||||
album.mDescription.clear();
|
||||
album.mHashTags.clear();
|
||||
album.mOther.clear();
|
||||
album.mPhotoPath.clear();
|
||||
album.mPhotographer.clear();
|
||||
album.mWhen.clear();
|
||||
album.mWhere.clear();
|
||||
album.mThumbnail.deleteImage();
|
||||
}
|
||||
|
||||
void RsGxsPhotoCommentItem::clear()
|
||||
{
|
||||
comment.mComment.clear();
|
||||
comment.mCommentFlag = 0;
|
||||
}
|
||||
|
||||
void RsGxsPhotoPhotoItem::clear()
|
||||
{
|
||||
photo.mCaption.clear();
|
||||
photo.mCategory.clear();
|
||||
photo.mDescription.clear();
|
||||
photo.mHashTags.clear();
|
||||
photo.mOther.clear();
|
||||
photo.mPhotographer.clear();
|
||||
photo.mWhen.clear();
|
||||
photo.mWhere.clear();
|
||||
photo.mThumbnail.deleteImage();
|
||||
}
|
96
libretroshare/src/rsitems/rsphotoitems.h
Normal file
96
libretroshare/src/rsitems/rsphotoitems.h
Normal file
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* libretroshare/src/retroshare: rsphoto.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2012 by Christopher Evi-Parker, 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RSPHOTOV2ITEMS_H_
|
||||
#define RSPHOTOV2ITEMS_H_
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/rsgxsitems.h"
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
#include "retroshare/rsphoto.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_PHOTO_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM = 0x04;
|
||||
|
||||
class RsGxsPhotoAlbumItem : public RsGxsGrpItem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsGxsPhotoAlbumItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_PHOTO,
|
||||
RS_PKT_SUBTYPE_PHOTO_ITEM) { return;}
|
||||
virtual ~RsGxsPhotoAlbumItem() { return;}
|
||||
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsPhotoAlbum album;
|
||||
};
|
||||
|
||||
class RsGxsPhotoPhotoItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsPhotoPhotoItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_PHOTO, RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM) {}
|
||||
virtual ~RsGxsPhotoPhotoItem() {}
|
||||
void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsPhotoPhoto photo;
|
||||
};
|
||||
|
||||
class RsGxsPhotoCommentItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsPhotoCommentItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_PHOTO, RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM) {}
|
||||
virtual ~RsGxsPhotoCommentItem() {}
|
||||
void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsPhotoComment comment;
|
||||
};
|
||||
|
||||
class RsGxsPhotoSerialiser : public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsPhotoSerialiser() :RsServiceSerializer(RS_SERVICE_GXS_TYPE_PHOTO) {}
|
||||
virtual ~RsGxsPhotoSerialiser() {}
|
||||
|
||||
virtual RsItem *create_item(uint16_t service, uint8_t item_sub_id) const;
|
||||
};
|
||||
|
||||
#endif /* RSPHOTOV2ITEMS_H_ */
|
73
libretroshare/src/rsitems/rspluginitems.h
Normal file
73
libretroshare/src/rsitems/rspluginitems.h
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* libretroshare/src/services: p3turtle.h
|
||||
*
|
||||
* Services for RetroShare.
|
||||
*
|
||||
* Copyright 2009 by Cyril Soler
|
||||
*
|
||||
* 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 "csoler@users.sourceforge.net".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/rsconfigitems.h"
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
const uint8_t RS_PKT_CLASS_PLUGIN_SUBTYPE_HASHSET = 0x01 ;
|
||||
|
||||
class RsPluginItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsPluginItem(uint8_t plugin_item_subtype): RsItem(RS_PKT_VERSION1,RS_PKT_CLASS_CONFIG,RS_PKT_TYPE_PLUGIN_CONFIG,plugin_item_subtype) {}
|
||||
virtual ~RsPluginItem() {}
|
||||
|
||||
virtual void clear() {}
|
||||
};
|
||||
|
||||
class RsPluginHashSetItem: public RsPluginItem
|
||||
{
|
||||
public:
|
||||
RsPluginHashSetItem() : RsPluginItem(RS_PKT_CLASS_PLUGIN_SUBTYPE_HASHSET) {}
|
||||
RsPluginHashSetItem(void *data,uint32_t size) ;
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,hashes,"hashes");
|
||||
}
|
||||
|
||||
RsTlvHashSet hashes ;
|
||||
};
|
||||
|
||||
class RsPluginSerialiser: public RsConfigSerializer
|
||||
{
|
||||
public:
|
||||
RsPluginSerialiser() : RsConfigSerializer(RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PLUGIN_CONFIG) {}
|
||||
|
||||
virtual RsItem *create_item(uint8_t class_type, uint8_t item_type) const
|
||||
{
|
||||
if(class_type == RS_PKT_TYPE_PLUGIN_CONFIG && item_type == RS_PKT_CLASS_PLUGIN_SUBTYPE_HASHSET)
|
||||
return new RsPluginHashSetItem() ;
|
||||
|
||||
return NULL ;
|
||||
}
|
||||
};
|
||||
|
||||
|
63
libretroshare/src/rsitems/rsposteditems.cc
Normal file
63
libretroshare/src/rsitems/rsposteditems.cc
Normal file
|
@ -0,0 +1,63 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/gxs: rsopsteditems.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2012-2013 by Robert Fernie, Christopher Evi-Parker
|
||||
*
|
||||
* 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 "rsitems/rsposteditems.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
void RsGxsPostedPostItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_LINK,mPost.mLink,"mPost.mLink") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG ,mPost.mNotes,"mPost.mNotes") ;
|
||||
}
|
||||
|
||||
void RsGxsPostedGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR ,mGroup.mDescription,"mGroup.mDescription") ;
|
||||
}
|
||||
|
||||
RsItem *RsGxsPostedSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) const
|
||||
{
|
||||
if(service_id != RS_SERVICE_GXS_TYPE_POSTED)
|
||||
return NULL ;
|
||||
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_POSTED_GRP_ITEM: return new RsGxsPostedGroupItem() ;
|
||||
case RS_PKT_SUBTYPE_POSTED_POST_ITEM: return new RsGxsPostedPostItem() ;
|
||||
default:
|
||||
return RsGxsCommentSerialiser::create_item(service_id,item_subtype) ;
|
||||
}
|
||||
}
|
||||
|
||||
void RsGxsPostedPostItem::clear()
|
||||
{
|
||||
mPost.mLink.clear();
|
||||
mPost.mNotes.clear();
|
||||
}
|
||||
void RsGxsPostedGroupItem::clear()
|
||||
{
|
||||
mGroup.mDescription.clear();
|
||||
}
|
49
libretroshare/src/rsitems/rsposteditems.h
Normal file
49
libretroshare/src/rsitems/rsposteditems.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
#ifndef RSPOSTEDITEMS_H
|
||||
#define RSPOSTEDITEMS_H
|
||||
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/rsgxscommentitems.h"
|
||||
#include "rsitems/rsgxsitems.h"
|
||||
|
||||
#include "retroshare/rsposted.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_POSTED_GRP_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_POSTED_POST_ITEM = 0x03;
|
||||
|
||||
class RsGxsPostedGroupItem : public RsGxsGrpItem
|
||||
{
|
||||
public:
|
||||
RsGxsPostedGroupItem() : RsGxsGrpItem(RS_SERVICE_GXS_TYPE_POSTED, RS_PKT_SUBTYPE_POSTED_GRP_ITEM) {}
|
||||
virtual ~RsGxsPostedGroupItem() {}
|
||||
|
||||
void clear();
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsPostedGroup mGroup;
|
||||
};
|
||||
|
||||
class RsGxsPostedPostItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
RsGxsPostedPostItem() : RsGxsMsgItem(RS_SERVICE_GXS_TYPE_POSTED, RS_PKT_SUBTYPE_POSTED_POST_ITEM) {}
|
||||
virtual ~RsGxsPostedPostItem() {}
|
||||
|
||||
void clear();
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsPostedPost mPost;
|
||||
};
|
||||
|
||||
class RsGxsPostedSerialiser : public RsGxsCommentSerialiser
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsPostedSerialiser() :RsGxsCommentSerialiser(RS_SERVICE_GXS_TYPE_POSTED) {}
|
||||
|
||||
virtual ~RsGxsPostedSerialiser() {}
|
||||
|
||||
virtual RsItem *create_item(uint16_t service_id,uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
|
||||
#endif // RSPOSTEDITEMS_H
|
67
libretroshare/src/rsitems/rsrttitems.cc
Normal file
67
libretroshare/src/rsitems/rsrttitems.cc
Normal file
|
@ -0,0 +1,67 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsrttitems.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2011-2013 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 "rsitems/rsrttitems.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsItem *RsRttSerialiser::create_item(uint16_t service,uint8_t type) const
|
||||
{
|
||||
if(service != RS_SERVICE_TYPE_RTT)
|
||||
return NULL ;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_RTT_PING: return new RsRttPingItem() ; //= 0x01;
|
||||
case RS_PKT_SUBTYPE_RTT_PONG: return new RsRttPongItem() ; // = 0x02;
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
void RsRttPingItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mSeqNo,"mSeqNo") ;
|
||||
RsTypeSerializer::serial_process<uint64_t>(j,ctx,mPingTS,"mPingTS") ;
|
||||
}
|
||||
|
||||
void RsRttPongItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mSeqNo,"mSeqNo") ;
|
||||
RsTypeSerializer::serial_process<uint64_t>(j,ctx,mPingTS,"mPingTS") ;
|
||||
RsTypeSerializer::serial_process<uint64_t>(j,ctx,mPongTS,"mPongTS") ;
|
||||
}
|
||||
|
||||
|
||||
|
97
libretroshare/src/rsitems/rsrttitems.h
Normal file
97
libretroshare/src/rsitems/rsrttitems.h
Normal file
|
@ -0,0 +1,97 @@
|
|||
#ifndef RS_RTT_ITEMS_H
|
||||
#define RS_RTT_ITEMS_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsrttitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2011-2013 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 <map>
|
||||
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_RTT_PING = 0x01;
|
||||
const uint8_t RS_PKT_SUBTYPE_RTT_PONG = 0x02;
|
||||
|
||||
class RsRttItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsRttItem(uint8_t subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_RTT,subtype)
|
||||
{ setPriorityLevel(QOS_PRIORITY_RS_RTT_PING) ;} // should be refined later.
|
||||
|
||||
virtual ~RsRttItem() {};
|
||||
virtual void clear() {};
|
||||
};
|
||||
|
||||
class RsRttPingItem: public RsRttItem
|
||||
{
|
||||
public:
|
||||
RsRttPingItem() :RsRttItem(RS_PKT_SUBTYPE_RTT_PING) {}
|
||||
|
||||
virtual ~RsRttPingItem(){}
|
||||
virtual void clear(){}
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
uint32_t mSeqNo;
|
||||
uint64_t mPingTS;
|
||||
};
|
||||
|
||||
class RsRttPongItem: public RsRttItem
|
||||
{
|
||||
public:
|
||||
RsRttPongItem() :RsRttItem(RS_PKT_SUBTYPE_RTT_PONG) {}
|
||||
|
||||
virtual ~RsRttPongItem(){}
|
||||
virtual void clear(){}
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
uint32_t mSeqNo;
|
||||
uint64_t mPingTS;
|
||||
uint64_t mPongTS;
|
||||
};
|
||||
|
||||
|
||||
class RsRttSerialiser: public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
RsRttSerialiser() :RsServiceSerializer(RS_SERVICE_TYPE_RTT) {}
|
||||
|
||||
virtual ~RsRttSerialiser(){}
|
||||
|
||||
virtual RsItem *create_item(uint16_t service,uint8_t type) const;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#endif /* RS_RTT_ITEMS_H */
|
||||
|
||||
|
162
libretroshare/src/rsitems/rsserviceids.h
Normal file
162
libretroshare/src/rsitems/rsserviceids.h
Normal file
|
@ -0,0 +1,162 @@
|
|||
#ifndef RS_SERVICE_IDS_H
|
||||
#define RS_SERVICE_IDS_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsserviceids.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 <inttypes.h>
|
||||
|
||||
/* Single place for Cache/Service Ids (uint16_t)
|
||||
* to 64K of them....
|
||||
*
|
||||
* Some Services/Caches are only msgs or caches...
|
||||
* but they need to be combined so that the messages/caches
|
||||
* can easily be aligned.
|
||||
*
|
||||
*/
|
||||
|
||||
/* These are Cache Only */
|
||||
const uint16_t RS_SERVICE_TYPE_FILE_INDEX = 0x0001;
|
||||
|
||||
/* These are Services only */
|
||||
const uint16_t RS_SERVICE_TYPE_DISC = 0x0011;
|
||||
const uint16_t RS_SERVICE_TYPE_CHAT = 0x0012;
|
||||
const uint16_t RS_SERVICE_TYPE_MSG = 0x0013;
|
||||
const uint16_t RS_SERVICE_TYPE_TURTLE = 0x0014;
|
||||
const uint16_t RS_SERVICE_TYPE_TUNNEL = 0x0015;
|
||||
const uint16_t RS_SERVICE_TYPE_HEARTBEAT = 0x0016;
|
||||
const uint16_t RS_SERVICE_TYPE_FILE_TRANSFER = 0x0017;
|
||||
const uint16_t RS_SERVICE_TYPE_GROUTER = 0x0018;
|
||||
const uint16_t RS_SERVICE_TYPE_FILE_DATABASE = 0x0019;
|
||||
|
||||
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;
|
||||
const uint16_t RS_SERVICE_TYPE_SERVICE_CONTROL= 0x0026;
|
||||
const uint16_t RS_SERVICE_TYPE_DISTANT_CHAT = 0x0027;
|
||||
const uint16_t RS_SERVICE_TYPE_GXS_TUNNEL = 0x0028;
|
||||
|
||||
// Non essential services.
|
||||
const uint16_t RS_SERVICE_TYPE_BANLIST = 0x0101;
|
||||
const uint16_t RS_SERVICE_TYPE_STATUS = 0x0102;
|
||||
|
||||
/* New Cache Services */
|
||||
/* Rs Network Exchange Service */
|
||||
const uint16_t RS_SERVICE_TYPE_NXS = 0x0200;
|
||||
|
||||
const uint16_t RS_SERVICE_GXS_TYPE_GXSID = 0x0211;
|
||||
const uint16_t RS_SERVICE_GXS_TYPE_PHOTO = 0x0212;
|
||||
const uint16_t RS_SERVICE_GXS_TYPE_WIKI = 0x0213;
|
||||
const uint16_t RS_SERVICE_GXS_TYPE_WIRE = 0x0214;
|
||||
const uint16_t RS_SERVICE_GXS_TYPE_FORUMS = 0x0215;
|
||||
const uint16_t RS_SERVICE_GXS_TYPE_POSTED = 0x0216;
|
||||
const uint16_t RS_SERVICE_GXS_TYPE_CHANNELS = 0x0217;
|
||||
const uint16_t RS_SERVICE_GXS_TYPE_GXSCIRCLE = 0x0218;
|
||||
// not gxs, but used with identities.
|
||||
const uint16_t RS_SERVICE_GXS_TYPE_REPUTATION = 0x0219;
|
||||
const uint16_t RS_SERVICE_TYPE_GXS_RECOGN = 0x0220;
|
||||
const uint16_t RS_SERVICE_TYPE_GXS_TRANS = 0x0230;
|
||||
|
||||
// Experimental Services.
|
||||
/* DSDV Testing at the moment - Service Only */
|
||||
const uint16_t RS_SERVICE_TYPE_DSDV = 0x1010;
|
||||
/* Latency RTT Measurements */
|
||||
const uint16_t RS_SERVICE_TYPE_RTT = 0x1011;
|
||||
|
||||
|
||||
/***************** IDS ALLOCATED FOR PLUGINS ******************/
|
||||
// 2000+
|
||||
|
||||
const uint16_t RS_SERVICE_TYPE_PLUGIN_ARADO_ID = 0x2001;
|
||||
const uint16_t RS_SERVICE_TYPE_PLUGIN_QCHESS_ID = 0x2002;
|
||||
const uint16_t RS_SERVICE_TYPE_PLUGIN_FEEDREADER = 0x2003;
|
||||
|
||||
// Reserved for packet slicing probes.
|
||||
const uint16_t RS_SERVICE_TYPE_PACKET_SLICING_PROBE = 0xAABB;
|
||||
|
||||
// Nabu's services.
|
||||
const uint16_t RS_SERVICE_TYPE_PLUGIN_FIDO_GW = 0xF1D0;
|
||||
const uint16_t RS_SERVICE_TYPE_PLUGIN_ZERORESERVE = 0xBEEF;
|
||||
|
||||
/****************** BELOW ARE ONLY THEORETICAL (CAN BE CHANGED) *****/
|
||||
/*
|
||||
* If you are planning on making a new service....
|
||||
* Test it out with an ID in the range from 0xf000 - 0xffff
|
||||
* And Change the ID everytime you make significant changes to the
|
||||
* data structures...
|
||||
*
|
||||
* eg.
|
||||
* const uint16_t RS_SERVICE_TYPE_DISTRIB_O1 = 0xf110; // First Revision.
|
||||
* const uint16_t RS_SERVICE_TYPE_DISTRIB_O2 = 0xf111; // Second Revision.
|
||||
* const uint16_t RS_SERVICE_TYPE_DISTRIB = 0xf112; // Final Revision.
|
||||
*
|
||||
* This minimises the chances of your new serialisers messing with
|
||||
* other existing, older, or proposed services.
|
||||
*
|
||||
* ONLY MOVE your Id once the service has been finalised.
|
||||
*
|
||||
*/
|
||||
|
||||
/*! for Qblog service (Cache Only) */
|
||||
//const uint16_t RS_SERVICE_TYPE_QBLOG = 0xf010;
|
||||
|
||||
/* TEST VOIP - Service only */
|
||||
// NOT SURE WHATS HAPPENING WITH THIS ONE?
|
||||
// SHOULD BE DEFINED IN PLUGIN SECTION!
|
||||
//const uint16_t RS_SERVICE_TYPE_VOIP = 0xf011;
|
||||
|
||||
/* Proxy - Service only */
|
||||
//const uint16_t RS_SERVICE_TYPE_PROXY = 0xf030;
|
||||
|
||||
/* Games/External Apps - Service Only */
|
||||
//const uint16_t RS_SERVICE_TYPE_GAME_LAUNCHER = 0xf200;
|
||||
//const uint16_t RS_SERVICE_TYPE_PORT = 0xf201;
|
||||
|
||||
/* Example Games (NOT USED YET!) */
|
||||
/* Board Games */
|
||||
//const uint16_t RS_SERVICE_TYPE_GAME_QTCHESS = 0xf211;
|
||||
//const uint16_t RS_SERVICE_TYPE_GAME_QGO = 0xf212;
|
||||
|
||||
/* Card Games */
|
||||
//const uint16_t RS_SERVICE_TYPE_GAME_BIGTWO = 0xf213;
|
||||
//const uint16_t RS_SERVICE_TYPE_GAME_POKER = 0xf214;
|
||||
|
||||
/***************** IDS ALLOCATED FOR PLUGINS ******************/
|
||||
|
||||
//const uint16_t RS_SERVICE_TYPE_PLUGIN_ARADO_TEST_ID1 = 0xf401;
|
||||
//const uint16_t RS_SERVICE_TYPE_PLUGIN_QCHESS_TEST_ID1 = 0xf402;
|
||||
|
||||
// test
|
||||
//const uint16_t RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM = 0xf403;
|
||||
|
||||
|
||||
#endif /* RS_SERVICE_IDS_H */
|
||||
|
||||
|
173
libretroshare/src/rsitems/rsserviceinfoitems.cc
Normal file
173
libretroshare/src/rsitems/rsserviceinfoitems.cc
Normal file
|
@ -0,0 +1,173 @@
|
|||
/*
|
||||
* 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/rstypeserializer.h"
|
||||
#include "rsitems/rsserviceinfoitems.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
/*************************************************************************/
|
||||
/***** RsServiceInfo ****/
|
||||
/*************************************************************************/
|
||||
|
||||
void RsServiceInfoListItem::clear()
|
||||
{
|
||||
mServiceInfo.clear();
|
||||
}
|
||||
|
||||
void RsServiceInfoListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTlvServiceInfoMapRef map(mServiceInfo);
|
||||
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,map,"map") ;
|
||||
}
|
||||
|
||||
void RsServiceInfoPermissionsItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,allowedBw,"allowedBw") ;
|
||||
}
|
||||
|
||||
RsItem *RsServiceInfoSerialiser::create_item(uint16_t service, uint8_t item_sub_id) const
|
||||
{
|
||||
if(service != RS_SERVICE_TYPE_SERVICEINFO)
|
||||
return NULL ;
|
||||
|
||||
switch(item_sub_id)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_SERVICELIST_ITEM: return new RsServiceInfoListItem() ;
|
||||
case RS_PKT_SUBTYPE_SERVICEPERMISSIONS_ITEM: return new RsServiceInfoPermissionsItem() ;
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<> std::ostream& RsTlvParamRef<RsServiceInfo>::print(std::ostream &out, uint16_t /*indent*/) const
|
||||
{
|
||||
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() const
|
||||
{
|
||||
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) const
|
||||
{
|
||||
/* 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>;
|
||||
|
109
libretroshare/src/rsitems/rsserviceinfoitems.h
Normal file
109
libretroshare/src/rsitems/rsserviceinfoitems.h
Normal file
|
@ -0,0 +1,109 @@
|
|||
#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 "rsitems/rsserviceids.h"
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/itempriorities.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();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
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(){}
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
uint32_t allowedBw; // Units are bytes/sec => 4Gb/s;
|
||||
};
|
||||
|
||||
class RsServiceInfoSerialiser: public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
RsServiceInfoSerialiser() :RsServiceSerializer(RS_SERVICE_TYPE_SERVICEINFO) {}
|
||||
virtual ~RsServiceInfoSerialiser() {}
|
||||
|
||||
virtual RsItem *create_item(uint16_t /* service */, uint8_t /* item_sub_id */) const;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#endif /* RS_SERVICE_INFO_ITEMS_H */
|
79
libretroshare/src/rsitems/rsstatusitems.h
Normal file
79
libretroshare/src/rsitems/rsstatusitems.h
Normal file
|
@ -0,0 +1,79 @@
|
|||
#ifndef RS_STATUS_ITEMS_H
|
||||
#define RS_STATUS_ITEMS_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsstatusitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Vinny Do.
|
||||
*
|
||||
* 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 "rsitems/rsserviceids.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
#include "rsitems/rsitem.h"
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
class RsStatusItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsStatusItem() :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_STATUS, RS_PKT_SUBTYPE_DEFAULT)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_STATUS_ITEM);
|
||||
}
|
||||
virtual ~RsStatusItem() {}
|
||||
virtual void clear() {}
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,sendTime,"sendTime") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,status ,"status") ;
|
||||
}
|
||||
|
||||
uint32_t sendTime;
|
||||
uint32_t status;
|
||||
|
||||
/* not serialised */
|
||||
uint32_t recvTime;
|
||||
};
|
||||
|
||||
class RsStatusSerialiser: public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
RsStatusSerialiser() :RsServiceSerializer(RS_SERVICE_TYPE_STATUS) {}
|
||||
virtual ~RsStatusSerialiser() {}
|
||||
|
||||
virtual RsItem *create_item(uint16_t service,uint8_t item_subtype) const
|
||||
{
|
||||
if(service == RS_SERVICE_TYPE_STATUS && item_subtype == RS_PKT_SUBTYPE_DEFAULT)
|
||||
return new RsStatusItem();
|
||||
else
|
||||
return NULL ;
|
||||
}
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#endif /* RS_STATUS_ITEMS_H */
|
||||
|
||||
|
84
libretroshare/src/rsitems/rswikiitems.cc
Normal file
84
libretroshare/src/rsitems/rswikiitems.cc
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rswikiitems.cc
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-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".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "rsitems/rswikiitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
#define GXSID_DEBUG 1
|
||||
|
||||
RsItem *RsGxsWikiSerialiser::create_item(uint16_t service, uint8_t item_sub_id) const
|
||||
{
|
||||
if(service != RS_SERVICE_GXS_TYPE_WIKI)
|
||||
return NULL ;
|
||||
|
||||
switch(item_sub_id)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM: return new RsGxsWikiCollectionItem();
|
||||
case RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM: return new RsGxsWikiCommentItem();
|
||||
case RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM: return new RsGxsWikiSnapshotItem();
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
void RsGxsWikiCollectionItem::clear()
|
||||
{
|
||||
collection.mDescription.clear();
|
||||
collection.mCategory.clear();
|
||||
collection.mHashTags.clear();
|
||||
}
|
||||
|
||||
void RsGxsWikiCollectionItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR ,collection.mDescription,"collection.mDescription") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_CATEGORY,collection.mCategory ,"collection.mCategory") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG,collection.mHashTags ,"collection.mHashTags") ;
|
||||
}
|
||||
|
||||
void RsGxsWikiSnapshotItem::clear()
|
||||
{
|
||||
snapshot.mPage.clear();
|
||||
snapshot.mHashTags.clear();
|
||||
}
|
||||
|
||||
void RsGxsWikiSnapshotItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_WIKI_PAGE,snapshot.mPage,"snapshot.mPage") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG ,snapshot.mPage,"snapshot.mHashTags") ;
|
||||
}
|
||||
|
||||
void RsGxsWikiCommentItem::clear()
|
||||
{
|
||||
comment.mComment.clear();
|
||||
}
|
||||
|
||||
void RsGxsWikiCommentItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_COMMENT,comment.mComment,"comment.mComment") ;
|
||||
}
|
||||
|
90
libretroshare/src/rsitems/rswikiitems.h
Normal file
90
libretroshare/src/rsitems/rswikiitems.h
Normal file
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rswikiitems.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-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".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RS_WIKI_ITEMS_H
|
||||
#define RS_WIKI_ITEMS_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/rsgxsitems.h"
|
||||
|
||||
#include "retroshare/rswiki.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM = 0x04;
|
||||
|
||||
class RsGxsWikiCollectionItem : public RsGxsGrpItem
|
||||
{
|
||||
public:
|
||||
RsGxsWikiCollectionItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_WIKI, RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM) {}
|
||||
virtual ~RsGxsWikiCollectionItem() {}
|
||||
|
||||
void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsWikiCollection collection;
|
||||
};
|
||||
|
||||
class RsGxsWikiSnapshotItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsWikiSnapshotItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_WIKI, RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM) {}
|
||||
virtual ~RsGxsWikiSnapshotItem() {}
|
||||
void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsWikiSnapshot snapshot;
|
||||
};
|
||||
|
||||
class RsGxsWikiCommentItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsWikiCommentItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_WIKI, RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM) {}
|
||||
virtual ~RsGxsWikiCommentItem() {}
|
||||
void clear();
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsWikiComment comment;
|
||||
|
||||
};
|
||||
|
||||
class RsGxsWikiSerialiser : public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsWikiSerialiser() :RsServiceSerializer(RS_SERVICE_GXS_TYPE_WIKI) {}
|
||||
virtual ~RsGxsWikiSerialiser() {}
|
||||
|
||||
virtual RsItem *create_item(uint16_t /* service */, uint8_t /* item_sub_id */) const;
|
||||
};
|
||||
|
||||
#endif /* RS_WIKI_ITEMS_H */
|
64
libretroshare/src/rsitems/rswireitems.cc
Normal file
64
libretroshare/src/rsitems/rswireitems.cc
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rswikiitems.cc
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-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".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "rswireitems.h"
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
#define WIRE_DEBUG 1
|
||||
|
||||
|
||||
RsItem *RsGxsWireSerialiser::create_item(uint16_t service,uint8_t item_subtype) const
|
||||
{
|
||||
if(service != RS_SERVICE_GXS_TYPE_WIRE)
|
||||
return NULL ;
|
||||
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_WIRE_GROUP_ITEM: return new RsGxsWireGroupItem();
|
||||
case RS_PKT_SUBTYPE_WIRE_PULSE_ITEM: return new RsGxsWirePulseItem();
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
void RsGxsWireGroupItem::clear()
|
||||
{
|
||||
group.mDescription.clear();
|
||||
}
|
||||
|
||||
void RsGxsWireGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR,group.mDescription,"group.mDescription") ;
|
||||
}
|
||||
|
||||
void RsGxsWirePulseItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,pulse.mPulseText,"pulse.mPulseText") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG,pulse.mHashTags,"pulse.mHashTags") ;
|
||||
}
|
||||
|
79
libretroshare/src/rsitems/rswireitems.h
Normal file
79
libretroshare/src/rsitems/rswireitems.h
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rswireitems.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-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".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RS_WIRE_ITEMS_H
|
||||
#define RS_WIRE_ITEMS_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
//#include "serialiser/rstlvtypes.h"
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
#include "retroshare/rswire.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_WIRE_GROUP_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_WIRE_PULSE_ITEM = 0x03;
|
||||
|
||||
class RsGxsWireGroupItem : public RsGxsGrpItem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsGxsWireGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_WIRE, RS_PKT_SUBTYPE_WIRE_GROUP_ITEM) {}
|
||||
virtual ~RsGxsWireGroupItem() {}
|
||||
|
||||
void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsWireGroup group;
|
||||
};
|
||||
|
||||
class RsGxsWirePulseItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsWirePulseItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_WIRE, RS_PKT_SUBTYPE_WIRE_PULSE_ITEM) {}
|
||||
virtual ~RsGxsWirePulseItem() {}
|
||||
void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsWirePulse pulse;
|
||||
};
|
||||
|
||||
class RsGxsWireSerialiser : public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsWireSerialiser() :RsServiceSerializer(RS_SERVICE_GXS_TYPE_WIRE) {}
|
||||
virtual ~RsGxsWireSerialiser() {}
|
||||
|
||||
virtual RsItem *create_item(uint16_t service,uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
#endif /* RS_WIKI_ITEMS_H */
|
Loading…
Add table
Add a link
Reference in a new issue