2012-06-26 15:52:01 -04:00
|
|
|
|
2012-08-06 17:00:38 -04:00
|
|
|
/*
|
|
|
|
* libretroshare/src/gxs: rsgxsdata.cc
|
|
|
|
*
|
|
|
|
* Gxs Data types used to specific services
|
|
|
|
*
|
|
|
|
* 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".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-06-26 15:52:01 -04:00
|
|
|
#include "rsgxsdata.h"
|
|
|
|
#include "serialiser/rsbaseserial.h"
|
2012-08-19 18:15:37 -04:00
|
|
|
#include "serialiser/rstlvbase.h"
|
2012-06-26 15:52:01 -04:00
|
|
|
|
|
|
|
RsGxsGrpMetaData::RsGxsGrpMetaData()
|
|
|
|
{
|
2012-09-30 10:21:17 -04:00
|
|
|
clear();
|
2012-06-26 15:52:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t RsGxsGrpMetaData::serial_size()
|
|
|
|
{
|
|
|
|
uint32_t s = 8; // header size
|
|
|
|
|
|
|
|
s += GetTlvStringSize(mGroupId);
|
|
|
|
s += GetTlvStringSize(mOrigGrpId);
|
|
|
|
s += GetTlvStringSize(mGroupName);
|
|
|
|
s += 4;
|
|
|
|
s += 4;
|
|
|
|
s += GetTlvStringSize(mAuthorId);
|
2012-08-18 06:01:35 -04:00
|
|
|
s += GetTlvStringSize(mServiceString);
|
2012-10-01 16:57:56 -04:00
|
|
|
s += signSet.TlvSize();
|
2012-06-26 15:52:01 -04:00
|
|
|
s += keys.TlvSize();
|
2012-12-02 14:40:17 -05:00
|
|
|
s += 4; // for mCircleType
|
|
|
|
s += GetTlvStringSize(mCircleId);
|
2013-06-04 17:00:43 -04:00
|
|
|
s += 4; // mAuthenFlag
|
2014-01-19 18:38:48 -05:00
|
|
|
s += GetTlvStringSize(mParentGrpId);
|
2012-06-26 15:52:01 -04:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2012-06-28 17:22:55 -04:00
|
|
|
void RsGxsGrpMetaData::clear(){
|
|
|
|
|
|
|
|
mGroupId.clear();
|
|
|
|
mOrigGrpId.clear();
|
|
|
|
mAuthorId.clear();
|
|
|
|
mGroupName.clear();
|
2012-08-18 06:01:35 -04:00
|
|
|
mServiceString.clear();
|
2012-06-28 17:22:55 -04:00
|
|
|
mPublishTs = 0;
|
|
|
|
mGroupFlags = 0;
|
|
|
|
mPop = 0;
|
|
|
|
mMsgCount = 0;
|
|
|
|
mGroupStatus = 0;
|
|
|
|
mLastPost = 0;
|
|
|
|
mSubscribeFlags = 0;
|
2012-10-01 16:57:56 -04:00
|
|
|
signSet.TlvClear();
|
2012-06-28 17:22:55 -04:00
|
|
|
keys.TlvClear();
|
2012-12-02 14:40:17 -05:00
|
|
|
mCircleId.clear();
|
|
|
|
mInternalCircle.clear();
|
|
|
|
mOriginator.clear();
|
|
|
|
mCircleType = 0;
|
2013-06-04 17:00:43 -04:00
|
|
|
mAuthenFlags = 0;
|
2014-01-19 18:38:48 -05:00
|
|
|
mParentGrpId.clear();
|
2013-11-23 18:39:55 -05:00
|
|
|
mRecvTS = 0;
|
2014-02-22 19:08:11 -05:00
|
|
|
mReputationCutOff = 0;
|
2012-10-01 16:57:56 -04:00
|
|
|
|
2012-06-28 17:22:55 -04:00
|
|
|
}
|
|
|
|
|
2012-06-26 15:52:01 -04:00
|
|
|
bool RsGxsGrpMetaData::serialise(void *data, uint32_t &pktsize)
|
|
|
|
{
|
|
|
|
|
|
|
|
uint32_t tlvsize = serial_size() ;
|
|
|
|
uint32_t offset = 0;
|
|
|
|
|
|
|
|
if (pktsize < tlvsize)
|
|
|
|
return false; /* not enough space */
|
|
|
|
|
|
|
|
pktsize = tlvsize;
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
ok &= setRsItemHeader(data, tlvsize, 0, tlvsize);
|
|
|
|
|
|
|
|
#ifdef GXS_DEBUG
|
|
|
|
std::cerr << "RsGxsGrpMetaData serialise()" << std::endl;
|
|
|
|
std::cerr << "RsGxsGrpMetaData serialise(): Header: " << ok << std::endl;
|
|
|
|
std::cerr << "RsGxsGrpMetaData serialise(): Size: " << tlvsize << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* skip header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
ok &= SetTlvString(data, tlvsize, &offset, 0, mGroupId);
|
|
|
|
ok &= SetTlvString(data, tlvsize, &offset, 0, mOrigGrpId);
|
2014-01-19 18:38:48 -05:00
|
|
|
ok &= SetTlvString(data, tlvsize, &offset, 0, mParentGrpId);
|
2012-06-26 15:52:01 -04:00
|
|
|
ok &= SetTlvString(data, tlvsize, &offset, 0, mGroupName);
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, mGroupFlags);
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, mPublishTs);
|
2012-12-02 14:40:17 -05:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, mCircleType);
|
2013-06-04 17:00:43 -04:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, mAuthenFlags);
|
2012-06-26 15:52:01 -04:00
|
|
|
ok &= SetTlvString(data, tlvsize, &offset, 0, mAuthorId);
|
2012-08-18 06:01:35 -04:00
|
|
|
ok &= SetTlvString(data, tlvsize, &offset, 0, mServiceString);
|
2012-12-02 14:40:17 -05:00
|
|
|
ok &= SetTlvString(data, tlvsize, &offset, 0, mCircleId);
|
2013-06-04 17:00:43 -04:00
|
|
|
|
2012-10-01 16:57:56 -04:00
|
|
|
ok &= signSet.SetTlv(data, tlvsize, &offset);
|
2012-06-26 15:52:01 -04:00
|
|
|
ok &= keys.SetTlv(data, tlvsize, &offset);
|
2012-10-01 16:57:56 -04:00
|
|
|
|
2012-06-26 15:52:01 -04:00
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RsGxsGrpMetaData::deserialise(void *data, uint32_t &pktsize)
|
|
|
|
{
|
|
|
|
|
|
|
|
uint32_t offset = 8; // skip the header
|
|
|
|
uint32_t rssize = getRsItemSize(data);
|
|
|
|
|
|
|
|
bool ok = true ;
|
|
|
|
|
2012-06-28 17:22:55 -04:00
|
|
|
ok &= rssize == pktsize;
|
2012-06-26 15:52:01 -04:00
|
|
|
|
|
|
|
if(!ok) return false;
|
|
|
|
|
|
|
|
ok &= GetTlvString(data, pktsize, &offset, 0, mGroupId);
|
|
|
|
ok &= GetTlvString(data, pktsize, &offset, 0, mOrigGrpId);
|
2014-01-19 18:38:48 -05:00
|
|
|
ok &= GetTlvString(data, pktsize, &offset, 0, mParentGrpId);
|
2012-06-28 17:22:55 -04:00
|
|
|
ok &= GetTlvString(data, pktsize, &offset, 0, mGroupName);
|
2012-06-26 15:52:01 -04:00
|
|
|
ok &= getRawUInt32(data, pktsize, &offset, &mGroupFlags);
|
|
|
|
ok &= getRawUInt32(data, pktsize, &offset, &mPublishTs);
|
2012-12-02 14:40:17 -05:00
|
|
|
ok &= getRawUInt32(data, pktsize, &offset, &mCircleType);
|
2013-06-04 17:00:43 -04:00
|
|
|
ok &= getRawUInt32(data, pktsize, &offset, &mAuthenFlags);
|
2012-06-26 15:52:01 -04:00
|
|
|
ok &= GetTlvString(data, pktsize, &offset, 0, mAuthorId);
|
2012-08-18 06:01:35 -04:00
|
|
|
ok &= GetTlvString(data, pktsize, &offset, 0, mServiceString);
|
2012-12-02 14:40:17 -05:00
|
|
|
ok &= GetTlvString(data, pktsize, &offset, 0, mCircleId);
|
2012-10-01 16:57:56 -04:00
|
|
|
ok &= signSet.GetTlv(data, pktsize, &offset);
|
2012-06-28 17:22:55 -04:00
|
|
|
ok &= keys.GetTlv(data, pktsize, &offset);
|
2012-10-01 16:57:56 -04:00
|
|
|
|
2012-06-26 15:52:01 -04:00
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
2013-02-07 18:04:16 -05:00
|
|
|
int RsGxsMsgMetaData::refcount = 0;
|
2012-06-26 15:52:01 -04:00
|
|
|
|
2012-06-28 17:22:55 -04:00
|
|
|
RsGxsMsgMetaData::RsGxsMsgMetaData(){
|
|
|
|
|
2013-02-07 18:04:16 -05:00
|
|
|
//std::cout << "\nrefcount++ : " << ++refcount << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RsGxsMsgMetaData::~RsGxsMsgMetaData(){
|
|
|
|
//std::cout << "\nrefcount-- : " << --refcount << std::endl;
|
|
|
|
return;
|
2012-06-28 17:22:55 -04:00
|
|
|
}
|
|
|
|
|
2012-06-26 15:52:01 -04:00
|
|
|
uint32_t RsGxsMsgMetaData::serial_size()
|
|
|
|
{
|
|
|
|
|
|
|
|
uint32_t s = 8; // header size
|
|
|
|
|
|
|
|
s += GetTlvStringSize(mGroupId);
|
|
|
|
s += GetTlvStringSize(mMsgId);
|
|
|
|
s += GetTlvStringSize(mThreadId);
|
|
|
|
s += GetTlvStringSize(mParentId);
|
|
|
|
s += GetTlvStringSize(mOrigMsgId);
|
2012-06-28 17:22:55 -04:00
|
|
|
s += GetTlvStringSize(mAuthorId);
|
2012-06-26 15:52:01 -04:00
|
|
|
|
2012-10-01 16:57:56 -04:00
|
|
|
s += signSet.TlvSize();
|
2012-06-26 15:52:01 -04:00
|
|
|
s += GetTlvStringSize(mMsgName);
|
|
|
|
s += 4;
|
|
|
|
s += 4;
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2012-06-28 17:22:55 -04:00
|
|
|
void RsGxsMsgMetaData::clear()
|
|
|
|
{
|
|
|
|
mGroupId.clear();
|
|
|
|
mMsgId.clear();
|
|
|
|
mThreadId.clear();
|
|
|
|
mParentId.clear();
|
|
|
|
mAuthorId.clear();
|
|
|
|
mOrigMsgId.clear();
|
|
|
|
mMsgName.clear();
|
2012-08-18 06:01:35 -04:00
|
|
|
mServiceString.clear();
|
2012-06-28 17:22:55 -04:00
|
|
|
|
2012-10-01 16:57:56 -04:00
|
|
|
signSet.TlvClear();
|
2012-06-28 17:22:55 -04:00
|
|
|
mPublishTs = 0;
|
|
|
|
mMsgFlags = 0;
|
|
|
|
mMsgStatus = 0;
|
|
|
|
mChildTs = 0;
|
2013-11-23 18:39:55 -05:00
|
|
|
recvTS = 0;
|
2012-06-28 17:22:55 -04:00
|
|
|
}
|
|
|
|
|
2012-06-26 15:52:01 -04:00
|
|
|
bool RsGxsMsgMetaData::serialise(void *data, uint32_t *size)
|
|
|
|
{
|
|
|
|
uint32_t tlvsize = serial_size() ;
|
|
|
|
uint32_t offset = 0;
|
|
|
|
|
|
|
|
if (*size < tlvsize)
|
|
|
|
return false; /* not enough space */
|
|
|
|
|
|
|
|
*size = tlvsize;
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
ok &= setRsItemHeader(data, tlvsize, 0, tlvsize);
|
|
|
|
|
|
|
|
#ifdef GXS_DEBUG
|
|
|
|
std::cerr << "RsGxsGrpMetaData serialise()" << std::endl;
|
|
|
|
std::cerr << "RsGxsGrpMetaData serialise(): Header: " << ok << std::endl;
|
|
|
|
std::cerr << "RsGxsGrpMetaData serialise(): Size: " << tlvsize << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* skip header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
ok &= SetTlvString(data, *size, &offset, 0, mGroupId);
|
|
|
|
ok &= SetTlvString(data, *size, &offset, 0, mMsgId);
|
|
|
|
ok &= SetTlvString(data, *size, &offset, 0, mThreadId);
|
|
|
|
ok &= SetTlvString(data, *size, &offset, 0, mParentId);
|
|
|
|
ok &= SetTlvString(data, *size, &offset, 0, mOrigMsgId);
|
2012-06-28 17:22:55 -04:00
|
|
|
ok &= SetTlvString(data, *size, &offset, 0, mAuthorId);
|
2012-06-26 15:52:01 -04:00
|
|
|
|
2012-10-01 16:57:56 -04:00
|
|
|
ok &= signSet.SetTlv(data, *size, &offset);
|
2012-06-26 15:52:01 -04:00
|
|
|
ok &= SetTlvString(data, *size, &offset, 0, mMsgName);
|
|
|
|
ok &= setRawUInt32(data, *size, &offset, mPublishTs);
|
|
|
|
ok &= setRawUInt32(data, *size, &offset, mMsgFlags);
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool RsGxsMsgMetaData::deserialise(void *data, uint32_t *size)
|
|
|
|
{
|
|
|
|
uint32_t offset = 8; // skip the header
|
|
|
|
uint32_t rssize = getRsItemSize(data);
|
|
|
|
|
|
|
|
bool ok = true ;
|
|
|
|
|
2012-06-28 17:22:55 -04:00
|
|
|
ok &= rssize == *size;
|
2012-06-26 15:52:01 -04:00
|
|
|
|
|
|
|
if(!ok) return false;
|
|
|
|
|
|
|
|
ok &= GetTlvString(data, *size, &offset, 0, mGroupId);
|
|
|
|
ok &= GetTlvString(data, *size, &offset, 0, mMsgId);
|
|
|
|
ok &= GetTlvString(data, *size, &offset, 0, mThreadId);
|
|
|
|
ok &= GetTlvString(data, *size, &offset, 0, mParentId);
|
|
|
|
ok &= GetTlvString(data, *size, &offset, 0, mOrigMsgId);
|
2012-06-28 17:22:55 -04:00
|
|
|
ok &= GetTlvString(data, *size, &offset, 0, mAuthorId);
|
2012-06-26 15:52:01 -04:00
|
|
|
|
2012-10-01 16:57:56 -04:00
|
|
|
ok &= signSet.GetTlv(data, *size, &offset);
|
2012-06-26 15:52:01 -04:00
|
|
|
ok &= GetTlvString(data, *size, &offset, 0, mMsgName);
|
|
|
|
uint32_t t;
|
|
|
|
ok &= getRawUInt32(data, *size, &offset, &t);
|
|
|
|
mPublishTs = t;
|
|
|
|
ok &= getRawUInt32(data, *size, &offset, &mMsgFlags);
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
2012-07-26 17:48:54 -04:00
|
|
|
|
|
|
|
void RsGxsGrpMetaData::operator =(const RsGroupMetaData& rMeta)
|
|
|
|
{
|
|
|
|
this->mAuthorId = rMeta.mAuthorId;
|
|
|
|
this->mGroupFlags = rMeta.mGroupFlags;
|
|
|
|
this->mGroupId = rMeta.mGroupId;
|
|
|
|
this->mGroupStatus = rMeta.mGroupStatus ;
|
|
|
|
this->mLastPost = rMeta.mLastPost;
|
|
|
|
this->mMsgCount = rMeta.mMsgCount ;
|
|
|
|
this->mPop = rMeta.mPop;
|
|
|
|
this->mPublishTs = rMeta.mPublishTs;
|
|
|
|
this->mSubscribeFlags = rMeta.mSubscribeFlags;
|
|
|
|
this->mGroupName = rMeta.mGroupName;
|
2012-08-18 06:01:35 -04:00
|
|
|
this->mServiceString = rMeta.mServiceString;
|
2012-08-26 10:02:47 -04:00
|
|
|
this->mSignFlags = rMeta.mSignFlags;
|
2012-12-02 14:40:17 -05:00
|
|
|
this->mCircleId = rMeta.mCircleId;
|
|
|
|
this->mCircleType = rMeta.mCircleType;
|
|
|
|
this->mInternalCircle = rMeta.mInternalCircle;
|
|
|
|
this->mOriginator = rMeta.mOriginator;
|
2013-06-04 17:00:43 -04:00
|
|
|
this->mAuthenFlags = rMeta.mAuthenFlags;
|
2014-01-19 18:38:48 -05:00
|
|
|
//std::cout << "rMeta.mParentGrpId= " <<rMeta.mParentGrpId<<"\n";
|
|
|
|
this->mParentGrpId = rMeta.mParentGrpId;
|
2012-07-26 17:48:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void RsGxsMsgMetaData::operator =(const RsMsgMetaData& rMeta)
|
|
|
|
{
|
|
|
|
this->mAuthorId = rMeta.mAuthorId;
|
|
|
|
this->mChildTs = rMeta.mChildTs ;
|
|
|
|
this->mGroupId = rMeta.mGroupId;
|
|
|
|
this->mMsgFlags = rMeta.mMsgFlags ;
|
|
|
|
this->mMsgId = rMeta.mMsgId ;
|
|
|
|
this->mMsgName = rMeta.mMsgName;
|
|
|
|
this->mMsgStatus = rMeta.mMsgStatus;
|
|
|
|
this->mOrigMsgId = rMeta.mOrigMsgId;
|
|
|
|
this->mParentId = rMeta.mParentId ;
|
|
|
|
this->mPublishTs = rMeta.mPublishTs ;
|
|
|
|
this->mThreadId = rMeta.mThreadId;
|
2012-08-18 06:01:35 -04:00
|
|
|
this->mServiceString = rMeta.mServiceString;
|
2012-08-19 18:15:37 -04:00
|
|
|
}
|
|
|
|
|
2012-07-26 17:48:54 -04:00
|
|
|
|