From: Eduardo Ramos Testillano Date: Sun, 13 Mar 2016 21:42:47 +0000 (+0100) Subject: Protection for non registered codec engines X-Git-Tag: REFACTORING_TESTING_LIBRARY~13 X-Git-Url: https://git.teslayout.com/public/public/public/?p=anna.git;a=commitdiff_plain;h=5e4f1d9d5902d86a37ecf88b372d9089d417e663 Protection for non registered codec engines --- diff --git a/example/diameter/launcher/OriginHost.cpp b/example/diameter/launcher/OriginHost.cpp index f8ee709..195edad 100644 --- a/example/diameter/launcher/OriginHost.cpp +++ b/example/diameter/launcher/OriginHost.cpp @@ -36,7 +36,7 @@ OriginHost::OriginHost(const std::string &originHost, unsigned int applicationId std::string commEngineName = a_originHost + "_DiameterCommEngine"; a_commEngine = new MyDiameterEngine(commEngineName.c_str(), baseProtocolDictionary); a_commEngine->setAutoBind(false); // allow to create client-sessions without binding them, in order to set timeouts. - a_codecEngine = anna::diameter::codec::EngineManager::instantiate().getCodecEngine(applicationId); + a_codecEngine = anna::diameter::codec::EngineManager::instantiate().getCodecEngine(applicationId); // i know, this is going to exist (getCodecEngine is not null) a_logFile = ""; a_burstLogFile = ""; diff --git a/example/diameter/launcher/ProgrammedAnswers.cpp b/example/diameter/launcher/ProgrammedAnswers.cpp index 3f64a35..b2b89b2 100644 --- a/example/diameter/launcher/ProgrammedAnswers.cpp +++ b/example/diameter/launcher/ProgrammedAnswers.cpp @@ -21,10 +21,18 @@ void ProgrammedAnswers::clear() throw () { try { anna::diameter::codec::EngineManager &em = anna::diameter::codec::EngineManager::instantiate(); + anna::diameter::codec::Engine *engine; + for (reacting_answers_const_iterator it = a_deques.begin(); it != a_deques.end(); it++) { anna::diameter::codec::Message *message = *(it->second->begin()); - em.getCodecEngine(message->getApplicationId())->releaseMessage(message); - delete (it->second); + engine = em.getCodecEngine(message->getApplicationId()); + if (engine) { + engine->releaseMessage(message); + delete (it->second); + } + else { + LOGWARNING(anna::Logger::warning("Cannot release a message for which i don't know the codec engine (check the registered stack id regarding the message application id) !", ANNA_FILE_LOCATION)); + } } a_deques.clear(); } @@ -79,16 +87,24 @@ anna::diameter::codec::Message* ProgrammedAnswers::getMessage(int code) const th } void ProgrammedAnswers::nextMessage(int code) throw () { //pops the deque and release the message (when deque is not empty: deque::empty) + anna::diameter::codec::Engine *engine; + try { reacting_answers_const_iterator it = a_deques.find(code); if (it != a_deques.end()) { if (!it->second->empty()) { + anna::diameter::codec::Message *message = *(it->second->begin()); if (a_rotate) { - addMessage(code, *(it->second->begin())); + addMessage(code, message); } else { - anna::diameter::codec::EngineManager &em = anna::diameter::codec::EngineManager::instantiate(); - anna::diameter::codec::Message *message = *(it->second->begin()); - em.getCodecEngine(message->getApplicationId())->releaseMessage(message); + engine = anna::diameter::codec::EngineManager::instantiate().getCodecEngine(message->getApplicationId()); + if (engine) { + engine->releaseMessage(message); + } + else { + LOGWARNING(anna::Logger::warning("Cannot release a message for which i don't know the codec engine (check the registered stack id regarding the message application id) !", ANNA_FILE_LOCATION)); + return; + } } it->second->pop_front(); } diff --git a/source/diameter.comm/LocalServer.cpp b/source/diameter.comm/LocalServer.cpp index 0e2bc2e..469fccd 100644 --- a/source/diameter.comm/LocalServer.cpp +++ b/source/diameter.comm/LocalServer.cpp @@ -47,7 +47,7 @@ LocalServer::LocalServer() : void LocalServer::initializeStatisticResources() throw() { - std::string accName = "local server '"; + std::string accName = "sent from local server '"; accName += anna::functions::socketLiteralAsString(a_key.first, a_key.second); accName += "' on origin-realm '"; accName += a_engine ? a_engine->getOriginRealm() : "unknown"; // it should be known (createServer) diff --git a/source/diameter.comm/Server.cpp b/source/diameter.comm/Server.cpp index 1ba8356..7bd1797 100644 --- a/source/diameter.comm/Server.cpp +++ b/source/diameter.comm/Server.cpp @@ -40,7 +40,7 @@ void Server::initialize() throw() { } void Server::initializeStatisticResources() throw() { - std::string accName = "remote server '"; + std::string accName = "sent to remote server '"; accName += anna::functions::socketLiteralAsString(a_socket.first, a_socket.second); accName += "' from origin-realm '"; accName += a_engine ? a_engine->getOriginRealm() : "unknown"; // it should be known (createServer)