diff --git a/sflphone-common/src/config/yamlemitter.cpp b/sflphone-common/src/config/yamlemitter.cpp index 1e0f1b481f5a1909ab8d53086d02bf0c24e88653..89ddaa79a880e614c010d0a28e1cf82971219c4b 100755 --- a/sflphone-common/src/config/yamlemitter.cpp +++ b/sflphone-common/src/config/yamlemitter.cpp @@ -32,13 +32,46 @@ namespace Conf { -YamlEmitter::YamlEmitter() {} +YamlEmitter::YamlEmitter() +{ + open(); +} + +YamlEmitter::~YamlEmitter() +{ + close(); +} + +void YamlEmitter::open() +{ + fd = fopen(filename.c_str(), "wb"); + + if(!fd) + throw YamlEmitterException("Could not open file descriptor"); + + if(!yaml_emitter_initialize(&emitter)) + throw YamlEmitterException("Could not open file descriptor"); -YamlEmitter::~YamlEmitter() {} + // Use unicode format + yaml_emitter_set_unicode(&emitter, 1); -void YamlEmitter::open() {} + yaml_emitter_set_output_file(&emitter, fd); -void YamlEmitter::close() {} + yaml_document_initialize(&document, NULL, NULL, NULL, 0, 0); +} + +void YamlEmitter::close() +{ + yaml_emitter_delete(&emitter); + + if(!fd) + throw YamlEmitterException("File descriptor not valid"); + + if(!fclose(fd)) + throw YamlEmitterException("Error closing file descriptor"); + + yaml_document_delete(&document); +} void YamlEmitter::read() {} diff --git a/sflphone-common/src/config/yamlemitter.h b/sflphone-common/src/config/yamlemitter.h index 3e55d102b118ab45252a5668562c5565c05c20de..6219f6788c575ef8677abe80f67d102a586da1be 100755 --- a/sflphone-common/src/config/yamlemitter.h +++ b/sflphone-common/src/config/yamlemitter.h @@ -31,15 +31,31 @@ #ifndef __YAMLEMITTER_H__ #define __YAMLEMITTER_H__ +#include <yaml.h> #include <exception> +#include <string> namespace Conf { -class YamlEmitterException : public std::exception { +#define EMITTER_BUFFERSIZE 65536 +#define EMITTER_MAXEVENT 1024 + +class YamlEmitterException : public std::exception +{ + public: + YamlEmitterException(const std::string& str="") throw() : errstr(str) {} + + virtual ~YamlEmitterException() throw() {} + + virtual const char *what() const throw() { + std::string expt("YamlParserException occured: "); + expt.append(errstr); + + return expt.c_str(); + } + private: + std::string errstr; - virtual const char *what() const throw() { - return "YamlEmitterException occured"; - } }; class YamlEmitter { @@ -61,6 +77,29 @@ class YamlEmitter { private: + std::string filename; + + FILE *fd; + + /** + * The parser structure. + */ + yaml_emitter_t emitter; + + /** + * The event structure array. + */ + yaml_event_t events[EMITTER_MAXEVENT]; + + /** + * + */ + unsigned char buffer[EMITTER_BUFFERSIZE]; + + yaml_document_t document; + + + }; } diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp index a138658c99dda85594019dcc884f5ebbecfd4f69..5d0b79c92f4826738cc19d0966779299b3d937dd 100755 --- a/sflphone-common/src/managerimpl.cpp +++ b/sflphone-common/src/managerimpl.cpp @@ -3824,7 +3824,9 @@ void ManagerImpl::setAccountDetails (const std::string& accountID, acc = getAccount(accountID); if (acc != NULL) { - acc->loadConfig(); + + + // acc->loadConfig(); if (acc->isEnabled()) { acc->registerVoIPLink(); diff --git a/sflphone-common/src/sip/sipaccount.cpp b/sflphone-common/src/sip/sipaccount.cpp index 495aec57d088a5c640a890272c6ab90d4a59462c..5c6513cda6d64119e87c5661c633d930cd2e28b0 100755 --- a/sflphone-common/src/sip/sipaccount.cpp +++ b/sflphone-common/src/sip/sipaccount.cpp @@ -134,7 +134,7 @@ SIPAccount::~SIPAccount() void SIPAccount::serialize(Engine *engine) { - + } @@ -159,9 +159,7 @@ void SIPAccount::unserialize(Conf::MappingNode *map) val = (Conf::ScalarNode *)(map->getValue(passwordKey)); if(val) { _password = val->getValue(); val = NULL; } val = (Conf::ScalarNode *)(map->getValue(hostnameKey)); - _debug("------------------------------------- hostname from config: %s, %s", _accountID.c_str(), val->getValue().c_str()); if(val) { _hostname = val->getValue(); val = NULL; } - _debug("------------------------------------- hostname from config: %s, %s", _accountID.c_str(), _hostname.c_str()); val = (Conf::ScalarNode *)(map->getValue(accountEnableKey)); if(val) { _enabled = (val->getValue().compare("true") == 0) ? true : false; val = NULL; } // val = (Conf::ScalarNode *)(map->getValue(mailboxKey)); diff --git a/sflphone-common/test/Makefile.am b/sflphone-common/test/Makefile.am index ed3baa511efa87f422b7e52bd0ec3681b7c9a287..9da8e2f60349f9304800235277ac1158142b6d92 100644 --- a/sflphone-common/test/Makefile.am +++ b/sflphone-common/test/Makefile.am @@ -40,5 +40,5 @@ LLIBS=$(CPPUNIT_LIBS) \ ../src/sflphoned-numbercleaner.o \ ../src/sflphoned-observer.o \ ../src/sflphoned-voiplink.o \ + ../src/sflphoned-preferences.o \ ../src/libsflphone.la - diff --git a/sflphone-common/test/configurationtest.cpp b/sflphone-common/test/configurationtest.cpp index 1c5805af03470140feab3ebe1076d7b4379a7149..bf92974cab547a30122e826631e568516387b3f3 100755 --- a/sflphone-common/test/configurationtest.cpp +++ b/sflphone-common/test/configurationtest.cpp @@ -176,39 +176,17 @@ void ConfigurationTest::testYamlParser() } - -void ConfigurationTest::testYamlComposition() +void ConfigurationTest::testYamlEmitter() { + Conf::YamlParser *emitter; - /* - Conf::YamlDocument *doc = new Conf::YamlDocument(); - - Conf::SequenceNode *seq = new Conf::SequenceNode(doc); - Conf::MappingNode *map = new Conf::MappingNode(); - Conf::ScalarNode *sclr = new Conf::ScalarNode(); - - CPPUNIT_ASSERT(seq->getType() == Conf::SEQUENCE); - CPPUNIT_ASSERT(map->getType() == Conf::MAPPING); - CPPUNIT_ASSERT(sclr->getType() == Conf::SCALAR); - - seq->addNode(map); - seq->addNode(sclr); - - Conf::Key key("username"); - Conf::ScalarNode *val = new Conf::ScalarNode("alexandre"); - - map->setKeyValue(key, val); - - Conf::YamlNode *node = map->getValue(key); - - CPPUNIT_ASSERT(node->getType() == Conf::SCALAR); - - delete val; - - delete seq; - delete map; - delete sclr; - */ + try{ + emitter = new Conf::YamlParser("sequenceEmiter.yml"); + delete emitter; + } + catch (Conf::YamlEmitterException &e) { + _error("ConfigTree: %s", e.what()); + } } diff --git a/sflphone-common/test/configurationtest.h b/sflphone-common/test/configurationtest.h index 8c9ff82fea485e5c36e0334782c6bce506a81404..00ee45e7ea3486f5eddb90db5852ed147496d2be 100755 --- a/sflphone-common/test/configurationtest.h +++ b/sflphone-common/test/configurationtest.h @@ -51,6 +51,7 @@ #include "global.h" #include "user_cfg.h" #include "config/yamlparser.h" +#include "config/yamlemitter.h" #include "config/yamlnode.h" class ConfigurationTest: public CppUnit::TestFixture { @@ -65,7 +66,7 @@ CPPUNIT_TEST_SUITE( ConfigurationTest ); // CPPUNIT_TEST( testDefaultValueSignalisation ); // CPPUNIT_TEST( testInitAudioDriver ); CPPUNIT_TEST( testYamlParser ); - CPPUNIT_TEST( testYamlComposition ); + CPPUNIT_TEST( testYamlEmitter ); CPPUNIT_TEST_SUITE_END(); public: @@ -98,7 +99,9 @@ public: void testYamlParser(); - void testYamlComposition(); + void testYamlEmitter(); + + }; /* Register our test module */ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ConfigurationTest, "ConfigurationTest");