Commit f39e33ae authored by yanmorin's avatar yanmorin
Browse files

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
SUBDIRS = audio config gui $(ZEROCONFDIR)
sflphoned_SOURCES = call.cpp eventthread.cpp main.cpp sipvoiplink.cpp voIPLink.cpp \
sipcall.cpp managerimpl.cpp \
observer.cpp \
account.cpp sipaccount.cpp aixaccount.cpp accountcreator.cpp aixvoiplink.cpp
sflphoned_SOURCES = eventthread.cpp main.cpp voIPLink.cpp \
managerimpl.cpp observer.cpp \
account.cpp sipaccount.cpp iaxaccount.cpp accountcreator.cpp iaxvoiplink.cpp \
sipvoiplink.cpp call.cpp sipcall.cpp
sflphoned_CXXFLAGS = -DPREFIX=\"$(prefix)\" -DPROGSHAREDIR=\"${datadir}/sflphone\" $(ZEROCONFFLAGS)
......@@ -38,6 +38,8 @@ libsflphone_la_LIBADD = \
libsflphone_la_SOURCES =
noinst_LTLIBRARIES = libsflphone.la
noinst_HEADERS = managerimpl.h manager.h global.h observer.h eventthread.h sipvoiplink.h user_cfg.h \
call.h voIPLink.h sipcall.h \
account.h sipaccount.h aixaccount.h accountcreator.h aixvoiplink.h
noinst_HEADERS = managerimpl.h manager.h global.h observer.h eventthread.h user_cfg.h \
voIPLink.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)
_link = 0;
_shouldInitOnStart = false;
_shouldRegisterOnStart = false;
_enabled = false;
_registered = false;
}
......
......@@ -28,6 +28,8 @@ typedef std::string AccountID;
#define AccountNULL ""
#define CONFIG_ACCOUNT_TYPE "Account.type"
#define CONFIG_ACCOUNT_ENABLE "Account.enable"
#define CONFIG_ACCOUNT_AUTO_REGISTER "Account.autoregister"
/**
@author Yan Morin
......@@ -39,13 +41,13 @@ class Account{
public:
Account(const AccountID& accountID);
~Account();
virtual ~Account();
/**
* Load the default properties for the account
*/
virtual void initConfig(Conf::ConfigTree& config) = 0;
virtual void loadConfig() = 0;
/**
* Get the voiplink pointer
......@@ -77,6 +79,18 @@ public:
*/
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:
/**
* Create a unique voIPLink() depending on the protocol
......@@ -102,6 +116,12 @@ protected:
*/
bool _shouldInitOnStart;
/**
* Tells if we should register automatically on startup
* Modified by the configuration
*/
bool _shouldRegisterOnStart;
/**
* Tells if the link is enabled or not
* Modified by init/terminate
......
......@@ -18,7 +18,7 @@
*/
#include "accountcreator.h"
#include "sipaccount.h"
#include "aixaccount.h"
#include "iaxaccount.h"
AccountCreator::AccountCreator()
{
......@@ -37,8 +37,8 @@ AccountCreator::createAccount(AccountType type, AccountID accountID)
return new SIPAccount(accountID);
break;
case AIX_ACCOUNT:
return new AIXAccount(accountID);
case IAX_ACCOUNT:
return new IAXAccount(accountID);
break;
}
return 0;
......
......@@ -33,7 +33,7 @@ public:
/**
* Public account type
*/
enum AccountType {SIP_ACCOUNT, AIX_ACCOUNT };
enum AccountType {SIP_ACCOUNT, IAX_ACCOUNT };
/**
* Create a new account or null
......
......@@ -49,7 +49,7 @@ AudioRtp::~AudioRtp (void) {
}
int
AudioRtp::createNewSession (SipCall *ca) {
AudioRtp::createNewSession (SIPCall *ca) {
ost::MutexLock m(_threadMutex);
// something should stop the thread before...
......@@ -90,7 +90,7 @@ AudioRtp::closeRtpSession () {
////////////////////////////////////////////////////////////////////////////////
// AudioRtpRTX Class //
////////////////////////////////////////////////////////////////////////////////
AudioRtpRTX::AudioRtpRTX (SipCall *sipcall, AudioLayer* driver, bool sym) {
AudioRtpRTX::AudioRtpRTX (SIPCall *sipcall, AudioLayer* driver, bool sym) {
setCancel(cancelDeferred);
time = new ost::Time();
_ca = sipcall;
......@@ -108,7 +108,7 @@ AudioRtpRTX::AudioRtpRTX (SipCall *sipcall, AudioLayer* driver, bool sym) {
// TODO: Change bind address according to user settings.
// 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());
//_debug("AudioRtpRTX ctor : Local IP:port %s:%d\tsymmetric:%d\n", local_ip.getHostname(), _ca->getLocalAudioPort(), _sym);
......@@ -159,9 +159,9 @@ AudioRtpRTX::initAudioRtpSession (void)
if (_ca == 0) { return; }
//_debug("Init audio RTP session\n");
ost::InetHostAddress remote_ip(_ca->getRemoteSdpAudioIp());
ost::InetHostAddress remote_ip(_ca->getRemoteIp().c_str());
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;
}
......@@ -178,12 +178,12 @@ AudioRtpRTX::initAudioRtpSession (void)
}
if (!_sym) {
if ( !_sessionRecv->addDestination(remote_ip, (unsigned short) _ca->getRemoteSdpAudioPort()) ) {
_debug("AudioRTP Thread Error: could not connect to port %d\n", _ca->getLocalAudioPort());
if ( !_sessionRecv->addDestination(remote_ip, (unsigned short) _ca->getRemoteAudioPort()) ) {
_debug("AudioRTP Thread Error: could not connect to port %d\n", _ca->getRemoteAudioPort());
return;
}
if (!_sessionSend->addDestination (remote_ip, (unsigned short) _ca->getRemoteSdpAudioPort())) {
_debug("AudioRTP Thread Error: could not connect to port %d\n", _ca->getRemoteSdpAudioPort());
if (!_sessionSend->addDestination (remote_ip, (unsigned short) _ca->getRemoteAudioPort())) {
_debug("AudioRTP Thread Error: could not connect to port %d\n", _ca->getRemoteAudioPort());
return;
}
......@@ -202,7 +202,7 @@ AudioRtpRTX::initAudioRtpSession (void)
//_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;
}
......@@ -451,6 +451,7 @@ AudioRtpRTX::run () {
audiolayer->flushMic();
audiolayer->startStream();
_start.post();
_debug("AudioRTP Start\n");
while (!testCancel()) {
////////////////////////////
// Send session
......@@ -471,11 +472,11 @@ AudioRtpRTX::run () {
audiolayer->stopStream();
} catch(std::exception &e) {
_start.post();
_debug("AudioRTP Thread, run: %s\n", e.what());
_debug("AudioRTP Stop: %s\n", e.what());
throw;
} catch(...) {
_start.post();
_debugException("AudioRTP Thread, run()");
_debugException("AudioRTP Stop");
throw;
}
delete [] data_for_speakers_stereo; data_for_speakers_stereo = 0;
......
......@@ -29,21 +29,21 @@
#define RTP_FRAMES2SEND 160
class AudioLayer;
class SipCall;
class SIPCall;
///////////////////////////////////////////////////////////////////////////////
// Two pair of sockets
///////////////////////////////////////////////////////////////////////////////
class AudioRtpRTX : public ost::Thread, public ost::TimerPort {
public:
AudioRtpRTX (SipCall *, AudioLayer*, bool);
AudioRtpRTX (SIPCall *, AudioLayer*, bool);
~AudioRtpRTX();
ost::Time *time; // For incoming call notification
virtual void run ();
private:
SipCall* _ca;
SIPCall* _ca;
AudioLayer* _audioDevice;
ost::RTPSession *_sessionSend;
ost::RTPSession *_sessionRecv;
......@@ -72,7 +72,7 @@ public:
AudioRtp();
~AudioRtp();
int createNewSession (SipCall *);
int createNewSession (SIPCall *);
void closeRtpSession ();
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: 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
* 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.
*
*
* 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.
*
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <iostream>
#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::setId (CALLID id)
Call::~Call()
{
_id = id;
}
void
Call::setVoIPLink (VoIPLink* voIPLink)
{
_voIPLink = voIPLink;
}
VoIPLink*
Call::getVoIPLink (void)
{
return _voIPLink;
}
std::string
Call::getCallerIdName (void)
Call::setConnectionState(ConnectionState state)
{
return _callerIdName;
ost::MutexLock m(_callMutex);
_connectionState = state;
}
void
Call::setCallerIdName (const std::string& callerId_name)
Call::ConnectionState
Call::getConnectionState()
{
_callerIdName = callerId_name;
ost::MutexLock m(_callMutex);
return _connectionState;
}
std::string
Call::getCallerIdNumber (void)
{
return _callerIdNumber;
}
void
Call::setCallerIdNumber (const std::string& callerId_number)
Call::setState(CallState state)
{
_callerIdNumber = callerId_number;
ost::MutexLock m(_callMutex);
_callState = state;
}
Call::CallState
Call::getState (void)
{
return _state;
}
void
Call::setState (Call::CallState state)
{
_state = state;
}
Call::CallType
Call::getType (void)
Call::getState()
{
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;
}
int
Call::answer (void)
{
_flagNotAnswered = false;
int i = _voIPLink->answer(_id);
setState(Answered);
return i;
}
int
Call::onHold (void)
{
int i = _voIPLink->onhold(_id);
setState(OnHold);
return i;
}
int
Call::offHold (void)
{
int i = _voIPLink->offhold(_id);
setState(OffHold);
return i;
}
int
Call::transfer (const std::string& to)
{
int i = _voIPLink->transfer(_id, to);
setState(Transfered);
return i;
}
int
Call::refuse (void)
{
int i = _voIPLink->refuse(_id);
return i;
}
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
/*
* Copyright (C) 2004-2006 Savoir-Faire Linux inc.
* 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
* 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.
*
*
* 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.
*
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __CALL_H__
#define __CALL_H__
#ifndef CALL_H
#define CALL_H
#include <string>
#include <cc++/thread.h> // for mutex
//TODO: remove this, it's only for call ID
typedef std::string CallID;
/**
@author Yan Morin <yan.morin@gmail.com>
A call is the base classes for protocol-based calls
*/
class Call{
public:
enum CallType {Incoming, Outgoing};
enum ConnectionState {Disconnected, Trying, Progressing, Ringing, Connected };
enum CallState {Inactive, Active, Hold, Busy, Refused, Error};
typedef unsigned int CALLID;
/**
* Constructor of a call
* @param id Unique identifier of the call
* @param type set definitely this call as incoming/outgoing
*/
Call(const CallID& id, Call::CallType type);
virtual ~Call();
/**
* Return a reference on the call id
* @return call id
*/
CallID& getCallId() {return _id; }
class VoIPLink;
/**
* Set the peer number (destination on outgoing)
* not protected by mutex (when created)
* @param number peer number
*/
void setPeerNumber(const std::string& number) { _peerNumber = number; }
const std::string& getPeerNumber() { return _peerNumber; }
class Call {
public:
enum CallType {
Null = 0,
Incoming,
Outgoing
};
/**
* Set the peer name (caller in ingoing)
* not protected by mutex (when created)
* @param number peer number
*/
void setPeerName(const std::string& name) { _peerName = name; }
const std::string& getPeerName() { return _peerName; }
/**
* Set the connection state of the call (protected by mutex)
*/
void setConnectionState(ConnectionState state);
/**
* get the connection state of the call (protected by mutex)
*/
ConnectionState getConnectionState();
enum CallState {
NotExist = 0,
Busy,
OnHold,
OffHold,
MuteOn,
MuteOff