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
92431fe9
Commit
92431fe9
authored
Sep 21, 2007
by
Alexandre Bourget
Committed by
Alexandre Bourget
Sep 24, 2007
Browse files
Beginning of CONFIGURATION rework.
parent
deda3bae
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/config/config.cpp
View file @
92431fe9
...
...
@@ -19,6 +19,7 @@
*/
#include
"config.h"
#include
"../global.h"
#include
<fstream>
namespace
Conf
{
...
...
@@ -50,6 +51,22 @@ ConfigTree::createSection(const std::string& section) {
}
}
/** Retrieve the sections as an array */
TokenList
ConfigTree
::
getSections
()
{
TokenList
sections
;
SectionMap
::
iterator
iter
=
_sections
.
begin
();
while
(
iter
!=
_sections
.
end
())
{
// add to token list the: iter->second;
sections
.
push_back
(
iter
->
first
);
iter
++
;
}
return
sections
;
}
/**
* Add the config item only if it exists..
* If the section doesn't exists, create it
...
...
@@ -73,15 +90,41 @@ ConfigTree::addConfigTreeItem(const std::string& section, const ConfigTreeItem i
}
}
/**
* Add the config item only if it doesn't exist. Set the default value.
*/
void
ConfigTree
::
verifyConfigTreeItem
(
const
std
::
string
&
section
,
const
std
::
string
&
itemName
,
const
std
::
string
&
defaultValue
,
const
std
::
string
&
type
)
{
// Create section if it doesn't exist.
SectionMap
::
iterator
iter
=
_sections
.
find
(
section
);
if
(
iter
==
_sections
.
end
())
{
_sections
[
section
]
=
new
ItemMap
;
iter
=
_sections
.
find
(
section
);
}
// Check for the item, and add it if necessary (with default value).
ItemMap
::
iterator
iterItem
=
iter
->
second
->
find
(
itemName
);
if
(
iterItem
==
iter
->
second
->
end
())
{
// It's not there, create it.
addConfigTreeItem
(
section
,
ConfigTreeItem
(
itemName
,
defaultValue
,
type
));
}
}
// throw a ConfigTreeItemException if not found
std
::
string
ConfigTree
::
getConfigTreeItemValue
(
const
std
::
string
&
section
,
const
std
::
string
&
itemName
)
{
ConfigTreeItem
*
item
=
getConfigTreeItem
(
section
,
itemName
);
if
(
item
!=
NULL
)
{
if
(
item
!=
NULL
)
{
return
item
->
getValue
();
}
else
{
throw
ConfigTreeItemException
();
_debug
(
"Unknown config option: [%s] %s
\n
"
,
section
.
c_str
(),
itemName
.
c_str
());
//throw ConfigTreeItemException();
}
return
""
;
}
...
...
@@ -91,10 +134,11 @@ int
ConfigTree
::
getConfigTreeItemIntValue
(
const
std
::
string
&
section
,
const
std
::
string
&
itemName
)
{
ConfigTreeItem
*
item
=
getConfigTreeItem
(
section
,
itemName
);
if
(
item
!=
NULL
&&
item
->
getType
()
==
"int"
)
{
if
(
item
!=
NULL
&&
item
->
getType
()
==
"int"
)
{
return
atoi
(
item
->
getValue
().
data
());
}
else
{
throw
ConfigTreeItemException
();
_debug
(
"Unknown config (int) option: [%s] %s
\n
"
,
section
.
c_str
(),
itemName
.
c_str
());
//throw ConfigTreeItemException();
}
return
0
;
}
...
...
@@ -133,17 +177,28 @@ ConfigTree::getConfigTreeItem(const std::string& section, const std::string& ite
}
/**
* Set the configItem if found, else do nothing
* Set the configItem if found, if not, *CREATE IT*
*
* @todo Faudra démêler tout ça, le verifyConfigTreeItem et setConfigTree qui font
* la même chose, et qui, inutilement, y'a plein de restrictions.
* @todo Élimier les 45,000 classes qui servent à rien pour Conf.
*/
bool
ConfigTree
::
setConfigTreeItem
(
const
std
::
string
&
section
,
const
std
::
string
&
itemName
,
const
std
::
string
&
value
)
{
ConfigTree
::
setConfigTreeItem
(
const
std
::
string
&
section
,
const
std
::
string
&
itemName
,
const
std
::
string
&
value
)
{
SectionMap
::
iterator
iter
=
_sections
.
find
(
section
);
if
(
iter
==
_sections
.
end
())
{
return
false
;
// Not found, create section
_sections
[
section
]
=
new
ItemMap
;
iter
=
_sections
.
find
(
section
);
}
ItemMap
::
iterator
iterItem
=
iter
->
second
->
find
(
itemName
);
if
(
iterItem
==
iter
->
second
->
end
())
{
return
false
;
// Item not found, create it, defaults to type "string"
addConfigTreeItem
(
section
,
ConfigTreeItem
(
itemName
,
value
,
"string"
));
return
true
;
}
iterItem
->
second
.
setValue
(
value
);
return
true
;
...
...
@@ -230,7 +285,6 @@ ConfigTree::populateFromFile(const std::string& fileName) {
// If the line is a section
pos
=
line
.
find
(
']'
);
section
=
line
.
substr
(
1
,
pos
-
1
);
}
else
if
(
line
[
0
]
!=
'#'
)
{
// If the line is "key=value" and doesn't begin with '#'(comments)
...
...
src/iaxaccount.cpp
View file @
92431fe9
...
...
@@ -93,11 +93,11 @@ IAXAccount::initConfig(Conf::ConfigTree& config)
Account
::
initConfig
(
config
);
// IAX specific
config
.
add
ConfigTreeItem
(
section
,
Conf
::
ConfigTreeItem
(
CONFIG_ACCOUNT_TYPE
,
"IAX"
,
type_str
)
)
;
config
.
add
ConfigTreeItem
(
section
,
Conf
::
ConfigTreeItem
(
IAX_FULL_NAME
,
""
,
type_str
)
)
;
config
.
add
ConfigTreeItem
(
section
,
Conf
::
ConfigTreeItem
(
IAX_HOST
,
""
,
type_str
)
)
;
config
.
add
ConfigTreeItem
(
section
,
Conf
::
ConfigTreeItem
(
IAX_USER
,
""
,
type_str
)
)
;
config
.
add
ConfigTreeItem
(
section
,
Conf
::
ConfigTreeItem
(
IAX_PASS
,
""
,
type_str
)
)
;
config
.
verify
ConfigTreeItem
(
section
,
CONFIG_ACCOUNT_TYPE
,
"IAX"
,
type_str
);
config
.
verify
ConfigTreeItem
(
section
,
IAX_FULL_NAME
,
""
,
type_str
);
config
.
verify
ConfigTreeItem
(
section
,
IAX_HOST
,
""
,
type_str
);
config
.
verify
ConfigTreeItem
(
section
,
IAX_USER
,
""
,
type_str
);
config
.
verify
ConfigTreeItem
(
section
,
IAX_PASS
,
""
,
type_str
);
}
void
...
...
src/managerimpl.cpp
View file @
92431fe9
...
...
@@ -91,7 +91,7 @@ ManagerImpl::ManagerImpl (void)
#endif
// should be call before initConfigFile
loadAccountMap
();
//
loadAccountMap();
, called in init() now.
}
// never call if we use only the singleton...
...
...
@@ -109,6 +109,9 @@ ManagerImpl::~ManagerImpl (void)
void
ManagerImpl
::
init
()
{
// Load accounts, init map
loadAccountMap
();
initVolume
();
if
(
_exist
==
0
)
{
...
...
@@ -147,10 +150,10 @@ void ManagerImpl::terminate()
delete
_dtmfKey
;
_debug
(
"Unload Audio Driver
\n
"
);
delete
_audiodriver
;
_audiodriver
=
0
;
delete
_audiodriver
;
_audiodriver
=
NULL
;
_debug
(
"Unload Telephone Tone
\n
"
);
delete
_telephoneTone
;
_telephoneTone
=
0
;
delete
_telephoneTone
;
_telephoneTone
=
NULL
;
}
bool
...
...
@@ -1004,8 +1007,6 @@ ManagerImpl::behindNat(const std::string& svr, int port)
* Initialization: Main Thread
* @return 1: ok
-1: error directory
0: unable to load the setting
2: file doesn't exist yet
*/
int
ManagerImpl
::
createSettingsPath
(
void
)
{
...
...
@@ -1021,7 +1022,7 @@ ManagerImpl::createSettingsPath (void) {
// Load user's configuration
_path
=
_path
+
DIR_SEPARATOR_STR
+
PROGNAME
+
"rc"
;
return
_config
.
populateFromFile
(
_path
)
;
return
1
;
}
/**
...
...
@@ -1063,7 +1064,10 @@ ManagerImpl::initConfigFile (void)
initConfigAccount
();
_exist
=
createSettingsPath
();
if
(
createSettingsPath
()
==
1
)
{
_exist
=
_config
.
populateFromFile
(
_path
);
}
_setupLoaded
=
(
_exist
==
2
)
?
false
:
true
;
}
...
...
@@ -1308,6 +1312,7 @@ ManagerImpl::getCallStatus(const std::string& sequenceId)
}
//THREAD=Main
/* Unused, Deprecated */
bool
ManagerImpl
::
getConfigAll
(
const
std
::
string
&
sequenceId
)
{
...
...
@@ -1379,7 +1384,7 @@ ManagerImpl::getConfigList(const std::string& sequenceId, const std::string& nam
{
bool
returnValue
=
false
;
TokenList
tk
;
if
(
name
==
"codecdescriptor"
)
{
if
(
name
==
"codecdescriptor"
)
{
CodecMap
map
=
_codecDescriptorMap
.
getMap
();
CodecMap
::
iterator
iter
=
map
.
begin
();
...
...
@@ -1397,7 +1402,7 @@ ManagerImpl::getConfigList(const std::string& sequenceId, const std::string& nam
iter
++
;
}
returnValue
=
true
;
}
else
if
(
name
==
"ringtones"
)
{
}
else
if
(
name
==
"ringtones"
)
{
// add empty line
std
::
ostringstream
str
;
str
<<
1
;
...
...
@@ -1413,13 +1418,13 @@ ManagerImpl::getConfigList(const std::string& sequenceId, const std::string& nam
// home directory
path
=
std
::
string
(
HOMEDIR
)
+
DIR_SEPARATOR_STR
+
"."
+
PROGDIR
+
DIR_SEPARATOR_STR
+
RINGDIR
;
getDirListing
(
sequenceId
,
path
,
&
nbFile
);
}
else
if
(
name
==
"audiodevice"
)
{
}
else
if
(
name
==
"audiodevice"
)
{
returnValue
=
getAudioDeviceList
(
sequenceId
,
AudioLayer
::
InputDevice
|
AudioLayer
::
OutputDevice
);
}
else
if
(
name
==
"audiodevicein"
)
{
}
else
if
(
name
==
"audiodevicein"
)
{
returnValue
=
getAudioDeviceList
(
sequenceId
,
AudioLayer
::
InputDevice
);
}
else
if
(
name
==
"audiodeviceout"
)
{
}
else
if
(
name
==
"audiodeviceout"
)
{
returnValue
=
getAudioDeviceList
(
sequenceId
,
AudioLayer
::
OutputDevice
);
}
else
if
(
name
==
"countrytones"
)
{
}
else
if
(
name
==
"countrytones"
)
{
returnValue
=
getCountryTones
(
sequenceId
);
}
return
returnValue
;
...
...
@@ -1694,7 +1699,8 @@ ManagerImpl::setAccountDetails( const ::DBus::String& accountID,
}
saveConfig
();
/** @todo Then, reset the VoIP link with the new information */
}
void
...
...
@@ -1742,9 +1748,9 @@ ManagerImpl::setSwitch(const std::string& switchName, std::string& message) {
_toneMutex
.
enterMutex
();
_debug
(
"Unload Telephone Tone
\n
"
);
delete
_telephoneTone
;
_telephoneTone
=
0
;
delete
_telephoneTone
;
_telephoneTone
=
NULL
;
_debug
(
"Unload DTMF Key
\n
"
);
delete
_dtmfKey
;
_dtmfKey
=
0
;
delete
_dtmfKey
;
_dtmfKey
=
NULL
;
_debug
(
"Load Telephone Tone
\n
"
);
std
::
string
country
=
getConfigString
(
PREFERENCES
,
ZONE_TONE
);
...
...
@@ -1836,8 +1842,43 @@ ManagerImpl::loadAccountMap()
{
_debugStart
(
"Load account:"
);
short
nbAccount
=
0
;
TokenList
sections
=
_config
.
getSections
();
std
::
string
accountType
;
Account
*
tmpAccount
;
// iter = std::string
TokenList
::
iterator
iter
=
sections
.
begin
();
while
(
iter
!=
sections
.
end
())
{
// Check if it starts with "Account:" (SIP and IAX pour le moment)
if
(
iter
->
find
(
"Account:"
)
==
-
1
)
{
iter
++
;
continue
;
}
accountType
=
getConfigString
(
*
iter
,
CONFIG_ACCOUNT_TYPE
);
if
(
accountType
==
"SIP"
)
{
tmpAccount
=
AccountCreator
::
createAccount
(
AccountCreator
::
SIP_ACCOUNT
,
*
iter
);
}
else
if
(
accountType
==
"IAX"
)
{
tmpAccount
=
AccountCreator
::
createAccount
(
AccountCreator
::
IAX_ACCOUNT
,
*
iter
);
}
else
{
_debug
(
"Unknown %s param in config file (%s)
\n
"
,
CONFIG_ACCOUNT_TYPE
,
accountType
.
c_str
());
}
if
(
tmpAccount
!=
NULL
)
{
_debugMid
(
" %s "
,
iter
->
c_str
());
_accountMap
[
iter
->
c_str
()]
=
tmpAccount
;
nbAccount
++
;
}
_debugEnd
(
"
\n
"
);
iter
++
;
}
/*
// SIP Loading X account...
short nbAccountSIP = ACCOUNT_SIP_COUNT_DEFAULT;
for (short iAccountSIP = 0; iAccountSIP<nbAccountSIP; iAccountSIP++) {
...
...
@@ -1865,6 +1906,7 @@ ManagerImpl::loadAccountMap()
}
}
_debugEnd("\n");
*/
return
nbAccount
;
}
...
...
src/sipaccount.cpp
View file @
92431fe9
...
...
@@ -103,15 +103,15 @@ SIPAccount::initConfig(Conf::ConfigTree& config)
Account
::
initConfig
(
config
);
// SIP specific
config
.
add
ConfigTreeItem
(
section
,
Conf
::
ConfigTreeItem
(
CONFIG_ACCOUNT_TYPE
,
"SIP"
,
type_str
)
)
;
config
.
add
ConfigTreeItem
(
section
,
Conf
::
ConfigTreeItem
(
SIP_FULL_NAME
,
""
,
type_str
)
)
;
config
.
add
ConfigTreeItem
(
section
,
Conf
::
ConfigTreeItem
(
SIP_USER_PART
,
""
,
type_str
)
)
;
config
.
add
ConfigTreeItem
(
section
,
Conf
::
ConfigTreeItem
(
SIP_HOST_PART
,
""
,
type_str
)
)
;
config
.
add
ConfigTreeItem
(
section
,
Conf
::
ConfigTreeItem
(
SIP_AUTH_NAME
,
""
,
type_str
)
)
;
config
.
add
ConfigTreeItem
(
section
,
Conf
::
ConfigTreeItem
(
SIP_PASSWORD
,
""
,
type_str
)
)
;
config
.
add
ConfigTreeItem
(
section
,
Conf
::
ConfigTreeItem
(
SIP_PROXY
,
""
,
type_str
)
)
;
config
.
add
ConfigTreeItem
(
section
,
Conf
::
ConfigTreeItem
(
SIP_STUN_SERVER
,
"stun.fwdnet.net:3478"
,
type_str
)
)
;
config
.
add
ConfigTreeItem
(
section
,
Conf
::
ConfigTreeItem
(
SIP_USE_STUN
,
"0"
,
type_int
)
)
;
config
.
verify
ConfigTreeItem
(
section
,
CONFIG_ACCOUNT_TYPE
,
"SIP"
,
type_str
);
config
.
verify
ConfigTreeItem
(
section
,
SIP_FULL_NAME
,
""
,
type_str
);
config
.
verify
ConfigTreeItem
(
section
,
SIP_USER_PART
,
""
,
type_str
);
config
.
verify
ConfigTreeItem
(
section
,
SIP_HOST_PART
,
""
,
type_str
);
config
.
verify
ConfigTreeItem
(
section
,
SIP_AUTH_NAME
,
""
,
type_str
);
config
.
verify
ConfigTreeItem
(
section
,
SIP_PASSWORD
,
""
,
type_str
);
config
.
verify
ConfigTreeItem
(
section
,
SIP_PROXY
,
""
,
type_str
);
config
.
verify
ConfigTreeItem
(
section
,
SIP_STUN_SERVER
,
"stun.fwdnet.net:3478"
,
type_str
);
config
.
verify
ConfigTreeItem
(
section
,
SIP_USE_STUN
,
"0"
,
type_int
);
}
void
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment