mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-14 09:29:30 -04:00
- moved RsAutoUpdatePage into retroshare-gui/ directory, to allow plugins to use it
- removed VOIP code from main executable. Moved it into VOIP plugin (c.f next commit) git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4963 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
0d4feb89b4
commit
ee5dcd1a8c
26 changed files with 18 additions and 1712 deletions
|
@ -1,373 +0,0 @@
|
|||
|
||||
/*
|
||||
* 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rsvoipitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
|
||||
RsVoipPingItem::~RsVoipPingItem()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void RsVoipPingItem::clear()
|
||||
{
|
||||
mSeqNo = 0;
|
||||
mPingTS = 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
RsVoipPongItem::~RsVoipPongItem()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void RsVoipPongItem::clear()
|
||||
{
|
||||
mSeqNo = 0;
|
||||
mPingTS = 0;
|
||||
mPongTS = 0;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
|
||||
uint32_t RsVoipSerialiser::sizeVoipPingItem(RsVoipPingItem */*item*/)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += 4; /* seqno */
|
||||
s += 8; /* pingTS */
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* serialise the data to the buffer */
|
||||
bool RsVoipSerialiser::serialiseVoipPingItem(RsVoipPingItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
uint32_t tlvsize = sizeVoipPingItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (*pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
#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 */
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->mSeqNo);
|
||||
ok &= setRawUInt64(data, tlvsize, &offset, item->mPingTS);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsVoipSerialiser::serialiseVoipPingItem() Size Error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsVoipPingItem *RsVoipSerialiser::deserialiseVoipPingItem(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* 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 != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_VOIP_PING != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*pktsize < rssize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*pktsize = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsVoipPingItem *item = new RsVoipPingItem();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* get mandatory parts first */
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->mSeqNo));
|
||||
ok &= getRawUInt64(data, rssize, &offset, &(item->mPingTS));
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
|
||||
uint32_t RsVoipSerialiser::sizeVoipPongItem(RsVoipPongItem */*item*/)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += 4; /* seqno */
|
||||
s += 8; /* pingTS */
|
||||
s += 8; /* pongTS */
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* serialise the data to the buffer */
|
||||
bool RsVoipSerialiser::serialiseVoipPongItem(RsVoipPongItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
uint32_t tlvsize = sizeVoipPongItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (*pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
#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 */
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->mSeqNo);
|
||||
ok &= setRawUInt64(data, tlvsize, &offset, item->mPingTS);
|
||||
ok &= setRawUInt64(data, tlvsize, &offset, item->mPongTS);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsVoipSerialiser::serialiseVoipPongItem() Size Error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsVoipPongItem *RsVoipSerialiser::deserialiseVoipPongItem(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* 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 != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_VOIP_PONG != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*pktsize < rssize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*pktsize = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsVoipPongItem *item = new RsVoipPongItem();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* get mandatory parts first */
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->mSeqNo));
|
||||
ok &= getRawUInt64(data, rssize, &offset, &(item->mPingTS));
|
||||
ok &= getRawUInt64(data, rssize, &offset, &(item->mPongTS));
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
uint32_t RsVoipSerialiser::size(RsItem *i)
|
||||
{
|
||||
RsVoipPingItem *ping;
|
||||
RsVoipPongItem *pong;
|
||||
|
||||
if (NULL != (ping = dynamic_cast<RsVoipPingItem *>(i)))
|
||||
{
|
||||
return sizeVoipPingItem(ping);
|
||||
}
|
||||
else if (NULL != (pong = dynamic_cast<RsVoipPongItem *>(i)))
|
||||
{
|
||||
return sizeVoipPongItem(pong);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool RsVoipSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
|
||||
{
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsMsgSerialiser::serialise()" << std::endl;
|
||||
#endif
|
||||
|
||||
RsVoipPingItem *ping;
|
||||
RsVoipPongItem *pong;
|
||||
|
||||
if (NULL != (ping = dynamic_cast<RsVoipPingItem *>(i)))
|
||||
{
|
||||
return serialiseVoipPingItem(ping, data, pktsize);
|
||||
}
|
||||
else if (NULL != (pong = dynamic_cast<RsVoipPongItem *>(i)))
|
||||
{
|
||||
return serialiseVoipPongItem(pong, data, pktsize);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_VOIP != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
case RS_PKT_SUBTYPE_VOIP_PING:
|
||||
return deserialiseVoipPingItem(data, pktsize);
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_VOIP_PONG:
|
||||
return deserialiseVoipPongItem(data, pktsize);
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
|
@ -1,108 +0,0 @@
|
|||
#ifndef RS_VOIP_ITEMS_H
|
||||
#define RS_VOIP_ITEMS_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsvoipitems.h
|
||||
*
|
||||
* 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_VOIP_PING = 0x01;
|
||||
const uint8_t RS_PKT_SUBTYPE_VOIP_PONG = 0x02;
|
||||
|
||||
class RsVoipItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsVoipItem(uint8_t chat_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_VOIP,chat_subtype)
|
||||
{ setPriorityLevel(QOS_PRIORITY_RS_VOIP_PING) ;} // should be refined later.
|
||||
|
||||
virtual ~RsVoipItem() {};
|
||||
virtual void clear() {};
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) = 0 ;
|
||||
};
|
||||
|
||||
class RsVoipPingItem: public RsVoipItem
|
||||
{
|
||||
public:
|
||||
RsVoipPingItem() :RsVoipItem(RS_PKT_SUBTYPE_VOIP_PING) {}
|
||||
|
||||
virtual ~RsVoipPingItem();
|
||||
virtual void clear();
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
uint32_t mSeqNo;
|
||||
uint64_t mPingTS;
|
||||
};
|
||||
|
||||
class RsVoipPongItem: public RsVoipItem
|
||||
{
|
||||
public:
|
||||
RsVoipPongItem() :RsVoipItem(RS_PKT_SUBTYPE_VOIP_PONG) {}
|
||||
|
||||
virtual ~RsVoipPongItem();
|
||||
virtual void clear();
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
uint32_t mSeqNo;
|
||||
uint64_t mPingTS;
|
||||
uint64_t mPongTS;
|
||||
};
|
||||
|
||||
|
||||
class RsVoipSerialiser: public RsSerialType
|
||||
{
|
||||
public:
|
||||
RsVoipSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_VOIP)
|
||||
{ return; }
|
||||
|
||||
virtual ~RsVoipSerialiser() { return; }
|
||||
|
||||
virtual uint32_t size(RsItem *);
|
||||
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
|
||||
virtual RsItem * deserialise(void *data, uint32_t *size);
|
||||
|
||||
private:
|
||||
|
||||
virtual uint32_t sizeVoipPingItem(RsVoipPingItem *);
|
||||
virtual bool serialiseVoipPingItem (RsVoipPingItem *item, void *data, uint32_t *size);
|
||||
virtual RsVoipPingItem *deserialiseVoipPingItem(void *data, uint32_t *size);
|
||||
|
||||
virtual uint32_t sizeVoipPongItem(RsVoipPongItem *);
|
||||
virtual bool serialiseVoipPongItem (RsVoipPongItem *item, void *data, uint32_t *size);
|
||||
virtual RsVoipPongItem *deserialiseVoipPongItem(void *data, uint32_t *size);
|
||||
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#endif /* RS_VOIP_ITEMS_H */
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue