2007-12-11 19:54:42 -05:00
/*
* 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 " .
*
*/
2009-05-05 09:18:53 -04:00
# include <stdexcept>
2013-10-21 07:00:49 -04:00
# include <time.h>
2007-12-11 19:54:42 -05:00
# include "serialiser/rsbaseserial.h"
# include "serialiser/rstlvbase.h"
2017-04-24 05:01:45 -04:00
# include "rsitems/rsmsgitems.h"
2017-04-23 16:40:26 -04:00
# include "serialization/rstypeserializer.h"
2008-03-31 10:06:59 -04:00
/***
2007-12-11 19:54:42 -05:00
# define RSSERIAL_DEBUG 1
2008-03-31 10:06:59 -04:00
* * */
2007-12-11 19:54:42 -05:00
# include <iostream>
2017-04-23 16:40:26 -04:00
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 ;
}
}
2007-12-11 19:54:42 -05:00
void RsMsgItem : : clear ( )
{
msgId = 0 ;
msgFlags = 0 ;
sendTime = 0 ;
recvTime = 0 ;
2008-01-26 08:00:57 -05:00
subject . clear ( ) ;
message . clear ( ) ;
2007-12-11 19:54:42 -05:00
2014-03-29 10:18:05 -04:00
rspeerid_msgto . TlvClear ( ) ;
rspeerid_msgcc . TlvClear ( ) ;
rspeerid_msgbcc . TlvClear ( ) ;
rsgxsid_msgto . TlvClear ( ) ;
rsgxsid_msgcc . TlvClear ( ) ;
rsgxsid_msgbcc . TlvClear ( ) ;
2007-12-11 19:54:42 -05:00
attachment . TlvClear ( ) ;
}
2017-04-23 16:40:26 -04:00
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 ( ) ;
}