Commit 8635de51 authored by pierre-luc's avatar pierre-luc

[#811] Got out of a precarious position were nothing would compile.

Inclusions were flawed and were creating cycles. Many header files were
fixed following :
"A header file should be included only when a forward declaration
would not do the job." principle.

ZRTP configuration re-added to getAccountDetails/setAccountDetails
parent 5509e52e
......@@ -48,7 +48,8 @@ typedef enum RegistrationState {
ErrorNetwork ,
ErrorHost,
ErrorExistStun,
ErrorConfStun
ErrorConfStun,
NumberOfState
} RegistrationState;
#define AccountNULL ""
......
......@@ -19,6 +19,8 @@
#include "alsalayer.h"
#include "managerimpl.h"
int framesPerBufferAlsa = 2048;
// Constructor
......
......@@ -25,7 +25,7 @@
#include "global.h"
#include "audiodevice.h"
#include "ringbuffer.h"
#include "manager.h"
#include <cc++/thread.h> // for ost::Mutex
......@@ -37,6 +37,8 @@
* @brief Main sound class. Manages the data transfers between the application and the hardware.
*/
class ManagerImpl;
class AudioLayer {
private:
......
......@@ -23,7 +23,7 @@
#define __AUDIOLOOP_H__
#include <string>
#include "../global.h" // for int16 declaration
#include "global.h" // for int16 declaration
/**
* @file audioloop.h
......
......@@ -16,14 +16,17 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <assert.h>
#include "AudioRtpFactory.h"
#include "AudioSymmetricRtpSession.h"
#include "AudioZrtpSession.h"
#include "AudioSymmetricRtpSession.h"
#include "manager.h"
#include "account.h"
#include "sip/sipcall.h"
#include <assert.h>
namespace sfl {
......@@ -83,7 +86,7 @@ namespace sfl {
switch(keyExchangeProtocol) {
case Zrtp:
_rtpSession = new AudioZrtpSession(ca, zidFilename);
_rtpSession = new AudioZrtpSession(&Manager::instance(), ca, zidFilename);
_rtpSessionType = Zrtp;
if (helloHashEnabled) {
// TODO: be careful with that. The hello hash is computed asynchronously. Maybe it's
......@@ -98,7 +101,7 @@ namespace sfl {
}
} else {
_rtpSessionType = Symmetric;
_rtpSession = new AudioSymmetricRtpSession(ca);
_rtpSession = new AudioSymmetricRtpSession(&Manager::instance(), ca);
_debug("Starting a symmetric unencrypted rtp session\n");
}
}
......@@ -152,4 +155,13 @@ namespace sfl {
throw AudioRtpFactoryException();
}
}
sfl::AudioZrtpSession * AudioRtpFactory::getAudioZrtpSession()
{
if ((_rtpSessionType == Zrtp) && (_rtpSessionType != NULL)) {
return static_cast<AudioZrtpSession *>(_rtpSession);
} else {
throw AudioRtpFactoryException();
}
}
}
......@@ -16,18 +16,21 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __AUDIO_RTP_FACTORY_H__
#define __AUDIO_RTP_FACTORY_H__
#ifndef __SFL_AUDIO_RTP_FACTORY_H__
#define __SFL_AUDIO_RTP_FACTORY_H__
#include <exception>
#include <cc++/thread.h>
#include "sip/sipcall.h"
class SIPCall;
namespace sfl {
class AudioZrtpSession;
}
namespace sfl {
class AudioZrtpSession;
// Possible kind of rtp session
typedef enum RtpMethod {
Symmetric,
......@@ -79,12 +82,19 @@ namespace sfl {
*/
void stop();
/**
* @param None
* @return The internal audio rtp thread of the type specified in the configuration
* file. initAudioRtpSession must have been called prior to that.
*/
/**
* @param None
* @return The internal audio rtp thread of the type specified in the configuration
* file. initAudioRtpSession must have been called prior to that.
*/
inline void * getAudioRtpSession(void) { return _rtpSession; }
/**
* Get the current AudioZrtpSession. Throws an AudioRtpFactoryException
* if the current rtp thread is null, or if it's not of the correct type.
* @return The current AudioZrtpSession thread.
*/
sfl::AudioZrtpSession * getAudioZrtpSession();
private:
void * _rtpSession;
......
......@@ -20,23 +20,27 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __AUDIO_RTP_SESSION_H__
#define __AUDIO_RTP_SESSION_H__
#ifndef __SFL_AUDIO_RTP_SESSION_H__
#define __SFL_AUDIO_RTP_SESSION_H__
#include <iostream>
#include <exception>
#include <ccrtp/rtp.h>
#include <cc++/thread.h>
#include <cc++/numbers.h>
#include <cc++/socket.h>
#include "global.h"
#include "sip/sipcall.h"
#include "audio/samplerateconverter.h"
#include "audio/codecs/audiocodec.h"
#include "sip/sdp.h"
#include "audio/audiolayer.h"
#include "audio/codecs/audiocodec.h"
#include "audio/samplerateconverter.h"
#include "managerimpl.h"
class SIPCall;
#include <ccrtp/rtp.h>
//#include <ccrtp/formats.h>
//#include <ccrtp/queuebase.h>
//#include <cc++/thread.h>
#include <cc++/numbers.h>
//#include <cc++/socket.h>
namespace sfl {
......@@ -58,7 +62,7 @@ namespace sfl {
* Constructor
* @param sipcall The pointer on the SIP call
*/
AudioRtpSession (SIPCall* sipcall);
AudioRtpSession (ManagerImpl * manager, SIPCall* sipcall);
~AudioRtpSession();
......@@ -143,13 +147,18 @@ namespace sfl {
*/
int _nbSamplesMax;
/**
* Manager instance.
*/
ManagerImpl * _manager;
protected:
SIPCall * _ca;
};
template <typename D>
AudioRtpSession<D>::AudioRtpSession(SIPCall * sipcall) :
AudioRtpSession<D>::AudioRtpSession(ManagerImpl * manager, SIPCall * sipcall) :
_time (new ost::Time()),
_mainloopSemaphore(0),
_audiocodec (NULL),
......@@ -163,7 +172,8 @@ namespace sfl {
_converter (NULL),
_layerSampleRate(0),
_codecSampleRate(0),
_layerFrameSize(0)
_layerFrameSize(0),
_manager(manager)
{
setCancel (cancelDefault);
......@@ -172,7 +182,7 @@ namespace sfl {
_debug ("Local audio port %i will be used\n", _ca->getLocalAudioPort());
//mic, we receive from soundcard in stereo, and we send encoded
_audiolayer = Manager::instance().getAudioDriver();
_audiolayer = _manager->getAudioDriver();
if (_audiolayer == NULL) { throw AudioRtpSessionException(); }
......@@ -354,11 +364,11 @@ namespace sfl {
// Notify (with a beep) an incoming call when there is already a call
countTime += _time->getSecond();
if (Manager::instance().incomingCallWaiting() > 0) {
if (_manager->incomingCallWaiting() > 0) {
countTime = countTime % 500; // more often...
if (countTime == 0) {
Manager::instance().notificationIncomingCall();
_manager->notificationIncomingCall();
}
}
......
......@@ -15,20 +15,22 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __AUDIO_SYMMETRIC_RTP_SESSION_H__
#define __AUDIO_SYMMETRIC_RTP_SESSION_H__
#ifndef __SFL_AUDIO_SYMMETRIC_RTP_SESSION_H__
#define __SFL_AUDIO_SYMMETRIC_RTP_SESSION_H__
#include <ccrtp/rtp.h>
#include "AudioRtpSession.h"
class ManagerImpl;
namespace sfl {
class AudioSymmetricRtpSession : public ost::SymmetricRTPSession, public AudioRtpSession<AudioSymmetricRtpSession>
{
public:
AudioSymmetricRtpSession(SIPCall * sipcall) :
AudioSymmetricRtpSession(ManagerImpl * manager, SIPCall * sipcall) :
ost::SymmetricRTPSession(ost::InetHostAddress(sipcall->getLocalIp().c_str()), sipcall->getLocalAudioPort()),
AudioRtpSession<AudioSymmetricRtpSession>(sipcall)
AudioRtpSession<AudioSymmetricRtpSession>(manager, sipcall)
{
_debug("AudioSymmetricRtpSession initialized\n");
}
......
......@@ -19,6 +19,8 @@
#include "ZrtpSessionCallback.h"
#include "user_cfg.h"
#include "sip/sipcall.h"
#include <libzrtpcpp/ZrtpQueue.h>
#include <libzrtpcpp/ZrtpUserCallback.h>
......@@ -28,6 +30,16 @@
namespace sfl {
AudioZrtpSession::AudioZrtpSession(ManagerImpl * manager, SIPCall * sipcall, const std::string& zidFilename) :
ost::SymmetricZRTPSession(ost::InetHostAddress(sipcall->getLocalIp().c_str()), sipcall->getLocalAudioPort()),
AudioRtpSession<AudioZrtpSession>(manager, sipcall),
_zidFilename(zidFilename)
{
_debug("AudioZrtpSession initialized\n");
initializeZid();
startZrtp();
}
void AudioZrtpSession::initializeZid(void)
{
......
......@@ -15,14 +15,15 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __AUDIO_ZRTP_SESSION_H__
#define __AUDIO_ZRTP_SESSION_H__
#ifndef __SFL_AUDIO_ZRTP_SESSION_H__
#define __SFL_AUDIO_ZRTP_SESSION_H__
#include "AudioRtpSession.h"
#include <libzrtpcpp/zrtpccrtp.h>
#include <iostream>
#include "AudioRtpSession.h"
#include <libzrtpcpp/zrtpccrtp.h>
class ManagerImpl;
class SIPCall;
namespace sfl {
......@@ -38,15 +39,7 @@ namespace sfl {
{
public:
AudioZrtpSession(SIPCall * sipcall, const std::string& zidFilename) :
ost::SymmetricZRTPSession(ost::InetHostAddress(sipcall->getLocalIp().c_str()), sipcall->getLocalAudioPort()),
AudioRtpSession<AudioZrtpSession>(sipcall),
_zidFilename(zidFilename)
{
_debug("AudioZrtpSession initialized\n");
initializeZid();
startZrtp();
}
AudioZrtpSession(ManagerImpl * manager, SIPCall * sipcall, const std::string& zidFilename);
private:
void initializeZid(void);
......
......@@ -18,7 +18,7 @@
*/
#include "ZrtpSessionCallback.h"
#include "managerimpl.h"
#include "manager.h"
#include "global.h"
#include <cstdlib>
......
......@@ -17,8 +17,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __ZRTP_CALLBACK_H__
#define __ZRTP_CALLBACK_H__
#ifndef __SFL_ZRTP_CALLBACK_H__
#define __SFL_ZRTP_CALLBACK_H__
#include <libzrtpcpp/zrtpccrtp.h>
#include <libzrtpcpp/ZrtpQueue.h>
......
......@@ -18,6 +18,7 @@
*/
#include "pulselayer.h"
#include "managerimpl.h"
int framesPerBuffer = 2048;
......
......@@ -17,6 +17,7 @@
*/
#include "samplerateconverter.h"
#include "manager.h"
SamplerateConverter::SamplerateConverter (void)
: _frequence (Manager::instance().getConfigInt (AUDIO , ALSA_SAMPLE_RATE)) //44100
......
......@@ -23,7 +23,7 @@
#include <math.h>
#include "global.h"
#include "manager.h"
class SamplerateConverter {
public:
......
......@@ -116,7 +116,7 @@ ConfigTree::addConfigTreeItem (const std::string& section, const ConfigTreeItem
}
}
// throw a ConfigTreeItemException if not found
// Return an empty string if not found
std::string
ConfigTree::getConfigTreeItemValue (const std::string& section, const std::string& itemName)
{
......
......@@ -117,6 +117,31 @@
<signal name="transferFailed">
</signal>
<method name="setSASVerified">
<arg type="s" name="callID" direction="in"/>
</method>
<method name="resetSASVerified">
<arg type="s" name="callID" direction="in"/>
</method>
<method name="setConfirmGoClear">
<arg type="s" name="callID" direction="in"/>
</method>
<method name="requestGoClear">
<arg type="s" name="callID" direction="in"/>
</method>
<method name="acceptEnrollment">
<arg type="s" name="callID" direction="in"/>
<arg type="b" name="accepted" direction="in"/>
</method>
<method name="setPBXEnrollment">
<arg type="s" name="callID" direction="in"/>
<arg type="b" name="yesNo" direction="in"/>
</method>
<!--
<signal name="error">
<annotation name="com.trolltech.QtDBus.QtTypeName.In0" value="MapStringString"/>
......
......@@ -18,9 +18,14 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <global.h>
#include <callmanager.h>
#include "../manager.h"
#include "global.h"
#include "callmanager.h"
#include "sip/sipvoiplink.h"
#include "audio/audiortp/AudioRtpFactory.h"
#include "audio/audiortp/AudioZrtpSession.h"
#include "manager.h"
const char* CallManager::SERVER_PATH = "/org/sflphone/SFLphone/CallManager";
......@@ -178,3 +183,122 @@ CallManager::startTone (const int32_t& start , const int32_t& type)
Manager::instance().stopTone (true);
}
// TODO: this will have to be adapted
// for conferencing in order to get
// the right pointer for the given
// callID.
sfl::AudioZrtpSession * CallManager::getAudioZrtpSession(void)
{
SIPVoIPLink * link = NULL;
link = dynamic_cast<SIPVoIPLink *> (Manager::instance().getAccountLink (AccountNULL));
if (link == NULL) {
_debug ("Failed to get sip link\n");
throw CallManagerException();
}
sfl::AudioRtpFactory * audioRtp = NULL;
audioRtp = link->getAudioRtp();
if (audioRtp == NULL) {
_debug ("Failed to get AudioRtpFactory\n");
throw CallManagerException();
}
sfl::AudioZrtpSession * zSession = NULL;
zSession = audioRtp->getAudioZrtpSession();
if (zSession == NULL) {
_debug("Failed to get AudioZrtpSession\n");
throw CallManagerException();
}
return zSession;
}
void
CallManager::setSASVerified(const std::string& callID)
{
_debug("CallManager::setSASVerified received for account %s\n", callID.c_str());
try {
sfl::AudioZrtpSession * zSession;
zSession = getAudioZrtpSession();
zSession->SASVerified();
} catch (...) {
throw;
}
}
void
CallManager::resetSASVerified(const std::string& callID)
{
_debug("CallManager::resetSASVerified received for account %s\n", callID.c_str());
try {
sfl::AudioZrtpSession * zSession;
zSession = getAudioZrtpSession();
zSession->resetSASVerified();
} catch (...) {
throw;
}
}
void
CallManager::setConfirmGoClear(const std::string& callID)
{
_debug("CallManager::setConfirmGoClear received for account %s\n", callID.c_str());
try {
sfl::AudioZrtpSession * zSession;
zSession = getAudioZrtpSession();
zSession->goClearOk();
} catch (...) {
throw;
}
}
void
CallManager::requestGoClear(const std::string& callID)
{
_debug("CallManager::requestGoClear received for account %s\n", callID.c_str());
try {
sfl::AudioZrtpSession * zSession;
zSession = getAudioZrtpSession();
zSession->requestGoClear();
} catch (...) {
throw;
}
}
void
CallManager::acceptEnrollment(const std::string& callID, const bool& accepted) {
_debug("CallManager::acceptEnrollment received for account %s\n", callID.c_str());
try {
sfl::AudioZrtpSession * zSession;
zSession = getAudioZrtpSession();
zSession->acceptEnrollment(accepted);
} catch (...) {
throw;
}
}
void
CallManager::setPBXEnrollment(const std::string& callID, const bool& yesNo) {
_debug("CallManager::setPBXEnrollment received for account %s\n", callID.c_str());
try {
sfl::AudioZrtpSession * zSession;
zSession = getAudioZrtpSession();
zSession->setPBXEnrollment(yesNo);
} catch (...) {
throw;
}
}
......@@ -17,48 +17,69 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef CALLMANAGER_H
#define CALLMANAGER_H
#ifndef __SFL_CALLMANAGER_H__
#define __SFL_CALLMANAGER_H__
#include "callmanager-glue.h"
#include <dbus-c++/dbus.h>
#include <exception>
class CallManagerException: public std::exception
{
virtual const char* what() const throw()
{
return "A CallManagerException occured";
}
};
namespace sfl {
class AudioZrtpSession;
}
class CallManager
: public org::sflphone::SFLphone::CallManager_adaptor,
public DBus::IntrospectableAdaptor,
public DBus::ObjectAdaptor
{
public:
public:
CallManager(DBus::Connection& connection);
static const char* SERVER_PATH;
CallManager(DBus::Connection& connection);
static const char* SERVER_PATH;
/* methods exported by this interface,
* you will have to implement them in your ObjectAdaptor
*/
void placeCall( const std::string& accountID, const std::string& callID, const std::string& to );
void refuse( const std::string& callID );
void accept( const std::string& callID );
void hangUp( const std::string& callID );
void hold( const std::string& callID );
void unhold( const std::string& callID );
void transfert( const std::string& callID, const std::string& to );
void setVolume( const std::string& device, const double& value );
double getVolume( const std::string& device );
void setRecording( const std::string& callID );
bool getIsRecording(const std::string& callID);
std::string getCurrentCodecName(const std::string& callID);
std::map< std::string, std::string > getCallDetails( const std::string& callID );
std::vector< std::string > getCallList (void);
public:
std::string getCurrentCallID( );
void playDTMF( const std::string& key );
void startTone( const int32_t& start, const int32_t& type );
/* methods exported by this interface,
* you will have to implement them in your ObjectAdaptor
*/
void placeCall( const std::string& accountID, const std::string& callID, const std::string& to );
void refuse( const std::string& callID );
void accept( const std::string& callID );
void hangUp( const std::string& callID );
void hold( const std::string& callID );
void unhold( const std::string& callID );
void transfert( const std::string& callID, const std::string& to );
void setVolume( const std::string& device, const double& value );
double getVolume( const std::string& device );
void setRecording( const std::string& callID );
bool getIsRecording(const std::string& callID);
std::string getCurrentCodecName(const std::string& callID);
std::map< std::string, std::string > getCallDetails( const std::string& callID );
std::vector< std::string > getCallList (void);
void setSASVerified(const std::string& callID);
void resetSASVerified(const std::string& callID);
void setConfirmGoClear(const std::string& callID);
void requestGoClear(const std::string& callID);
void acceptEnrollment(const std::string& callID, const bool& accepted);
void setPBXEnrollment(const std::string& callID, const bool& yesNo);
private:
std::string getCurrentCallID( );
void playDTMF( const std::string& key );
void startTone( const int32_t& start, const int32_t& type );
sfl::AudioZrtpSession * getAudioZrtpSession(void);
};
......
......@@ -23,7 +23,6 @@
#include <configurationmanager.h>
#include <sstream>
#include "../manager.h"
#include "../audio/audiortp/AudioRtpFactory.h"
const char* ConfigurationManager::SERVER_PATH = "/org/sflphone/SFLphone/ConfigurationManager";
......@@ -74,18 +73,18 @@ void
ConfigurationManager::setIp2IpDetails(const std::map< std::string, std::string >& details )
{
Manager::instance().setConfigOrDefaultEmptyField(details, IP2IP_PROFILE, SRTP_ENABLE);
Manager::instance().setConfigOrDefaultEmptyField(details, IP2IP_PROFILE, ZRTP_DISPLAY_SAS);
Manager::instance().setConfigOrDefaultEmptyField(details, IP2IP_PROFILE, ZRTP_NOT_SUPP_WARNING);
Manager::instance().setConfigOrDefaultEmptyField(details, IP2IP_PROFILE, ZRTP_HELLO_HASH);
Manager::instance().setConfigOrDefaultEmptyField(details, IP2IP_PROFILE, ZRTP_DISPLAY_SAS_ONCE);
Manager::instance().setConfigOrDefaultValue(details, IP2IP_PROFILE, SRTP_ENABLE);
Manager::instance().setConfigOrDefaultValue(details, IP2IP_PROFILE, ZRTP_DISPLAY_SAS);
Manager::instance().setConfigOrDefaultValue(details, IP2IP_PROFILE, ZRTP_NOT_SUPP_WARNING);
Manager::instance().setConfigOrDefaultValue(details, IP2IP_PROFILE, ZRTP_HELLO_HASH);
Manager::instance().setConfigOrDefaultValue(details, IP2IP_PROFILE, ZRTP_DISPLAY_SAS_ONCE);
std::string keyExchange(details.find(SRTP_KEY_EXCHANGE)->second);
if(keyExchange.find("ZRTP") == 0) {
Manager::instance().setConfig(IP2IP_PROFILE, SRTP_KEY_EXCHANGE, sfl::Zrtp);
Manager::instance().setConfig(IP2IP_PROFILE, SRTP_KEY_EXCHANGE, "0");
} else {
Manager::instance().setConfig(IP2IP_PROFILE, SRTP_KEY_EXCHANGE, sfl::Sdes);
Manager::instance().setConfig(IP2IP_PROFILE, SRTP_KEY_EXCHANGE, "1");
}
Manager::instance().saveConfig();
......
......@@ -18,8 +18,12 @@
*/
#include <dbusmanagerimpl.h>
#include "global.h"
#include "manager.h"
#include "callmanager.h"
#include "configurationmanager.h"