Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
savoirfairelinux
jami-daemon
Commits
b0a05007
Commit
b0a05007
authored
Aug 19, 2011
by
Tristan Matthews
Browse files
* #6699: cleanup account
parent
f079c6f2
Changes
6
Hide whitespace changes
Inline
Side-by-side
daemon/src/account.cpp
View file @
b0a05007
...
...
@@ -34,17 +34,17 @@
#include
"manager.h"
Account
::
Account
(
const
std
::
string
&
accountID
,
const
std
::
string
&
type
)
:
_
accountID
(
accountID
)
,
_
link
(
NULL
)
,
_
enabled
(
true
)
,
_
type
(
type
)
,
_
registrationState
(
Unregistered
)
,
_
codecOrder
()
,
_
codecStr
(
""
)
,
_
ringtonePath
(
"/usr/share/sflphone/ringtones/konga.ul"
)
,
_
ringtoneEnabled
(
true
)
,
_
displayName
(
""
)
,
_
user
a
gent
(
"SFLphone"
)
accountID
_
(
accountID
)
,
link
_
(
NULL
)
,
enabled
_
(
true
)
,
type
_
(
type
)
,
registrationState
_
(
Unregistered
)
,
codecOrder
_
()
,
codecStr
_
(
""
)
,
ringtonePath
_
(
"/usr/share/sflphone/ringtones/konga.ul"
)
,
ringtoneEnabled
_
(
true
)
,
displayName
_
(
""
)
,
user
A
gent
_
(
"SFLphone"
)
{
// Initialize the codec order, used when creating a new account
loadDefaultCodecs
();
...
...
@@ -54,10 +54,10 @@ Account::~Account()
{
}
void
Account
::
setRegistrationState
(
RegistrationState
state
)
void
Account
::
setRegistrationState
(
const
RegistrationState
&
state
)
{
if
(
state
!=
_
registrationState
)
{
_
registrationState
=
state
;
if
(
state
!=
registrationState
_
)
{
registrationState
_
=
state
;
// Notify the client
Manager
::
instance
().
connectionStatusNotification
();
...
...
@@ -87,16 +87,16 @@ void Account::loadDefaultCodecs()
void
Account
::
setActiveCodecs
(
const
std
::
vector
<
std
::
string
>
&
list
)
{
// first clear the previously stored codecs
_
codecOrder
.
clear
();
codecOrder
_
.
clear
();
// list contains the ordered payload of active codecs picked by the user for this account
// we used the CodecOrder vector to save the order.
size_t
i
,
size
=
list
.
size
();
for
(
i
=
0
;
i
<
size
;
i
++
)
{
int
payload
=
std
::
atoi
(
list
[
i
].
data
());
_
codecOrder
.
push_back
(
(
AudioCodecType
)
payload
);
for
(
std
::
vector
<
std
::
string
>::
const_iterator
iter
=
list
.
begin
();
iter
!
=
list
.
end
();
++
iter
)
{
int
payload
=
std
::
atoi
(
iter
->
c_str
());
codecOrder
_
.
push_back
(
(
AudioCodecType
)
payload
);
}
// update the codec string according to new codec selection
_
codecStr
=
ManagerImpl
::
serialize
(
list
);
codecStr
_
=
ManagerImpl
::
serialize
(
list
);
}
daemon/src/account.h
View file @
b0a05007
...
...
@@ -130,20 +130,20 @@ typedef enum RegistrationState {
// General configuration keys for accounts
const
std
::
string
aliasKey
(
"alias"
)
;
const
std
::
string
typeKey
(
"type"
)
;
const
std
::
string
idKey
(
"id"
)
;
const
std
::
string
usernameKey
(
"username"
)
;
const
std
::
string
authenticationUsernameKey
(
"authenticationUsername"
)
;
const
std
::
string
passwordKey
(
"password"
)
;
const
std
::
string
hostnameKey
(
"hostname"
)
;
const
std
::
string
accountEnableKey
(
"enable"
)
;
const
std
::
string
mailboxKey
(
"mailbox"
)
;
const
std
::
string
codecsKey
(
"codecs"
)
;
// 0/9/110/111/112/
const
std
::
string
ringtonePathKey
(
"ringtonePath"
)
;
const
std
::
string
ringtoneEnabledKey
(
"ringtoneEnabled"
)
;
const
std
::
string
displayNameKey
(
"displayName"
)
;
static
const
char
*
const
aliasKey
=
"alias"
;
static
const
char
*
const
typeKey
=
"type"
;
static
const
char
*
const
idKey
=
"id"
;
static
const
char
*
const
usernameKey
=
"username"
;
static
const
char
*
const
authenticationUsernameKey
=
"authenticationUsername"
;
static
const
char
*
const
passwordKey
=
"password"
;
static
const
char
*
const
hostnameKey
=
"hostname"
;
static
const
char
*
const
accountEnableKey
=
"enable"
;
static
const
char
*
const
mailboxKey
=
"mailbox"
;
static
const
char
*
const
codecsKey
=
"codecs"
;
// 0/9/110/111/112/
static
const
char
*
const
ringtonePathKey
=
"ringtonePath"
;
static
const
char
*
const
ringtoneEnabledKey
=
"ringtoneEnabled"
;
static
const
char
*
const
displayNameKey
=
"displayName"
;
class
Account
:
public
Serializable
{
...
...
@@ -182,8 +182,8 @@ class Account : public Serializable
* Get the account ID
* @return constant account id
*/
const
std
::
string
&
getAccountID
()
const
{
return
_
accountID
;
std
::
string
getAccountID
()
const
{
return
accountID
_
;
}
/**
...
...
@@ -191,7 +191,7 @@ class Account : public Serializable
* @return VoIPLink* the pointer or 0
*/
VoIPLink
*
getVoIPLink
()
const
{
return
_
link
;
return
link
_
;
}
virtual
void
setVoIPLink
()
=
0
;
...
...
@@ -214,11 +214,11 @@ class Account : public Serializable
* false otherwise
*/
bool
isEnabled
()
const
{
return
_
enabled
;
return
enabled
_
;
}
void
setEnabled
(
bool
enabl
)
{
_
enabled
=
enabl
;
void
setEnabled
(
bool
enabl
e
)
{
enabled
_
=
enabl
e
;
}
/**
...
...
@@ -226,14 +226,14 @@ class Account : public Serializable
* @return RegistrationState The registration state of underlying VoIPLink
*/
RegistrationState
getRegistrationState
()
const
{
return
_
registrationState
;
return
registrationState
_
;
}
/**
* Set the registration state of the specified link
* @param state The registration state of underlying VoIPLink
*/
void
setRegistrationState
(
RegistrationState
state
);
void
setRegistrationState
(
const
RegistrationState
&
state
);
/**
* Set the latest up-to-date state code
...
...
@@ -243,7 +243,7 @@ class Account : public Serializable
* @return void
*/
void
setRegistrationStateDetailed
(
std
::
pair
<
int
,
std
::
string
>
state
)
{
_
registrationStateDetailed
=
state
;
registrationStateDetailed
_
=
state
;
}
/**
...
...
@@ -254,37 +254,37 @@ class Account : public Serializable
* @return std::pair<int, std::string> A Code:Description state
*/
std
::
pair
<
int
,
std
::
string
>
getRegistrationStateDetailed
(
void
)
const
{
return
_
registrationStateDetailed
;
return
registrationStateDetailed
_
;
}
/* They should be treated like macro definitions by the C++ compiler */
std
::
string
getUsername
(
void
)
const
{
return
_
username
;
return
username
_
;
}
void
setUsername
(
const
std
::
string
&
username
)
{
_
username
=
username
;
username
_
=
username
;
}
std
::
string
getHostname
(
void
)
const
{
return
_
hostname
;
return
hostname
_
;
}
void
setHostname
(
const
std
::
string
&
hostname
)
{
_
hostname
=
hostname
;
hostname
_
=
hostname
;
}
std
::
string
getAlias
(
void
)
const
{
return
_
alias
;
return
alias
_
;
}
void
setAlias
(
const
std
::
string
&
alias
)
{
_
alias
=
alias
;
alias
_
=
alias
;
}
std
::
string
getType
(
void
)
const
{
return
_
type
;
return
type
_
;
}
void
setType
(
const
std
::
string
&
type
)
{
_
type
=
type
;
type
_
=
type
;
}
/**
...
...
@@ -292,7 +292,7 @@ class Account : public Serializable
* @return CodecOrder& The list that reflects the user's choice
*/
const
CodecOrder
&
getActiveCodecs
(
void
)
const
{
return
_
codecOrder
;
return
codecOrder
_
;
}
/**
...
...
@@ -302,39 +302,39 @@ class Account : public Serializable
void
setActiveCodecs
(
const
std
::
vector
<
std
::
string
>&
list
);
std
::
string
getRingtonePath
(
void
)
const
{
return
_
ringtonePath
;
return
ringtonePath
_
;
}
void
setRingtonePath
(
const
std
::
string
&
path
)
{
_
ringtonePath
=
path
;
ringtonePath
_
=
path
;
}
bool
getRingtoneEnabled
(
void
)
const
{
return
_
ringtoneEnabled
;
return
ringtoneEnabled
_
;
}
void
setRingtoneEnabled
(
bool
enabl
)
{
_
ringtoneEnabled
=
enabl
;
void
setRingtoneEnabled
(
bool
enabl
e
)
{
ringtoneEnabled
_
=
enabl
e
;
}
std
::
string
getDisplayName
(
void
)
const
{
return
_
displayName
;
return
displayName
_
;
}
void
setDisplayName
(
const
std
::
string
&
name
)
{
_
displayName
=
name
;
displayName
_
=
name
;
}
std
::
string
getUser
a
gent
(
void
)
const
{
return
_
user
a
gent
;
std
::
string
getUser
A
gent
(
void
)
const
{
return
user
A
gent
_
;
}
void
setUseragent
(
const
std
::
string
&
ua
)
{
_
user
a
gent
=
ua
;
user
A
gent
_
=
ua
;
}
std
::
string
getMailBox
(
void
)
const
{
return
_
mailBox
;
return
mailBox
_
;
}
void
setMailBox
(
const
std
::
string
&
mb
)
{
_
mailBox
=
mb
;
mailBox
_
=
mb
;
}
private:
...
...
@@ -352,93 +352,92 @@ class Account : public Serializable
protected:
/**
* Account ID are assign in constructor and shall not changed
*/
const
std
::
string
_
accountID
;
const
std
::
string
accountID
_
;
/**
* Account login information: username
*/
std
::
string
_
username
;
std
::
string
username
_
;
/**
* Account login information: hostname
*/
std
::
string
_
hostname
;
std
::
string
hostname
_
;
/**
* Account login information: Alias
*/
std
::
string
_
alias
;
std
::
string
alias
_
;
/**
* Voice over IP Link contains a listener thread and calls
*/
VoIPLink
*
_
link
;
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
;
bool
enabled
_
;
/*
* The account type
* IAX2 or SIP
*/
std
::
string
_
type
;
std
::
string
type
_
;
/*
* The general, protocol neutral registration
* state of the account
*/
RegistrationState
_
registrationState
;
RegistrationState
registrationState
_
;
/*
* Details about the registration state.
* This is a protocol Code:Description pair.
*/
std
::
pair
<
int
,
std
::
string
>
_
registrationStateDetailed
;
std
::
pair
<
int
,
std
::
string
>
registrationStateDetailed
_
;
/**
* Vector containing the order of the codecs
*/
CodecOrder
_
codecOrder
;
CodecOrder
codecOrder
_
;
/**
* List of codec obtained when parsing configuration and used
* to generate codec order list
*/
std
::
string
_
codecStr
;
std
::
string
codecStr
_
;
/**
* Ringtone .au file used for this account
*/
std
::
string
_
ringtonePath
;
std
::
string
ringtonePath
_
;
/**
* Play ringtone when receiving a call
*/
bool
_
ringtoneEnabled
;
bool
ringtoneEnabled
_
;
/**
* Display name when calling
*/
std
::
string
_
displayName
;
std
::
string
displayName
_
;
/**
* Useragent used for registration
*/
std
::
string
_
user
a
gent
;
std
::
string
user
A
gent
_
;
/**
* Account mail box
*/
std
::
string
_
mailBox
;
std
::
string
mailBox
_
;
};
...
...
daemon/src/iax/iaxaccount.cpp
View file @
b0a05007
...
...
@@ -38,35 +38,35 @@
IAXAccount
::
IAXAccount
(
const
std
::
string
&
accountID
)
:
Account
(
accountID
,
"iax2"
)
{
_
link
=
new
IAXVoIPLink
(
accountID
);
link
_
=
new
IAXVoIPLink
(
accountID
);
}
IAXAccount
::~
IAXAccount
()
{
delete
_
link
;
delete
link
_
;
}
void
IAXAccount
::
serialize
(
Conf
::
YamlEmitter
*
emitter
)
{
if
(
emitter
==
NULL
)
{
if
(
emitter
==
NULL
)
{
_error
(
"IAXAccount: Error: emitter is NULL in serialize"
);
return
;
}
Conf
::
MappingNode
accountmap
(
NULL
);
Conf
::
ScalarNode
id
(
Account
::
_
accountID
);
Conf
::
ScalarNode
username
(
Account
::
_
username
);
Conf
::
ScalarNode
password
(
_
password
);
Conf
::
ScalarNode
alias
(
Account
::
_
alias
);
Conf
::
ScalarNode
hostname
(
Account
::
_
hostname
);
Conf
::
ScalarNode
enable
(
_
enabled
);
Conf
::
ScalarNode
type
(
Account
::
_
type
);
Conf
::
ScalarNode
mailbox
(
_
mailBox
);
Conf
::
ScalarNode
id
(
accountID
_
);
Conf
::
ScalarNode
username
(
username
_
);
Conf
::
ScalarNode
password
(
password
_
);
Conf
::
ScalarNode
alias
(
alias
_
);
Conf
::
ScalarNode
hostname
(
hostname
_
);
Conf
::
ScalarNode
enable
(
enabled
_
);
Conf
::
ScalarNode
type
(
type
_
);
Conf
::
ScalarNode
mailbox
(
mailBox
_
);
Conf
::
ScalarNode
codecs
(
_
codecStr
);
Conf
::
ScalarNode
displayName
(
_
displayName
);
Conf
::
ScalarNode
codecs
(
codecStr
_
);
Conf
::
ScalarNode
displayName
(
displayName
_
);
accountmap
.
setKeyValue
(
aliasKey
,
&
alias
);
accountmap
.
setKeyValue
(
typeKey
,
&
type
);
...
...
@@ -89,68 +89,66 @@ void IAXAccount::serialize (Conf::YamlEmitter *emitter)
void
IAXAccount
::
unserialize
(
Conf
::
MappingNode
*
map
)
{
if
(
map
==
NULL
)
{
if
(
map
==
NULL
)
{
_error
(
"IAXAccount: Error: Map is NULL in unserialize"
);
return
;
}
map
->
getValue
(
aliasKey
,
&
_
alias
);
map
->
getValue
(
typeKey
,
&
_
type
);
map
->
getValue
(
usernameKey
,
&
_
username
);
map
->
getValue
(
passwordKey
,
&
_
password
);
map
->
getValue
(
hostnameKey
,
&
_
hostname
);
map
->
getValue
(
accountEnableKey
,
&
_
enabled
);
map
->
getValue
(
mailboxKey
,
&
_
mailBox
);
map
->
getValue
(
codecsKey
,
&
_
codecStr
);
map
->
getValue
(
aliasKey
,
&
alias
_
);
map
->
getValue
(
typeKey
,
&
type
_
);
map
->
getValue
(
usernameKey
,
&
username
_
);
map
->
getValue
(
passwordKey
,
&
password
_
);
map
->
getValue
(
hostnameKey
,
&
hostname
_
);
map
->
getValue
(
accountEnableKey
,
&
enabled
_
);
map
->
getValue
(
mailboxKey
,
&
mailBox
_
);
map
->
getValue
(
codecsKey
,
&
codecStr
_
);
// Update codec list which one is used for SDP offer
setActiveCodecs
(
ManagerImpl
::
unserialize
(
_
codecStr
));
map
->
getValue
(
displayNameKey
,
&
_
displayName
);
setActiveCodecs
(
ManagerImpl
::
unserialize
(
codecStr
_
));
map
->
getValue
(
displayNameKey
,
&
displayName
_
);
}
void
IAXAccount
::
setAccountDetails
(
std
::
map
<
std
::
string
,
std
::
string
>
details
)
{
// Account setting common to SIP and IAX
setAlias
(
details
[
CONFIG_ACCOUNT_ALIAS
]);
setType
(
details
[
CONFIG_ACCOUNT_TYPE
]);
setUsername
(
details
[
USERNAME
]);
setHostname
(
details
[
HOSTNAME
]);
_password
=
(
details
[
PASSWORD
]);
setEnabled
(
(
details
[
CONFIG_ACCOUNT_ENABLE
].
compare
(
"true"
)
==
0
));
setMailBox
(
details
[
CONFIG_ACCOUNT_MAILBOX
]);
setDisplayName
(
details
[
DISPLAY_NAME
]);
setUseragent
(
details
[
USERAGENT
]);
alias_
=
details
[
CONFIG_ACCOUNT_ALIAS
];
type_
=
details
[
CONFIG_ACCOUNT_TYPE
];
username_
=
details
[
USERNAME
];
hostname_
=
details
[
HOSTNAME
];
password_
=
details
[
PASSWORD
];
enabled_
=
details
[
CONFIG_ACCOUNT_ENABLE
]
==
"true"
;
mailBox_
=
details
[
CONFIG_ACCOUNT_MAILBOX
];
displayName_
=
details
[
DISPLAY_NAME
];
userAgent_
=
details
[
USERAGENT
];
}
std
::
map
<
std
::
string
,
std
::
string
>
IAXAccount
::
getAccountDetails
()
const
{
std
::
map
<
std
::
string
,
std
::
string
>
a
;
a
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
ACCOUNT_ID
,
_
accountID
))
;
a
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
CONFIG_ACCOUNT_ALIAS
,
getAlias
()))
;
a
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
CONFIG_ACCOUNT_ENABLE
,
isE
nabled
()
?
"true"
:
"false"
))
;
a
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
CONFIG_ACCOUNT_TYPE
,
getType
()))
;
a
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
HOSTNAME
,
getH
ostname
()))
;
a
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
USERNAME
,
getU
sername
()))
;
a
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
PASSWORD
,
getP
assword
()))
;
a
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
CONFIG_ACCOUNT_MAILBOX
,
getM
ailBox
()))
;
a
[
ACCOUNT_ID
]
=
accountID
_
;
a
[
CONFIG_ACCOUNT_ALIAS
]
=
alias_
;
a
[
CONFIG_ACCOUNT_ENABLE
]
=
e
nabled
_
?
"true"
:
"false"
;
a
[
CONFIG_ACCOUNT_TYPE
]
=
type_
;
a
[
HOSTNAME
]
=
h
ostname
_
;
a
[
USERNAME
]
=
u
sername
_
;
a
[
PASSWORD
]
=
p
assword
_
;
a
[
CONFIG_ACCOUNT_MAILBOX
]
=
m
ailBox
_
;
RegistrationState
state
=
Unregistered
;
std
::
string
registrationStateCode
;
std
::
string
registrationStateDescription
;
state
=
getR
egistrationState
(
);
RegistrationState
state
(
r
egistrationState
_
);
int
code
=
getRegistrationStateDetailed
().
first
;
std
::
stringstream
out
;
out
<<
code
;
registrationStateCode
=
out
.
str
();
registrationStateDescription
=
getRegistrationStateDetailed
().
second
;
a
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
REGISTRATION_STATUS
,
Manager
::
instance
().
mapStateNumberToString
(
state
)
))
;
a
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
REGISTRATION_STATE_CODE
,
registrationStateCode
))
;
a
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
REGISTRATION_STATE_DESCRIPTION
,
registrationStateDescription
))
;
a
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
USERAGENT
,
getU
ser
a
gent
()))
;
a
[
REGISTRATION_STATUS
]
=
Manager
::
instance
().
mapStateNumberToString
(
state
);
a
[
REGISTRATION_STATE_CODE
]
=
registrationStateCode
;
a
[
REGISTRATION_STATE_DESCRIPTION
]
=
registrationStateDescription
;
a
[
USERAGENT
]
=
u
ser
A
gent
_
;
return
a
;
}
...
...
@@ -158,22 +156,16 @@ std::map<std::string, std::string> IAXAccount::getAccountDetails() const
void
IAXAccount
::
setVoIPLink
()
{
}
int
IAXAccount
::
registerVoIPLink
()
{
try
{
link_
->
init
();
_link
->
init
();
// Stuff needed for IAX registration
setHostname
(
_hostname
);
setUsername
(
_username
);
_link
->
sendRegister
(
this
);
link_
->
sendRegister
(
this
);
}
catch
(
VoipLinkException
&
e
)
{
catch
(
const
VoipLinkException
&
e
)
{
_error
(
"IAXAccount: %s"
,
e
.
what
());
}
...
...
@@ -184,12 +176,11 @@ int
IAXAccount
::
unregisterVoIPLink
()
{
try
{
_link
->
sendUnregister
(
this
);
_link
->
terminate
();
link_
->
sendUnregister
(
this
);
link_
->
terminate
();
return
0
;
}
catch
(
VoipLinkException
&
e
)
{
catch
(
const
VoipLinkException
&
e
)
{
_error
(
"IAXAccount: %s"
,
e
.
what
());
}
...
...
@@ -201,6 +192,6 @@ IAXAccount::loadConfig()
{
// If IAX is not supported, do not register this account
#if !HAVE_IAX
_
enabled
=
false
;
enabled
_
=
false
;
#endif
}
daemon/src/iax/iaxaccount.h
View file @
b0a05007
...
...
@@ -69,8 +69,8 @@ class IAXAccount : public Account
*/
int
unregisterVoIPLink
();
const
std
::
string
&
getPassword
(
void
)
const
{
return
_
password
;
std
::
string
getPassword
(
void
)
const
{
return
password
_
;
}
private:
...
...
@@ -78,7 +78,7 @@ class IAXAccount : public Account
/**
* Account login information: password
*/
std
::
string
_
password
;
std
::
string
password
_
;
};
#endif
daemon/src/sip/sipaccount.cpp
View file @
b0a05007
...
...
@@ -93,8 +93,8 @@ SIPAccount::SIPAccount (const std::string& accountID)
SIPAccount
::~
SIPAccount
()
{
/* One SIP account less connected to the sip voiplink */
if
(
_
accountID
!=
"default"
)
dynamic_cast
<
SIPVoIPLink
*>
(
_
link
)
->
decrementClients
();
if
(
accountID
_
!=
"default"
)
dynamic_cast
<
SIPVoIPLink
*>
(
link
_
)
->
decrementClients
();