diff --git a/sflphone-common/src/account.h b/sflphone-common/src/account.h index 80bfbd36ba1838b9e0c2d6dc482b3185f3e44219..cec37565b1ed1da1a7d65f1cec4e4e867636d6a8 100644 --- a/sflphone-common/src/account.h +++ b/sflphone-common/src/account.h @@ -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. */ diff --git a/sflphone-common/src/config/config.cpp b/sflphone-common/src/config/config.cpp index 0c937b6f94693eac2c963f5ebf674a921ee149c2..9f735964de9e45de8aa005817d8b7b714f6d13ac 100755 --- a/sflphone-common/src/config/config.cpp +++ b/sflphone-common/src/config/config.cpp @@ -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(); diff --git a/sflphone-common/src/config/serializable.h b/sflphone-common/src/config/serializable.h index 781b3a45be4a3c77e0c91a6cbd5c6908c2f8363e..7b7cf657a4661592a19eec5e7e1df348c3b78c96 100755 --- a/sflphone-common/src/config/serializable.h +++ b/sflphone-common/src/config/serializable.h @@ -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 diff --git a/sflphone-common/src/config/yamlnode.h b/sflphone-common/src/config/yamlnode.h index 4b8ae443acf5c4854a4bf428d1bcae17d717770b..e341b355038910426e5a47d1c9569582178d3563 100755 --- a/sflphone-common/src/config/yamlnode.h +++ b/sflphone-common/src/config/yamlnode.h @@ -98,7 +98,9 @@ class YamlDocument : YamlNode { void addNode(YamlNode *node); - YamlNode *popNode(); + YamlNode *popNode(void); + + Sequence *getSequence(void) { return &doc; } private: diff --git a/sflphone-common/src/config/yamlparser.cpp b/sflphone-common/src/config/yamlparser.cpp index ba0f0d24bcc14409ea94b45935884be85dc5cd01..d68c1febcf356effecc17bad2598adbb05f905af 100755 --- a/sflphone-common/src/config/yamlparser.cpp +++ b/sflphone-common/src/config/yamlparser.cpp @@ -103,18 +103,18 @@ int YamlParser::copyEvent(yaml_event_t *event_to, yaml_event_t *event_from) switch (event_from->type) { case YAML_STREAM_START_EVENT: { - // _debug("YAML_STREAM_START_EVENT"); + _debug("YAML_STREAM_START_EVENT"); return yaml_stream_start_event_initialize(event_to, event_from->data.stream_start.encoding); } case YAML_STREAM_END_EVENT: { - // _debug("YAML_STREAM_END_EVENT"); + _debug("YAML_STREAM_END_EVENT"); return yaml_stream_end_event_initialize(event_to); } case YAML_DOCUMENT_START_EVENT: { - // _debug("YAML_DOCUMENT_START_EVENT"); + _debug("YAML_DOCUMENT_START_EVENT"); return yaml_document_start_event_initialize(event_to, event_from->data.document_start.version_directive, event_from->data.document_start.tag_directives.start, @@ -123,17 +123,17 @@ int YamlParser::copyEvent(yaml_event_t *event_to, yaml_event_t *event_from) } case YAML_DOCUMENT_END_EVENT: { - // _debug("YAML_DOCUMENT_END_EVENT"); + _debug("YAML_DOCUMENT_END_EVENT"); return yaml_document_end_event_initialize(event_to, event_from->data.document_end.implicit); } case YAML_ALIAS_EVENT:{ - // _debug("YAML_ALIAS_EVENT"); + _debug("YAML_ALIAS_EVENT"); return yaml_alias_event_initialize(event_to, event_from->data.alias.anchor); } case YAML_SCALAR_EVENT: { - // _debug("YAML_SCALAR_EVENT"); + _debug("YAML_SCALAR_EVENT"); return yaml_scalar_event_initialize(event_to, event_from->data.scalar.anchor, event_from->data.scalar.tag, @@ -144,7 +144,7 @@ int YamlParser::copyEvent(yaml_event_t *event_to, yaml_event_t *event_from) event_from->data.scalar.style); } case YAML_SEQUENCE_START_EVENT: { - // _debug("YAML_SEQUENCE_START_EVENT"); + _debug("YAML_SEQUENCE_START_EVENT"); return yaml_sequence_start_event_initialize(event_to, event_from->data.sequence_start.anchor, event_from->data.sequence_start.tag, @@ -152,11 +152,11 @@ int YamlParser::copyEvent(yaml_event_t *event_to, yaml_event_t *event_from) event_from->data.sequence_start.style); } case YAML_SEQUENCE_END_EVENT: { - // _debug("YAML_SEQUENCE_END_EVENT"); + _debug("YAML_SEQUENCE_END_EVENT"); return yaml_sequence_end_event_initialize(event_to); } case YAML_MAPPING_START_EVENT: { - // _debug("YAML_MAPPING_START_EVENT"); + _debug("YAML_MAPPING_START_EVENT"); return yaml_mapping_start_event_initialize(event_to, event_from->data.mapping_start.anchor, event_from->data.mapping_start.tag, @@ -164,7 +164,7 @@ int YamlParser::copyEvent(yaml_event_t *event_to, yaml_event_t *event_from) event_from->data.mapping_start.style); } case YAML_MAPPING_END_EVENT: { - // _debug("YAML_MAPPING_END_EVENT"); + _debug("YAML_MAPPING_END_EVENT"); return yaml_mapping_end_event_initialize(event_to); } @@ -179,6 +179,8 @@ int YamlParser::copyEvent(yaml_event_t *event_to, yaml_event_t *event_from) YamlDocument *YamlParser::composeEvents() { + _debug("Compose Events"); + if(eventNumber == 0) throw YamlParserException("No event available"); @@ -189,89 +191,13 @@ YamlDocument *YamlParser::composeEvents() { processStream(); - /* - for (int i = 0; i < eventNumber;) { - - switch(events[i].type) { - - _debug("YAML_DOCUMENT_END_EVENT"); - // topNode = NULL; - break; - } - case YAML_ALIAS_EVENT: - _debug("YAML_ALIAS_EVENT"); - break; - case YAML_SCALAR_EVENT: { - _debug("YAML_SCALAR_EVENT: anchor %s, tag %s, value %s", events[i].data.scalar.anchor, events[i].data.scalar.tag, events[i].data.scalar.value); - - char buffer[1000]; - snprintf(buffer, 1000, "%s", events[i].data.scalar.value); - composeScalarEvent(topNode, buffer); - - break; - } - case YAML_SEQUENCE_START_EVENT: { - _debug("YAML_SEQUENCE_START_EVENT: anchor %s, tag %s", events[i].data.sequence_start.anchor, events[i].data.sequence_start.tag); - // startSequence(); - break; - } - case YAML_SEQUENCE_END_EVENT: { - _debug("YAML_SEQUENCE_END_EVENT"); - // endSequence(); - break; - } - case YAML_MAPPING_START_EVENT: { - _debug("YAML_MAPPING_START_EVENT: anchor %s, tag %s", events[i].data.mapping_start.anchor, events[i].data.sequence_start.tag); - - Key mapkey; - YamlNode *mapvalue; - - MappingNode *map = new MappingNode(topNode); - - if(events[i+1].type == YAML_SCALAR_EVENT) { - char buffer[1000]; - snprintf(buffer, 1000, "%s", events[i+1].data.scalar.value); - mapkey = Key(buffer); - i++; - } - else - throw YamlParserException("Mapping event not followed by scalar"); - - if(events[i+1].type == YAML_SCALAR_EVENT) { - char buffer[1000]; - snprintf(buffer, 1000, "%s", events[i+1].data.scalar.value); - ScalarNode *sclr = new ScalarNode(buffer, topNode); - mapvalue = (YamlNode *)sclr; - composeMappingEvent(map, mapkey, mapvalue); - } - else if(events[i+1].type == YAML_SEQUENCE_START_EVENT) { - SequenceNode *seq = new SequenceNode(topNode); - mapvalue = (YamlNode *)seq; - composeMappingEvent(map, mapkey, mapvalue); - topNode = (YamlNode *)seq; - } - else - throw YamlParserException("Not acceptable value for mapping"); - - break; - } - case YAML_MAPPING_END_EVENT: { - _debug("YAML_MAPPING_END_EVENT"); - // endMapping(); - break; - } - default: - throw YamlParserException("Unknown Event"); - } - - i++; - } - */ return doc; } void YamlParser::processStream () { + _debug("ProcessStream"); + while((eventIndex < eventNumber) && (events[eventIndex].type != YAML_STREAM_END_EVENT)) { if(events[eventIndex].type == YAML_DOCUMENT_START_EVENT) @@ -287,6 +213,8 @@ void YamlParser::processStream () { void YamlParser::processDocument() { + _debug("ProcessDocument"); + doc = new YamlDocument(); if(!doc) @@ -320,6 +248,8 @@ void YamlParser::processDocument() void YamlParser::processScalar(YamlNode *topNode) { + _debug("ProcessScalar"); + if(!topNode) throw YamlParserException("No container for scalar"); @@ -346,6 +276,8 @@ void YamlParser::processScalar(YamlNode *topNode) void YamlParser::processSequence(YamlNode *topNode) { + _debug("ProcessSequence"); + if(!topNode) throw YamlParserException("No container for sequence"); @@ -365,7 +297,9 @@ void YamlParser::processSequence(YamlNode *topNode) break; } - while((eventIndex < eventNumber) < (events[eventIndex].type != YAML_SEQUENCE_END_EVENT)) { + eventIndex++; + + while((eventIndex < eventNumber) && (events[eventIndex].type != YAML_SEQUENCE_END_EVENT)) { switch(events[eventIndex].type){ case YAML_SCALAR_EVENT: @@ -391,6 +325,8 @@ void YamlParser::processSequence(YamlNode *topNode) void YamlParser::processMapping(YamlNode *topNode) { + _debug("ProcessMapping"); + if(!topNode) throw YamlParserException("No container for mapping"); @@ -410,11 +346,13 @@ void YamlParser::processMapping(YamlNode *topNode) break; } - while((eventIndex < eventNumber) < (events[eventIndex].type != YAML_MAPPING_END_EVENT)) { + eventIndex++; + + while((eventIndex < eventNumber) && (events[eventIndex].type != YAML_MAPPING_END_EVENT)) { if(events[eventIndex].type != YAML_SCALAR_EVENT) throw YamlParserException("Mapping not followed by a key"); - + char buffer[1000]; snprintf(buffer, 1000, "%s", events[eventIndex].data.scalar.value); map->setTmpKey(Key(buffer)); @@ -442,4 +380,134 @@ void YamlParser::processMapping(YamlNode *topNode) throw YamlParserException("Did not found end of mapping"); } +void YamlParser::constructNativeData() { + + Sequence *seq; + + seq = doc->getSequence(); + + Sequence::iterator iter = seq->begin(); + + while(iter != seq->end()) { + + switch((*iter)->getType()){ + case SCALAR: + _debug("construct scalar"); + throw YamlParserException("No scalar allowed at document level, expect a mapping"); + break; + case SEQUENCE: + _debug("construct sequence"); + throw YamlParserException("No sequence allowed at document level, expect a mapping"); + break; + case MAPPING: { + _debug("construct mapping"); + MappingNode *map = (MappingNode *)(*iter); + mainNativeDataMapping(map); + break; + } + default: + throw YamlParserException("Unknown type in configuration file, expect a mapping"); + break; + } + iter++; + + } + +} + + +void YamlParser::mainNativeDataMapping(MappingNode *map) { + + + Mapping::iterator iter = map->getMapping()->begin(); + + Key accounts("accounts"); + Key addressbook("addressbook"); + Key audio("audio"); + Key hooks("hooks"); + Key preferences("preferences"); + Key voiplink("voiplink"); + + while(iter != map->getMapping()->end()) { + + _debug("Iterating: %s", iter->first.c_str()); + if(accounts.compare(iter->first) == 0) { + // buildAccounts((SequenceNode *)(iter->second)); + accountSequence = (SequenceNode *)(iter->second); + } + else if(addressbook.compare(iter->first) == 0) + _debug("ok"); + else if(audio.compare(iter->first) == 0) + _debug("ok"); + else if(hooks.compare(iter->first) == 0) + _debug("ok"); + else if(preferences.compare(iter->first) == 0) + _debug("ok"); + else if(voiplink.compare(iter->first) == 0) + _debug("ok"); + else + throw YamlParserException("Unknow map key in configuration"); + + iter++; + } +} + + /* +void YamlParser::buildAccounts(SequenceNode *seq) { + + // Each element in sequence is a new account to create + Sequence::iterator iterSeq = seq->getSequence()->begin(); + + MappingNode *map; + + Key accTypeKey("type"); + while(iterSeq != seq->getSequence()->end()) { + + map = (MappingNode *)(*iterSeq); + + ScalarNode * val = (ScalarNode *)(map->getValue(accTypeKey)); + Value accountType = val->getValue(); + + iterSeq++; + + if (accountType == "sip") { + // tmpAccount = AccountCreator::createAccount(AccountCreator::SIP_ACCOUNT, *iter); + _debug("Account is SIP!!!"); + } + else if (accountType == "iax") { + // tmpAccount = AccountCreator::createAccount(AccountCreator::IAX_ACCOUNT, *iter); + } + + /* + std::string accountType; + + 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 { + _error ("Unknown %s param in config file (%s)", CONFIG_ACCOUNT_TYPE, accountType.c_str()); + } + + if (tmpAccount != NULL) { + _debug ("Loading account %s ", iter->c_str()); + _accountMap[iter->c_str()] = tmpAccount; + // tmpAccount->setVoIPLink(SIPVoIPLink::instance ("")); + tmpAccount->setVoIPLink(); + nbAccount++; + } + + iter++; + */ +// } + +//} } diff --git a/sflphone-common/src/config/yamlparser.h b/sflphone-common/src/config/yamlparser.h index 701dc46b479f278b0e2278245376e823bcff0efe..fdc13f1c9ac473115dea26e252df0628777393de 100755 --- a/sflphone-common/src/config/yamlparser.h +++ b/sflphone-common/src/config/yamlparser.h @@ -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; + }; } diff --git a/sflphone-common/src/iax/iaxaccount.cpp b/sflphone-common/src/iax/iaxaccount.cpp index 2c277cb0827ee138efb7e835d4362a188ba7d032..b94ca59623863b4ef4a9600e087754bd77d90d6d 100644 --- a/sflphone-common/src/iax/iaxaccount.cpp +++ b/sflphone-common/src/iax/iaxaccount.cpp @@ -47,6 +47,16 @@ IAXAccount::~IAXAccount() _link = NULL; } +void IAXAccount::serialize(Engine *engine) +{ + +} + +void IAXAccount::unserialize(Conf::MappingNode *map) +{ + +} + void IAXAccount::setVoIPLink() { diff --git a/sflphone-common/src/iax/iaxaccount.h b/sflphone-common/src/iax/iaxaccount.h index 929f7af38a8fa391bc154c88fa05f72ce138cbec..f6fb6414e30b42ec09eff029cd493f4cd52fab16 100644 --- a/sflphone-common/src/iax/iaxaccount.h +++ b/sflphone-common/src/iax/iaxaccount.h @@ -44,6 +44,10 @@ class IAXAccount : public Account ~IAXAccount(); + virtual void serialize(Engine *engine); + + virtual void unserialize(Conf::MappingNode *map); + void setVoIPLink (); /** diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp old mode 100644 new mode 100755 index da9bbcf51f4c5b0d39c2541c9d25035863727533..6dc7f3dfae00bb33f04400feaeceba022b10bd88 --- a/sflphone-common/src/managerimpl.cpp +++ b/sflphone-common/src/managerimpl.cpp @@ -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(); diff --git a/sflphone-common/src/managerimpl.h b/sflphone-common/src/managerimpl.h old mode 100644 new mode 100755 index fc457c767d62130242f5665b3b4e573ddd3c8ebe..a5d03170e4a22d8a768efce9f4da953e6a6f4ec6 --- a/sflphone-common/src/managerimpl.h +++ b/sflphone-common/src/managerimpl.h @@ -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 diff --git a/sflphone-common/src/managerimpl_registration.cpp b/sflphone-common/src/managerimpl_registration.cpp index 552b2eb4568b25771a766a8c9950b38a4e03b3e8..e0605aa93620c993c75da0cb190a76900cd50bb7 100644 --- a/sflphone-common/src/managerimpl_registration.cpp +++ b/sflphone-common/src/managerimpl_registration.cpp @@ -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 */ diff --git a/sflphone-common/src/sip/sipaccount.cpp b/sflphone-common/src/sip/sipaccount.cpp index 97318b47928130283ed86f44dcd0dd056f1edbc8..4c5fbb1ffcb8b3a82affc55777327c0af5a72278 100644 --- a/sflphone-common/src/sip/sipaccount.cpp +++ b/sflphone-common/src/sip/sipaccount.cpp @@ -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; diff --git a/sflphone-common/src/sip/sipaccount.h b/sflphone-common/src/sip/sipaccount.h index 51fb6de0c451eaffd5642f2b4824f15384ab14e0..2f923f3a9d2b23611dd2a63f404bccf6134a2fd8 100644 --- a/sflphone-common/src/sip/sipaccount.h +++ b/sflphone-common/src/sip/sipaccount.h @@ -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 diff --git a/sflphone-common/test/configurationtest.cpp b/sflphone-common/test/configurationtest.cpp index 03ab6c2de35d9e26184fc08a8454f2c1a0a60771..1c5805af03470140feab3ebe1076d7b4379a7149 100755 --- a/sflphone-common/test/configurationtest.cpp +++ b/sflphone-common/test/configurationtest.cpp @@ -163,6 +163,8 @@ void ConfigurationTest::testYamlParser() parser->serializeEvents(); parser->composeEvents(); + + parser->constructNativeData(); delete parser; parser = NULL;