new msg items to store srcid/from address for rs messages

also updated tests for new rsitems

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3594 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2010-10-03 11:56:53 +00:00
parent cfa10c6f80
commit 9bdf222418
4 changed files with 224 additions and 1 deletions

View File

@ -559,6 +559,20 @@ void RsMsgTags::clear()
std::ostream& RsMsgTagType::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsMsgTagType", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "rgb_color : " << rgb_color << std::endl;
printIndent(out, int_Indent);
out << "text: " << text << std::endl;
printIndent(out, int_Indent);
out << "tagId: " << tagId << std::endl;
printRsItemEnd(out, "RsMsgTagTypeItem", indent);
return out;
}
@ -566,6 +580,22 @@ std::ostream& RsMsgTagType::print(std::ostream &out, uint16_t indent)
std::ostream& RsMsgTags::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsMsgTagsItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "msgId : " << msgId << std::endl;
std::list<uint32_t>::iterator it;
for(it=tagIds.begin(); it != tagIds.end(); it++)
{
printIndent(out, int_Indent);
out << "tagId : " << *it << std::endl;
}
printRsItemEnd(out, "RsMsgTags", indent);
return out;
}
@ -937,17 +967,157 @@ RsMsgTags* RsMsgSerialiser::deserialiseMsgTagItem(void* data, uint32_t* pktsize)
return item;
}
/************************************** Message SrcId **********************/
RsMsgSrcId::~RsMsgSrcId()
{
return;
}
std::ostream& RsMsgSrcId::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsMsgSrcIdItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "msgId : " << msgId << std::endl;
printIndent(out, int_Indent);
out << "SrcId: " << srcId << std::endl;
printRsItemEnd(out, "RsMsgItem", indent);
return out;
}
void RsMsgSrcId::clear()
{
msgId = 0;
srcId.clear();
return;
}
uint32_t RsMsgSerialiser::sizeMsgSrcIdItem(RsMsgSrcId* item)
{
uint32_t s = 8; /* header */
s += 4;
s += GetTlvStringSize(item->srcId);
return s;
}
bool RsMsgSerialiser::serialiseMsgSrcIdItem(RsMsgSrcId *item, void *data, uint32_t* pktsize)
{
uint32_t tlvsize = sizeMsgSrcIdItem(item);
uint32_t offset = 0;
if (*pktsize < tlvsize)
return false; /* not enough space */
*pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsMsgSerialiser::serialiseMsgSrcIdItem() Header: " << ok << std::endl;
std::cerr << "RsMsgSerialiser::serialiseMsgSrcIdItem() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
ok &= setRawUInt32(data, tlvsize, &offset, item->msgId);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PEERID, (item->srcId));
if (offset != tlvsize)
{
ok = false;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsMsgSerialiser::serialiseMsgSrcIdItem() Size Error! " << std::endl;
#endif
}
return ok;
}
RsMsgSrcId* RsMsgSerialiser::deserialiseMsgSrcIdItem(void* data, uint32_t* pktsize)
{
/* 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_MSG != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_MSG_SRC_TAG != 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 */
RsMsgSrcId *item = new RsMsgSrcId();
item->clear();
/* skip the header */
offset += 8;
/* get mandatory parts first */
ok &= getRawUInt32(data, rssize, &offset, &(item->msgId));
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PEERID, item->srcId);
if (offset != rssize)
{
/* error */
delete item;
return NULL;
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
/************************* end of definition of msgSrcId serialisation functions ************************/
uint32_t RsMsgSerialiser::size(RsItem *i)
{
RsMsgItem *mi;
RsMsgTagType *mtt;
RsMsgTags *mts;
RsMsgSrcId *msi;
/* in order of frequency */
if (NULL != (mi = dynamic_cast<RsMsgItem *>(i)))
{
return sizeMsgItem(mi);
}
else if (NULL != (msi = dynamic_cast<RsMsgSrcId *>(i)))
{
return sizeMsgSrcIdItem(msi);
}
else if (NULL != (mtt = dynamic_cast<RsMsgTagType *>(i)))
{
return sizeTagItem(mtt);
@ -967,13 +1137,19 @@ bool RsMsgSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
#endif
RsMsgItem *mi;
RsMsgSrcId* msi;
RsMsgTagType *mtt;
RsMsgTags *mts;
if (NULL != (mi = dynamic_cast<RsMsgItem *>(i)))
{
return serialiseMsgItem(mi, data, pktsize);
}
else if (NULL != (msi = dynamic_cast<RsMsgSrcId *>(i)))
{
return serialiseMsgSrcIdItem(msi, data, pktsize);
}
else if (NULL != (mtt = dynamic_cast<RsMsgTagType *>(i)))
{
return serialiseTagItem(mtt, data, pktsize);
@ -982,6 +1158,7 @@ bool RsMsgSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
{
return serialiseMsgTagItem(mts, data, pktsize);
}
return false;
}
@ -1005,6 +1182,9 @@ RsItem* RsMsgSerialiser::deserialise(void *data, uint32_t *pktsize)
case RS_PKT_SUBTYPE_DEFAULT:
return deserialiseMsgItem(data, pktsize);
break;
case RS_PKT_SUBTYPE_MSG_SRC_TAG:
return deserialiseMsgSrcIdItem(data, pktsize);
break;
case RS_PKT_SUBTYPE_MSG_TAG_TYPE:
return deserialiseTagItem(data, pktsize);
break;

View File

@ -53,6 +53,7 @@ const uint8_t RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG = 0x05 ; // default is 0x01
// 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;
class RsChatItem: public RsItem
@ -254,6 +255,26 @@ public:
std::list<uint32_t> tagIds;
};
class RsMsgSrcId : public RsItem
{
public:
RsMsgSrcId()
: RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_MSG,
RS_PKT_SUBTYPE_MSG_SRC_TAG)
{ return;}
std::ostream &print(std::ostream &out, uint16_t indent = 0);
virtual ~RsMsgSrcId();
virtual void clear();
uint32_t msgId;
std::string srcId;
};
class RsMsgSerialiser: public RsSerialType
{
public:
@ -286,6 +307,10 @@ virtual uint32_t sizeMsgTagItem(RsMsgTags *);
virtual bool serialiseMsgTagItem (RsMsgTags *item, void *data, uint32_t *size);
virtual RsMsgTags *deserialiseMsgTagItem(void *data, uint32_t *size);
virtual uint32_t sizeMsgSrcIdItem(RsMsgSrcId *);
virtual bool serialiseMsgSrcIdItem (RsMsgSrcId *item, void *data, uint32_t *size);
virtual RsMsgSrcId *deserialiseMsgSrcIdItem(void *data, uint32_t *size);
bool m_bConfiguration; // is set to true for saving configuration (enables serialising msgId)

View File

@ -104,6 +104,14 @@ RsSerialType* init_item(RsMsgTags& mt)
return new RsMsgSerialiser();
}
RsSerialType* init_item(RsMsgSrcId& ms)
{
ms.msgId = rand()%434;
randString(SHORT_STR, ms.srcId);
return new RsMsgSerialiser();
}
bool operator ==(const RsChatMsgItem& cmiLeft,const RsChatMsgItem& cmiRight)
{
@ -182,6 +190,14 @@ bool operator ==(const RsMsgTags& mtLeft, const RsMsgTags& mtRight)
return true;
}
bool operator ==(const RsMsgSrcId& msLeft, const RsMsgSrcId& msRight)
{
if(msLeft.msgId != msRight.msgId) return false;
if(msLeft.srcId != msRight.srcId) return false;
return true;
}
int main()
{
test_RsItem<RsChatMsgItem >(); REPORT("Serialise/Deserialise RsChatMsgItem");
@ -190,6 +206,7 @@ int main()
test_RsItem<RsMsgItem >(); REPORT("Serialise/Deserialise RsMsgItem");
test_RsItem<RsMsgTagType>(); REPORT("Serialise/Deserialise RsMsgTagType");
test_RsItem<RsMsgTags>(); REPORT("Serialise/Deserialise RsMsgTags");
test_RsItem<RsMsgSrcId>(); REPORT("Serialise/Deserialise RsMsgSrcId");
std::cerr << std::endl;

View File

@ -37,6 +37,7 @@ RsSerialType* init_item(RsChatAvatarItem& );
RsSerialType* init_item(RsMsgItem& );
RsSerialType* init_item(RsMsgTagType& );
RsSerialType* init_item(RsMsgTags& );
RsSerialType* init_item(RsMsgSrcId& );
bool operator ==(const RsChatMsgItem& ,const RsChatMsgItem& );
bool operator ==(const RsChatStatusItem& , const RsChatStatusItem& );
@ -44,6 +45,6 @@ bool operator ==(const RsChatAvatarItem&, const RsChatAvatarItem& );
bool operator ==(const RsMsgTagType&, const RsMsgTagType& );
bool operator ==(const RsMsgTags&, const RsMsgTags& );
bool operator ==(const RsMsgItem&, const RsMsgItem& );
bool operator ==(const RsMsgSrcId&, const RsMsgSrcId& );
#endif /* MSGITEM_TEST_H_ */