Commit 45e3e58d authored by Alexandre Savard's avatar Alexandre Savard

#10795: fix sipaccount deserialisation broken

parent fdd135d5
...@@ -93,8 +93,7 @@ typedef std::map<std::string, YamlNode*> Mapping; ...@@ -93,8 +93,7 @@ typedef std::map<std::string, YamlNode*> Mapping;
void MappingNode::setKeyValue(const std::string &key, YamlNode *value) void MappingNode::setKeyValue(const std::string &key, YamlNode *value)
{ {
Mapping::iterator it = map_.end(); map_[key] = value;
map_.insert(it, std::pair<std::string, YamlNode *>(key, value));
} }
void MappingNode::removeKeyValue(const std::string &key) void MappingNode::removeKeyValue(const std::string &key)
...@@ -107,6 +106,8 @@ YamlNode *MappingNode::getValue(const std::string &key) const ...@@ -107,6 +106,8 @@ YamlNode *MappingNode::getValue(const std::string &key) const
{ {
Mapping::const_iterator it = map_.find(key); Mapping::const_iterator it = map_.find(key);
if (it != map_.end()) if (it != map_.end())
return it->second; return it->second;
else else
...@@ -125,19 +126,23 @@ void MappingNode::getValue(const std::string &key, bool *b) const ...@@ -125,19 +126,23 @@ void MappingNode::getValue(const std::string &key, bool *b) const
void MappingNode::getValue(const std::string &key, int *i) const void MappingNode::getValue(const std::string &key, int *i) const
{ {
ScalarNode *node = static_cast<ScalarNode*>(getValue(key)); ScalarNode *node = dynamic_cast<ScalarNode*>(getValue(key));
if (!node) if (!node) {
ERROR("node %s not found", key.c_str());
return; return;
}
*i = std::atoi(node->getValue().c_str()); *i = std::atoi(node->getValue().c_str());
} }
void MappingNode::getValue(const std::string &key, std::string *v) const void MappingNode::getValue(const std::string &key, std::string *v) const
{ {
ScalarNode *node = static_cast<ScalarNode*>(getValue(key)); ScalarNode *node = dynamic_cast<ScalarNode*>(getValue(key));
if (!node) if (!node) {
ERROR("node %s not found", key.c_str());
return; return;
}
*v = node->getValue(); *v = node->getValue();
} }
...@@ -146,7 +151,7 @@ void MappingNode::getValue(const std::string &key, std::string *v) const ...@@ -146,7 +151,7 @@ void MappingNode::getValue(const std::string &key, std::string *v) const
void MappingNode::deleteChildNodes() void MappingNode::deleteChildNodes()
{ {
for (Mapping::iterator it = map_.begin(); it != map_.end(); ++it) { for (Mapping::iterator it = map_.begin(); it != map_.end(); ++it) {
YamlNode *yamlNode = static_cast<YamlNode *>(it->second); YamlNode *yamlNode = dynamic_cast<YamlNode *>(it->second);
if (!yamlNode) if (!yamlNode)
continue; continue;
...@@ -155,21 +160,21 @@ void MappingNode::deleteChildNodes() ...@@ -155,21 +160,21 @@ void MappingNode::deleteChildNodes()
case DOCUMENT: case DOCUMENT:
break; break;
case SEQUENCE: { case SEQUENCE: {
SequenceNode *sequence = static_cast<SequenceNode *>(yamlNode); SequenceNode *sequence = dynamic_cast<SequenceNode *>(yamlNode);
sequence->deleteChildNodes(); sequence->deleteChildNodes();
delete sequence; delete sequence;
sequence = NULL; sequence = NULL;
} }
break; break;
case MAPPING: { case MAPPING: {
MappingNode *mapping = static_cast<MappingNode *>(yamlNode); MappingNode *mapping = dynamic_cast<MappingNode *>(yamlNode);
mapping->deleteChildNodes(); mapping->deleteChildNodes();
delete mapping; delete mapping;
mapping = NULL; mapping = NULL;
} }
break; break;
case SCALAR: { case SCALAR: {
ScalarNode *scalar = static_cast<ScalarNode *>(yamlNode); ScalarNode *scalar = dynamic_cast<ScalarNode *>(yamlNode);
delete scalar; delete scalar;
scalar = NULL; scalar = NULL;
} }
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "../global.h" #include "../global.h"
#include "sfl_config.h" #include "sfl_config.h"
#include "yamlnode.h" #include "yamlnode.h"
#include "logger.h"
#include <cstdio> #include <cstdio>
namespace Conf { namespace Conf {
...@@ -258,6 +259,7 @@ void YamlParser::processScalar(YamlNode *topNode) ...@@ -258,6 +259,7 @@ void YamlParser::processScalar(YamlNode *topNode)
break; break;
case MAPPING: case MAPPING:
((MappingNode *)(topNode))->addNode(sclr); ((MappingNode *)(topNode))->addNode(sclr);
break;
case SCALAR: case SCALAR:
default: default:
break; break;
......
...@@ -2611,8 +2611,9 @@ void ManagerImpl::loadAccountMap(Conf::YamlParser &parser) ...@@ -2611,8 +2611,9 @@ void ManagerImpl::loadAccountMap(Conf::YamlParser &parser)
Sequence::const_iterator ip2ip = std::find_if(seq->begin(), seq->end(), isIP2IP); Sequence::const_iterator ip2ip = std::find_if(seq->begin(), seq->end(), isIP2IP);
if (ip2ip != seq->end()) { if (ip2ip != seq->end()) {
MappingNode *node = dynamic_cast<MappingNode*>(*ip2ip); MappingNode *node = dynamic_cast<MappingNode*>(*ip2ip);
if (node) if (node) {
accountMap_[SIPAccount::IP2IP_PROFILE]->unserialize(node); accountMap_[SIPAccount::IP2IP_PROFILE]->unserialize(*node);
}
} }
// Initialize default UDP transport according to // Initialize default UDP transport according to
......
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