Commit 532b35b1 authored by Alexandre Savard's avatar Alexandre Savard

[#3649] Implement unserialize method for accounts

parent c8164af5
......@@ -37,6 +37,7 @@
#include "config/config.h"
#include "voiplink.h"
#include "config/serializable.h"
class VoIPLink;
......@@ -131,7 +132,19 @@ typedef enum RegistrationState {
#define REGISTRATION_STATE_DESCRIPTION "Registration.description"
class Account{
// General configuration keys for accounts
const Conf::Key aliasKey("alias");
const Conf::Key typeKey("type");
const Conf::Key idKey("id");
const Conf::Key usernameKey("username");
const Conf::Key passwordKey("password");
const Conf::Key hostnameKey("hostname");
const Conf::Key accountEnableKey("enable");
const Conf::Key mailboxKey("mailbox");
const Conf::Key codecsKey("codecs"); // 0/9/110/111/112/
class Account : public Serializable{
public:
......@@ -142,6 +155,10 @@ class Account{
*/
virtual ~Account();
virtual void serialize(Engine *engine) = 0;
virtual void unserialize(Conf::MappingNode *map) = 0;
/**
* Load the settings for this account.
*/
......
......@@ -46,45 +46,12 @@ namespace Conf
// ctor
ConfigTree::ConfigTree() :_sections()
{
/*
YamlParser *parser;
try {
parser = new YamlParser("sequence.yml");
}
catch (YamlParserException &e) {
_error("ConfigTree: %s", e.what());
}
try {
parser->serializeEvents();
}
catch(YamlParserException &e) {
_error("ConfigTree: %s", e.what());
}
try {
parser->composeEvents();
}
catch(YamlParserException &e) {
_error("ConfigTree: %s", e.what());
}
try {
delete parser;
parser = NULL;
}
catch (YamlParserException &e) {
_error("ConfigTree: %s", e.what());
}
*/
}
// dtor
ConfigTree::~ConfigTree()
{
// erase every new ItemMap (by CreateSection)
SectionMap::iterator iter = _sections.begin();
......
......@@ -32,18 +32,22 @@
#define __SERIALIZABLE_H__
#include "yamlparser.h"
#include "yamlnode.h"
class Engine;
// class MappingNode;
class Serializable {
public:
Serializable();
~Serializable();
virtual void serialize(Engine *engine) = 0;
virtual void Serialize(Engine *engine) = 0;
virtual void unserialize(Conf::MappingNode *map) = 0;
private:
};
#endif
......@@ -98,7 +98,9 @@ class YamlDocument : YamlNode {
void addNode(YamlNode *node);
YamlNode *popNode();
YamlNode *popNode(void);
Sequence *getSequence(void) { return &doc; }
private:
......
This diff is collapsed.
......@@ -76,6 +76,10 @@ class YamlParser {
YamlDocument *composeEvents();
void constructNativeData();
SequenceNode *getAccountSequence(void) { return accountSequence; };
private:
/**
......@@ -93,6 +97,10 @@ class YamlParser {
void processMapping(YamlNode *topNode);
void mainNativeDataMapping(MappingNode *map);
// void buildAccounts(SequenceNode *map);
std::string filename;
FILE *fd;
......@@ -121,6 +129,8 @@ class YamlParser {
int eventIndex;
SequenceNode *accountSequence;
};
}
......
......@@ -47,6 +47,16 @@ IAXAccount::~IAXAccount()
_link = NULL;
}
void IAXAccount::serialize(Engine *engine)
{
}
void IAXAccount::unserialize(Conf::MappingNode *map)
{
}
void IAXAccount::setVoIPLink()
{
......
......@@ -44,6 +44,10 @@ class IAXAccount : public Account
~IAXAccount();
virtual void serialize(Engine *engine);
virtual void unserialize(Conf::MappingNode *map);
void setVoIPLink ();
/**
......
......@@ -3964,6 +3964,9 @@ short ManagerImpl::loadAccountMap () {
_debug ("Loading account map");
buildAccounts();
short nbAccount = 0;
TokenList sections = _config.getSections();
std::string accountType;
......@@ -4043,6 +4046,69 @@ short ManagerImpl::loadAccountMap () {
return nbAccount;
}
void ManagerImpl::buildAccounts() {
Conf::YamlParser *parser;
Account *tmpAccount = 0;
try {
parser = new Conf::YamlParser("sequence2.yml");
parser->serializeEvents();
parser->composeEvents();
parser->constructNativeData();
}
catch (Conf::YamlParserException &e) {
_error("ConfigTree: %s", e.what());
}
Conf::SequenceNode *seq = parser->getAccountSequence();
// Each element in sequence is a new account to create
Conf::Sequence::iterator iterSeq = seq->getSequence()->begin();
Conf::MappingNode *map;
Conf::Key accTypeKey("type");
Conf::Key accID("id");
while(iterSeq != seq->getSequence()->end()) {
map = (Conf::MappingNode *)(*iterSeq);
Conf::ScalarNode * val = (Conf::ScalarNode *)(map->getValue(accTypeKey));
Conf::Value accountType = val->getValue();
val = (Conf::ScalarNode *)(map->getValue(accID));
Conf::Value accountid = val->getValue();
if (accountType == "sip") {
tmpAccount = AccountCreator::createAccount(AccountCreator::SIP_ACCOUNT, accountid);
_debug("Account is SIP!!!");
}
else if (accountType == "iax") {
tmpAccount = AccountCreator::createAccount(AccountCreator::IAX_ACCOUNT, accountid);
}
tmpAccount->unserialize(map);
iterSeq++;
}
try {
delete parser;
}
catch (Conf::YamlParserException &e) {
_error("AccountCreator: %s", e.what());
}
parser = NULL;
}
void ManagerImpl::unloadAccountMap () {
AccountMap::iterator iter = _accountMap.begin();
......
......@@ -55,6 +55,7 @@
#include "audio/codecs/codecDescriptor.h" // CodecDescriptor class contained by value here
#include "audio/mainbuffer.h"
#include "yamlparser.h"
class AudioLayer;
class GuiFramework;
......@@ -111,6 +112,9 @@ class ManagerImpl {
ManagerImpl (void);
~ManagerImpl (void);
void buildAccounts();
/**
* Initialisation of thread (sound) and map.
* Init a new VoIPLink, audio codec and audio driver
......
......@@ -58,7 +58,7 @@ ManagerImpl::registerAccounts()
bool flag = true;
AccountMap::iterator iter;
_debugInit ("Initiate VoIP Links Registration");
_debugInit ("Manager: Initiate VoIP Links Registration");
iter = _accountMap.begin();
/* Loop on the account map previously loaded */
......@@ -98,7 +98,7 @@ ManagerImpl::initRegisterAccounts()
bool flag = true;
AccountMap::iterator iter;
_debugInit ("Initiate VoIP Links Registration");
_debugInit ("Manager: Initiate VoIP Links Registration");
iter = _accountMap.begin();
/* Loop on the account map previously loaded */
......
......@@ -35,6 +35,7 @@
#include "user_cfg.h"
#include <pwd.h>
SIPAccount::SIPAccount (const AccountID& accountID)
: Account (accountID, "sip")
, _routeSet("")
......@@ -56,6 +57,7 @@ SIPAccount::SIPAccount (const AccountID& accountID)
, _tlsSetting (NULL)
, _dtmfType(OVERRTP)
, _displayName ("")
{
// IP2IP settings must be loaded before singleton instanciation, cannot call it here...
......@@ -78,6 +80,112 @@ SIPAccount::~SIPAccount()
free (_tlsSetting);
}
void SIPAccount::serialize(Engine *engine) {
}
void SIPAccount::unserialize(Conf::MappingNode *map)
{
Conf::ScalarNode *val;
Conf::MappingNode *srtpMap;
Conf::MappingNode *tlsMap;
Conf::MappingNode *zrtpMap;
val = (Conf::ScalarNode *)(map->getValue(aliasKey));
_alias = val->getValue();
val = (Conf::ScalarNode *)(map->getValue(typeKey));
_type = val->getValue();
val = (Conf::ScalarNode *)(map->getValue(idKey));
_accountID = val->getValue();
val = (Conf::ScalarNode *)(map->getValue(usernameKey));
_username = val->getValue();
val = (Conf::ScalarNode *)(map->getValue(passwordKey));
_password = val->getValue();
val = (Conf::ScalarNode *)(map->getValue(hostnameKey));
_hostname = val->getValue();
val = (Conf::ScalarNode *)(map->getValue(accountEnableKey));
_enabled = val->getValue().compare("true") ? true : false;
// val = (Conf::ScalarNode *)(map->getValue(mailboxKey));
val = (Conf::ScalarNode *)(map->getValue(codecsKey));
// _codecOrder = val->getValue();
val = (Conf::ScalarNode *)(map->getValue(expireKey));
_registrationExpire = val->getValue();
val = (Conf::ScalarNode *)(map->getValue(interfaceKey));
_interface = val->getValue();
val = (Conf::ScalarNode *)(map->getValue(portKey));
_localPort = atoi(val->getValue().data());
// val = (Conf::ScalarNode *)(map->getValue(mailboxKey));
val = (Conf::ScalarNode *)(map->getValue(publishAddrKey));
_publishedIpAddress = val->getValue();
val = (Conf::ScalarNode *)(map->getValue(publishPortKey));
_publishedPort = atoi(val->getValue().data());
val = (Conf::ScalarNode *)(map->getValue(sameasLocalKey));
_publishedSameasLocal = val->getValue().compare("true") ? true : false;
val = (Conf::ScalarNode *)(map->getValue(resolveOnceKey));
_resolveOnce = val->getValue().compare("true") ? true : false;
val = (Conf::ScalarNode *)(map->getValue(dtmfTypeKey));
// _dtmfType = atoi(val->getValue();
// stun enabled
// get srtp submap
srtpMap = (Conf::MappingNode *)(map->getValue(srtpKey));
val = (Conf::ScalarNode *)(srtpMap->getValue(srtpEnableKey));
_srtpEnabled = val->getValue().compare("true") ? true : false;
val = (Conf::ScalarNode *)(srtpMap->getValue(keyExchangeKey));
_srtpKeyExchange = val->getValue();
val = (Conf::ScalarNode *)(srtpMap->getValue(rtpFallbackKey));
_srtpFallback = val->getValue().compare("true") ? true : false;
// get zrtp submap
zrtpMap = (Conf::MappingNode *)(map->getValue(zrtpKey));
val = (Conf::ScalarNode *)(zrtpMap->getValue(displaySasKey));
_zrtpDisplaySas = val->getValue().compare("true") ? true : false;
val = (Conf::ScalarNode *)(zrtpMap->getValue(displaySasOnceKey));
_zrtpDisplaySasOnce = val->getValue().compare("true") ? true : false;
val = (Conf::ScalarNode *)(zrtpMap->getValue(helloHashEnabledKey));
_zrtpHelloHash = val->getValue().compare("true") ? true : false;
val = (Conf::ScalarNode *)(zrtpMap->getValue(notSuppWarningKey));
_zrtpNotSuppWarning = val->getValue().compare("true") ? true : false;
// get tls submap
tlsMap = (Conf::MappingNode *)(map->getValue(tlsKey));
val = (Conf::ScalarNode *)(tlsMap->getValue(tlsEnableKey));
_tlsEnable = val->getValue();
val = (Conf::ScalarNode *)(tlsMap->getValue(tlsPortKey));
_tlsPortStr = val->getValue();
val = (Conf::ScalarNode *)(tlsMap->getValue(certificateKey));
_tlsCertificateFile = val->getValue();
val = (Conf::ScalarNode *)(tlsMap->getValue(calistKey));
_tlsCaListFile = val->getValue();
val = (Conf::ScalarNode *)(tlsMap->getValue(ciphersKey));
_tlsCiphers = val->getValue();
val = (Conf::ScalarNode *)(tlsMap->getValue(methodKey));
_tlsMethod = val->getValue();
val = (Conf::ScalarNode *)(tlsMap->getValue(timeoutKey));
_tlsNegotiationTimeoutSec = val->getValue();
_tlsNegotiationTimeoutMsec = val->getValue();
val = (Conf::ScalarNode *)(tlsMap->getValue(tlsPasswordKey));
_tlsPassword = val->getValue();
val = (Conf::ScalarNode *)(tlsMap->getValue(privateKeyKey));
_tlsPrivateKeyFile = val->getValue();
val = (Conf::ScalarNode *)(tlsMap->getValue(requireCertifKey));
_tlsRequireClientCertificate = val->getValue().compare("true") ? true : false;
val = (Conf::ScalarNode *)(tlsMap->getValue(serverKey));
_tlsServerName = val->getValue();
val = (Conf::ScalarNode *)(tlsMap->getValue(verifyClientKey));
_tlsVerifyServer = val->getValue().compare("true") ? true : false;
val = (Conf::ScalarNode *)(tlsMap->getValue(verifyServerKey));
_tlsVerifyClient = val->getValue().compare("true") ? true : false;
}
// void SIPAccount::setVoIPLink(VoIPLink *link) {
void SIPAccount::setVoIPLink() {
......@@ -184,10 +292,10 @@ int SIPAccount::initCredential (void)
int SIPAccount::registerVoIPLink()
{
_debug ("Register account %s", getAccountID().c_str());
_debug ("Account: Register account %s", getAccountID().c_str());
// Init general settings
loadConfig();
// loadConfig();
if (_hostname.length() >= PJ_MAX_HOSTNAME) {
return !SUCCESS;
......
......@@ -41,12 +41,53 @@
#include "sipvoiplink.h"
#include "pjsip/sip_transport_tls.h"
#include "pjsip/sip_types.h"
#include "config/serializable.h"
enum DtmfType { OVERRTP, SIPINFO};
#define OVERRTPSTR "overrtp"
#define SIPINFOSTR "sipinfo"
// SIP specific configuration keys
const Conf::Key expireKey("expire");
const Conf::Key interfaceKey("interface");
const Conf::Key portKey("port");
const Conf::Key publishAddrKey("publishAddr");
const Conf::Key publishPortKey("publishPort");
const Conf::Key sameasLocalKey("sameasLocal");
const Conf::Key resolveOnceKey("resolveOnce");
const Conf::Key dtmfTypeKey("dtmfType");
// TODO: write an object to store credential which implement serializable
const Conf::Key srtpKey("srtp");
const Conf::Key srtpEnableKey("enable");
const Conf::Key keyExchangeKey("keyExchange");
const Conf::Key rtpFallbackKey("rtpFallback");
// TODO: wirte an object to store zrtp params wich implement serializable
const Conf::Key zrtpKey("zrtp");
const Conf::Key displaySasKey("displaySas");
const Conf::Key displaySasOnceKey("displaySasOnce");
const Conf::Key helloHashEnabledKey("helloHashEnabled");
const Conf::Key notSuppWarningKey("notSuppWarning");
// TODO: write an object to store tls params which implement serializable
const Conf::Key tlsKey("tls");
const Conf::Key tlsPortKey("tlsPort");
const Conf::Key certificateKey("certificate");
const Conf::Key calistKey("calist");
const Conf::Key ciphersKey("ciphers");
const Conf::Key tlsEnableKey("enable");
const Conf::Key methodKey("method");
const Conf::Key timeoutKey("timeout");
const Conf::Key tlsPasswordKey("password");
const Conf::Key privateKeyKey("privateKey");
const Conf::Key requireCertifKey("requireCertif");
const Conf::Key serverKey("server");
const Conf::Key verifyClientKey("verifyClient");
const Conf::Key verifyServerKey("verifyServer");
class SIPVoIPLink;
/**
......@@ -74,6 +115,10 @@ class SIPAccount : public Account
*/
virtual ~SIPAccount();
virtual void serialize(Engine *engine);
virtual void unserialize(Conf::MappingNode *map);
/**
* Set route header to appears in sip messages for this account
*/
......@@ -429,7 +474,48 @@ class SIPAccount : public Account
DtmfType _dtmfType;
// Display Name that can be used in SIP URI.
std::string _displayName;
std::string _displayName;
std::string _tlsEnable;
std::string _tlsPortStr;// = Manager::instance().getConfigString(_accountID, TLS_LISTENER_PORT);
std::string _tlsCaListFile;// = Manager::instance().getConfigString (_accountID, TLS_CA_LIST_FILE);
std::string _tlsCertificateFile;// = Manager::instance().getConfigString (_accountID, TLS_CERTIFICATE_FILE);
std::string _tlsPrivateKeyFile;// = Manager::instance().getConfigString (_accountID, TLS_PRIVATE_KEY_FILE);
std::string _tlsPassword;// = Manager::instance().getConfigString (_accountID, TLS_PASSWORD);
std::string _tlsMethod;// = Manager::instance().getConfigString (_accountID, TLS_METHOD);
std::string _tlsCiphers;// = Manager::instance().getConfigString (_accountID, TLS_CIPHERS);
std::string _tlsServerName;// = Manager::instance().getConfigString (_accountID, TLS_SERVER_NAME);
bool _tlsVerifyServer;// = Manager::instance().getConfigBool (_accountID, TLS_VERIFY_SERVER);
bool _tlsVerifyClient;// = Manager::instance().getConfigBool (_accountID, TLS_VERIFY_CLIENT);
bool _tlsRequireClientCertificate;// = Manager::instance().getConfigBool (_accountID, TLS_REQUIRE_CLIENT_CERTIFICATE);
std::string _tlsNegotiationTimeoutSec;// = Manager::instance().getConfigString (_accountID, TLS_NEGOTIATION_TIMEOUT_SEC);
std::string _tlsNegotiationTimeoutMsec;// = Manager::instance().getConfigString (_accountID, TLS_NEGOTIATION_TIMEOUT_MSEC);
std::string _stunServer; // = Manager::instance().getConfigString (_accountID, STUN_SERVER);
bool _tlsEnabled; // = Manager::instance().getConfigBool (_accountID, TLS_ENABLE);
bool _stunEnabled; // = Manager::instance().getConfigBool (_accountID, STUN_ENABLE);
std::string _routeset;
// std::string _realm;
std::string _authenticationUsename;
// std::string _tlsListenerPort;
// std::string _routeSet;
// std::string _dtmfType;
bool _srtpEnabled;
std::string _srtpKeyExchange;
bool _srtpFallback;
bool _zrtpDisplaySas;
bool _zrtpDisplaySasOnce;
bool _zrtpHelloHash;
bool _zrtpNotSuppWarning;
};
#endif
......@@ -163,6 +163,8 @@ void ConfigurationTest::testYamlParser()
parser->serializeEvents();
parser->composeEvents();
parser->constructNativeData();
delete parser;
parser = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment