From: Eduardo Ramos Testillano Date: Mon, 8 Jun 2015 21:21:06 +0000 (+0200) Subject: Preparing for multistack X-Git-Tag: REFACTORING_TESTING_LIBRARY~127 X-Git-Url: https://git.teslayout.com/public/public/public/?a=commitdiff_plain;h=6f990d26c49e6f5bbb31cb1a2a47615918b6c339;p=anna.git Preparing for multistack --- diff --git a/example/diameter/launcher/Launcher.cpp b/example/diameter/launcher/Launcher.cpp index 8804736..710ebfe 100644 --- a/example/diameter/launcher/Launcher.cpp +++ b/example/diameter/launcher/Launcher.cpp @@ -58,16 +58,7 @@ void Launcher::releaseCommMessage(anna::diameter::comm::Message *msg) throw() { a_commMessages.release(msg); } -anna::diameter::codec::Message *Launcher::createCodecMessage() throw(anna::RuntimeException) { - return a_codecMessages.create(); -} - -void Launcher::releaseCodecMessage(anna::diameter::codec::Message *msg) throw() { - a_codecMessages.release(msg); -} - - -void Launcher::baseProtocolSetupAsClient(void) throw(anna::RuntimeException) { +void Launcher::baseProtocolSetupAsClient(anna::diameter::codec::Engine *codecEngine) throw(anna::RuntimeException) { // Build CER // ::= < Diameter Header: 257, REQ > // { Origin-Host } 264 diameterIdentity @@ -79,7 +70,7 @@ void Launcher::baseProtocolSetupAsClient(void) throw(anna::RuntimeException) { // * [ Supported-Vendor-Id ] 265 Unsigned32 // * [ Auth-Application-Id ] 258 Unsigned32 // * [Acct-Application-Id] 259 Unsigned32 - anna::diameter::codec::Message diameterCER; + anna::diameter::codec::Message diameterCER(codecEngine); int applicationId = 0 /*anna::diameter::helpers::APPID__3GPP_Rx*/; // Unsigned32 std::string OH = a_myDiameterEngine->getHost(); std::string OR = a_myDiameterEngine->getRealm(); @@ -111,7 +102,7 @@ void Launcher::baseProtocolSetupAsClient(void) throw(anna::RuntimeException) { // ::= < Diameter Header: 280, REQ > // { Origin-Host } // { Origin-Realm } - anna::diameter::codec::Message diameterDWR; + anna::diameter::codec::Message diameterDWR(codecEngine); loadingError = false; try { @@ -129,77 +120,14 @@ void Launcher::baseProtocolSetupAsClient(void) throw(anna::RuntimeException) { diameterDWR.addAvp(anna::diameter::helpers::base::AVPID__Origin_Realm)->getDiameterIdentity()->setValue(OR); } -////////////////////////// -// IDEM FOR CEA AND DWA // -////////////////////////// -// // Build CER -// // ::= < Diameter Header: 257, REQ > -// // { Origin-Host } 264 diameterIdentity -// // { Origin-Realm } 296 idem -// // 1* { Host-IP-Address } 257, address -// // { Vendor-Id } 266 Unsigned32 -// // { Product-Name } 269 UTF8String -// // [Origin-State-Id] 278 Unsigned32 -// // * [ Supported-Vendor-Id ] 265 Unsigned32 -// // * [ Auth-Application-Id ] 258 Unsigned32 -// // * [Acct-Application-Id] 259 Unsigned32 -// anna::diameter::codec::Message diameterCER; -// int applicationId = 0 /*anna::diameter::helpers::APPID__3GPP_Rx*/; // Unsigned32 -// std::string OH = a_myDiameterEngine->getHost(); -// std::string OR = a_myDiameterEngine->getRealm(); -// std::string hostIP = anna::functions::getHostnameIP(); // Address -// int vendorId = anna::diameter::helpers::VENDORID__tgpp; // Unsigned32 -// std::string productName = "ANNA Diameter Launcher"; // UTF8String -// bool loadingError = false; -// -// try { -// diameterCER.loadXML("cer.xml"); -// } catch (anna::RuntimeException &ex) { -// ex.trace(); -// loadingError = true; -// } -// -// if (loadingError) { -// LOGWARNING(anna::Logger::warning("CER file not found. Get harcoded.", ANNA_FILE_LOCATION)); -// diameterCER.setId(anna::diameter::helpers::base::COMMANDID__Capabilities_Exchange_Request); -// diameterCER.setApplicationId(applicationId); -// diameterCER.addAvp(anna::diameter::helpers::base::AVPID__Origin_Host)->getDiameterIdentity()->setValue(OH); -// diameterCER.addAvp(anna::diameter::helpers::base::AVPID__Origin_Realm)->getDiameterIdentity()->setValue(OR); -// diameterCER.addAvp(anna::diameter::helpers::base::AVPID__Host_IP_Address)->getAddress()->fromPrintableString(hostIP.c_str()); // supported by Address class, anyway is better to provide "1|" -// diameterCER.addAvp(anna::diameter::helpers::base::AVPID__Vendor_Id)->getUnsigned32()->setValue(vendorId); -// diameterCER.addAvp(anna::diameter::helpers::base::AVPID__Product_Name)->getUTF8String()->setValue(productName); -// diameterCER.addAvp(anna::diameter::helpers::base::AVPID__Auth_Application_Id)->getUnsigned32()->setValue(applicationId); -// } -// -// // Build DWR -// // ::= < Diameter Header: 280, REQ > -// // { Origin-Host } -// // { Origin-Realm } -// anna::diameter::codec::Message diameterDWR; -// loadingError = false; -// -// try { -// diameterDWR.loadXML("dwr.xml"); -// } catch (anna::RuntimeException &ex) { -// ex.trace(); -// loadingError = true; -// } -// -// if (loadingError) { -// LOGWARNING(anna::Logger::warning("DWR file not found. Get harcoded.", ANNA_FILE_LOCATION)); -// diameterDWR.setId(anna::diameter::helpers::base::COMMANDID__Device_Watchdog_Request); -// diameterDWR.setApplicationId(applicationId); -// diameterDWR.addAvp(anna::diameter::helpers::base::AVPID__Origin_Host)->getDiameterIdentity()->setValue(OH); -// diameterDWR.addAvp(anna::diameter::helpers::base::AVPID__Origin_Realm)->getDiameterIdentity()->setValue(OR); -// } // Assignment for CER/DWR and CEA/DWA: a_myDiameterEngine->setCERandDWR(diameterCER.code(), diameterDWR.code()); //a_myDiameterEngine->setCEAandDWA(diameterCEA.code(), diameterDWA.code()); } -void Launcher::writeLogFile(const anna::DataBlock & db, const std::string &logExtension, const std::string &detail) const throw() { +void Launcher::writeLogFile(const anna::DataBlock & db, const std::string &logExtension, const std::string &detail, anna::diameter::codec::Engine *codecEngine) const throw() { // if (!logEnabled()) return; - anna::diameter::codec::Message codecMsg; + anna::diameter::codec::Message codecMsg(codecEngine); try { codecMsg.decode(db); } catch(anna::RuntimeException &ex) { ex.trace(); } writeLogFile(codecMsg, logExtension, detail); @@ -327,7 +255,7 @@ void Launcher::startDiameterServer(int diameterServerSessions) throw(anna::Runti //ServerSocket *createServerSocket(const std::string & addr, int port = Session::DefaultPort, int maxConnections = -1, int category = 1, const std::string & description = "") a_diameterLocalServer = (MyLocalServer*)(a_myDiameterEngine->createLocalServer(address, port, diameterServerSessions)); a_diameterLocalServer->setDescription("Launcher diameter local server"); - a_diameterLocalServer->setProgrammedAnswersCodecEngine(getCodecEngine()); + a_diameterLocalServer->setCodecEngine(getCodecEngine()); // this is for automatic answers (failed-avp) XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX el del nodo correspondiente int allowedInactivityTime = 90000; // ms if(cl.exists("allowedInactivityTime")) allowedInactivityTime = cl.getIntegerValue("allowedInactivityTime"); @@ -424,7 +352,7 @@ throw(anna::RuntimeException) { } } - getCodecEngine()->setDictionary(d); + getCodecEngine()->setDictionary(d); // XXXX esto cambiara... LOGDEBUG(anna::Logger::debug(getCodecEngine()->asString(), ANNA_FILE_LOCATION)); if(lst.size() > 1) { @@ -571,7 +499,7 @@ throw(anna::RuntimeException) { // Integration (validation 'Complete' for receiving messages) and debugging (validation also before encoding: 'Always'). // If missing 'integrationAndDebugging', default behaviour at engine is: mode 'AfterDecoding', depth 'FirstError': if(cl.exists("integrationAndDebugging")) { - getCodecEngine()->setValidationMode(anna::diameter::codec::Engine::ValidationMode::Always); + getCodecEngine()->setValidationMode(anna::diameter::codec::Engine::ValidationMode::Always); // XXXXXXXXXXXXXXXXXXXXXXXXX getCodecEngine()->setValidationDepth(anna::diameter::codec::Engine::ValidationDepth::Complete); } @@ -584,10 +512,10 @@ throw(anna::RuntimeException) { else if (fixMode == "Always") fm = anna::diameter::codec::Engine::FixMode::Always; else if (fixMode == "Never") fm = anna::diameter::codec::Engine::FixMode::Never; else LOGINFORMATION(anna::Logger::information("Unreconized command-line fix mode. Assumed default 'BeforeEncoding'", ANNA_FILE_LOCATION)); - getCodecEngine()->setFixMode(fm); + getCodecEngine()->setFixMode(fm); // XXXXXXXXXXXXXXXXXXXXXXX } - getCodecEngine()->ignoreFlagsOnValidation(cl.exists("ignoreFlags")); + getCodecEngine()->ignoreFlagsOnValidation(cl.exists("ignoreFlags")); // XXXXXXXXXXXXXXXXXXXXXXX // Diameter Server: if(cl.exists("diameterServer")) @@ -638,13 +566,13 @@ throw(anna::RuntimeException) { int entityServerSessions = cl.exists("entityServerSessions") ? cl.getIntegerValue("entityServerSessions") : 1; if(entityServerSessions > 0) { - baseProtocolSetupAsClient(); // Same CER/CEA, DWR/DWA for all diameter servers + baseProtocolSetupAsClient(getCodecEngine()); // Same CER/CEA, DWR/DWA for all diameter servers XXXXXXXXXXXXXXXXXXXXXXXXX anna::socket_v servers = anna::functions::getSocketVectorFromString(cl.getValue("entity")); a_myDiameterEngine->setNumberOfClientSessionsPerServer(entityServerSessions); a_entity = (MyDiameterEntity*)(a_myDiameterEngine->createEntity(servers, "Launcher diameter entity")); a_entity->setClassCodeTimeout(anna::diameter::comm::ClassCode::Bind, ceaTimeout); a_entity->setClassCodeTimeout(anna::diameter::comm::ClassCode::ApplicationMessage, answersTimeout); - a_entity->setProgrammedAnswersCodecEngine(getCodecEngine()); + a_entity->setCodecEngine(getCodecEngine()); // XXXXXXXXXXXXXXXXXXXXXXX a_entity->bind(); } } @@ -901,7 +829,7 @@ bool Launcher::sendBurstMessage(bool anyway) throw() { anna::diameter::comm::Server *usedServer = a_entity->getLastUsedResource(); anna::diameter::comm::ClientSession *usedClientSession = usedServer ? usedServer->getLastUsedResource() : NULL; std::string detail = usedClientSession ? usedClientSession->asString() : ""; // esto no deberia ocurrir - writeLogFile(msg->getBody(), (result ? "sent2e" : "send2eError"), detail); + writeLogFile(msg->getBody(), (result ? "sent2e" : "send2eError"), detail, getCodecEngine()); // el del nodo de trabajo } return result; @@ -915,7 +843,7 @@ std::string Launcher::lookBurst(int order) const throw() { if(it != a_burstMessages.end()) { // Decode - anna::diameter::codec::Message codecMsg; + anna::diameter::codec::Message codecMsg(getCodecEngine()); // XXXXXXXXXXXXXXXX el del nodo de trabajo try { codecMsg.decode((*it).second->getBody()); } catch(anna::RuntimeException &ex) { ex.trace(); } result = codecMsg.asXMLString(); } @@ -1232,7 +1160,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons response_content = "Operation processed with exception. See traces\n"; // supposed std::string result = ""; anna::DataBlock db_aux(true); - anna::diameter::codec::Message codecMsg; + anna::diameter::codec::Message codecMsg(getCodecEngine()); // XXXXXXXXXXXXXX el del nodo de trabajo /////////////////////////////////////////////////////////////////// // Simple operations without arguments: @@ -1563,7 +1491,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons } else if (param1 == "dump") { localServer->getReactingAnswers()->dump(); } else { - anna::diameter::codec::Message *message = getCodecEngine()->createMessage(param1); + anna::diameter::codec::Message *message = getCodecEngine()->createMessage(param1); // // XXXXXXXXXXXXXX el del nodo de trabajo LOGDEBUG ( anna::Logger::debug(message->asXMLString(), ANNA_FILE_LOCATION); @@ -1595,7 +1523,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons } else if (param1 == "dump") { entity->getReactingAnswers()->dump(); } else { - anna::diameter::codec::Message *message = getCodecEngine()->createMessage(param1); + anna::diameter::codec::Message *message = getCodecEngine()->createMessage(param1); // XXXXXXXXXXXXXX el del nodo de trabajo LOGDEBUG ( anna::Logger::debug(message->asXMLString(), ANNA_FILE_LOCATION); @@ -1731,7 +1659,7 @@ throw() { result->createAttribute("StartTime", a_start_time.asString()); result->createAttribute("SecondsLifeTime", anna::time::functions::lapsedMilliseconds() / 1000); // Diameter: - getCodecEngine()->asXML(result); + getCodecEngine()->asXML(result); // XXXXXXXXXXXXXXX todos los nodos ... // OAM: anna::diameter::comm::OamModule::instantiate().asXML(result); anna::diameter::comm::ApplicationMessageOamModule::instantiate().asXML(result); diff --git a/example/diameter/launcher/Launcher.hpp b/example/diameter/launcher/Launcher.hpp index 25f20c8..b1bf52a 100644 --- a/example/diameter/launcher/Launcher.hpp +++ b/example/diameter/launcher/Launcher.hpp @@ -65,7 +65,6 @@ class Launcher : public anna::comm::Application { // comm Messages factory: anna::Recycler a_commMessages; - anna::Recycler a_codecMessages; anna::comm::ServerSocket* a_httpServerSocket; // HTTP MyLocalServer* a_diameterLocalServer; // DIAMETER @@ -76,15 +75,15 @@ class Launcher : public anna::comm::Application { public: Launcher(); - anna::diameter::codec::Engine *getCodecEngine() const throw() { return a_codecEngine; } + anna::diameter::codec::Engine *getCodecEngine() const throw() { return a_codecEngine; } // XXXXXXXXXXXXXXXXX El del nodo de trabajo MyCommunicator *getCommunicator() throw() { return a_communicator; } MyDiameterEngine* getMyDiameterEngine() const throw() { return (a_myDiameterEngine); } - void baseProtocolSetupAsClient(void) throw(anna::RuntimeException); + void baseProtocolSetupAsClient(anna::diameter::codec::Engine *codecEngine) throw(anna::RuntimeException); MyDiameterEntity *getEntity() throw() { return a_entity; } MyLocalServer* getDiameterLocalServer() throw() { return a_diameterLocalServer; } void eventOperation(const std::string &, std::string &) throw(anna::RuntimeException); bool logEnabled() const throw() { return (((a_logFile == "") || (a_logFile == "null")) ? false : true); } - void writeLogFile(const anna::DataBlock & db, const std::string &logExtension, const std::string &detail) const throw(); + void writeLogFile(const anna::DataBlock & db, const std::string &logExtension, const std::string &detail, anna::diameter::codec::Engine *codecEngine) const throw(); void writeLogFile(const anna::diameter::codec::Message & decodedMessage, const std::string &logExtension, const std::string &detail) const throw(); void writeBurstLogFile(const std::string &buffer) throw(); bool burstLogEnabled() const throw() { return (((a_burstLogFile == "") || (a_burstLogFile == "null")) ? false : true); } @@ -100,8 +99,6 @@ public: // Messages factory: anna::diameter::comm::Message *createCommMessage() throw(anna::RuntimeException); void releaseCommMessage(anna::diameter::comm::Message*) throw(); - anna::diameter::codec::Message *createCodecMessage() throw(anna::RuntimeException); - void releaseCodecMessage(anna::diameter::codec::Message*) throw(); // helpers bool getDataBlockFromHexFile(const std::string &pathfile, anna::DataBlock &db) const throw(); diff --git a/example/diameter/launcher/MyDiameterEntity.cpp b/example/diameter/launcher/MyDiameterEntity.cpp index f6fce7b..702ec56 100644 --- a/example/diameter/launcher/MyDiameterEntity.cpp +++ b/example/diameter/launcher/MyDiameterEntity.cpp @@ -37,7 +37,7 @@ throw(anna::RuntimeException) { ); // Write reception - if(my_app.logEnabled()) my_app.writeLogFile(message, "recvfe", clientSession->asString()); + if(my_app.logEnabled()) my_app.writeLogFile(message, "recvfe", clientSession->asString(), a_codecEngine); // Lookup reacting answers list: int code = cid.first; @@ -87,7 +87,7 @@ throw(anna::RuntimeException) { if(my_app.logEnabled()) { anna::diameter::comm::ServerSession *usedServerSession = localServer->getLastUsedResource(); std::string detail = usedServerSession ? usedServerSession->asString() : ""; // esto no deberia ocurrir - my_app.writeLogFile(message, (success ? "fwd2c" : "fwd2cError"), detail); + my_app.writeLogFile(message, (success ? "fwd2c" : "fwd2cError"), detail, a_codecEngine); } } catch(anna::RuntimeException &ex) { ex.trace(); @@ -135,7 +135,7 @@ throw(anna::RuntimeException) { LOGWARNING(anna::Logger::warning("Context Expired for Diameter Request which was sent to the entity", ANNA_FILE_LOCATION)); if(request_cid != anna::diameter::helpers::base::COMMANDID__Capabilities_Exchange_Request) { // don't trace CEA - if(my_app.logEnabled()) my_app.writeLogFile(*request, "req2e-expired", clientSession->asString()); + if(my_app.logEnabled()) my_app.writeLogFile(*request, "req2e-expired", clientSession->asString(), a_codecEngine); } } @@ -149,7 +149,7 @@ throw(anna::RuntimeException) { // Write reception if(request_cid != anna::diameter::helpers::base::COMMANDID__Capabilities_Exchange_Request) { // don't trace CEA if(my_app.logEnabled()) { - my_app.writeLogFile(*message, "recvfe", clientSession->asString()); + my_app.writeLogFile(*message, "recvfe", clientSession->asString(), a_codecEngine); } } @@ -170,7 +170,7 @@ throw(anna::RuntimeException) { std::string detail = usedServerSession ? usedServerSession->asString() : ""; // esto no deberia ocurrir if(my_app.logEnabled()) { - my_app.writeLogFile(*message, (success ? "fwd2c" : "fwd2cError"), detail); + my_app.writeLogFile(*message, (success ? "fwd2c" : "fwd2cError"), detail, a_codecEngine); } } catch(anna::RuntimeException &ex) { ex.trace(); @@ -201,7 +201,7 @@ throw(anna::RuntimeException) { ); // Write reception - if(my_app.logEnabled()) my_app.writeLogFile(message, "recvfe-ans-unknown", clientSession->asString()); + if(my_app.logEnabled()) my_app.writeLogFile(message, "recvfe-ans-unknown", clientSession->asString(), a_codecEngine); } void MyDiameterEntity::eventDPA(anna::diameter::comm::ClientSession *clientSession, const anna::DataBlock &message) @@ -223,5 +223,5 @@ throw(anna::RuntimeException) { ); // Write reception - if(my_app.logEnabled()) my_app.writeLogFile(message, "recvfe", clientSession->asString()); + if(my_app.logEnabled()) my_app.writeLogFile(message, "recvfe", clientSession->asString(), a_codecEngine); } diff --git a/example/diameter/launcher/MyDiameterEntity.hpp b/example/diameter/launcher/MyDiameterEntity.hpp index 654a640..e60fdfc 100644 --- a/example/diameter/launcher/MyDiameterEntity.hpp +++ b/example/diameter/launcher/MyDiameterEntity.hpp @@ -25,6 +25,8 @@ namespace anna { class MyDiameterEntity : public anna::diameter::comm::Entity { + anna::diameter::codec::Engine * a_codecEngine; // for automatic answers (failed-avp), write logs, etc. + void eventResponse(const anna::diameter::comm::Response&) throw(anna::RuntimeException); void eventRequest(anna::diameter::comm::ClientSession *, const anna::DataBlock&) throw(anna::RuntimeException); void eventUnknownResponse(anna::diameter::comm::ClientSession *, const anna::DataBlock&) throw(anna::RuntimeException); @@ -36,7 +38,7 @@ class MyDiameterEntity : public anna::diameter::comm::Entity { public: ProgrammedAnswers a_reactingAnswers; - void setProgrammedAnswersCodecEngine(anna::diameter::codec::Engine *codecEngine) throw() { a_reactingAnswers.setCodecEngine(codecEngine); } + void setCodecEngine(anna::diameter::codec::Engine *codecEngine) throw() { a_codecEngine = codecEngine; a_reactingAnswers.setCodecEngine(codecEngine); } ProgrammedAnswers *getReactingAnswers() throw() { return (ProgrammedAnswers *)&a_reactingAnswers; } }; diff --git a/example/diameter/launcher/MyLocalServer.cpp b/example/diameter/launcher/MyLocalServer.cpp index 9346c5d..91e95f5 100644 --- a/example/diameter/launcher/MyLocalServer.cpp +++ b/example/diameter/launcher/MyLocalServer.cpp @@ -38,7 +38,7 @@ throw(anna::RuntimeException) { ); // Write reception - if(my_app.logEnabled()) my_app.writeLogFile(message, "recvfc", serverSession->asString()); + if(my_app.logEnabled()) my_app.writeLogFile(message, "recvfc", serverSession->asString(), a_codecEngine); // If no answer is programmed and entity is configured, the failed request would be forwarded even being wrong (delegates at the end point) int code = cid.first; @@ -58,7 +58,7 @@ throw(anna::RuntimeException) { anna::diameter::comm::Server *usedServer = entity->getLastUsedResource(); anna::diameter::comm::ClientSession *usedClientSession = usedServer ? usedServer->getLastUsedResource() : NULL; std::string detail = usedClientSession ? usedClientSession->asString() : ""; // esto no deberia ocurrir - my_app.writeLogFile(message, (success ? "fwd2e" : "fwd2eError"), detail); // forwarded + my_app.writeLogFile(message, (success ? "fwd2e" : "fwd2eError"), detail, a_codecEngine); // forwarded } return; @@ -67,17 +67,17 @@ throw(anna::RuntimeException) { // Error analisys: bool analysisOK = true; // by default anna::diameter::codec::Message *answer_message = NULL; - anna::diameter::codec::Message *codecMsg = my_app.createCodecMessage(); + anna::diameter::codec::Message codecMsg(a_codecEngine); + anna::diameter::codec::Message codecAnsMsg(a_codecEngine); if(!cl.exists("ignoreErrors")) { // Error analysis - answer_message = my_app.createCodecMessage(); + answer_message = (anna::diameter::codec::Message *)&codecAnsMsg; answer_message->clear(); // Decode - try { codecMsg->decode(message, answer_message); } catch(anna::RuntimeException &ex) { ex.trace(); } + try { codecMsg.decode(message, answer_message); } catch(anna::RuntimeException &ex) { ex.trace(); } - answer_message->setStandardToAnswer(*codecMsg, my_app.getMyDiameterEngine()->getHost(), my_app.getMyDiameterEngine()->getRealm()); - my_app.releaseCodecMessage(codecMsg); + answer_message->setStandardToAnswer(codecMsg, my_app.getMyDiameterEngine()->getHost(), my_app.getMyDiameterEngine()->getRealm()); analysisOK = (answer_message->getResultCode() == anna::diameter::helpers::base::AVPVALUES__Result_Code::DIAMETER_SUCCESS); } @@ -90,11 +90,10 @@ throw(anna::RuntimeException) { } else return; // nothing done } - anna::diameter::codec::Engine *codecEngine = my_app.getCodecEngine(); - anna::diameter::codec::Engine::ValidationMode::_v backupVM = codecEngine->getValidationMode(); + anna::diameter::codec::Engine::ValidationMode::_v backupVM = a_codecEngine->getValidationMode(); if(!analysisOK) - codecEngine->setValidationMode(anna::diameter::codec::Engine::ValidationMode::Never); + a_codecEngine->setValidationMode(anna::diameter::codec::Engine::ValidationMode::Never); try { anna::diameter::comm::Message *msg = my_app.createCommMessage(); @@ -108,11 +107,8 @@ throw(anna::RuntimeException) { if(my_app.logEnabled()) my_app.writeLogFile(*answer_message, "send2cError", serverSession->asString()); } - // Release auxiliary codec message - my_app.releaseCodecMessage(answer_message); - // Restore validation mode - codecEngine->setValidationMode(backupVM); + a_codecEngine->setValidationMode(backupVM); // Pop front the reacting answer: if(analysisOK && programmed) a_reactingAnswers.nextMessage(code); @@ -158,7 +154,7 @@ throw(anna::RuntimeException) { LOGWARNING(anna::Logger::warning("Context Expired for Diameter Request which was sent to the client", ANNA_FILE_LOCATION)); if(request_cid != anna::diameter::helpers::base::COMMANDID__Capabilities_Exchange_Request) { // don't trace CEA - if(my_app.logEnabled()) my_app.writeLogFile(*request, "req2c-expired", serverSession->asString()); + if(my_app.logEnabled()) my_app.writeLogFile(*request, "req2c-expired", serverSession->asString(), a_codecEngine); } } @@ -170,7 +166,7 @@ throw(anna::RuntimeException) { ); // Write reception - if(my_app.logEnabled()) my_app.writeLogFile(*message, "recvfc", serverSession->asString()); + if(my_app.logEnabled()) my_app.writeLogFile(*message, "recvfc", serverSession->asString(), a_codecEngine); // This is not very usual, but answers could arrive from clients: anna::diameter::comm::Entity *entity = my_app.getEntity(); @@ -196,10 +192,10 @@ throw(anna::RuntimeException) { my_app.releaseCommMessage(msg); my_app.releaseCommMessage(request); - if(my_app.logEnabled()) my_app.writeLogFile(*message, "fwd2e", detail); // forwarded + if(my_app.logEnabled()) my_app.writeLogFile(*message, "fwd2e", detail, a_codecEngine); // forwarded } catch(anna::RuntimeException &ex) { ex.trace(); - if(my_app.logEnabled()) my_app.writeLogFile(*message, "fwd2eError", detail); // forwarded + if(my_app.logEnabled()) my_app.writeLogFile(*message, "fwd2eError", detail, a_codecEngine); // forwarded } } } @@ -223,7 +219,7 @@ throw(anna::RuntimeException) { anna::Logger::debug(msg, ANNA_FILE_LOCATION); ); - if(my_app.logEnabled()) my_app.writeLogFile(message, "recvfc-ans-unknown", serverSession->asString()); + if(my_app.logEnabled()) my_app.writeLogFile(message, "recvfc-ans-unknown", serverSession->asString(), a_codecEngine); } void MyLocalServer::eventDPA(anna::diameter::comm::ServerSession *serverSession, const anna::DataBlock &message) @@ -244,5 +240,5 @@ throw(anna::RuntimeException) { anna::Logger::debug(msg, ANNA_FILE_LOCATION); ); - if(my_app.logEnabled()) my_app.writeLogFile(message, "recvfc", serverSession->asString()); + if(my_app.logEnabled()) my_app.writeLogFile(message, "recvfc", serverSession->asString(), a_codecEngine); } diff --git a/example/diameter/launcher/MyLocalServer.hpp b/example/diameter/launcher/MyLocalServer.hpp index a7c139a..c90d8f2 100644 --- a/example/diameter/launcher/MyLocalServer.hpp +++ b/example/diameter/launcher/MyLocalServer.hpp @@ -25,6 +25,8 @@ namespace anna { class MyLocalServer : public anna::diameter::comm::LocalServer { + anna::diameter::codec::Engine * a_codecEngine; // for automatic answers (failed-avp), write logs, etc. + void eventResponse(const anna::diameter::comm::Response&) throw(anna::RuntimeException); void eventRequest(anna::diameter::comm::ServerSession *, const anna::DataBlock&) throw(anna::RuntimeException); void eventUnknownResponse(anna::diameter::comm::ServerSession *, const anna::DataBlock&) throw(anna::RuntimeException); @@ -33,7 +35,7 @@ class MyLocalServer : public anna::diameter::comm::LocalServer { public: ProgrammedAnswers a_reactingAnswers; - void setProgrammedAnswersCodecEngine(anna::diameter::codec::Engine *codecEngine) throw() { a_reactingAnswers.setCodecEngine(codecEngine); } + void setCodecEngine(anna::diameter::codec::Engine *codecEngine) throw() { a_codecEngine = codecEngine; a_reactingAnswers.setCodecEngine(codecEngine); } ProgrammedAnswers *getReactingAnswers() throw() { return (ProgrammedAnswers *)&a_reactingAnswers; } }; diff --git a/example/diameter/launcher/ProgrammedAnswers.cpp b/example/diameter/launcher/ProgrammedAnswers.cpp index f617282..8e310d7 100644 --- a/example/diameter/launcher/ProgrammedAnswers.cpp +++ b/example/diameter/launcher/ProgrammedAnswers.cpp @@ -45,6 +45,9 @@ void ProgrammedAnswers::dump () throw() { } void ProgrammedAnswers::addMessage(int code, anna::diameter::codec::Message *message) throw() { + if (!message) return; // just in case + message->setEngine(a_codecEngine); // just in case + reacting_answers_const_iterator it = a_deques.find(code); if (it != a_deques.end()) { it->second->push_back(message); diff --git a/include/anna/diameter.comm/Entity.hpp b/include/anna/diameter.comm/Entity.hpp index 2674e85..2335d82 100644 --- a/include/anna/diameter.comm/Entity.hpp +++ b/include/anna/diameter.comm/Entity.hpp @@ -134,6 +134,11 @@ public: */ void setEngine(Engine *e) throw() { a_engine = e; } +// /** +// * Gets the diameter::comm::Engine +// * @return Diameter::comm::Engine +// */ +// Engine *getEngine() const throw() { return a_engine; } /** * Add a server to the entity and create all the servers configured at #setSocketsPerDiameterServer within that server. diff --git a/include/anna/diameter.comm/LocalServer.hpp b/include/anna/diameter.comm/LocalServer.hpp index 03308b1..f8f0079 100644 --- a/include/anna/diameter.comm/LocalServer.hpp +++ b/include/anna/diameter.comm/LocalServer.hpp @@ -175,6 +175,11 @@ public: */ void setEngine(Engine *e) throw() { a_engine = e; } +// /** +// * Gets the diameter::comm::Engine +// * @return Diameter::comm::Engine +// */ +// Engine *getEngine() const throw() { return a_engine; } // getters