mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-04-29 11:26:09 -04:00
switched rsphotoitems to new serialization
This commit is contained in:
parent
d3c960e4e7
commit
634efb6142
@ -14,6 +14,7 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
#include <retroshare/rstypes.h>
|
#include <retroshare/rstypes.h>
|
||||||
|
#include <retroshare/rsids.h>
|
||||||
|
|
||||||
typedef GXSGroupId RsGxsGroupId;
|
typedef GXSGroupId RsGxsGroupId;
|
||||||
typedef Sha1CheckSum RsGxsMessageId;
|
typedef Sha1CheckSum RsGxsMessageId;
|
||||||
|
@ -33,6 +33,22 @@
|
|||||||
#define GXS_PHOTO_SERIAL_DEBUG
|
#define GXS_PHOTO_SERIAL_DEBUG
|
||||||
|
|
||||||
|
|
||||||
|
virtual RsItem *create_item(uint16_t service, uint8_t item_sub_id) const
|
||||||
|
{
|
||||||
|
if(service != RS_SERVICE_GXS_TYPE_PHOTO)
|
||||||
|
return NULL ;
|
||||||
|
|
||||||
|
switch(item_sub_id)
|
||||||
|
{
|
||||||
|
case RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM: return new RsGxsPhotoCommentItem() ;
|
||||||
|
case RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM: return new RsGxsPhotoAlbumItem() ;
|
||||||
|
case RS_PKT_SUBTYPE_PHOTO_ITEM: return new RsGxsPhotoPhotoItem() ;
|
||||||
|
default:
|
||||||
|
return NULL ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef TO_REMOVE
|
||||||
uint32_t RsGxsPhotoSerialiser::size(RsItem* item)
|
uint32_t RsGxsPhotoSerialiser::size(RsItem* item)
|
||||||
{
|
{
|
||||||
RsGxsPhotoPhotoItem* ppItem = NULL;
|
RsGxsPhotoPhotoItem* ppItem = NULL;
|
||||||
@ -161,7 +177,27 @@ uint32_t RsGxsPhotoSerialiser::sizeGxsPhotoCommentItem(RsGxsPhotoCommentItem
|
|||||||
return s;
|
return s;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void RsGxsPhotoAlbumItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||||
|
{
|
||||||
|
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_CAPTION, album.mCaption, "mCaption");
|
||||||
|
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_CATEGORY, album.mCategory, "mCategory");
|
||||||
|
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR, album.mDescription, "mDescription");
|
||||||
|
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG, album.mHashTags, "mHashTags");
|
||||||
|
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG, album.mOther, "mOther");
|
||||||
|
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_PATH, album.mPhotoPath, "mPhotoPath");
|
||||||
|
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_NAME, album.mPhotographer, "mPhotographer");
|
||||||
|
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DATE, album.mWhen, "mWhen");
|
||||||
|
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_LOCATION, album.mWhere, "mWhere");
|
||||||
|
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_PIC_TYPE, album.mThumbnail.type,"mThumbnail.type");
|
||||||
|
|
||||||
|
RsTlvBinaryDataRef b(RS_SERVICE_GXS_TYPE_PHOTO, album.mThumbnail.data,album.mThumbnail.size);
|
||||||
|
|
||||||
|
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,b,"thumbnail binary data") ;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef TO_REMOVE
|
||||||
bool RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem(RsGxsPhotoAlbumItem* item, void* data,
|
bool RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem(RsGxsPhotoAlbumItem* item, void* data,
|
||||||
uint32_t* size)
|
uint32_t* size)
|
||||||
{
|
{
|
||||||
@ -326,7 +362,25 @@ uint32_t RsGxsPhotoSerialiser::sizeGxsPhotoPhotoItem(RsGxsPhotoPhotoItem* item)
|
|||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void RsGxsPhotoPhotoItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||||
|
{
|
||||||
|
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_CAPTION, photo.mCaption);
|
||||||
|
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_CATEGORY, photo.mCategory);
|
||||||
|
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_DESCR, photo.mDescription);
|
||||||
|
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_HASH_TAG, photo.mHashTags);
|
||||||
|
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_MSG, photo.mOther);
|
||||||
|
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_PIC_AUTH, photo.mPhotographer);
|
||||||
|
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_DATE, photo.mWhen);
|
||||||
|
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_LOCATION, photo.mWhere);
|
||||||
|
RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_PIC_TYPE, photo.mThumbnail.type);
|
||||||
|
|
||||||
|
RsTlvBinaryDataRef b(RS_SERVICE_GXS_TYPE_PHOTO,photo.mThumbnail.data, photo.mThumbnail.size);
|
||||||
|
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx, b, "mThumbnail") ;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef TO_REMOVE
|
||||||
bool RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem(RsGxsPhotoPhotoItem* item, void* data,
|
bool RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem(RsGxsPhotoPhotoItem* item, void* data,
|
||||||
uint32_t* size)
|
uint32_t* size)
|
||||||
{
|
{
|
||||||
@ -468,8 +522,15 @@ RsGxsPhotoPhotoItem* RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem(void* da
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void RsGxsPhotoCommentItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||||
|
{
|
||||||
|
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_COMMENT,comment.mComment,"mComment");
|
||||||
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,comment.mCommentFlag,"mCommentFlag");
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef TO_REMOVE
|
||||||
bool RsGxsPhotoSerialiser::serialiseGxsPhotoCommentItem (RsGxsPhotoCommentItem *item, void *data, uint32_t *size)
|
bool RsGxsPhotoSerialiser::serialiseGxsPhotoCommentItem (RsGxsPhotoCommentItem *item, void *data, uint32_t *size)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -586,6 +647,7 @@ RsGxsPhotoCommentItem * RsGxsPhotoSerialiser::deserialiseGxsPhotoCommentItem(
|
|||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void RsGxsPhotoAlbumItem::clear()
|
void RsGxsPhotoAlbumItem::clear()
|
||||||
{
|
{
|
||||||
@ -607,6 +669,7 @@ void RsGxsPhotoCommentItem::clear()
|
|||||||
comment.mCommentFlag = 0;
|
comment.mCommentFlag = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TO_REMOVE
|
||||||
std::ostream& RsGxsPhotoCommentItem::print(std::ostream& out, uint16_t indent)
|
std::ostream& RsGxsPhotoCommentItem::print(std::ostream& out, uint16_t indent)
|
||||||
{
|
{
|
||||||
printRsItemBase(out, "RsGxsPhotoCommentItem", indent);
|
printRsItemBase(out, "RsGxsPhotoCommentItem", indent);
|
||||||
@ -628,6 +691,19 @@ std::ostream& RsGxsPhotoAlbumItem::print(std::ostream& out, uint16_t indent)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
void RsGxsPhotoPhotoItem::clear()
|
void RsGxsPhotoPhotoItem::clear()
|
||||||
{
|
{
|
||||||
photo.mCaption.clear();
|
photo.mCaption.clear();
|
||||||
@ -640,14 +716,3 @@ void RsGxsPhotoPhotoItem::clear()
|
|||||||
photo.mWhere.clear();
|
photo.mWhere.clear();
|
||||||
photo.mThumbnail.deleteImage();
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -29,9 +29,11 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "rsitems/rsserviceids.h"
|
#include "rsitems/rsserviceids.h"
|
||||||
#include "serialiser/rsserial.h"
|
#include "rsitems/rsgxsitems.h"
|
||||||
|
|
||||||
|
#include "serialiser/rsserial.h"
|
||||||
|
#include "serialization/rsserializer.h"
|
||||||
|
|
||||||
#include "rsgxsitems.h"
|
|
||||||
#include "retroshare/rsphoto.h"
|
#include "retroshare/rsphoto.h"
|
||||||
|
|
||||||
const uint8_t RS_PKT_SUBTYPE_PHOTO_ITEM = 0x02;
|
const uint8_t RS_PKT_SUBTYPE_PHOTO_ITEM = 0x02;
|
||||||
@ -50,6 +52,7 @@ public:
|
|||||||
void clear();
|
void clear();
|
||||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||||
|
|
||||||
|
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||||
|
|
||||||
RsPhotoAlbum album;
|
RsPhotoAlbum album;
|
||||||
};
|
};
|
||||||
@ -58,11 +61,12 @@ class RsGxsPhotoPhotoItem : public RsGxsMsgItem
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RsGxsPhotoPhotoItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_PHOTO,
|
RsGxsPhotoPhotoItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_PHOTO, RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM) {}
|
||||||
RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM) {return; }
|
virtual ~RsGxsPhotoPhotoItem() {}
|
||||||
virtual ~RsGxsPhotoPhotoItem() { return;}
|
|
||||||
void clear();
|
void clear();
|
||||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
|
||||||
|
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||||
|
|
||||||
RsPhotoPhoto photo;
|
RsPhotoPhoto photo;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -70,43 +74,23 @@ class RsGxsPhotoCommentItem : public RsGxsMsgItem
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RsGxsPhotoCommentItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_PHOTO,
|
RsGxsPhotoCommentItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_PHOTO, RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM) {}
|
||||||
RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM) { return; }
|
virtual ~RsGxsPhotoCommentItem() {}
|
||||||
virtual ~RsGxsPhotoCommentItem() { return; }
|
|
||||||
void clear();
|
void clear();
|
||||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
|
||||||
|
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||||
|
|
||||||
RsPhotoComment comment;
|
RsPhotoComment comment;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class RsGxsPhotoSerialiser : public RsSerialType
|
class RsGxsPhotoSerialiser : public RsServiceSerializer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RsGxsPhotoSerialiser()
|
RsGxsPhotoSerialiser() :RsServiceSerializer(RS_SERVICE_GXS_TYPE_PHOTO) {}
|
||||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_PHOTO)
|
virtual ~RsGxsPhotoSerialiser() {}
|
||||||
{ 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);
|
|
||||||
|
|
||||||
uint32_t sizeGxsPhotoCommentItem(RsGxsPhotoCommentItem *item);
|
|
||||||
bool serialiseGxsPhotoCommentItem (RsGxsPhotoCommentItem *item, void *data, uint32_t *size);
|
|
||||||
RsGxsPhotoCommentItem * deserialiseGxsPhotoCommentItem(void *data, uint32_t *size);
|
|
||||||
|
|
||||||
|
virtual RsItem *create_item(uint16_t service, uint8_t item_sub_id) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* RSPHOTOV2ITEMS_H_ */
|
#endif /* RSPHOTOV2ITEMS_H_ */
|
||||||
|
@ -218,5 +218,89 @@ std::ostream &RsTlvBinaryData::print(std::ostream &out, uint16_t indent) const
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RsTlvBinaryDataRef::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||||
|
{
|
||||||
|
/* must check sizes */
|
||||||
|
uint32_t tlvsize = TlvSize();
|
||||||
|
uint32_t tlvend = *offset + tlvsize;
|
||||||
|
|
||||||
|
if (size < tlvend)
|
||||||
|
return false; /* not enough space */
|
||||||
|
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
/* start at data[offset] */
|
||||||
|
ok &= SetTlvBase(data, tlvend, offset, tlvtype, tlvsize);
|
||||||
|
|
||||||
|
/* add mandatory data */
|
||||||
|
|
||||||
|
// Warning: this is actually not an error if bin_len=0, as it does not
|
||||||
|
// corrupt the packet structure. We thus still return true in this case.
|
||||||
|
//
|
||||||
|
if (mDataRef != NULL && mSizeRef > 0)
|
||||||
|
{
|
||||||
|
memcpy(&(((uint8_t *) data)[*offset]), mDataRef, mSizeRef);
|
||||||
|
*offset += mSizeRef;
|
||||||
|
}
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
bool RsTlvBinaryDataRef::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||||
|
{
|
||||||
|
if (size < *offset + TLV_HEADER_SIZE)
|
||||||
|
{
|
||||||
|
return false; /* not enough space to get the header */
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t tlvtype_in = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||||
|
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
|
||||||
|
uint32_t tlvend = *offset + tlvsize;
|
||||||
|
|
||||||
|
if (size < tlvend) /* check size */
|
||||||
|
return false; /* not enough space */
|
||||||
|
|
||||||
|
if (tlvsize < TLV_HEADER_SIZE)
|
||||||
|
return false; /* bad tlv size */
|
||||||
|
|
||||||
|
if (tlvtype != tlvtype_in) /* check type */
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* skip the header */
|
||||||
|
(*offset) += TLV_HEADER_SIZE;
|
||||||
|
|
||||||
|
mDataRef = (uint8_t*)rs_malloc(tlvsize - TLV_HEADER_SIZE) ;
|
||||||
|
|
||||||
|
if(mDataRef == NULL)
|
||||||
|
return false ;
|
||||||
|
|
||||||
|
mSizeRef = tlvsize - TLV_HEADER_SIZE;
|
||||||
|
|
||||||
|
memcpy(mDataRef,&(((uint8_t *) data)[*offset]), tlvsize - TLV_HEADER_SIZE);
|
||||||
|
*offset += mSizeRef;
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* NB: extra components could be added (for future expansion of the type).
|
||||||
|
* or be present (if this code is reading an extended version).
|
||||||
|
*
|
||||||
|
* We must chew up the extra characters to conform with TLV specifications
|
||||||
|
***************************************************************************/
|
||||||
|
if (*offset != tlvend)
|
||||||
|
{
|
||||||
|
#ifdef TLV_DEBUG
|
||||||
|
std::cerr << "RsTlvBinaryData::GetTlv() Warning extra bytes at end of item";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
*offset = tlvend;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t RsTlvBinaryDataRef::TlvSize() const
|
||||||
|
{
|
||||||
|
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||||
|
|
||||||
|
if (mDataRef != NULL)
|
||||||
|
s += mSizeRef; // len is the size of data
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
@ -64,4 +64,23 @@ public:
|
|||||||
void *bin_data; /// mandatory
|
void *bin_data; /// mandatory
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// This class is mainly used for on-the-fly serialization
|
||||||
|
|
||||||
|
class RsTlvBinaryDataRef: public RsTlvItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RsTlvBinaryDataRef(uint16_t type,uint8_t *& data_ref,uint32_t& size_ref) : mDataRef(data_ref),mSizeRef(size_ref),tlvtype(type) {}
|
||||||
|
virtual ~RsTlvBinaryDataRef() {}
|
||||||
|
|
||||||
|
virtual uint32_t TlvSize() const;
|
||||||
|
virtual void TlvClear(){}
|
||||||
|
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||||
|
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||||
|
|
||||||
|
uint8_t *& mDataRef ;
|
||||||
|
uint32_t & mSizeRef ;
|
||||||
|
uint16_t tlvtype ;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user