moved rspluginitems to rsitems/

This commit is contained in:
csoler 2017-04-28 16:44:04 +02:00
parent d32a8caf06
commit c33c34b175
4 changed files with 4 additions and 141 deletions

View file

@ -1,135 +0,0 @@
#include "rspluginitems.h"
#ifdef TO_REMOVE
#ifndef WINDOWS_SYS
#include <stdexcept>
#endif
bool RsPluginHashSetItem::serialise(void *data,uint32_t& pktsize)
{
uint32_t tlvsize = serial_size();
uint32_t offset = 0;
#ifdef P3TURTLE_DEBUG
std::cerr << "RsPluginSerialiser::serialising HashSet packet (size=" << tlvsize << ")" << std::endl;
#endif
if (pktsize < tlvsize)
return false; /* not enough space */
pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data,tlvsize,PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= hashes.SetTlv(data,tlvsize,&offset) ;
if (offset != tlvsize)
{
ok = false;
#ifdef P3TURTLE_DEBUG
std::cerr << "RsPluginHashSetItem::serialise() Size Error! (offset=" << offset << ", tlvsize=" << tlvsize << ")" << std::endl;
#endif
}
return ok ;
}
RsPluginHashSetItem::RsPluginHashSetItem(void *data,uint32_t size)
: RsPluginItem(RS_PKT_CLASS_PLUGIN_SUBTYPE_HASHSET)
{
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
hashes.ids.clear() ;
ok &= hashes.GetTlv(data,size,&offset) ;
if (offset != rssize)
{
#ifdef TLV_DEBUG
std::cerr << "RsTlvPeerIdSet::GetTlv() Warning extra bytes at end of item";
std::cerr << std::endl;
#endif
ok = false ;
}
#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs).
UNREFERENCED_LOCAL_VARIABLE(rssize);
#else
if (!ok)
throw std::runtime_error("Unknown error while deserializing.") ;
#endif
}
RsItem *RsPluginSerialiser::deserialise(void *data, uint32_t *size)
{
// look what we have...
/* get the type */
uint32_t rstype = getRsItemId(data);
#ifdef P3TURTLE_DEBUG
std::cerr << "p3turtle: deserialising packet: " << std::endl ;
#endif
if ( (RS_PKT_VERSION1 != getRsItemVersion(rstype))
|| (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype))
|| (RS_PKT_TYPE_PLUGIN_CONFIG != getRsItemType(rstype)))
{
#ifdef P3TURTLE_DEBUG
std::cerr << " Wrong type !!" << std::endl ;
#endif
return NULL; /* wrong type */
}
#ifndef WINDOWS_SYS
try
{
#endif
switch(getRsItemSubType(rstype))
{
case RS_PKT_CLASS_PLUGIN_SUBTYPE_HASHSET : return new RsPluginHashSetItem(data,*size) ;
default:
std::cerr << "Unknown packet type in RsPluginSerialiser. Type = " << rstype << std::endl;
return NULL ;
}
#ifndef WINDOWS_SYS
}
catch(std::exception& e)
{
std::cerr << "Exception raised: " << e.what() << std::endl ;
return NULL ;
}
#endif
}
uint32_t RsPluginHashSetItem::serial_size()
{
uint32_t size = 8 ;
size += hashes.TlvSize() ;
return size ;
}
std::ostream& RsPluginHashSetItem::print(std::ostream& o, uint16_t)
{
o << "Item type: RsPluginHashSetItem" << std::endl;
o << " Hash list: " << std::endl;
for(std::set<Sha1CheckSum>::const_iterator it(hashes.ids.begin());it!=hashes.ids.end();++it)
o << " " << *it << std::endl;
return o ;
}
#endif

View file

@ -1,73 +0,0 @@
/*
* libretroshare/src/services: p3turtle.h
*
* Services for RetroShare.
*
* Copyright 2009 by Cyril Soler
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "csoler@users.sourceforge.net".
*
*/
#pragma once
#include "rsitems/rsitem.h"
#include "rsitems/rsconfigitems.h"
#include "serialization/rstypeserializer.h"
const uint8_t RS_PKT_CLASS_PLUGIN_SUBTYPE_HASHSET = 0x01 ;
class RsPluginItem: public RsItem
{
public:
RsPluginItem(uint8_t plugin_item_subtype): RsItem(RS_PKT_VERSION1,RS_PKT_CLASS_CONFIG,RS_PKT_TYPE_PLUGIN_CONFIG,plugin_item_subtype) {}
virtual ~RsPluginItem() {}
virtual void clear() {}
};
class RsPluginHashSetItem: public RsPluginItem
{
public:
RsPluginHashSetItem() : RsPluginItem(RS_PKT_CLASS_PLUGIN_SUBTYPE_HASHSET) {}
RsPluginHashSetItem(void *data,uint32_t size) ;
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,hashes,"hashes");
}
RsTlvHashSet hashes ;
};
class RsPluginSerialiser: public RsConfigSerializer
{
public:
RsPluginSerialiser() : RsConfigSerializer(RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PLUGIN_CONFIG) {}
virtual RsItem *create_item(uint8_t class_type, uint8_t item_type) const
{
if(class_type == RS_PKT_TYPE_PLUGIN_CONFIG && item_type == RS_PKT_CLASS_PLUGIN_SUBTYPE_HASHSET)
return new RsPluginHashSetItem() ;
return NULL ;
}
};