Commit 3c592870 authored by Emmanuel Milou's avatar Emmanuel Milou

clean up account/voiplink. !!! Code broken for now !!!

parent a360c591
......@@ -27,17 +27,17 @@ SUBDIRS = audio config dbus $(ZEROCONFDIR)
# Add here the cpp files to be build with sflphone
sflphoned_SOURCES = \
eventthread.cpp \
main.cpp \
voiplink.cpp \
main.cpp \
managerimpl.cpp \
observer.cpp \
samplerateconverter.cpp \
account.cpp \
eventthread.cpp \
sipaccount.cpp \
accountcreator.cpp \
sipvoiplink.cpp \
sipvoiplink.cpp \
call.cpp \
account.cpp \
sipcall.cpp \
$(IAXSOURCES) \
useragent.cpp
......@@ -65,18 +65,18 @@ sflphoned_LDADD = \
noinst_LTLIBRARIES = libsflphone.la
noinst_HEADERS = \
voiplink.h \
managerimpl.h \
manager.h \
global.h \
observer.h \
eventthread.h \
user_cfg.h \
voiplink.h \
samplerateconverter.h \
account.h \
sipaccount.h \
accountcreator.h \
sipvoiplink.h \
sipvoiplink.h \
call.h \
sipcall.h \
useragent.h
......
/*
* Copyright (C) 2006-2007 Savoir-Faire Linux inc.
* Copyright (C) 2006-2009 Savoir-Faire Linux inc.
*
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
* Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com>
* Author: Yan Morin <yan.morin@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
......@@ -17,13 +18,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "account.h"
#include "voiplink.h"
#include "manager.h"
#include <string>
Account::Account(const AccountID& accountID) : _accountID(accountID), _link(NULL), _enabled(false)
Account::Account(const AccountID& accountID) :
_accountID(accountID), _link(NULL), _enabled(false)
{
}
......@@ -31,62 +31,18 @@ Account::~Account()
{
}
void
Account::loadConfig()
void Account::loadConfig()
{
std::string p = Manager::instance().getConfigString( _accountID , CONFIG_ACCOUNT_TYPE );
std::string p;
p = Manager::instance().getConfigString( _accountID , CONFIG_ACCOUNT_TYPE );
#ifdef USE_IAX
_enabled = Manager::instance().getConfigInt(_accountID, CONFIG_ACCOUNT_ENABLE) ? true : false;
_enabled = Manager::instance().getConfigInt(_accountID, CONFIG_ACCOUNT_ENABLE) ? true : false;
#else
if( p.c_str() == "IAX" )
_enabled = false;
else
_enabled = Manager::instance().getConfigInt(_accountID, CONFIG_ACCOUNT_ENABLE) ? true : false;
if( p.c_str() == "IAX" )
_enabled = false;
else
_enabled = Manager::instance().getConfigInt(_accountID, CONFIG_ACCOUNT_ENABLE) ? true : false;
#endif
}
// NOW
void
Account::loadContacts()
{
/*
// TMP
Contact* contact1 = new Contact("1223345", "Guillaume140", "<sip:140@asterix.inside.savoirfairelinux.net>");
_contacts.push_back(contact1);
Contact* contact2 = new Contact("9876543", "SFLphone131", "<sip:131@asterix.inside.savoirfairelinux.net>");
_contacts.push_back(contact2);
Contact* contact3 = new Contact("6867823", "Guillaume201", "<sip:201@192.168.1.202:5066>");
_contacts.push_back(contact3);
Contact* contact4 = new Contact("3417928", "SFLphone203", "<sip:203@192.168.1.202:5066>");
_contacts.push_back(contact4);
// TODO Load contact file containing list of contacts
// or a configuration for LDAP contacts
*/
}
void
Account::subscribeContactsPresence()
{
/*
if(_link->isContactPresenceSupported())
{
// Subscribe to presence for each contact that presence is enabled
std::vector<Contact*>::iterator iter;
for(iter = _contacts.begin(); iter != _contacts.end(); iter++)
{
_link->subscribePresenceForContact(*iter);
}
}
*/
}
void
Account::publishPresence(std::string presenceStatus UNUSED)
{
/*
if(_link->isContactPresenceSupported())
_link->publishPresenceStatus(presenceStatus);
*/
}
/*
* Copyright (C) 2006-2007 Savoir-Faire Linux inc.
* Copyright (C) 2006-2009 Savoir-Faire Linux inc.
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
* Author: Yan Morin <yan.morin@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
......@@ -16,11 +17,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef ACCOUNT_H
#define ACCOUNT_H
#include <string>
#include <vector>
#include "config/config.h"
#include "voiplink.h"
......@@ -36,132 +39,101 @@ class VoIPLink;
typedef std::string AccountID;
#define AccountNULL ""
/** Account type: SIP / IAX2 are supported */
#define CONFIG_ACCOUNT_TYPE "Account.type"
/** Tells if account is enable or not */
#define CONFIG_ACCOUNT_ENABLE "Account.enable"
/** Account alias */
// Common account parameters
#define CONFIG_ACCOUNT_TYPE "Account.type"
#define CONFIG_ACCOUNT_ALIAS "Account.alias"
/** Mail box number */
#define CONFIG_ACCOUNT_MAILBOX "Account.mailbox"
/** IAX paramater : host name */
#define IAX_HOST "IAX.host"
/** IAX paramater : user name */
#define IAX_USER "IAX.user"
/** IAX paramater : password */
#define IAX_PASSWORD "IAX.password"
/** SIP parameter : authorization name */
#define SIP_USER "SIP.username"
/** SIP parameter : password */
#define SIP_PASSWORD "SIP.password"
/** SIP parameter : host name */
#define SIP_HOST "SIP.hostPart"
/** SIP parameter : proxy address */
#define CONFIG_ACCOUNT_ENABLE "Account.enable"
#define HOSTNAME "hostname"
#define USERNAME "username"
#define PASSWORD "password"
// SIP specific parameters
#define SIP_PROXY "SIP.proxy"
/** SIP parameter : stun server address */
#define SIP_STUN_SERVER "STUN.server"
/** SIP parameter : tells if stun is used or not */
#define SIP_USE_STUN "STUN.enable"
/** SIP parameter : stun port */
#define SIP_STUN_PORT "STUN.port"
class Account{
public:
Account(const AccountID& accountID);
/**
* Virtual destructor
*/
virtual ~Account();
/**
* Load the settings for this account.
*/
virtual void loadConfig();
/**
* Get the account ID
* @return constant account id
*/
inline const AccountID& getAccountID() { return _accountID; }
/**
* Get the voiplink pointer
* @return VoIPLink* the pointer or 0
*/
inline VoIPLink* getVoIPLink() { return _link; }
/**
* Register the underlying VoIPLink. Launch the event listener.
* This should update the getRegistrationState() return value.
*/
virtual int registerVoIPLink() = 0;
/**
* Unregister the underlying VoIPLink. Stop the event listener.
* This should update the getRegistrationState() return value.
*/
virtual int unregisterVoIPLink() = 0;
/**
* Tell if the account is enable or not.
* @return true if enabled
* false otherwise
*/
bool isEnabled() { return _enabled; }
/**
* Get the registration state of the specified link
* @return RegistrationState The registration state of underlying VoIPLink
*/
VoIPLink::RegistrationState getRegistrationState() { return _link->getRegistrationState(); }
/**
* Load all contacts
*/
void loadContacts();
/**
* Suscribe presence information for selected contacts if supported
*/
void subscribeContactsPresence();
/**
* Publish our presence information to the server
*/
void publishPresence(std::string presenceStatus);
private:
// copy constructor
Account(const Account& rh);
// assignment operator
Account& operator=(const Account& rh);
protected:
/**
* Account ID are assign in constructor and shall not changed
*/
AccountID _accountID;
/**
* Voice over IP Link contains a listener thread and calls
*/
VoIPLink* _link;
/**
* Tells if the link is enabled, active.
* This implies the link will be initialized on startup.
* Modified by the configuration (key: ENABLED)
*/
bool _enabled;
/**
* Contacts related to account that can have presence information
*/
//std::vector<Contact*> _contacts;
public:
Account(const AccountID& accountID);
/**
* Virtual destructor
*/
virtual ~Account();
/**
* Load the settings for this account.
*/
virtual void loadConfig();
/**
* Get the account ID
* @return constant account id
*/
inline const AccountID& getAccountID() { return _accountID; }
/**
* Get the voiplink pointer
* @return VoIPLink* the pointer or 0
*/
inline VoIPLink* getVoIPLink() { return _link; }
/**
* Register the underlying VoIPLink. Launch the event listener.
* This should update the getRegistrationState() return value.
*/
virtual int registerVoIPLink() = 0;
/**
* Unregister the underlying VoIPLink. Stop the event listener.
* This should update the getRegistrationState() return value.
*/
virtual int unregisterVoIPLink() = 0;
/**
* Tell if the account is enable or not.
* @return true if enabled
* false otherwise
*/
bool isEnabled() { return _enabled; }
/**
* Get the registration state of the specified link
* @return RegistrationState The registration state of underlying VoIPLink
*/
VoIPLink::RegistrationState getRegistrationState() { return _link->getRegistrationState(); }
private:
// copy constructor
Account(const Account& rh);
// assignment operator
Account& operator=(const Account& rh);
protected:
/**
* Account ID are assign in constructor and shall not changed
*/
AccountID _accountID;
/**
* Voice over IP Link contains a listener thread and calls
*/
VoIPLink* _link;
/**
* Tells if the link is enabled, active.
* This implies the link will be initialized on startup.
* Modified by the configuration (key: ENABLED)
*/
bool _enabled;
};
#endif
......@@ -22,7 +22,6 @@
#ifndef __CODEC_DESCRIPTOR_H__
#define __CODEC_DESCRIPTOR_H__
#include <string>
#include <map>
#include <vector>
#include <dirent.h>
......
......@@ -20,8 +20,8 @@
#ifndef CALL_H
#define CALL_H
#include <string>
#include <cc++/thread.h> // for mutex
#include "audio/codecDescriptor.h"
/*
......
......@@ -21,7 +21,6 @@
#include "eventthread.h"
#include "voiplink.h"
EventThread::EventThread (VoIPLink* link) : Thread (), _linkthread(link), stopIt(false)
{
setCancel(cancelDeferred);
......
......@@ -27,73 +27,51 @@
#include <libintl.h>
#include <locale.h>
#define SFLPHONED_VERSION "0.9.2-4" /** Version number */
typedef float float32;
typedef short int16;
#define SUCCESS 0
#define ASSERT( expected , value) if( value == expected ) return SUCCESS; \
else return 1;
#define PIDFILE "sfl.pid"
#ifdef DATAFORMAT_IS_FLOAT
#define SFLDataFormat float32
#define SFLDataFormatString "Float32"
#define SFLDataAmplitude 0.05
#define SFLConvertInt16(s) ((float)(s)-16384.0)/16384.0
#else
#define SFLDataFormat int16
#define SFLDataFormatString "Int16"
#define SFLDataAmplitude (32767 >> 4)
#define SFLConvertInt16(s) (s)
#endif
#ifdef SFLDEBUG
#define _debug(...) fprintf(stderr, "[sfl-debug] " __VA_ARGS__)
#define _debugStart(...) fprintf(stderr, "[sfl-debug] " __VA_ARGS__)
#define _debugMid(...) fprintf(stderr, __VA_ARGS__)
#define _debugEnd(...) fprintf(stderr, __VA_ARGS__)
#define _debugException(...) fprintf(stderr, "[sfl-excep] " __VA_ARGS__ "\n")
#define _debugInit(...) fprintf(stderr, "[sfl-init] " __VA_ARGS__ "\n")
#define _debugAlsa(...) fprintf(stderr, "[alsa-debug] " __VA_ARGS__ )
#else
#define _debug(...)
#define _debugStart(...)
#define _debugMid(...)
#define _debugEnd(...)
#define _debugException(...)
#define _debugInit(...)
#define _debugAlsa(...)
#endif
#define SFLPHONED_VERSION "0.8.2" /** Version number */
#define SFLPHONED_VERSIONNUM 0x000802
#define PROGNAME "sflphoned" /** Binary name */
#define PROGNAME_GLOBAL "sflphone" /** Program name */
#define PROGDIR "sflphone" /** Program directory */
#define RINGDIR "ringtones" /** Ringtones directory */
#define CODECDIR "codecs" /** Codecs directory */
#define _(arg) arg
#define MONO 1
#define CHANNELS 2
#define SIZEBUF 1024*1024
#define ALSA_DFT_CARD_ID 0 /** Index of the default soundcard */
#define PCM_HW "hw" /** Alsa plugin hardware */
#define PCM_PLUGHW "plughw" /** Alsa plugin */
#define PCM_PULSE "pulse" /** Alsa plugin for pulse audio */
#define PCM_FRONT "plug:front" /** Alsa plugin: front PCM */
#define PCM_DEFAULT "default" /** Default ALSA plugin */
#define PCM_DMIX "plug:dmix" /** Alsa plugin for software mixing */
#define PCM_DSNOOP "plug:dsnoop" /** Alsa plugin for software mixing */
#define PCM_SURROUND40 "plug:surround40" /** Alsa plugin: surround40 */
#define PCM_SURROUND41 "plug:surround41" /** Alsa plugin: surround41 */
#define PCM_SURROUND50 "plug:surround50" /** Alsa plugin: surround50 */
#define PCM_SURROUND51 "plug:surround51" /** Alsa plugin: surround51 */
#define PCM_SURROUND71 "plug:surround71" /** Alsa plugin: surround71 */
#define SFL_CODEC_VALID_PREFIX "libcodec_" /** Valid prefix for codecs shared library */
#define SFL_CODEC_VALID_EXTEN ".so" /** Valid extension for codecs shared library */
......@@ -134,4 +112,6 @@ typedef short int16;
#define UNUSED __attribute__((__unused__))
#define DEFAULT_SIP_PORT 5060
#endif // __GLOBAL_H__
/*
* Copyright (C) 2006-2007 Savoir-Faire Linux inc.
* Copyright (C) 2006-2009 Savoir-Faire Linux inc.
*
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
* Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com>
* Author: Yan Morin <yan.morin@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
......@@ -17,58 +18,55 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "iaxaccount.h"
#include "account.h"
#include "iaxvoiplink.h"
#include "manager.h"
IAXAccount::IAXAccount(const AccountID& accountID)
: Account(accountID)
IAXAccount::IAXAccount(const AccountID& accountID)
: Account(accountID)
{
_link = new IAXVoIPLink(accountID);
_link = new IAXVoIPLink(accountID);
}
IAXAccount::~IAXAccount()
{
delete _link;
_link = NULL;
delete _link;
_link = NULL;
}
int
int
IAXAccount::registerVoIPLink()
{
_link->init();
IAXVoIPLink *thislink;
_link->init();
//unregisterAccount(); No need to unregister first.
IAXVoIPLink* thislink = dynamic_cast<IAXVoIPLink*> (_link);
if (thislink) {
// Stuff needed for IAX registration
thislink->setHost(Manager::instance().getConfigString(_accountID, IAX_HOST));
thislink->setUser(Manager::instance().getConfigString(_accountID, IAX_USER));
thislink->setPass(Manager::instance().getConfigString(_accountID, IAX_PASSWORD));
}
thislink = dynamic_cast<IAXVoIPLink*> (_link);
if (thislink) {
// Stuff needed for IAX registration
thislink->setHost(Manager::instance().getConfigString(_accountID, HOSTNAME));
thislink->setUser(Manager::instance().getConfigString(_accountID, USERNAME));
thislink->setPass(Manager::instance().getConfigString(_accountID, PASSWORD));
}
_link->sendRegister();
_link->sendRegister();
return SUCCESS;
return SUCCESS;
}
int
int
IAXAccount::unregisterVoIPLink()
{
_link->sendUnregister();
_link->terminate();
_link->sendUnregister();
_link->terminate();
return SUCCESS;
return SUCCESS;
}
void
void
IAXAccount::loadConfig()
{
// Account generic
Account::loadConfig();
// IAX specific
//none
// Account generic
Account::loadConfig();
}
/*
* Copyright (C) 2006-2007 Savoir-Faire Linux inc.
* Copyright (C) 2006-2009 Savoir-Faire Linux inc.
* Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com>
* Author: Yan Morin <yan.morin@savoirfairelinux.com>
*
......@@ -22,34 +22,33 @@
#include "account.h"
/**
* @file: iaxaccount.h
* @brief An IAX Account specify IAX specific functions and objects (IAXCall/IAXVoIPLink)
*/
class IAXAccount : public Account
{
public:
IAXAccount(const AccountID& accountID);
public:
IAXAccount(const AccountID& accountID);
~IAXAccount();
~IAXAccount();
/**
* Actually unuseful, since config loading is done in init()
*/
void loadConfig();
/**
* Actually unuseful, since config loading is done in init()
*/
void loadConfig();
/**
* Register an account
*/
int registerVoIPLink();
/**
* Register an account
*/
int registerVoIPLink();
/**
* Unregister an account
*/
int unregisterVoIPLink();
/**
* Unregister an account
*/
int unregisterVoIPLink();
private:
private:
};
#endif
......@@ -759,7 +759,7 @@ IAXVoIPLink::iaxHandleRegReply(iax_event* event)
iax_destroy(_regSession);
_mutexIAX.leaveMutex();
_regSession = NULL;
setRegistrationState(ErrorAuth);
setRegistrationState(Bad_Authentification);
}
else if (event->etype == IAX_EVENT_REGACK) {
......
......@@ -67,13 +67,6 @@ class IAXVoIPLink : public VoIPLink
*/
bool init (void);
/**
* Check if a local IP can be found
* @return true if pingable
* false otherwise
*/
bool checkNetwork (void) { return false; }
/**
* Terminate a voip link by clearing the call list
*/
......
......@@ -42,14 +42,14 @@ main (int argc, char **argv) {
//bindtextdomain (PACKAGE, LOCALEDIR);
//textdomain (PACKAGE);
if (argc == 2 && strcmp(argv[1], _("--help")) == 0) {
if (argc == 2 && strcmp(argv[1], "--help") == 0) {
printf(_("%1$s Daemon %2$s, by Savoir-Faire Linux 2004-2005\n\n"),
printf("%1$s Daemon %2$s, by Savoir-Faire Linux 2004-2009\n\n",
PROGNAME,
SFLPHONED_VERSION);
printf(_("USAGE: sflphoned [--help]\nParameters: \n --help\tfor this message\n\n --port=3999\tchange the session port\n\n"));
printf(_("See http://www.sflphone.org/ for more information\n"));
printf("USAGE: sflphoned [--help]\nParameters: \n --help\tfor this message\n\n --port=3999\tchange the session port\n\n");
printf("See http://www.sflphone.org/ for more information\n");
} else {
FILE *fp;
......@@ -76,7 +76,7 @@ main (int argc, char **argv) {
// PID file doesn't exists, create and write pid in it
if( (fp = fopen(homepid,"w")) == NULL ){
fprintf(stderr, _("Creating PID file %s failed. Exited.\n"), homepid);
fprintf(stderr, "Creating PID file %s failed. Exited.\n", homepid);
exit(-1);
} else {
fputs(cPid , fp );
......@@ -87,11 +87,11 @@ main (int argc, char **argv) {
fgets( cOldPid, 64, fp );
fclose(fp);
if (kill(atoi(cOldPid), 0) == SUCCESS) {
fprintf(stderr, _("There is already a sflphoned daemon running in the system. Starting Failed.\n"));
fprintf(stderr, "There is already a sflphoned daemon running in the system. Starting Failed.\n");
exit(-1);
} else {
if( (fp = fopen(homepid,"w")) == NULL ){
fprintf(stderr, _("Writing to PID file %s failed. Exited.\n"), homepid);
fprintf(stderr, "Writing to PID file %s failed. Exited.\n", homepid);
exit(-1);
} else {
fputs(cPid , fp );
......@@ -119,7 +119,7 @@ main (int argc, char **argv) {
exit_code = -1;
}
catch (...) {
fprintf(stderr, _("An exception occured when initializing the system.\n"));
fprintf(stderr, "An exception occured when initializing the system.\n");
exit_code = -1;
}
if (initOK) {
......
This diff is collapsed.
......@@ -181,11 +181,6 @@ class ManagerImpl {
*/
bool _hasTriedToRegister;
/**
* Undocumented
*/
bool sendTextMessage(const AccountID& accountId, const std::string& to, const std::string& message);
/**
* Handle choice of the DTMF-send-way
* @param id: callid of the line.
......@@ -257,35 +252,16 @@ class ManagerImpl {
void incomingMessage(const AccountID& accountId, const std::string& message);
/**
* Notify the user he has voice mails
* Notify the client he has voice mails
* @param accountId The account identifier
* @param nb_msg The number of messages
*/
void startVoiceMessageNotification(const AccountID& accountId, int nb_msg);
/**
* Notify the user that registration succeeded
* @param accountId The account identifier
*/
void registrationSucceed(const AccountID& accountId);
/**
* Notify the user that unregistration succeeded
* @param accountId The account identifier
*/
void unregistrationSucceed(const AccountID& accountId);
/**
* Notify the user that registration failed
* @param accountId The account identifier
*/
void registrationFailed(const AccountID& accountId);
/**
* Notify the user that registration is trying
* @param accountId The account identifier
* Notify the client through DBus that registration state has been updated
*/