mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-20 04:14:27 -04:00
moved msgitems to rsitems/
This commit is contained in:
parent
fc82b20833
commit
5071c4bc7f
2 changed files with 0 additions and 0 deletions
181
libretroshare/src/rsitems/rsmsgitems.cc
Normal file
181
libretroshare/src/rsitems/rsmsgitems.cc
Normal file
|
@ -0,0 +1,181 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsbaseitems.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdexcept>
|
||||
#include <time.h>
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rsmsgitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
RsItem *RsMsgSerialiser::create_item(uint16_t service,uint8_t type) const
|
||||
{
|
||||
if(service != RS_SERVICE_TYPE_MSG)
|
||||
return NULL ;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_DEFAULT : return new RsMsgItem() ; //= 0x01;
|
||||
case RS_PKT_SUBTYPE_MSG_TAG_TYPE : return new RsMsgTagType() ; //= 0x03;
|
||||
case RS_PKT_SUBTYPE_MSG_TAGS : return new RsMsgTags() ; //= 0x04;
|
||||
case RS_PKT_SUBTYPE_MSG_SRC_TAG : return new RsMsgSrcId(); //= 0x05;
|
||||
case RS_PKT_SUBTYPE_MSG_PARENT_TAG : return new RsMsgParentId() ; //= 0x06;
|
||||
case RS_PKT_SUBTYPE_MSG_INVITE : return new RsPublicMsgInviteConfigItem(); //= 0x07;
|
||||
case RS_PKT_SUBTYPE_MSG_GROUTER_MAP : return new RsMsgGRouterMap(); //= 0x08;
|
||||
case RS_PKT_SUBTYPE_MSG_DISTANT_MSG_MAP : return new RsMsgDistantMessagesHashMap();//= 0x09;
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
void RsMsgItem::clear()
|
||||
{
|
||||
msgId = 0;
|
||||
msgFlags = 0;
|
||||
sendTime = 0;
|
||||
recvTime = 0;
|
||||
subject.clear();
|
||||
message.clear();
|
||||
|
||||
rspeerid_msgto.TlvClear();
|
||||
rspeerid_msgcc.TlvClear();
|
||||
rspeerid_msgbcc.TlvClear();
|
||||
|
||||
rsgxsid_msgto.TlvClear();
|
||||
rsgxsid_msgcc.TlvClear();
|
||||
rsgxsid_msgbcc.TlvClear();
|
||||
|
||||
attachment.TlvClear();
|
||||
}
|
||||
|
||||
void RsPublicMsgInviteConfigItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_SHA1,hash,"hash") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,(uint32_t&)time_stamp,"time_stamp") ;
|
||||
}
|
||||
void RsMsgTagType::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_NAME,text,"text") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,rgb_color,"rgb_color") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,tagId,"tagId") ;
|
||||
}
|
||||
|
||||
void RsMsgTags::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgId,"msgId") ;
|
||||
|
||||
#warning this is not the correct way to serialise here. We should directly call serial_process<std::vector<uint32_t> >() but for backward compatibility, we cannot
|
||||
|
||||
if(j == RsItem::DESERIALIZE)
|
||||
while(ctx.mOffset < ctx.mSize)
|
||||
{
|
||||
uint32_t n ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,n,"tagIds element") ;
|
||||
tagIds.push_back(n) ;
|
||||
}
|
||||
else
|
||||
for(std::list<uint32_t>::iterator it(tagIds.begin());it!=tagIds.end();++it)
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,*it,"tagIds element") ;
|
||||
}
|
||||
|
||||
void RsMsgSrcId::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgId,"msgId") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,srcId,"srcId") ;
|
||||
}
|
||||
|
||||
void RsMsgGRouterMap::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,ongoing_msgs,"ongoing_msgs") ;
|
||||
}
|
||||
|
||||
void RsMsgGRouterMap::clear()
|
||||
{
|
||||
ongoing_msgs.clear() ;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void RsMsgDistantMessagesHashMap::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,hash_map,"hash_map") ;
|
||||
}
|
||||
|
||||
void RsMsgParentId::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgId,"msgId") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgParentId,"msgParentId") ;
|
||||
}
|
||||
|
||||
void RsMsgItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgFlags,"msgFlags");
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,sendTime,"sendTime");
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,recvTime,"recvTime");
|
||||
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_SUBJECT,subject,"subject");
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_MSG,message,"message");
|
||||
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,rspeerid_msgto,"rspeerid_msgto");
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,rspeerid_msgcc,"rspeerid_msgcc");
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,rspeerid_msgbcc,"rspeerid_msgbcc");
|
||||
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,rsgxsid_msgto,"rsgxsid_msgto");
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,rsgxsid_msgcc,"rsgxsid_msgcc");
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,rsgxsid_msgbcc,"rsgxsid_msgbcc");
|
||||
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,attachment,"attachment");
|
||||
|
||||
if(ctx.mFlags & RsSerializer::SERIALIZATION_FLAG_CONFIG)
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgId,"msgId");
|
||||
}
|
||||
|
||||
void RsMsgTagType::clear()
|
||||
{
|
||||
text.clear();
|
||||
tagId = 0;
|
||||
rgb_color = 0;
|
||||
}
|
||||
|
||||
void RsPublicMsgInviteConfigItem::clear()
|
||||
{
|
||||
hash.clear() ;
|
||||
time_stamp = 0 ;
|
||||
}
|
||||
void RsMsgTags::clear()
|
||||
{
|
||||
msgId = 0;
|
||||
tagIds.clear();
|
||||
}
|
||||
|
253
libretroshare/src/rsitems/rsmsgitems.h
Normal file
253
libretroshare/src/rsitems/rsmsgitems.h
Normal file
|
@ -0,0 +1,253 @@
|
|||
#ifndef RS_MSG_ITEMS_H
|
||||
#define RS_MSG_ITEMS_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsmsgitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "serialiser/rstlvfileitem.h"
|
||||
#include "grouter/grouteritems.h"
|
||||
|
||||
#if 0
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvfileitem.h"
|
||||
#endif
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
// for defining tags themselves and msg tags
|
||||
const uint8_t RS_PKT_SUBTYPE_MSG_TAG_TYPE = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_MSG_TAGS = 0x04;
|
||||
const uint8_t RS_PKT_SUBTYPE_MSG_SRC_TAG = 0x05;
|
||||
const uint8_t RS_PKT_SUBTYPE_MSG_PARENT_TAG = 0x06;
|
||||
const uint8_t RS_PKT_SUBTYPE_MSG_INVITE = 0x07;
|
||||
const uint8_t RS_PKT_SUBTYPE_MSG_GROUTER_MAP = 0x08;
|
||||
const uint8_t RS_PKT_SUBTYPE_MSG_DISTANT_MSG_MAP = 0x09;
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
const uint32_t RS_MSG_FLAGS_OUTGOING = 0x00000001;
|
||||
const uint32_t RS_MSG_FLAGS_PENDING = 0x00000002;
|
||||
const uint32_t RS_MSG_FLAGS_DRAFT = 0x00000004;
|
||||
const uint32_t RS_MSG_FLAGS_NEW = 0x00000010;
|
||||
const uint32_t RS_MSG_FLAGS_TRASH = 0x00000020;
|
||||
const uint32_t RS_MSG_FLAGS_UNREAD_BY_USER = 0x00000040;
|
||||
const uint32_t RS_MSG_FLAGS_REPLIED = 0x00000080;
|
||||
const uint32_t RS_MSG_FLAGS_FORWARDED = 0x00000100;
|
||||
const uint32_t RS_MSG_FLAGS_STAR = 0x00000200;
|
||||
const uint32_t RS_MSG_FLAGS_PARTIAL = 0x00000400;
|
||||
const uint32_t RS_MSG_FLAGS_USER_REQUEST = 0x00000800;
|
||||
const uint32_t RS_MSG_FLAGS_FRIEND_RECOMMENDATION = 0x00001000;
|
||||
const uint32_t RS_MSG_FLAGS_RETURN_RECEPT = 0x00002000;
|
||||
const uint32_t RS_MSG_FLAGS_ENCRYPTED = 0x00004000;
|
||||
const uint32_t RS_MSG_FLAGS_DISTANT = 0x00008000;
|
||||
const uint32_t RS_MSG_FLAGS_SIGNATURE_CHECKS = 0x00010000;
|
||||
const uint32_t RS_MSG_FLAGS_SIGNED = 0x00020000;
|
||||
const uint32_t RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES = 0x00040000;
|
||||
const uint32_t RS_MSG_FLAGS_DECRYPTED = 0x00080000;
|
||||
const uint32_t RS_MSG_FLAGS_ROUTED = 0x00100000;
|
||||
const uint32_t RS_MSG_FLAGS_PUBLISH_KEY = 0x00200000;
|
||||
|
||||
const uint32_t RS_MSG_FLAGS_SYSTEM = RS_MSG_FLAGS_USER_REQUEST | RS_MSG_FLAGS_FRIEND_RECOMMENDATION | RS_MSG_FLAGS_PUBLISH_KEY;
|
||||
|
||||
class RsMessageItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsMessageItem(uint8_t msg_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_MSG,msg_subtype)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_MSG_ITEM) ;
|
||||
}
|
||||
|
||||
virtual ~RsMessageItem() {}
|
||||
virtual void clear() {}
|
||||
};
|
||||
|
||||
|
||||
class RsMsgItem: public RsMessageItem
|
||||
{
|
||||
public:
|
||||
RsMsgItem() :RsMessageItem(RS_PKT_SUBTYPE_DEFAULT) {}
|
||||
|
||||
virtual ~RsMsgItem() {}
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */);
|
||||
|
||||
// ----------- Specific fields ------------- //
|
||||
|
||||
uint32_t msgFlags;
|
||||
uint32_t msgId;
|
||||
|
||||
uint32_t sendTime;
|
||||
uint32_t recvTime;
|
||||
|
||||
std::string subject;
|
||||
std::string message;
|
||||
|
||||
RsTlvPeerIdSet rspeerid_msgto;
|
||||
RsTlvPeerIdSet rspeerid_msgcc;
|
||||
RsTlvPeerIdSet rspeerid_msgbcc;
|
||||
|
||||
RsTlvGxsIdSet rsgxsid_msgto;
|
||||
RsTlvGxsIdSet rsgxsid_msgcc;
|
||||
RsTlvGxsIdSet rsgxsid_msgbcc;
|
||||
|
||||
RsTlvFileSet attachment;
|
||||
};
|
||||
|
||||
class RsMsgTagType : public RsMessageItem
|
||||
{
|
||||
public:
|
||||
RsMsgTagType() :RsMessageItem(RS_PKT_SUBTYPE_MSG_TAG_TYPE) {}
|
||||
|
||||
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */);
|
||||
|
||||
virtual ~RsMsgTagType() {}
|
||||
virtual void clear();
|
||||
|
||||
// ----------- Specific fields ------------- //
|
||||
//
|
||||
std::string text;
|
||||
uint32_t rgb_color;
|
||||
uint32_t tagId;
|
||||
};
|
||||
|
||||
class RsMsgTags : public RsMessageItem
|
||||
{
|
||||
public:
|
||||
RsMsgTags()
|
||||
:RsMessageItem(RS_PKT_SUBTYPE_MSG_TAGS) {}
|
||||
|
||||
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */);
|
||||
|
||||
virtual ~RsMsgTags() {}
|
||||
virtual void clear();
|
||||
|
||||
// ----------- Specific fields ------------- //
|
||||
//
|
||||
uint32_t msgId;
|
||||
std::list<uint32_t> tagIds;
|
||||
};
|
||||
|
||||
class RsMsgSrcId : public RsMessageItem
|
||||
{
|
||||
public:
|
||||
RsMsgSrcId() : RsMessageItem(RS_PKT_SUBTYPE_MSG_SRC_TAG) {}
|
||||
|
||||
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */);
|
||||
|
||||
virtual ~RsMsgSrcId() {}
|
||||
virtual void clear(){}
|
||||
|
||||
// ----------- Specific fields ------------- //
|
||||
//
|
||||
|
||||
uint32_t msgId;
|
||||
RsPeerId srcId;
|
||||
};
|
||||
class RsPublicMsgInviteConfigItem : public RsMessageItem
|
||||
{
|
||||
public:
|
||||
RsPublicMsgInviteConfigItem() : RsMessageItem(RS_PKT_SUBTYPE_MSG_INVITE) {}
|
||||
|
||||
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */);
|
||||
|
||||
virtual ~RsPublicMsgInviteConfigItem() {}
|
||||
virtual void clear();
|
||||
|
||||
// ----------- Specific fields ------------- //
|
||||
//
|
||||
std::string hash ;
|
||||
time_t time_stamp ;
|
||||
};
|
||||
|
||||
class RsMsgGRouterMap : public RsMessageItem
|
||||
{
|
||||
public:
|
||||
RsMsgGRouterMap() : RsMessageItem(RS_PKT_SUBTYPE_MSG_GROUTER_MAP) {}
|
||||
|
||||
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */);
|
||||
|
||||
virtual ~RsMsgGRouterMap() {}
|
||||
virtual void clear();
|
||||
|
||||
// ----------- Specific fields ------------- //
|
||||
//
|
||||
std::map<GRouterMsgPropagationId,uint32_t> ongoing_msgs ;
|
||||
};
|
||||
class RsMsgDistantMessagesHashMap : public RsMessageItem
|
||||
{
|
||||
public:
|
||||
RsMsgDistantMessagesHashMap() : RsMessageItem(RS_PKT_SUBTYPE_MSG_DISTANT_MSG_MAP) {}
|
||||
|
||||
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */);
|
||||
|
||||
virtual ~RsMsgDistantMessagesHashMap() {}
|
||||
virtual void clear() { hash_map.clear() ;}
|
||||
|
||||
// ----------- Specific fields ------------- //
|
||||
//
|
||||
std::map<Sha1CheckSum,uint32_t> hash_map ;
|
||||
};
|
||||
class RsMsgParentId : public RsMessageItem
|
||||
{
|
||||
public:
|
||||
RsMsgParentId() : RsMessageItem(RS_PKT_SUBTYPE_MSG_PARENT_TAG) {}
|
||||
|
||||
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */);
|
||||
|
||||
virtual ~RsMsgParentId() {}
|
||||
virtual void clear(){}
|
||||
|
||||
// ----------- Specific fields ------------- //
|
||||
//
|
||||
uint32_t msgId;
|
||||
uint32_t msgParentId;
|
||||
};
|
||||
|
||||
class RsMsgSerialiser: public RsSerializer
|
||||
{
|
||||
public:
|
||||
RsMsgSerialiser(SerializationFlags flags)
|
||||
:RsSerializer(RS_SERVICE_TYPE_MSG,SerializeContext::FORMAT_BINARY,flags){}
|
||||
|
||||
virtual ~RsMsgSerialiser() {}
|
||||
|
||||
virtual RsItem *create_item(uint16_t service,uint8_t type) const ;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#endif /* RS_MSG_ITEMS_H */
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue