diff --git a/sflphone-common/src/config/yamlemitter.cpp b/sflphone-common/src/config/yamlemitter.cpp index 7cd1eacba182d2c8d60746b1b01f301a03127f55..4aae4eda3664fe81efcb723451a715becc4132f3 100755 --- a/sflphone-common/src/config/yamlemitter.cpp +++ b/sflphone-common/src/config/yamlemitter.cpp @@ -62,7 +62,8 @@ void YamlEmitter::open() yaml_document_initialize(&document, NULL, NULL, NULL, 0, 0); // Init the main configuration mapping - topLevelMapping = yaml_document_add_mapping (&document, NULL, YAML_BLOCK_MAPPING_STYLE); + if((topLevelMapping = yaml_document_add_mapping (&document, NULL, YAML_BLOCK_MAPPING_STYLE)) == 0) + throw YamlEmitterException("Could not create top level mapping"); } void YamlEmitter::close() @@ -94,21 +95,37 @@ void YamlEmitter::serializeData() } -void YamlEmitter::writeAccount(MappingNode *map) +void YamlEmitter::serializeAccount(MappingNode *map) { std::string accountstr("accounts"); + int accountid, accountmapping; + + _debug("YamlEmitter: Serialize account"); + + if(map->getType() != MAPPING) + throw YamlEmitterException("Node type is not a mapping while writing account"); + if(isFirstAccount) { // accountSequence need to be static outside this scope since reused each time an account is written - accountSequence = yaml_document_add_sequence (&document, NULL, YAML_BLOCK_SEQUENCE_STYLE); - int accountid = yaml_document_add_scalar(&document, NULL, (yaml_char_t *)accountstr.c_str(), -1, YAML_PLAIN_SCALAR_STYLE); - yaml_document_append_mapping_pair (&document, topLevelMapping, accountid, accountSequence); + if((accountid = yaml_document_add_scalar(&document, NULL, (yaml_char_t *)accountstr.c_str(), -1, YAML_PLAIN_SCALAR_STYLE)) == 0) + throw YamlEmitterException("Could not add preference scalar to document"); + + if((accountSequence = yaml_document_add_sequence (&document, NULL, YAML_BLOCK_SEQUENCE_STYLE)) == 0) + throw YamlEmitterException("Could not add sequence to document"); + + if(!yaml_document_append_mapping_pair (&document, topLevelMapping, accountid, accountSequence)) + throw YamlEmitterException("Could not add mapping pair to top level mapping"); + isFirstAccount = false; } - int accountmapping = yaml_document_add_mapping (&document, NULL, YAML_BLOCK_MAPPING_STYLE); - yaml_document_append_sequence_item (&document, accountSequence, accountmapping); + if((accountmapping = yaml_document_add_mapping (&document, NULL, YAML_BLOCK_MAPPING_STYLE)) == 0) + throw YamlEmitterException("Could not add account mapping to document"); + + if(!yaml_document_append_sequence_item (&document, accountSequence, accountmapping)) + throw YamlEmitterException("Could not append account mapping to sequence"); Mapping *internalmap = map->getMapping(); Mapping::iterator iter = internalmap->begin(); @@ -120,17 +137,25 @@ void YamlEmitter::writeAccount(MappingNode *map) } -void YamlEmitter::writePreference(MappingNode *map) +void YamlEmitter::serializePreference(MappingNode *map) { std::string preferencestr("preferences"); - if(map->getType() == MAPPING) + int preferenceid, preferencemapping; + + _debug("YamlEmitter: Serialize preference"); + + if(map->getType() != MAPPING) throw YamlEmitterException("Node type is not a mapping while writing preferences"); - int preferenceid = yaml_document_add_scalar(&document, NULL, (yaml_char_t *)preferencestr.c_str(), -1, YAML_PLAIN_SCALAR_STYLE); - int preferencemapping = yaml_document_add_mapping (&document, NULL, YAML_BLOCK_MAPPING_STYLE); + if((preferenceid = yaml_document_add_scalar(&document, NULL, (yaml_char_t *)preferencestr.c_str(), -1, YAML_PLAIN_SCALAR_STYLE)) == 0) + throw YamlEmitterException("Could not add scalar to document"); - yaml_document_append_mapping_pair (&document, topLevelMapping, preferenceid, preferencemapping); + if((preferencemapping = yaml_document_add_mapping (&document, NULL, YAML_BLOCK_MAPPING_STYLE)) == 0) + throw YamlEmitterException("Could not add mapping to document"); + + if(!yaml_document_append_mapping_pair (&document, topLevelMapping, preferenceid, preferencemapping)) + throw YamlEmitterException("Could not add mapping pair to top leve mapping"); Mapping *internalmap = map->getMapping(); Mapping::iterator iter = internalmap->begin(); @@ -148,18 +173,32 @@ void YamlEmitter::addMappingItem(int mappingid, Key key, YamlNode *node) if(node->getType() == SCALAR) { + int temp1, temp2; + ScalarNode *sclr = (ScalarNode *)node; - int temp1 = yaml_document_add_scalar(&document, NULL, (yaml_char_t *)key.c_str(), -1, YAML_PLAIN_SCALAR_STYLE); - int temp2 = yaml_document_add_scalar(&document, NULL, (yaml_char_t *)sclr->getValue().c_str(), -1, YAML_PLAIN_SCALAR_STYLE); - yaml_document_append_mapping_pair (&document, mappingid, temp1, temp2); + if((temp1 = yaml_document_add_scalar(&document, NULL, (yaml_char_t *)key.c_str(), -1, YAML_PLAIN_SCALAR_STYLE)) == 0) + throw YamlEmitterException("Could not add scalar to document"); + + if((temp2 = yaml_document_add_scalar(&document, NULL, (yaml_char_t *)sclr->getValue().c_str(), -1, YAML_PLAIN_SCALAR_STYLE)) == 0) + throw YamlEmitterException("Could not add scalar to document"); + + if(!yaml_document_append_mapping_pair (&document, mappingid, temp1, temp2)) + throw YamlEmitterException("Could not append mapping pair to mapping"); } else if(node->getType() == MAPPING){ - int temp1 = yaml_document_add_scalar(&document, NULL, (yaml_char_t *)key.c_str(), -1, YAML_PLAIN_SCALAR_STYLE); - int temp2 = yaml_document_add_mapping (&document, NULL, YAML_BLOCK_MAPPING_STYLE); - yaml_document_append_mapping_pair (&document, mappingid, temp1, temp2); + int temp1, temp2; + + if((temp1 = yaml_document_add_scalar(&document, NULL, (yaml_char_t *)key.c_str(), -1, YAML_PLAIN_SCALAR_STYLE)) == 0) + throw YamlEmitterException("Could not add scalar to document"); + + if((temp2 = yaml_document_add_mapping (&document, NULL, YAML_BLOCK_MAPPING_STYLE)) == 0) + throw YamlEmitterException("Could not add scalar to document"); + + if(!yaml_document_append_mapping_pair (&document, mappingid, temp1, temp2)) + throw YamlEmitterException("Could not add mapping pair to mapping"); MappingNode *map = (MappingNode *)node; Mapping *internalmap = map->getMapping(); diff --git a/sflphone-common/src/config/yamlemitter.h b/sflphone-common/src/config/yamlemitter.h index 47bce14a5fb0b4cd04c68c51ec9166a7725e5d72..62cb3745d2a6c5e525877e17eb1b9475c98a0f74 100755 --- a/sflphone-common/src/config/yamlemitter.h +++ b/sflphone-common/src/config/yamlemitter.h @@ -75,9 +75,9 @@ class YamlEmitter { void write(); - void writeAccount(MappingNode *map); + void serializeAccount(MappingNode *map); - void writePreference(MappingNode *map); + void serializePreference(MappingNode *map); void writeAddressbook(); diff --git a/sflphone-common/src/config/yamlparser.cpp b/sflphone-common/src/config/yamlparser.cpp old mode 100755 new mode 100644 diff --git a/sflphone-common/src/config/yamlparser.h b/sflphone-common/src/config/yamlparser.h old mode 100755 new mode 100644 diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp old mode 100755 new mode 100644 index bc208691dafb2f8022707144cc805fca286e63a0..959716c5a1796ce14d1340afbdd1a770f623a57d --- a/sflphone-common/src/managerimpl.cpp +++ b/sflphone-common/src/managerimpl.cpp @@ -1413,15 +1413,12 @@ bool ManagerImpl::saveConfig (void) { setConfig(AUDIO, VOLUME_SPKR, getSpkrVolume()); setConfig(AUDIO, VOLUME_MICRO, getMicVolume()); + AccountMap::iterator iter = _accountMap.begin(); try{ emitter = new Conf::YamlEmitter("/tmp/sequenceEmiter.txt"); - // emitter->writeAccount(&accountmap); - // emitter->writeAccount(&accountmap); - emitter->serializeData(); - while(iter != _accountMap.end()) { iter->second->serialize(emitter); iter++; @@ -1429,6 +1426,8 @@ bool ManagerImpl::saveConfig (void) { preferences.serialize(emitter); + emitter->serializeData(); + delete emitter; } catch (Conf::YamlEmitterException &e) { diff --git a/sflphone-common/src/preferences.cpp b/sflphone-common/src/preferences.cpp index f3de3357fdf2a2859e46d3f7a6c2a149bda09e9d..d0190ae96c01f210fcf7dd3c0fec745d33ffb9a1 100644 --- a/sflphone-common/src/preferences.cpp +++ b/sflphone-common/src/preferences.cpp @@ -86,7 +86,7 @@ void Preferences::serialize(Conf::YamlEmitter *emiter) preferencemap.setKeyValue(zeroConfenableKey, &zeroConfenable); preferencemap.setKeyValue(md5HashKey, &md5Hash); - + emiter->serializePreference(&preferencemap); } void Preferences::unserialize(Conf::MappingNode *map) diff --git a/sflphone-common/src/sip/sipaccount.cpp b/sflphone-common/src/sip/sipaccount.cpp old mode 100755 new mode 100644 index 49667c510586e363a229330bb84dcd9176e71d09..ff3a5e6ea6fe947c9e6333dbd365fcedf109a3da --- a/sflphone-common/src/sip/sipaccount.cpp +++ b/sflphone-common/src/sip/sipaccount.cpp @@ -240,6 +240,12 @@ void SIPAccount::serialize(Conf::YamlEmitter *emitter) { tlsmap.setKeyValue(verifyClientKey, &verifyclient); tlsmap.setKeyValue(verifyServerKey, &verifyserver); + try{ + emitter->serializeAccount(&accountmap); + } + catch (Conf::YamlEmitterException &e) { + _error("ConfigTree: %s", e.what()); + } }