X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=source%2Fdiameter%2Fcodec%2FMessage.cpp;h=28a1d4587d27f6618c5170be15fe1bd390ec0fc0;hb=a59cea2b1fd2a149c4c8ad161a449bf75a36ac77;hp=b5d87f6e2fbc349fdfa29fff8f70d718ccc085c3;hpb=e80e62a5cf9aacad1a9551c68c432147ef98cd29;p=anna.git diff --git a/source/diameter/codec/Message.cpp b/source/diameter/codec/Message.cpp index b5d87f6..28a1d45 100644 --- a/source/diameter/codec/Message.cpp +++ b/source/diameter/codec/Message.cpp @@ -84,7 +84,12 @@ Message::~Message() { //------------------------------------------------------------------------------ void Message::setEngine(Engine *engine) throw() { - if (a_engine && engine != a_engine) { + if (!engine) { + LOGWARNING(anna::Logger::warning("Ignored: you must assign a valid codec engine. If you want to set NULL engine, clear the message", ANNA_FILE_LOCATION)); + return; + } + + if (a_engine && (engine != a_engine)) { LOGWARNING(anna::Logger::warning("Ignored: it is not a good practice to change the codec engine once assigned. Clear the message first to set the engine again.", ANNA_FILE_LOCATION)); return; } @@ -124,7 +129,7 @@ void Message::initialize() throw() { //------------------------------------------------------------------------------ //------------------------------------------------------------- Message::clear() //------------------------------------------------------------------------------ -void Message::clear() throw(anna::RuntimeException) { +void Message::clear(bool resetEngine) throw(anna::RuntimeException) { for(avp_iterator it = avp_begin(); it != avp_end(); it++) { /*avp(it)->clear(); */getEngine()->releaseAvp(Avp::avp(it)); } a_avps.clear(); @@ -133,6 +138,7 @@ void Message::clear() throw(anna::RuntimeException) { a_finds.clear(); // Initialize: initialize(); + if (resetEngine) a_engine = NULL; } @@ -191,9 +197,7 @@ bool Message::flagsOK(int &rc) const throw() { //------------------------------------------------------------------------------ //------------------------------------------------------------- Message::setId() //------------------------------------------------------------------------------ -void Message::setId(CommandId id, bool _clear) throw(anna::RuntimeException) { - // Clear class content: - if(_clear) clear(); +void Message::setId(CommandId id) throw(anna::RuntimeException) { // Id assignment: a_id = id; @@ -229,6 +233,7 @@ void Message::setApplicationId(U32 aid) throw(anna::RuntimeException) { // Codec engine manager (a multithreaded application, normally does not achieve this point, because // messages are prepared for each interface with the corresponding codec engine) anna::diameter::codec::EngineManager &em = anna::diameter::codec::EngineManager::instantiate(); + if (em.size() == 0) return; if (em.selectFromApplicationId()) { Engine *monostackEngine = em.getMonoStackCodecEngine(); if (monostackEngine) { a_engine = monostackEngine; return; } @@ -305,7 +310,7 @@ void Message::decode(const anna::DataBlock &db, Message *ptrAnswer) throw(anna:: trace += db.asString(); anna::Logger::debug(trace, ANNA_FILE_LOCATION); ); - clear(); + clear(false /* respect engine */); // EXCEPTION MANAGEMENT IN THIS METHOD // =================================== // DECODE PHASE @@ -775,7 +780,7 @@ void Message::fromXML(const anna::xml::Node* messageNode) throw(anna::RuntimeExc unsigned int u_aux; // Clear the message - clear(); + clear(false /* respect engine */); if(version) { i_aux = version->getIntegerValue(); @@ -822,7 +827,8 @@ void Message::fromXML(const anna::xml::Node* messageNode) throw(anna::RuntimeExc throw anna::RuntimeException(msg, ANNA_FILE_LOCATION); } - setId(stackCommand->getId(), false /* don't clear */); + setId(stackCommand->getId()); + // 'P', 'E' and 'T' flags: bool activateP = pbit ? (pbit->getValue() == "yes") : false; bool activateE = ebit ? (ebit->getValue() == "yes") : false;