mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 00:19:25 -05:00
fixed up tlv serialisers:
- Added RsTvlUnit: public RsTlvItem, which handles some of the infrstructure. - made TlvSize() SetTlv() and print() const. - split rstlvtypes into its bits and cleaned up header files. - added templated RsTlvList, imilar to cyrils id one. - removed GXS_GEN_TESTNET - cleanedup rsserviceids. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7215 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
1042744685
commit
600639db51
@ -27,8 +27,10 @@
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <retroshare/rstypes.h>
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "serialiser/rsgxsitems.h"
|
||||
|
||||
|
@ -8,7 +8,7 @@ TARGET = retroshare
|
||||
# This should be disabled for releases until further notice.
|
||||
CONFIG += gxs debug
|
||||
|
||||
#CONFIG += dsdv
|
||||
CONFIG += dsdv
|
||||
|
||||
profiling {
|
||||
QMAKE_CXXFLAGS -= -fomit-frame-pointer
|
||||
@ -399,12 +399,18 @@ HEADERS += serialiser/rsbaseserial.h \
|
||||
serialiser/rsstatusitems.h \
|
||||
serialiser/rstlvaddrs.h \
|
||||
serialiser/rstlvbase.h \
|
||||
serialiser/rstlvitem.h \
|
||||
serialiser/rstlvidset.h \
|
||||
serialiser/rstlvfileitem.h \
|
||||
serialiser/rstlvimage.h \
|
||||
serialiser/rstlvstring.h \
|
||||
serialiser/rstlvbinary.h \
|
||||
serialiser/rstlvkeys.h \
|
||||
serialiser/rstlvkvwide.h \
|
||||
serialiser/rstlvtypes.h \
|
||||
serialiser/rstlvkeyvalue.h \
|
||||
serialiser/rstlvgenericparam.h \
|
||||
serialiser/rstlvgenericmap.h \
|
||||
serialiser/rstlvgenericmap.inl \
|
||||
serialiser/rstlvlist.h \
|
||||
serialiser/rstlvmaps.h \
|
||||
serialiser/rstlvutil.h \
|
||||
serialiser/rstlvbanlist.h \
|
||||
@ -541,11 +547,14 @@ SOURCES += serialiser/rsbaseserial.cc \
|
||||
serialiser/rsstatusitems.cc \
|
||||
serialiser/rstlvaddrs.cc \
|
||||
serialiser/rstlvbase.cc \
|
||||
serialiser/rstlvitem.cc \
|
||||
serialiser/rstlvidset.cc \
|
||||
serialiser/rstlvfileitem.cc \
|
||||
serialiser/rstlvimage.cc \
|
||||
serialiser/rstlvstring.cc \
|
||||
serialiser/rstlvbinary.cc \
|
||||
serialiser/rstlvkeys.cc \
|
||||
serialiser/rstlvkvwide.cc \
|
||||
serialiser/rstlvtypes.cc \
|
||||
serialiser/rstlvkeyvalue.cc \
|
||||
serialiser/rstlvgenericparam.cc \
|
||||
serialiser/rstlvutil.cc \
|
||||
serialiser/rstlvbanlist.cc \
|
||||
@ -640,8 +649,6 @@ SOURCES += zeroconf/p3zcnatassist.cc \
|
||||
gxs {
|
||||
DEFINES *= RS_ENABLE_GXS
|
||||
DEFINES *= SQLITE_HAS_CODEC
|
||||
|
||||
DEFINES *= GXS_DEV_TESTNET
|
||||
DEFINES *= GXS_ENABLE_SYNC_MSGS
|
||||
|
||||
HEADERS += serialiser/rsnxsitems.h \
|
||||
|
@ -2,10 +2,16 @@
|
||||
|
||||
#include "pluginmanager.h"
|
||||
#include <dirent.h>
|
||||
|
||||
#if 0
|
||||
#include <serialiser/rsserial.h>
|
||||
#include <serialiser/rstlvbase.h>
|
||||
#include <serialiser/rstlvtypes.h>
|
||||
#endif
|
||||
|
||||
#include <serialiser/rspluginitems.h>
|
||||
|
||||
|
||||
#include <rsserver/p3face.h>
|
||||
#include <util/rsdir.h>
|
||||
#include <util/folderiterator.h>
|
||||
|
@ -164,7 +164,8 @@ void pqiIpAddrList::extractFromTlv(const RsTlvIpAddrSet &tlvAddrs)
|
||||
{
|
||||
std::list<RsTlvIpAddressInfo>::const_iterator it;
|
||||
|
||||
for(it = tlvAddrs.addrs.begin(); it != tlvAddrs.addrs.end() ; ++it)
|
||||
//for(it = tlvAddrs.addrs.begin(); it != tlvAddrs.addrs.end() ; ++it)
|
||||
for(it = tlvAddrs.mList.begin(); it != tlvAddrs.mList.end() ; ++it)
|
||||
{
|
||||
pqiIpAddress addr;
|
||||
addr.mAddr = it->addr.addr;
|
||||
@ -186,7 +187,8 @@ void pqiIpAddrList::loadTlv(RsTlvIpAddrSet &tlvAddrs) const
|
||||
addr.seenTime = it->mSeenTime;
|
||||
addr.source = it->mSrc;
|
||||
|
||||
tlvAddrs.addrs.push_back(addr);
|
||||
//tlvAddrs.addrs.push_back(addr);
|
||||
tlvAddrs.mList.push_back(addr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,9 +96,9 @@ void RsServer::rsGlobalShutDown()
|
||||
if(mGxsChannels) mGxsChannels->join();
|
||||
if(mGxsIdService) mGxsIdService->join();
|
||||
if(mPosted) mPosted->join();
|
||||
//if(mPhoto) mPhoto->join();
|
||||
if(mWiki) mWiki->join();
|
||||
if(mWire) mWire->join();
|
||||
//if(mPhoto) mPhoto->join();
|
||||
//if(mWire) mWire->join();
|
||||
#endif
|
||||
|
||||
AuthGPG::exit();
|
||||
|
@ -1300,29 +1300,9 @@ int RsServer::StartupRetroShare()
|
||||
|
||||
#ifdef RS_ENABLE_GXS
|
||||
|
||||
// The idea is that if priorGxsDir is non
|
||||
// empty and matches an exist directory location
|
||||
// the given ssl user id then this directory is cleaned
|
||||
// and deleted
|
||||
std::string priorGxsDir = "./" + mLinkMgr->getOwnId().toStdString() + "/";
|
||||
std::string currGxsDir = rsAccounts.PathAccountDirectory() + "/GXS_phase2";
|
||||
std::string currGxsDir = rsAccounts.PathAccountDirectory() + "/gxs";
|
||||
currGxsDir += "_FINALTESTS";
|
||||
|
||||
#ifdef GXS_DEV_TESTNET // Different Directory for testing.
|
||||
currGxsDir += "_TESTNET10";
|
||||
#endif
|
||||
|
||||
if(!priorGxsDir.empty())
|
||||
RsDirUtil::checkDirectory(priorGxsDir);
|
||||
|
||||
std::set<std::string> filesToKeep;
|
||||
bool cleanUpSuccess = RsDirUtil::cleanupDirectory(priorGxsDir, filesToKeep);
|
||||
|
||||
if(!cleanUpSuccess)
|
||||
std::cerr << "RsInit::StartupRetroShare() Clean up of Old Gxs Dir Failed!";
|
||||
else
|
||||
rmdir(priorGxsDir.c_str());
|
||||
|
||||
// TODO: temporary to store GXS service data, remove
|
||||
RsDirUtil::checkCreateDirectory(currGxsDir);
|
||||
|
||||
RsNxsNetMgr* nxsMgr = new RsNxsNetMgrImpl(serviceCtrl);
|
||||
@ -1330,23 +1310,19 @@ int RsServer::StartupRetroShare()
|
||||
/**** Identity service ****/
|
||||
|
||||
RsGeneralDataService* gxsid_ds = new RsDataService(currGxsDir + "/", "gxsid_db",
|
||||
RS_SERVICE_GXSV2_TYPE_GXSID, NULL, RsInitConfig::gxs_passwd);
|
||||
|
||||
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
|
||||
gxsid_ds->resetDataStore();
|
||||
#endif
|
||||
RS_SERVICE_GXS_TYPE_GXSID, NULL, RsInitConfig::gxs_passwd);
|
||||
|
||||
// init gxs services
|
||||
mGxsIdService = new p3IdService(gxsid_ds, NULL);
|
||||
|
||||
RsGeneralDataService* gxscircles_ds = new RsDataService(currGxsDir + "/", "gxscircles_db",
|
||||
RS_SERVICE_GXSV2_TYPE_GXSCIRCLE, NULL, RsInitConfig::gxs_passwd);
|
||||
RS_SERVICE_GXS_TYPE_GXSCIRCLE, NULL, RsInitConfig::gxs_passwd);
|
||||
|
||||
mGxsCircles = new p3GxsCircles(gxscircles_ds, NULL, mGxsIdService);
|
||||
|
||||
// create GXS ID service
|
||||
RsGxsNetService* gxsid_ns = new RsGxsNetService(
|
||||
RS_SERVICE_GXSV2_TYPE_GXSID, gxsid_ds, nxsMgr,
|
||||
RS_SERVICE_GXS_TYPE_GXSID, gxsid_ds, nxsMgr,
|
||||
mGxsIdService, mGxsIdService->getServiceInfo(),
|
||||
mGxsIdService, mGxsCircles,
|
||||
false); // don't synchronise group automatic (need explicit group request)
|
||||
@ -1355,54 +1331,29 @@ int RsServer::StartupRetroShare()
|
||||
/**** GxsCircle service ****/
|
||||
|
||||
|
||||
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
|
||||
gxscircles_ds->resetDataStore();
|
||||
#endif
|
||||
|
||||
// init gxs services
|
||||
mGxsCircles = new p3GxsCircles(gxscircles_ds, NULL, mGxsIdService);
|
||||
|
||||
// create GXS Circle service
|
||||
RsGxsNetService* gxscircles_ns = new RsGxsNetService(
|
||||
RS_SERVICE_GXSV2_TYPE_GXSCIRCLE, gxscircles_ds, nxsMgr,
|
||||
RS_SERVICE_GXS_TYPE_GXSCIRCLE, gxscircles_ds, nxsMgr,
|
||||
mGxsCircles, mGxsCircles->getServiceInfo(),
|
||||
mGxsIdService, mGxsCircles);
|
||||
|
||||
|
||||
/**** Photo service ****/
|
||||
RsGeneralDataService* photo_ds = new RsDataService(currGxsDir + "/", "photoV2_db",
|
||||
RS_SERVICE_GXSV2_TYPE_PHOTO, NULL, RsInitConfig::gxs_passwd);
|
||||
|
||||
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
|
||||
photo_ds->resetDataStore(); //TODO: remove, new service data per RS session, for testing
|
||||
#endif
|
||||
|
||||
// init gxs services
|
||||
mPhoto = new p3PhotoService(photo_ds, NULL, mGxsIdService);
|
||||
|
||||
// create GXS photo service
|
||||
RsGxsNetService* photo_ns = new RsGxsNetService(
|
||||
RS_SERVICE_GXSV2_TYPE_PHOTO, photo_ds, nxsMgr,
|
||||
mPhoto, mPhoto->getServiceInfo(),
|
||||
mGxsIdService, mGxsCircles);
|
||||
|
||||
/**** Posted GXS service ****/
|
||||
|
||||
|
||||
|
||||
RsGeneralDataService* posted_ds = new RsDataService(currGxsDir + "/", "posted_db",
|
||||
RS_SERVICE_GXSV2_TYPE_POSTED,
|
||||
RS_SERVICE_GXS_TYPE_POSTED,
|
||||
NULL, RsInitConfig::gxs_passwd);
|
||||
|
||||
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
|
||||
posted_ds->resetDataStore(); //TODO: remove, new service data per RS session, for testing
|
||||
#endif
|
||||
|
||||
mPosted = new p3Posted(posted_ds, NULL, mGxsIdService);
|
||||
|
||||
// create GXS photo service
|
||||
RsGxsNetService* posted_ns = new RsGxsNetService(
|
||||
RS_SERVICE_GXSV2_TYPE_POSTED, posted_ds, nxsMgr,
|
||||
RS_SERVICE_GXS_TYPE_POSTED, posted_ds, nxsMgr,
|
||||
mPosted, mPosted->getServiceInfo(),
|
||||
mGxsIdService, mGxsCircles);
|
||||
|
||||
@ -1410,56 +1361,29 @@ int RsServer::StartupRetroShare()
|
||||
|
||||
|
||||
RsGeneralDataService* wiki_ds = new RsDataService(currGxsDir + "/", "wiki_db",
|
||||
RS_SERVICE_GXSV2_TYPE_WIKI,
|
||||
RS_SERVICE_GXS_TYPE_WIKI,
|
||||
NULL, RsInitConfig::gxs_passwd);
|
||||
|
||||
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
|
||||
wiki_ds->resetDataStore(); //TODO: remove, new service data per RS session, for testing
|
||||
#endif
|
||||
|
||||
mWiki = new p3Wiki(wiki_ds, NULL, mGxsIdService);
|
||||
|
||||
// create GXS photo service
|
||||
RsGxsNetService* wiki_ns = new RsGxsNetService(
|
||||
RS_SERVICE_GXSV2_TYPE_WIKI, wiki_ds, nxsMgr,
|
||||
RS_SERVICE_GXS_TYPE_WIKI, wiki_ds, nxsMgr,
|
||||
mWiki, mWiki->getServiceInfo(),
|
||||
mGxsIdService, mGxsCircles);
|
||||
|
||||
|
||||
/**** Wire GXS service ****/
|
||||
|
||||
|
||||
RsGeneralDataService* wire_ds = new RsDataService(currGxsDir + "/", "wire_db",
|
||||
RS_SERVICE_GXSV2_TYPE_WIRE,
|
||||
NULL, RsInitConfig::gxs_passwd);
|
||||
|
||||
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
|
||||
wire_ds->resetDataStore(); //TODO: remove, new service data per RS session, for testing
|
||||
#endif
|
||||
|
||||
mWire = new p3Wire(wire_ds, NULL, mGxsIdService);
|
||||
|
||||
// create GXS photo service
|
||||
RsGxsNetService* wire_ns = new RsGxsNetService(
|
||||
RS_SERVICE_GXSV2_TYPE_WIRE, wire_ds, nxsMgr,
|
||||
mWire, mWire->getServiceInfo(),
|
||||
mGxsIdService, mGxsCircles);
|
||||
|
||||
|
||||
/**** Forum GXS service ****/
|
||||
|
||||
RsGeneralDataService* gxsforums_ds = new RsDataService(currGxsDir + "/", "gxsforums_db",
|
||||
RS_SERVICE_GXSV2_TYPE_FORUMS, NULL, RsInitConfig::gxs_passwd);
|
||||
RS_SERVICE_GXS_TYPE_FORUMS, NULL, RsInitConfig::gxs_passwd);
|
||||
|
||||
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
|
||||
gxsforums_ds->resetDataStore(); //TODO: remove, new service data per RS session, for testing
|
||||
#endif
|
||||
|
||||
mGxsForums = new p3GxsForums(gxsforums_ds, NULL, mGxsIdService);
|
||||
|
||||
// create GXS photo service
|
||||
RsGxsNetService* gxsforums_ns = new RsGxsNetService(
|
||||
RS_SERVICE_GXSV2_TYPE_FORUMS, gxsforums_ds, nxsMgr,
|
||||
RS_SERVICE_GXS_TYPE_FORUMS, gxsforums_ds, nxsMgr,
|
||||
mGxsForums, mGxsForums->getServiceInfo(),
|
||||
mGxsIdService, mGxsCircles);
|
||||
|
||||
@ -1467,28 +1391,55 @@ int RsServer::StartupRetroShare()
|
||||
/**** Channel GXS service ****/
|
||||
|
||||
RsGeneralDataService* gxschannels_ds = new RsDataService(currGxsDir + "/", "gxschannels_db",
|
||||
RS_SERVICE_GXSV2_TYPE_CHANNELS, NULL, RsInitConfig::gxs_passwd);
|
||||
|
||||
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
|
||||
gxschannels_ds->resetDataStore(); //TODO: remove, new service data per RS session, for testing
|
||||
#endif
|
||||
RS_SERVICE_GXS_TYPE_CHANNELS, NULL, RsInitConfig::gxs_passwd);
|
||||
|
||||
mGxsChannels = new p3GxsChannels(gxschannels_ds, NULL, mGxsIdService);
|
||||
|
||||
// create GXS photo service
|
||||
RsGxsNetService* gxschannels_ns = new RsGxsNetService(
|
||||
RS_SERVICE_GXSV2_TYPE_CHANNELS, gxschannels_ds, nxsMgr,
|
||||
RS_SERVICE_GXS_TYPE_CHANNELS, gxschannels_ds, nxsMgr,
|
||||
mGxsChannels, mGxsChannels->getServiceInfo(),
|
||||
mGxsIdService, mGxsCircles);
|
||||
|
||||
|
||||
|
||||
#if 0 // PHOTO IS DISABLED FOR THE MOMENT
|
||||
/**** Photo service ****/
|
||||
RsGeneralDataService* photo_ds = new RsDataService(currGxsDir + "/", "photoV2_db",
|
||||
RS_SERVICE_GXS_TYPE_PHOTO, NULL, RsInitConfig::gxs_passwd);
|
||||
|
||||
// init gxs services
|
||||
mPhoto = new p3PhotoService(photo_ds, NULL, mGxsIdService);
|
||||
|
||||
// create GXS photo service
|
||||
RsGxsNetService* photo_ns = new RsGxsNetService(
|
||||
RS_SERVICE_GXS_TYPE_PHOTO, photo_ds, nxsMgr,
|
||||
mPhoto, mPhoto->getServiceInfo(),
|
||||
mGxsIdService, mGxsCircles);
|
||||
#endif
|
||||
|
||||
#if 0 // WIRE IS DISABLED FOR THE MOMENT
|
||||
/**** Wire GXS service ****/
|
||||
RsGeneralDataService* wire_ds = new RsDataService(currGxsDir + "/", "wire_db",
|
||||
RS_SERVICE_GXS_TYPE_WIRE,
|
||||
NULL, RsInitConfig::gxs_passwd);
|
||||
|
||||
mWire = new p3Wire(wire_ds, NULL, mGxsIdService);
|
||||
|
||||
// create GXS photo service
|
||||
RsGxsNetService* wire_ns = new RsGxsNetService(
|
||||
RS_SERVICE_GXS_TYPE_WIRE, wire_ds, nxsMgr,
|
||||
mWire, mWire->getServiceInfo(),
|
||||
mGxsIdService, mGxsCircles);
|
||||
#endif
|
||||
// now add to p3service
|
||||
pqih->addService(gxsid_ns, true);
|
||||
pqih->addService(gxscircles_ns, true);
|
||||
pqih->addService(photo_ns, true);
|
||||
pqih->addService(posted_ns, true);
|
||||
pqih->addService(wiki_ns, true);
|
||||
pqih->addService(gxsforums_ns, true);
|
||||
pqih->addService(gxschannels_ns, true);
|
||||
//pqih->addService(photo_ns, true);
|
||||
|
||||
// remove pword from memory
|
||||
RsInitConfig::gxs_passwd = "";
|
||||
@ -1652,9 +1603,9 @@ int RsServer::StartupRetroShare()
|
||||
mConfigMgr->addConfiguration("gxschannels.cfg", gxschannels_ns);
|
||||
mConfigMgr->addConfiguration("gxscircles.cfg", gxscircles_ns);
|
||||
mConfigMgr->addConfiguration("posted.cfg", posted_ns);
|
||||
mConfigMgr->addConfiguration("wire.cfg", wire_ns);
|
||||
mConfigMgr->addConfiguration("wiki.cfg", wiki_ns);
|
||||
mConfigMgr->addConfiguration("photo.cfg", photo_ns);
|
||||
//mConfigMgr->addConfiguration("photo.cfg", photo_ns);
|
||||
//mConfigMgr->addConfiguration("wire.cfg", wire_ns);
|
||||
#endif
|
||||
|
||||
mPluginsManager->addConfigurations(mConfigMgr) ;
|
||||
@ -1763,31 +1714,33 @@ int RsServer::StartupRetroShare()
|
||||
rsGxsCircles = mGxsCircles;
|
||||
rsWiki = mWiki;
|
||||
rsPosted = mPosted;
|
||||
rsPhoto = mPhoto;
|
||||
rsGxsForums = mGxsForums;
|
||||
rsGxsChannels = mGxsChannels;
|
||||
rsWire = mWire;
|
||||
//rsPhoto = mPhoto;
|
||||
//rsWire = mWire;
|
||||
|
||||
/*** start up GXS core runner ***/
|
||||
createThread(*mGxsIdService);
|
||||
createThread(*mGxsCircles);
|
||||
createThread(*mPhoto);
|
||||
createThread(*mPosted);
|
||||
createThread(*mWiki);
|
||||
createThread(*mWire);
|
||||
createThread(*mGxsForums);
|
||||
createThread(*mGxsChannels);
|
||||
|
||||
//createThread(*mPhoto);
|
||||
//createThread(*mWire);
|
||||
|
||||
// cores ready start up GXS net servers
|
||||
createThread(*gxsid_ns);
|
||||
createThread(*gxscircles_ns);
|
||||
createThread(*photo_ns);
|
||||
createThread(*posted_ns);
|
||||
createThread(*wiki_ns);
|
||||
createThread(*wire_ns);
|
||||
createThread(*gxsforums_ns);
|
||||
createThread(*gxschannels_ns);
|
||||
|
||||
//createThread(*photo_ns);
|
||||
//createThread(*wire_ns);
|
||||
|
||||
#endif // RS_ENABLE_GXS
|
||||
|
||||
ftserver->StartupThreads();
|
||||
|
@ -30,7 +30,6 @@
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvbanlist.h"
|
||||
|
||||
#define RS_PKT_SUBTYPE_BANLIST_ITEM 0x01
|
||||
|
@ -31,9 +31,16 @@
|
||||
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "serialiser/rstlvfileitem.h"
|
||||
#include "serialiser/rstlvkeyvalue.h"
|
||||
#include "serialiser/rstlvaddrs.h"
|
||||
|
||||
#if 0
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvaddrs.h"
|
||||
#endif
|
||||
|
||||
class RsGroupInfo;
|
||||
|
||||
|
@ -24,14 +24,16 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rsdiscovery2items.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#if 0
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsdiscovery2items.h"
|
||||
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#endif
|
||||
|
||||
/***
|
||||
* #define RSSERIAL_DEBUG 1
|
||||
|
@ -29,10 +29,9 @@
|
||||
#define RS_DISC_ITEMS_H
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "serialiser/rstlvaddrs.h"
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_DISC_PGP_LIST = 0x01;
|
||||
const uint8_t RS_PKT_SUBTYPE_DISC_PGP_CERT = 0x02;
|
||||
|
@ -31,7 +31,7 @@
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvbinary.h"
|
||||
#include "serialiser/rstlvdsdv.h"
|
||||
|
||||
/**************************************************************************/
|
||||
|
@ -29,9 +29,11 @@
|
||||
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
//#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvfileitem.h"
|
||||
#include "serialiser/rsserviceids.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;
|
||||
|
@ -89,7 +89,7 @@ RsItem* RsGxsChannelSerialiser::deserialise(void* data, uint32_t* size)
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_CHANNELS != getRsItemService(rstype)))
|
||||
(RS_SERVICE_GXS_TYPE_CHANNELS != getRsItemService(rstype)))
|
||||
{
|
||||
#ifdef GXSCHANNEL_DEBUG
|
||||
std::cerr << "RsGxsChannelSerialiser::deserialise() ERROR Wrong Type" << std::endl;
|
||||
@ -255,7 +255,7 @@ RsGxsChannelGroupItem* RsGxsChannelSerialiser::deserialiseGxsChannelGroupItem(vo
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_CHANNELS != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_CHANNELS != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSCHANNEL_GROUP_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSCHANNEL_DEBUG
|
||||
@ -478,7 +478,7 @@ RsGxsChannelPostItem* RsGxsChannelSerialiser::deserialiseGxsChannelPostItem(void
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_CHANNELS != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_CHANNELS != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSCHANNEL_DEBUG
|
||||
|
@ -30,7 +30,9 @@
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
//#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvfileitem.h"
|
||||
#include "serialiser/rstlvimage.h"
|
||||
|
||||
#include "serialiser/rsgxscommentitems.h"
|
||||
|
||||
@ -47,7 +49,7 @@ class RsGxsChannelGroupItem : public RsGxsGrpItem
|
||||
|
||||
public:
|
||||
|
||||
RsGxsChannelGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV2_TYPE_CHANNELS,
|
||||
RsGxsChannelGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_CHANNELS,
|
||||
RS_PKT_SUBTYPE_GXSCHANNEL_GROUP_ITEM) { return;}
|
||||
virtual ~RsGxsChannelGroupItem() { return;}
|
||||
|
||||
@ -66,7 +68,7 @@ class RsGxsChannelPostItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsChannelPostItem(): RsGxsMsgItem(RS_SERVICE_GXSV2_TYPE_CHANNELS,
|
||||
RsGxsChannelPostItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_CHANNELS,
|
||||
RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM) {return; }
|
||||
virtual ~RsGxsChannelPostItem() { return;}
|
||||
void clear();
|
||||
@ -88,7 +90,7 @@ class RsGxsChannelSerialiser : public RsGxsCommentSerialiser
|
||||
public:
|
||||
|
||||
RsGxsChannelSerialiser()
|
||||
:RsGxsCommentSerialiser(RS_SERVICE_GXSV2_TYPE_CHANNELS)
|
||||
:RsGxsCommentSerialiser(RS_SERVICE_GXS_TYPE_CHANNELS)
|
||||
{ return; }
|
||||
virtual ~RsGxsChannelSerialiser() { return; }
|
||||
|
||||
|
@ -74,7 +74,7 @@ RsItem* RsGxsCircleSerialiser::deserialise(void* data, uint32_t* size)
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_GXSCIRCLE != getRsItemService(rstype)))
|
||||
(RS_SERVICE_GXS_TYPE_GXSCIRCLE != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
@ -277,7 +277,7 @@ RsGxsCircleGroupItem* RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem(void
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_GXSCIRCLE != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_GXSCIRCLE != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
@ -427,7 +427,7 @@ RsGxsCircleMsgItem* RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem(void *dat
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_GXSCIRCLE != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_GXSCIRCLE != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
|
@ -30,7 +30,8 @@
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvitem.h"
|
||||
#include "serialiser/rstlvstring.h"
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
#include "retroshare/rsgxscircles.h"
|
||||
@ -47,7 +48,7 @@ class RsGxsCircleGroupItem : public RsGxsGrpItem
|
||||
|
||||
public:
|
||||
|
||||
RsGxsCircleGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV2_TYPE_GXSCIRCLE,
|
||||
RsGxsCircleGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_GXSCIRCLE,
|
||||
RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM),
|
||||
pgpIdSet(GXSCIRCLE_PGPIDSET),
|
||||
gxsIdSet(GXSCIRCLE_GXSIDSET),
|
||||
@ -70,7 +71,7 @@ class RsGxsCircleMsgItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsCircleMsgItem(): RsGxsMsgItem(RS_SERVICE_GXSV2_TYPE_GXSCIRCLE,
|
||||
RsGxsCircleMsgItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_GXSCIRCLE,
|
||||
RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM) {return; }
|
||||
virtual ~RsGxsCircleMsgItem() { return;}
|
||||
void clear();
|
||||
@ -83,7 +84,7 @@ class RsGxsCircleSerialiser : public RsSerialType
|
||||
public:
|
||||
|
||||
RsGxsCircleSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV2_TYPE_GXSCIRCLE)
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_GXSCIRCLE)
|
||||
{ return; }
|
||||
virtual ~RsGxsCircleSerialiser() { return; }
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
//#include "serialiser/rstlvtypes.h"
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
|
||||
|
@ -76,7 +76,7 @@ RsItem* RsGxsForumSerialiser::deserialise(void* data, uint32_t* size)
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_FORUMS != getRsItemService(rstype)))
|
||||
(RS_SERVICE_GXS_TYPE_FORUMS != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
@ -198,7 +198,7 @@ RsGxsForumGroupItem* RsGxsForumSerialiser::deserialiseGxsForumGroupItem(void *da
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_FORUMS != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_FORUMS != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
@ -346,7 +346,7 @@ RsGxsForumMsgItem* RsGxsForumSerialiser::deserialiseGxsForumMsgItem(void *data,
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_FORUMS != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_FORUMS != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
//#include "serialiser/rstlvtypes.h"
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
#include "retroshare/rsgxsforums.h"
|
||||
@ -43,7 +43,7 @@ class RsGxsForumGroupItem : public RsGxsGrpItem
|
||||
|
||||
public:
|
||||
|
||||
RsGxsForumGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV2_TYPE_FORUMS,
|
||||
RsGxsForumGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_FORUMS,
|
||||
RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM) { return;}
|
||||
virtual ~RsGxsForumGroupItem() { return;}
|
||||
|
||||
@ -58,7 +58,7 @@ class RsGxsForumMsgItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsForumMsgItem(): RsGxsMsgItem(RS_SERVICE_GXSV2_TYPE_FORUMS,
|
||||
RsGxsForumMsgItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_FORUMS,
|
||||
RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM) {return; }
|
||||
virtual ~RsGxsForumMsgItem() { return;}
|
||||
void clear();
|
||||
@ -72,7 +72,7 @@ class RsGxsForumSerialiser : public RsSerialType
|
||||
public:
|
||||
|
||||
RsGxsForumSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV2_TYPE_FORUMS)
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_FORUMS)
|
||||
{ return; }
|
||||
virtual ~RsGxsForumSerialiser() { return; }
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "rsgxsiditems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rstlvstring.h"
|
||||
|
||||
#define GXSID_DEBUG 1
|
||||
|
||||
@ -91,7 +92,7 @@ RsItem* RsGxsIdSerialiser::deserialise(void* data, uint32_t* size)
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_GXSID != getRsItemService(rstype)))
|
||||
(RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
@ -236,7 +237,7 @@ RsGxsIdGroupItem* RsGxsIdSerialiser::deserialiseGxsIdGroupItem(void *data, uint3
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_GXSID != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSID_GROUP_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
@ -394,7 +395,7 @@ RsGxsIdOpinionItem* RsGxsIdSerialiser::deserialiseGxsIdOpinionItem(void *data, u
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_GXSID != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSID_OPINION_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
@ -536,7 +537,7 @@ RsGxsIdCommentItem* RsGxsIdSerialiser::deserialiseGxsIdCommentItem(void *data, u
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_GXSID != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
|
@ -30,7 +30,6 @@
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
#include "retroshare/rsidentity.h"
|
||||
@ -44,7 +43,7 @@ class RsGxsIdGroupItem : public RsGxsGrpItem
|
||||
|
||||
public:
|
||||
|
||||
RsGxsIdGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV2_TYPE_GXSID,
|
||||
RsGxsIdGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_GXSID,
|
||||
RS_PKT_SUBTYPE_GXSID_GROUP_ITEM) { return;}
|
||||
virtual ~RsGxsIdGroupItem() { return;}
|
||||
|
||||
@ -60,7 +59,7 @@ class RsGxsIdOpinionItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsIdOpinionItem(): RsGxsMsgItem(RS_SERVICE_GXSV2_TYPE_GXSID,
|
||||
RsGxsIdOpinionItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_GXSID,
|
||||
RS_PKT_SUBTYPE_GXSID_OPINION_ITEM) {return; }
|
||||
virtual ~RsGxsIdOpinionItem() { return;}
|
||||
void clear();
|
||||
@ -72,7 +71,7 @@ class RsGxsIdCommentItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsIdCommentItem(): RsGxsMsgItem(RS_SERVICE_GXSV2_TYPE_GXSID,
|
||||
RsGxsIdCommentItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_GXSID,
|
||||
RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM) { return; }
|
||||
virtual ~RsGxsIdCommentItem() { return; }
|
||||
void clear();
|
||||
@ -87,7 +86,7 @@ class RsGxsIdSerialiser : public RsSerialType
|
||||
public:
|
||||
|
||||
RsGxsIdSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV2_TYPE_GXSID)
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_GXSID)
|
||||
{ return; }
|
||||
virtual ~RsGxsIdSerialiser() { return; }
|
||||
|
||||
|
@ -28,8 +28,8 @@
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
//#include "serialiser/rstlvtypes.h"
|
||||
//#include "serialiser/rstlvkeys.h"
|
||||
#include "retroshare/rsgxsifacetypes.h"
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const RsGroupMetaData &meta);
|
||||
|
@ -23,8 +23,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rsgxsrecognitems.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
|
@ -30,9 +30,14 @@
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "serialiser/rstlvidset.h"
|
||||
|
||||
#if 0
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
|
||||
#endif
|
||||
|
||||
#include "retroshare/rsgxsifacetypes.h"
|
||||
|
||||
|
@ -30,7 +30,6 @@
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "retroshare/rsgxsifacetypes.h"
|
||||
|
||||
#define RS_PKT_SUBTYPE_GXSREPUTATION_CONFIG_ITEM 0x01
|
||||
@ -44,7 +43,7 @@ class RsGxsReputationConfigItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsGxsReputationConfigItem()
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV2_TYPE_REPUTATION,
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_REPUTATION,
|
||||
RS_PKT_SUBTYPE_GXSREPUTATION_CONFIG_ITEM)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_GXSREPUTATION_ITEM);
|
||||
@ -64,7 +63,7 @@ class RsGxsReputationSetItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsGxsReputationSetItem()
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV2_TYPE_REPUTATION,
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_REPUTATION,
|
||||
RS_PKT_SUBTYPE_GXSREPUTATION_SET_ITEM)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_GXSREPUTATION_ITEM);
|
||||
@ -86,7 +85,7 @@ class RsGxsReputationUpdateItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsGxsReputationUpdateItem()
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV2_TYPE_REPUTATION,
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_REPUTATION,
|
||||
RS_PKT_SUBTYPE_GXSREPUTATION_UPDATE_ITEM)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_GXSREPUTATION_ITEM);
|
||||
@ -105,7 +104,7 @@ class RsGxsReputationRequestItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsGxsReputationRequestItem()
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV2_TYPE_REPUTATION,
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_REPUTATION,
|
||||
RS_PKT_SUBTYPE_GXSREPUTATION_REQUEST_ITEM)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_GXSREPUTATION_ITEM);
|
||||
@ -124,7 +123,7 @@ class RsGxsReputationSerialiser: public RsSerialType
|
||||
{
|
||||
public:
|
||||
RsGxsReputationSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV2_TYPE_REPUTATION)
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_REPUTATION)
|
||||
{ return; }
|
||||
virtual ~RsGxsReputationSerialiser()
|
||||
{ return; }
|
||||
|
@ -27,13 +27,16 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <map>
|
||||
|
||||
#if 0
|
||||
#include <map>
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#endif
|
||||
|
||||
#include "gxs/rsgxsdata.h"
|
||||
|
||||
|
||||
|
@ -31,7 +31,14 @@
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "serialiser/rstlvfileitem.h"
|
||||
|
||||
#if 0
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvfileitem.h"
|
||||
#endif
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvitem.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "gxs/rsgxsdata.h"
|
||||
|
||||
|
@ -25,8 +25,9 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "rsphotoitems.h"
|
||||
#include "serialiser/rsphotoitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvbinary.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#define GXS_PHOTO_SERIAL_DEBUG
|
||||
@ -98,7 +99,7 @@ RsItem* RsGxsPhotoSerialiser::deserialise(void* data, uint32_t* size)
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_PHOTO != getRsItemService(rstype)))
|
||||
(RS_SERVICE_GXS_TYPE_PHOTO != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
@ -200,7 +201,7 @@ bool RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem(RsGxsPhotoAlbumItem* item,
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DATE, item->album.mWhen);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_LOCATION, item->album.mWhere);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PIC_TYPE, item->album.mThumbnail.type);
|
||||
RsTlvBinaryData b(RS_SERVICE_GXSV2_TYPE_PHOTO); // TODO, need something more persisitent
|
||||
RsTlvBinaryData b(RS_SERVICE_GXS_TYPE_PHOTO); // TODO, need something more persisitent
|
||||
b.setBinData(item->album.mThumbnail.data, item->album.mThumbnail.size);
|
||||
ok &= b.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
@ -238,7 +239,7 @@ RsGxsPhotoAlbumItem* RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem(void* da
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_PHOTO != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_PHOTO != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_PHOTO_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
@ -275,7 +276,7 @@ RsGxsPhotoAlbumItem* RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem(void* da
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_LOCATION, item->album.mWhere);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PIC_TYPE, item->album.mThumbnail.type);
|
||||
|
||||
RsTlvBinaryData b(RS_SERVICE_GXSV2_TYPE_PHOTO); // TODO, need something more persisitent
|
||||
RsTlvBinaryData b(RS_SERVICE_GXS_TYPE_PHOTO); // TODO, need something more persisitent
|
||||
ok &= b.GetTlv(data, rssize, &offset);
|
||||
item->album.mThumbnail.data = (uint8_t*)b.bin_data;
|
||||
item->album.mThumbnail.size = b.bin_len;
|
||||
@ -365,7 +366,7 @@ bool RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem(RsGxsPhotoPhotoItem* item,
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DATE, item->photo.mWhen);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_LOCATION, item->photo.mWhere);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PIC_TYPE, item->photo.mThumbnail.type);
|
||||
RsTlvBinaryData b(RS_SERVICE_GXSV2_TYPE_PHOTO); // TODO, need something more persisitent
|
||||
RsTlvBinaryData b(RS_SERVICE_GXS_TYPE_PHOTO); // TODO, need something more persisitent
|
||||
b.setBinData(item->photo.mThumbnail.data, item->photo.mThumbnail.size);
|
||||
ok &= b.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
@ -403,7 +404,7 @@ RsGxsPhotoPhotoItem* RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem(void* da
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_PHOTO != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_PHOTO != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
@ -439,7 +440,7 @@ RsGxsPhotoPhotoItem* RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem(void* da
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_LOCATION, item->photo.mWhere);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PIC_TYPE, item->photo.mThumbnail.type);
|
||||
|
||||
RsTlvBinaryData b(RS_SERVICE_GXSV2_TYPE_PHOTO); // TODO, need something more persisitent
|
||||
RsTlvBinaryData b(RS_SERVICE_GXS_TYPE_PHOTO); // TODO, need something more persisitent
|
||||
ok &= b.GetTlv(data, rssize, &offset);
|
||||
item->photo.mThumbnail.data = (uint8_t*)(b.bin_data);
|
||||
item->photo.mThumbnail.size = b.bin_len;
|
||||
@ -534,7 +535,7 @@ RsGxsPhotoCommentItem * RsGxsPhotoSerialiser::deserialiseGxsPhotoCommentItem(
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_PHOTO != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_PHOTO != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
|
@ -30,7 +30,6 @@
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
#include "retroshare/rsphoto.h"
|
||||
@ -44,7 +43,7 @@ class RsGxsPhotoAlbumItem : public RsGxsGrpItem
|
||||
|
||||
public:
|
||||
|
||||
RsGxsPhotoAlbumItem(): RsGxsGrpItem(RS_SERVICE_GXSV2_TYPE_PHOTO,
|
||||
RsGxsPhotoAlbumItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_PHOTO,
|
||||
RS_PKT_SUBTYPE_PHOTO_ITEM) { return;}
|
||||
virtual ~RsGxsPhotoAlbumItem() { return;}
|
||||
|
||||
@ -59,7 +58,7 @@ class RsGxsPhotoPhotoItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsPhotoPhotoItem(): RsGxsMsgItem(RS_SERVICE_GXSV2_TYPE_PHOTO,
|
||||
RsGxsPhotoPhotoItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_PHOTO,
|
||||
RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM) {return; }
|
||||
virtual ~RsGxsPhotoPhotoItem() { return;}
|
||||
void clear();
|
||||
@ -71,7 +70,7 @@ class RsGxsPhotoCommentItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsPhotoCommentItem(): RsGxsMsgItem(RS_SERVICE_GXSV2_TYPE_PHOTO,
|
||||
RsGxsPhotoCommentItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_PHOTO,
|
||||
RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM) { return; }
|
||||
virtual ~RsGxsPhotoCommentItem() { return; }
|
||||
void clear();
|
||||
@ -86,7 +85,7 @@ class RsGxsPhotoSerialiser : public RsSerialType
|
||||
public:
|
||||
|
||||
RsGxsPhotoSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV2_TYPE_PHOTO)
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_PHOTO)
|
||||
{ return; }
|
||||
virtual ~RsGxsPhotoSerialiser() { return; }
|
||||
|
||||
|
@ -27,11 +27,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#if 0
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#endif
|
||||
|
||||
const uint8_t RS_PKT_CLASS_PLUGIN_SUBTYPE_HASHSET = 0x01 ;
|
||||
|
||||
class RsPluginItem: public RsItem
|
||||
|
@ -87,7 +87,7 @@ RsItem* RsGxsPostedSerialiser::deserialise(void *data, uint32_t *size)
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_POSTED != getRsItemService(rstype)))
|
||||
(RS_SERVICE_GXS_TYPE_POSTED != getRsItemService(rstype)))
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialise() ERROR Wrong Type";
|
||||
std::cerr << std::endl;
|
||||
@ -207,7 +207,7 @@ RsGxsPostedPostItem* RsGxsPostedSerialiser::deserialiseGxsPostedPostItem(void *d
|
||||
uint32_t offset = 0;
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_POSTED != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_POSTED != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_POSTED_POST_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() FAIL wrong type" << std::endl;
|
||||
@ -347,7 +347,7 @@ RsGxsPostedGroupItem* RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem(void
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_POSTED != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_POSTED != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_POSTED_GRP_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL wrong type" << std::endl;
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
//#include "serialiser/rstlvtypes.h"
|
||||
|
||||
#include "serialiser/rsgxscommentitems.h"
|
||||
|
||||
@ -16,7 +16,7 @@ const uint8_t RS_PKT_SUBTYPE_POSTED_POST_ITEM = 0x03;
|
||||
class RsGxsPostedGroupItem : public RsGxsGrpItem
|
||||
{
|
||||
public:
|
||||
RsGxsPostedGroupItem() : RsGxsGrpItem(RS_SERVICE_GXSV2_TYPE_POSTED,
|
||||
RsGxsPostedGroupItem() : RsGxsGrpItem(RS_SERVICE_GXS_TYPE_POSTED,
|
||||
RS_PKT_SUBTYPE_POSTED_GRP_ITEM) { return; }
|
||||
virtual ~RsGxsPostedGroupItem() { return; }
|
||||
|
||||
@ -29,7 +29,7 @@ public:
|
||||
class RsGxsPostedPostItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
RsGxsPostedPostItem() : RsGxsMsgItem(RS_SERVICE_GXSV2_TYPE_POSTED,
|
||||
RsGxsPostedPostItem() : RsGxsMsgItem(RS_SERVICE_GXS_TYPE_POSTED,
|
||||
RS_PKT_SUBTYPE_POSTED_POST_ITEM) {return ; }
|
||||
virtual ~RsGxsPostedPostItem() { return; }
|
||||
|
||||
@ -45,7 +45,7 @@ class RsGxsPostedSerialiser : public RsGxsCommentSerialiser
|
||||
public:
|
||||
|
||||
RsGxsPostedSerialiser()
|
||||
:RsGxsCommentSerialiser(RS_SERVICE_GXSV2_TYPE_POSTED)
|
||||
:RsGxsCommentSerialiser(RS_SERVICE_GXS_TYPE_POSTED)
|
||||
{ return; }
|
||||
|
||||
virtual ~RsGxsPostedSerialiser() { return; }
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rsrttitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
//#include "serialiser/rstlvbase.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
|
@ -30,7 +30,6 @@
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
|
@ -50,27 +50,43 @@ 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;
|
||||
|
||||
/* BanList Still Testing at the moment - Service Only */
|
||||
const uint16_t RS_SERVICE_TYPE_BANLIST = 0x0101;
|
||||
const uint16_t RS_SERVICE_TYPE_SERVICEINFO = 0x0020;
|
||||
/* Bandwidth Control */
|
||||
const uint16_t RS_SERVICE_TYPE_BWCTRL = 0x0021;
|
||||
|
||||
const uint16_t RS_SERVICE_TYPE_SERVICEINFO = 0x0201;
|
||||
// Non essential services.
|
||||
const uint16_t RS_SERVICE_TYPE_BANLIST = 0x0101;
|
||||
const uint16_t RS_SERVICE_TYPE_STATUS = 0x0102;
|
||||
|
||||
/* Caches based on p3distrib (Cache Only)
|
||||
* Unfortunately, noone changed the DUMMY IDS... so we are stuck with them!
|
||||
*/
|
||||
const uint16_t RS_SERVICE_TYPE_DISTRIB = 0xf110;
|
||||
const uint16_t RS_SERVICE_TYPE_FORUM = 0xf120;
|
||||
const uint16_t RS_SERVICE_TYPE_CHANNEL = 0xf130;
|
||||
const uint16_t RS_SERVICE_TYPE_CHANNEL_SOCKET = 0xf140;
|
||||
/* 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;
|
||||
|
||||
// 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;
|
||||
|
||||
/* Status - Service only */
|
||||
const uint16_t RS_SERVICE_TYPE_STATUS = 0xf020;
|
||||
|
||||
/***************** IDS ALLOCATED FOR PLUGINS ******************/
|
||||
// 2000+
|
||||
|
||||
const uint16_t RS_SERVICE_TYPE_PLUGIN_ARADO_ID = 0x0401;
|
||||
const uint16_t RS_SERVICE_TYPE_PLUGIN_QCHESS_ID = 0x0402;
|
||||
const uint16_t RS_SERVICE_TYPE_PLUGIN_FEEDREADER = 0x0403;
|
||||
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;
|
||||
|
||||
|
||||
/****************** BELOW ARE ONLY THEORETICAL (CAN BE CHANGED) *****/
|
||||
@ -93,82 +109,36 @@ const uint16_t RS_SERVICE_TYPE_PLUGIN_FEEDREADER = 0x0403;
|
||||
*/
|
||||
|
||||
/*! for Qblog service (Cache Only) */
|
||||
const uint16_t RS_SERVICE_TYPE_QBLOG = 0xf010;
|
||||
//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;
|
||||
|
||||
/* Status - Service only */
|
||||
//const uint16_t RS_SERVICE_TYPE_STATUS = 0xf020;
|
||||
|
||||
/* Proxy - Service only */
|
||||
const uint16_t RS_SERVICE_TYPE_PROXY = 0xf030;
|
||||
|
||||
/* DSDV Testing at the moment - Service Only */
|
||||
const uint16_t RS_SERVICE_TYPE_DSDV = 0xf050;
|
||||
/* Latency RTT Measurements */
|
||||
const uint16_t RS_SERVICE_TYPE_RTT = 0xf051;
|
||||
|
||||
/* Bandwidth Testing at the moment - Service Only */
|
||||
const uint16_t RS_SERVICE_TYPE_BWCTRL = 0xf060;
|
||||
|
||||
|
||||
|
||||
|
||||
//const uint16_t RS_SERVICE_TYPE_DISTRIB = 0xf110;
|
||||
//const uint16_t RS_SERVICE_TYPE_FORUM = 0xf120;
|
||||
//const uint16_t RS_SERVICE_TYPE_CHANNEL = 0xf130;
|
||||
//const uint16_t RS_SERVICE_TYPE_CHANNEL_SOCKET = 0xf140;
|
||||
//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;
|
||||
//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;
|
||||
//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;
|
||||
|
||||
/* New Cache Services */
|
||||
/* Rs Network Exchange Service */
|
||||
const uint16_t RS_SERVICE_TYPE_NXS = 0xf300;
|
||||
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_GXSID = 0xf311;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_GXSCIRCLE = 0xf312;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_PHOTO = 0xf313;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_WIKI = 0xf314;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_WIRE = 0xf315;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_FORUMS = 0xf316;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_POSTED = 0xf317;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_CHANNELS = 0xf318;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_REPUTATION = 0xf319;
|
||||
|
||||
const uint16_t RS_SERVICE_GXSV3_TYPE_GXSID = 0xf321;
|
||||
const uint16_t RS_SERVICE_GXSV3_TYPE_PHOTO = 0xf322;
|
||||
const uint16_t RS_SERVICE_GXSV3_TYPE_WIKI = 0xf323;
|
||||
const uint16_t RS_SERVICE_GXSV3_TYPE_WIRE = 0xf324;
|
||||
const uint16_t RS_SERVICE_GXSV3_TYPE_FORUMS = 0xf325;
|
||||
const uint16_t RS_SERVICE_GXSV3_TYPE_POSTED = 0xf326;
|
||||
const uint16_t RS_SERVICE_GXSV3_TYPE_CHANNELS = 0xf327;
|
||||
const uint16_t RS_SERVICE_GXSV3_TYPE_GXSCIRCLE = 0xf328;
|
||||
const uint16_t RS_SERVICE_GXSV3_TYPE_REPUTATION = 0xf329;
|
||||
|
||||
const uint16_t RS_SERVICE_TYPE_GXS_RECOGN = 0xf331;
|
||||
//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;
|
||||
//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;
|
||||
|
||||
//const uint16_t RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM = 0xf403;
|
||||
|
||||
|
||||
#endif /* RS_SERVICE_IDS_H */
|
||||
|
@ -36,7 +36,7 @@
|
||||
/***** RsServiceInfo ****/
|
||||
|
||||
template<>
|
||||
std::ostream &RsTlvParamRef<RsServiceInfo>::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream &RsTlvParamRef<RsServiceInfo>::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
out << "RsServiceInfo: " << mParam.mServiceType << " name " << mParam.mServiceName;
|
||||
out << std::endl;
|
||||
@ -47,7 +47,7 @@ std::ostream &RsTlvParamRef<RsServiceInfo>::print(std::ostream &out, uint16_t in
|
||||
}
|
||||
|
||||
template<>
|
||||
uint32_t RsTlvParamRef<RsServiceInfo>::TlvSize()
|
||||
uint32_t RsTlvParamRef<RsServiceInfo>::TlvSize() const
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header + 4 for size */
|
||||
|
||||
@ -66,7 +66,7 @@ void RsTlvParamRef<RsServiceInfo>::TlvClear()
|
||||
}
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<RsServiceInfo>::SetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
bool RsTlvParamRef<RsServiceInfo>::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
|
@ -24,15 +24,17 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "rstlvaddrs.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvaddrs.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#include "rstlvbase.h"
|
||||
#if 0
|
||||
#include "rstlvtypes.h"
|
||||
#include "rsbaseserial.h"
|
||||
#include "util/rsprint.h"
|
||||
#include <ostream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
|
||||
/************************************* RsTlvIpAddress ************************************/
|
||||
@ -49,7 +51,7 @@ void RsTlvIpAddress::TlvClear()
|
||||
sockaddr_storage_clear(addr);
|
||||
}
|
||||
|
||||
uint32_t RsTlvIpAddress::TlvSize()
|
||||
uint32_t RsTlvIpAddress::TlvSize() const
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE;
|
||||
switch(addr.ss_family)
|
||||
@ -67,7 +69,7 @@ uint32_t RsTlvIpAddress::TlvSize()
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsTlvIpAddress::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvIpAddress::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
@ -101,7 +103,7 @@ bool RsTlvIpAddress::SetTlv(void *data, uint32_t size, uint32_t *offset) /* ser
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvIpAddress::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvIpAddress::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
@ -163,7 +165,7 @@ bool RsTlvIpAddress::GetTlv(void *data, uint32_t size, uint32_t *offset) /* ser
|
||||
}
|
||||
|
||||
|
||||
std::ostream &RsTlvIpAddress::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream &RsTlvIpAddress::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "RsTlvIpAddress", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
@ -194,7 +196,7 @@ void RsTlvIpAddressInfo::TlvClear()
|
||||
source = 0;
|
||||
}
|
||||
|
||||
uint32_t RsTlvIpAddressInfo::TlvSize()
|
||||
uint32_t RsTlvIpAddressInfo::TlvSize() const
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header + IpAddr + 8 for time & 4 for size */
|
||||
|
||||
@ -206,7 +208,7 @@ uint32_t RsTlvIpAddressInfo::TlvSize()
|
||||
|
||||
}
|
||||
|
||||
bool RsTlvIpAddressInfo::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvIpAddressInfo::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
@ -231,7 +233,7 @@ bool RsTlvIpAddressInfo::SetTlv(void *data, uint32_t size, uint32_t *offset) /*
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvIpAddressInfo::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvIpAddressInfo::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
@ -279,7 +281,7 @@ bool RsTlvIpAddressInfo::GetTlv(void *data, uint32_t size, uint32_t *offset) /*
|
||||
}
|
||||
|
||||
|
||||
std::ostream &RsTlvIpAddressInfo::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream &RsTlvIpAddressInfo::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "RsTlvIpAddressInfo", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
@ -300,7 +302,7 @@ std::ostream &RsTlvIpAddressInfo::print(std::ostream &out, uint16_t indent)
|
||||
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
/************************************* RsTlvIpAddrSet ************************************/
|
||||
|
||||
void RsTlvIpAddrSet::TlvClear()
|
||||
@ -308,7 +310,7 @@ void RsTlvIpAddrSet::TlvClear()
|
||||
addrs.clear();
|
||||
}
|
||||
|
||||
uint32_t RsTlvIpAddrSet::TlvSize()
|
||||
uint32_t RsTlvIpAddrSet::TlvSize() const
|
||||
{
|
||||
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
@ -327,7 +329,7 @@ uint32_t RsTlvIpAddrSet::TlvSize()
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsTlvIpAddrSet::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvIpAddrSet::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
@ -355,7 +357,7 @@ return ok;
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvIpAddrSet::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvIpAddrSet::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
@ -427,7 +429,7 @@ bool RsTlvIpAddrSet::GetTlv(void *data, uint32_t size, uint32_t *offset) /* ser
|
||||
}
|
||||
|
||||
// prints out contents of RsTlvIpAddrSet
|
||||
std::ostream &RsTlvIpAddrSet::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream &RsTlvIpAddrSet::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "RsTlvIpAddrSet", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
@ -443,3 +445,4 @@ std::ostream &RsTlvIpAddrSet::print(std::ostream &out, uint16_t indent)
|
||||
|
||||
/************************************* RsTlvIpAddressInfo ************************************/
|
||||
|
||||
#endif
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef RS_TLV_ADDRS_TYPES_H
|
||||
#define RS_TLV_ADDRS_TYPES_H
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvaddrs.h
|
||||
@ -30,20 +29,22 @@
|
||||
* These are the Compound TLV structures that must be (un)packed.
|
||||
******************************************************************/
|
||||
|
||||
#include <map>
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvitem.h"
|
||||
#include "util/rsnet.h"
|
||||
#include <list>
|
||||
|
||||
#include "serialiser/rstlvlist.h"
|
||||
|
||||
class RsTlvIpAddress: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvIpAddress();
|
||||
virtual ~RsTlvIpAddress() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
|
||||
struct sockaddr_storage addr; // Mandatory :
|
||||
};
|
||||
@ -54,17 +55,20 @@ class RsTlvIpAddressInfo: public RsTlvItem
|
||||
public:
|
||||
RsTlvIpAddressInfo();
|
||||
virtual ~RsTlvIpAddressInfo() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
|
||||
RsTlvIpAddress addr; // Mandatory :
|
||||
uint64_t seenTime; // Mandatory :
|
||||
uint32_t source; // Mandatory :
|
||||
};
|
||||
|
||||
typedef t_RsTlvList<RsTlvIpAddressInfo,TLV_TYPE_ADDRESS_SET> RsTlvIpAddrSet;
|
||||
|
||||
#if 0
|
||||
class RsTlvIpAddrSet: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
@ -78,7 +82,6 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
std::list<RsTlvIpAddressInfo> addrs; // Mandatory :
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -24,15 +24,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "rstlvbanlist.h"
|
||||
#include "serialiser/rstlvbanlist.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
|
||||
#include "rstlvbase.h"
|
||||
#include "rstlvtypes.h"
|
||||
#include "rsbaseserial.h"
|
||||
#include "util/rsprint.h"
|
||||
#include <ostream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
|
||||
/************************************* RsTlvBanListEntry ************************************/
|
||||
@ -51,7 +46,7 @@ void RsTlvBanListEntry::TlvClear()
|
||||
age = 0;
|
||||
}
|
||||
|
||||
uint32_t RsTlvBanListEntry::TlvSize()
|
||||
uint32_t RsTlvBanListEntry::TlvSize() const
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE;
|
||||
|
||||
@ -64,7 +59,7 @@ uint32_t RsTlvBanListEntry::TlvSize()
|
||||
|
||||
}
|
||||
|
||||
bool RsTlvBanListEntry::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvBanListEntry::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
@ -89,7 +84,7 @@ bool RsTlvBanListEntry::SetTlv(void *data, uint32_t size, uint32_t *offset) /*
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvBanListEntry::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvBanListEntry::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
@ -137,7 +132,7 @@ bool RsTlvBanListEntry::GetTlv(void *data, uint32_t size, uint32_t *offset) /*
|
||||
}
|
||||
|
||||
|
||||
std::ostream &RsTlvBanListEntry::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream &RsTlvBanListEntry::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "RsTlvBanListEntry", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
@ -163,151 +158,3 @@ std::ostream &RsTlvBanListEntry::print(std::ostream &out, uint16_t indent)
|
||||
}
|
||||
|
||||
|
||||
/************************************* RsTlvBanList ************************************/
|
||||
|
||||
RsTlvBanList::RsTlvBanList()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RsTlvBanList::TlvClear()
|
||||
{
|
||||
entries.clear();
|
||||
}
|
||||
|
||||
uint32_t RsTlvBanList::TlvSize()
|
||||
{
|
||||
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
|
||||
std::list<RsTlvBanListEntry>::iterator it;
|
||||
|
||||
|
||||
if(!entries.empty())
|
||||
{
|
||||
|
||||
for(it = entries.begin(); it != entries.end() ; ++it)
|
||||
s += it->TlvSize();
|
||||
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsTlvBanList::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* start at data[offset] */
|
||||
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_BAN_LIST , tlvsize);
|
||||
|
||||
if(!entries.empty())
|
||||
{
|
||||
std::list<RsTlvBanListEntry>::iterator it;
|
||||
|
||||
for(it = entries.begin(); it != entries.end() ; ++it)
|
||||
ok &= it->SetTlv(data, size, offset);
|
||||
}
|
||||
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvBanList::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
|
||||
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend) /* check size */
|
||||
return false; /* not enough space */
|
||||
|
||||
if (tlvtype != TLV_TYPE_BAN_LIST) /* check type */
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
/* while there is TLV */
|
||||
while((*offset) + 2 < tlvend)
|
||||
{
|
||||
/* get the next type */
|
||||
uint16_t tlvsubtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
|
||||
switch(tlvsubtype)
|
||||
{
|
||||
case TLV_TYPE_BAN_ENTRY:
|
||||
{
|
||||
RsTlvBanListEntry entry;
|
||||
ok &= entry.GetTlv(data, size, offset);
|
||||
if (ok)
|
||||
{
|
||||
entries.push_back(entry);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ok &= SkipUnknownTlv(data, tlvend, offset);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* NB: extra components could be added (for future expansion of the type).
|
||||
* or be present (if this code is reading an extended version).
|
||||
*
|
||||
* We must chew up the extra characters to conform with TLV specifications
|
||||
***************************************************************************/
|
||||
if (*offset != tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvBanList::GetTlv() Warning extra bytes at end of item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
*offset = tlvend;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
// prints out contents of RsTlvBanList
|
||||
std::ostream &RsTlvBanList::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printBase(out, "RsTlvBanList", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
std::list<RsTlvBanListEntry>::iterator it;
|
||||
for(it = entries.begin(); it != entries.end() ; ++it)
|
||||
it->print(out, int_Indent);
|
||||
|
||||
printEnd(out, "RsTlvBanList", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
/************************************* RsTlvBanList ************************************/
|
||||
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef RS_TLV_BANLIST_TYPES_H
|
||||
#define RS_TLV_BANLIST_TYPES_H
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvbanlist.h
|
||||
@ -30,10 +29,10 @@
|
||||
* These are the Compound TLV structures that must be (un)packed.
|
||||
******************************************************************/
|
||||
|
||||
#include <map>
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvitem.h"
|
||||
#include "serialiser/rstlvaddrs.h"
|
||||
#include "util/rsnet.h"
|
||||
#include "serialiser/rstlvlist.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
|
||||
#define RSDSDV_MAX_ROUTE_TABLE 1000
|
||||
|
||||
@ -42,11 +41,11 @@ class RsTlvBanListEntry: public RsTlvItem
|
||||
public:
|
||||
RsTlvBanListEntry();
|
||||
virtual ~RsTlvBanListEntry() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
|
||||
RsTlvIpAddress addr;
|
||||
uint32_t level;
|
||||
@ -54,20 +53,8 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
uint32_t age;
|
||||
};
|
||||
|
||||
class RsTlvBanList: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvBanList();
|
||||
virtual ~RsTlvBanList() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
std::list<RsTlvBanListEntry> entries;
|
||||
};
|
||||
typedef t_RsTlvList<RsTlvBanListEntry,TLV_TYPE_BAN_LIST> RsTlvBanList;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef RS_TLV_BASE_H
|
||||
#define RS_TLV_BASE_H
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvbase.h
|
||||
@ -62,11 +61,11 @@
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <string>
|
||||
#include "util/rsnet.h"
|
||||
|
||||
|
||||
/* 0b 0000 0000 0001 XXXX UInt8 */
|
||||
/* 0b 0000 0000 0010 XXXX UInt16 */
|
||||
/* 0b 0000 0000 0011 XXXX UInt32 */
|
||||
@ -105,11 +104,6 @@ const uint32_t TLV_HEADER_LEN_SIZE = 4;
|
||||
const uint32_t TLV_HEADER_SIZE = TLV_HEADER_TYPE_SIZE + TLV_HEADER_LEN_SIZE;
|
||||
/* TLV HEADER SIZE (Reference) *******************************/
|
||||
|
||||
|
||||
const uint16_t TLV_TYPE_UINT8_SERID = 0x0010;
|
||||
|
||||
const uint16_t TLV_TYPE_UINT16_SERID = 0x0020;
|
||||
|
||||
const uint16_t TLV_TYPE_UINT32_SIZE = 0x0030;
|
||||
const uint16_t TLV_TYPE_UINT32_POP = 0x0031;
|
||||
const uint16_t TLV_TYPE_UINT32_AGE = 0x0032;
|
||||
@ -141,22 +135,6 @@ const uint16_t TLV_TYPE_STR_CERT_SSL = 0x005e;
|
||||
const uint16_t TLV_TYPE_STR_VERSION = 0x005f;
|
||||
const uint16_t TLV_TYPE_STR_PARAM = 0x0054; /* same as VALUE ---- TO FIX */
|
||||
|
||||
|
||||
|
||||
|
||||
/* Wide Chars (4 bytes per char) for internationalisation */
|
||||
const uint16_t TLV_TYPE_WSTR_PEERID = 0x0060;
|
||||
const uint16_t TLV_TYPE_WSTR_NAME = 0x0061;
|
||||
const uint16_t TLV_TYPE_WSTR_PATH = 0x0062;
|
||||
const uint16_t TLV_TYPE_WSTR_KEY = 0x0063;
|
||||
const uint16_t TLV_TYPE_WSTR_VALUE = 0x0064;
|
||||
const uint16_t TLV_TYPE_WSTR_COMMENT = 0x0065;
|
||||
const uint16_t TLV_TYPE_WSTR_TITLE = 0x0066;
|
||||
const uint16_t TLV_TYPE_WSTR_MSG = 0x0067;
|
||||
const uint16_t TLV_TYPE_WSTR_SUBJECT = 0x0068;
|
||||
const uint16_t TLV_TYPE_WSTR_LINK = 0x0069;
|
||||
const uint16_t TLV_TYPE_WSTR_GENID = 0x006a;
|
||||
|
||||
/* Hashs are always strings */
|
||||
const uint16_t TLV_TYPE_STR_HASH_SHA1 = 0x0070;
|
||||
const uint16_t TLV_TYPE_STR_HASH_ED2K = 0x0071;
|
||||
@ -178,8 +156,6 @@ const uint16_t TLV_TYPE_STR_PARENTID = 0x00a2;
|
||||
const uint16_t TLV_TYPE_STR_THREADID = 0x00a3;
|
||||
const uint16_t TLV_TYPE_STR_KEYID = 0x00a4;
|
||||
|
||||
const uint16_t TLV_TYPE_WSTR_CATEGORY = 0x00b0;
|
||||
|
||||
/* even MORE string Ids for GXS services */
|
||||
|
||||
const uint16_t TLV_TYPE_STR_CAPTION = 0x00b1;
|
||||
@ -220,9 +196,7 @@ const uint16_t TLV_TYPE_FILESET = 0x1001;
|
||||
const uint16_t TLV_TYPE_FILEDATA = 0x1002;
|
||||
|
||||
const uint16_t TLV_TYPE_KEYVALUE = 0x1010;
|
||||
const uint16_t TLV_TYPE_WKEYVALUE = 0x1012;
|
||||
const uint16_t TLV_TYPE_KEYVALUESET = 0x1011;
|
||||
const uint16_t TLV_TYPE_WKEYVALUESET = 0x1013;
|
||||
|
||||
const uint16_t TLV_TYPE_STRINGSET = 0x1020; /* dummy non-existant */
|
||||
const uint16_t TLV_TYPE_PEERSET = 0x1021;
|
||||
@ -255,6 +229,7 @@ const uint16_t TLV_TYPE_BAN_ENTRY = 0x1090;
|
||||
const uint16_t TLV_TYPE_BAN_LIST = 0x1091;
|
||||
|
||||
|
||||
|
||||
const uint32_t RSTLV_IMAGE_TYPE_PNG = 0x0001;
|
||||
const uint32_t RSTLV_IMAGE_TYPE_JPG = 0x0002;
|
||||
|
||||
@ -317,4 +292,3 @@ above(SetTlvbinData) is partially implemented
|
||||
bool GetTlvBinData(void* data, uint32_t size, uint32_t* offset, uint16_t type, void* data_bin, uint32_t len_tlv)
|
||||
|
||||
*************************************/
|
||||
#endif
|
||||
|
213
libretroshare/src/serialiser/rstlvbinary.cc
Normal file
213
libretroshare/src/serialiser/rstlvbinary.cc
Normal file
@ -0,0 +1,213 @@
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvbinary.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/rstlvbinary.h"
|
||||
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include <stdlib.h>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
#define TLV_DEBUG 1
|
||||
|
||||
/*!********************************** RsTlvFileBinaryData **********************************/
|
||||
|
||||
|
||||
RsTlvBinaryData::RsTlvBinaryData(uint16_t t)
|
||||
:tlvtype(t), bin_len(0), bin_data(NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RsTlvBinaryData::RsTlvBinaryData(const RsTlvBinaryData &b)
|
||||
: tlvtype(b.tlvtype), bin_len(0) , bin_data(NULL) {
|
||||
|
||||
setBinData(b.bin_data, b.bin_len);
|
||||
}
|
||||
|
||||
RsTlvBinaryData::~RsTlvBinaryData()
|
||||
{
|
||||
TlvClear();
|
||||
}
|
||||
|
||||
void RsTlvBinaryData::operator =(const RsTlvBinaryData& b){
|
||||
|
||||
setBinData(b.bin_data, b.bin_len);
|
||||
tlvtype = b.tlvtype;
|
||||
}
|
||||
|
||||
/// used to allocate memory andinitialize binary data member
|
||||
bool RsTlvBinaryData::setBinData(const void *data, uint32_t size)
|
||||
{
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* get mandatory */
|
||||
/* the rest of the TLV size binary data */
|
||||
bin_len = size;
|
||||
if (bin_len == 0)
|
||||
{
|
||||
bin_data = NULL;
|
||||
return true;
|
||||
}
|
||||
|
||||
bin_data = malloc(bin_len);
|
||||
memcpy(bin_data, data, bin_len);
|
||||
return true;
|
||||
}
|
||||
|
||||
void RsTlvBinaryData::TlvClear()
|
||||
{
|
||||
if (bin_data)
|
||||
{
|
||||
free(bin_data);
|
||||
}
|
||||
TlvShallowClear();
|
||||
}
|
||||
|
||||
void RsTlvBinaryData::TlvShallowClear()
|
||||
{
|
||||
bin_data = NULL;
|
||||
bin_len = 0;
|
||||
}
|
||||
|
||||
uint32_t RsTlvBinaryData::TlvSize() const
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
|
||||
if (bin_data != NULL)
|
||||
s += bin_len; // len is the size of data
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvBinaryData::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* start at data[offset] */
|
||||
ok &= SetTlvBase(data, tlvend, offset, tlvtype, tlvsize);
|
||||
|
||||
/* add mandatory data */
|
||||
|
||||
// Warning: this is actually not an error if bin_len=0, as it does not
|
||||
// corrupt the packet structure. We thus still return true in this case.
|
||||
//
|
||||
if (bin_data != NULL && bin_len > 0)
|
||||
{
|
||||
memcpy(&(((uint8_t *) data)[*offset]), bin_data, bin_len);
|
||||
*offset += bin_len;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool RsTlvBinaryData::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
{
|
||||
return false; /* not enough space to get the header */
|
||||
}
|
||||
|
||||
uint16_t tlvtype_in = 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 (tlvsize < TLV_HEADER_SIZE)
|
||||
{
|
||||
return false; /* bad tlv size */
|
||||
}
|
||||
|
||||
if (tlvtype != tlvtype_in) /* check type */
|
||||
return false;
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
bool ok = setBinData(&(((uint8_t *) data)[*offset]), tlvsize - TLV_HEADER_SIZE);
|
||||
(*offset) += bin_len;
|
||||
|
||||
/***************************************************************************
|
||||
* NB: extra components could be added (for future expansion of the type).
|
||||
* or be present (if this code is reading an extended version).
|
||||
*
|
||||
* We must chew up the extra characters to conform with TLV specifications
|
||||
***************************************************************************/
|
||||
if (*offset != tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvBinaryData::GetTlv() Warning extra bytes at end of item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
*offset = tlvend;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
std::ostream &RsTlvBinaryData::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
uint32_t i;
|
||||
std::ostringstream sout;
|
||||
printIndent(sout, indent);
|
||||
sout << "RsTlvBinaryData: Type: " << tlvtype << " Size: " << bin_len;
|
||||
sout << std::hex;
|
||||
|
||||
for(i = 0; i < bin_len; i++)
|
||||
{
|
||||
if (i % 16 == 0)
|
||||
{
|
||||
sout << std::endl;
|
||||
printIndent(sout, int_Indent);
|
||||
}
|
||||
sout << std::setw(2) << std::setfill('0')
|
||||
<< (int) (((unsigned char *) bin_data)[i]) << ":";
|
||||
}
|
||||
|
||||
sout << std::endl;
|
||||
out << sout.str();
|
||||
|
||||
printEnd(out, "RsTlvBinaryData", indent);
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
63
libretroshare/src/serialiser/rstlvbinary.h
Normal file
63
libretroshare/src/serialiser/rstlvbinary.h
Normal file
@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvbinary.h
|
||||
*
|
||||
* 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".
|
||||
*
|
||||
*/
|
||||
|
||||
/*******************************************************************
|
||||
* These are the Compound TLV structures that must be (un)packed.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
#include "serialiser/rstlvitem.h"
|
||||
|
||||
|
||||
class RsTlvBinaryData: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvBinaryData(uint16_t t);
|
||||
RsTlvBinaryData(const RsTlvBinaryData& b); // as per rule of three
|
||||
void operator=(const RsTlvBinaryData& b); // as per rule of three
|
||||
virtual ~RsTlvBinaryData(); // as per rule of three
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear(); /*! Initialize fields to empty legal values ( "0", "", etc) */
|
||||
virtual void TlvShallowClear(); /*! Don't delete the binary data */
|
||||
|
||||
/// Serialise.
|
||||
/*! Serialise Tlv to buffer(*data) of 'size' bytes starting at *offset */
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
|
||||
/// Deserialise.
|
||||
/*! Deserialise Tlv buffer(*data) of 'size' bytes starting at *offset */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const; /*! Error/Debug util function */
|
||||
|
||||
bool setBinData(const void *data, uint32_t size);
|
||||
|
||||
uint16_t tlvtype; /// set/checked against TLV input
|
||||
uint32_t bin_len; /// size of malloc'ed data (not serialised)
|
||||
void *bin_data; /// mandatory
|
||||
};
|
||||
|
||||
|
@ -25,14 +25,7 @@
|
||||
*/
|
||||
|
||||
#include "rstlvdsdv.h"
|
||||
|
||||
#include "rstlvbase.h"
|
||||
#include "rstlvtypes.h"
|
||||
#include "rsbaseserial.h"
|
||||
#include "util/rsprint.h"
|
||||
#include <ostream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
/************************************* RsTlvDsdvEndPoint ************************************/
|
||||
@ -50,7 +43,7 @@ void RsTlvDsdvEndPoint::TlvClear()
|
||||
serviceId.clear();
|
||||
}
|
||||
|
||||
uint32_t RsTlvDsdvEndPoint::TlvSize()
|
||||
uint32_t RsTlvDsdvEndPoint::TlvSize() const
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header + 4 + str + str */
|
||||
|
||||
@ -62,7 +55,7 @@ uint32_t RsTlvDsdvEndPoint::TlvSize()
|
||||
|
||||
}
|
||||
|
||||
bool RsTlvDsdvEndPoint::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvDsdvEndPoint::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
@ -86,7 +79,7 @@ bool RsTlvDsdvEndPoint::SetTlv(void *data, uint32_t size, uint32_t *offset) /*
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvDsdvEndPoint::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvDsdvEndPoint::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
@ -133,7 +126,7 @@ bool RsTlvDsdvEndPoint::GetTlv(void *data, uint32_t size, uint32_t *offset) /*
|
||||
}
|
||||
|
||||
|
||||
std::ostream &RsTlvDsdvEndPoint::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream &RsTlvDsdvEndPoint::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "RsTlvDsdvEndPoint", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
@ -170,7 +163,7 @@ void RsTlvDsdvEntry::TlvClear()
|
||||
distance = 0;
|
||||
}
|
||||
|
||||
uint32_t RsTlvDsdvEntry::TlvSize()
|
||||
uint32_t RsTlvDsdvEntry::TlvSize() const
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header + EndPoint.Size + 4 + 4 */
|
||||
|
||||
@ -182,7 +175,7 @@ uint32_t RsTlvDsdvEntry::TlvSize()
|
||||
|
||||
}
|
||||
|
||||
bool RsTlvDsdvEntry::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvDsdvEntry::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
@ -207,7 +200,7 @@ bool RsTlvDsdvEntry::SetTlv(void *data, uint32_t size, uint32_t *offset) /* ser
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvDsdvEntry::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvDsdvEntry::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
@ -255,7 +248,7 @@ bool RsTlvDsdvEntry::GetTlv(void *data, uint32_t size, uint32_t *offset) /* ser
|
||||
}
|
||||
|
||||
|
||||
std::ostream &RsTlvDsdvEntry::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream &RsTlvDsdvEntry::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "RsTlvDsdvEntry", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
@ -277,6 +270,7 @@ std::ostream &RsTlvDsdvEntry::print(std::ostream &out, uint16_t indent)
|
||||
|
||||
/************************************* RsTlvDsdvEntrySet ************************************/
|
||||
|
||||
#if 0
|
||||
RsTlvDsdvEntrySet::RsTlvDsdvEntrySet()
|
||||
{
|
||||
|
||||
@ -420,6 +414,6 @@ std::ostream &RsTlvDsdvEntrySet::print(std::ostream &out, uint16_t indent)
|
||||
}
|
||||
|
||||
|
||||
/************************************* RsTlvIpAddressInfo ************************************/
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef RS_TLV_DSDV_TYPES_H
|
||||
#define RS_TLV_DSDV_TYPES_H
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvdsdv.h
|
||||
@ -30,9 +29,9 @@
|
||||
* These are the Compound TLV structures that must be (un)packed.
|
||||
******************************************************************/
|
||||
|
||||
#include <map>
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "util/rsnet.h"
|
||||
#include "serialiser/rstlvitem.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvlist.h"
|
||||
|
||||
#define RSDSDV_MAX_ROUTE_TABLE 1000
|
||||
|
||||
@ -41,11 +40,11 @@ class RsTlvDsdvEndPoint: public RsTlvItem
|
||||
public:
|
||||
RsTlvDsdvEndPoint();
|
||||
virtual ~RsTlvDsdvEndPoint() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
|
||||
uint32_t idType;
|
||||
std::string anonChunk;
|
||||
@ -57,17 +56,20 @@ class RsTlvDsdvEntry: public RsTlvItem
|
||||
public:
|
||||
RsTlvDsdvEntry();
|
||||
virtual ~RsTlvDsdvEntry() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
|
||||
RsTlvDsdvEndPoint endPoint;
|
||||
uint32_t sequence;
|
||||
uint32_t distance;
|
||||
};
|
||||
|
||||
typedef t_RsTlvList<RsTlvDsdvEntry,TLV_TYPE_DSDV_ENTRY_SET> RsTlvDsdvEntrySet;
|
||||
|
||||
#if 0
|
||||
class RsTlvDsdvEntrySet: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
@ -82,6 +84,5 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
std::list<RsTlvDsdvEntry> entries;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -24,11 +24,15 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rstlvfileitem.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#if 0
|
||||
#include <iostream>
|
||||
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#endif
|
||||
|
||||
/***
|
||||
* #define TLV_FI_DEBUG 1
|
||||
@ -52,7 +56,7 @@ void RsTlvFileItem::TlvClear()
|
||||
hashset.TlvClear();
|
||||
}
|
||||
|
||||
uint32_t RsTlvFileItem::TlvSize()
|
||||
uint32_t RsTlvFileItem::TlvSize() const
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
s += 8; /* filesize */
|
||||
@ -119,7 +123,7 @@ uint32_t RsTlvFileItem::TlvSize()
|
||||
}
|
||||
|
||||
/* serialise the data to the buffer */
|
||||
bool RsTlvFileItem::SetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
bool RsTlvFileItem::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
@ -342,7 +346,7 @@ bool RsTlvFileItem::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
|
||||
|
||||
/* print it out */
|
||||
std::ostream &RsTlvFileItem::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream &RsTlvFileItem::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "RsTlvFileItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
@ -401,13 +405,13 @@ void RsTlvFileSet::TlvClear()
|
||||
items.clear();
|
||||
}
|
||||
|
||||
uint32_t RsTlvFileSet::TlvSize()
|
||||
uint32_t RsTlvFileSet::TlvSize() const
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
|
||||
/* first determine the total size of RstlvFileItems in list */
|
||||
|
||||
std::list<RsTlvFileItem>::iterator it;
|
||||
std::list<RsTlvFileItem>::const_iterator it;
|
||||
|
||||
for(it = items.begin(); it != items.end() ; ++it)
|
||||
{
|
||||
@ -427,7 +431,7 @@ uint32_t RsTlvFileSet::TlvSize()
|
||||
|
||||
/* serialize data to the buffer */
|
||||
|
||||
bool RsTlvFileSet::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvFileSet::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
@ -442,7 +446,7 @@ bool RsTlvFileSet::SetTlv(void *data, uint32_t size, uint32_t *offset) /* se
|
||||
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_FILESET, tlvsize);
|
||||
|
||||
/* add mandatory parts first */
|
||||
std::list<RsTlvFileItem>::iterator it;
|
||||
std::list<RsTlvFileItem>::const_iterator it;
|
||||
|
||||
for(it = items.begin(); it != items.end() ; ++it)
|
||||
{
|
||||
@ -542,7 +546,7 @@ bool RsTlvFileSet::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
|
||||
/* print it out */
|
||||
|
||||
std::ostream &RsTlvFileSet::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream &RsTlvFileSet::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "RsTlvFileSet", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
@ -550,7 +554,7 @@ std::ostream &RsTlvFileSet::print(std::ostream &out, uint16_t indent)
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Mandatory:" << std::endl;
|
||||
std::list<RsTlvFileItem>::iterator it;
|
||||
std::list<RsTlvFileItem>::const_iterator it;
|
||||
|
||||
for(it = items.begin(); it != items.end() ; ++it)
|
||||
{
|
||||
@ -595,7 +599,7 @@ void RsTlvFileData::TlvClear()
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsTlvFileData::TlvSize()
|
||||
uint32_t RsTlvFileData::TlvSize() const
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
|
||||
@ -608,7 +612,7 @@ uint32_t RsTlvFileData::TlvSize()
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvFileData::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvFileData::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
@ -633,7 +637,7 @@ bool RsTlvFileData::SetTlv(void *data, uint32_t size, uint32_t *offset) /* seria
|
||||
|
||||
}
|
||||
|
||||
bool RsTlvFileData::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvFileData::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
{
|
||||
@ -684,7 +688,7 @@ bool RsTlvFileData::GetTlv(void *data, uint32_t size, uint32_t *offset) /* seria
|
||||
}
|
||||
|
||||
/* print it out */
|
||||
std::ostream &RsTlvFileData::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream &RsTlvFileData::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "RsTlvFileData", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
93
libretroshare/src/serialiser/rstlvfileitem.h
Normal file
93
libretroshare/src/serialiser/rstlvfileitem.h
Normal file
@ -0,0 +1,93 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvfileitem.h
|
||||
*
|
||||
* 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".
|
||||
*
|
||||
*/
|
||||
|
||||
/*******************************************************************
|
||||
* These are the Compound TLV structures that must be (un)packed.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
#include "serialiser/rstlvitem.h"
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "serialiser/rstlvbinary.h"
|
||||
|
||||
class RsTlvFileItem: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvFileItem();
|
||||
virtual ~RsTlvFileItem() { return; }
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
|
||||
uint64_t filesize; /// Mandatory: size of file to be downloaded
|
||||
RsFileHash hash; /// Mandatory: to find file
|
||||
std::string name; /// Optional: name of file
|
||||
std::string path; /// Optional: path on host computer
|
||||
uint32_t pop; /// Optional: Popularity of file
|
||||
uint32_t age; /// Optional: age of file
|
||||
// For chunk hashing.
|
||||
uint32_t piecesize; /// Optional: bytes/piece for hashset.
|
||||
RsTlvHashSet hashset; /// Optional: chunk hashes.
|
||||
|
||||
};
|
||||
|
||||
class RsTlvFileSet: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvFileSet() { return; }
|
||||
virtual ~RsTlvFileSet() { return; }
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
|
||||
std::list<RsTlvFileItem> items; /// Mandatory
|
||||
std::string title; /// Optional: title of file set
|
||||
std::string comment; /// Optional: comments for file
|
||||
};
|
||||
|
||||
|
||||
class RsTlvFileData: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvFileData();
|
||||
virtual ~RsTlvFileData() { return; }
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
|
||||
RsTlvFileItem file; /// Mandatory: file information
|
||||
uint64_t file_offset; /// Mandatory: where to start in bin data
|
||||
RsTlvBinaryData binData; /// Mandatory: serialised file info
|
||||
};
|
||||
|
||||
|
@ -26,13 +26,16 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvitem.h"
|
||||
#include "serialiser/rstlvgenericparam.h"
|
||||
|
||||
#if 0
|
||||
#include <map>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "serialiser/rstlvgenericparam.h"
|
||||
#endif
|
||||
|
||||
/*********************************** RsTlvGenericPairRef ***********************************/
|
||||
|
||||
@ -46,11 +49,11 @@ class RsTlvGenericPairRef: public RsTlvItem
|
||||
mValueType(value_type), mKey(k), mValue(v) { return; }
|
||||
|
||||
virtual ~RsTlvGenericPairRef() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
|
||||
uint16_t mPairType;
|
||||
uint16_t mKeyType;
|
||||
@ -72,11 +75,11 @@ class RsTlvGenericMapRef: public RsTlvItem
|
||||
mKeyType(key_type), mValueType(value_type), mRefMap(refmap) { return; }
|
||||
|
||||
virtual ~RsTlvGenericMapRef() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
|
||||
uint16_t mMapType;
|
||||
uint16_t mPairType;
|
||||
|
@ -24,17 +24,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "rstlvbase.h"
|
||||
#include "rstlvtypes.h"
|
||||
#include "rstlvgenericmap.h"
|
||||
#include "rsbaseserial.h"
|
||||
#include "util/rsprint.h"
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
#define TLV_DEBUG 1
|
||||
// Must be different - as this is inline in headers.
|
||||
#define TLV_GENERICMAP_DEBUG 1
|
||||
|
||||
/*********************************** RsTlvGenericPairRef ***********************************/
|
||||
|
||||
@ -48,7 +40,7 @@ void RsTlvGenericPairRef<K, V>::TlvClear()
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
uint32_t RsTlvGenericPairRef<K, V>::TlvSize()
|
||||
uint32_t RsTlvGenericPairRef<K, V>::TlvSize() const
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
RsTlvParamRef<K> key(mKeyType, mKey);
|
||||
@ -61,7 +53,7 @@ uint32_t RsTlvGenericPairRef<K, V>::TlvSize()
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
bool RsTlvGenericPairRef<K, V>::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvGenericPairRef<K, V>::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
@ -94,7 +86,7 @@ bool RsTlvGenericPairRef<K, V>::SetTlv(void *data, uint32_t size, uint32_t *off
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
bool RsTlvGenericPairRef<K, V>::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvGenericPairRef<K, V>::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
@ -130,7 +122,7 @@ bool RsTlvGenericPairRef<K, V>::GetTlv(void *data, uint32_t size, uint32_t *off
|
||||
***************************************************************************/
|
||||
if (*offset != tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
#ifdef TLV_GENERICMAP_DEBUG
|
||||
std::cerr << "RsTlvGenericPairRef::GetTlv() Warning extra bytes at end of item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
@ -141,7 +133,7 @@ bool RsTlvGenericPairRef<K, V>::GetTlv(void *data, uint32_t size, uint32_t *off
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
std::ostream &RsTlvGenericPairRef<K, V>::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream &RsTlvGenericPairRef<K, V>::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
//printBase(out, "RsTlvGenericPairRef", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
@ -178,7 +170,7 @@ void RsTlvGenericMapRef<K, V>::TlvClear()
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
uint32_t RsTlvGenericMapRef<K, V>::TlvSize()
|
||||
uint32_t RsTlvGenericMapRef<K, V>::TlvSize() const
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
|
||||
@ -193,7 +185,7 @@ uint32_t RsTlvGenericMapRef<K, V>::TlvSize()
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
bool RsTlvGenericMapRef<K, V>::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvGenericMapRef<K, V>::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
@ -225,7 +217,7 @@ bool RsTlvGenericMapRef<K, V>::SetTlv(void *data, uint32_t size, uint32_t *offs
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
bool RsTlvGenericMapRef<K, V>::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvGenericMapRef<K, V>::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
@ -283,7 +275,7 @@ bool RsTlvGenericMapRef<K, V>::GetTlv(void *data, uint32_t size, uint32_t *offs
|
||||
***************************************************************************/
|
||||
if (*offset != tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
#ifdef TLV_GENERICMAP_DEBUG
|
||||
std::cerr << "RsTlvGenericMapRef::GetTlv() Warning extra bytes at end of item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
@ -294,7 +286,7 @@ bool RsTlvGenericMapRef<K, V>::GetTlv(void *data, uint32_t size, uint32_t *offs
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
std::ostream &RsTlvGenericMapRef<K, V>::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream &RsTlvGenericMapRef<K, V>::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
//printBase(out, "RsTlvGenericMapRef", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
@ -313,13 +305,3 @@ std::ostream &RsTlvGenericMapRef<K, V>::print(std::ostream &out, uint16_t indent
|
||||
return out;
|
||||
}
|
||||
|
||||
// declare likely combinations.
|
||||
//template class RsTlvGenericMapRef<uint32_t, uint32_t>;
|
||||
//template class RsTlvGenericMapRef<uint32_t, std::string>;
|
||||
//template class RsTlvGenericMapRef<std::string, uint32_t>;
|
||||
//template class RsTlvGenericMapRef<std::string, std::string>;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -24,21 +24,15 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "rstlvbase.h"
|
||||
#include "rstlvtypes.h"
|
||||
#include "rstlvgenericmap.h"
|
||||
#include "rsbaseserial.h"
|
||||
#include "util/rsprint.h"
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include "serialiser/rstlvgenericparam.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include <iostream>
|
||||
|
||||
#define TLV_DEBUG 1
|
||||
|
||||
/* generic print */
|
||||
template<class T>
|
||||
std::ostream & RsTlvParamRef<T>::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream & RsTlvParamRef<T>::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printIndent(out, indent);
|
||||
out << "Type: " << mParamType << " Param: " << mParam;
|
||||
@ -48,7 +42,7 @@ std::ostream & RsTlvParamRef<T>::print(std::ostream &out, uint16_t indent)
|
||||
|
||||
/***** uint16_t ****/
|
||||
template<>
|
||||
uint32_t RsTlvParamRef<uint16_t>::TlvSize()
|
||||
uint32_t RsTlvParamRef<uint16_t>::TlvSize() const
|
||||
{
|
||||
return GetTlvUInt16Size();
|
||||
}
|
||||
@ -60,7 +54,7 @@ void RsTlvParamRef<uint16_t>::TlvClear()
|
||||
}
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<uint16_t>::SetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
bool RsTlvParamRef<uint16_t>::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
uint16_t param = mParam;
|
||||
return SetTlvUInt16(data, size, offset, mParamType, mParam);
|
||||
@ -76,7 +70,7 @@ bool RsTlvParamRef<uint16_t>::GetTlv(void *data, uint32_t size, uint32_t *offset
|
||||
}
|
||||
|
||||
template<>
|
||||
std::ostream & RsTlvParamRef<uint16_t>::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream & RsTlvParamRef<uint16_t>::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printIndent(out, indent);
|
||||
out << "Type: " << mParamType << "Param: " << mParam;
|
||||
@ -87,7 +81,7 @@ std::ostream & RsTlvParamRef<uint16_t>::print(std::ostream &out, uint16_t indent
|
||||
/***** const uint16_t ****/
|
||||
|
||||
template<>
|
||||
uint32_t RsTlvParamRef<const uint16_t>::TlvSize()
|
||||
uint32_t RsTlvParamRef<const uint16_t>::TlvSize() const
|
||||
{
|
||||
return GetTlvUInt16Size();
|
||||
}
|
||||
@ -100,7 +94,7 @@ void RsTlvParamRef<const uint16_t>::TlvClear()
|
||||
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<const uint16_t>::SetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
bool RsTlvParamRef<const uint16_t>::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
return SetTlvUInt16(data, size, offset, mParamType, mParam);
|
||||
}
|
||||
@ -113,17 +107,16 @@ bool RsTlvParamRef<const uint16_t>::GetTlv(void *data, uint32_t size, uint32_t *
|
||||
|
||||
|
||||
template<>
|
||||
std::ostream & RsTlvParamRef<const uint16_t>::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream & RsTlvParamRef<const uint16_t>::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printIndent(out, indent);
|
||||
out << "Type: " << mParamType << "Param: " << mParam;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
/***** uint32_t ****/
|
||||
template<>
|
||||
uint32_t RsTlvParamRef<uint32_t>::TlvSize()
|
||||
uint32_t RsTlvParamRef<uint32_t>::TlvSize() const
|
||||
{
|
||||
return GetTlvUInt32Size();
|
||||
}
|
||||
@ -135,7 +128,7 @@ void RsTlvParamRef<uint32_t>::TlvClear()
|
||||
}
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<uint32_t>::SetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
bool RsTlvParamRef<uint32_t>::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
return SetTlvUInt32(data, size, offset, mParamType, mParam);
|
||||
}
|
||||
@ -147,7 +140,7 @@ bool RsTlvParamRef<uint32_t>::GetTlv(void *data, uint32_t size, uint32_t *offset
|
||||
}
|
||||
|
||||
template<>
|
||||
std::ostream & RsTlvParamRef<uint32_t>::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream & RsTlvParamRef<uint32_t>::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printIndent(out, indent);
|
||||
out << "Type: " << mParamType << "Param: " << mParam;
|
||||
@ -158,7 +151,7 @@ std::ostream & RsTlvParamRef<uint32_t>::print(std::ostream &out, uint16_t indent
|
||||
|
||||
/***** const uint32_t ****/
|
||||
template<>
|
||||
uint32_t RsTlvParamRef<const uint32_t>::TlvSize()
|
||||
uint32_t RsTlvParamRef<const uint32_t>::TlvSize() const
|
||||
{
|
||||
return GetTlvUInt32Size();
|
||||
}
|
||||
@ -170,7 +163,7 @@ void RsTlvParamRef<const uint32_t>::TlvClear()
|
||||
}
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<const uint32_t>::SetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
bool RsTlvParamRef<const uint32_t>::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
return SetTlvUInt32(data, size, offset, mParamType, mParam);
|
||||
}
|
||||
@ -183,7 +176,7 @@ bool RsTlvParamRef<const uint32_t>::GetTlv(void *data, uint32_t size, uint32_t *
|
||||
}
|
||||
|
||||
template<>
|
||||
std::ostream & RsTlvParamRef<const uint32_t>::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream & RsTlvParamRef<const uint32_t>::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printIndent(out, indent);
|
||||
out << "Type: " << mParamType << "Param: " << mParam;
|
||||
@ -193,7 +186,7 @@ std::ostream & RsTlvParamRef<const uint32_t>::print(std::ostream &out, uint16_t
|
||||
|
||||
/***** std::string ****/
|
||||
template<>
|
||||
uint32_t RsTlvParamRef<std::string>::TlvSize()
|
||||
uint32_t RsTlvParamRef<std::string>::TlvSize() const
|
||||
{
|
||||
return GetTlvStringSize(mParam);
|
||||
}
|
||||
@ -205,7 +198,7 @@ void RsTlvParamRef<std::string>::TlvClear()
|
||||
}
|
||||
|
||||
template<>
|
||||
bool RsTlvParamRef<std::string>::SetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
bool RsTlvParamRef<std::string>::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
return SetTlvString(data, size, offset, mParamType, mParam);
|
||||
}
|
||||
@ -217,7 +210,7 @@ bool RsTlvParamRef<std::string>::GetTlv(void *data, uint32_t size, uint32_t *off
|
||||
}
|
||||
|
||||
template<>
|
||||
std::ostream & RsTlvParamRef<std::string>::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream & RsTlvParamRef<std::string>::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printIndent(out, indent);
|
||||
out << "Type: " << mParamType << "Param: " << mParam;
|
||||
|
@ -26,11 +26,14 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvitem.h"
|
||||
|
||||
#if 0
|
||||
#include <map>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
|
||||
/**** TLV *****
|
||||
@ -44,11 +47,11 @@ class RsTlvParamRef: public RsTlvItem
|
||||
public:
|
||||
RsTlvParamRef(uint16_t param_type, T &p): mParamType(param_type), mParam(p) {}
|
||||
virtual ~RsTlvParamRef() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
|
||||
uint16_t mParamType;
|
||||
T &mParam;
|
||||
|
181
libretroshare/src/serialiser/rstlvidset.cc
Normal file
181
libretroshare/src/serialiser/rstlvidset.cc
Normal file
@ -0,0 +1,181 @@
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvtypes.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 "rstlvidset.h"
|
||||
|
||||
#if 0
|
||||
#include "rstlvbase.h"
|
||||
#include "rsbaseserial.h"
|
||||
#include "util/rsprint.h"
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
#define TLV_DEBUG 1
|
||||
|
||||
/************************************* Service Id Set ************************************/
|
||||
|
||||
void RsTlvServiceIdSet::TlvClear()
|
||||
{
|
||||
ids.clear();
|
||||
|
||||
}
|
||||
|
||||
uint32_t RsTlvServiceIdSet::TlvSize() const
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
|
||||
/* determine the total size of ids strings in list */
|
||||
std::list<uint32_t>::const_iterator it;
|
||||
for(it = ids.begin(); it != ids.end() ; ++it)
|
||||
{
|
||||
if (*it > 0)
|
||||
s += GetTlvUInt32Size();
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsTlvServiceIdSet::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true;
|
||||
|
||||
|
||||
/* start at data[offset] */
|
||||
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_SERVICESET , tlvsize);
|
||||
|
||||
/* determine the total size of ids strings in list */
|
||||
std::list<uint32_t>::const_iterator it;
|
||||
for(it = ids.begin(); it != ids.end() ; ++it)
|
||||
{
|
||||
if (*it > 0)
|
||||
ok &= SetTlvUInt32(data, tlvend, offset, TLV_TYPE_UINT32_SERID, *it);
|
||||
}
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
bool RsTlvServiceIdSet::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
|
||||
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend) /* check size */
|
||||
return false; /* not enough space */
|
||||
|
||||
if (tlvtype != TLV_TYPE_SERVICESET) /* check type */
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
/* while there is TLV */
|
||||
while((*offset) + 2 < tlvend)
|
||||
{
|
||||
/* get the next type */
|
||||
uint16_t tlvsubtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
|
||||
if (tlvsubtype == TLV_TYPE_UINT32_SERID)
|
||||
{
|
||||
uint32_t newIds;
|
||||
ok &= GetTlvUInt32(data, tlvend, offset, TLV_TYPE_UINT32_SERID, &newIds);
|
||||
if(ok)
|
||||
{
|
||||
ids.push_back(newIds);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Step past unknown TLV TYPE */
|
||||
ok &= SkipUnknownTlv(data, tlvend, offset);
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* NB: extra components could be added (for future expansion of the type).
|
||||
* or be present (if this code is reading an extended version).
|
||||
*
|
||||
* We must chew up the extra characters to conform with TLV specifications
|
||||
***************************************************************************/
|
||||
if (*offset != tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvServiceIdSet::GetTlv() Warning extra bytes at end of item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
*offset = tlvend;
|
||||
}
|
||||
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/// print to screen RsTlvServiceSet contents
|
||||
std::ostream &RsTlvServiceIdSet::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "RsTlvServiceIdSet", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
std::list<uint32_t>::const_iterator it;
|
||||
for(it = ids.begin(); it != ids.end() ; ++it)
|
||||
{
|
||||
printIndent(out, int_Indent);
|
||||
out << "id:" << *it;
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
printEnd(out, "RsTlvServiceIdSet", indent);
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
133
libretroshare/src/serialiser/rstlvidset.h
Normal file
133
libretroshare/src/serialiser/rstlvidset.h
Normal file
@ -0,0 +1,133 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvidset.h
|
||||
*
|
||||
* 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".
|
||||
*
|
||||
*/
|
||||
|
||||
/*******************************************************************
|
||||
* These are the Compound TLV structures that must be (un)packed.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvitem.h"
|
||||
|
||||
#include <retroshare/rstypes.h>
|
||||
#include <retroshare/rsgxsifacetypes.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
template<class ID_CLASS,uint32_t TLV_TYPE> class t_RsTlvIdSet: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
t_RsTlvIdSet() {}
|
||||
virtual ~t_RsTlvIdSet() {}
|
||||
|
||||
virtual uint32_t TlvSize() const { return ID_CLASS::SIZE_IN_BYTES * ids.size() + TLV_HEADER_SIZE; }
|
||||
virtual void TlvClear(){ ids.clear() ; }
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{ /* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* start at data[offset] */
|
||||
ok = ok && SetTlvBase(data, tlvend, offset, TLV_TYPE, tlvsize);
|
||||
|
||||
for(typename std::list<ID_CLASS>::const_iterator it(ids.begin());it!=ids.end();++it)
|
||||
ok = ok && (*it).serialise(data,size,*offset) ;
|
||||
|
||||
return ok ;
|
||||
}
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
|
||||
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend) /* check size */
|
||||
return false; /* not enough space */
|
||||
|
||||
if (tlvtype != TLV_TYPE) /* check type */
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
while(*offset + ID_CLASS::SIZE_IN_BYTES <= tlvend)
|
||||
{
|
||||
ID_CLASS id ;
|
||||
ok = ok && id.deserialise(data,size,*offset) ;
|
||||
ids.push_back(id) ;
|
||||
}
|
||||
if(*offset != tlvend)
|
||||
std::cerr << "(EE) deserialisaiton error in " << __PRETTY_FUNCTION__ << std::endl;
|
||||
return *offset == tlvend ;
|
||||
}
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t /* indent */) const
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": not implemented" << std::endl;
|
||||
return out ;
|
||||
}
|
||||
virtual std::ostream &printHex(std::ostream &out, uint16_t /* indent */) const /* SPECIAL One */
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": not implemented" << std::endl;
|
||||
return out ;
|
||||
}
|
||||
|
||||
std::list<ID_CLASS> ids ;
|
||||
};
|
||||
|
||||
typedef t_RsTlvIdSet<RsPeerId,TLV_TYPE_PEERSET> RsTlvPeerIdSet ;
|
||||
typedef t_RsTlvIdSet<RsPgpId,TLV_TYPE_PGPIDSET> RsTlvPgpIdSet ;
|
||||
typedef t_RsTlvIdSet<Sha1CheckSum,TLV_TYPE_HASHSET> RsTlvHashSet ;
|
||||
typedef t_RsTlvIdSet<RsGxsId,TLV_TYPE_GXSIDSET> RsTlvGxsIdSet ;
|
||||
|
||||
class RsTlvServiceIdSet: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvServiceIdSet() { return; }
|
||||
virtual ~RsTlvServiceIdSet() { return; }
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
|
||||
std::list<uint32_t> ids; /* Mandatory */
|
||||
};
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvfileitem.cc
|
||||
* libretroshare/src/serialiser: rstlvimage.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
@ -24,11 +24,14 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rstlvimage.h"
|
||||
|
||||
#if 0
|
||||
#include <iostream>
|
||||
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#endif
|
||||
|
||||
/***
|
||||
* #define TLV_IMG_DEBUG 1
|
||||
@ -49,7 +52,7 @@ void RsTlvImage::TlvClear()
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsTlvImage::TlvSize()
|
||||
uint32_t RsTlvImage::TlvSize() const
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
|
||||
@ -61,7 +64,7 @@ uint32_t RsTlvImage::TlvSize()
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvImage::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvImage::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
#ifdef TLV_IMG_DEBUG
|
||||
std::cerr << "RsTlvImage::SetTlv()" << std::endl;
|
||||
@ -108,7 +111,7 @@ bool RsTlvImage::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialis
|
||||
|
||||
}
|
||||
|
||||
bool RsTlvImage::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvImage::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
#ifdef TLV_IMG_DEBUG
|
||||
std::cerr << "RsTlvImage::GetTlv()" << std::endl;
|
||||
@ -176,7 +179,7 @@ bool RsTlvImage::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialis
|
||||
}
|
||||
|
||||
/* print it out */
|
||||
std::ostream &RsTlvImage::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream &RsTlvImage::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "RsTlvImage", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
55
libretroshare/src/serialiser/rstlvimage.h
Normal file
55
libretroshare/src/serialiser/rstlvimage.h
Normal file
@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvimage.h
|
||||
*
|
||||
* 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".
|
||||
*
|
||||
*/
|
||||
|
||||
/*******************************************************************
|
||||
* These are the Compound TLV structures that must be (un)packed.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
#include "serialiser/rstlvitem.h"
|
||||
#include "serialiser/rstlvbinary.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
class RsTlvImage: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvImage();
|
||||
RsTlvImage(const RsTlvImage& );
|
||||
virtual ~RsTlvImage() { return; }
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
|
||||
uint32_t image_type; // Mandatory:
|
||||
RsTlvBinaryData binData; // Mandatory: serialised file info
|
||||
};
|
||||
|
||||
|
197
libretroshare/src/serialiser/rstlvitem.cc
Normal file
197
libretroshare/src/serialiser/rstlvitem.cc
Normal file
@ -0,0 +1,197 @@
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvtypes.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 "rstlvitem.h"
|
||||
#include "rstlvbase.h"
|
||||
#include <iostream>
|
||||
|
||||
#if 0
|
||||
#include "rsbaseserial.h"
|
||||
#include "util/rsprint.h"
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#endif
|
||||
|
||||
#define TLV_DEBUG 1
|
||||
|
||||
void RsTlvItem::TlvShallowClear()
|
||||
{
|
||||
TlvClear(); /* unless overloaded! */
|
||||
}
|
||||
|
||||
std::ostream &RsTlvItem::printBase(std::ostream &out, std::string clsName, uint16_t indent) const
|
||||
{
|
||||
printIndent(out, indent);
|
||||
out << "RsTlvItem: " << clsName << " Size: " << TlvSize() << " ***********************";
|
||||
out << std::endl;
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream &RsTlvItem::printEnd(std::ostream &out, std::string clsName, uint16_t indent) const
|
||||
{
|
||||
printIndent(out, indent);
|
||||
out << "********************** " << clsName << " *********************";
|
||||
out << std::endl;
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream &printIndent(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
for(int i = 0; i < indent; i++)
|
||||
{
|
||||
out << " ";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
RsTlvUnit::RsTlvUnit(const uint16_t tlv_type)
|
||||
:RsTlvItem(), mTlvType(tlv_type)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t RsTlvUnit::TlvSize() const
|
||||
{
|
||||
return TLV_HEADER_SIZE + TlvSizeUnit();
|
||||
}
|
||||
|
||||
/* serialise */
|
||||
bool RsTlvUnit::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvUnit::SetTlv()" << std::endl;
|
||||
#endif
|
||||
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvImage::SetTlv() ERROR not enough space" << std::endl;
|
||||
#endif
|
||||
return false; /* not enough space */
|
||||
}
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* start at data[offset] */
|
||||
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_IMAGE , tlvsize);
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvUnit::SetTlv() ERROR Setting base" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
ok &= SetTlvUnit(data, tlvend, offset);
|
||||
|
||||
#ifdef TLV_DEBUG
|
||||
if (!ok)
|
||||
std::cerr << "RsTlvUnit::SetTlv() ERROR in SetTlvUnit" << std::endl;
|
||||
#endif
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* deserialise */
|
||||
bool RsTlvUnit::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvUnit::GetTlv() ERROR not enough size for header";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
uint16_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend) /* check size */
|
||||
{
|
||||
#ifdef TLV_IMG_DEBUG
|
||||
std::cerr << "RsTlvImage::GetTlv() ERROR no space";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
return false; /* not enough space */
|
||||
}
|
||||
|
||||
if (tlvtype != mTlvType) /* check type */
|
||||
{
|
||||
#ifdef TLV_IMG_DEBUG
|
||||
std::cerr << "RsTlvImage::GetTlv() ERROR wrong type";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
/* extract components */
|
||||
ok &= GetTlvUnit(data, tlvend, offset);
|
||||
|
||||
#ifdef TLV_IMG_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsTlvUnit::GetTlv() ERROR GetTlvUnit() NOK";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
/***************************************************************************
|
||||
* NB: extra components could be added (for future expansion of the type).
|
||||
* or be present (if this code is reading an extended version).
|
||||
*
|
||||
* We must chew up the extra characters to conform with TLV specifications
|
||||
***************************************************************************/
|
||||
if (*offset != tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvUnit::GetTlv() Warning extra bytes at end of item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
*offset = tlvend;
|
||||
}
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
|
82
libretroshare/src/serialiser/rstlvitem.h
Normal file
82
libretroshare/src/serialiser/rstlvitem.h
Normal file
@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvitem.h
|
||||
*
|
||||
* 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".
|
||||
*
|
||||
*/
|
||||
|
||||
/*******************************************************************
|
||||
* These are the Compound TLV structures that must be (un)packed.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
#include <inttypes.h>
|
||||
|
||||
//! A base class for all tlv items
|
||||
/*! This class is provided to allow the serialisation and deserialization of compund
|
||||
tlv items
|
||||
*/
|
||||
class RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvItem() { return; }
|
||||
virtual ~RsTlvItem() { return; }
|
||||
virtual uint32_t TlvSize() const = 0;
|
||||
virtual void TlvClear() = 0;
|
||||
virtual void TlvShallowClear(); /*! Don't delete allocated data */
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const = 0; /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset) = 0; /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const = 0;
|
||||
std::ostream &printBase(std::ostream &out, std::string clsName, uint16_t indent) const;
|
||||
std::ostream &printEnd(std::ostream &out, std::string clsName, uint16_t indent) const;
|
||||
};
|
||||
|
||||
std::ostream &printIndent(std::ostream &out, uint16_t indent);
|
||||
|
||||
|
||||
class RsTlvUnit: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvUnit(uint16_t tlv_type);
|
||||
virtual ~RsTlvUnit() { return; }
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
|
||||
virtual uint16_t TlvType() const { return mTlvType; }
|
||||
|
||||
// These Functions need to be implemented.
|
||||
//virtual void TlvClear() = 0;
|
||||
//virtual std::ostream &print(std::ostream &out, uint16_t indent) = 0 const;
|
||||
|
||||
virtual uint32_t TlvSizeUnit() const = 0;
|
||||
virtual bool SetTlvUnit(void *data, uint32_t size, uint32_t *offset) const = 0;
|
||||
virtual bool GetTlvUnit(void *data, uint32_t size, uint32_t *offset) = 0;
|
||||
|
||||
|
||||
private:
|
||||
uint16_t mTlvType;
|
||||
};
|
||||
|
||||
|
@ -25,13 +25,9 @@
|
||||
*/
|
||||
|
||||
#include "rstlvkeys.h"
|
||||
|
||||
#include "rstlvbase.h"
|
||||
#include "rstlvtypes.h"
|
||||
#include "rsbaseserial.h"
|
||||
#include "util/rsprint.h"
|
||||
#include <ostream>
|
||||
#include <iomanip>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#define TLV_DEBUG 1
|
||||
@ -65,7 +61,7 @@ void RsTlvSecurityKey::ShallowClear()
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsTlvSecurityKey::TlvSize()
|
||||
uint32_t RsTlvSecurityKey::TlvSize() const
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header + 4 for size */
|
||||
|
||||
@ -81,7 +77,7 @@ uint32_t RsTlvSecurityKey::TlvSize()
|
||||
|
||||
}
|
||||
|
||||
bool RsTlvSecurityKey::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvSecurityKey::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
@ -114,7 +110,7 @@ bool RsTlvSecurityKey::SetTlv(void *data, uint32_t size, uint32_t *offset) /* s
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvSecurityKey::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvSecurityKey::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
@ -180,11 +176,10 @@ bool RsTlvSecurityKey::GetTlv(void *data, uint32_t size, uint32_t *offset) /* s
|
||||
}
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::ostream &RsTlvSecurityKey::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream &RsTlvSecurityKey::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "RsTlvSecurityKey", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
@ -224,12 +219,12 @@ void RsTlvSecurityKeySet::TlvClear()
|
||||
keys.clear(); //empty list
|
||||
}
|
||||
|
||||
uint32_t RsTlvSecurityKeySet::TlvSize()
|
||||
uint32_t RsTlvSecurityKeySet::TlvSize() const
|
||||
{
|
||||
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
|
||||
std::map<std::string, RsTlvSecurityKey>::iterator it;
|
||||
std::map<std::string, RsTlvSecurityKey>::const_iterator it;
|
||||
|
||||
s += GetTlvStringSize(groupId);
|
||||
|
||||
@ -244,7 +239,7 @@ uint32_t RsTlvSecurityKeySet::TlvSize()
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsTlvSecurityKeySet::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvSecurityKeySet::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
@ -269,7 +264,7 @@ bool RsTlvSecurityKeySet::SetTlv(void *data, uint32_t size, uint32_t *offset) /
|
||||
|
||||
if(!keys.empty())
|
||||
{
|
||||
std::map<std::string, RsTlvSecurityKey>::iterator it;
|
||||
std::map<std::string, RsTlvSecurityKey>::const_iterator it;
|
||||
|
||||
for(it = keys.begin(); it != keys.end() ; ++it)
|
||||
ok &= (it->second).SetTlv(data, size, offset);
|
||||
@ -281,7 +276,7 @@ return ok;
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvSecurityKeySet::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvSecurityKeySet::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
@ -357,7 +352,7 @@ bool RsTlvSecurityKeySet::GetTlv(void *data, uint32_t size, uint32_t *offset) /
|
||||
}
|
||||
|
||||
// prints out contents of RsTlvSecurityKeySet
|
||||
std::ostream &RsTlvSecurityKeySet::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream &RsTlvSecurityKeySet::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "RsTlvSecurityKeySet", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
@ -366,7 +361,7 @@ std::ostream &RsTlvSecurityKeySet::print(std::ostream &out, uint16_t indent)
|
||||
out << "GroupId: " << groupId;
|
||||
out << std::endl;
|
||||
|
||||
std::map<std::string, RsTlvSecurityKey>::iterator it;
|
||||
std::map<std::string, RsTlvSecurityKey>::const_iterator it;
|
||||
for(it = keys.begin(); it != keys.end() ; ++it)
|
||||
(it->second).print(out, int_Indent);
|
||||
|
||||
@ -397,7 +392,7 @@ void RsTlvKeySignature::ShallowClear()
|
||||
signData.bin_len = 0;
|
||||
}
|
||||
|
||||
uint32_t RsTlvKeySignature::TlvSize()
|
||||
uint32_t RsTlvKeySignature::TlvSize() const
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header + 4 for size */
|
||||
|
||||
@ -407,7 +402,7 @@ uint32_t RsTlvKeySignature::TlvSize()
|
||||
|
||||
}
|
||||
|
||||
bool RsTlvKeySignature::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvKeySignature::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
@ -445,7 +440,7 @@ bool RsTlvKeySignature::SetTlv(void *data, uint32_t size, uint32_t *offset) /*
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvKeySignature::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
bool RsTlvKeySignature::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
@ -503,7 +498,7 @@ bool RsTlvKeySignature::GetTlv(void *data, uint32_t size, uint32_t *offset) /*
|
||||
}
|
||||
|
||||
|
||||
std::ostream &RsTlvKeySignature::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream &RsTlvKeySignature::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "RsTlvKeySignature", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
@ -528,19 +523,19 @@ RsTlvKeySignatureSet::RsTlvKeySignatureSet()
|
||||
|
||||
}
|
||||
|
||||
std::ostream &RsTlvKeySignatureSet::print(std::ostream &out, uint16_t indent)
|
||||
std::ostream &RsTlvKeySignatureSet::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "RsTlvKeySignatureSet", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
|
||||
std::map<SignType, RsTlvKeySignature>::iterator mit = keySignSet.begin();
|
||||
std::map<SignType, RsTlvKeySignature>::const_iterator mit = keySignSet.begin();
|
||||
|
||||
for(; mit != keySignSet.end(); mit++)
|
||||
{
|
||||
out << "SignType: " << mit->first << std::endl;
|
||||
RsTlvKeySignature& sign = mit->second;
|
||||
const RsTlvKeySignature& sign = mit->second;
|
||||
sign.print(out, indent);
|
||||
}
|
||||
|
||||
@ -555,7 +550,7 @@ void RsTlvKeySignatureSet::TlvClear()
|
||||
keySignSet.clear();
|
||||
}
|
||||
|
||||
bool RsTlvKeySignatureSet::SetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
bool RsTlvKeySignatureSet::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
|
||||
/* must check sizes */
|
||||
@ -579,7 +574,7 @@ bool RsTlvKeySignatureSet::SetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
|
||||
if(!keySignSet.empty())
|
||||
{
|
||||
std::map<SignType, RsTlvKeySignature>::iterator it;
|
||||
std::map<SignType, RsTlvKeySignature>::const_iterator it;
|
||||
|
||||
for(it = keySignSet.begin(); it != keySignSet.end() ; ++it)
|
||||
{
|
||||
@ -674,10 +669,10 @@ bool RsTlvKeySignatureSet::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
return ok;
|
||||
}
|
||||
|
||||
uint32_t RsTlvKeySignatureSet::TlvSize()
|
||||
uint32_t RsTlvKeySignatureSet::TlvSize() const
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; // header size
|
||||
std::map<SignType, RsTlvKeySignature>::iterator it;
|
||||
std::map<SignType, RsTlvKeySignature>::const_iterator it;
|
||||
|
||||
for(it = keySignSet.begin(); it != keySignSet.end() ; ++it)
|
||||
{
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef RS_TLV_KEY_TYPES_H
|
||||
#define RS_TLV_KEY_TYPES_H
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvkeys.h
|
||||
@ -30,8 +29,10 @@
|
||||
* These are the Compound TLV structures that must be (un)packed.
|
||||
******************************************************************/
|
||||
|
||||
#include "serialiser/rstlvitem.h"
|
||||
#include "serialiser/rstlvbinary.h"
|
||||
|
||||
#include <map>
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
|
||||
const uint32_t RSTLV_KEY_TYPE_MASK = 0x000f;
|
||||
const uint32_t RSTLV_KEY_DISTRIB_MASK = 0x00f0;
|
||||
@ -49,11 +50,11 @@ class RsTlvSecurityKey: public RsTlvItem
|
||||
public:
|
||||
RsTlvSecurityKey();
|
||||
virtual ~RsTlvSecurityKey() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
|
||||
/* clears KeyData - but doesn't delete - to transfer ownership */
|
||||
void ShallowClear();
|
||||
@ -70,11 +71,11 @@ class RsTlvSecurityKeySet: public RsTlvItem
|
||||
public:
|
||||
RsTlvSecurityKeySet() { return; }
|
||||
virtual ~RsTlvSecurityKeySet() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
|
||||
std::string groupId; // Mandatory :
|
||||
std::map<std::string, RsTlvSecurityKey> keys; // Mandatory :
|
||||
@ -86,11 +87,11 @@ class RsTlvKeySignature: public RsTlvItem
|
||||
public:
|
||||
RsTlvKeySignature();
|
||||
virtual ~RsTlvKeySignature() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
|
||||
void ShallowClear(); /* clears signData - but doesn't delete */
|
||||
|
||||
@ -106,15 +107,13 @@ class RsTlvKeySignatureSet : public RsTlvItem
|
||||
public:
|
||||
RsTlvKeySignatureSet();
|
||||
virtual ~RsTlvKeySignatureSet() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
|
||||
std::map<SignType, RsTlvKeySignature> keySignSet; // mandatory
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -1,291 +1,301 @@
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvkvwide.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by 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 "rstlvbase.h"
|
||||
#include "rstlvkvwide.h"
|
||||
#include "rsbaseserial.h"
|
||||
#include "util/rsprint.h"
|
||||
#include <ostream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
void RsTlvKeyValueWide::TlvClear()
|
||||
{
|
||||
wKey.clear();
|
||||
wValue.clear();
|
||||
}
|
||||
|
||||
uint32_t RsTlvKeyValueWide::TlvSize()
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header size */
|
||||
s += GetTlvWideStringSize(wKey);
|
||||
s += GetTlvWideStringSize(wValue);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
std::ostream &RsTlvKeyValueWide::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printBase(out, "RsTlvKeyValueWide", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
std::string cnv_str(wKey.begin(), wKey.end()); // to convert to string
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "wKey:" << cnv_str;
|
||||
cnv_str.clear();
|
||||
cnv_str.assign(wValue.begin(), wValue.end());
|
||||
printIndent(out, int_Indent);
|
||||
out << "wValue:" << cnv_str;
|
||||
out << std::endl;
|
||||
|
||||
printEnd(out, "RsTlvKeyValuewide", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
bool RsTlvKeyValueWide::SetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* start at data[offset] */
|
||||
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_WKEYVALUE, tlvsize);
|
||||
|
||||
|
||||
|
||||
/* now optional ones */
|
||||
if (wKey.length() > 0)
|
||||
ok &= SetTlvWideString(data, tlvend, offset, TLV_TYPE_WSTR_KEY, wKey); // no base tlv type for title?
|
||||
if (wValue.length() > 0)
|
||||
ok &= SetTlvWideString(data, tlvend, offset, TLV_TYPE_WSTR_VALUE, wValue); // no base tlv type for comment?
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsTlvKeyValueWide::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]) );
|
||||
uint16_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend) /* check size */
|
||||
return false; /* not enough space */
|
||||
|
||||
if (tlvtype != TLV_TYPE_WKEYVALUE ) /* check type */
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
/* while there is TLV */
|
||||
while((*offset) + 2 < tlvend)
|
||||
{
|
||||
/* get the next type */
|
||||
uint16_t tlvsubtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
|
||||
switch(tlvsubtype)
|
||||
{
|
||||
case TLV_TYPE_WSTR_KEY:
|
||||
ok &= GetTlvWideString(data, tlvend, offset, TLV_TYPE_WSTR_KEY, wKey);
|
||||
break;
|
||||
case TLV_TYPE_WSTR_VALUE:
|
||||
ok &= GetTlvWideString(data, tlvend, offset, TLV_TYPE_WSTR_VALUE, wValue);
|
||||
break;
|
||||
default:
|
||||
ok &= SkipUnknownTlv(data, tlvend, offset);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* NB: extra components could be added (for future expansion of the type).
|
||||
* or be present (if this code is reading an extended version).
|
||||
*
|
||||
* We must chew up the extra characters to conform with TLV specifications
|
||||
***************************************************************************/
|
||||
if (*offset != tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvKeyValueWide::GetTlv() Warning extra bytes at end of item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
*offset = tlvend;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/******************************************* Wide Key Value set *************************************/
|
||||
|
||||
|
||||
void RsTlvKeyValueWideSet::TlvClear()
|
||||
{
|
||||
wPairs.clear();
|
||||
}
|
||||
|
||||
uint32_t RsTlvKeyValueWideSet::TlvSize()
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header size */
|
||||
|
||||
std::list<RsTlvKeyValueWide>::iterator it;
|
||||
|
||||
for(it = wPairs.begin(); it != wPairs.end(); it++)
|
||||
{
|
||||
s += it->TlvSize();
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
std::ostream &RsTlvKeyValueWideSet::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printBase(out, "RsTlvKeyValueWide", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
std::list<RsTlvKeyValueWide>::iterator it;
|
||||
|
||||
for(it = wPairs.begin(); it != wPairs.end(); it++)
|
||||
{
|
||||
it->print(out, int_Indent);
|
||||
}
|
||||
|
||||
printEnd(out, "RsTlvKeyValuewide", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
bool RsTlvKeyValueWideSet::SetTlv(void *data, uint32_t size, uint32_t* offset)
|
||||
{
|
||||
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* start at data[offset] */
|
||||
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_WKEYVALUESET, tlvsize);
|
||||
std::list<RsTlvKeyValueWide>::iterator it;
|
||||
|
||||
for(it = wPairs.begin(); it != wPairs.end(); it++)
|
||||
{
|
||||
ok &= it->SetTlv(data, size, offset);
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsTlvKeyValueWideSet::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]) );
|
||||
uint16_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend) /* check size */
|
||||
return false; /* not enough space */
|
||||
|
||||
if (tlvtype != TLV_TYPE_WKEYVALUESET) /* check type */
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
/* while there is TLV */
|
||||
while((*offset) + 2 < tlvend)
|
||||
{
|
||||
/* get the next type */
|
||||
uint16_t tlvsubtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
|
||||
switch(tlvsubtype)
|
||||
{
|
||||
case TLV_TYPE_WKEYVALUE:
|
||||
{
|
||||
RsTlvKeyValueWide kv;
|
||||
ok &= kv.GetTlv(data, size, offset);
|
||||
if (ok)
|
||||
{
|
||||
wPairs.push_back(kv);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ok &= SkipUnknownTlv(data, tlvend, offset);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* NB: extra components could be added (for future expansion of the type).
|
||||
* or be present (if this code is reading an extended version).
|
||||
*
|
||||
* We must chew up the extra characters to conform with TLV specifications
|
||||
***************************************************************************/
|
||||
if (*offset != tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvBinaryData::GetTlv() Warning extra bytes at end of item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
*offset = tlvend;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvtypes.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 "rstlvkeyvalue.h"
|
||||
#include "rstlvbase.h"
|
||||
|
||||
#define TLV_DEBUG 1
|
||||
|
||||
|
||||
void RsTlvKeyValue::TlvClear()
|
||||
{
|
||||
key = "";
|
||||
value = "";
|
||||
}
|
||||
|
||||
uint32_t RsTlvKeyValue::TlvSize() const
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
|
||||
/* now add comment and title length of this tlv object */
|
||||
|
||||
if (key.length() > 0)
|
||||
s += GetTlvStringSize(key);
|
||||
if (value.length() > 0)
|
||||
s += GetTlvStringSize(value);
|
||||
|
||||
return s;
|
||||
|
||||
}
|
||||
|
||||
bool RsTlvKeyValue::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* start at data[offset] */
|
||||
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_KEYVALUE, tlvsize);
|
||||
|
||||
|
||||
|
||||
/* now optional ones */
|
||||
if (key.length() > 0)
|
||||
ok &= SetTlvString(data, tlvend, offset, TLV_TYPE_STR_KEY, key); // no base tlv type for title?
|
||||
if (value.length() > 0)
|
||||
ok &= SetTlvString(data, tlvend, offset, TLV_TYPE_STR_VALUE, value); // no base tlv type for comment?
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
bool RsTlvKeyValue::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
|
||||
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend) /* check size */
|
||||
return false; /* not enough space */
|
||||
|
||||
if (tlvtype != TLV_TYPE_KEYVALUE) /* check type */
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
/* while there is TLV */
|
||||
while((*offset) + 2 < tlvend)
|
||||
{
|
||||
/* get the next type */
|
||||
uint16_t tlvsubtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
|
||||
switch(tlvsubtype)
|
||||
{
|
||||
case TLV_TYPE_STR_KEY:
|
||||
ok &= GetTlvString(data, tlvend, offset, TLV_TYPE_STR_KEY, key);
|
||||
break;
|
||||
case TLV_TYPE_STR_VALUE:
|
||||
ok &= GetTlvString(data, tlvend, offset, TLV_TYPE_STR_VALUE, value);
|
||||
break;
|
||||
default:
|
||||
ok &= SkipUnknownTlv(data, tlvend, offset);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* NB: extra components could be added (for future expansion of the type).
|
||||
* or be present (if this code is reading an extended version).
|
||||
*
|
||||
* We must chew up the extra characters to conform with TLV specifications
|
||||
***************************************************************************/
|
||||
if (*offset != tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvKeyValue::GetTlv() Warning extra bytes at end of item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
*offset = tlvend;
|
||||
}
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
std::ostream &RsTlvKeyValue::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "RsTlvKeyValue", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Key:" << key;
|
||||
printIndent(out, int_Indent);
|
||||
out << "Value:" << value;
|
||||
out << std::endl;
|
||||
|
||||
|
||||
printEnd(out, "RsTlvKeyValue", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
/************************************* RsTlvKeyValueSet ************************************/
|
||||
|
||||
void RsTlvKeyValueSet::TlvClear()
|
||||
{
|
||||
pairs.clear(); //empty list
|
||||
}
|
||||
|
||||
uint32_t RsTlvKeyValueSet::TlvSize() const
|
||||
{
|
||||
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
|
||||
std::list<RsTlvKeyValue>::const_iterator it;
|
||||
|
||||
if(!pairs.empty())
|
||||
{
|
||||
|
||||
for(it = pairs.begin(); it != pairs.end() ; ++it)
|
||||
s += it->TlvSize();
|
||||
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsTlvKeyValueSet::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* start at data[offset] */
|
||||
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_KEYVALUESET , tlvsize);
|
||||
|
||||
|
||||
if(!pairs.empty())
|
||||
{
|
||||
std::list<RsTlvKeyValue>::const_iterator it;
|
||||
|
||||
for(it = pairs.begin(); it != pairs.end() ; ++it)
|
||||
ok &= it->SetTlv(data, size, offset);
|
||||
}
|
||||
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvKeyValueSet::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
|
||||
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend) /* check size */
|
||||
return false; /* not enough space */
|
||||
|
||||
if (tlvtype != TLV_TYPE_KEYVALUESET) /* check type */
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
/* while there is TLV */
|
||||
while((*offset) + 2 < tlvend)
|
||||
{
|
||||
/* get the next type */
|
||||
uint16_t tlvsubtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
|
||||
switch(tlvsubtype)
|
||||
{
|
||||
case TLV_TYPE_KEYVALUE:
|
||||
{
|
||||
RsTlvKeyValue kv;
|
||||
ok &= kv.GetTlv(data, size, offset);
|
||||
if (ok)
|
||||
{
|
||||
pairs.push_back(kv);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ok &= SkipUnknownTlv(data, tlvend, offset);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
break;
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* NB: extra components could be added (for future expansion of the type).
|
||||
* or be present (if this code is reading an extended version).
|
||||
*
|
||||
* We must chew up the extra characters to conform with TLV specifications
|
||||
***************************************************************************/
|
||||
if (*offset != tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvKeyValueSet::GetTlv() Warning extra bytes at end of item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
*offset = tlvend;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/// prints out contents of RsTlvKeyValueSet
|
||||
std::ostream &RsTlvKeyValueSet::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "RsTlvKeyValue", indent);
|
||||
|
||||
std::list<RsTlvKeyValue>::const_iterator it;
|
||||
|
||||
for(it = pairs.begin(); it != pairs.end() ; ++it)
|
||||
it->print(out, indent);
|
||||
|
||||
printEnd(out, "RsTlvKeyValue", indent);
|
||||
return out;
|
||||
}
|
||||
|
66
libretroshare/src/serialiser/rstlvkeyvalue.h
Normal file
66
libretroshare/src/serialiser/rstlvkeyvalue.h
Normal file
@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvkeyvalue.h
|
||||
*
|
||||
* 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".
|
||||
*
|
||||
*/
|
||||
|
||||
/*******************************************************************
|
||||
* These are the Compound TLV structures that must be (un)packed.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
#include "serialiser/rstlvitem.h"
|
||||
#include <list>
|
||||
|
||||
class RsTlvKeyValue: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvKeyValue() { return; }
|
||||
RsTlvKeyValue(const std::string& k,const std::string& v): key(k),value(v) {}
|
||||
virtual ~RsTlvKeyValue() { return; }
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
|
||||
std::string key; /// Mandatory : For use in hash tables
|
||||
std::string value; /// Mandatory : For use in hash tables
|
||||
};
|
||||
|
||||
class RsTlvKeyValueSet: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvKeyValueSet() { return; }
|
||||
virtual ~RsTlvKeyValueSet() { return; }
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
|
||||
std::list<RsTlvKeyValue> pairs; /// For use in hash tables
|
||||
};
|
||||
|
||||
|
@ -1,66 +0,0 @@
|
||||
#ifndef RSTLVKVWIDE_H_
|
||||
#define RSTLVKVWIDE_H_
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvkvwide.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by 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 "rstlvtypes.h"
|
||||
|
||||
class RsTlvKeyValueWide: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsTlvKeyValueWide() { return;}
|
||||
virtual ~RsTlvKeyValueWide() { return;}
|
||||
|
||||
virtual uint32_t TlvSize();
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
std::wstring wKey;
|
||||
std::wstring wValue;
|
||||
};
|
||||
|
||||
|
||||
class RsTlvKeyValueWideSet : public RsTlvItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsTlvKeyValueWideSet() { return;}
|
||||
virtual ~RsTlvKeyValueWideSet() { return; }
|
||||
|
||||
virtual uint32_t TlvSize();
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
std::list<RsTlvKeyValueWide> wPairs;
|
||||
};
|
||||
|
||||
|
||||
#endif /*RSTLVKVWIDE_H_*/
|
129
libretroshare/src/serialiser/rstlvlist.h
Normal file
129
libretroshare/src/serialiser/rstlvlist.h
Normal file
@ -0,0 +1,129 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvlist.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2014 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvitem.h"
|
||||
|
||||
#include <list>
|
||||
|
||||
template<class TLV_CLASS,uint32_t TLV_TYPE> class t_RsTlvList: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
t_RsTlvList() {}
|
||||
virtual ~t_RsTlvList() {}
|
||||
|
||||
virtual uint32_t TlvSize() const
|
||||
{
|
||||
uint32_t size = TLV_HEADER_SIZE;
|
||||
typename std::list<TLV_CLASS>::const_iterator it;
|
||||
for(it = mList.begin();it != mList.end(); ++it)
|
||||
{
|
||||
size += it->TlvSize();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
virtual void TlvClear(){ mList.clear(); }
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* start at data[offset] */
|
||||
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE, tlvsize);
|
||||
|
||||
typename std::list<TLV_CLASS>::const_iterator it;
|
||||
for(it = mList.begin();it != mList.end(); ++it)
|
||||
{
|
||||
ok &= it->SetTlv(data,tlvsize,offset) ;
|
||||
}
|
||||
|
||||
return ok ;
|
||||
}
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
|
||||
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend) /* check size */
|
||||
return false; /* not enough space */
|
||||
|
||||
if (tlvtype != TLV_TYPE) /* check type */
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
/* while there is TLV : 2 (type) + 4 (len) */
|
||||
while(ok && ((*offset) + 6 < tlvend))
|
||||
{
|
||||
TLV_CLASS item;
|
||||
ok &= item.GetTlv(data,size,offset);
|
||||
if (ok)
|
||||
{
|
||||
mList.push_back(item);
|
||||
}
|
||||
}
|
||||
|
||||
if(*offset != tlvend)
|
||||
{
|
||||
std::cerr << "(EE) deserialisation error in " << __PRETTY_FUNCTION__ << std::endl;
|
||||
}
|
||||
return *offset == tlvend ;
|
||||
}
|
||||
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "Template TlvList", indent);
|
||||
typename std::list<TLV_CLASS>::const_iterator it;
|
||||
for(it = mList.begin();it != mList.end(); ++it)
|
||||
{
|
||||
it->print(out, indent + 2) ;
|
||||
}
|
||||
printEnd(out, "Template TlvList", indent);
|
||||
return out ;
|
||||
}
|
||||
|
||||
std::list<TLV_CLASS> mList;
|
||||
};
|
||||
|
||||
|
||||
|
@ -26,8 +26,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#include "serialiser/rstlvgenericmaps.h"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
class RsTlvOpinionMapRef: public RsTlvGenericMapRef<std::string, uint32_t>
|
||||
{
|
||||
|
376
libretroshare/src/serialiser/rstlvstring.cc
Normal file
376
libretroshare/src/serialiser/rstlvstring.cc
Normal file
@ -0,0 +1,376 @@
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvstring.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/rstlvstring.h"
|
||||
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "util/rsprint.h"
|
||||
#include <iostream>
|
||||
|
||||
#define TLV_DEBUG 1
|
||||
|
||||
/************************************* Peer Id Set ************************************/
|
||||
|
||||
|
||||
RsTlvStringSet::RsTlvStringSet(uint16_t type) :mType(type)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvStringSet::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true;
|
||||
|
||||
|
||||
/* start at data[offset] */
|
||||
ok &= SetTlvBase(data, tlvend, offset, mType , tlvsize);
|
||||
|
||||
/* determine the total size of ids strings in list */
|
||||
|
||||
std::list<std::string>::const_iterator it;
|
||||
|
||||
for(it = ids.begin(); it != ids.end() ; ++it)
|
||||
{
|
||||
if (it->length() > 0)
|
||||
ok &= SetTlvString(data, tlvend, offset, TLV_TYPE_STR_GENID, *it);
|
||||
}
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void RsTlvStringSet::TlvClear()
|
||||
{
|
||||
ids.clear();
|
||||
|
||||
}
|
||||
|
||||
uint32_t RsTlvStringSet::TlvSize() const
|
||||
{
|
||||
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
|
||||
/* determine the total size of ids strings in list */
|
||||
|
||||
std::list<std::string>::const_iterator it;
|
||||
|
||||
for(it = ids.begin(); it != ids.end() ; ++it)
|
||||
{
|
||||
if (it->length() > 0)
|
||||
s += GetTlvStringSize(*it);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvStringSet::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 != mType) /* check type */
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
|
||||
|
||||
/* while there is TLV */
|
||||
while((*offset) + 2 < tlvend)
|
||||
{
|
||||
/* get the next type */
|
||||
uint16_t tlvsubtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
|
||||
if (tlvsubtype == TLV_TYPE_STR_GENID)
|
||||
{
|
||||
std::string newIds;
|
||||
ok &= GetTlvString(data, tlvend, offset, TLV_TYPE_STR_GENID, newIds);
|
||||
if(ok)
|
||||
{
|
||||
ids.push_back(newIds);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Step past unknown TLV TYPE */
|
||||
ok &= SkipUnknownTlv(data, tlvend, offset);
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* NB: extra components could be added (for future expansion of the type).
|
||||
* or be present (if this code is reading an extended version).
|
||||
*
|
||||
* We must chew up the extra characters to conform with TLV specifications
|
||||
***************************************************************************/
|
||||
if (*offset != tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvPeerIdSet::GetTlv() Warning extra bytes at end of item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
*offset = tlvend;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/// print to screen RsTlvStringSet contents
|
||||
std::ostream &RsTlvStringSet::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "RsTlvStringSet", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "type:" << mType;
|
||||
out << std::endl;
|
||||
|
||||
std::list<std::string>::const_iterator it;
|
||||
for(it = ids.begin(); it != ids.end() ; ++it)
|
||||
{
|
||||
printIndent(out, int_Indent);
|
||||
out << "id:" << *it;
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
printEnd(out, "RsTlvStringSet", indent);
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
/// print to screen RsTlvStringSet contents
|
||||
std::ostream &RsTlvStringSet::printHex(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "RsTlvStringSet", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "type:" << mType;
|
||||
out << std::endl;
|
||||
|
||||
std::list<std::string>::const_iterator it;
|
||||
for(it = ids.begin(); it != ids.end() ; ++it)
|
||||
{
|
||||
printIndent(out, int_Indent);
|
||||
out << "id: 0x" << RsUtil::BinToHex(*it);
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
printEnd(out, "RsTlvStringSet", indent);
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/************************************* String Set Ref ************************************/
|
||||
/* This is exactly the same as StringSet, but it uses an alternative list.
|
||||
*/
|
||||
RsTlvStringSetRef::RsTlvStringSetRef(uint16_t type, std::list<std::string> &refids)
|
||||
:mType(type), ids(refids)
|
||||
{
|
||||
}
|
||||
|
||||
void RsTlvStringSetRef::TlvClear()
|
||||
{
|
||||
ids.clear();
|
||||
|
||||
}
|
||||
|
||||
uint32_t RsTlvStringSetRef::TlvSize() const
|
||||
{
|
||||
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
|
||||
/* determine the total size of ids strings in list */
|
||||
|
||||
std::list<std::string>::const_iterator it;
|
||||
|
||||
for(it = ids.begin(); it != ids.end() ; ++it)
|
||||
{
|
||||
if (it->length() > 0)
|
||||
s += GetTlvStringSize(*it);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvStringSetRef::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true;
|
||||
|
||||
|
||||
/* start at data[offset] */
|
||||
ok &= SetTlvBase(data, tlvend, offset, mType , tlvsize);
|
||||
|
||||
/* determine the total size of ids strings in list */
|
||||
|
||||
std::list<std::string>::const_iterator it;
|
||||
|
||||
for(it = ids.begin(); it != ids.end() ; ++it)
|
||||
{
|
||||
if (it->length() > 0)
|
||||
ok &= SetTlvString(data, tlvend, offset, TLV_TYPE_STR_GENID, *it);
|
||||
}
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvStringSetRef::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 != mType) /* check type */
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
|
||||
|
||||
/* while there is TLV */
|
||||
while((*offset) + 2 < tlvend)
|
||||
{
|
||||
/* get the next type */
|
||||
uint16_t tlvsubtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
|
||||
if (tlvsubtype == TLV_TYPE_STR_GENID)
|
||||
{
|
||||
std::string newIds;
|
||||
ok &= GetTlvString(data, tlvend, offset, TLV_TYPE_STR_GENID, newIds);
|
||||
if(ok)
|
||||
{
|
||||
ids.push_back(newIds);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Step past unknown TLV TYPE */
|
||||
ok &= SkipUnknownTlv(data, tlvend, offset);
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* NB: extra components could be added (for future expansion of the type).
|
||||
* or be present (if this code is reading an extended version).
|
||||
*
|
||||
* We must chew up the extra characters to conform with TLV specifications
|
||||
***************************************************************************/
|
||||
if (*offset != tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvPeerIdSetRef::GetTlv() Warning extra bytes at end of item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
*offset = tlvend;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/// print to screen RsTlvStringSet contents
|
||||
std::ostream &RsTlvStringSetRef::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "RsTlvStringSetRef", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "type:" << mType;
|
||||
out << std::endl;
|
||||
|
||||
std::list<std::string>::const_iterator it;
|
||||
for(it = ids.begin(); it != ids.end() ; ++it)
|
||||
{
|
||||
printIndent(out, int_Indent);
|
||||
out << "id:" << *it;
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
printEnd(out, "RsTlvStringSetRef", indent);
|
||||
return out;
|
||||
|
||||
}
|
||||
|
68
libretroshare/src/serialiser/rstlvstring.h
Normal file
68
libretroshare/src/serialiser/rstlvstring.h
Normal file
@ -0,0 +1,68 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvstring.h
|
||||
*
|
||||
* 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".
|
||||
*
|
||||
*/
|
||||
|
||||
/*******************************************************************
|
||||
* These are the Compound TLV structures that must be (un)packed.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
#include "serialiser/rstlvitem.h"
|
||||
|
||||
#include <list>
|
||||
|
||||
class RsTlvStringSet: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvStringSet(uint16_t type);
|
||||
virtual ~RsTlvStringSet() { return; }
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
virtual std::ostream &printHex(std::ostream &out, uint16_t indent) const;
|
||||
|
||||
uint16_t mType;
|
||||
std::list<std::string> ids; /* Mandatory */
|
||||
};
|
||||
|
||||
class RsTlvStringSetRef: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvStringSetRef(uint16_t type, std::list<std::string> &refids);
|
||||
virtual ~RsTlvStringSetRef() { return; }
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
|
||||
uint16_t mType;
|
||||
std::list<std::string> &ids; /* Mandatory */
|
||||
};
|
||||
|
||||
|
@ -1,997 +0,0 @@
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvtypes.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 "rstlvbase.h"
|
||||
#include "rstlvtypes.h"
|
||||
#include "rsbaseserial.h"
|
||||
#include "util/rsprint.h"
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
#define TLV_DEBUG 1
|
||||
|
||||
void RsTlvItem::TlvShallowClear()
|
||||
{
|
||||
TlvClear(); /* unless overloaded! */
|
||||
}
|
||||
|
||||
std::ostream &RsTlvItem::printBase(std::ostream &out, std::string clsName, uint16_t indent)
|
||||
{
|
||||
printIndent(out, indent);
|
||||
out << "RsTlvItem: " << clsName << " Size: " << TlvSize() << " ***********************";
|
||||
out << std::endl;
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream &RsTlvItem::printEnd(std::ostream &out, std::string clsName, uint16_t indent)
|
||||
{
|
||||
printIndent(out, indent);
|
||||
out << "********************** " << clsName << " *********************";
|
||||
out << std::endl;
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream &printIndent(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
for(int i = 0; i < indent; i++)
|
||||
{
|
||||
out << " ";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*!********************************** RsTlvFileBinaryData **********************************/
|
||||
|
||||
|
||||
RsTlvBinaryData::RsTlvBinaryData(uint16_t t)
|
||||
:tlvtype(t), bin_len(0), bin_data(NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RsTlvBinaryData::RsTlvBinaryData(const RsTlvBinaryData &b)
|
||||
: tlvtype(b.tlvtype), bin_len(0) , bin_data(NULL) {
|
||||
|
||||
setBinData(b.bin_data, b.bin_len);
|
||||
}
|
||||
|
||||
RsTlvBinaryData::~RsTlvBinaryData()
|
||||
{
|
||||
TlvClear();
|
||||
}
|
||||
|
||||
void RsTlvBinaryData::operator =(const RsTlvBinaryData& b){
|
||||
|
||||
setBinData(b.bin_data, b.bin_len);
|
||||
tlvtype = b.tlvtype;
|
||||
}
|
||||
|
||||
/// used to allocate memory andinitialize binary data member
|
||||
bool RsTlvBinaryData::setBinData(const void *data, uint32_t size)
|
||||
{
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* get mandatory */
|
||||
/* the rest of the TLV size binary data */
|
||||
bin_len = size;
|
||||
if (bin_len == 0)
|
||||
{
|
||||
bin_data = NULL;
|
||||
return true;
|
||||
}
|
||||
|
||||
bin_data = malloc(bin_len);
|
||||
memcpy(bin_data, data, bin_len);
|
||||
return true;
|
||||
}
|
||||
|
||||
void RsTlvBinaryData::TlvClear()
|
||||
{
|
||||
if (bin_data)
|
||||
{
|
||||
free(bin_data);
|
||||
}
|
||||
TlvShallowClear();
|
||||
}
|
||||
|
||||
void RsTlvBinaryData::TlvShallowClear()
|
||||
{
|
||||
bin_data = NULL;
|
||||
bin_len = 0;
|
||||
}
|
||||
|
||||
uint32_t RsTlvBinaryData::TlvSize()
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
|
||||
if (bin_data != NULL)
|
||||
s += bin_len; // len is the size of data
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvBinaryData::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* start at data[offset] */
|
||||
ok &= SetTlvBase(data, tlvend, offset, tlvtype, tlvsize);
|
||||
|
||||
/* add mandatory data */
|
||||
|
||||
// Warning: this is actually not an error if bin_len=0, as it does not
|
||||
// corrupt the packet structure. We thus still return true in this case.
|
||||
//
|
||||
if (bin_data != NULL && bin_len > 0)
|
||||
{
|
||||
memcpy(&(((uint8_t *) data)[*offset]), bin_data, bin_len);
|
||||
*offset += bin_len;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool RsTlvBinaryData::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
{
|
||||
return false; /* not enough space to get the header */
|
||||
}
|
||||
|
||||
uint16_t tlvtype_in = 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 (tlvsize < TLV_HEADER_SIZE)
|
||||
{
|
||||
return false; /* bad tlv size */
|
||||
}
|
||||
|
||||
if (tlvtype != tlvtype_in) /* check type */
|
||||
return false;
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
bool ok = setBinData(&(((uint8_t *) data)[*offset]), tlvsize - TLV_HEADER_SIZE);
|
||||
(*offset) += bin_len;
|
||||
|
||||
/***************************************************************************
|
||||
* NB: extra components could be added (for future expansion of the type).
|
||||
* or be present (if this code is reading an extended version).
|
||||
*
|
||||
* We must chew up the extra characters to conform with TLV specifications
|
||||
***************************************************************************/
|
||||
if (*offset != tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvBinaryData::GetTlv() Warning extra bytes at end of item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
*offset = tlvend;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
std::ostream &RsTlvBinaryData::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
uint32_t i;
|
||||
std::ostringstream sout;
|
||||
printIndent(sout, indent);
|
||||
sout << "RsTlvBinaryData: Type: " << tlvtype << " Size: " << bin_len;
|
||||
sout << std::hex;
|
||||
|
||||
for(i = 0; i < bin_len; i++)
|
||||
{
|
||||
if (i % 16 == 0)
|
||||
{
|
||||
sout << std::endl;
|
||||
printIndent(sout, int_Indent);
|
||||
}
|
||||
sout << std::setw(2) << std::setfill('0')
|
||||
<< (int) (((unsigned char *) bin_data)[i]) << ":";
|
||||
}
|
||||
|
||||
sout << std::endl;
|
||||
out << sout.str();
|
||||
|
||||
printEnd(out, "RsTlvBinaryData", indent);
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
/************************************* Peer Id Set ************************************/
|
||||
|
||||
|
||||
RsTlvStringSet::RsTlvStringSet(uint16_t type) :mType(type)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvStringSet::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true;
|
||||
|
||||
|
||||
/* start at data[offset] */
|
||||
ok &= SetTlvBase(data, tlvend, offset, mType , tlvsize);
|
||||
|
||||
/* determine the total size of ids strings in list */
|
||||
|
||||
std::list<std::string>::iterator it;
|
||||
|
||||
for(it = ids.begin(); it != ids.end() ; ++it)
|
||||
{
|
||||
if (it->length() > 0)
|
||||
ok &= SetTlvString(data, tlvend, offset, TLV_TYPE_STR_GENID, *it);
|
||||
}
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void RsTlvStringSet::TlvClear()
|
||||
{
|
||||
ids.clear();
|
||||
|
||||
}
|
||||
|
||||
uint32_t RsTlvStringSet::TlvSize()
|
||||
{
|
||||
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
|
||||
/* determine the total size of ids strings in list */
|
||||
|
||||
std::list<std::string>::iterator it;
|
||||
|
||||
for(it = ids.begin(); it != ids.end() ; ++it)
|
||||
{
|
||||
if (it->length() > 0)
|
||||
s += GetTlvStringSize(*it);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvStringSet::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
{
|
||||
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 != mType) /* check type */
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
|
||||
|
||||
/* while there is TLV */
|
||||
while((*offset) + 2 < tlvend)
|
||||
{
|
||||
/* get the next type */
|
||||
uint16_t tlvsubtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
|
||||
if (tlvsubtype == TLV_TYPE_STR_GENID)
|
||||
{
|
||||
std::string newIds;
|
||||
ok &= GetTlvString(data, tlvend, offset, TLV_TYPE_STR_GENID, newIds);
|
||||
if(ok)
|
||||
{
|
||||
ids.push_back(newIds);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Step past unknown TLV TYPE */
|
||||
ok &= SkipUnknownTlv(data, tlvend, offset);
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* NB: extra components could be added (for future expansion of the type).
|
||||
* or be present (if this code is reading an extended version).
|
||||
*
|
||||
* We must chew up the extra characters to conform with TLV specifications
|
||||
***************************************************************************/
|
||||
if (*offset != tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvPeerIdSet::GetTlv() Warning extra bytes at end of item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
*offset = tlvend;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/// print to screen RsTlvStringSet contents
|
||||
std::ostream &RsTlvStringSet::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printBase(out, "RsTlvStringSet", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "type:" << mType;
|
||||
out << std::endl;
|
||||
|
||||
std::list<std::string>::iterator it;
|
||||
for(it = ids.begin(); it != ids.end() ; ++it)
|
||||
{
|
||||
printIndent(out, int_Indent);
|
||||
out << "id:" << *it;
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
printEnd(out, "RsTlvStringSet", indent);
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
/// print to screen RsTlvStringSet contents
|
||||
std::ostream &RsTlvStringSet::printHex(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printBase(out, "RsTlvStringSet", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "type:" << mType;
|
||||
out << std::endl;
|
||||
|
||||
std::list<std::string>::iterator it;
|
||||
for(it = ids.begin(); it != ids.end() ; ++it)
|
||||
{
|
||||
printIndent(out, int_Indent);
|
||||
out << "id: 0x" << RsUtil::BinToHex(*it);
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
printEnd(out, "RsTlvStringSet", indent);
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/************************************* String Set Ref ************************************/
|
||||
/* This is exactly the same as StringSet, but it uses an alternative list.
|
||||
*/
|
||||
RsTlvStringSetRef::RsTlvStringSetRef(uint16_t type, std::list<std::string> &refids)
|
||||
:mType(type), ids(refids)
|
||||
{
|
||||
}
|
||||
|
||||
void RsTlvStringSetRef::TlvClear()
|
||||
{
|
||||
ids.clear();
|
||||
|
||||
}
|
||||
|
||||
uint32_t RsTlvStringSetRef::TlvSize()
|
||||
{
|
||||
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
|
||||
/* determine the total size of ids strings in list */
|
||||
|
||||
std::list<std::string>::iterator it;
|
||||
|
||||
for(it = ids.begin(); it != ids.end() ; ++it)
|
||||
{
|
||||
if (it->length() > 0)
|
||||
s += GetTlvStringSize(*it);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvStringSetRef::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true;
|
||||
|
||||
|
||||
/* start at data[offset] */
|
||||
ok &= SetTlvBase(data, tlvend, offset, mType , tlvsize);
|
||||
|
||||
/* determine the total size of ids strings in list */
|
||||
|
||||
std::list<std::string>::iterator it;
|
||||
|
||||
for(it = ids.begin(); it != ids.end() ; ++it)
|
||||
{
|
||||
if (it->length() > 0)
|
||||
ok &= SetTlvString(data, tlvend, offset, TLV_TYPE_STR_GENID, *it);
|
||||
}
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvStringSetRef::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
{
|
||||
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 != mType) /* check type */
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
|
||||
|
||||
/* while there is TLV */
|
||||
while((*offset) + 2 < tlvend)
|
||||
{
|
||||
/* get the next type */
|
||||
uint16_t tlvsubtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
|
||||
if (tlvsubtype == TLV_TYPE_STR_GENID)
|
||||
{
|
||||
std::string newIds;
|
||||
ok &= GetTlvString(data, tlvend, offset, TLV_TYPE_STR_GENID, newIds);
|
||||
if(ok)
|
||||
{
|
||||
ids.push_back(newIds);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Step past unknown TLV TYPE */
|
||||
ok &= SkipUnknownTlv(data, tlvend, offset);
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* NB: extra components could be added (for future expansion of the type).
|
||||
* or be present (if this code is reading an extended version).
|
||||
*
|
||||
* We must chew up the extra characters to conform with TLV specifications
|
||||
***************************************************************************/
|
||||
if (*offset != tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvPeerIdSetRef::GetTlv() Warning extra bytes at end of item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
*offset = tlvend;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/// print to screen RsTlvStringSet contents
|
||||
std::ostream &RsTlvStringSetRef::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printBase(out, "RsTlvStringSetRef", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "type:" << mType;
|
||||
out << std::endl;
|
||||
|
||||
std::list<std::string>::iterator it;
|
||||
for(it = ids.begin(); it != ids.end() ; ++it)
|
||||
{
|
||||
printIndent(out, int_Indent);
|
||||
out << "id:" << *it;
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
printEnd(out, "RsTlvStringSetRef", indent);
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
/************************************* Service Id Set ************************************/
|
||||
|
||||
void RsTlvServiceIdSet::TlvClear()
|
||||
{
|
||||
ids.clear();
|
||||
|
||||
}
|
||||
|
||||
uint32_t RsTlvServiceIdSet::TlvSize()
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
|
||||
/* determine the total size of ids strings in list */
|
||||
std::list<uint32_t>::iterator it;
|
||||
for(it = ids.begin(); it != ids.end() ; ++it)
|
||||
{
|
||||
if (*it > 0)
|
||||
s += GetTlvUInt32Size();
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsTlvServiceIdSet::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true;
|
||||
|
||||
|
||||
/* start at data[offset] */
|
||||
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_SERVICESET , tlvsize);
|
||||
|
||||
/* determine the total size of ids strings in list */
|
||||
std::list<uint32_t>::iterator it;
|
||||
for(it = ids.begin(); it != ids.end() ; ++it)
|
||||
{
|
||||
if (*it > 0)
|
||||
ok &= SetTlvUInt32(data, tlvend, offset, TLV_TYPE_UINT32_SERID, *it);
|
||||
}
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
bool RsTlvServiceIdSet::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
|
||||
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend) /* check size */
|
||||
return false; /* not enough space */
|
||||
|
||||
if (tlvtype != TLV_TYPE_SERVICESET) /* check type */
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
/* while there is TLV */
|
||||
while((*offset) + 2 < tlvend)
|
||||
{
|
||||
/* get the next type */
|
||||
uint16_t tlvsubtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
|
||||
if (tlvsubtype == TLV_TYPE_UINT32_SERID)
|
||||
{
|
||||
uint32_t newIds;
|
||||
ok &= GetTlvUInt32(data, tlvend, offset, TLV_TYPE_UINT32_SERID, &newIds);
|
||||
if(ok)
|
||||
{
|
||||
ids.push_back(newIds);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Step past unknown TLV TYPE */
|
||||
ok &= SkipUnknownTlv(data, tlvend, offset);
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* NB: extra components could be added (for future expansion of the type).
|
||||
* or be present (if this code is reading an extended version).
|
||||
*
|
||||
* We must chew up the extra characters to conform with TLV specifications
|
||||
***************************************************************************/
|
||||
if (*offset != tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvServiceIdSet::GetTlv() Warning extra bytes at end of item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
*offset = tlvend;
|
||||
}
|
||||
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/// print to screen RsTlvServiceSet contents
|
||||
std::ostream &RsTlvServiceIdSet::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printBase(out, "RsTlvServiceIdSet", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
std::list<uint32_t>::iterator it;
|
||||
for(it = ids.begin(); it != ids.end() ; ++it)
|
||||
{
|
||||
printIndent(out, int_Indent);
|
||||
out << "id:" << *it;
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
printEnd(out, "RsTlvServiceIdSet", indent);
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
/************************************* RsTlvKeyValue ************************************/
|
||||
|
||||
void RsTlvKeyValue::TlvClear()
|
||||
{
|
||||
key = "";
|
||||
value = "";
|
||||
}
|
||||
|
||||
uint32_t RsTlvKeyValue::TlvSize()
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
|
||||
/* now add comment and title length of this tlv object */
|
||||
|
||||
if (key.length() > 0)
|
||||
s += GetTlvStringSize(key);
|
||||
if (value.length() > 0)
|
||||
s += GetTlvStringSize(value);
|
||||
|
||||
return s;
|
||||
|
||||
}
|
||||
|
||||
bool RsTlvKeyValue::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* start at data[offset] */
|
||||
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_KEYVALUE, tlvsize);
|
||||
|
||||
|
||||
|
||||
/* now optional ones */
|
||||
if (key.length() > 0)
|
||||
ok &= SetTlvString(data, tlvend, offset, TLV_TYPE_STR_KEY, key); // no base tlv type for title?
|
||||
if (value.length() > 0)
|
||||
ok &= SetTlvString(data, tlvend, offset, TLV_TYPE_STR_VALUE, value); // no base tlv type for comment?
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
bool RsTlvKeyValue::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
|
||||
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend) /* check size */
|
||||
return false; /* not enough space */
|
||||
|
||||
if (tlvtype != TLV_TYPE_KEYVALUE) /* check type */
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
/* while there is TLV */
|
||||
while((*offset) + 2 < tlvend)
|
||||
{
|
||||
/* get the next type */
|
||||
uint16_t tlvsubtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
|
||||
switch(tlvsubtype)
|
||||
{
|
||||
case TLV_TYPE_STR_KEY:
|
||||
ok &= GetTlvString(data, tlvend, offset, TLV_TYPE_STR_KEY, key);
|
||||
break;
|
||||
case TLV_TYPE_STR_VALUE:
|
||||
ok &= GetTlvString(data, tlvend, offset, TLV_TYPE_STR_VALUE, value);
|
||||
break;
|
||||
default:
|
||||
ok &= SkipUnknownTlv(data, tlvend, offset);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* NB: extra components could be added (for future expansion of the type).
|
||||
* or be present (if this code is reading an extended version).
|
||||
*
|
||||
* We must chew up the extra characters to conform with TLV specifications
|
||||
***************************************************************************/
|
||||
if (*offset != tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvKeyValue::GetTlv() Warning extra bytes at end of item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
*offset = tlvend;
|
||||
}
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
std::ostream &RsTlvKeyValue::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printBase(out, "RsTlvKeyValue", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Key:" << key;
|
||||
printIndent(out, int_Indent);
|
||||
out << "Value:" << value;
|
||||
out << std::endl;
|
||||
|
||||
|
||||
printEnd(out, "RsTlvKeyValue", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
/************************************* RsTlvKeyValueSet ************************************/
|
||||
|
||||
void RsTlvKeyValueSet::TlvClear()
|
||||
{
|
||||
pairs.clear(); //empty list
|
||||
}
|
||||
|
||||
uint32_t RsTlvKeyValueSet::TlvSize()
|
||||
{
|
||||
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
|
||||
std::list<RsTlvKeyValue>::iterator it;
|
||||
|
||||
if(!pairs.empty())
|
||||
{
|
||||
|
||||
for(it = pairs.begin(); it != pairs.end() ; ++it)
|
||||
s += it->TlvSize();
|
||||
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsTlvKeyValueSet::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* start at data[offset] */
|
||||
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_KEYVALUESET , tlvsize);
|
||||
|
||||
|
||||
if(!pairs.empty())
|
||||
{
|
||||
std::list<RsTlvKeyValue>::iterator it;
|
||||
|
||||
for(it = pairs.begin(); it != pairs.end() ; ++it)
|
||||
ok &= it->SetTlv(data, size, offset);
|
||||
}
|
||||
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvKeyValueSet::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
|
||||
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend) /* check size */
|
||||
return false; /* not enough space */
|
||||
|
||||
if (tlvtype != TLV_TYPE_KEYVALUESET) /* check type */
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
/* while there is TLV */
|
||||
while((*offset) + 2 < tlvend)
|
||||
{
|
||||
/* get the next type */
|
||||
uint16_t tlvsubtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
|
||||
switch(tlvsubtype)
|
||||
{
|
||||
case TLV_TYPE_KEYVALUE:
|
||||
{
|
||||
RsTlvKeyValue kv;
|
||||
ok &= kv.GetTlv(data, size, offset);
|
||||
if (ok)
|
||||
{
|
||||
pairs.push_back(kv);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ok &= SkipUnknownTlv(data, tlvend, offset);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
break;
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* NB: extra components could be added (for future expansion of the type).
|
||||
* or be present (if this code is reading an extended version).
|
||||
*
|
||||
* We must chew up the extra characters to conform with TLV specifications
|
||||
***************************************************************************/
|
||||
if (*offset != tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvKeyValueSet::GetTlv() Warning extra bytes at end of item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
*offset = tlvend;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/// prints out contents of RsTlvKeyValueSet
|
||||
std::ostream &RsTlvKeyValueSet::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printBase(out, "RsTlvKeyValue", indent);
|
||||
|
||||
std::list<RsTlvKeyValue>::iterator it;
|
||||
|
||||
for(it = pairs.begin(); it != pairs.end() ; ++it)
|
||||
it->print(out, indent);
|
||||
|
||||
printEnd(out, "RsTlvKeyValue", indent);
|
||||
return out;
|
||||
}
|
||||
|
@ -1,350 +0,0 @@
|
||||
#ifndef RS_TLV_COMPOUND_TYPES_H
|
||||
#define RS_TLV_COMPOUND_TYPES_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvtypes.h
|
||||
*
|
||||
* 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".
|
||||
*
|
||||
*/
|
||||
|
||||
/*******************************************************************
|
||||
* These are the Compound TLV structures that must be (un)packed.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <retroshare/rstypes.h>
|
||||
#include <serialiser/rstlvtypes.h>
|
||||
#include <serialiser/rstlvbase.h>
|
||||
#include <serialiser/rsbaseserial.h>
|
||||
#include <retroshare/rsgxsifacetypes.h>
|
||||
|
||||
//! A base class for all tlv items
|
||||
/*! This class is provided to allow the serialisation and deserialization of compund
|
||||
tlv items
|
||||
*/
|
||||
class RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvItem() { return; }
|
||||
virtual ~RsTlvItem() { return; }
|
||||
virtual uint32_t TlvSize() = 0;
|
||||
virtual void TlvClear() = 0;
|
||||
virtual void TlvShallowClear(); /*! Don't delete allocated data */
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) = 0; /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset) = 0; /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) = 0;
|
||||
std::ostream &printBase(std::ostream &out, std::string clsName, uint16_t indent);
|
||||
std::ostream &printEnd(std::ostream &out, std::string clsName, uint16_t indent);
|
||||
};
|
||||
|
||||
std::ostream &printIndent(std::ostream &out, uint16_t indent);
|
||||
|
||||
|
||||
//! GENERIC Binary Data TLV
|
||||
/*! Use to serialise and deserialise binary data, usually included in other compound tlvs
|
||||
*/
|
||||
class RsTlvBinaryData: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvBinaryData(uint16_t t);
|
||||
RsTlvBinaryData(const RsTlvBinaryData& b); // as per rule of three
|
||||
void operator=(const RsTlvBinaryData& b); // as per rule of three
|
||||
virtual ~RsTlvBinaryData(); // as per rule of three
|
||||
virtual uint32_t TlvSize();
|
||||
virtual void TlvClear(); /*! Initialize fields to empty legal values ( "0", "", etc) */
|
||||
virtual void TlvShallowClear(); /*! Don't delete the binary data */
|
||||
|
||||
/// Serialise.
|
||||
/*! Serialise Tlv to buffer(*data) of 'size' bytes starting at *offset */
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
|
||||
/// Deserialise.
|
||||
/*! Deserialise Tlv buffer(*data) of 'size' bytes starting at *offset */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent); /*! Error/Debug util function */
|
||||
|
||||
bool setBinData(const void *data, uint32_t size);
|
||||
|
||||
uint16_t tlvtype; /// set/checked against TLV input
|
||||
uint32_t bin_len; /// size of malloc'ed data (not serialised)
|
||||
void *bin_data; /// mandatory
|
||||
};
|
||||
|
||||
|
||||
/**** MORE TLV *****
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class RsTlvStringSet: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvStringSet(uint16_t type);
|
||||
virtual ~RsTlvStringSet() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
virtual std::ostream &printHex(std::ostream &out, uint16_t indent); /* SPECIAL One */
|
||||
|
||||
uint16_t mType;
|
||||
std::list<std::string> ids; /* Mandatory */
|
||||
};
|
||||
|
||||
template<class ID_CLASS,uint32_t TLV_TYPE> class t_RsTlvIdSet: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
t_RsTlvIdSet() {}
|
||||
virtual ~t_RsTlvIdSet() {}
|
||||
|
||||
virtual uint32_t TlvSize() { return ID_CLASS::SIZE_IN_BYTES * ids.size() + TLV_HEADER_SIZE; }
|
||||
virtual void TlvClear(){ ids.clear() ; }
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
{ /* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* start at data[offset] */
|
||||
ok = ok && SetTlvBase(data, tlvend, offset, TLV_TYPE, tlvsize);
|
||||
|
||||
for(typename std::list<ID_CLASS>::const_iterator it(ids.begin());it!=ids.end();++it)
|
||||
ok = ok && (*it).serialise(data,size,*offset) ;
|
||||
|
||||
return ok ;
|
||||
}
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset) /* deserialise */
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
|
||||
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend) /* check size */
|
||||
return false; /* not enough space */
|
||||
|
||||
if (tlvtype != TLV_TYPE) /* check type */
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
while(*offset + ID_CLASS::SIZE_IN_BYTES <= tlvend)
|
||||
{
|
||||
ID_CLASS id ;
|
||||
ok = ok && id.deserialise(data,size,*offset) ;
|
||||
ids.push_back(id) ;
|
||||
}
|
||||
if(*offset != tlvend)
|
||||
std::cerr << "(EE) deserialisaiton error in " << __PRETTY_FUNCTION__ << std::endl;
|
||||
return *offset == tlvend ;
|
||||
}
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t /* indent */)
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": not implemented" << std::endl;
|
||||
return out ;
|
||||
}
|
||||
virtual std::ostream &printHex(std::ostream &out, uint16_t /* indent */) /* SPECIAL One */
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": not implemented" << std::endl;
|
||||
return out ;
|
||||
}
|
||||
|
||||
std::list<ID_CLASS> ids ;
|
||||
};
|
||||
|
||||
typedef t_RsTlvIdSet<RsPeerId,TLV_TYPE_PEERSET> RsTlvPeerIdSet ;
|
||||
typedef t_RsTlvIdSet<RsPgpId,TLV_TYPE_PGPIDSET> RsTlvPgpIdSet ;
|
||||
typedef t_RsTlvIdSet<Sha1CheckSum,TLV_TYPE_HASHSET> RsTlvHashSet ;
|
||||
typedef t_RsTlvIdSet<RsGxsId,TLV_TYPE_GXSIDSET> RsTlvGxsIdSet ;
|
||||
|
||||
class RsTlvServiceIdSet: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvServiceIdSet() { return; }
|
||||
virtual ~RsTlvServiceIdSet() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
std::list<uint32_t> ids; /* Mandatory */
|
||||
};
|
||||
|
||||
|
||||
class RsTlvStringSetRef: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvStringSetRef(uint16_t type, std::list<std::string> &refids);
|
||||
virtual ~RsTlvStringSetRef() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
uint16_t mType;
|
||||
std::list<std::string> &ids; /* Mandatory */
|
||||
};
|
||||
|
||||
|
||||
/**** MORE TLV *****
|
||||
*
|
||||
* File Items/Data.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class RsTlvFileItem: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvFileItem();
|
||||
virtual ~RsTlvFileItem() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
uint64_t filesize; /// Mandatory: size of file to be downloaded
|
||||
RsFileHash hash; /// Mandatory: to find file
|
||||
std::string name; /// Optional: name of file
|
||||
std::string path; /// Optional: path on host computer
|
||||
uint32_t pop; /// Optional: Popularity of file
|
||||
uint32_t age; /// Optional: age of file
|
||||
// For chunk hashing.
|
||||
uint32_t piecesize; /// Optional: bytes/piece for hashset.
|
||||
RsTlvHashSet hashset; /// Optional: chunk hashes.
|
||||
|
||||
};
|
||||
|
||||
class RsTlvFileSet: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvFileSet() { return; }
|
||||
virtual ~RsTlvFileSet() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
std::list<RsTlvFileItem> items; /// Mandatory
|
||||
std::string title; /// Optional: title of file set
|
||||
std::string comment; /// Optional: comments for file
|
||||
};
|
||||
|
||||
|
||||
class RsTlvFileData: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvFileData();
|
||||
virtual ~RsTlvFileData() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
RsTlvFileItem file; /// Mandatory: file information
|
||||
uint64_t file_offset; /// Mandatory: where to start in bin data
|
||||
RsTlvBinaryData binData; /// Mandatory: serialised file info
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/**** MORE TLV *****
|
||||
* Key/Value + Set used for Generic Configuration Parameters.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class RsTlvKeyValue: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvKeyValue() { return; }
|
||||
RsTlvKeyValue(const std::string& k,const std::string& v): key(k),value(v) {}
|
||||
virtual ~RsTlvKeyValue() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
std::string key; /// Mandatory : For use in hash tables
|
||||
std::string value; /// Mandatory : For use in hash tables
|
||||
};
|
||||
|
||||
class RsTlvKeyValueSet: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvKeyValueSet() { return; }
|
||||
virtual ~RsTlvKeyValueSet() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
std::list<RsTlvKeyValue> pairs; /// For use in hash tables
|
||||
};
|
||||
|
||||
|
||||
class RsTlvImage: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvImage();
|
||||
RsTlvImage(const RsTlvImage& );
|
||||
virtual ~RsTlvImage() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
uint32_t image_type; // Mandatory:
|
||||
RsTlvBinaryData binData; // Mandatory: serialised file info
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -31,16 +31,23 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/* print out a packet */
|
||||
#include <stdlib.h>
|
||||
#include "serialiser/rstlvutil.h"
|
||||
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvitem.h"
|
||||
#include "util/rsstring.h"
|
||||
#include "util/utest.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if 0
|
||||
/* print out a packet */
|
||||
#include <iomanip>
|
||||
#include <vector>
|
||||
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "util/utest.h"
|
||||
#include "util/rsstring.h"
|
||||
|
||||
#endif
|
||||
|
||||
void displayRawPacket(std::ostream &out, void *data, uint32_t size)
|
||||
{
|
||||
|
@ -29,7 +29,9 @@
|
||||
/* some utility functions mainly for debugging
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
|
||||
class RsTlvItem;
|
||||
|
||||
@ -37,7 +39,6 @@ class RsTlvItem;
|
||||
void displayRawPacket(std::ostream &out, void *data, uint32_t size);
|
||||
int test_SerialiseTlvItem(std::ostream &str, RsTlvItem *in, RsTlvItem *out);
|
||||
|
||||
#include <vector>
|
||||
|
||||
bool test_StepThroughTlvStack(std::ostream &str, void *data, int size);
|
||||
int test_CreateTlvStack(std::ostream &str,
|
||||
|
@ -84,7 +84,7 @@ RsItem* RsGxsWikiSerialiser::deserialise(void* data, uint32_t* size)
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_WIKI != getRsItemService(rstype)))
|
||||
(RS_SERVICE_GXS_TYPE_WIKI != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
@ -219,7 +219,7 @@ RsGxsWikiCollectionItem* RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem(v
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_WIKI != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_WIKI != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
@ -375,7 +375,7 @@ RsGxsWikiSnapshotItem* RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem(void
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_WIKI != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_WIKI != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
@ -523,7 +523,7 @@ RsGxsWikiCommentItem* RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem(void *d
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_WIKI != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_WIKI != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
//#include "serialiser/rstlvtypes.h"
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
#include "retroshare/rswiki.h"
|
||||
@ -44,7 +44,7 @@ class RsGxsWikiCollectionItem : public RsGxsGrpItem
|
||||
|
||||
public:
|
||||
|
||||
RsGxsWikiCollectionItem(): RsGxsGrpItem(RS_SERVICE_GXSV2_TYPE_WIKI,
|
||||
RsGxsWikiCollectionItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_WIKI,
|
||||
RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM) { return;}
|
||||
virtual ~RsGxsWikiCollectionItem() { return;}
|
||||
|
||||
@ -59,7 +59,7 @@ class RsGxsWikiSnapshotItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsWikiSnapshotItem(): RsGxsMsgItem(RS_SERVICE_GXSV2_TYPE_WIKI,
|
||||
RsGxsWikiSnapshotItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_WIKI,
|
||||
RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM) {return; }
|
||||
virtual ~RsGxsWikiSnapshotItem() { return;}
|
||||
void clear();
|
||||
@ -71,7 +71,7 @@ class RsGxsWikiCommentItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsWikiCommentItem(): RsGxsMsgItem(RS_SERVICE_GXSV2_TYPE_WIKI,
|
||||
RsGxsWikiCommentItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_WIKI,
|
||||
RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM) { return; }
|
||||
virtual ~RsGxsWikiCommentItem() { return; }
|
||||
void clear();
|
||||
@ -85,7 +85,7 @@ class RsGxsWikiSerialiser : public RsSerialType
|
||||
public:
|
||||
|
||||
RsGxsWikiSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV2_TYPE_WIKI)
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_WIKI)
|
||||
{ return; }
|
||||
virtual ~RsGxsWikiSerialiser() { return; }
|
||||
|
||||
|
@ -74,7 +74,7 @@ RsItem* RsGxsWireSerialiser::deserialise(void* data, uint32_t* size)
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_WIRE != getRsItemService(rstype)))
|
||||
(RS_SERVICE_GXS_TYPE_WIRE != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
@ -196,7 +196,7 @@ RsGxsWireGroupItem* RsGxsWireSerialiser::deserialiseGxsWireGroupItem(void *data,
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_WIRE != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_WIRE != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_WIRE_GROUP_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
@ -350,7 +350,7 @@ RsGxsWirePulseItem* RsGxsWireSerialiser::deserialiseGxsWirePulseItem(void *data,
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_WIRE != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXS_TYPE_WIRE != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_WIRE_PULSE_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
//#include "serialiser/rstlvtypes.h"
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
#include "retroshare/rswire.h"
|
||||
@ -43,7 +43,7 @@ class RsGxsWireGroupItem : public RsGxsGrpItem
|
||||
|
||||
public:
|
||||
|
||||
RsGxsWireGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV2_TYPE_WIRE,
|
||||
RsGxsWireGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_WIRE,
|
||||
RS_PKT_SUBTYPE_WIRE_GROUP_ITEM) { return;}
|
||||
virtual ~RsGxsWireGroupItem() { return;}
|
||||
|
||||
@ -58,7 +58,7 @@ class RsGxsWirePulseItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsWirePulseItem(): RsGxsMsgItem(RS_SERVICE_GXSV2_TYPE_WIRE,
|
||||
RsGxsWirePulseItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_WIRE,
|
||||
RS_PKT_SUBTYPE_WIRE_PULSE_ITEM) {return; }
|
||||
virtual ~RsGxsWirePulseItem() { return;}
|
||||
void clear();
|
||||
@ -71,7 +71,7 @@ class RsGxsWireSerialiser : public RsSerialType
|
||||
public:
|
||||
|
||||
RsGxsWireSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV2_TYPE_WIRE)
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_WIRE)
|
||||
{ return; }
|
||||
virtual ~RsGxsWireSerialiser() { return; }
|
||||
|
||||
|
@ -151,7 +151,8 @@ bool p3BanList::recvBanItem(RsBanListItem *item)
|
||||
bool updated = false;
|
||||
|
||||
std::list<RsTlvBanListEntry>::const_iterator it;
|
||||
for(it = item->peerList.entries.begin(); it != item->peerList.entries.end(); it++)
|
||||
//for(it = item->peerList.entries.begin(); it != item->peerList.entries.end(); it++)
|
||||
for(it = item->peerList.mList.begin(); it != item->peerList.mList.end(); it++)
|
||||
{
|
||||
// Order is important!.
|
||||
updated = (addBanEntry(item->PeerId(), it->addr.addr, it->level,
|
||||
@ -450,7 +451,8 @@ int p3BanList::sendBanSet(const RsPeerId& peerid)
|
||||
bi.level = it->second.level;
|
||||
bi.age = now - it->second.mTs;
|
||||
|
||||
item->peerList.entries.push_back(bi);
|
||||
//item->peerList.entries.push_back(bi);
|
||||
item->peerList.mList.push_back(bi);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -273,9 +273,11 @@ int p3Dsdv::generateRoutingTable(const RsPeerId &peerId, bool incremental)
|
||||
entry.sequence = v.mStableRoute.mSequence;
|
||||
entry.distance = v.mStableRoute.mDistance;
|
||||
|
||||
dsdv->routes.entries.push_back(entry);
|
||||
//dsdv->routes.entries.push_back(entry);
|
||||
dsdv->routes.mList.push_back(entry);
|
||||
|
||||
if (dsdv->routes.entries.size() > RSDSDV_MAX_ROUTE_TABLE)
|
||||
//if (dsdv->routes.entries.size() > RSDSDV_MAX_ROUTE_TABLE)
|
||||
if (dsdv->routes.mList.size() > RSDSDV_MAX_ROUTE_TABLE)
|
||||
{
|
||||
sendItem(dsdv);
|
||||
dsdv = new RsDsdvRouteItem();
|
||||
@ -329,7 +331,8 @@ int p3Dsdv::handleDSDV(RsDsdvRouteItem *dsdv)
|
||||
#endif
|
||||
|
||||
std::list<RsTlvDsdvEntry>::iterator it;
|
||||
for(it = dsdv->routes.entries.begin(); it != dsdv->routes.entries.end(); it++)
|
||||
//for(it = dsdv->routes.entries.begin(); it != dsdv->routes.entries.end(); it++)
|
||||
for(it = dsdv->routes.mList.begin(); it != dsdv->routes.mList.end(); it++)
|
||||
{
|
||||
/* check for existing */
|
||||
RsTlvDsdvEntry &entry = *it;
|
||||
|
@ -65,11 +65,11 @@ RsGxsChannels *rsGxsChannels = NULL;
|
||||
/********************************************************************************/
|
||||
|
||||
p3GxsChannels::p3GxsChannels(RsGeneralDataService *gds, RsNetworkExchangeService *nes, RsGixs* gixs)
|
||||
: RsGenExchange(gds, nes, new RsGxsChannelSerialiser(), RS_SERVICE_GXSV2_TYPE_CHANNELS, gixs, channelsAuthenPolicy()), RsGxsChannels(this), GxsTokenQueue(this)
|
||||
: RsGenExchange(gds, nes, new RsGxsChannelSerialiser(), RS_SERVICE_GXS_TYPE_CHANNELS, gixs, channelsAuthenPolicy()), RsGxsChannels(this), GxsTokenQueue(this)
|
||||
{
|
||||
// For Dummy Msgs.
|
||||
mGenActive = false;
|
||||
mCommentService = new p3GxsCommentService(this, RS_SERVICE_GXSV2_TYPE_CHANNELS);
|
||||
mCommentService = new p3GxsCommentService(this, RS_SERVICE_GXS_TYPE_CHANNELS);
|
||||
|
||||
RsTickEvent::schedule_in(CHANNEL_PROCESS, 0);
|
||||
|
||||
@ -87,7 +87,7 @@ const uint16_t GXS_CHANNELS_MIN_MINOR_VERSION = 0;
|
||||
|
||||
RsServiceInfo p3GxsChannels::getServiceInfo()
|
||||
{
|
||||
return RsServiceInfo(RS_SERVICE_GXSV2_TYPE_CHANNELS,
|
||||
return RsServiceInfo(RS_SERVICE_GXS_TYPE_CHANNELS,
|
||||
GXS_CHANNELS_APP_NAME,
|
||||
GXS_CHANNELS_APP_MAJOR_VERSION,
|
||||
GXS_CHANNELS_APP_MINOR_VERSION,
|
||||
|
@ -108,7 +108,7 @@ RsGxsCircles *rsGxsCircles = NULL;
|
||||
|
||||
p3GxsCircles::p3GxsCircles(RsGeneralDataService *gds, RsNetworkExchangeService *nes, p3IdService *identities)
|
||||
: RsGxsCircleExchange(gds, nes, new RsGxsCircleSerialiser(),
|
||||
RS_SERVICE_GXSV2_TYPE_GXSCIRCLE, identities, circleAuthenPolicy()),
|
||||
RS_SERVICE_GXS_TYPE_GXSCIRCLE, identities, circleAuthenPolicy()),
|
||||
RsGxsCircles(this), GxsTokenQueue(this), RsTickEvent(), mIdentities(identities),
|
||||
mCircleMtx("p3GxsCircles"),
|
||||
mCircleCache(DEFAULT_MEM_CACHE_SIZE, "GxsCircleCache")
|
||||
@ -120,12 +120,7 @@ p3GxsCircles::p3GxsCircles(RsGeneralDataService *gds, RsNetworkExchangeService *
|
||||
RsTickEvent::schedule_now(CIRCLE_EVENT_LOADIDS);
|
||||
|
||||
// Dummy Circles.
|
||||
|
||||
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
|
||||
|
||||
RsTickEvent::schedule_in(CIRCLE_EVENT_DUMMYSTART, CIRCLE_DUMMY_STARTPERIOD);
|
||||
|
||||
#endif
|
||||
// RsTickEvent::schedule_in(CIRCLE_EVENT_DUMMYSTART, CIRCLE_DUMMY_STARTPERIOD);
|
||||
|
||||
}
|
||||
|
||||
@ -138,7 +133,7 @@ const uint16_t GXS_CIRCLES_MIN_MINOR_VERSION = 0;
|
||||
|
||||
RsServiceInfo p3GxsCircles::getServiceInfo()
|
||||
{
|
||||
return RsServiceInfo(RS_SERVICE_GXSV2_TYPE_GXSCIRCLE,
|
||||
return RsServiceInfo(RS_SERVICE_GXS_TYPE_GXSCIRCLE,
|
||||
GXS_CIRCLES_APP_NAME,
|
||||
GXS_CIRCLES_APP_MAJOR_VERSION,
|
||||
GXS_CIRCLES_APP_MINOR_VERSION,
|
||||
|
@ -51,7 +51,7 @@ RsGxsForums *rsGxsForums = NULL;
|
||||
/********************************************************************************/
|
||||
|
||||
p3GxsForums::p3GxsForums(RsGeneralDataService *gds, RsNetworkExchangeService *nes, RsGixs* gixs)
|
||||
: RsGenExchange(gds, nes, new RsGxsForumSerialiser(), RS_SERVICE_GXSV2_TYPE_FORUMS, gixs, forumsAuthenPolicy()), RsGxsForums(this)
|
||||
: RsGenExchange(gds, nes, new RsGxsForumSerialiser(), RS_SERVICE_GXS_TYPE_FORUMS, gixs, forumsAuthenPolicy()), RsGxsForums(this)
|
||||
{
|
||||
// For Dummy Msgs.
|
||||
mGenActive = false;
|
||||
@ -70,7 +70,7 @@ const uint16_t GXS_FORUMS_MIN_MINOR_VERSION = 0;
|
||||
|
||||
RsServiceInfo p3GxsForums::getServiceInfo()
|
||||
{
|
||||
return RsServiceInfo(RS_SERVICE_GXSV2_TYPE_FORUMS,
|
||||
return RsServiceInfo(RS_SERVICE_GXS_TYPE_FORUMS,
|
||||
GXS_FORUMS_APP_NAME,
|
||||
GXS_FORUMS_APP_MAJOR_VERSION,
|
||||
GXS_FORUMS_APP_MINOR_VERSION,
|
||||
|
@ -142,7 +142,7 @@ const uint16_t GXS_REPUTATION_MIN_MINOR_VERSION = 0;
|
||||
|
||||
RsServiceInfo p3GxsReputation::getServiceInfo()
|
||||
{
|
||||
return RsServiceInfo(RS_SERVICE_GXSV2_TYPE_REPUTATION,
|
||||
return RsServiceInfo(RS_SERVICE_GXS_TYPE_REPUTATION,
|
||||
GXS_REPUTATION_APP_NAME,
|
||||
GXS_REPUTATION_APP_MAJOR_VERSION,
|
||||
GXS_REPUTATION_APP_MINOR_VERSION,
|
||||
|
@ -139,7 +139,7 @@ RsIdentity *rsIdentity = NULL;
|
||||
/********************************************************************************/
|
||||
|
||||
p3IdService::p3IdService(RsGeneralDataService *gds, RsNetworkExchangeService *nes)
|
||||
: RsGxsIdExchange(gds, nes, new RsGxsIdSerialiser(), RS_SERVICE_GXSV2_TYPE_GXSID, idAuthenPolicy()),
|
||||
: RsGxsIdExchange(gds, nes, new RsGxsIdSerialiser(), RS_SERVICE_GXS_TYPE_GXSID, idAuthenPolicy()),
|
||||
RsIdentity(this), GxsTokenQueue(this), RsTickEvent(),
|
||||
mPublicKeyCache(DEFAULT_MEM_CACHE_SIZE, "GxsIdPublicKeyCache"),
|
||||
mPrivateKeyCache(DEFAULT_MEM_CACHE_SIZE, "GxsIdPrivateKeyCache"),
|
||||
@ -153,13 +153,10 @@ p3IdService::p3IdService(RsGeneralDataService *gds, RsNetworkExchangeService *ne
|
||||
RsTickEvent::schedule_in(GXSID_EVENT_REPUTATION, REPUTATION_PERIOD);
|
||||
RsTickEvent::schedule_now(GXSID_EVENT_CACHEOWNIDS);
|
||||
|
||||
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
|
||||
//RsTickEvent::schedule_in(GXSID_EVENT_CACHETEST, CACHETEST_PERIOD);
|
||||
|
||||
RsTickEvent::schedule_in(GXSID_EVENT_CACHETEST, CACHETEST_PERIOD);
|
||||
|
||||
#ifdef GXSID_GEN_DUMMY_DATA
|
||||
RsTickEvent::schedule_now(GXSID_EVENT_DUMMYDATA);
|
||||
#endif
|
||||
#ifdef GXSID_GEN_DUMMY_DATA
|
||||
//RsTickEvent::schedule_now(GXSID_EVENT_DUMMYDATA);
|
||||
#endif
|
||||
|
||||
loadRecognKeys();
|
||||
@ -173,7 +170,7 @@ const uint16_t GXSID_MIN_MINOR_VERSION = 0;
|
||||
|
||||
RsServiceInfo p3IdService::getServiceInfo()
|
||||
{
|
||||
return RsServiceInfo(RS_SERVICE_GXSV2_TYPE_GXSID,
|
||||
return RsServiceInfo(RS_SERVICE_GXS_TYPE_GXSID,
|
||||
GXSID_APP_NAME,
|
||||
GXSID_APP_MAJOR_VERSION,
|
||||
GXSID_APP_MINOR_VERSION,
|
||||
@ -2091,10 +2088,10 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
|
||||
std::cerr << std::endl;
|
||||
|
||||
#ifdef GXSID_GEN_DUMMY_DATA
|
||||
if (item->group.mMeta.mAuthorId != "")
|
||||
{
|
||||
ownId = RsPgpId(item->group.mMeta.mAuthorId);
|
||||
}
|
||||
// if (item->group.mMeta.mAuthorId != "")
|
||||
// {
|
||||
// ownId = RsPgpId(item->group.mMeta.mAuthorId);
|
||||
// }
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -87,7 +87,7 @@ std::ostream &operator<<(std::ostream &out, const RsPhotoAlbum &album)
|
||||
}
|
||||
|
||||
p3PhotoService::p3PhotoService(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs)
|
||||
: RsGenExchange(gds, nes, new RsGxsPhotoSerialiser(), RS_SERVICE_GXSV2_TYPE_PHOTO, gixs, photoAuthenPolicy()),
|
||||
: RsGenExchange(gds, nes, new RsGxsPhotoSerialiser(), RS_SERVICE_GXS_TYPE_PHOTO, gixs, photoAuthenPolicy()),
|
||||
mPhotoMutex(std::string("Photo Mutex"))
|
||||
{
|
||||
}
|
||||
@ -100,7 +100,7 @@ const uint16_t GXS_PHOTO_MIN_MINOR_VERSION = 0;
|
||||
|
||||
RsServiceInfo p3PhotoService::getServiceInfo()
|
||||
{
|
||||
return RsServiceInfo(RS_SERVICE_GXSV2_TYPE_PHOTO,
|
||||
return RsServiceInfo(RS_SERVICE_GXS_TYPE_PHOTO,
|
||||
GXS_PHOTO_APP_NAME,
|
||||
GXS_PHOTO_APP_MAJOR_VERSION,
|
||||
GXS_PHOTO_APP_MINOR_VERSION,
|
||||
|
@ -39,7 +39,7 @@ RsPosted *rsPosted = NULL;
|
||||
/********************************************************************************/
|
||||
|
||||
p3Posted::p3Posted(RsGeneralDataService *gds, RsNetworkExchangeService *nes, RsGixs* gixs)
|
||||
:p3PostBase(gds, nes, gixs, new RsGxsPostedSerialiser(), RS_SERVICE_GXSV2_TYPE_POSTED),
|
||||
:p3PostBase(gds, nes, gixs, new RsGxsPostedSerialiser(), RS_SERVICE_GXS_TYPE_POSTED),
|
||||
RsPosted(this)
|
||||
{
|
||||
return;
|
||||
@ -54,7 +54,7 @@ const uint16_t GXS_POSTED_MIN_MINOR_VERSION = 0;
|
||||
|
||||
RsServiceInfo p3Posted::getServiceInfo()
|
||||
{
|
||||
return RsServiceInfo(RS_SERVICE_GXSV2_TYPE_POSTED,
|
||||
return RsServiceInfo(RS_SERVICE_GXS_TYPE_POSTED,
|
||||
GXS_POSTED_APP_NAME,
|
||||
GXS_POSTED_APP_MAJOR_VERSION,
|
||||
GXS_POSTED_APP_MINOR_VERSION,
|
||||
|
@ -43,7 +43,7 @@ RsWiki *rsWiki = NULL;
|
||||
#define DUMMYTICK_PERIOD 3
|
||||
|
||||
p3Wiki::p3Wiki(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs *gixs)
|
||||
:RsGenExchange(gds, nes, new RsGxsWikiSerialiser(), RS_SERVICE_GXSV2_TYPE_WIKI, gixs, wikiAuthenPolicy()),
|
||||
:RsGenExchange(gds, nes, new RsGxsWikiSerialiser(), RS_SERVICE_GXS_TYPE_WIKI, gixs, wikiAuthenPolicy()),
|
||||
RsWiki(this)
|
||||
{
|
||||
// Setup of dummy Pages.
|
||||
@ -65,7 +65,7 @@ const uint16_t GXS_WIKI_MIN_MINOR_VERSION = 0;
|
||||
|
||||
RsServiceInfo p3Wiki::getServiceInfo()
|
||||
{
|
||||
return RsServiceInfo(RS_SERVICE_GXSV2_TYPE_WIKI,
|
||||
return RsServiceInfo(RS_SERVICE_GXS_TYPE_WIKI,
|
||||
GXS_WIKI_APP_NAME,
|
||||
GXS_WIKI_APP_MAJOR_VERSION,
|
||||
GXS_WIKI_APP_MINOR_VERSION,
|
||||
|
@ -36,7 +36,7 @@ RsWire *rsWire = NULL;
|
||||
|
||||
|
||||
p3Wire::p3Wire(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs *gixs)
|
||||
:RsGenExchange(gds, nes, new RsGxsWireSerialiser(), RS_SERVICE_GXSV2_TYPE_WIRE, gixs, wireAuthenPolicy()),
|
||||
:RsGenExchange(gds, nes, new RsGxsWireSerialiser(), RS_SERVICE_GXS_TYPE_WIRE, gixs, wireAuthenPolicy()),
|
||||
RsWire(this), mWireMtx("WireMtx")
|
||||
{
|
||||
|
||||
@ -51,7 +51,7 @@ const uint16_t WIRE_MIN_MINOR_VERSION = 0;
|
||||
|
||||
RsServiceInfo p3Wire::getServiceInfo()
|
||||
{
|
||||
return RsServiceInfo(RS_SERVICE_GXSV2_TYPE_WIRE,
|
||||
return RsServiceInfo(RS_SERVICE_GXS_TYPE_WIRE,
|
||||
WIRE_APP_NAME,
|
||||
WIRE_APP_MAJOR_VERSION,
|
||||
WIRE_APP_MINOR_VERSION,
|
||||
|
Loading…
Reference in New Issue
Block a user