Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
savoirfairelinux
jami-daemon
Commits
9aa98b7b
Commit
9aa98b7b
authored
Jan 28, 2009
by
Emmanuel Milou
Browse files
Migrate to 1->N relationship between voiplink and accounts
parent
54dd1aec
Changes
15
Hide whitespace changes
Inline
Side-by-side
src/account.cpp
View file @
9aa98b7b
...
...
@@ -22,9 +22,10 @@
#include
"account.h"
#include
"manager.h"
Account
::
Account
(
const
AccountID
&
accountID
)
:
_accountID
(
accountID
),
_link
(
NULL
),
_enabled
(
false
)
Account
::
Account
(
const
AccountID
&
accountID
,
std
::
string
type
)
:
_accountID
(
accountID
),
_link
(
NULL
),
_enabled
(
false
)
,
_type
(
type
)
{
setRegistrationState
(
VoIPLink
::
Unregistered
);
}
Account
::~
Account
()
...
...
src/account.h
View file @
9aa98b7b
...
...
@@ -38,6 +38,19 @@ class VoIPLink;
typedef
std
::
string
AccountID
;
/** Contains all the state an Voip can be in */
typedef
enum
RegistrationState
{
Unregistered
,
Trying
,
Registered
,
Error
,
ErrorAuth
,
ErrorNetwork
,
ErrorHost
,
ErrorExistStun
,
ErrorConfStun
}
RegistrationState
;
#define AccountNULL ""
// Common account parameters
...
...
@@ -59,7 +72,7 @@ class Account{
public:
Account
(
const
AccountID
&
accountID
);
Account
(
const
AccountID
&
accountID
,
std
::
string
type
);
/**
* Virtual destructor
...
...
@@ -106,10 +119,31 @@ class Account{
* Get the registration state of the specified link
* @return RegistrationState The registration state of underlying VoIPLink
*/
VoIPLink
::
RegistrationState
getRegistrationState
()
{
return
_
link
->
getR
egistrationState
()
;
}
inline
RegistrationState
getRegistrationState
()
{
return
_
r
egistrationState
;
}
private:
inline
void
setRegistrationState
(
RegistrationState
state
)
{
_registrationState
=
state
;
// Notify the client
Manager
::
instance
().
connectionStatusNotification
(
);
}
inline
std
::
string
getUsername
(
void
)
{
return
_username
;
}
inline
void
setUsername
(
std
::
string
username
)
{
_username
=
username
;
}
inline
std
::
string
getHostname
(
void
)
{
return
_hostname
;
}
inline
void
setHostname
(
std
::
string
hostname
)
{
_hostname
=
hostname
;
}
inline
std
::
string
getPassword
(
void
)
{
return
_password
;
}
inline
void
setPassword
(
std
::
string
password
)
{
_password
=
password
;
}
inline
std
::
string
getAlias
(
void
)
{
return
_alias
;
}
inline
void
setAlias
(
std
::
string
alias
)
{
_alias
=
alias
;
}
inline
std
::
string
getType
(
void
)
{
return
_type
;
}
inline
void
setType
(
std
::
string
type
)
{
_type
=
type
;
}
private:
// copy constructor
Account
(
const
Account
&
rh
);
...
...
@@ -122,6 +156,32 @@ class Account{
*/
AccountID
_accountID
;
/**
* Account login information: username
*/
std
::
string
_username
;
/**
* Account login information: hostname
*/
std
::
string
_hostname
;
/**
* Account login information: password
*/
std
::
string
_password
;
/**
* Account login information: Alias
*/
std
::
string
_alias
;
/*
* The account type
* IAX2 or SIP
*/
std
::
string
_type
;
/**
* Voice over IP Link contains a listener thread and calls
*/
...
...
@@ -134,6 +194,11 @@ class Account{
*/
bool
_enabled
;
/*
* The registration state of the account
*/
RegistrationState
_registrationState
;
};
#endif
src/eventthread.cpp
View file @
9aa98b7b
...
...
@@ -20,31 +20,22 @@
#include
"eventthread.h"
#include
"voiplink.h"
/********************************** IAX Voiplink thread *************************************/
/**
* Reimplementation of run()
*/
void
IAXEventThread
::
run
(
void
)
/********************************** Voiplink thread *************************************/
EventThread
::
EventThread
(
VoIPLink
*
link
)
:
Thread
(),
_linkthread
(
link
)
{
while
(
!
testCancel
())
{
_linkthread
->
getEvent
();
}
}
/********************************************************************************************/
setCancel
(
cancelDeferred
);
}
/********************************** SIP Voiplink thread *************************************/
/**
* Reimplementation of run()
*/
void
SIPEventThread
::
run
(
void
)
void
EventThread
::
run
(
void
)
{
while
(
!
testCancel
())
{
_linkthread
->
getEvent
();
}
}
}
/********************************************************************************************/
src/eventthread.h
View file @
9aa98b7b
...
...
@@ -31,23 +31,17 @@ class VoIPLink;
class
EventThread
:
public
ost
::
Thread
{
friend
class
SIPEventThread
;
friend
class
IAXEventThread
;
public:
/**
* Thread constructor
*/
EventThread
(
VoIPLink
*
link
)
:
Thread
(),
_linkthread
(
link
){
setCancel
(
cancelDeferred
);
}
EventThread
(
VoIPLink
*
link
);
virtual
~
EventThread
(
void
){
~
EventThread
(
void
){
terminate
();
}
virtual
void
run
()
=
0
;
virtual
void
run
()
;
private:
EventThread
(
const
EventThread
&
rh
);
// copy constructor
...
...
@@ -57,25 +51,5 @@ class EventThread : public ost::Thread {
VoIPLink
*
_linkthread
;
};
class
IAXEventThread
:
public
EventThread
{
public:
IAXEventThread
(
VoIPLink
*
voiplink
)
:
EventThread
(
voiplink
){
}
virtual
void
run
();
};
class
SIPEventThread
:
public
EventThread
{
public:
SIPEventThread
(
VoIPLink
*
voiplink
)
:
EventThread
(
voiplink
){
}
virtual
void
run
();
};
#endif // __EVENT_THREAD_H__
src/iaxaccount.cpp
View file @
9aa98b7b
...
...
@@ -23,7 +23,7 @@
#include
"iaxvoiplink.h"
IAXAccount
::
IAXAccount
(
const
AccountID
&
accountID
)
:
Account
(
accountID
)
:
Account
(
accountID
,
"iax2"
)
{
_link
=
new
IAXVoIPLink
(
accountID
);
}
...
...
@@ -35,8 +35,7 @@ IAXAccount::~IAXAccount()
_link
=
NULL
;
}
int
IAXAccount
::
registerVoIPLink
()
int
IAXAccount
::
registerVoIPLink
()
{
IAXVoIPLink
*
thislink
;
...
...
src/iaxvoiplink.cpp
View file @
9aa98b7b
...
...
@@ -45,7 +45,7 @@
IAXVoIPLink
::
IAXVoIPLink
(
const
AccountID
&
accountID
)
:
VoIPLink
(
accountID
)
{
_evThread
=
new
IAX
EventThread
(
this
);
_evThread
=
new
EventThread
(
this
);
_regSession
=
NULL
;
_nextRefreshStamp
=
0
;
...
...
@@ -207,7 +207,7 @@ IAXVoIPLink::getEvent()
// Refresh registration.
if
(
_nextRefreshStamp
&&
_nextRefreshStamp
-
2
<
time
(
NULL
))
{
sendRegister
();
sendRegister
(
-
1
);
}
// thread wait 3 millisecond
...
...
@@ -308,7 +308,7 @@ IAXVoIPLink::getIAXCall(const CallID& id)
int
IAXVoIPLink
::
sendRegister
()
IAXVoIPLink
::
sendRegister
(
AccountID
id
UNUSED
)
{
bool
result
=
false
;
if
(
_host
.
empty
())
{
...
...
src/iaxvoiplink.h
View file @
9aa98b7b
...
...
@@ -76,7 +76,7 @@ class IAXVoIPLink : public VoIPLink
* Send out registration
* @return bool The new registration state (are we registered ?)
*/
int
sendRegister
(
vo
id
);
int
sendRegister
(
AccountID
id
);
/**
* Destroy registration session
...
...
src/managerimpl.cpp
View file @
9aa98b7b
...
...
@@ -680,7 +680,7 @@ ManagerImpl::startVoiceMessageNotification(const AccountID& accountId, int nb_ms
if
(
_dbus
)
_dbus
->
getCallManager
()
->
voiceMailNotify
(
accountId
,
nb_msg
)
;
}
void
ManagerImpl
::
connectionStatusNotification
(
void
)
void
ManagerImpl
::
connectionStatusNotification
(
)
{
if
(
_dbus
)
_dbus
->
getConfigurationManager
()
->
accountsChanged
();
...
...
@@ -1701,88 +1701,6 @@ int ManagerImpl::getSipPort( void )
}
/**
* configuration function requests
* Main Thread
*/
bool
ManagerImpl
::
getZeroconf
(
const
std
::
string
&
sequenceId
)
{
bool
returnValue
=
false
;
#ifdef USE_ZEROCONF
int
useZeroconf
=
getConfigInt
(
PREFERENCES
,
CONFIG_ZEROCONF
);
if
(
useZeroconf
&&
_dbus
!=
NULL
)
{
TokenList
arg
;
TokenList
argTXT
;
std
::
string
newService
=
"new service"
;
std
::
string
newTXT
=
"new txt record"
;
if
(
!
_DNSService
->
isStart
())
{
_DNSService
->
startScanServices
();
}
DNSServiceMap
services
=
_DNSService
->
getServices
();
DNSServiceMap
::
iterator
iter
=
services
.
begin
();
arg
.
push_back
(
newService
);
while
(
iter
!=
services
.
end
())
{
arg
.
push_front
(
iter
->
first
);
//_gui->sendMessage("100",sequenceId,arg);
arg
.
pop_front
();
// remove the first, the name
TXTRecordMap
record
=
iter
->
second
.
getTXTRecords
();
TXTRecordMap
::
iterator
iterTXT
=
record
.
begin
();
while
(
iterTXT
!=
record
.
end
())
{
argTXT
.
clear
();
argTXT
.
push_back
(
iter
->
first
);
argTXT
.
push_back
(
iterTXT
->
first
);
argTXT
.
push_back
(
iterTXT
->
second
);
argTXT
.
push_back
(
newTXT
);
// _gui->sendMessage("101",sequenceId,argTXT);
iterTXT
++
;
}
iter
++
;
}
returnValue
=
true
;
}
#else
(
void
)
sequenceId
;
#endif
return
returnValue
;
}
/**
* Main Thread
*/
bool
ManagerImpl
::
attachZeroconfEvents
(
const
std
::
string
&
sequenceId
,
Pattern
::
Observer
&
observer
)
{
bool
returnValue
=
false
;
// don't need the _gui like getZeroconf function
// because Observer is here
#ifdef USE_ZEROCONF
int
useZeroconf
=
getConfigInt
(
PREFERENCES
,
CONFIG_ZEROCONF
);
if
(
useZeroconf
)
{
if
(
!
_DNSService
->
isStart
())
{
_DNSService
->
startScanServices
();
}
_DNSService
->
attach
(
observer
);
returnValue
=
true
;
}
#else
(
void
)
sequenceId
;
(
void
)
observer
;
#endif
return
returnValue
;
}
bool
ManagerImpl
::
detachZeroconfEvents
(
Pattern
::
Observer
&
observer
)
{
bool
returnValue
=
false
;
#ifdef USE_ZEROCONF
if
(
_DNSService
)
{
_DNSService
->
detach
(
observer
);
returnValue
=
true
;
}
#else
(
void
)
observer
;
#endif
return
returnValue
;
}
// TODO: rewrite this
/**
* Main Thread
...
...
@@ -2227,8 +2145,25 @@ ManagerImpl::getAccountIdFromNameAndServer(const std::string& userName, const st
return
AccountNULL
;
}
VoIPLink
*
ManagerImpl
::
getAccountLink
(
const
AccountID
&
accountID
)
AccountMap
ManagerImpl
::
getSipAccountMap
(
void
)
{
AccountMap
::
iterator
iter
;
AccountMap
sipaccounts
;
AccountID
id
;
Account
*
account
;
for
(
iter
=
_accountMap
.
begin
();
iter
!=
_accountMap
.
end
();
++
iter
)
{
if
(
iter
->
second
->
getType
()
==
"sip"
){
//id = iter->first;
//account = iter->second;
//sipaccounts.insert( std::pair<id, account> );
}
}
return
sipaccounts
;
}
VoIPLink
*
ManagerImpl
::
getAccountLink
(
const
AccountID
&
accountID
)
{
Account
*
acc
=
getAccount
(
accountID
);
if
(
acc
)
{
...
...
src/managerimpl.h
View file @
9aa98b7b
...
...
@@ -271,9 +271,6 @@ class ManagerImpl {
*/
void
sendRegister
(
const
::
std
::
string
&
accountId
,
const
int32_t
&
expire
);
bool
getZeroconf
(
const
std
::
string
&
sequenceId
);
bool
attachZeroconfEvents
(
const
std
::
string
&
sequenceId
,
Pattern
::
Observer
&
observer
);
bool
detachZeroconfEvents
(
Pattern
::
Observer
&
observer
);
bool
getCallStatus
(
const
std
::
string
&
sequenceId
);
/**
...
...
@@ -798,6 +795,11 @@ class ManagerImpl {
void
registerCurSIPAccounts
();
/**
* Returns a map with only the existing SIP accounts
*/
AccountMap
getSipAccountMap
(
void
);
private:
/**
...
...
src/sipaccount.cpp
View file @
9aa98b7b
...
...
@@ -25,9 +25,7 @@
#include
"user_cfg.h"
SIPAccount
::
SIPAccount
(
const
AccountID
&
accountID
)
:
Account
(
accountID
)
,
_userName
(
""
)
,
_server
(
""
)
:
Account
(
accountID
,
"sip"
)
,
_cred
(
NULL
)
,
_contact
(
""
)
{
...
...
@@ -46,56 +44,51 @@ SIPAccount::~SIPAccount()
int
SIPAccount
::
registerVoIPLink
()
{
int
status
,
useStun
;
SIPVoIPLink
*
thislink
;
/* Retrieve the account information */
_link
->
setHostname
(
Manager
::
instance
().
getConfigString
(
_accountID
,
HOSTNAME
));
useStun
=
Manager
::
instance
().
getConfigInt
(
_accountID
,
SIP_USE_STUN
);
/* Stuff needed for SIP registration */
setHostname
(
Manager
::
instance
().
getConfigString
(
_accountID
,
HOSTNAME
));
setUsername
(
Manager
::
instance
().
getConfigString
(
_accountID
,
USERNAME
));
setPassword
(
Manager
::
instance
().
getConfigString
(
_accountID
,
PASSWORD
));
/* Retrieve STUN stuff */
/* STUN configuration is attached to a voiplink because it is applied to every accounts (PJSIP limitation)*/
thislink
=
dynamic_cast
<
SIPVoIPLink
*>
(
_link
);
thislink
->
setStunServer
(
Manager
::
instance
().
getConfigString
(
_accountID
,
SIP_STUN_SERVER
));
thislink
->
setUseStun
(
useStun
!=
0
?
true
:
false
);
if
(
thislink
)
{
useStun
=
Manager
::
instance
().
getConfigInt
(
_accountID
,
SIP_USE_STUN
);
thislink
->
setStunServer
(
Manager
::
instance
().
getConfigString
(
_accountID
,
SIP_STUN_SERVER
));
thislink
->
setUseStun
(
useStun
!=
0
?
true
:
false
);
}
/* Link initialization */
_link
->
init
();
// Stuff needed for SIP registration.
thislink
->
setUsername
(
Manager
::
instance
().
getConfigString
(
_accountID
,
USERNAME
));
thislink
->
setPassword
(
Manager
::
instance
().
getConfigString
(
_accountID
,
PASSWORD
));
thislink
->
setHostname
(
Manager
::
instance
().
getConfigString
(
_accountID
,
HOSTNAME
));
/
/
Start registration
status
=
_link
->
sendRegister
();
/
*
Start registration
*/
status
=
_link
->
sendRegister
(
_accountID
);
ASSERT
(
status
,
SUCCESS
);
return
SUCCESS
;
}
int
SIPAccount
::
unregisterVoIPLink
()
int
SIPAccount
::
unregisterVoIPLink
()
{
_debug
(
"SIPAccount: unregister account %s
\n
"
,
getAccountID
().
c_str
());
_link
->
sendUnregister
();
return
SUCCESS
;
return
_link
->
sendUnregister
();
}
void
SIPAccount
::
loadConfig
()
void
SIPAccount
::
loadConfig
()
{
// Account generic
Account
::
loadConfig
();
}
bool
SIPAccount
::
fullMatch
(
const
std
::
string
&
userName
,
const
std
::
string
&
server
)
bool
SIPAccount
::
fullMatch
(
const
std
::
string
&
username
,
const
std
::
string
&
hostname
)
{
return
(
user
N
ame
==
_u
ser
N
ame
&&
server
==
_server
);
return
(
user
n
ame
==
getU
ser
n
ame
()
&&
hostname
==
getHostname
()
);
}
bool
SIPAccount
::
userMatch
(
const
std
::
string
&
userName
)
bool
SIPAccount
::
userMatch
(
const
std
::
string
&
username
)
{
return
(
user
N
ame
==
_u
ser
N
ame
);
return
(
user
n
ame
==
getU
ser
n
ame
()
);
}
src/sipaccount.h
View file @
9aa98b7b
...
...
@@ -33,69 +33,75 @@ class SIPVoIPLink;
/**
* @file sipaccount.h
* @brief A SIP Account specify SIP specific functions and object (SIPCall/SIPVoIPLink)
*/
*/
class
SIPAccount
:
public
Account
{
public:
/**
* Constructor
* @param accountID The account identifier
*/
SIPAccount
(
const
AccountID
&
accountID
);
/* Copy Constructor */
SIPAccount
(
const
SIPAccount
&
rh
);
public:
/**
* Constructor
* @param accountID The account identifier
*/
SIPAccount
(
const
AccountID
&
accountID
);
/* Assignment Operator */
SIPAccount
&
operator
=
(
const
SIPAccount
&
rh
);
/**
* Virtual destructor
*/
virtual
~
SIPAccount
();
/* Copy Constructor */
SIPAccount
(
const
SIPAccount
&
rh
);
/**
* Actually unuseful, since config loading is done in init()
*/
void
loadConfig
();
/* Assignment Operator */
SIPAccount
&
operator
=
(
const
SIPAccount
&
rh
);
/**
* Initialize the SIP voip link with the account parameters and send registration
*/
int
registerVoIPLink
();
/**
* Virtual destructor
*/
virtual
~
SIPAccount
();
/**
* Send unregistration and clean all related stuff ( calls , thread )
*/
int
unregisterVoIPLink
();
/**
* Actually unuseful, since config loading is done in init()
*/
void
loadConfig
();
/**
* Initialize the SIP voip link with the account parameters and send registration
*/
int
registerVoIPLink
();
void
setUserName
(
const
std
::
string
&
name
)
{
_userName
=
name
;}
/**
* Send unregistration and clean all related stuff ( calls , thread )
*/
int
unregisterVoIPLink
();
std
::
string
getUserName
()
{
return
_userName
;}
inline
void
setCredInfo
(
pjsip_cred_info
*
cred
)
{
_cred
=
cred
;}
inline
pjsip_cred_info
*
getCredInfo
()
{
return
_cred
;}
void
setServer
(
const
std
::
string
&
server
)
{
_server
=
server
;}
inline
void
setContact
(
const
std
::
string
&
contact
)
{
_contact
=
contact
;}
inline
std
::
string
getContact
()
{
return
_contact
;}
std
::
string
getServer
()
{
return
_server
;}
bool
fullMatch
(
const
std
::
string
&
username
,
const
std
::
string
&
hostname
);
bool
userMatch
(
const
std
::
string
&
username
);
void
setCredInfo
(
pjsip_cred_info
*
cred
)
{
_cred
=
cred
;}
inline
std
::
string
getHostname
(
void
)
{
return
_hostname
;
}
inline
void
setHostname
(
std
::
string
hostname
)
{
_hostname
=
hostname
;
}
pjsip_cred_info
*
getCredInfo
()
{
return
_cred
;}
inline
std
::
string
getPassword
(
void
)
{
return
_password
;
}
inline
void
setPassword
(
std
::
string
password
)
{
_password
=
password
;
}
void
setContact
(
const
std
::
string
contact
)
{
_contact
=
contact
;}
inline
std
::
string
getAlias
(
void
)
{
return
_alias
;
}
inline
void
setAlias
(
std
::
string
alias
)
{
_alias
=
alias
;
}
std
::
string
getContact
()
{
return
_contact
;}
inline
std
::
string
getType
(
void
)
{
return
_type
;
}
inline
void
setType
(
std
::
string
type
)
{
_type
=
type
;
}
bool
fullMatch
(
const
std
::
string
&
userName
,
const
std
::
string
&
server
);
bool
userMatch
(
const
std
::
string
&
userName
);
private:
/**
* Credential information
*/
pjsip_cred_info
*
_cred
;
private:
std
::
string
_userName
;
std
::
string
_server
;
pjsip_cred_info
*
_cred
;
std
::
string
_contact
;
/*
* SIP address
*/
std
::
string
_contact
;
};
#endif
src/sipvoiplink.cpp
View file @
9aa98b7b
...
...
@@ -2,8 +2,7 @@
* Copyright (C) 2004-2009 Savoir-Faire Linux inc.
*