2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* libretroshare/src/serialiser: rsvoipitems.cc
|
|
|
|
*
|
|
|
|
* RetroShare Serialiser.
|
|
|
|
*
|
|
|
|
* Copyright 2011 by 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-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"
|
|
|
|
|
2012-02-19 10:07:47 -05:00
|
|
|
#include "services/rsvoipitems.h"
|
|
|
|
|
2012-02-19 03:32:47 -05:00
|
|
|
/***
|
|
|
|
#define RSSERIAL_DEBUG 1
|
|
|
|
***/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
std::ostream& RsVoipPingItem::print(std::ostream &out, uint16_t indent)
|
|
|
|
{
|
|
|
|
printRsItemBase(out, "RsVoipPingItem", indent);
|
|
|
|
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;
|
|
|
|
|
|
|
|
printRsItemEnd(out, "RsVoipPingItem", indent);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream& RsVoipPongItem::print(std::ostream &out, uint16_t indent)
|
|
|
|
{
|
|
|
|
printRsItemBase(out, "RsVoipPongItem", indent);
|
|
|
|
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;
|
|
|
|
|
|
|
|
printRsItemEnd(out, "RsVoipPongItem", indent);
|
|
|
|
return out;
|
|
|
|
}
|
2012-02-21 16:53:25 -05:00
|
|
|
std::ostream& RsVoipProtocolItem::print(std::ostream &out, uint16_t indent)
|
|
|
|
{
|
|
|
|
printRsItemBase(out, "RsVoipProtocolItem", indent);
|
|
|
|
uint16_t int_Indent = indent + 2;
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "flags: " << flags << std::endl;
|
|
|
|
|
|
|
|
printIndent(out, int_Indent);
|
|
|
|
out << "protocol: " << std::hex << protocol << std::dec << std::endl;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2012-02-21 16:53:25 -05:00
|
|
|
printRsItemEnd(out, "RsVoipProtocolItem", indent);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
std::ostream& RsVoipDataItem::print(std::ostream &out, uint16_t indent)
|
|
|
|
{
|
|
|
|
printRsItemBase(out, "RsVoipDataItem", indent);
|
|
|
|
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;
|
|
|
|
|
|
|
|
printRsItemEnd(out, "RsVoipDataItem", indent);
|
|
|
|
return out;
|
|
|
|
}
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
/*************************************************************************/
|
2012-02-19 16:13:20 -05:00
|
|
|
uint32_t RsVoipDataItem::serial_size() const
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
uint32_t RsVoipProtocolItem::serial_size() const
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2012-02-19 16:13:20 -05:00
|
|
|
bool RsVoipProtocolItem::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::serialiseVoipDataItem() Header: " << ok << std::endl;
|
|
|
|
std::cerr << "RsVoipSerialiser::serialiseVoipDataItem() Size: " << tlvsize << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* skip the header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
/* add mandatory parts first */
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, protocol);
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, flags);
|
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
std::cerr << "RsVoipSerialiser::serialiseVoipPingItem() Size Error! " << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
/* serialise the data to the buffer */
|
|
|
|
bool RsVoipDataItem::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;
|
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
|
|
|
|
std::cerr << "RsVoipSerialiser::serialiseVoipDataItem() Header: " << ok << std::endl;
|
|
|
|
std::cerr << "RsVoipSerialiser::serialiseVoipDataItem() 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, data_size);
|
2012-02-26 11:10:27 -05:00
|
|
|
std::cerr << "data_size : " << data_size << std::endl;
|
2012-11-18 11:22:58 -05:00
|
|
|
//memcpy(data+offset,voip_data,data_size) ;
|
|
|
|
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;
|
|
|
|
std::cerr << "RsVoipSerialiser::serialiseVoipPingItem() Size Error! " << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
2012-02-19 03:32:47 -05:00
|
|
|
/* serialise the data to the buffer */
|
2012-02-19 16:13:20 -05: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
|
|
|
|
std::cerr << "RsVoipSerialiser::serialiseVoipPingItem() Header: " << ok << std::endl;
|
|
|
|
std::cerr << "RsVoipSerialiser::serialiseVoipPingItem() Size: " << tlvsize << std::endl;
|
|
|
|
#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;
|
|
|
|
std::cerr << "RsVoipSerialiser::serialiseVoipPingItem() Size Error! " << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2012-02-19 16:13:20 -05: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;
|
|
|
|
|
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!") ;
|
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 */
|
|
|
|
ok &= getRawUInt32(data, rssize, &offset, &protocol);
|
|
|
|
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!") ;
|
|
|
|
}
|
|
|
|
RsVoipPingItem::RsVoipPingItem(void *data, uint32_t pktsize)
|
|
|
|
: RsVoipItem(RS_PKT_SUBTYPE_VOIP_PING)
|
|
|
|
{
|
|
|
|
/* 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
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
|
2012-02-19 16:13:20 -05: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 */
|
2012-02-19 16:13:20 -05: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
|
|
|
|
std::cerr << "RsVoipSerialiser::serialiseVoipPongItem() Header: " << ok << std::endl;
|
|
|
|
std::cerr << "RsVoipSerialiser::serialiseVoipPongItem() Size: " << tlvsize << std::endl;
|
|
|
|
#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;
|
|
|
|
std::cerr << "RsVoipSerialiser::serialiseVoipPongItem() Size Error! " << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
2012-02-19 16:13:20 -05: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);
|
|
|
|
|
|
|
|
voip_data = malloc(data_size) ;
|
|
|
|
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
|
|
|
}
|
2012-02-19 16:13:20 -05:00
|
|
|
RsVoipPongItem::RsVoipPongItem(void *data, uint32_t pktsize)
|
|
|
|
: RsVoipItem(RS_PKT_SUBTYPE_VOIP_PONG)
|
|
|
|
{
|
|
|
|
/* 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
|
|
|
/*************************************************************************/
|
|
|
|
|
2012-02-19 03:32:47 -05:00
|
|
|
RsItem* RsVoipSerialiser::deserialise(void *data, uint32_t *pktsize)
|
|
|
|
{
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsVoipSerialiser::deserialise()" << std::endl;
|
|
|
|
#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))
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2012-02-19 16:13:20 -05:00
|
|
|
std::cerr << "RsVoipSerialiser: deserialization error: " << e.what() << std::endl;
|
|
|
|
return NULL;
|
2012-02-19 03:32:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|