mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-22 14:10:54 -04:00
Merged branch v0.5-gxs-b1 into trunk (from -r 5351 -> 5995)
This brings a huge amount of goodness into the trunk, but there is still a big chunk todo before it can be released. * GXS Backend. * GXS Services: - Identities. - Circles - Photos - Wiki - GxsForums - Posted. * SSH no-gui server. See branch commits for more info. To switch on GXS stuff, enable CONFIG += gxs in both libretroshare.pro and retroshare-gui.pro git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5996 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
commit
069b72e0b2
549 changed files with 111171 additions and 25579 deletions
|
@ -90,3 +90,6 @@ const uint8_t QOS_PRIORITY_RS_BWCTRL_ALLOWED_ITEM = 9 ;
|
|||
const uint8_t QOS_PRIORITY_RS_DSDV_ROUTE = 4 ;
|
||||
const uint8_t QOS_PRIORITY_RS_DSDV_DATA = 2 ;
|
||||
|
||||
// GXS
|
||||
//
|
||||
const uint8_t QOS_PRIORITY_RS_GXS_NET = 3 ;
|
||||
|
|
422
libretroshare/src/serialiser/rsgxscircleitems.cc
Normal file
422
libretroshare/src/serialiser/rsgxscircleitems.cc
Normal file
|
@ -0,0 +1,422 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rswikiitems.cc
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2012 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2.1 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "rsgxscircleitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#define CIRCLE_DEBUG 1
|
||||
|
||||
|
||||
uint32_t RsGxsCircleSerialiser::size(RsItem *item)
|
||||
{
|
||||
RsGxsCircleGroupItem* grp_item = NULL;
|
||||
RsGxsCircleMsgItem* snap_item = NULL;
|
||||
|
||||
if((grp_item = dynamic_cast<RsGxsCircleGroupItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsCircleGroupItem(grp_item);
|
||||
}
|
||||
else if((snap_item = dynamic_cast<RsGxsCircleMsgItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsCircleMsgItem(snap_item);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool RsGxsCircleSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
RsGxsCircleGroupItem* grp_item = NULL;
|
||||
RsGxsCircleMsgItem* snap_item = NULL;
|
||||
|
||||
if((grp_item = dynamic_cast<RsGxsCircleGroupItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsCircleGroupItem(grp_item, data, size);
|
||||
}
|
||||
else if((snap_item = dynamic_cast<RsGxsCircleMsgItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsCircleMsgItem(snap_item, data, size);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem* RsGxsCircleSerialiser::deserialise(void* data, uint32_t* size)
|
||||
{
|
||||
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialise()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_GXSCIRCLE != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
|
||||
case RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM:
|
||||
return deserialiseGxsCircleGroupItem(data, size);
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM:
|
||||
return deserialiseGxsCircleMsgItem(data, size);
|
||||
break;
|
||||
default:
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialise(): unknown subtype";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
|
||||
void RsGxsCircleGroupItem::clear()
|
||||
{
|
||||
gxsIdSet.TlvClear();
|
||||
subCircleSet.TlvClear();
|
||||
}
|
||||
|
||||
bool RsGxsCircleGroupItem::convertFrom(const RsGxsCircleGroup &group)
|
||||
{
|
||||
clear();
|
||||
|
||||
meta = group.mMeta;
|
||||
gxsIdSet.ids = group.mInvitedMembers;
|
||||
subCircleSet.ids = group.mSubCircles;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RsGxsCircleGroupItem::convertTo(RsGxsCircleGroup &group) const
|
||||
{
|
||||
group.mMeta = meta;
|
||||
group.mInvitedMembers = gxsIdSet.ids;
|
||||
group.mSubCircles = subCircleSet.ids;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
std::ostream& RsGxsCircleGroupItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsCircleGroupItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
gxsIdSet.print(out, int_Indent);
|
||||
subCircleSet.print(out, int_Indent);
|
||||
|
||||
printRsItemEnd(out ,"RsGxsCircleGroupItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsCircleSerialiser::sizeGxsCircleGroupItem(RsGxsCircleGroupItem *item)
|
||||
{
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += item->gxsIdSet.TlvSize();
|
||||
s += item->subCircleSet.TlvSize();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsCircleSerialiser::serialiseGxsCircleGroupItem(RsGxsCircleGroupItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleGroupItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsCircleGroupItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize)
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleGroupItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsCircleGroupItem */
|
||||
ok &= item->gxsIdSet.SetTlv(data, tlvsize, &offset);
|
||||
ok &= item->subCircleSet.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleGroupItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef CIRCLE_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleGroupItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsCircleGroupItem* RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_GXSCIRCLE != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsCircleGroupItem* item = new RsGxsCircleGroupItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= item->gxsIdSet.GetTlv(data, rssize, &offset);
|
||||
ok &= item->subCircleSet.GetTlv(data, rssize, &offset);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
|
||||
void RsGxsCircleMsgItem::clear()
|
||||
{
|
||||
msg.stuff.clear();
|
||||
}
|
||||
|
||||
std::ostream& RsGxsCircleMsgItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsCircleMsgItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Stuff: " << msg.stuff << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsCircleMsgItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsCircleSerialiser::sizeGxsCircleMsgItem(RsGxsCircleMsgItem *item)
|
||||
{
|
||||
|
||||
const RsGxsCircleMsg &msg = item->msg;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(msg.stuff);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsCircleSerialiser::serialiseGxsCircleMsgItem(RsGxsCircleMsgItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleMsgItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsCircleMsgItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize)
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleMsgItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsCircleMsgItem */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->msg.stuff);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleMsgItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef CIRCLE_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleMsgItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsCircleMsgItem* RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_GXSCIRCLE != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsCircleMsgItem* item = new RsGxsCircleMsgItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->msg.stuff);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
102
libretroshare/src/serialiser/rsgxscircleitems.h
Normal file
102
libretroshare/src/serialiser/rsgxscircleitems.h
Normal file
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsgxscircleitems.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2012 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2.1 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RS_GXSCIRCLE_ITEMS_H
|
||||
#define RS_GXSCIRCLE_ITEMS_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
#include "retroshare/rsgxscircles.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM = 0x03;
|
||||
|
||||
const uint16_t GXSCIRCLE_GXSIDSET = 0x0001;
|
||||
const uint16_t GXSCIRCLE_SUBCIRCLESET = 0x0002;
|
||||
|
||||
class RsGxsCircleGroupItem : public RsGxsGrpItem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsGxsCircleGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_GXSCIRCLE,
|
||||
RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM),
|
||||
gxsIdSet(GXSCIRCLE_GXSIDSET),
|
||||
subCircleSet(GXSCIRCLE_SUBCIRCLESET) { return;}
|
||||
virtual ~RsGxsCircleGroupItem() { return;}
|
||||
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
bool convertFrom(const RsGxsCircleGroup &group);
|
||||
bool convertTo(RsGxsCircleGroup &group) const;
|
||||
|
||||
// DIFFERENT FROM OTHER ONES, as stupid serialisation otherwise.
|
||||
RsTlvStringSet gxsIdSet;
|
||||
RsTlvStringSet subCircleSet;
|
||||
};
|
||||
|
||||
class RsGxsCircleMsgItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsCircleMsgItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_GXSCIRCLE,
|
||||
RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM) {return; }
|
||||
virtual ~RsGxsCircleMsgItem() { return;}
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
RsGxsCircleMsg msg;
|
||||
};
|
||||
|
||||
class RsGxsCircleSerialiser : public RsSerialType
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsCircleSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_GXSCIRCLE)
|
||||
{ return; }
|
||||
virtual ~RsGxsCircleSerialiser() { return; }
|
||||
|
||||
uint32_t size(RsItem *item);
|
||||
bool serialise (RsItem *item, void *data, uint32_t *size);
|
||||
RsItem * deserialise(void *data, uint32_t *size);
|
||||
|
||||
private:
|
||||
|
||||
uint32_t sizeGxsCircleGroupItem(RsGxsCircleGroupItem *item);
|
||||
bool serialiseGxsCircleGroupItem (RsGxsCircleGroupItem *item, void *data, uint32_t *size);
|
||||
RsGxsCircleGroupItem * deserialiseGxsCircleGroupItem(void *data, uint32_t *size);
|
||||
|
||||
uint32_t sizeGxsCircleMsgItem(RsGxsCircleMsgItem *item);
|
||||
bool serialiseGxsCircleMsgItem (RsGxsCircleMsgItem *item, void *data, uint32_t *size);
|
||||
RsGxsCircleMsgItem * deserialiseGxsCircleMsgItem(void *data, uint32_t *size);
|
||||
};
|
||||
|
||||
#endif /* RS_GXSCIRCLE_ITEMS_H */
|
402
libretroshare/src/serialiser/rsgxsforumitems.cc
Normal file
402
libretroshare/src/serialiser/rsgxsforumitems.cc
Normal file
|
@ -0,0 +1,402 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsgxsforumitems.cc
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2012 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2.1 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "rsgxsforumitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#define GXSFORUM_DEBUG 1
|
||||
|
||||
|
||||
uint32_t RsGxsForumSerialiser::size(RsItem *item)
|
||||
{
|
||||
RsGxsForumGroupItem* grp_item = NULL;
|
||||
RsGxsForumMsgItem* op_item = NULL;
|
||||
|
||||
if((grp_item = dynamic_cast<RsGxsForumGroupItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsForumGroupItem(grp_item);
|
||||
}
|
||||
else if((op_item = dynamic_cast<RsGxsForumMsgItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsForumMsgItem(op_item);
|
||||
}
|
||||
std::cerr << "RsGxsForumSerialiser::size() ERROR invalid item" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool RsGxsForumSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
RsGxsForumGroupItem* grp_item = NULL;
|
||||
RsGxsForumMsgItem* op_item = NULL;
|
||||
|
||||
if((grp_item = dynamic_cast<RsGxsForumGroupItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsForumGroupItem(grp_item, data, size);
|
||||
}
|
||||
else if((op_item = dynamic_cast<RsGxsForumMsgItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsForumMsgItem(op_item, data, size);
|
||||
}
|
||||
std::cerr << "RsGxsForumSerialiser::serialise() ERROR invalid item" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem* RsGxsForumSerialiser::deserialise(void* data, uint32_t* size)
|
||||
{
|
||||
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
std::cerr << "RsGxsForumSerialiser::deserialise()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_FORUMS != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
|
||||
case RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM:
|
||||
return deserialiseGxsForumGroupItem(data, size);
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM:
|
||||
return deserialiseGxsForumMsgItem(data, size);
|
||||
break;
|
||||
default:
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
std::cerr << "RsGxsForumSerialiser::deserialise(): unknown subtype";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
|
||||
void RsGxsForumGroupItem::clear()
|
||||
{
|
||||
mGroup.mDescription.clear();
|
||||
}
|
||||
|
||||
std::ostream& RsGxsForumGroupItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsForumGroupItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Description: " << mGroup.mDescription << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsForumGroupItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsForumSerialiser::sizeGxsForumGroupItem(RsGxsForumGroupItem *item)
|
||||
{
|
||||
|
||||
const RsGxsForumGroup& group = item->mGroup;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(group.mDescription);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsForumSerialiser::serialiseGxsForumGroupItem(RsGxsForumGroupItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumGroupItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsForumGroupItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize)
|
||||
{
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumGroupItem() Size too small" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsForumGroupItem */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mGroup.mDescription);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumGroupItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumGroupItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsForumGroupItem* RsGxsForumSerialiser::deserialiseGxsForumGroupItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumGroupItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_FORUMS != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumGroupItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumGroupItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsForumGroupItem* item = new RsGxsForumGroupItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->mGroup.mDescription);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumGroupItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumGroupItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
|
||||
void RsGxsForumMsgItem::clear()
|
||||
{
|
||||
mMsg.mMsg.clear();
|
||||
}
|
||||
|
||||
std::ostream& RsGxsForumMsgItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsForumMsgItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Msg: " << mMsg.mMsg << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsForumMsgItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsForumSerialiser::sizeGxsForumMsgItem(RsGxsForumMsgItem *item)
|
||||
{
|
||||
|
||||
const RsGxsForumMsg& msg = item->mMsg;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(msg.mMsg); // mMsg.
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsForumSerialiser::serialiseGxsForumMsgItem(RsGxsForumMsgItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumMsgItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsForumMsgItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize)
|
||||
{
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumMsgItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsForumMsgItem */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mMsg.mMsg);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumMsgItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsForumSerialiser::serialiseGxsForumGroupItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsForumMsgItem* RsGxsForumSerialiser::deserialiseGxsForumMsgItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumMsgItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_FORUMS != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumMsgItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumMsgItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsForumMsgItem* item = new RsGxsForumMsgItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->mMsg.mMsg);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumMsgItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumMsgItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
95
libretroshare/src/serialiser/rsgxsforumitems.h
Normal file
95
libretroshare/src/serialiser/rsgxsforumitems.h
Normal file
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsgxsforumitems.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2012 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RS_GXS_FORUM_ITEMS_H
|
||||
#define RS_GXS_FORUM_ITEMS_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
#include "retroshare/rsgxsforums.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM = 0x03;
|
||||
|
||||
class RsGxsForumGroupItem : public RsGxsGrpItem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsGxsForumGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_FORUMS,
|
||||
RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM) { return;}
|
||||
virtual ~RsGxsForumGroupItem() { return;}
|
||||
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
|
||||
RsGxsForumGroup mGroup;
|
||||
};
|
||||
|
||||
class RsGxsForumMsgItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsForumMsgItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_FORUMS,
|
||||
RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM) {return; }
|
||||
virtual ~RsGxsForumMsgItem() { return;}
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
RsGxsForumMsg mMsg;
|
||||
};
|
||||
|
||||
class RsGxsForumSerialiser : public RsSerialType
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsForumSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_FORUMS)
|
||||
{ return; }
|
||||
virtual ~RsGxsForumSerialiser() { return; }
|
||||
|
||||
uint32_t size(RsItem *item);
|
||||
bool serialise (RsItem *item, void *data, uint32_t *size);
|
||||
RsItem * deserialise(void *data, uint32_t *size);
|
||||
|
||||
private:
|
||||
|
||||
uint32_t sizeGxsForumGroupItem(RsGxsForumGroupItem *item);
|
||||
bool serialiseGxsForumGroupItem (RsGxsForumGroupItem *item, void *data, uint32_t *size);
|
||||
RsGxsForumGroupItem * deserialiseGxsForumGroupItem(void *data, uint32_t *size);
|
||||
|
||||
uint32_t sizeGxsForumMsgItem(RsGxsForumMsgItem *item);
|
||||
bool serialiseGxsForumMsgItem (RsGxsForumMsgItem *item, void *data, uint32_t *size);
|
||||
RsGxsForumMsgItem * deserialiseGxsForumMsgItem(void *data, uint32_t *size);
|
||||
|
||||
};
|
||||
|
||||
#endif /* RS_GXS_FORUM_ITEMS_H */
|
576
libretroshare/src/serialiser/rsgxsiditems.cc
Normal file
576
libretroshare/src/serialiser/rsgxsiditems.cc
Normal file
|
@ -0,0 +1,576 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsgxsiditems.cc
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2012 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2.1 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "rsgxsiditems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#define GXSID_DEBUG 1
|
||||
|
||||
|
||||
uint32_t RsGxsIdSerialiser::size(RsItem *item)
|
||||
{
|
||||
RsGxsIdGroupItem* grp_item = NULL;
|
||||
RsGxsIdOpinionItem* op_item = NULL;
|
||||
RsGxsIdCommentItem* com_item = NULL;
|
||||
|
||||
if((grp_item = dynamic_cast<RsGxsIdGroupItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsIdGroupItem(grp_item);
|
||||
}
|
||||
else if((op_item = dynamic_cast<RsGxsIdOpinionItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsIdOpinionItem(op_item);
|
||||
}
|
||||
else if((com_item = dynamic_cast<RsGxsIdCommentItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsIdCommentItem(com_item);
|
||||
}
|
||||
std::cerr << "RsGxsIdSerialiser::size() ERROR invalid item" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool RsGxsIdSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
RsGxsIdGroupItem* grp_item = NULL;
|
||||
RsGxsIdOpinionItem* op_item = NULL;
|
||||
RsGxsIdCommentItem* com_item = NULL;
|
||||
|
||||
if((grp_item = dynamic_cast<RsGxsIdGroupItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsIdGroupItem(grp_item, data, size);
|
||||
}
|
||||
else if((op_item = dynamic_cast<RsGxsIdOpinionItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsIdOpinionItem(op_item, data, size);
|
||||
}
|
||||
else if((com_item = dynamic_cast<RsGxsIdCommentItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsIdCommentItem(com_item, data, size);
|
||||
}
|
||||
std::cerr << "RsGxsIdSerialiser::serialise() ERROR invalid item" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem* RsGxsIdSerialiser::deserialise(void* data, uint32_t* size)
|
||||
{
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialise()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_GXSID != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
|
||||
case RS_PKT_SUBTYPE_GXSID_GROUP_ITEM:
|
||||
return deserialiseGxsIdGroupItem(data, size);
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_GXSID_OPINION_ITEM:
|
||||
return deserialiseGxsIdOpinionItem(data, size);
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM:
|
||||
return deserialiseGxsIdCommentItem(data, size);
|
||||
break;
|
||||
default:
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialise(): unknown subtype";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
|
||||
void RsGxsIdGroupItem::clear()
|
||||
{
|
||||
group.mPgpIdHash.clear();
|
||||
group.mPgpIdSign.clear();
|
||||
|
||||
group.mPgpKnown = false;
|
||||
group.mPgpId.clear();
|
||||
|
||||
}
|
||||
|
||||
std::ostream& RsGxsIdGroupItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsIdGroupItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "PgpIdHash: " << group.mPgpIdHash << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "PgpIdSign: " << group.mPgpIdSign << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsIdGroupItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsIdSerialiser::sizeGxsIdGroupItem(RsGxsIdGroupItem *item)
|
||||
{
|
||||
|
||||
const RsGxsIdGroup& group = item->group;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(group.mPgpIdHash);
|
||||
s += GetTlvStringSize(group.mPgpIdSign);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsIdSerialiser::serialiseGxsIdGroupItem(RsGxsIdGroupItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdGroupItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsIdGroupItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdGroupItem() Size too small" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsIdGroupItem */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->group.mPgpIdHash);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->group.mPgpIdSign);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdGroupItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsIdGroupItem* RsGxsIdSerialiser::deserialiseGxsIdGroupItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_GXSID != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSID_GROUP_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsIdGroupItem* item = new RsGxsIdGroupItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->group.mPgpIdHash);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->group.mPgpIdSign);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
|
||||
void RsGxsIdOpinionItem::clear()
|
||||
{
|
||||
opinion.mOpinion = 0;
|
||||
|
||||
// Others that aren't serialised. - but should be cleared anyway
|
||||
opinion.mReputation = 0;
|
||||
}
|
||||
|
||||
std::ostream& RsGxsIdOpinionItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsIdOpinionItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Opinion: " << opinion.mOpinion << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsIdOpinionItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsIdSerialiser::sizeGxsIdOpinionItem(RsGxsIdOpinionItem *item)
|
||||
{
|
||||
|
||||
const RsGxsIdOpinion& opinion = item->opinion;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += 4; // mOpinion.
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsIdSerialiser::serialiseGxsIdOpinionItem(RsGxsIdOpinionItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdOpinionItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsIdOpinionItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdOpinionItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsIdOpinionItem */
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->opinion.mOpinion);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdOpinionItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsIdOpinionItem* RsGxsIdSerialiser::deserialiseGxsIdOpinionItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_GXSID != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSID_OPINION_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsIdOpinionItem* item = new RsGxsIdOpinionItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->opinion.mOpinion));
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
|
||||
void RsGxsIdCommentItem::clear()
|
||||
{
|
||||
comment.mComment.clear();
|
||||
}
|
||||
|
||||
std::ostream& RsGxsIdCommentItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsIdCommentItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Comment: " << comment.mComment << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsIdCommentItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsIdSerialiser::sizeGxsIdCommentItem(RsGxsIdCommentItem *item)
|
||||
{
|
||||
|
||||
const RsGxsIdComment& comment = item->comment;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(comment.mComment);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsIdSerialiser::serialiseGxsIdCommentItem(RsGxsIdCommentItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdCommentItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsIdCommentItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdCommentItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsIdCommentItem */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->comment.mComment);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdCommentItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsIdCommentItem* RsGxsIdSerialiser::deserialiseGxsIdCommentItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_GXSID != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsIdCommentItem* item = new RsGxsIdCommentItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->comment.mComment);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
112
libretroshare/src/serialiser/rsgxsiditems.h
Normal file
112
libretroshare/src/serialiser/rsgxsiditems.h
Normal file
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsgxsiditems.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2012 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RS_GXS_IDENTITY_ITEMS_H
|
||||
#define RS_GXS_IDENTITY_ITEMS_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
#include "retroshare/rsidentity.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSID_GROUP_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSID_OPINION_ITEM = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM = 0x04;
|
||||
|
||||
class RsGxsIdGroupItem : public RsGxsGrpItem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsGxsIdGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_GXSID,
|
||||
RS_PKT_SUBTYPE_GXSID_GROUP_ITEM) { return;}
|
||||
virtual ~RsGxsIdGroupItem() { return;}
|
||||
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
|
||||
RsGxsIdGroup group;
|
||||
};
|
||||
|
||||
class RsGxsIdOpinionItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsIdOpinionItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_GXSID,
|
||||
RS_PKT_SUBTYPE_GXSID_OPINION_ITEM) {return; }
|
||||
virtual ~RsGxsIdOpinionItem() { return;}
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
RsGxsIdOpinion opinion;
|
||||
};
|
||||
|
||||
class RsGxsIdCommentItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsIdCommentItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_GXSID,
|
||||
RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM) { return; }
|
||||
virtual ~RsGxsIdCommentItem() { return; }
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
RsGxsIdComment comment;
|
||||
|
||||
};
|
||||
|
||||
class RsGxsIdSerialiser : public RsSerialType
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsIdSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_GXSID)
|
||||
{ return; }
|
||||
virtual ~RsGxsIdSerialiser() { return; }
|
||||
|
||||
uint32_t size(RsItem *item);
|
||||
bool serialise (RsItem *item, void *data, uint32_t *size);
|
||||
RsItem * deserialise(void *data, uint32_t *size);
|
||||
|
||||
private:
|
||||
|
||||
uint32_t sizeGxsIdGroupItem(RsGxsIdGroupItem *item);
|
||||
bool serialiseGxsIdGroupItem (RsGxsIdGroupItem *item, void *data, uint32_t *size);
|
||||
RsGxsIdGroupItem * deserialiseGxsIdGroupItem(void *data, uint32_t *size);
|
||||
|
||||
uint32_t sizeGxsIdOpinionItem(RsGxsIdOpinionItem *item);
|
||||
bool serialiseGxsIdOpinionItem (RsGxsIdOpinionItem *item, void *data, uint32_t *size);
|
||||
RsGxsIdOpinionItem * deserialiseGxsIdOpinionItem(void *data, uint32_t *size);
|
||||
|
||||
uint32_t sizeGxsIdCommentItem(RsGxsIdCommentItem *item);
|
||||
bool serialiseGxsIdCommentItem (RsGxsIdCommentItem *item, void *data, uint32_t *size);
|
||||
RsGxsIdCommentItem * deserialiseGxsIdCommentItem(void *data, uint32_t *size);
|
||||
|
||||
};
|
||||
|
||||
#endif /* RS_GXS_IDENTITY_ITEMS_H */
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "rsgxsitems.h"
|
||||
#include "gxs/rsgxsdata.h"
|
||||
#include <iostream>
|
||||
|
||||
void RsMsgMetaData::operator =(const RsGxsMsgMetaData& rGxsMeta)
|
||||
{
|
||||
|
@ -22,6 +23,8 @@
|
|||
this->mParentId = rGxsMeta.mParentId;
|
||||
this->mPublishTs = rGxsMeta.mPublishTs;
|
||||
this->mThreadId = rGxsMeta.mThreadId;
|
||||
this->mServiceString = rGxsMeta.mServiceString;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -37,4 +40,31 @@
|
|||
this->mPublishTs = rGxsMeta.mPublishTs;
|
||||
this->mSubscribeFlags = rGxsMeta.mSubscribeFlags;
|
||||
this->mGroupName = rGxsMeta.mGroupName;
|
||||
this->mServiceString = rGxsMeta.mServiceString;
|
||||
this->mSignFlags = rGxsMeta.mSignFlags;
|
||||
this->mCircleId = rGxsMeta.mCircleId;
|
||||
this->mCircleType = rGxsMeta.mCircleType;
|
||||
this->mInternalCircle = rGxsMeta.mInternalCircle;
|
||||
this->mOriginator = rGxsMeta.mOriginator;
|
||||
}
|
||||
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const RsGroupMetaData &meta)
|
||||
{
|
||||
out << "[ GroupId: " << meta.mGroupId << " Name: " << meta.mGroupName << " ]";
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const RsMsgMetaData &meta)
|
||||
{
|
||||
out << "[ GroupId: " << meta.mGroupId << " MsgId: " << meta.mMsgId;
|
||||
out << " Name: " << meta.mMsgName;
|
||||
out << " OrigMsgId: " << meta.mOrigMsgId;
|
||||
out << " ThreadId: " << meta.mThreadId;
|
||||
out << " ParentId: " << meta.mParentId;
|
||||
out << " AuthorId: " << meta.mAuthorId;
|
||||
out << " Name: " << meta.mMsgName << " ]";
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -28,48 +28,62 @@
|
|||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
|
||||
class RsGxsGrpMetaData;
|
||||
class RsGxsMsgMetaData;
|
||||
|
||||
|
||||
class RsGroupMetaData
|
||||
{
|
||||
public:
|
||||
public:
|
||||
|
||||
RsGroupMetaData()
|
||||
{
|
||||
mGroupFlags = 0;
|
||||
mSubscribeFlags = 0;
|
||||
RsGroupMetaData()
|
||||
{
|
||||
mGroupFlags = 0;
|
||||
mSubscribeFlags = 0;
|
||||
|
||||
mPop = 0;
|
||||
mMsgCount = 0;
|
||||
mLastPost = 0;
|
||||
mGroupStatus = 0;
|
||||
mPop = 0;
|
||||
mMsgCount = 0;
|
||||
mLastPost = 0;
|
||||
|
||||
//mPublishTs = 0;
|
||||
}
|
||||
mGroupStatus = 0;
|
||||
mCircleType = 0;
|
||||
|
||||
void operator =(const RsGxsGrpMetaData& rGxsMeta);
|
||||
//mPublishTs = 0;
|
||||
}
|
||||
|
||||
std::string mGroupId;
|
||||
std::string mGroupName;
|
||||
uint32_t mGroupFlags;
|
||||
void operator =(const RsGxsGrpMetaData& rGxsMeta);
|
||||
|
||||
time_t mPublishTs; // Mandatory.
|
||||
std::string mAuthorId; // Optional.
|
||||
std::string mGroupId;
|
||||
std::string mGroupName;
|
||||
uint32_t mGroupFlags;
|
||||
uint32_t mSignFlags; // Combination of RSGXS_GROUP_SIGN_PUBLISH_MASK & RSGXS_GROUP_SIGN_AUTHOR_MASK.
|
||||
|
||||
time_t mPublishTs; // Mandatory.
|
||||
std::string mAuthorId; // Optional.
|
||||
|
||||
// for circles
|
||||
std::string mCircleId;
|
||||
uint32_t mCircleType;
|
||||
|
||||
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
|
||||
|
||||
uint32_t mSubscribeFlags;
|
||||
|
||||
uint32_t mPop; // HOW DO WE DO THIS NOW.
|
||||
uint32_t mMsgCount; // ???
|
||||
time_t mLastPost; // ???
|
||||
|
||||
uint32_t mGroupStatus;
|
||||
std::string mServiceString; // Service Specific Free-Form extra storage.
|
||||
std::string mOriginator;
|
||||
std::string mInternalCircle;
|
||||
|
||||
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
|
||||
|
||||
uint32_t mSubscribeFlags;
|
||||
|
||||
uint32_t mPop; // HOW DO WE DO THIS NOW.
|
||||
uint32_t mMsgCount; // ???
|
||||
time_t mLastPost; // ???
|
||||
|
||||
uint32_t mGroupStatus;
|
||||
|
||||
};
|
||||
|
||||
|
@ -78,40 +92,50 @@ class RsGroupMetaData
|
|||
|
||||
class RsMsgMetaData
|
||||
{
|
||||
public:
|
||||
|
||||
RsMsgMetaData()
|
||||
{
|
||||
mPublishTs = 0;
|
||||
mMsgFlags = 0;
|
||||
mMsgStatus = 0;
|
||||
mChildTs = 0;
|
||||
}
|
||||
public:
|
||||
|
||||
void operator =(const RsGxsMsgMetaData& rGxsMeta);
|
||||
RsMsgMetaData()
|
||||
{
|
||||
mPublishTs = 0;
|
||||
mMsgFlags = 0;
|
||||
|
||||
mMsgStatus = 0;
|
||||
mChildTs = 0;
|
||||
}
|
||||
|
||||
void operator =(const RsGxsMsgMetaData& rGxsMeta);
|
||||
|
||||
|
||||
std::string mGroupId;
|
||||
std::string mMsgId;
|
||||
std::string mGroupId;
|
||||
std::string mMsgId;
|
||||
|
||||
std::string mThreadId;
|
||||
std::string mParentId;
|
||||
std::string mOrigMsgId;
|
||||
std::string mThreadId;
|
||||
std::string mParentId;
|
||||
std::string mOrigMsgId;
|
||||
|
||||
std::string mAuthorId;
|
||||
std::string mAuthorId;
|
||||
|
||||
std::string mMsgName;
|
||||
time_t mPublishTs;
|
||||
std::string mMsgName;
|
||||
time_t mPublishTs;
|
||||
|
||||
uint32_t mMsgFlags; // Whats this for?
|
||||
/// the first 16 bits for service, last 16 for GXS
|
||||
uint32_t mMsgFlags;
|
||||
|
||||
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
|
||||
// normally READ / UNREAD flags. LOCAL Data.
|
||||
uint32_t mMsgStatus;
|
||||
time_t mChildTs;
|
||||
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
|
||||
// normally READ / UNREAD flags. LOCAL Data.
|
||||
|
||||
/// the first 16 bits for service, last 16 for GXS
|
||||
uint32_t mMsgStatus;
|
||||
|
||||
time_t mChildTs;
|
||||
std::string mServiceString; // Service Specific Free-Form extra storage.
|
||||
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const RsGroupMetaData &meta);
|
||||
std::ostream &operator<<(std::ostream &out, const RsMsgMetaData &meta);
|
||||
|
||||
|
||||
class RsGxsGrpItem : public RsItem
|
||||
{
|
||||
|
@ -122,6 +146,7 @@ public:
|
|||
: RsItem(RS_PKT_VERSION_SERVICE, service, subtype) { return; }
|
||||
virtual ~RsGxsGrpItem(){}
|
||||
|
||||
|
||||
RsGroupMetaData meta;
|
||||
};
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
|
||||
#include "gxs/rsgxsdata.h"
|
||||
|
||||
|
||||
|
@ -69,7 +68,11 @@ class RsNxsItem : public RsItem
|
|||
|
||||
public:
|
||||
RsNxsItem(uint16_t servtype, uint8_t subtype)
|
||||
: RsItem(RS_PKT_VERSION_SERVICE, servtype, subtype), transactionNumber(0) { return; }
|
||||
: RsItem(RS_PKT_VERSION_SERVICE, servtype, subtype), transactionNumber(0)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_VOIP_PING);
|
||||
return;
|
||||
}
|
||||
|
||||
virtual void clear() = 0;
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0) = 0;
|
||||
|
@ -196,7 +199,7 @@ public:
|
|||
RsTlvBinaryData grp; /// actual group data
|
||||
|
||||
/*!
|
||||
* This should contains all the data
|
||||
* This should contains all data
|
||||
* which is not specific to the Gxs service data
|
||||
*/
|
||||
RsTlvBinaryData meta;
|
||||
|
@ -259,7 +262,9 @@ class RsNxsMsg : public RsNxsItem
|
|||
{
|
||||
public:
|
||||
|
||||
RsNxsMsg(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_MSG), msg(servtype), meta(servtype) { clear(); return; }
|
||||
RsNxsMsg(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_MSG), meta(servtype), msg(servtype),
|
||||
metaData(NULL) { clear(); return; }
|
||||
~RsNxsMsg() { if(metaData) delete metaData; }
|
||||
|
||||
virtual void clear();
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
@ -294,7 +299,7 @@ public:
|
|||
virtual ~RsNxsSearchReq() { return;}
|
||||
|
||||
virtual void clear() { return;}
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) { return out; }
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t /*indent*/) { return out; }
|
||||
|
||||
uint8_t nHops; /// how many peers to jump to
|
||||
uint32_t token; // search token
|
||||
|
@ -332,7 +337,7 @@ public:
|
|||
|
||||
RsNxsSearchResultMsg() : context(0) { return;}
|
||||
void clear() {}
|
||||
std::ostream &print(std::ostream &out, uint16_t indent) { return out; }
|
||||
std::ostream &print(std::ostream &out, uint16_t /*indent*/) { return out; }
|
||||
|
||||
uint32_t token; // search token to be redeemed
|
||||
RsTlvBinaryData context; // used by client service
|
||||
|
@ -353,7 +358,7 @@ public:
|
|||
|
||||
RsNxsSearchResultGrp();
|
||||
void clear() {}
|
||||
std::ostream &print(std::ostream &out, uint16_t indent) { return out; }
|
||||
std::ostream &print(std::ostream &out, uint16_t /*indent*/) { return out; }
|
||||
|
||||
uint32_t token; // search token to be redeemed
|
||||
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsphotoitems.cc
|
||||
* libretroshare/src/retroshare: rsphoto.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2007-2008 by Robert Fernie.
|
||||
* Copyright 2012-2012 by Christopher Evi-Parker, Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
|
@ -24,267 +23,631 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rsphotoitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
|
||||
#define RSSERIAL_DEBUG 1
|
||||
#include <iostream>
|
||||
|
||||
/*************************************************************************/
|
||||
#include "rsphotoitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
void RsPhotoItem::clear()
|
||||
#define GXS_PHOTO_SERIAL_DEBUG
|
||||
|
||||
|
||||
uint32_t RsGxsPhotoSerialiser::size(RsItem* item)
|
||||
{
|
||||
srcId.clear();
|
||||
photoId.clear();
|
||||
size = 0;
|
||||
RsGxsPhotoPhotoItem* ppItem = NULL;
|
||||
RsGxsPhotoAlbumItem* paItem = NULL;
|
||||
RsGxsPhotoCommentItem* cItem = NULL;
|
||||
|
||||
name.clear();
|
||||
comment.clear();
|
||||
|
||||
location.clear();
|
||||
date.clear();
|
||||
|
||||
/* not serialised */
|
||||
isAvailable = false;
|
||||
path.clear();
|
||||
}
|
||||
|
||||
std::ostream &RsPhotoItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsPhotoItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
printIndent(out, int_Indent);
|
||||
out << "srcId: " << srcId << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "photoId: " << photoId << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "size: " << size << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "name: " << name << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
std::string cnv_comment(comment.begin(), comment.end());
|
||||
out << "msg: " << cnv_comment << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "location: " << location << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "date: " << date << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "(NS) isAvailable: " << isAvailable << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "(NS) path: " << path << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsPhotoItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
void RsPhotoShowItem::clear()
|
||||
{
|
||||
showId.clear();
|
||||
name.clear();
|
||||
comment.clear();
|
||||
|
||||
location.clear();
|
||||
date.clear();
|
||||
|
||||
photos.clear();
|
||||
}
|
||||
|
||||
std::ostream &RsPhotoShowItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsPhotoShowItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
uint16_t int_Indent2 = int_Indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "showId: " << showId << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "name: " << name << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
std::string cnv_comment(comment.begin(), comment.end());
|
||||
out << "msg: " << cnv_comment << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "location: " << location << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "date: " << date << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Photos in Show: " << photos.size() << std::endl;
|
||||
|
||||
std::list<RsPhotoRefItem>::iterator it;
|
||||
for(it = photos.begin(); it != photos.end(); it++)
|
||||
if((ppItem = dynamic_cast<RsGxsPhotoPhotoItem*>(item)) != NULL)
|
||||
{
|
||||
printIndent(out, int_Indent2);
|
||||
out << "PhotoId: " << it->photoId << std::endl;
|
||||
printIndent(out, int_Indent2 + 2);
|
||||
std::string cnv_comment2(it->altComment.begin(), it->altComment.end());
|
||||
out << "AltComment: " << cnv_comment2 << std::endl;
|
||||
printIndent(out, int_Indent2 + 2);
|
||||
out << "Delta T: " << it->deltaT << std::endl;
|
||||
return sizeGxsPhotoPhotoItem(ppItem);
|
||||
}
|
||||
else if((paItem = dynamic_cast<RsGxsPhotoAlbumItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsPhotoAlbumItem(paItem);
|
||||
}
|
||||
else if((cItem = dynamic_cast<RsGxsPhotoCommentItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsPhotoCommentItem(cItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
printRsItemEnd(out, "RsPhotoShowItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
RsPhotoRefItem::RsPhotoRefItem()
|
||||
:deltaT(0)
|
||||
bool RsGxsPhotoSerialiser::serialise(RsItem* item, void* data, uint32_t* size)
|
||||
{
|
||||
return;
|
||||
|
||||
RsGxsPhotoPhotoItem* ppItem = NULL;
|
||||
RsGxsPhotoAlbumItem* paItem = NULL;
|
||||
RsGxsPhotoCommentItem* cItem = NULL;
|
||||
|
||||
if((ppItem = dynamic_cast<RsGxsPhotoPhotoItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsPhotoPhotoItem(ppItem, data, size);
|
||||
}
|
||||
else if((paItem = dynamic_cast<RsGxsPhotoAlbumItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsPhotoAlbumItem(paItem, data, size);
|
||||
}else if((cItem = dynamic_cast<RsGxsPhotoCommentItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsPhotoCommentItem(cItem, data, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
/* TODO serialiser */
|
||||
|
||||
#if 0
|
||||
|
||||
uint32_t RsPhotoSerialiser::sizeLink(RsPhotoLinkMsg *item)
|
||||
RsItem* RsGxsPhotoSerialiser::deserialise(void* data, uint32_t* size)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += GetTlvStringSize(item->rid);
|
||||
s += 4; /* timestamp */
|
||||
s += GetTlvWideStringSize(item->title);
|
||||
s += GetTlvWideStringSize(item->comment);
|
||||
s += 4; /* linktype */
|
||||
s += GetTlvWideStringSize(item->link);
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialise()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_PHOTO != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
|
||||
case RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM:
|
||||
return deserialiseGxsPhotoPhotoItem(data, size);
|
||||
case RS_PKT_SUBTYPE_PHOTO_ITEM:
|
||||
return deserialiseGxsPhotoAlbumItem(data, size);
|
||||
case RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM:
|
||||
return deserialiseGxsPhotoCommentItem(data, size);
|
||||
default:
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialise(): subtype could not be dealt with"
|
||||
<< std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint32_t RsGxsPhotoSerialiser::sizeGxsPhotoAlbumItem(RsGxsPhotoAlbumItem* item)
|
||||
{
|
||||
|
||||
const RsPhotoAlbum& album = item->album;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(album.mCaption);
|
||||
s += GetTlvStringSize(album.mCategory);
|
||||
s += GetTlvStringSize(album.mDescription);
|
||||
s += GetTlvStringSize(album.mHashTags);
|
||||
s += GetTlvStringSize(album.mOther);
|
||||
s += GetTlvStringSize(album.mPhotoPath);
|
||||
s += GetTlvStringSize(album.mPhotographer);
|
||||
s += GetTlvStringSize(album.mWhen);
|
||||
s += GetTlvStringSize(album.mWhere);
|
||||
|
||||
RsTlvBinaryData b(item->PacketService()); // TODO, need something more persisitent
|
||||
b.setBinData(album.mThumbnail.data, album.mThumbnail.size);
|
||||
s += GetTlvStringSize(album.mThumbnail.type);
|
||||
s += b.TlvSize();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* serialise the data to the buffer */
|
||||
bool RsPhotoSerialiser::serialiseLink(RsPhotoLinkMsg *item, void *data, uint32_t *pktsize)
|
||||
uint32_t RsGxsPhotoSerialiser::sizeGxsPhotoCommentItem(RsGxsPhotoCommentItem *item)
|
||||
{
|
||||
uint32_t tlvsize = sizeLink(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (*pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
const RsPhotoComment& comment = item->comment;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
*pktsize = tlvsize;
|
||||
s += GetTlvStringSize(comment.mComment);
|
||||
s += 4; // mflags
|
||||
|
||||
bool ok = true;
|
||||
return s;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() Header: " << ok << std::endl;
|
||||
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() Size: " << tlvsize << std::endl;
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GENID, item->rid);
|
||||
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() rid: " << ok << std::endl;
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->timestamp);
|
||||
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() timestamp: " << ok << std::endl;
|
||||
|
||||
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_TITLE, item->title);
|
||||
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() Title: " << ok << std::endl;
|
||||
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_COMMENT, item->comment);
|
||||
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() Comment: " << ok << std::endl;
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->linktype);
|
||||
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() linktype: " << ok << std::endl;
|
||||
|
||||
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_LINK, item->link);
|
||||
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() Link: " << ok << std::endl;
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() Size Error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsPhotoLinkMsg *RsPhotoSerialiser::deserialiseLink(void *data, uint32_t *pktsize)
|
||||
bool RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem(RsGxsPhotoAlbumItem* item, void* data,
|
||||
uint32_t* size)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_RANK != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_RANK_LINK != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*pktsize < rssize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*pktsize = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsPhotoLinkMsg *item = new RsPhotoLinkMsg();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* get mandatory parts first */
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_GENID, item->rid);
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->timestamp));
|
||||
ok &= GetTlvWideString(data, rssize, &offset, TLV_TYPE_WSTR_TITLE, item->title);
|
||||
ok &= GetTlvWideString(data, rssize, &offset, TLV_TYPE_WSTR_COMMENT, item->comment);
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->linktype));
|
||||
ok &= GetTlvWideString(data, rssize, &offset, TLV_TYPE_WSTR_LINK, item->link);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsPhotoSerialiser::size(RsItem *item)
|
||||
{
|
||||
return sizeLink((RsPhotoLinkMsg *) item);
|
||||
}
|
||||
|
||||
bool RsPhotoSerialiser::serialise(RsItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
return serialiseLink((RsPhotoLinkMsg *) item, data, pktsize);
|
||||
}
|
||||
|
||||
RsItem *RsPhotoSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
{
|
||||
return deserialiseLink(data, pktsize);
|
||||
}
|
||||
|
||||
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsPhotoAlbumItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
/*************************************************************************/
|
||||
if(*size < tlvsize){
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsPhotoAlbumItem */
|
||||
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mCaption);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mCategory);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mDescription);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mHashTags);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mOther);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mPhotoPath);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mPhotographer);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mWhen);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mWhere);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mThumbnail.type);
|
||||
RsTlvBinaryData b(RS_SERVICE_GXSV1_TYPE_PHOTO); // TODO, need something more persisitent
|
||||
b.setBinData(item->album.mThumbnail.data, item->album.mThumbnail.size);
|
||||
ok &= b.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsPhotoAlbumItem* RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem(void* data,
|
||||
uint32_t* size)
|
||||
{
|
||||
|
||||
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_PHOTO != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_PHOTO_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsPhotoAlbumItem* item = new RsGxsPhotoAlbumItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mCaption);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mCategory);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mDescription);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mHashTags);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mOther);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mPhotoPath);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mPhotographer);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mWhen);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mWhere);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mThumbnail.type);
|
||||
|
||||
RsTlvBinaryData b(RS_SERVICE_GXSV1_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;
|
||||
b.TlvShallowClear();
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
uint32_t RsGxsPhotoSerialiser::sizeGxsPhotoPhotoItem(RsGxsPhotoPhotoItem* item)
|
||||
{
|
||||
|
||||
const RsPhotoPhoto& photo = item->photo;
|
||||
|
||||
uint32_t s = 8; // header size
|
||||
s += GetTlvStringSize(photo.mCaption);
|
||||
s += GetTlvStringSize(photo.mCategory);
|
||||
s += GetTlvStringSize(photo.mDescription);
|
||||
s += GetTlvStringSize(photo.mHashTags);
|
||||
s += GetTlvStringSize(photo.mOther);
|
||||
s += GetTlvStringSize(photo.mPhotographer);
|
||||
s += GetTlvStringSize(photo.mWhen);
|
||||
s += GetTlvStringSize(photo.mWhere);
|
||||
|
||||
RsTlvBinaryData b(item->PacketService()); // TODO, need something more persisitent
|
||||
b.setBinData(photo.mThumbnail.data, photo.mThumbnail.size);
|
||||
s += GetTlvStringSize(photo.mThumbnail.type);
|
||||
s += b.TlvSize();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem(RsGxsPhotoPhotoItem* item, void* data,
|
||||
uint32_t* size)
|
||||
{
|
||||
|
||||
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsPhotoPhotoItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize){
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsPhotoAlbumItem */
|
||||
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mCaption);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mCategory);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mDescription);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mHashTags);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mOther);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mPhotographer);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mWhen);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mWhere);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mThumbnail.type);
|
||||
RsTlvBinaryData b(RS_SERVICE_GXSV1_TYPE_PHOTO); // TODO, need something more persisitent
|
||||
b.setBinData(item->photo.mThumbnail.data, item->photo.mThumbnail.size);
|
||||
ok &= b.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsPhotoPhotoItem* RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem(void* data,
|
||||
uint32_t* size)
|
||||
{
|
||||
|
||||
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_PHOTO != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsPhotoPhotoItem* item = new RsGxsPhotoPhotoItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mCaption);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mCategory);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mDescription);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mHashTags);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mOther);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mPhotographer);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mWhen);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mWhere);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mThumbnail.type);
|
||||
|
||||
RsTlvBinaryData b(RS_SERVICE_GXSV1_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;
|
||||
b.TlvShallowClear();
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool RsGxsPhotoSerialiser::serialiseGxsPhotoCommentItem (RsGxsPhotoCommentItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoCommentItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsPhotoCommentItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize){
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoCommentItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsPhotoAlbumItem */
|
||||
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 0, item->comment.mComment);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->comment.mCommentFlag);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoCommentItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoCommentItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsPhotoCommentItem * RsGxsPhotoSerialiser::deserialiseGxsPhotoCommentItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_PHOTO != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoCommentItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoCommentItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsPhotoCommentItem* item = new RsGxsPhotoCommentItem();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 0, item->comment.mComment);
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->comment.mCommentFlag));
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoCommentItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoCommentItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
void RsGxsPhotoAlbumItem::clear()
|
||||
{
|
||||
album.mCaption.clear();
|
||||
album.mCategory.clear();
|
||||
album.mDescription.clear();
|
||||
album.mHashTags.clear();
|
||||
album.mOther.clear();
|
||||
album.mPhotoPath.clear();
|
||||
album.mPhotographer.clear();
|
||||
album.mWhen.clear();
|
||||
album.mWhere.clear();
|
||||
album.mThumbnail.deleteImage();
|
||||
}
|
||||
|
||||
void RsGxsPhotoCommentItem::clear()
|
||||
{
|
||||
comment.mComment.clear();
|
||||
comment.mCommentFlag = 0;
|
||||
}
|
||||
|
||||
std::ostream& RsGxsPhotoCommentItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsPhotoCommentItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
|
||||
printRsItemEnd(out ,"RsGxsPhotoCommentItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream& RsGxsPhotoAlbumItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsPhotoAlbumItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
out << album << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsPhotoAlbumItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
void RsGxsPhotoPhotoItem::clear()
|
||||
{
|
||||
photo.mCaption.clear();
|
||||
photo.mCategory.clear();
|
||||
photo.mDescription.clear();
|
||||
photo.mHashTags.clear();
|
||||
photo.mOther.clear();
|
||||
photo.mPhotographer.clear();
|
||||
photo.mWhen.clear();
|
||||
photo.mWhere.clear();
|
||||
photo.mThumbnail.deleteImage();
|
||||
}
|
||||
|
||||
std::ostream& RsGxsPhotoPhotoItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsPhotoPhotoItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
|
||||
printRsItemEnd(out ,"RsGxsPhotoPhotoItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
#ifndef P3_PHOTO_ITEMS_H
|
||||
#define P3_PHOTO_ITEMS_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsphotoitems.h
|
||||
* libretroshare/src/retroshare: rsphoto.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2007-2008 by Robert Fernie.
|
||||
* Copyright 2012-2012 by Christopher Evi-Parker, Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
|
@ -26,113 +23,91 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#ifndef RSPHOTOV2ITEMS_H_
|
||||
#define RSPHOTOV2ITEMS_H_
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
#include "retroshare/rsphoto.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_PHOTO_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM = 0x04;
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
class RsPhotoItem;
|
||||
class RsPhotoShowItem;
|
||||
class RsPhotoCommentItem;
|
||||
|
||||
class RsPhotoItem: public RsItem
|
||||
class RsGxsPhotoAlbumItem : public RsGxsGrpItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsPhotoItem()
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_PHOTO,
|
||||
RS_PKT_SUBTYPE_PHOTO_ITEM) { return; }
|
||||
virtual ~RsPhotoItem() { return; }
|
||||
virtual void clear();
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
public:
|
||||
|
||||
std::string srcId;
|
||||
std::string photoId; /* same as hash */
|
||||
uint64_t size; /* file size */
|
||||
RsGxsPhotoAlbumItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_PHOTO,
|
||||
RS_PKT_SUBTYPE_PHOTO_ITEM) { return;}
|
||||
virtual ~RsGxsPhotoAlbumItem() { return;}
|
||||
|
||||
std::string name;
|
||||
std::wstring comment;
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
std::string location; /* TODO: change to TLV */
|
||||
std::string date; /* TODO: change to TLV */
|
||||
|
||||
/* not serialised */
|
||||
bool isAvailable;
|
||||
std::string path;
|
||||
RsPhotoAlbum album;
|
||||
};
|
||||
|
||||
/* THIS must be turned into a TLV type + set (TOD) */
|
||||
class RsPhotoRefItem
|
||||
class RsGxsPhotoPhotoItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
RsPhotoRefItem();
|
||||
public:
|
||||
|
||||
std::string photoId;
|
||||
std::wstring altComment;
|
||||
uint32_t deltaT; /* in 100ths of sec? */
|
||||
RsGxsPhotoPhotoItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_PHOTO,
|
||||
RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM) {return; }
|
||||
virtual ~RsGxsPhotoPhotoItem() { return;}
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
RsPhotoPhoto photo;
|
||||
};
|
||||
|
||||
class RsPhotoShowItem: public RsItem
|
||||
class RsGxsPhotoCommentItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
RsPhotoShowItem()
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_PHOTO,
|
||||
RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM) { return; }
|
||||
public:
|
||||
|
||||
virtual ~RsPhotoShowItem() { return; }
|
||||
virtual void clear();
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
RsGxsPhotoCommentItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_PHOTO,
|
||||
RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM) { return; }
|
||||
virtual ~RsGxsPhotoCommentItem() { return; }
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
RsPhotoComment comment;
|
||||
|
||||
std::string showId;
|
||||
|
||||
std::string name;
|
||||
std::wstring comment;
|
||||
|
||||
std::string location; /* TODO -> TLV */
|
||||
std::string date; /* TODO -> TLV */
|
||||
std::list<RsPhotoRefItem> photos; /* list as ordered */
|
||||
};
|
||||
|
||||
class RsPhotoSerialiser: public RsSerialType
|
||||
class RsGxsPhotoSerialiser : public RsSerialType
|
||||
{
|
||||
public:
|
||||
RsPhotoSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_PHOTO)
|
||||
public:
|
||||
|
||||
RsGxsPhotoSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_PHOTO)
|
||||
{ return; }
|
||||
virtual ~RsPhotoSerialiser()
|
||||
{ return; }
|
||||
|
||||
virtual uint32_t size(RsItem *) { return 0; }
|
||||
virtual bool serialise (RsItem */*item*/, void */*data*/, uint32_t */*size*/) { return false; }
|
||||
virtual RsItem * deserialise(void */*data*/, uint32_t */*size*/) { return NULL; }
|
||||
virtual ~RsGxsPhotoSerialiser() { return; }
|
||||
|
||||
uint32_t size(RsItem *item);
|
||||
bool serialise (RsItem *item, void *data, uint32_t *size);
|
||||
RsItem * deserialise(void *data, uint32_t *size);
|
||||
|
||||
private:
|
||||
|
||||
/* For RS_PKT_SUBTYPE_PHOTO_ITEM */
|
||||
//virtual uint32_t sizeLink(RsPhotoItem *);
|
||||
//virtual bool serialiseLink (RsPhotoItem *item, void *data, uint32_t *size);
|
||||
//virtual RsPhotoItem *deserialiseLink(void *data, uint32_t *size);
|
||||
uint32_t sizeGxsPhotoAlbumItem(RsGxsPhotoAlbumItem *item);
|
||||
bool serialiseGxsPhotoAlbumItem (RsGxsPhotoAlbumItem *item, void *data, uint32_t *size);
|
||||
RsGxsPhotoAlbumItem * deserialiseGxsPhotoAlbumItem(void *data, uint32_t *size);
|
||||
|
||||
/* For RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM */
|
||||
//virtual uint32_t sizeLink(RsPhotoShowItem *);
|
||||
//virtual bool serialiseLink (RsPhotoShowItem *item, void *data, uint32_t *size);
|
||||
//virtual RsPhotoShowItem *deserialiseLink(void *data, uint32_t *size);
|
||||
uint32_t sizeGxsPhotoPhotoItem(RsGxsPhotoPhotoItem *item);
|
||||
bool serialiseGxsPhotoPhotoItem (RsGxsPhotoPhotoItem *item, void *data, uint32_t *size);
|
||||
RsGxsPhotoPhotoItem * deserialiseGxsPhotoPhotoItem(void *data, uint32_t *size);
|
||||
|
||||
/* For RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM */
|
||||
//virtual uint32_t sizeLink(RsPhotoCommentItem *);
|
||||
//virtual bool serialiseLink (RsPhotoCommentItem *item, void *data, uint32_t *size);
|
||||
//virtual RsPhotoCommentItem *deserialiseLink(void *data, uint32_t *size);
|
||||
uint32_t sizeGxsPhotoCommentItem(RsGxsPhotoCommentItem *item);
|
||||
bool serialiseGxsPhotoCommentItem (RsGxsPhotoCommentItem *item, void *data, uint32_t *size);
|
||||
RsGxsPhotoCommentItem * deserialiseGxsPhotoCommentItem(void *data, uint32_t *size);
|
||||
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#endif /* RS_PHOTO_ITEMS_H */
|
||||
|
||||
#endif /* RSPHOTOV2ITEMS_H_ */
|
||||
|
|
|
@ -1,491 +0,0 @@
|
|||
/*
|
||||
* libretroshare/src/retroshare: rsphoto.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2012 by Christopher Evi-Parker, Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "rsphotov2items.h"
|
||||
|
||||
#define GXS_PHOTO_SERIAL_DEBUG
|
||||
|
||||
|
||||
uint32_t RsGxsPhotoSerialiser::size(RsItem* item)
|
||||
{
|
||||
|
||||
RsGxsPhotoPhotoItem* ppItem = NULL;
|
||||
RsGxsPhotoAlbumItem* paItem = NULL;
|
||||
|
||||
if((ppItem = dynamic_cast<RsGxsPhotoPhotoItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsPhotoPhotoItem(ppItem);
|
||||
}
|
||||
else if((paItem = dynamic_cast<RsGxsPhotoAlbumItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsPhotoAlbumItem(paItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool RsGxsPhotoSerialiser::serialise(RsItem* item, void* data, uint32_t* size)
|
||||
{
|
||||
|
||||
RsGxsPhotoPhotoItem* ppItem = NULL;
|
||||
RsGxsPhotoAlbumItem* paItem = NULL;
|
||||
|
||||
if((ppItem = dynamic_cast<RsGxsPhotoPhotoItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsPhotoPhotoItem(ppItem, data, size);
|
||||
}
|
||||
else if((paItem = dynamic_cast<RsGxsPhotoAlbumItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsPhotoAlbumItem(paItem, data, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RsItem* RsGxsPhotoSerialiser::deserialise(void* data, uint32_t* size)
|
||||
{
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialise()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_PHOTO != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
|
||||
case RS_PKT_SUBTYPE_NXS_SYNC_GRP:
|
||||
return deserialiseGxsPhotoPhotoItem(data, size);
|
||||
case RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM:
|
||||
return deserialiseGxsPhotoAlbumItem(data, size);
|
||||
default:
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialise(): subtype could not be dealt with"
|
||||
<< std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint32_t RsGxsPhotoSerialiser::sizeGxsPhotoAlbumItem(RsGxsPhotoAlbumItem* item)
|
||||
{
|
||||
|
||||
const RsPhotoAlbum& album = item->album;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(album.mCaption);
|
||||
s += GetTlvStringSize(album.mCategory);
|
||||
s += GetTlvStringSize(album.mDescription);
|
||||
s += GetTlvStringSize(album.mHashTags);
|
||||
s += GetTlvStringSize(album.mOther);
|
||||
s += GetTlvStringSize(album.mPhotoPath);
|
||||
s += GetTlvStringSize(album.mPhotographer);
|
||||
s += GetTlvStringSize(album.mWhen);
|
||||
s += GetTlvStringSize(album.mWhere);
|
||||
|
||||
RsTlvBinaryData b(item->PacketService()); // TODO, need something more persisitent
|
||||
b.setBinData(album.mThumbnail.data, album.mThumbnail.size);
|
||||
s += GetTlvStringSize(album.mThumbnail.type);
|
||||
s += b.TlvSize();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem(RsGxsPhotoAlbumItem* item, void* data,
|
||||
uint32_t* size)
|
||||
{
|
||||
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsPhotoAlbumItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize){
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsPhotoAlbumItem */
|
||||
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mCaption);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mCategory);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mDescription);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mHashTags);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mOther);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mPhotoPath);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mPhotographer);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mWhen);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mWhere);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mThumbnail.type);
|
||||
RsTlvBinaryData b(item->PacketService()); // TODO, need something more persisitent
|
||||
b.setBinData(item->album.mThumbnail.data, item->album.mThumbnail.size);
|
||||
b.SetTlv(item->album.mThumbnail.data, tlvsize, &offset);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsPhotoAlbumItem* RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem(void* data,
|
||||
uint32_t* size)
|
||||
{
|
||||
|
||||
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_PHOTO != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_PHOTO_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsPhotoAlbumItem* item = new RsGxsPhotoAlbumItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mCaption);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mCategory);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mDescription);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mHashTags);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mOther);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mPhotoPath);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mPhotographer);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mWhen);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mWhere);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mThumbnail.type);
|
||||
|
||||
RsTlvBinaryData b(RS_SERVICE_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;
|
||||
b.TlvShallowClear();
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
uint32_t RsGxsPhotoSerialiser::sizeGxsPhotoPhotoItem(RsGxsPhotoPhotoItem* item)
|
||||
{
|
||||
|
||||
const RsPhotoPhoto& photo = item->photo;
|
||||
|
||||
uint32_t s = 8; // header size
|
||||
s += GetTlvStringSize(photo.mCaption);
|
||||
s += GetTlvStringSize(photo.mCategory);
|
||||
s += GetTlvStringSize(photo.mDescription);
|
||||
s += GetTlvStringSize(photo.mHashTags);
|
||||
s += GetTlvStringSize(photo.mOther);
|
||||
s += GetTlvStringSize(photo.mPhotographer);
|
||||
s += GetTlvStringSize(photo.mWhen);
|
||||
s += GetTlvStringSize(photo.mWhere);
|
||||
|
||||
RsTlvBinaryData b(item->PacketService()); // TODO, need something more persisitent
|
||||
b.setBinData(photo.mThumbnail.data, photo.mThumbnail.size);
|
||||
s += GetTlvStringSize(photo.mThumbnail.type);
|
||||
s += b.TlvSize();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem(RsGxsPhotoPhotoItem* item, void* data,
|
||||
uint32_t* size)
|
||||
{
|
||||
|
||||
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsPhotoPhotoItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize){
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsPhotoAlbumItem */
|
||||
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mCaption);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mCategory);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mDescription);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mHashTags);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mOther);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mPhotographer);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mWhen);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mWhere);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mThumbnail.type);
|
||||
RsTlvBinaryData b(RS_SERVICE_TYPE_PHOTO); // TODO, need something more persisitent
|
||||
b.setBinData(item->photo.mThumbnail.data, item->photo.mThumbnail.size);
|
||||
b.SetTlv(item->photo.mThumbnail.data, tlvsize, &offset);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsPhotoPhotoItem* RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem(void* data,
|
||||
uint32_t* size)
|
||||
{
|
||||
|
||||
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_PHOTO != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsPhotoPhotoItem* item = new RsGxsPhotoPhotoItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mCaption);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mCategory);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mDescription);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mHashTags);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mOther);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mPhotographer);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mWhen);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mWhere);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mThumbnail.type);
|
||||
|
||||
RsTlvBinaryData b(RS_SERVICE_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;
|
||||
b.TlvShallowClear();
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
void RsGxsPhotoAlbumItem::clear()
|
||||
{
|
||||
album.mCaption.clear();
|
||||
album.mCategory.clear();
|
||||
album.mDescription.clear();
|
||||
album.mHashTags.clear();
|
||||
album.mOther.clear();
|
||||
album.mPhotoPath.clear();
|
||||
album.mPhotographer.clear();
|
||||
album.mWhen.clear();
|
||||
album.mWhere.clear();
|
||||
album.mThumbnail.deleteImage();
|
||||
}
|
||||
|
||||
std::ostream& RsGxsPhotoAlbumItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsPhotoAlbumItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
|
||||
printRsItemEnd(out ,"RsGxsPhotoAlbumItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
void RsGxsPhotoPhotoItem::clear()
|
||||
{
|
||||
photo.mCaption.clear();
|
||||
photo.mCategory.clear();
|
||||
photo.mDescription.clear();
|
||||
photo.mHashTags.clear();
|
||||
photo.mOther.clear();
|
||||
photo.mPhotographer.clear();
|
||||
photo.mWhen.clear();
|
||||
photo.mWhere.clear();
|
||||
photo.mThumbnail.deleteImage();
|
||||
}
|
||||
|
||||
std::ostream& RsGxsPhotoPhotoItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsPhotoPhotoItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
|
||||
printRsItemEnd(out ,"RsGxsPhotoPhotoItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
/*
|
||||
* libretroshare/src/retroshare: rsphoto.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2012 by Christopher Evi-Parker, Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RSPHOTOV2ITEMS_H_
|
||||
#define RSPHOTOV2ITEMS_H_
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
#include "rsphotoitems.h"
|
||||
#include "retroshare/rsphotoV2.h"
|
||||
|
||||
|
||||
class RsGxsPhotoAlbumItem : public RsGxsGrpItem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsGxsPhotoAlbumItem(): RsGxsGrpItem(RS_SERVICE_TYPE_PHOTO,
|
||||
RS_PKT_SUBTYPE_PHOTO_ITEM) { return;}
|
||||
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
|
||||
RsPhotoAlbum album;
|
||||
};
|
||||
|
||||
class RsGxsPhotoPhotoItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsPhotoPhotoItem(): RsGxsMsgItem(RS_SERVICE_TYPE_PHOTO,
|
||||
RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM) {return; }
|
||||
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
RsPhotoPhoto photo;
|
||||
};
|
||||
|
||||
class RsGxsPhotoSerialiser : public RsSerialType
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsPhotoSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_PHOTO)
|
||||
{ return; }
|
||||
virtual ~RsGxsPhotoSerialiser() { return; }
|
||||
|
||||
uint32_t size(RsItem *item);
|
||||
bool serialise (RsItem *item, void *data, uint32_t *size);
|
||||
RsItem * deserialise(void *data, uint32_t *size);
|
||||
|
||||
private:
|
||||
|
||||
uint32_t sizeGxsPhotoAlbumItem(RsGxsPhotoAlbumItem *item);
|
||||
bool serialiseGxsPhotoAlbumItem (RsGxsPhotoAlbumItem *item, void *data, uint32_t *size);
|
||||
RsGxsPhotoAlbumItem * deserialiseGxsPhotoAlbumItem(void *data, uint32_t *size);
|
||||
|
||||
uint32_t sizeGxsPhotoPhotoItem(RsGxsPhotoPhotoItem *item);
|
||||
bool serialiseGxsPhotoPhotoItem (RsGxsPhotoPhotoItem *item, void *data, uint32_t *size);
|
||||
RsGxsPhotoPhotoItem * deserialiseGxsPhotoPhotoItem(void *data, uint32_t *size);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif /* RSPHOTOV2ITEMS_H_ */
|
656
libretroshare/src/serialiser/rsposteditems.cc
Normal file
656
libretroshare/src/serialiser/rsposteditems.cc
Normal file
|
@ -0,0 +1,656 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/gxs: rsopsteditems.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2012 by Christopher Evi-Parker
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rsposteditems.h"
|
||||
#include "rsbaseserial.h"
|
||||
|
||||
|
||||
uint32_t RsGxsPostedSerialiser::size(RsItem *item)
|
||||
{
|
||||
RsGxsPostedPostItem* ppItem = NULL;
|
||||
RsGxsPostedCommentItem* pcItem = NULL;
|
||||
RsGxsPostedVoteItem* pvItem = NULL;
|
||||
RsGxsPostedGroupItem* pgItem = NULL;
|
||||
|
||||
if((ppItem = dynamic_cast<RsGxsPostedPostItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsPostedPostItem(ppItem);
|
||||
}
|
||||
else if((pcItem = dynamic_cast<RsGxsPostedCommentItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsPostedCommentItem(pcItem);
|
||||
}else if((pvItem = dynamic_cast<RsGxsPostedVoteItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsPostedVoteItem(pvItem);
|
||||
}else if((pgItem = dynamic_cast<RsGxsPostedGroupItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsPostedGroupItem(pgItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::size() Failed" << std::endl;
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool RsGxsPostedSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
RsGxsPostedPostItem* ppItem = NULL;
|
||||
RsGxsPostedCommentItem* pcItem = NULL;
|
||||
RsGxsPostedVoteItem* pvItem = NULL;
|
||||
RsGxsPostedGroupItem* pgItem = NULL;
|
||||
|
||||
if((ppItem = dynamic_cast<RsGxsPostedPostItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsPostedPostItem(ppItem, data, size);
|
||||
}
|
||||
else if((pcItem = dynamic_cast<RsGxsPostedCommentItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsPostedCommentItem(pcItem, data, size);
|
||||
}else if((pvItem = dynamic_cast<RsGxsPostedVoteItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsPostedVoteItem(pvItem, data, size);
|
||||
}else if((pgItem = dynamic_cast<RsGxsPostedGroupItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsPostedGroupItem(pgItem, data, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialise() FAILED" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
RsItem* RsGxsPostedSerialiser::deserialise(void *data, uint32_t *size)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialise()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
|
||||
case RS_PKT_SUBTYPE_POSTED_COMMENT_ITEM:
|
||||
return deserialiseGxsPostedCommentItem(data, size);
|
||||
case RS_PKT_SUBTYPE_POSTED_GRP_ITEM:
|
||||
return deserialiseGxsPostedGroupItem(data, size);
|
||||
case RS_PKT_SUBTYPE_POSTED_POST_ITEM:
|
||||
return deserialiseGxsPostedPostItem(data, size);
|
||||
case RS_PKT_SUBTYPE_POSTED_VOTE_ITEM:
|
||||
return deserialiseGxsPostedVoteItem(data, size);
|
||||
default:
|
||||
{
|
||||
#ifdef RS_SSERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialise(): subtype could not be dealt with"
|
||||
<< std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsPostedSerialiser::sizeGxsPostedPostItem(RsGxsPostedPostItem* item)
|
||||
{
|
||||
RsPostedPost& p = item->mPost;
|
||||
|
||||
uint32_t s = 8;
|
||||
|
||||
s += GetTlvStringSize(p.mLink);
|
||||
s += GetTlvStringSize(p.mNotes);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
uint32_t RsGxsPostedSerialiser::sizeGxsPostedCommentItem(RsGxsPostedCommentItem* item)
|
||||
{
|
||||
RsPostedComment& c = item->mComment;
|
||||
|
||||
uint32_t s = 8;
|
||||
|
||||
s += GetTlvStringSize(c.mComment);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
uint32_t RsGxsPostedSerialiser::sizeGxsPostedVoteItem(RsGxsPostedVoteItem* item)
|
||||
{
|
||||
RsPostedVote& v = item->mVote;
|
||||
|
||||
uint32_t s = 8;
|
||||
s += 1; // for vote direction
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
uint32_t RsGxsPostedSerialiser::sizeGxsPostedGroupItem(RsGxsPostedGroupItem* item)
|
||||
{
|
||||
RsPostedGroup& g = item->mGroup;
|
||||
|
||||
uint32_t s = 8;
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsPostedSerialiser::serialiseGxsPostedPostItem(RsGxsPostedPostItem* item, void* data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsPostedPostItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize){
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem()()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsPhotoAlbumItem */
|
||||
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mPost.mLink);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mPost.mNotes);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsGxsPostedSerialiser::serialiseGxsPostedCommentItem(RsGxsPostedCommentItem* item, void* data, uint32_t *size)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedCommentItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsPostedCommentItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize){
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedCommentItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsPhotoAlbumItem */
|
||||
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mComment.mComment);
|
||||
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedCommentItem()() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedCommentItem()() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsGxsPostedSerialiser::serialiseGxsPostedVoteItem(RsGxsPostedVoteItem* item, void* data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedVoteItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsPostedVoteItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize){
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedVoteItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= setRawUInt8(data, tlvsize, &offset, item->mVote.mDirection);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedVoteItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedVoteItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsGxsPostedSerialiser::serialiseGxsPostedGroupItem(RsGxsPostedGroupItem* item, void* data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsPostedGroupItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize){
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsPhotoAlbumItem */
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsPostedPostItem* RsGxsPostedSerialiser::deserialiseGxsPostedPostItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_POSTED_POST_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsPostedPostItem* item = new RsGxsPostedPostItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->mPost.mLink);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->mPost.mNotes);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
RsGxsPostedCommentItem* RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem(void *data, uint32_t *size)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_POSTED_COMMENT_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsPostedCommentItem* item = new RsGxsPostedCommentItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->mComment.mComment);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
RsGxsPostedVoteItem* RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_POSTED_VOTE_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsPostedVoteItem* item = new RsGxsPostedVoteItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= getRawUInt8(data, rssize, &offset, &(item->mVote.mDirection));
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
RsGxsPostedGroupItem* RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_POSTED_VOTE_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsPostedGroupItem* item = new RsGxsPostedGroupItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
void RsGxsPostedPostItem::clear()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::ostream & RsGxsPostedPostItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
return out;
|
||||
}
|
||||
|
||||
void RsGxsPostedVoteItem::clear()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::ostream & RsGxsPostedVoteItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
return out;
|
||||
}
|
||||
|
||||
void RsGxsPostedCommentItem::clear()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::ostream & RsGxsPostedCommentItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
return out;
|
||||
}
|
||||
|
||||
void RsGxsPostedGroupItem::clear()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::ostream & RsGxsPostedGroupItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
return out;
|
||||
|
||||
}
|
103
libretroshare/src/serialiser/rsposteditems.h
Normal file
103
libretroshare/src/serialiser/rsposteditems.h
Normal file
|
@ -0,0 +1,103 @@
|
|||
#ifndef RSPOSTEDITEMS_H
|
||||
#define RSPOSTEDITEMS_H
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
#include "retroshare/rsposted.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_POSTED_GRP_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_POSTED_POST_ITEM = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_POSTED_VOTE_ITEM = 0x04;
|
||||
const uint8_t RS_PKT_SUBTYPE_POSTED_COMMENT_ITEM = 0x05;
|
||||
|
||||
class RsGxsPostedPostItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
RsGxsPostedPostItem() : RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_POSTED,
|
||||
RS_PKT_SUBTYPE_POSTED_POST_ITEM)
|
||||
{return ; }
|
||||
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
RsPostedPost mPost;
|
||||
};
|
||||
|
||||
class RsGxsPostedVoteItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
RsGxsPostedVoteItem() : RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_POSTED,
|
||||
RS_PKT_SUBTYPE_POSTED_VOTE_ITEM)
|
||||
{return ;}
|
||||
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
RsPostedVote mVote;
|
||||
};
|
||||
|
||||
class RsGxsPostedCommentItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
RsGxsPostedCommentItem() : RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_POSTED,
|
||||
RS_PKT_SUBTYPE_POSTED_COMMENT_ITEM)
|
||||
{ return; }
|
||||
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
RsPostedComment mComment;
|
||||
};
|
||||
|
||||
class RsGxsPostedGroupItem : public RsGxsGrpItem
|
||||
{
|
||||
public:
|
||||
RsGxsPostedGroupItem() : RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_POSTED,
|
||||
RS_PKT_SUBTYPE_POSTED_GRP_ITEM)
|
||||
{ return; }
|
||||
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
RsPostedGroup mGroup;
|
||||
};
|
||||
|
||||
class RsGxsPostedSerialiser : public RsSerialType
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsGxsPostedSerialiser()
|
||||
: RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_PHOTO)
|
||||
{ return; }
|
||||
|
||||
virtual ~RsGxsPostedSerialiser() { return; }
|
||||
|
||||
uint32_t size(RsItem *item);
|
||||
bool serialise(RsItem *item, void *data, uint32_t *size);
|
||||
RsItem* deserialise(void *data, uint32_t *size);
|
||||
|
||||
private:
|
||||
|
||||
uint32_t sizeGxsPostedPostItem(RsGxsPostedPostItem* item);
|
||||
bool serialiseGxsPostedPostItem(RsGxsPostedPostItem* item, void* data, uint32_t *size);
|
||||
RsGxsPostedPostItem* deserialiseGxsPostedPostItem(void *data, uint32_t *size);
|
||||
|
||||
uint32_t sizeGxsPostedCommentItem(RsGxsPostedCommentItem* item);
|
||||
bool serialiseGxsPostedCommentItem(RsGxsPostedCommentItem* item, void* data, uint32_t *size);
|
||||
RsGxsPostedCommentItem* deserialiseGxsPostedCommentItem(void *data, uint32_t *size);
|
||||
|
||||
uint32_t sizeGxsPostedVoteItem(RsGxsPostedVoteItem* item);
|
||||
bool serialiseGxsPostedVoteItem(RsGxsPostedVoteItem* item, void* data, uint32_t *size);
|
||||
RsGxsPostedVoteItem* deserialiseGxsPostedVoteItem(void *data, uint32_t *size);
|
||||
|
||||
uint32_t sizeGxsPostedGroupItem(RsGxsPostedGroupItem* item);
|
||||
bool serialiseGxsPostedGroupItem(RsGxsPostedGroupItem* item, void* data, uint32_t *size);
|
||||
RsGxsPostedGroupItem* deserialiseGxsPostedGroupItem(void *data, uint32_t *size);
|
||||
};
|
||||
|
||||
|
||||
#endif // RSPOSTEDITEMS_H
|
|
@ -65,6 +65,7 @@ const uint16_t RS_SERVICE_TYPE_STATUS = 0xf020;
|
|||
|
||||
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;
|
||||
|
||||
|
||||
/****************** BELOW ARE ONLY THEORETICAL (CAN BE CHANGED) *****/
|
||||
|
@ -107,13 +108,6 @@ const uint16_t RS_SERVICE_TYPE_DSDV = 0xf050;
|
|||
const uint16_t RS_SERVICE_TYPE_BWCTRL = 0xf060;
|
||||
|
||||
|
||||
/* New Cache Services */
|
||||
const uint16_t RS_SERVICE_TYPE_IDENTITY = 0xf100;
|
||||
const uint16_t RS_SERVICE_TYPE_PHOTO = 0xf101;
|
||||
const uint16_t RS_SERVICE_TYPE_WIKI = 0xf102;
|
||||
const uint16_t RS_SERVICE_TYPE_WIRE = 0xf103;
|
||||
const uint16_t RS_SERVICE_TYPE_FORUMSV2 = 0xf104;
|
||||
const uint16_t RS_SERVICE_TYPE_POSTED = 0xf105;
|
||||
|
||||
//const uint16_t RS_SERVICE_TYPE_DISTRIB = 0xf110;
|
||||
//const uint16_t RS_SERVICE_TYPE_FORUM = 0xf120;
|
||||
|
@ -133,9 +127,35 @@ const uint16_t RS_SERVICE_TYPE_GAME_QGO = 0xf212;
|
|||
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_TYPE_NXS = 0xf300;
|
||||
|
||||
const uint16_t RS_SERVICE_GXSV1_TYPE_GXSID = 0xf301;
|
||||
const uint16_t RS_SERVICE_GXSV1_TYPE_PHOTO = 0xf302;
|
||||
const uint16_t RS_SERVICE_GXSV1_TYPE_WIKI = 0xf303;
|
||||
const uint16_t RS_SERVICE_GXSV1_TYPE_WIRE = 0xf304;
|
||||
const uint16_t RS_SERVICE_GXSV1_TYPE_FORUMS = 0xf305;
|
||||
const uint16_t RS_SERVICE_GXSV1_TYPE_POSTED = 0xf306;
|
||||
const uint16_t RS_SERVICE_GXSV1_TYPE_CHANNELS = 0xf307;
|
||||
const uint16_t RS_SERVICE_GXSV1_TYPE_GXSCIRCLE = 0xf307;
|
||||
|
||||
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;
|
||||
|
||||
/* Example Versions (VEG) of New Cache Services */
|
||||
const uint16_t RS_SERVICE_VEG_TYPE_IDENTITY = 0xf320;
|
||||
const uint16_t RS_SERVICE_VEG_TYPE_PHOTO = 0xf321;
|
||||
const uint16_t RS_SERVICE_VEG_TYPE_WIKI = 0xf322;
|
||||
const uint16_t RS_SERVICE_VEG_TYPE_WIRE = 0xf323;
|
||||
const uint16_t RS_SERVICE_VEG_TYPE_FORUMS = 0xf324;
|
||||
const uint16_t RS_SERVICE_VEG_TYPE_POSTED = 0xf325;
|
||||
|
||||
/***************** IDS ALLOCATED FOR PLUGINS ******************/
|
||||
|
||||
|
|
|
@ -207,6 +207,8 @@ const uint16_t TLV_TYPE_SECURITYKEY = 0x1040;
|
|||
const uint16_t TLV_TYPE_SECURITYKEYSET= 0x1041;
|
||||
|
||||
const uint16_t TLV_TYPE_KEYSIGNATURE = 0x1050;
|
||||
const uint16_t TLV_TYPE_KEYSIGNATURESET = 0x1051;
|
||||
const uint16_t TLV_TYPE_KEYSIGNATURETYPE = 0x1052;
|
||||
|
||||
const uint16_t TLV_TYPE_IMAGE = 0x1060;
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
//#define TLV_DEBUG 1
|
||||
#define TLV_DEBUG 1
|
||||
|
||||
/************************************* RsTlvSecurityKey ************************************/
|
||||
|
||||
|
@ -322,7 +322,7 @@ bool RsTlvSecurityKeySet::GetTlv(void *data, uint32_t size, uint32_t *offset) /
|
|||
if (ok)
|
||||
{
|
||||
keys[key.keyId] = key;
|
||||
key.ShallowClear(); /* so that the Map can get control - should be ref counted*/
|
||||
key.TlvClear(); /* so that the Map can get control - should be ref counted*/
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -520,3 +520,170 @@ std::ostream &RsTlvKeySignature::print(std::ostream &out, uint16_t indent)
|
|||
return out;
|
||||
}
|
||||
|
||||
|
||||
/************************************* RsTlvKeySignatureSet ************************************/
|
||||
|
||||
RsTlvKeySignatureSet::RsTlvKeySignatureSet()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::ostream &RsTlvKeySignatureSet::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printBase(out, "RsTlvKeySignatureSet", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
|
||||
std::map<SignType, RsTlvKeySignature>::iterator mit = keySignSet.begin();
|
||||
|
||||
for(; mit != keySignSet.end(); mit++)
|
||||
{
|
||||
out << "SignType: " << mit->first << std::endl;
|
||||
RsTlvKeySignature& sign = mit->second;
|
||||
sign.print(out, indent);
|
||||
}
|
||||
|
||||
out << std::endl;
|
||||
|
||||
printEnd(out, "RsTlvKeySignatureSet", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
void RsTlvKeySignatureSet::TlvClear()
|
||||
{
|
||||
keySignSet.clear();
|
||||
}
|
||||
|
||||
bool RsTlvKeySignatureSet::SetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvKeySignatureSet::SetTlv() Failed not enough space";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
return false; /* not enough space */
|
||||
}
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* start at data[offset] */
|
||||
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_KEYSIGNATURESET , tlvsize);
|
||||
|
||||
|
||||
if(!keySignSet.empty())
|
||||
{
|
||||
std::map<SignType, RsTlvKeySignature>::iterator it;
|
||||
|
||||
for(it = keySignSet.begin(); it != keySignSet.end() ; ++it)
|
||||
{
|
||||
ok &= SetTlvUInt32(data, size, offset, TLV_TYPE_KEYSIGNATURETYPE, it->first);
|
||||
ok &= (it->second).SetTlv(data, size, offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsTlvKeySignatureSet::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_KEYSIGNATURESET) /* check type */
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
SignType sign_type = 0;
|
||||
|
||||
/* while there is TLV */
|
||||
while((*offset) + 2 < tlvend)
|
||||
{
|
||||
|
||||
/* get the next type */
|
||||
uint16_t tlvsubtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
SignType currType;
|
||||
|
||||
switch(tlvsubtype)
|
||||
{
|
||||
case TLV_TYPE_KEYSIGNATURE:
|
||||
{
|
||||
RsTlvKeySignature sign;
|
||||
ok &= sign.GetTlv(data, size, offset);
|
||||
if (ok)
|
||||
{
|
||||
keySignSet[currType] = sign;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TLV_TYPE_KEYSIGNATURETYPE:
|
||||
{
|
||||
ok = GetTlvUInt32(data, size, offset, TLV_TYPE_KEYSIGNATURETYPE, &sign_type);
|
||||
|
||||
if(ok)
|
||||
currType = sign_type;
|
||||
}
|
||||
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 << "RsTlvKeySignatureSet::GetTlv() Warning extra bytes at end of item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
*offset = tlvend;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
uint32_t RsTlvKeySignatureSet::TlvSize()
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; // header size
|
||||
std::map<SignType, RsTlvKeySignature>::iterator it;
|
||||
|
||||
for(it = keySignSet.begin(); it != keySignSet.end() ; ++it)
|
||||
{
|
||||
s += GetTlvUInt32Size(); // sign type
|
||||
s += it->second.TlvSize(); // signature
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ const uint32_t RSTLV_KEY_TYPE_SHARED = 0x0004;
|
|||
const uint32_t RSTLV_KEY_DISTRIB_PUBLIC = 0x0010;
|
||||
const uint32_t RSTLV_KEY_DISTRIB_PRIVATE = 0x0020;
|
||||
const uint32_t RSTLV_KEY_DISTRIB_ADMIN = 0x0040;
|
||||
const uint32_t RSTLV_KEY_DISTRIB_IDENTITY = 0x0080;
|
||||
|
||||
|
||||
class RsTlvSecurityKey: public RsTlvItem
|
||||
|
@ -98,6 +99,21 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
|||
// NO Certificates in Signatures... add as separate data type.
|
||||
};
|
||||
|
||||
typedef uint32_t SignType;
|
||||
|
||||
class RsTlvKeySignatureSet : public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvKeySignatureSet();
|
||||
virtual ~RsTlvKeySignatureSet() { 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::map<SignType, RsTlvKeySignature> keySignSet; // mandatory
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
580
libretroshare/src/serialiser/rswikiitems.cc
Normal file
580
libretroshare/src/serialiser/rswikiitems.cc
Normal file
|
@ -0,0 +1,580 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rswikiitems.cc
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2012 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2.1 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "rswikiitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#define GXSID_DEBUG 1
|
||||
|
||||
|
||||
uint32_t RsGxsWikiSerialiser::size(RsItem *item)
|
||||
{
|
||||
RsGxsWikiCollectionItem* grp_item = NULL;
|
||||
RsGxsWikiSnapshotItem* snap_item = NULL;
|
||||
RsGxsWikiCommentItem* com_item = NULL;
|
||||
|
||||
if((grp_item = dynamic_cast<RsGxsWikiCollectionItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsWikiCollectionItem(grp_item);
|
||||
}
|
||||
else if((snap_item = dynamic_cast<RsGxsWikiSnapshotItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsWikiSnapshotItem(snap_item);
|
||||
}
|
||||
else if((com_item = dynamic_cast<RsGxsWikiCommentItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsWikiCommentItem(com_item);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool RsGxsWikiSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
RsGxsWikiCollectionItem* grp_item = NULL;
|
||||
RsGxsWikiSnapshotItem* snap_item = NULL;
|
||||
RsGxsWikiCommentItem* com_item = NULL;
|
||||
|
||||
if((grp_item = dynamic_cast<RsGxsWikiCollectionItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsWikiCollectionItem(grp_item, data, size);
|
||||
}
|
||||
else if((snap_item = dynamic_cast<RsGxsWikiSnapshotItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsWikiSnapshotItem(snap_item, data, size);
|
||||
}
|
||||
else if((com_item = dynamic_cast<RsGxsWikiCommentItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsWikiCommentItem(com_item, data, size);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem* RsGxsWikiSerialiser::deserialise(void* data, uint32_t* size)
|
||||
{
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialise()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_WIKI != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
|
||||
case RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM:
|
||||
return deserialiseGxsWikiCollectionItem(data, size);
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM:
|
||||
return deserialiseGxsWikiSnapshotItem(data, size);
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM:
|
||||
return deserialiseGxsWikiCommentItem(data, size);
|
||||
break;
|
||||
default:
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialise(): unknown subtype";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
|
||||
void RsGxsWikiCollectionItem::clear()
|
||||
{
|
||||
collection.mDescription.clear();
|
||||
collection.mCategory.clear();
|
||||
collection.mHashTags.clear();
|
||||
}
|
||||
|
||||
std::ostream& RsGxsWikiCollectionItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsWikiCollectionItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Description: " << collection.mDescription << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "Category: " << collection.mCategory << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "HashTags: " << collection.mHashTags << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsWikiCollectionItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsWikiSerialiser::sizeGxsWikiCollectionItem(RsGxsWikiCollectionItem *item)
|
||||
{
|
||||
|
||||
const RsWikiCollection& collection = item->collection;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(collection.mDescription);
|
||||
s += GetTlvStringSize(collection.mCategory);
|
||||
s += GetTlvStringSize(collection.mHashTags);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem(RsGxsWikiCollectionItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsWikiCollectionItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsWikiCollectionItem */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->collection.mDescription);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->collection.mCategory);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->collection.mHashTags);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsWikiCollectionItem* RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_WIKI != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsWikiCollectionItem* item = new RsGxsWikiCollectionItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->collection.mDescription);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->collection.mCategory);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->collection.mHashTags);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
|
||||
void RsGxsWikiSnapshotItem::clear()
|
||||
{
|
||||
snapshot.mPage.clear();
|
||||
snapshot.mHashTags.clear();
|
||||
}
|
||||
|
||||
std::ostream& RsGxsWikiSnapshotItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsWikiSnapshotItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Page: " << snapshot.mPage << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "HashTags: " << snapshot.mHashTags << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsWikiSnapshotItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsWikiSerialiser::sizeGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *item)
|
||||
{
|
||||
|
||||
const RsWikiSnapshot& snapshot = item->snapshot;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(snapshot.mPage);
|
||||
s += GetTlvStringSize(snapshot.mHashTags);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsWikiSnapshotItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsWikiSnapshotItem */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->snapshot.mPage);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->snapshot.mHashTags);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsWikiSnapshotItem* RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_WIKI != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsWikiSnapshotItem* item = new RsGxsWikiSnapshotItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->snapshot.mPage);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->snapshot.mHashTags);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
|
||||
void RsGxsWikiCommentItem::clear()
|
||||
{
|
||||
comment.mComment.clear();
|
||||
}
|
||||
|
||||
std::ostream& RsGxsWikiCommentItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsWikiCommentItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Comment: " << comment.mComment << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsWikiCommentItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsWikiSerialiser::sizeGxsWikiCommentItem(RsGxsWikiCommentItem *item)
|
||||
{
|
||||
|
||||
const RsWikiComment& comment = item->comment;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(comment.mComment);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsWikiSerialiser::serialiseGxsWikiCommentItem(RsGxsWikiCommentItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsWikiCommentItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsWikiCommentItem */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->comment.mComment);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsWikiCommentItem* RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_WIKI != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsWikiCommentItem* item = new RsGxsWikiCommentItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->comment.mComment);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
112
libretroshare/src/serialiser/rswikiitems.h
Normal file
112
libretroshare/src/serialiser/rswikiitems.h
Normal file
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rswikiitems.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2012 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2.1 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RS_WIKI_ITEMS_H
|
||||
#define RS_WIKI_ITEMS_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
#include "retroshare/rswiki.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM = 0x04;
|
||||
|
||||
class RsGxsWikiCollectionItem : public RsGxsGrpItem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsGxsWikiCollectionItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_WIKI,
|
||||
RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM) { return;}
|
||||
virtual ~RsGxsWikiCollectionItem() { return;}
|
||||
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
|
||||
RsWikiCollection collection;
|
||||
};
|
||||
|
||||
class RsGxsWikiSnapshotItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsWikiSnapshotItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_WIKI,
|
||||
RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM) {return; }
|
||||
virtual ~RsGxsWikiSnapshotItem() { return;}
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
RsWikiSnapshot snapshot;
|
||||
};
|
||||
|
||||
class RsGxsWikiCommentItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsWikiCommentItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_WIKI,
|
||||
RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM) { return; }
|
||||
virtual ~RsGxsWikiCommentItem() { return; }
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
RsWikiComment comment;
|
||||
|
||||
};
|
||||
|
||||
class RsGxsWikiSerialiser : public RsSerialType
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsWikiSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_WIKI)
|
||||
{ return; }
|
||||
virtual ~RsGxsWikiSerialiser() { return; }
|
||||
|
||||
uint32_t size(RsItem *item);
|
||||
bool serialise (RsItem *item, void *data, uint32_t *size);
|
||||
RsItem * deserialise(void *data, uint32_t *size);
|
||||
|
||||
private:
|
||||
|
||||
uint32_t sizeGxsWikiCollectionItem(RsGxsWikiCollectionItem *item);
|
||||
bool serialiseGxsWikiCollectionItem (RsGxsWikiCollectionItem *item, void *data, uint32_t *size);
|
||||
RsGxsWikiCollectionItem * deserialiseGxsWikiCollectionItem(void *data, uint32_t *size);
|
||||
|
||||
uint32_t sizeGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *item);
|
||||
bool serialiseGxsWikiSnapshotItem (RsGxsWikiSnapshotItem *item, void *data, uint32_t *size);
|
||||
RsGxsWikiSnapshotItem * deserialiseGxsWikiSnapshotItem(void *data, uint32_t *size);
|
||||
|
||||
uint32_t sizeGxsWikiCommentItem(RsGxsWikiCommentItem *item);
|
||||
bool serialiseGxsWikiCommentItem (RsGxsWikiCommentItem *item, void *data, uint32_t *size);
|
||||
RsGxsWikiCommentItem * deserialiseGxsWikiCommentItem(void *data, uint32_t *size);
|
||||
|
||||
};
|
||||
|
||||
#endif /* RS_WIKI_ITEMS_H */
|
408
libretroshare/src/serialiser/rswireitems.cc
Normal file
408
libretroshare/src/serialiser/rswireitems.cc
Normal file
|
@ -0,0 +1,408 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rswikiitems.cc
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2012 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2.1 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "rswireitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#define WIRE_DEBUG 1
|
||||
|
||||
|
||||
uint32_t RsGxsWireSerialiser::size(RsItem *item)
|
||||
{
|
||||
RsGxsWireGroupItem* grp_item = NULL;
|
||||
RsGxsWirePulseItem* snap_item = NULL;
|
||||
|
||||
if((grp_item = dynamic_cast<RsGxsWireGroupItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsWireGroupItem(grp_item);
|
||||
}
|
||||
else if((snap_item = dynamic_cast<RsGxsWirePulseItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsWirePulseItem(snap_item);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool RsGxsWireSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
RsGxsWireGroupItem* grp_item = NULL;
|
||||
RsGxsWirePulseItem* snap_item = NULL;
|
||||
|
||||
if((grp_item = dynamic_cast<RsGxsWireGroupItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsWireGroupItem(grp_item, data, size);
|
||||
}
|
||||
else if((snap_item = dynamic_cast<RsGxsWirePulseItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsWirePulseItem(snap_item, data, size);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem* RsGxsWireSerialiser::deserialise(void* data, uint32_t* size)
|
||||
{
|
||||
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialise()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_WIRE != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
|
||||
case RS_PKT_SUBTYPE_WIRE_GROUP_ITEM:
|
||||
return deserialiseGxsWireGroupItem(data, size);
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_WIRE_PULSE_ITEM:
|
||||
return deserialiseGxsWirePulseItem(data, size);
|
||||
break;
|
||||
default:
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialise(): unknown subtype";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
|
||||
void RsGxsWireGroupItem::clear()
|
||||
{
|
||||
group.mDescription.clear();
|
||||
}
|
||||
|
||||
std::ostream& RsGxsWireGroupItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsWireGroupItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Description: " << group.mDescription << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsWireGroupItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsWireSerialiser::sizeGxsWireGroupItem(RsGxsWireGroupItem *item)
|
||||
{
|
||||
|
||||
const RsWireGroup& group = item->group;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(group.mDescription);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsWireSerialiser::serialiseGxsWireGroupItem(RsGxsWireGroupItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsWireGroupItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize)
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsWireGroupItem */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->group.mDescription);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef WIRE_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsWireGroupItem* RsGxsWireSerialiser::deserialiseGxsWireGroupItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_WIRE != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_WIRE_GROUP_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsWireGroupItem* item = new RsGxsWireGroupItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->group.mDescription);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
|
||||
void RsGxsWirePulseItem::clear()
|
||||
{
|
||||
pulse.mPulseText.clear();
|
||||
pulse.mHashTags.clear();
|
||||
}
|
||||
|
||||
std::ostream& RsGxsWirePulseItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsWirePulseItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Page: " << pulse.mPulseText << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "HashTags: " << pulse.mHashTags << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsWirePulseItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsWireSerialiser::sizeGxsWirePulseItem(RsGxsWirePulseItem *item)
|
||||
{
|
||||
|
||||
const RsWirePulse& pulse = item->pulse;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(pulse.mPulseText);
|
||||
s += GetTlvStringSize(pulse.mHashTags);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsWireSerialiser::serialiseGxsWirePulseItem(RsGxsWirePulseItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsWirePulseItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize)
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsWirePulseItem */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->pulse.mPulseText);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->pulse.mHashTags);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef WIRE_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsWirePulseItem* RsGxsWireSerialiser::deserialiseGxsWirePulseItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_WIRE != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_WIRE_PULSE_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsWirePulseItem* item = new RsGxsWirePulseItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->pulse.mPulseText);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->pulse.mHashTags);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
93
libretroshare/src/serialiser/rswireitems.h
Normal file
93
libretroshare/src/serialiser/rswireitems.h
Normal file
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rswireitems.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2012 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2.1 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RS_WIRE_ITEMS_H
|
||||
#define RS_WIRE_ITEMS_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
#include "retroshare/rswire.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_WIRE_GROUP_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_WIRE_PULSE_ITEM = 0x03;
|
||||
|
||||
class RsGxsWireGroupItem : public RsGxsGrpItem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsGxsWireGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_WIRE,
|
||||
RS_PKT_SUBTYPE_WIRE_GROUP_ITEM) { return;}
|
||||
virtual ~RsGxsWireGroupItem() { return;}
|
||||
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
|
||||
RsWireGroup group;
|
||||
};
|
||||
|
||||
class RsGxsWirePulseItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsWirePulseItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_WIRE,
|
||||
RS_PKT_SUBTYPE_WIRE_PULSE_ITEM) {return; }
|
||||
virtual ~RsGxsWirePulseItem() { return;}
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
RsWirePulse pulse;
|
||||
};
|
||||
|
||||
class RsGxsWireSerialiser : public RsSerialType
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsWireSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_WIRE)
|
||||
{ return; }
|
||||
virtual ~RsGxsWireSerialiser() { return; }
|
||||
|
||||
uint32_t size(RsItem *item);
|
||||
bool serialise (RsItem *item, void *data, uint32_t *size);
|
||||
RsItem * deserialise(void *data, uint32_t *size);
|
||||
|
||||
private:
|
||||
|
||||
uint32_t sizeGxsWireGroupItem(RsGxsWireGroupItem *item);
|
||||
bool serialiseGxsWireGroupItem (RsGxsWireGroupItem *item, void *data, uint32_t *size);
|
||||
RsGxsWireGroupItem * deserialiseGxsWireGroupItem(void *data, uint32_t *size);
|
||||
|
||||
uint32_t sizeGxsWirePulseItem(RsGxsWirePulseItem *item);
|
||||
bool serialiseGxsWirePulseItem (RsGxsWirePulseItem *item, void *data, uint32_t *size);
|
||||
RsGxsWirePulseItem * deserialiseGxsWirePulseItem(void *data, uint32_t *size);
|
||||
};
|
||||
|
||||
#endif /* RS_WIKI_ITEMS_H */
|
Loading…
Add table
Add a link
Reference in a new issue