Commit f39e33ae authored by yanmorin's avatar yanmorin

New account implementation.
Need to test more and add dynamic handling in Qt Interface.
SipCall, Call, VoIPLink were rewritten completly
Configuration now in [SIP0] section of .sflphonedrc
The debug of sflphoned is very verbose.
sflphone-cli may not work right now (need to send SIP0 as accountId).
parent d62caf5e
...@@ -13,10 +13,10 @@ endif ...@@ -13,10 +13,10 @@ endif
SUBDIRS = audio config gui $(ZEROCONFDIR) SUBDIRS = audio config gui $(ZEROCONFDIR)
sflphoned_SOURCES = call.cpp eventthread.cpp main.cpp sipvoiplink.cpp voIPLink.cpp \ sflphoned_SOURCES = eventthread.cpp main.cpp voIPLink.cpp \
sipcall.cpp managerimpl.cpp \ managerimpl.cpp observer.cpp \
observer.cpp \ account.cpp sipaccount.cpp iaxaccount.cpp accountcreator.cpp iaxvoiplink.cpp \
account.cpp sipaccount.cpp aixaccount.cpp accountcreator.cpp aixvoiplink.cpp sipvoiplink.cpp call.cpp sipcall.cpp
sflphoned_CXXFLAGS = -DPREFIX=\"$(prefix)\" -DPROGSHAREDIR=\"${datadir}/sflphone\" $(ZEROCONFFLAGS) sflphoned_CXXFLAGS = -DPREFIX=\"$(prefix)\" -DPROGSHAREDIR=\"${datadir}/sflphone\" $(ZEROCONFFLAGS)
...@@ -38,6 +38,8 @@ libsflphone_la_LIBADD = \ ...@@ -38,6 +38,8 @@ libsflphone_la_LIBADD = \
libsflphone_la_SOURCES = libsflphone_la_SOURCES =
noinst_LTLIBRARIES = libsflphone.la noinst_LTLIBRARIES = libsflphone.la
noinst_HEADERS = managerimpl.h manager.h global.h observer.h eventthread.h sipvoiplink.h user_cfg.h \ noinst_HEADERS = managerimpl.h manager.h global.h observer.h eventthread.h user_cfg.h \
call.h voIPLink.h sipcall.h \ voIPLink.h \
account.h sipaccount.h aixaccount.h accountcreator.h aixvoiplink.h account.h sipaccount.h iaxaccount.h accountcreator.h iaxvoiplink.h \
sipvoiplink.h call.h sipcall.h
...@@ -24,6 +24,7 @@ Account::Account(const AccountID& accountID) : _accountID(accountID) ...@@ -24,6 +24,7 @@ Account::Account(const AccountID& accountID) : _accountID(accountID)
_link = 0; _link = 0;
_shouldInitOnStart = false; _shouldInitOnStart = false;
_shouldRegisterOnStart = false;
_enabled = false; _enabled = false;
_registered = false; _registered = false;
} }
......
...@@ -28,6 +28,8 @@ typedef std::string AccountID; ...@@ -28,6 +28,8 @@ typedef std::string AccountID;
#define AccountNULL "" #define AccountNULL ""
#define CONFIG_ACCOUNT_TYPE "Account.type" #define CONFIG_ACCOUNT_TYPE "Account.type"
#define CONFIG_ACCOUNT_ENABLE "Account.enable" #define CONFIG_ACCOUNT_ENABLE "Account.enable"
#define CONFIG_ACCOUNT_AUTO_REGISTER "Account.autoregister"
/** /**
@author Yan Morin @author Yan Morin
...@@ -39,13 +41,13 @@ class Account{ ...@@ -39,13 +41,13 @@ class Account{
public: public:
Account(const AccountID& accountID); Account(const AccountID& accountID);
~Account(); virtual ~Account();
/** /**
* Load the default properties for the account * Load the default properties for the account
*/ */
virtual void initConfig(Conf::ConfigTree& config) = 0; virtual void initConfig(Conf::ConfigTree& config) = 0;
virtual void loadConfig() = 0;
/** /**
* Get the voiplink pointer * Get the voiplink pointer
...@@ -77,6 +79,18 @@ public: ...@@ -77,6 +79,18 @@ public:
*/ */
virtual bool terminate() = 0; virtual bool terminate() = 0;
/**
* Tell if we should init the account on start
* @return true if we must init the link
*/
bool shouldInitOnStart() {return _shouldInitOnStart; }
/**
* Tell if we should init the account on start
* @return true if we must init the link
*/
bool shouldRegisterOnStart() {return _shouldRegisterOnStart; }
private: private:
/** /**
* Create a unique voIPLink() depending on the protocol * Create a unique voIPLink() depending on the protocol
...@@ -102,6 +116,12 @@ protected: ...@@ -102,6 +116,12 @@ protected:
*/ */
bool _shouldInitOnStart; bool _shouldInitOnStart;
/**
* Tells if we should register automatically on startup
* Modified by the configuration
*/
bool _shouldRegisterOnStart;
/** /**
* Tells if the link is enabled or not * Tells if the link is enabled or not
* Modified by init/terminate * Modified by init/terminate
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
*/ */
#include "accountcreator.h" #include "accountcreator.h"
#include "sipaccount.h" #include "sipaccount.h"
#include "aixaccount.h" #include "iaxaccount.h"
AccountCreator::AccountCreator() AccountCreator::AccountCreator()
{ {
...@@ -37,8 +37,8 @@ AccountCreator::createAccount(AccountType type, AccountID accountID) ...@@ -37,8 +37,8 @@ AccountCreator::createAccount(AccountType type, AccountID accountID)
return new SIPAccount(accountID); return new SIPAccount(accountID);
break; break;
case AIX_ACCOUNT: case IAX_ACCOUNT:
return new AIXAccount(accountID); return new IAXAccount(accountID);
break; break;
} }
return 0; return 0;
......
...@@ -33,7 +33,7 @@ public: ...@@ -33,7 +33,7 @@ public:
/** /**
* Public account type * Public account type
*/ */
enum AccountType {SIP_ACCOUNT, AIX_ACCOUNT }; enum AccountType {SIP_ACCOUNT, IAX_ACCOUNT };
/** /**
* Create a new account or null * Create a new account or null
......
...@@ -49,7 +49,7 @@ AudioRtp::~AudioRtp (void) { ...@@ -49,7 +49,7 @@ AudioRtp::~AudioRtp (void) {
} }
int int
AudioRtp::createNewSession (SipCall *ca) { AudioRtp::createNewSession (SIPCall *ca) {
ost::MutexLock m(_threadMutex); ost::MutexLock m(_threadMutex);
// something should stop the thread before... // something should stop the thread before...
...@@ -90,7 +90,7 @@ AudioRtp::closeRtpSession () { ...@@ -90,7 +90,7 @@ AudioRtp::closeRtpSession () {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// AudioRtpRTX Class // // AudioRtpRTX Class //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
AudioRtpRTX::AudioRtpRTX (SipCall *sipcall, AudioLayer* driver, bool sym) { AudioRtpRTX::AudioRtpRTX (SIPCall *sipcall, AudioLayer* driver, bool sym) {
setCancel(cancelDeferred); setCancel(cancelDeferred);
time = new ost::Time(); time = new ost::Time();
_ca = sipcall; _ca = sipcall;
...@@ -108,7 +108,7 @@ AudioRtpRTX::AudioRtpRTX (SipCall *sipcall, AudioLayer* driver, bool sym) { ...@@ -108,7 +108,7 @@ AudioRtpRTX::AudioRtpRTX (SipCall *sipcall, AudioLayer* driver, bool sym) {
// TODO: Change bind address according to user settings. // TODO: Change bind address according to user settings.
// TODO: this should be the local ip not the external (router) IP // TODO: this should be the local ip not the external (router) IP
std::string localipConfig = "0.0.0.0"; // _ca->getLocalIp(); std::string localipConfig = _ca->getLocalIp(); // _ca->getLocalIp();
ost::InetHostAddress local_ip(localipConfig.c_str()); ost::InetHostAddress local_ip(localipConfig.c_str());
//_debug("AudioRtpRTX ctor : Local IP:port %s:%d\tsymmetric:%d\n", local_ip.getHostname(), _ca->getLocalAudioPort(), _sym); //_debug("AudioRtpRTX ctor : Local IP:port %s:%d\tsymmetric:%d\n", local_ip.getHostname(), _ca->getLocalAudioPort(), _sym);
...@@ -159,9 +159,9 @@ AudioRtpRTX::initAudioRtpSession (void) ...@@ -159,9 +159,9 @@ AudioRtpRTX::initAudioRtpSession (void)
if (_ca == 0) { return; } if (_ca == 0) { return; }
//_debug("Init audio RTP session\n"); //_debug("Init audio RTP session\n");
ost::InetHostAddress remote_ip(_ca->getRemoteSdpAudioIp()); ost::InetHostAddress remote_ip(_ca->getRemoteIp().c_str());
if (!remote_ip) { if (!remote_ip) {
_debug("AudioRTP Thread Error: Target IP address [%s] is not correct!\n", _ca->getRemoteSdpAudioIp()); _debug("AudioRTP Thread Error: Target IP address [%s] is not correct!\n", _ca->getRemoteIp().data());
return; return;
} }
...@@ -178,12 +178,12 @@ AudioRtpRTX::initAudioRtpSession (void) ...@@ -178,12 +178,12 @@ AudioRtpRTX::initAudioRtpSession (void)
} }
if (!_sym) { if (!_sym) {
if ( !_sessionRecv->addDestination(remote_ip, (unsigned short) _ca->getRemoteSdpAudioPort()) ) { if ( !_sessionRecv->addDestination(remote_ip, (unsigned short) _ca->getRemoteAudioPort()) ) {
_debug("AudioRTP Thread Error: could not connect to port %d\n", _ca->getLocalAudioPort()); _debug("AudioRTP Thread Error: could not connect to port %d\n", _ca->getRemoteAudioPort());
return; return;
} }
if (!_sessionSend->addDestination (remote_ip, (unsigned short) _ca->getRemoteSdpAudioPort())) { if (!_sessionSend->addDestination (remote_ip, (unsigned short) _ca->getRemoteAudioPort())) {
_debug("AudioRTP Thread Error: could not connect to port %d\n", _ca->getRemoteSdpAudioPort()); _debug("AudioRTP Thread Error: could not connect to port %d\n", _ca->getRemoteAudioPort());
return; return;
} }
...@@ -202,7 +202,7 @@ AudioRtpRTX::initAudioRtpSession (void) ...@@ -202,7 +202,7 @@ AudioRtpRTX::initAudioRtpSession (void)
//_debug("AudioRTP Thread: Added session destination %s:%d\n", remote_ip.getHostname(), (unsigned short) _ca->getRemoteSdpAudioPort()); //_debug("AudioRTP Thread: Added session destination %s:%d\n", remote_ip.getHostname(), (unsigned short) _ca->getRemoteSdpAudioPort());
if (!_session->addDestination (remote_ip, (unsigned short) _ca->getRemoteSdpAudioPort())) { if (!_session->addDestination (remote_ip, (unsigned short) _ca->getRemoteAudioPort())) {
return; return;
} }
...@@ -451,6 +451,7 @@ AudioRtpRTX::run () { ...@@ -451,6 +451,7 @@ AudioRtpRTX::run () {
audiolayer->flushMic(); audiolayer->flushMic();
audiolayer->startStream(); audiolayer->startStream();
_start.post(); _start.post();
_debug("AudioRTP Start\n");
while (!testCancel()) { while (!testCancel()) {
//////////////////////////// ////////////////////////////
// Send session // Send session
...@@ -471,11 +472,11 @@ AudioRtpRTX::run () { ...@@ -471,11 +472,11 @@ AudioRtpRTX::run () {
audiolayer->stopStream(); audiolayer->stopStream();
} catch(std::exception &e) { } catch(std::exception &e) {
_start.post(); _start.post();
_debug("AudioRTP Thread, run: %s\n", e.what()); _debug("AudioRTP Stop: %s\n", e.what());
throw; throw;
} catch(...) { } catch(...) {
_start.post(); _start.post();
_debugException("AudioRTP Thread, run()"); _debugException("AudioRTP Stop");
throw; throw;
} }
delete [] data_for_speakers_stereo; data_for_speakers_stereo = 0; delete [] data_for_speakers_stereo; data_for_speakers_stereo = 0;
......
...@@ -29,21 +29,21 @@ ...@@ -29,21 +29,21 @@
#define RTP_FRAMES2SEND 160 #define RTP_FRAMES2SEND 160
class AudioLayer; class AudioLayer;
class SipCall; class SIPCall;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Two pair of sockets // Two pair of sockets
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
class AudioRtpRTX : public ost::Thread, public ost::TimerPort { class AudioRtpRTX : public ost::Thread, public ost::TimerPort {
public: public:
AudioRtpRTX (SipCall *, AudioLayer*, bool); AudioRtpRTX (SIPCall *, AudioLayer*, bool);
~AudioRtpRTX(); ~AudioRtpRTX();
ost::Time *time; // For incoming call notification ost::Time *time; // For incoming call notification
virtual void run (); virtual void run ();
private: private:
SipCall* _ca; SIPCall* _ca;
AudioLayer* _audioDevice; AudioLayer* _audioDevice;
ost::RTPSession *_sessionSend; ost::RTPSession *_sessionSend;
ost::RTPSession *_sessionRecv; ost::RTPSession *_sessionRecv;
...@@ -72,7 +72,7 @@ public: ...@@ -72,7 +72,7 @@ public:
AudioRtp(); AudioRtp();
~AudioRtp(); ~AudioRtp();
int createNewSession (SipCall *); int createNewSession (SIPCall *);
void closeRtpSession (); void closeRtpSession ();
private: private:
......
/** /*
* Copyright (C) 2004-2005 Savoir-Faire Linux inc. * Copyright (C) 2004-2006 Savoir-Faire Linux inc.
* Author: Yan Morin <yan.morin@savoirfairelinux.com> * Author: Yan Morin <yan.morin@savoirfairelinux.com>
* Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com> * Author : Laurielle Lea <laurielle.lea@savoirfairelinux.com>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#include <iostream>
#include "call.h" #include "call.h"
#include "voIPLink.h"
Call::Call (CALLID id, Call::CallType type, VoIPLink* voiplink)
{
_state = NotExist;
_type = Null;
_id = id;
_type = type;
_voIPLink = voiplink;
_flagNotAnswered = true;
switch (_type) {
case Outgoing:
_voIPLink->newOutgoingCall(_id);
break;
case Incoming:
_voIPLink->newIncomingCall(_id);
break;
default:
break;
}
}
Call::~Call (void) Call::Call(const CallID& id, Call::CallType type) : _id(id), _type(type)
{ {
_connectionState = Call::Disconnected;
_callState = Call::Inactive;
} }
CALLID
Call::getId (void)
{
return _id;
}
void Call::~Call()
Call::setId (CALLID id)
{ {
_id = id;
} }
void void
Call::setVoIPLink (VoIPLink* voIPLink) Call::setConnectionState(ConnectionState state)
{
_voIPLink = voIPLink;
}
VoIPLink*
Call::getVoIPLink (void)
{
return _voIPLink;
}
std::string
Call::getCallerIdName (void)
{ {
return _callerIdName; ost::MutexLock m(_callMutex);
_connectionState = state;
} }
void Call::ConnectionState
Call::setCallerIdName (const std::string& callerId_name) Call::getConnectionState()
{ {
_callerIdName = callerId_name; ost::MutexLock m(_callMutex);
return _connectionState;
} }
std::string
Call::getCallerIdNumber (void)
{
return _callerIdNumber;
}
void void
Call::setCallerIdNumber (const std::string& callerId_number) Call::setState(CallState state)
{ {
_callerIdNumber = callerId_number; ost::MutexLock m(_callMutex);
_callState = state;
} }
Call::CallState Call::CallState
Call::getState (void) Call::getState()
{
return _state;
}
void
Call::setState (Call::CallState state)
{
_state = state;
}
Call::CallType
Call::getType (void)
{ {
return _type; ost::MutexLock m(_callMutex);
return _callState;
} }
void
Call::setType (Call::CallType type)
{
_type = type;
}
bool
Call::isBusy (void)
{
if (isAnswered() or isOffHold() or isOnMute() or isOffMute()) {
return true;
} else {
return false;
}
}
bool
Call::isOnHold (void)
{
return (_state == OnHold) ? true : false;
}
bool
Call::isOffHold (void)
{
return (_state == OffHold) ? true : false;
}
bool
Call::isOnMute (void)
{
return (_state == MuteOn) ? true : false;
}
bool
Call::isOffMute (void)
{
return (_state == MuteOff) ? true : false;
}
bool
Call::isTransfered (void)
{
return (_state == Transfered) ? true : false;
}
bool
Call::isHungup (void)
{
return (_state == Hungup) ? true : false;
}
bool
Call::isRinging (void)
{
return (_state == Ringing) ? true : false;
}
bool
Call::isRefused (void)
{
return (_state == Refused) ? true : false;
}
bool
Call::isAnswered (void)
{
return (_state == Answered) ? true : false;
}
bool
Call::isNotAnswered (void)
{
return (_state == Error || _state == NotExist || _state == Busy) ? true : false;
}
bool
Call::isProgressing (void)
{
return (_state == Progressing) ? true : false;
}
bool
Call::isOutgoingType (void)
{
return (_type == Outgoing) ? true : false;
}
bool
Call::isIncomingType (void)
{
return (_type == Incoming) ? true : false;
}
int
Call::outgoingCall(const std::string& to)
{
return _voIPLink->outgoingInvite(_id, to);
}
int
Call::hangup (void)
{
int i = _voIPLink->hangup(_id);
setState(Hungup);
return i;
}
int
Call::cancel (void)
{
int i = _voIPLink->cancel(_id);
setState(Hungup);
return i;
}