Changed LICENSE. Now referenced to web site and file on project root directory
[anna.git] / source / diameter.comm / ClientSession.cpp
index 73d097a..87a2f60 100644 (file)
@@ -1,37 +1,9 @@
-// ANNA - Anna is Not 'N' Anymore
-//
-// (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
-//
-// https://bitbucket.org/testillano/anna
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-//
-//     * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-//     * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-//     * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-// Authors: eduardo.ramos.testillano@gmail.com
-//          cisco.tierra@gmail.com
+// ANNA - Anna is Not Nothingness Anymore                                                         //
+//                                                                                                //
+// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
+//                                                                                                //
+// See project site at http://redmine.teslayout.com/projects/anna-suite                           //
+// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
 
 
 #include <anna/core/functions.hpp>
@@ -140,6 +112,10 @@ void ClientSession::bind() throw(anna::RuntimeException) {
     return;
   }
 
+  // Some operations could be done before sending CER, for example non-standard Origin-Host manipulation for
+  // Tekelec PCRF
+  a_engine->bindingClientSession(this);
+
   // OAM Lo comento, porque no se contabilizan los reintentos y por lo tanto no son muy Ăștiles.
 //  OamModule &oamModule = OamModule::instantiate();
 //  oamModule.count(a_server->isAvailable() ? OamModule::Counter::TCPConnectOK:OamModule::Counter::TCPConnectNOK);
@@ -478,6 +454,11 @@ void ClientSession::eventUnknownResponse(const anna::DataBlock& response) throw(
   a_parent->eventUnknownResponse(this, response);
 }
 
+void ClientSession::eventDPA(const anna::DataBlock& response) throw(anna::RuntimeException) {
+  // Inform father server:
+  a_parent->eventDPA(this, response);
+}
+
 
 
 //------------------------------------------------------------------------------------------
@@ -578,7 +559,10 @@ throw(anna::RuntimeException) {
     }
 
     if(resultCode != helpers::base::AVPVALUES__Result_Code::DIAMETER_SUCCESS) {
-      LOGWARNING(anna::Logger::warning("Received CEA with non-success Result-Code. Unbinding connection.", ANNA_FILE_LOCATION));
+      LOGWARNING(
+        std::string msg = anna::functions::asString("Received CEA with non-success Result-Code (%d). Unbinding connection.", resultCode);
+        anna::Logger::warning(msg, ANNA_FILE_LOCATION);
+      );
       doUnbind = true;
     } else {
       setState(State::Bound);
@@ -594,7 +578,10 @@ throw(anna::RuntimeException) {
     setWatchdogState(WatchdogState::WaitingTimerExpiration);
 
     if(resultCode != helpers::base::AVPVALUES__Result_Code::DIAMETER_SUCCESS)
-      LOGWARNING(anna::Logger::warning("Received DWA with non-success Result-Code... but ASSUME keep-alive is reached", ANNA_FILE_LOCATION));
+      LOGWARNING(
+        std::string msg = anna::functions::asString("Received DWA with non-success Result-Code (%d)... but ASSUME keep-alive is reached", resultCode);
+        anna::Logger::warning(msg, ANNA_FILE_LOCATION);
+      );
 
     if(a_state == State::Failover) {
       setState(State::Bound);
@@ -615,7 +602,10 @@ throw(anna::RuntimeException) {
 
     if(a_state == State::WaitingDPA) {
       if(resultCode != helpers::base::AVPVALUES__Result_Code::DIAMETER_SUCCESS) {
-        LOGWARNING(anna::Logger::warning("Received DPA with non-success Result-Code. Ignoring and recovering Bound state", ANNA_FILE_LOCATION));
+        LOGWARNING(
+          std::string msg = anna::functions::asString("Received DPA with non-success Result-Code (%d). Ignoring and recovering Bound state", resultCode);
+          anna::Logger::warning(msg, ANNA_FILE_LOCATION);
+        );
         setState(State::Bound);
       } else {
         LOGWARNING(anna::Logger::warning("Received DPA With Result-Code = DIAMETER_SUCCESS. Disconnect now.", ANNA_FILE_LOCATION));
@@ -666,7 +656,6 @@ throw(anna::RuntimeException) {
   requestMessage->setRequestServerSessionKey(response->getRequest()->getRequestServerSessionKey()); // -1 means unkown/unset
 
   if(cid != helpers::base::COMMANDID__Disconnect_Peer_Answer) {
-    // don't progress DPA: unbind is automatically performed and not open to any application decision
     try {
       response->setMessage(&db);
       // Restore received datablock
@@ -685,6 +674,11 @@ throw(anna::RuntimeException) {
       ex.trace();
     }
   }
+  else { // DPA
+    // unbind is automatically performed, anyway we can inform to the application just in case some additional
+    //  procedure could be issued:
+    eventDPA(db);
+  }
 
   response_erase(response);