1 #ifndef __RTFX_PARCEL__
2 #define __RTFX_PARCEL__
16 #include <boost/uuid/uuid.hpp>
17 #include <boost/uuid/uuid_generators.hpp>
18 #include <boost/lexical_cast.hpp>
19 #include <boost/uuid/uuid_io.hpp>
23 #include "RTFXDebug.h"
24 #include "RTFXHelpers.h"
82 void CreateHeader( boost::uuids::uuid _messageID, boost::uuids::uuid _senderID,
char * _mailboxID,
83 unsigned int _messageSize, RTFXBIGINT _packetNumber, RTFXBIGINT _packetCount,
84 bool _isCompressed,
unsigned int _compressionType,
bool _keepData,
bool _isRTFX,
bool _isBinary )
86 SetMessageID( _messageID );
87 SetSenderID( _senderID );
88 SetMailboxID( _mailboxID );
89 SetMessageSize( _messageSize );
90 SetPacketNumber( _packetNumber );
91 SetNumberOfPackets( _packetCount );
92 SetCompressed( _isCompressed );
93 SetCompressionType( _compressionType );
94 SetKeepData( _keepData );
95 SetRTFXData( _isRTFX );
96 SetIsBinary( _isBinary );
99 isHeaderDecoded =
false;
103 void EncodeUUID( boost::uuids::uuid _encodeMe,
unsigned int _startingAt )
105 for (
unsigned int i = 0; i < 16; i ++ )
107 data[ _startingAt + i ] = _encodeMe.data[i];
112 void EncodeString(
char * _encodeMe,
unsigned int _startingAt,
unsigned int _length )
114 for (
unsigned int i = 0; i < _length; i ++ )
116 data[ _startingAt + i ] = _encodeMe[i];
121 void EncodeInteger(
unsigned int _encodeMe,
unsigned int _startingAt )
123 char * ptr_ = &data[_startingAt];
124 memcpy( ptr_, &_encodeMe,
sizeof(
unsigned int ) );
128 void EncodeLong( RTFXBIGINT _encodeMe, RTFXBIGINT _startingAt )
130 char * ptr_ = &data[_startingAt];
131 memcpy( ptr_, &_encodeMe,
sizeof( RTFXBIGINT ) );
136 void EncodeBoolean(
bool _encodeMe,
unsigned int _startingAt )
139 data[_startingAt] = 124;
141 data[_startingAt] = 106;
145 void CreateParcel( boost::uuids::uuid _senderID, boost::uuids::uuid _msgID,
char * _mailboxID,
146 unsigned int _msgSize, RTFXBIGINT _pNum, RTFXBIGINT _pCount,
bool _compressed,
147 unsigned int _compressionType,
bool _keepData,
bool _isRTFX,
bool _isBinary,
const char * _msg )
149 SetSenderID( _senderID );
150 SetMessageID( _msgID );
151 SetMailboxID( _mailboxID );
152 SetMessageSize( _msgSize );
153 SetPacketNumber( _pNum );
154 SetNumberOfPackets( _pCount );
155 SetCompressed( _compressed );
156 SetMessageData( _msg, _msgSize );
157 SetCompressionType( _compressionType );
158 SetKeepData( _keepData );
159 SetRTFXData( _isRTFX );
160 SetIsBinary( _isBinary );
167 void CreateParcel( boost::uuids::uuid _senderID, boost::uuids::uuid _msgID,
char * _mailboxID,
168 unsigned int _msgSize, RTFXBIGINT _pNum, RTFXBIGINT _pCount,
bool _compressed,
169 unsigned int _compressionType,
bool _keepData,
bool _isRTFX,
bool _isBinary,
char * _msg )
171 SetSenderID( _senderID );
172 SetMessageID( _msgID );
173 SetMailboxID( _mailboxID );
174 SetMessageSize( _msgSize );
175 SetPacketNumber( _pNum );
176 SetNumberOfPackets( _pCount );
177 SetCompressed( _compressed );
178 SetMessageData( _msg, _msgSize );
179 SetCompressionType( _compressionType );
180 SetKeepData( _keepData );
181 SetIsBinary( _isBinary );
182 SetRTFXData( _isRTFX );
191 EncodeUUID( senderID, 0 );
192 EncodeUUID( messageID, 16 );
193 EncodeString( (
char * )mailboxID, 32, 16 );
194 EncodeInteger( messageSize, 48 );
195 EncodeLong( packetNumber, 52 );
196 EncodeLong( numberOfPackets, 60 );
197 EncodeBoolean( isCompressed, 68 );
198 EncodeInteger( compressionType, 69 );
199 EncodeBoolean( keepDataAtServer, 73 );
200 EncodeBoolean( isDataRTFX, 74 );
201 EncodeBoolean( isBinary, 75 );
205 void DecodeUUID( boost::uuids::uuid &_decodeTo,
unsigned int _startingAt )
207 for (
unsigned int i = 0; i < 16; i ++ )
209 _decodeTo.data[i] = data[ _startingAt + i ];
214 void DecodeString(
char * _decodeTo,
unsigned int _startingAt,
unsigned int _length )
216 for (
unsigned int i = 0; i < _length; i ++ )
218 _decodeTo[i] = data[ _startingAt + i ];
223 void DecodeLong( RTFXBIGINT &_decodeTo, RTFXBIGINT _startingAt )
225 char * ptr_ = &data[_startingAt];
227 memcpy( &ret_, ptr_,
sizeof( RTFXBIGINT ) );
232 void DecodeInteger(
unsigned int &_decodeTo,
unsigned int _startingAt )
234 char * ptr_ = &data[_startingAt];
236 memcpy( &ret_, ptr_,
sizeof(
unsigned int ) );
241 void DecodeBoolean(
bool &_decodeTo,
unsigned int _startingAt )
243 if ( data[_startingAt] == 106 )
252 DecodeUUID( senderID, 0 );
253 DecodeUUID( messageID, 16 );
254 DecodeString( (
char * )mailboxID, 32, 16 );
255 DecodeInteger( messageSize, 48 );
256 DecodeLong( packetNumber, 52 );
257 DecodeLong( numberOfPackets, 60 );
258 DecodeBoolean( isCompressed, 68 );
259 DecodeInteger( compressionType, 69 );
260 DecodeBoolean( keepDataAtServer, 73 );
261 DecodeBoolean( isDataRTFX, 74 );
262 DecodeBoolean( isBinary, 75 );
264 verbose( ostringstream().flush() <<
"RTFXParcel::DecodeHeader: message size - " << messageSize << endl );
265 isHeaderDecoded =
false;
293 void SetMailboxID(
char * _mid )
295 memcpy( mailboxID, _mid, 16 *
sizeof(
char ) );
326 void SetMessageData(
char * _data,
unsigned int _length )
328 for (
unsigned int i = 0; i < _length; i ++ )
330 data[ headerLength + i ] = _data[i];
334 void SetMessageData(
const char * _data,
unsigned int _length )
336 for (
unsigned int i = 0; i < _length; i ++ )
338 data[ headerLength + i ] = _data[i];
343 char * GetMessageData()
345 return ( data + headerLength );
355 void SetCompressionType(
unsigned int _type )
359 compressionType = _type;
363 unsigned int GetCompressionType()
365 return compressionType;
369 void SetKeepData(
bool _store )
371 keepDataAtServer = _store;
377 return keepDataAtServer;
381 void SetRTFXData(
bool _value )
393 void SetIsBinary(
bool _isBinary )
395 isBinary = _isBinary;
407 static const unsigned int maxBodyLength = 65458;
410 static const unsigned int headerLength = 76;
413 static const unsigned int maximumLength = 65534;
452 char data[maximumLength];
463 void CreateParcelList( vector<RTFXParcel> &_parcelList, boost::uuids::uuid _senderID,
char * _mailboxName,
string &_data,
bool _isCompressed,
unsigned int _compressionType,
bool _keepDataAtServer,
bool _isDataRTFX,
bool _isBinary );