2017-01-14 17:20:42 -05:00
|
|
|
#pragma once
|
|
|
|
/*
|
|
|
|
* GXS Mailing Service
|
|
|
|
* Copyright (C) 2016-2017 Gioacchino Mazzurco <gio@eigenlab.org>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2017-03-01 20:37:53 -05:00
|
|
|
#include "serialiser/rsgxsitems.h"
|
2017-01-14 17:20:42 -05:00
|
|
|
#include "serialiser/rsbaseserial.h"
|
|
|
|
#include "serialiser/rstlvidset.h"
|
|
|
|
#include "retroshare/rsgxsflags.h"
|
2017-01-18 18:32:37 -05:00
|
|
|
#include "retroshare/rsgxscircles.h" // For: GXS_CIRCLE_TYPE_PUBLIC
|
2017-01-30 09:18:12 -05:00
|
|
|
#include "services/p3idservice.h"
|
2017-01-14 17:20:42 -05:00
|
|
|
|
2017-02-25 18:46:02 -05:00
|
|
|
/// Subservices identifiers (like port for TCP)
|
2017-03-01 20:37:53 -05:00
|
|
|
enum class GxsTransSubServices : uint16_t
|
2017-02-25 18:46:02 -05:00
|
|
|
{
|
2017-02-27 16:18:37 -05:00
|
|
|
UNKNOWN = 0,
|
|
|
|
TEST_SERVICE = 1,
|
|
|
|
P3_MSG_SERVICE = 2,
|
|
|
|
P3_CHAT_SERVICE = 3
|
2017-02-25 18:46:02 -05:00
|
|
|
};
|
|
|
|
|
2017-01-30 09:18:12 -05:00
|
|
|
/// Values must fit into uint8_t
|
2017-03-01 20:37:53 -05:00
|
|
|
enum class GxsTransItemsSubtypes : uint8_t
|
2017-01-14 17:20:42 -05:00
|
|
|
{
|
2017-03-01 20:37:53 -05:00
|
|
|
GXS_TRANS_SUBTYPE_MAIL = 1,
|
|
|
|
GXS_TRANS_SUBTYPE_RECEIPT = 2,
|
|
|
|
GXS_TRANS_SUBTYPE_GROUP = 3,
|
|
|
|
OUTGOING_RECORD_ITEM = 4
|
2017-01-14 17:20:42 -05:00
|
|
|
};
|
|
|
|
|
2017-03-01 20:37:53 -05:00
|
|
|
typedef uint64_t RsGxsTransId;
|
2017-02-21 06:02:27 -05:00
|
|
|
|
2017-03-01 20:37:53 -05:00
|
|
|
struct RsNxsTransPresignedReceipt : RsNxsMsg
|
2017-02-18 14:32:25 -05:00
|
|
|
{
|
2017-03-01 20:37:53 -05:00
|
|
|
RsNxsTransPresignedReceipt() : RsNxsMsg(RS_SERVICE_TYPE_GXS_TRANS) {}
|
2017-02-18 14:32:25 -05:00
|
|
|
};
|
|
|
|
|
2017-03-01 20:37:53 -05:00
|
|
|
struct RsGxsTransBaseItem : RsGxsMsgItem
|
2017-02-18 14:32:25 -05:00
|
|
|
{
|
2017-03-01 20:37:53 -05:00
|
|
|
RsGxsTransBaseItem(GxsTransItemsSubtypes subtype) :
|
|
|
|
RsGxsMsgItem( RS_SERVICE_TYPE_GXS_TRANS,
|
2017-02-21 06:02:27 -05:00
|
|
|
static_cast<uint8_t>(subtype) ), mailId(0) {}
|
2017-02-18 14:32:25 -05:00
|
|
|
|
2017-03-01 20:37:53 -05:00
|
|
|
RsGxsTransId mailId;
|
2017-02-18 14:32:25 -05:00
|
|
|
|
2017-02-21 06:02:27 -05:00
|
|
|
void inline clear()
|
2017-02-18 14:32:25 -05:00
|
|
|
{
|
2017-02-21 06:02:27 -05:00
|
|
|
mailId = 0;
|
|
|
|
meta = RsMsgMetaData();
|
2017-02-18 14:32:25 -05:00
|
|
|
}
|
2017-02-21 06:02:27 -05:00
|
|
|
|
2017-03-01 20:37:53 -05:00
|
|
|
static uint32_t inline serial_size()
|
2017-02-18 14:32:25 -05:00
|
|
|
{
|
2017-02-21 06:02:27 -05:00
|
|
|
return 8 + // Header
|
|
|
|
8; // mailId
|
2017-02-18 14:32:25 -05:00
|
|
|
}
|
2017-02-21 06:02:27 -05:00
|
|
|
bool serialize(uint8_t* data, uint32_t size, uint32_t& offset) const;
|
|
|
|
bool deserialize(const uint8_t* data, uint32_t& size, uint32_t& offset);
|
|
|
|
std::ostream &print(std::ostream &out, uint16_t /*indent = 0*/);
|
|
|
|
};
|
2017-02-18 14:32:25 -05:00
|
|
|
|
2017-03-01 20:37:53 -05:00
|
|
|
struct RsGxsTransPresignedReceipt : RsGxsTransBaseItem
|
2017-02-21 06:02:27 -05:00
|
|
|
{
|
2017-03-01 20:37:53 -05:00
|
|
|
RsGxsTransPresignedReceipt() :
|
|
|
|
RsGxsTransBaseItem(GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_RECEIPT) {}
|
2017-02-18 14:32:25 -05:00
|
|
|
};
|
|
|
|
|
2017-03-01 20:37:53 -05:00
|
|
|
enum class RsGxsTransEncryptionMode : uint8_t
|
2017-02-21 06:02:27 -05:00
|
|
|
{
|
|
|
|
CLEAR_TEXT = 1,
|
|
|
|
RSA = 2,
|
|
|
|
UNDEFINED_ENCRYPTION = 250
|
|
|
|
};
|
2017-02-18 14:32:25 -05:00
|
|
|
|
2017-03-01 20:37:53 -05:00
|
|
|
struct RsGxsTransMailItem : RsGxsTransBaseItem
|
2017-01-14 17:20:42 -05:00
|
|
|
{
|
2017-03-01 20:37:53 -05:00
|
|
|
RsGxsTransMailItem() :
|
|
|
|
RsGxsTransBaseItem(GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL),
|
|
|
|
cryptoType(RsGxsTransEncryptionMode::UNDEFINED_ENCRYPTION) {}
|
2017-01-14 17:20:42 -05:00
|
|
|
|
2017-03-01 20:37:53 -05:00
|
|
|
RsGxsTransEncryptionMode cryptoType;
|
2017-01-14 17:20:42 -05:00
|
|
|
|
|
|
|
/**
|
2017-03-01 20:37:53 -05:00
|
|
|
* @brief recipientHint used instead of plain recipient id, so sender can
|
2017-01-14 17:20:42 -05:00
|
|
|
* decide the equilibrium between exposing the recipient and the cost of
|
|
|
|
* completely anonymize it. So a bunch of luky non recipient can conclude
|
2017-01-30 09:18:12 -05:00
|
|
|
* rapidly that they are not the recipient without trying to decrypt the
|
2017-01-14 17:20:42 -05:00
|
|
|
* message.
|
|
|
|
*
|
|
|
|
* To be able to decide how much metadata we disclose sending a message we
|
|
|
|
* send an hint instead of the recipient id in clear, the hint cannot be
|
|
|
|
* false (the recipient would discard the mail) but may be arbitrarly
|
|
|
|
* obscure like 0xFF...FF so potentially everyone could be the recipient, or
|
|
|
|
* may expose the complete recipient id or be a middle ground.
|
|
|
|
* To calculate arbitrary precise hint one do a bitwise OR of the recipients
|
2017-01-30 09:18:12 -05:00
|
|
|
* keys and an arbitrary salt, the more recipients has the mail and the more
|
|
|
|
* 1 bits has the salt the less accurate is the hint.
|
2017-01-14 17:20:42 -05:00
|
|
|
* This way the sender is able to adjust the metadata privacy needed for the
|
2017-03-01 20:37:53 -05:00
|
|
|
* message, in the more private case (recipientHint == 0xFFF...FFF) no one
|
2017-01-14 17:20:42 -05:00
|
|
|
* has a clue about who is the actual recipient, while this imply the cost
|
|
|
|
* that every potencial recipient has to try to decrypt it to know if it is
|
|
|
|
* for herself. This way a bunch of non recipients can rapidly discover that
|
|
|
|
* the message is not directed to them without attempting it's decryption.
|
|
|
|
*
|
|
|
|
* To check if one id may be the recipient of the mail or not one need to
|
|
|
|
* bitwise compare the hint with the id, if at least one bit of the hint is
|
2017-03-03 06:21:43 -05:00
|
|
|
* 0 while the corresponding bit in the id is 1 then the id cannot be the
|
2017-01-14 17:20:42 -05:00
|
|
|
* recipient of the mail.
|
|
|
|
*
|
|
|
|
* Note that by design one can prove that an id is not recipient of the mail
|
|
|
|
* but cannot prove it is.
|
|
|
|
* Also in the extreme case of using 0x00...00 as salt that is equivalent
|
|
|
|
* to not salting at all (aka the plain recipient id is used as hint) a
|
|
|
|
* malicious observer could not demostrate in a conclusive manner that the
|
|
|
|
* mail is directed to the actual recipient as the "apparently"
|
|
|
|
* corresponding hint may be fruit of a "luky" salting of another id.
|
|
|
|
*/
|
2017-03-01 17:07:53 -05:00
|
|
|
RsGxsId recipientHint;
|
2017-01-31 14:14:17 -05:00
|
|
|
void inline saltRecipientHint(const RsGxsId& salt)
|
2017-03-01 17:07:53 -05:00
|
|
|
{ recipientHint = recipientHint | salt; }
|
2017-01-14 17:20:42 -05:00
|
|
|
|
|
|
|
/**
|
2017-01-30 09:18:12 -05:00
|
|
|
* @brief maybeRecipient given an id and an hint check if they match
|
|
|
|
* @see recipientHint
|
2017-01-14 17:20:42 -05:00
|
|
|
* @return true if the id may be recipient of the hint, false otherwise
|
|
|
|
*/
|
2017-01-31 14:14:17 -05:00
|
|
|
bool inline maybeRecipient(const RsGxsId& id) const
|
2017-03-01 17:07:53 -05:00
|
|
|
{ return (~id|recipientHint) == allRecipientsHint; }
|
2017-01-30 09:18:12 -05:00
|
|
|
|
|
|
|
const static RsGxsId allRecipientsHint;
|
|
|
|
|
|
|
|
/** This should travel encrypted, unless EncryptionMode::CLEAR_TEXT
|
|
|
|
* is specified */
|
|
|
|
std::vector<uint8_t> payload;
|
2017-01-14 17:20:42 -05:00
|
|
|
|
2017-03-01 20:37:53 -05:00
|
|
|
uint32_t serial_size() const
|
2017-02-21 06:02:27 -05:00
|
|
|
{
|
2017-03-01 20:37:53 -05:00
|
|
|
return RsGxsTransBaseItem::serial_size() +
|
2017-02-21 06:02:27 -05:00
|
|
|
1 + // cryptoType
|
2017-03-01 17:07:53 -05:00
|
|
|
recipientHint.serial_size() +
|
2017-02-21 06:02:27 -05:00
|
|
|
payload.size();
|
|
|
|
}
|
2017-01-30 09:18:12 -05:00
|
|
|
bool serialize(uint8_t* data, uint32_t size, uint32_t& offset) const
|
|
|
|
{
|
2017-01-31 14:14:17 -05:00
|
|
|
bool ok = size < MAX_SIZE;
|
2017-03-01 20:37:53 -05:00
|
|
|
ok = ok && RsGxsTransBaseItem::serialize(data, size, offset);
|
2017-02-21 06:02:27 -05:00
|
|
|
ok = ok && setRawUInt8( data, size, &offset,
|
|
|
|
static_cast<uint8_t>(cryptoType) );
|
2017-03-01 17:07:53 -05:00
|
|
|
ok = ok && recipientHint.serialise(data, size, offset);
|
2017-01-31 14:14:17 -05:00
|
|
|
uint32_t psz = payload.size();
|
|
|
|
ok = ok && memcpy(data+offset, &payload[0], psz);
|
|
|
|
offset += psz;
|
|
|
|
return ok;
|
2017-01-30 09:18:12 -05:00
|
|
|
}
|
|
|
|
bool deserialize(const uint8_t* data, uint32_t& size, uint32_t& offset)
|
2017-01-14 17:20:42 -05:00
|
|
|
{
|
2017-02-25 18:46:02 -05:00
|
|
|
void* sizePtr = const_cast<uint8_t*>(data+offset);
|
|
|
|
uint32_t rssize = getRsItemSize(sizePtr);
|
|
|
|
|
2017-02-21 06:02:27 -05:00
|
|
|
uint32_t roffset = offset;
|
|
|
|
bool ok = rssize <= size && size < MAX_SIZE;
|
2017-03-01 20:37:53 -05:00
|
|
|
ok = ok && RsGxsTransBaseItem::deserialize(data, rssize, roffset);
|
2017-02-25 18:46:02 -05:00
|
|
|
|
|
|
|
void* dataPtr = const_cast<uint8_t*>(data);
|
2017-02-21 06:02:27 -05:00
|
|
|
uint8_t crType;
|
|
|
|
ok = ok && getRawUInt8(dataPtr, rssize, &roffset, &crType);
|
2017-03-01 20:37:53 -05:00
|
|
|
cryptoType = static_cast<RsGxsTransEncryptionMode>(crType);
|
2017-03-01 17:07:53 -05:00
|
|
|
ok = ok && recipientHint.deserialise(dataPtr, rssize, roffset);
|
2017-02-21 06:02:27 -05:00
|
|
|
uint32_t psz = rssize - roffset;
|
|
|
|
ok = ok && (payload.resize(psz), memcpy(&payload[0], data+roffset, psz));
|
2017-02-25 18:46:02 -05:00
|
|
|
ok = ok && (roffset += psz);
|
2017-02-21 06:02:27 -05:00
|
|
|
if(ok) { size = rssize; offset = roffset; }
|
|
|
|
else size = 0;
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
void clear()
|
|
|
|
{
|
2017-03-01 20:37:53 -05:00
|
|
|
RsGxsTransBaseItem::clear();
|
|
|
|
cryptoType = RsGxsTransEncryptionMode::UNDEFINED_ENCRYPTION;
|
2017-03-01 17:07:53 -05:00
|
|
|
recipientHint.clear();
|
2017-02-21 06:02:27 -05:00
|
|
|
payload.clear();
|
2017-01-14 17:20:42 -05:00
|
|
|
}
|
2017-01-30 09:18:12 -05:00
|
|
|
|
|
|
|
/// Maximum mail size in bytes 10 MiB is more than anything sane can need
|
|
|
|
const static uint32_t MAX_SIZE = 10*8*1024*1024;
|
2017-01-14 17:20:42 -05:00
|
|
|
};
|
|
|
|
|
2017-03-01 20:37:53 -05:00
|
|
|
struct RsGxsTransGroupItem : RsGxsGrpItem
|
2017-01-14 17:20:42 -05:00
|
|
|
{
|
2017-03-01 20:37:53 -05:00
|
|
|
RsGxsTransGroupItem() :
|
|
|
|
RsGxsGrpItem( RS_SERVICE_TYPE_GXS_TRANS,
|
2017-02-25 18:46:02 -05:00
|
|
|
static_cast<uint8_t>(
|
2017-03-01 20:37:53 -05:00
|
|
|
GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_GROUP) )
|
2017-01-14 17:20:42 -05:00
|
|
|
{
|
|
|
|
meta.mGroupFlags = GXS_SERV::FLAG_PRIVACY_PUBLIC;
|
|
|
|
meta.mGroupName = "Mail";
|
2017-01-18 18:32:37 -05:00
|
|
|
meta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC;
|
2017-01-14 17:20:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void clear() {}
|
|
|
|
std::ostream &print(std::ostream &out, uint16_t /*indent = 0*/)
|
|
|
|
{ return out; }
|
|
|
|
};
|
|
|
|
|
2017-03-01 20:37:53 -05:00
|
|
|
enum class GxsTransSendStatus : uint8_t
|
2017-02-25 18:46:02 -05:00
|
|
|
{
|
|
|
|
UNKNOWN = 0,
|
|
|
|
PENDING_PROCESSING,
|
|
|
|
PENDING_PREFERRED_GROUP,
|
|
|
|
PENDING_RECEIPT_CREATE,
|
|
|
|
PENDING_RECEIPT_SIGNATURE,
|
|
|
|
PENDING_SERIALIZATION,
|
|
|
|
PENDING_PAYLOAD_CREATE,
|
|
|
|
PENDING_PAYLOAD_ENCRYPT,
|
|
|
|
PENDING_PUBLISH,
|
|
|
|
/** This will be useful so the user can know if the mail reached at least
|
|
|
|
* some friend node, in case of internet connection interruption */
|
|
|
|
//PENDING_TRANSFER,
|
|
|
|
PENDING_RECEIPT_RECEIVE,
|
|
|
|
/// Records with status >= RECEIPT_RECEIVED get deleted
|
|
|
|
RECEIPT_RECEIVED,
|
|
|
|
FAILED_RECEIPT_SIGNATURE = 240,
|
|
|
|
FAILED_ENCRYPTION
|
|
|
|
};
|
|
|
|
|
2017-03-01 20:37:53 -05:00
|
|
|
class RsGxsTransSerializer;
|
2017-02-25 18:46:02 -05:00
|
|
|
struct OutgoingRecord : RsItem
|
|
|
|
{
|
2017-03-01 20:37:53 -05:00
|
|
|
OutgoingRecord( RsGxsId rec, GxsTransSubServices cs,
|
2017-02-25 18:46:02 -05:00
|
|
|
const uint8_t* data, uint32_t size );
|
|
|
|
|
2017-03-01 20:37:53 -05:00
|
|
|
GxsTransSendStatus status;
|
2017-02-25 18:46:02 -05:00
|
|
|
RsGxsId recipient;
|
|
|
|
/// Don't use a pointer would be invalid after publish
|
2017-03-01 20:37:53 -05:00
|
|
|
RsGxsTransMailItem mailItem;
|
2017-02-25 18:46:02 -05:00
|
|
|
std::vector<uint8_t> mailData;
|
2017-03-01 20:37:53 -05:00
|
|
|
GxsTransSubServices clientService;
|
|
|
|
RsNxsTransPresignedReceipt presignedReceipt;
|
2017-02-25 18:46:02 -05:00
|
|
|
|
2017-03-03 06:21:43 -05:00
|
|
|
uint32_t serial_size() const;
|
2017-02-25 18:46:02 -05:00
|
|
|
bool serialize(uint8_t* data, uint32_t size, uint32_t& offset) const;
|
|
|
|
bool deserialize(const uint8_t* data, uint32_t& size, uint32_t& offset);
|
|
|
|
|
|
|
|
virtual void clear();
|
|
|
|
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
|
|
|
|
|
|
|
private:
|
2017-03-01 20:37:53 -05:00
|
|
|
friend class RsGxsTransSerializer;
|
2017-02-25 18:46:02 -05:00
|
|
|
OutgoingRecord();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-03-01 20:37:53 -05:00
|
|
|
struct RsGxsTransSerializer : RsSerialType
|
2017-01-14 17:20:42 -05:00
|
|
|
{
|
2017-03-01 20:37:53 -05:00
|
|
|
RsGxsTransSerializer() : RsSerialType( RS_PKT_VERSION_SERVICE,
|
|
|
|
RS_SERVICE_TYPE_GXS_TRANS ) {}
|
|
|
|
~RsGxsTransSerializer() {}
|
2017-01-14 17:20:42 -05:00
|
|
|
|
|
|
|
uint32_t size(RsItem* item)
|
|
|
|
{
|
2017-01-30 09:18:12 -05:00
|
|
|
uint32_t sz = 0;
|
2017-03-01 20:37:53 -05:00
|
|
|
switch(static_cast<GxsTransItemsSubtypes>(item->PacketSubType()))
|
2017-01-14 17:20:42 -05:00
|
|
|
{
|
2017-03-01 20:37:53 -05:00
|
|
|
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL:
|
2017-01-14 17:20:42 -05:00
|
|
|
{
|
2017-03-01 20:37:53 -05:00
|
|
|
RsGxsTransMailItem* i = dynamic_cast<RsGxsTransMailItem*>(item);
|
|
|
|
if(i) sz = i->serial_size();
|
2017-01-14 17:20:42 -05:00
|
|
|
break;
|
|
|
|
}
|
2017-03-01 20:37:53 -05:00
|
|
|
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_RECEIPT:
|
|
|
|
sz = RsGxsTransPresignedReceipt::serial_size(); break;
|
|
|
|
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_GROUP: sz = 8; break;
|
|
|
|
case GxsTransItemsSubtypes::OUTGOING_RECORD_ITEM:
|
2017-02-25 18:46:02 -05:00
|
|
|
{
|
|
|
|
OutgoingRecord* ci = dynamic_cast<OutgoingRecord*>(item);
|
2017-03-03 06:21:43 -05:00
|
|
|
if(ci) sz = ci->serial_size();
|
2017-02-25 18:46:02 -05:00
|
|
|
break;
|
|
|
|
}
|
2017-01-30 09:18:12 -05:00
|
|
|
default: break;
|
2017-01-14 17:20:42 -05:00
|
|
|
}
|
|
|
|
|
2017-01-30 09:18:12 -05:00
|
|
|
return sz;
|
2017-01-14 17:20:42 -05:00
|
|
|
}
|
|
|
|
|
2017-01-30 09:18:12 -05:00
|
|
|
bool serialise(RsItem* item, void* data, uint32_t* size);
|
2017-01-14 17:20:42 -05:00
|
|
|
|
|
|
|
RsItem* deserialise(void* data, uint32_t* size)
|
|
|
|
{
|
|
|
|
uint32_t rstype = getRsItemId(data);
|
|
|
|
uint32_t rssize = getRsItemSize(data);
|
2017-01-30 09:18:12 -05:00
|
|
|
uint8_t pktv = getRsItemVersion(rstype);
|
|
|
|
uint16_t srvc = getRsItemService(rstype);
|
2017-02-18 14:32:25 -05:00
|
|
|
const uint8_t* dataPtr = reinterpret_cast<uint8_t*>(data);
|
2017-01-14 17:20:42 -05:00
|
|
|
|
2017-01-30 09:18:12 -05:00
|
|
|
if ( (RS_PKT_VERSION_SERVICE != pktv) || // 0x02
|
2017-03-01 20:37:53 -05:00
|
|
|
(RS_SERVICE_TYPE_GXS_TRANS != srvc) || // 0x0230 = 560
|
2017-01-14 17:20:42 -05:00
|
|
|
(*size < rssize) )
|
2017-01-30 09:18:12 -05:00
|
|
|
{
|
|
|
|
print_stacktrace();
|
2017-01-14 17:20:42 -05:00
|
|
|
return NULL;
|
2017-01-30 09:18:12 -05:00
|
|
|
}
|
2017-01-14 17:20:42 -05:00
|
|
|
|
|
|
|
*size = rssize;
|
|
|
|
bool ok = true;
|
|
|
|
RsItem* ret = NULL;
|
|
|
|
|
2017-03-01 20:37:53 -05:00
|
|
|
switch (static_cast<GxsTransItemsSubtypes>(getRsItemSubType(rstype)))
|
2017-01-14 17:20:42 -05:00
|
|
|
{
|
2017-03-01 20:37:53 -05:00
|
|
|
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL:
|
2017-01-14 17:20:42 -05:00
|
|
|
{
|
2017-03-01 20:37:53 -05:00
|
|
|
RsGxsTransMailItem* i = new RsGxsTransMailItem();
|
2017-01-30 09:18:12 -05:00
|
|
|
uint32_t offset = 0;
|
|
|
|
ok = ok && i->deserialize(dataPtr, *size, offset);
|
2017-01-14 17:20:42 -05:00
|
|
|
ret = i;
|
|
|
|
break;
|
|
|
|
}
|
2017-03-01 20:37:53 -05:00
|
|
|
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_RECEIPT:
|
2017-01-14 17:20:42 -05:00
|
|
|
{
|
2017-03-01 20:37:53 -05:00
|
|
|
RsGxsTransPresignedReceipt* i = new RsGxsTransPresignedReceipt();
|
2017-01-30 09:18:12 -05:00
|
|
|
uint32_t offset = 0;
|
2017-02-18 14:32:25 -05:00
|
|
|
ok &= i->deserialize(dataPtr, *size, offset);
|
2017-01-14 17:20:42 -05:00
|
|
|
ret = i;
|
|
|
|
break;
|
|
|
|
}
|
2017-03-01 20:37:53 -05:00
|
|
|
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_GROUP:
|
2017-01-14 17:20:42 -05:00
|
|
|
{
|
2017-03-01 20:37:53 -05:00
|
|
|
ret = new RsGxsTransGroupItem();
|
2017-01-14 17:20:42 -05:00
|
|
|
break;
|
|
|
|
}
|
2017-03-01 20:37:53 -05:00
|
|
|
case GxsTransItemsSubtypes::OUTGOING_RECORD_ITEM:
|
2017-02-25 18:46:02 -05:00
|
|
|
{
|
|
|
|
OutgoingRecord* i = new OutgoingRecord();
|
|
|
|
uint32_t offset = 0;
|
|
|
|
ok = ok && i->deserialize(dataPtr, *size, offset);
|
|
|
|
ret = i;
|
|
|
|
break;
|
|
|
|
}
|
2017-01-14 17:20:42 -05:00
|
|
|
default:
|
|
|
|
ok = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ok) return ret;
|
|
|
|
|
|
|
|
delete ret;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|