2015-05-11 15:40:07 -04:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
2012-02-19 03:32:47 -05:00
|
|
|
*
|
2015-05-11 15:40:07 -04:00
|
|
|
* Copyright (C) 2015
|
2012-02-19 03:32:47 -05:00
|
|
|
*
|
2015-05-11 15:40:07 -04:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2012-02-19 03:32:47 -05:00
|
|
|
*
|
2015-05-11 15:40:07 -04:00
|
|
|
* 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 General Public License for more details.
|
2012-02-19 03:32:47 -05:00
|
|
|
*
|
2015-05-11 15:40:07 -04:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2012-02-19 16:13:20 -05:00
|
|
|
#include <stdexcept>
|
2012-02-19 03:32:47 -05:00
|
|
|
#include "serialiser/rsbaseserial.h"
|
|
|
|
#include "serialiser/rstlvbase.h"
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
#include "services/rsVOIPItems.h"
|
2012-02-19 10:07:47 -05:00
|
|
|
|
2012-02-19 03:32:47 -05:00
|
|
|
/***
|
|
|
|
#define RSSERIAL_DEBUG 1
|
|
|
|
***/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
std::ostream& RsVOIPPingItem::print(std::ostream &out, uint16_t indent)
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
printRsItemBase(out, "RsVOIPPingItem", indent);
|
2012-02-19 03:32:47 -05:00
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "SeqNo: " << mSeqNo << std::endl;
|
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "PingTS: " << std::hex << mPingTS << std::dec << std::endl;
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
printRsItemEnd(out, "RsVOIPPingItem", indent);
|
2012-02-19 03:32:47 -05:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
std::ostream& RsVOIPPongItem::print(std::ostream &out, uint16_t indent)
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
printRsItemBase(out, "RsVOIPPongItem", indent);
|
2012-02-19 03:32:47 -05:00
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "SeqNo: " << mSeqNo << std::endl;
|
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "PingTS: " << std::hex << mPingTS << std::dec << std::endl;
|
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "PongTS: " << std::hex << mPongTS << std::dec << std::endl;
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
printRsItemEnd(out, "RsVOIPPongItem", indent);
|
2012-02-19 03:32:47 -05:00
|
|
|
return out;
|
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
std::ostream& RsVOIPProtocolItem::print(std::ostream &out, uint16_t indent)
|
2012-02-21 16:53:25 -05:00
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
printRsItemBase(out, "RsVOIPProtocolItem", indent);
|
2012-02-21 16:53:25 -05:00
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "flags: " << flags << std::endl;
|
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
2015-10-10 09:21:59 -04:00
|
|
|
out << "protocol: " << std::hex << (uint32_t)protocol << std::dec << std::endl;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
printRsItemEnd(out, "RsVOIPProtocolItem", indent);
|
2012-02-21 16:53:25 -05:00
|
|
|
return out;
|
|
|
|
}
|
2015-08-10 22:13:50 -04:00
|
|
|
std::ostream& RsVOIPBandwidthItem::print(std::ostream &out, uint16_t indent)
|
|
|
|
{
|
|
|
|
printRsItemBase(out, "RsVOIPBandwidthItem", indent);
|
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "flags: " << std::hex << flags << std::dec << std::endl;
|
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "speed: " << bytes_per_sec << std::endl;
|
|
|
|
|
|
|
|
printRsItemEnd(out, "RsVOIPBandwidthItem", indent);
|
|
|
|
return out;
|
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
std::ostream& RsVOIPDataItem::print(std::ostream &out, uint16_t indent)
|
2012-02-21 16:53:25 -05:00
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
printRsItemBase(out, "RsVOIPDataItem", indent);
|
2012-02-21 16:53:25 -05:00
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "flags: " << flags << std::endl;
|
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "data size: " << std::hex << data_size << std::dec << std::endl;
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
printRsItemEnd(out, "RsVOIPDataItem", indent);
|
2012-02-21 16:53:25 -05:00
|
|
|
return out;
|
|
|
|
}
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
/*************************************************************************/
|
2015-05-11 15:40:07 -04:00
|
|
|
uint32_t RsVOIPDataItem::serial_size() const
|
2012-02-19 16:13:20 -05:00
|
|
|
{
|
|
|
|
uint32_t s = 8; /* header */
|
|
|
|
s += 4; /* flags */
|
|
|
|
s += 4; /* data_size */
|
|
|
|
s += data_size; /* data */
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2012-02-19 16:13:20 -05:00
|
|
|
return s;
|
|
|
|
}
|
2015-08-10 22:13:50 -04:00
|
|
|
uint32_t RsVOIPBandwidthItem::serial_size() const
|
|
|
|
{
|
|
|
|
uint32_t s = 8; /* header */
|
|
|
|
s += 4; /* flags */
|
|
|
|
s += 4; /* bandwidth */
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
uint32_t RsVOIPProtocolItem::serial_size() const
|
2012-02-19 16:13:20 -05:00
|
|
|
{
|
|
|
|
uint32_t s = 8; /* header */
|
|
|
|
s += 4; /* flags */
|
|
|
|
s += 4; /* protocol */
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2012-02-19 16:13:20 -05:00
|
|
|
return s;
|
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
uint32_t RsVOIPPingItem::serial_size() const
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
|
|
|
uint32_t s = 8; /* header */
|
|
|
|
s += 4; /* seqno */
|
|
|
|
s += 8; /* pingTS */
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
bool RsVOIPProtocolItem::serialise(void *data, uint32_t& pktsize)
|
2012-02-19 16:13:20 -05:00
|
|
|
{
|
|
|
|
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, PacketId(), tlvsize);
|
|
|
|
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
2015-05-11 15:40:07 -04:00
|
|
|
std::cerr << "RsVOIPSerialiser::serialiseVOIPDataItem() Header: " << ok << std::endl;
|
|
|
|
std::cerr << "RsVOIPSerialiser::serialiseVOIPDataItem() Size: " << tlvsize << std::endl;
|
2012-02-19 16:13:20 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
/* add mandatory parts first */
|
2015-10-10 09:21:59 -04:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, (uint32_t)protocol);
|
2012-02-19 16:13:20 -05:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, flags);
|
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
2015-05-11 15:40:07 -04:00
|
|
|
std::cerr << "RsVOIPSerialiser::serialiseVOIPPingItem() Size Error! " << std::endl;
|
2012-02-19 16:13:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
2015-08-10 22:13:50 -04:00
|
|
|
bool RsVOIPBandwidthItem::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, PacketId(), tlvsize);
|
|
|
|
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsVOIPSerialiser::serialiseVOIPBandwidthItem() Header: " << ok << std::endl;
|
|
|
|
std::cerr << "RsVOIPSerialiser::serialiseVOIPBandwidthItem() Size: " << tlvsize << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
/* add mandatory parts first */
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, flags);
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, bytes_per_sec);
|
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
std::cerr << "RsVOIPSerialiser::serialiseVOIPBandwidthItem() Size Error! " << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
2012-02-19 16:13:20 -05:00
|
|
|
/* serialise the data to the buffer */
|
2015-05-11 15:40:07 -04:00
|
|
|
bool RsVOIPDataItem::serialise(void *data, uint32_t& pktsize)
|
2012-02-19 16:13:20 -05:00
|
|
|
{
|
|
|
|
uint32_t tlvsize = serial_size() ;
|
|
|
|
uint32_t offset = 0;
|
|
|
|
|
|
|
|
if (pktsize < tlvsize)
|
|
|
|
return false; /* not enough space */
|
|
|
|
|
|
|
|
pktsize = tlvsize;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2012-02-19 16:13:20 -05:00
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
|
|
|
|
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
2015-05-11 15:40:07 -04:00
|
|
|
std::cerr << "RsVOIPSerialiser::serialiseVOIPDataItem() Header: " << ok << std::endl;
|
|
|
|
std::cerr << "RsVOIPSerialiser::serialiseVOIPDataItem() Size: " << tlvsize << std::endl;
|
2012-02-19 16:13:20 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
/* add mandatory parts first */
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, flags);
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, data_size);
|
2014-07-20 16:50:36 -04:00
|
|
|
|
|
|
|
memcpy( &((uint8_t*)data)[offset],voip_data,data_size) ;
|
2012-02-19 16:13:20 -05:00
|
|
|
offset += data_size ;
|
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
2015-05-11 15:40:07 -04:00
|
|
|
std::cerr << "RsVOIPSerialiser::serialiseVOIPPingItem() Size Error! " << std::endl;
|
2012-02-19 16:13:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
2012-02-19 03:32:47 -05:00
|
|
|
/* serialise the data to the buffer */
|
2015-05-11 15:40:07 -04:00
|
|
|
bool RsVOIPPingItem::serialise(void *data, uint32_t& pktsize)
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
2012-02-19 16:13:20 -05:00
|
|
|
uint32_t tlvsize = serial_size() ;
|
2012-02-19 03:32:47 -05:00
|
|
|
uint32_t offset = 0;
|
|
|
|
|
2012-02-19 16:13:20 -05:00
|
|
|
if (pktsize < tlvsize)
|
2012-02-19 03:32:47 -05:00
|
|
|
return false; /* not enough space */
|
|
|
|
|
2012-02-19 16:13:20 -05:00
|
|
|
pktsize = tlvsize;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
2012-02-19 16:13:20 -05:00
|
|
|
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
2015-05-11 15:40:07 -04:00
|
|
|
std::cerr << "RsVOIPSerialiser::serialiseVOIPPingItem() Header: " << ok << std::endl;
|
|
|
|
std::cerr << "RsVOIPSerialiser::serialiseVOIPPingItem() Size: " << tlvsize << std::endl;
|
2012-02-19 03:32:47 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
/* add mandatory parts first */
|
2012-02-19 16:13:20 -05:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, mSeqNo);
|
|
|
|
ok &= setRawUInt64(data, tlvsize, &offset, mPingTS);
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
2015-05-11 15:40:07 -04:00
|
|
|
std::cerr << "RsVOIPSerialiser::serialiseVOIPPingItem() Size Error! " << std::endl;
|
2012-02-19 03:32:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
RsVOIPProtocolItem::RsVOIPProtocolItem(void *data, uint32_t pktsize)
|
|
|
|
: RsVOIPItem(RS_PKT_SUBTYPE_VOIP_PROTOCOL)
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
|
|
|
/* get the type and size */
|
|
|
|
uint32_t rstype = getRsItemId(data);
|
|
|
|
uint32_t rssize = getRsItemSize(data);
|
|
|
|
|
|
|
|
uint32_t offset = 0;
|
|
|
|
|
2014-07-20 16:50:36 -04:00
|
|
|
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_VOIP_PLUGIN != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_VOIP_PROTOCOL != getRsItemSubType(rstype)))
|
2012-02-19 16:13:20 -05:00
|
|
|
throw std::runtime_error("Wrong packet type!") ;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2012-02-19 16:13:20 -05:00
|
|
|
if (pktsize < rssize) /* check size */
|
|
|
|
throw std::runtime_error("Not enough size!") ;
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2012-02-19 16:13:20 -05:00
|
|
|
/* get mandatory parts first */
|
2015-10-10 09:21:59 -04:00
|
|
|
uint32_t uint_Protocol;
|
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &uint_Protocol);
|
|
|
|
protocol = static_cast<en_Protocol>(uint_Protocol);
|
2012-02-19 16:13:20 -05:00
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &flags);
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2012-02-19 16:13:20 -05:00
|
|
|
if (offset != rssize)
|
|
|
|
throw std::runtime_error("Deserialisation error!") ;
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
throw std::runtime_error("Deserialisation error!") ;
|
|
|
|
}
|
2015-08-10 22:13:50 -04:00
|
|
|
RsVOIPBandwidthItem::RsVOIPBandwidthItem(void *data, uint32_t pktsize)
|
|
|
|
: RsVOIPItem(RS_PKT_SUBTYPE_VOIP_BANDWIDTH)
|
|
|
|
{
|
|
|
|
/* 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_VOIP_PLUGIN != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_VOIP_BANDWIDTH != getRsItemSubType(rstype)))
|
|
|
|
throw std::runtime_error("Wrong packet type!") ;
|
|
|
|
|
|
|
|
if (pktsize < rssize) /* check size */
|
|
|
|
throw std::runtime_error("Not enough size!") ;
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
/* get mandatory parts first */
|
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &flags);
|
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &bytes_per_sec);
|
|
|
|
|
|
|
|
if (offset != rssize)
|
|
|
|
throw std::runtime_error("Deserialisation error!") ;
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
throw std::runtime_error("Deserialisation error!") ;
|
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
RsVOIPPingItem::RsVOIPPingItem(void *data, uint32_t pktsize)
|
|
|
|
: RsVOIPItem(RS_PKT_SUBTYPE_VOIP_PING)
|
2012-02-19 16:13:20 -05:00
|
|
|
{
|
|
|
|
/* get the type and size */
|
|
|
|
uint32_t rstype = getRsItemId(data);
|
|
|
|
uint32_t rssize = getRsItemSize(data);
|
|
|
|
|
|
|
|
uint32_t offset = 0;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
|
2012-02-26 12:13:54 -05:00
|
|
|
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_VOIP_PLUGIN != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_VOIP_PING != getRsItemSubType(rstype)))
|
2012-02-19 16:13:20 -05:00
|
|
|
throw std::runtime_error("Wrong packet type!") ;
|
|
|
|
|
|
|
|
if (pktsize < rssize) /* check size */
|
|
|
|
throw std::runtime_error("Not enough size!") ;
|
|
|
|
|
|
|
|
bool ok = true;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
/* get mandatory parts first */
|
2012-02-19 16:13:20 -05:00
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &mSeqNo);
|
|
|
|
ok &= getRawUInt64(data, rssize, &offset, &mPingTS);
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
if (offset != rssize)
|
2012-02-19 16:13:20 -05:00
|
|
|
throw std::runtime_error("Deserialisation error!") ;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
if (!ok)
|
2012-02-19 16:13:20 -05:00
|
|
|
throw std::runtime_error("Deserialisation error!") ;
|
2012-02-19 03:32:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
uint32_t RsVOIPPongItem::serial_size() const
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
|
|
|
uint32_t s = 8; /* header */
|
|
|
|
s += 4; /* seqno */
|
|
|
|
s += 8; /* pingTS */
|
|
|
|
s += 8; /* pongTS */
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* serialise the data to the buffer */
|
2015-05-11 15:40:07 -04:00
|
|
|
bool RsVOIPPongItem::serialise(void *data, uint32_t& pktsize)
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
2012-02-19 16:13:20 -05:00
|
|
|
uint32_t tlvsize = serial_size() ;
|
2012-02-19 03:32:47 -05:00
|
|
|
uint32_t offset = 0;
|
|
|
|
|
2012-02-19 16:13:20 -05:00
|
|
|
if (pktsize < tlvsize)
|
2012-02-19 03:32:47 -05:00
|
|
|
return false; /* not enough space */
|
|
|
|
|
2012-02-19 16:13:20 -05:00
|
|
|
pktsize = tlvsize;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
2012-02-19 16:13:20 -05:00
|
|
|
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
2015-05-11 15:40:07 -04:00
|
|
|
std::cerr << "RsVOIPSerialiser::serialiseVOIPPongItem() Header: " << ok << std::endl;
|
|
|
|
std::cerr << "RsVOIPSerialiser::serialiseVOIPPongItem() Size: " << tlvsize << std::endl;
|
2012-02-19 03:32:47 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
/* add mandatory parts first */
|
2012-02-19 16:13:20 -05:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, mSeqNo);
|
|
|
|
ok &= setRawUInt64(data, tlvsize, &offset, mPingTS);
|
|
|
|
ok &= setRawUInt64(data, tlvsize, &offset, mPongTS);
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
2015-05-11 15:40:07 -04:00
|
|
|
std::cerr << "RsVOIPSerialiser::serialiseVOIPPongItem() Size Error! " << std::endl;
|
2012-02-19 03:32:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
RsVOIPDataItem::RsVOIPDataItem(void *data, uint32_t pktsize)
|
|
|
|
: RsVOIPItem(RS_PKT_SUBTYPE_VOIP_DATA)
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
|
|
|
/* get the type and size */
|
|
|
|
uint32_t rstype = getRsItemId(data);
|
|
|
|
uint32_t rssize = getRsItemSize(data);
|
|
|
|
|
|
|
|
uint32_t offset = 0;
|
|
|
|
|
2012-02-26 12:13:54 -05:00
|
|
|
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_VOIP_PLUGIN != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_VOIP_DATA != getRsItemSubType(rstype)))
|
2012-02-19 16:13:20 -05:00
|
|
|
throw std::runtime_error("Wrong packet subtype") ;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2012-02-19 16:13:20 -05:00
|
|
|
if (pktsize < rssize) /* check size */
|
|
|
|
throw std::runtime_error("Not enough space") ;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
/* get mandatory parts first */
|
2012-02-19 16:13:20 -05:00
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &flags);
|
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &data_size);
|
|
|
|
|
2016-01-11 20:26:19 -05:00
|
|
|
if(data_size > rssize || rssize - data_size < offset)
|
|
|
|
throw std::runtime_error("Not enough space.") ;
|
|
|
|
|
2016-01-12 21:10:11 -05:00
|
|
|
voip_data = rs_safe_malloc(data_size) ;
|
|
|
|
|
|
|
|
if(!voip_data)
|
|
|
|
throw std::runtime_error("Serialization error.") ;
|
|
|
|
|
2012-02-19 16:13:20 -05:00
|
|
|
memcpy(voip_data,&((uint8_t*)data)[offset],data_size) ;
|
|
|
|
offset += data_size ;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
if (offset != rssize)
|
2012-02-19 16:13:20 -05:00
|
|
|
throw std::runtime_error("Serialization error.") ;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
if (!ok)
|
2012-02-19 16:13:20 -05:00
|
|
|
throw std::runtime_error("Serialization error.") ;
|
2012-02-19 03:32:47 -05:00
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
RsVOIPPongItem::RsVOIPPongItem(void *data, uint32_t pktsize)
|
|
|
|
: RsVOIPItem(RS_PKT_SUBTYPE_VOIP_PONG)
|
2012-02-19 16:13:20 -05:00
|
|
|
{
|
|
|
|
/* get the type and size */
|
|
|
|
uint32_t rstype = getRsItemId(data);
|
|
|
|
uint32_t rssize = getRsItemSize(data);
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2012-02-19 16:13:20 -05:00
|
|
|
uint32_t offset = 0;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2012-02-26 12:13:54 -05:00
|
|
|
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_VOIP_PLUGIN != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_VOIP_PONG != getRsItemSubType(rstype)))
|
2012-02-19 16:13:20 -05:00
|
|
|
throw std::runtime_error("Wrong packet subtype") ;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2012-02-19 16:13:20 -05:00
|
|
|
if (pktsize < rssize) /* check size */
|
|
|
|
throw std::runtime_error("Not enough space") ;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2012-02-19 16:13:20 -05:00
|
|
|
bool ok = true;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2012-02-19 16:13:20 -05:00
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2012-02-19 16:13:20 -05:00
|
|
|
/* get mandatory parts first */
|
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &mSeqNo);
|
|
|
|
ok &= getRawUInt64(data, rssize, &offset, &mPingTS);
|
|
|
|
ok &= getRawUInt64(data, rssize, &offset, &mPongTS);
|
|
|
|
|
|
|
|
if (offset != rssize)
|
|
|
|
throw std::runtime_error("Serialization error.") ;
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
throw std::runtime_error("Serialization error.") ;
|
2012-02-19 03:32:47 -05:00
|
|
|
}
|
|
|
|
|
2012-02-19 16:13:20 -05:00
|
|
|
/*************************************************************************/
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
RsItem* RsVOIPSerialiser::deserialise(void *data, uint32_t *pktsize)
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
2015-05-11 15:40:07 -04:00
|
|
|
std::cerr << "RsVOIPSerialiser::deserialise()" << std::endl;
|
2012-02-19 03:32:47 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get the type and size */
|
|
|
|
uint32_t rstype = getRsItemId(data);
|
|
|
|
|
2012-02-26 12:13:54 -05:00
|
|
|
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_VOIP_PLUGIN != getRsItemService(rstype)))
|
2012-02-19 16:13:20 -05:00
|
|
|
return NULL ;
|
|
|
|
|
|
|
|
try
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
2012-02-19 16:13:20 -05:00
|
|
|
switch(getRsItemSubType(rstype))
|
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
case RS_PKT_SUBTYPE_VOIP_PING: return new RsVOIPPingItem(data, *pktsize);
|
|
|
|
case RS_PKT_SUBTYPE_VOIP_PONG: return new RsVOIPPongItem(data, *pktsize);
|
|
|
|
case RS_PKT_SUBTYPE_VOIP_PROTOCOL: return new RsVOIPProtocolItem(data, *pktsize);
|
|
|
|
case RS_PKT_SUBTYPE_VOIP_DATA: return new RsVOIPDataItem(data, *pktsize);
|
2012-02-19 16:13:20 -05:00
|
|
|
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-02-19 03:32:47 -05:00
|
|
|
}
|
2012-02-19 16:13:20 -05:00
|
|
|
catch(std::exception& e)
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
std::cerr << "RsVOIPSerialiser: deserialization error: " << e.what() << std::endl;
|
2012-02-19 16:13:20 -05:00
|
|
|
return NULL;
|
2012-02-19 03:32:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|