Fixed multiple AVP error. Missing fix RFC 6733 section 7.5 regarding avps within...
[anna.git] / source / diameter / codec / Avp.cpp
index 19a0780..7f33851 100644 (file)
@@ -644,7 +644,7 @@ void Avp::unknownAvpWithMandatoryBit(Message *answer) const throw(anna::RuntimeE
 
   if(answer) {
     answer->setResultCode(helpers::base::AVPVALUES__Result_Code::DIAMETER_AVP_UNSUPPORTED);
-    answer->setNewFailedAvp((Avp*)this);
+    answer->setFailedAvp((Avp*)this);
   }
 }
 
@@ -679,6 +679,12 @@ void Avp::decodeDataPart(const char * buffer, int size, Message *answer) throw(a
     if((size % 4) != 0) {
       oamModule.activateAlarm(OamModule::Alarm::AvpDecode__IncorrectLength);
       oamModule.count(OamModule::Counter::AvpDecode__IncorrectLength);
+
+      if(answer) {
+        answer->setResultCode(helpers::base::AVPVALUES__Result_Code::DIAMETER_INVALID_AVP_LENGTH);
+        //answer->setFailedAvp(a_id);
+      }
+
       throw anna::RuntimeException("Avp format error, the avp length is incorrect (must be multiple of 4 on grouped type)", ANNA_FILE_LOCATION);
     }
 
@@ -724,7 +730,7 @@ void Avp::decode(const anna::DataBlock &db, Message *answer) throw(anna::Runtime
   if(db.getSize() < HeaderLengthVinactive) {
     oamModule.activateAlarm(OamModule::Alarm::AvpDecode__NotEnoughBytesToCoverAvpHeaderLength);
     oamModule.count(OamModule::Counter::AvpDecode__NotEnoughBytesToCoverAvpHeaderLength);
-    // DIAMETER_INVALID_AVP_LENGTH; // no podré construir un avp fiable, así que no registro el result-code
+    // DIAMETER_INVALID_AVP_LENGTH; // no podr� construir un avp fiable, as� que no registro el result-code
     throw anna::RuntimeException("Not enough bytes to cover avp header length", ANNA_FILE_LOCATION);
   }
 
@@ -752,7 +758,7 @@ void Avp::decode(const anna::DataBlock &db, Message *answer) throw(anna::Runtime
     if(db.getSize() < HeaderLengthVactive) {
       oamModule.activateAlarm(OamModule::Alarm::AvpDecode__NotEnoughBytesToCoverAvpHeaderLength);
       oamModule.count(OamModule::Counter::AvpDecode__NotEnoughBytesToCoverAvpHeaderLength);
-      // DIAMETER_INVALID_AVP_LENGTH; // no podré construir un avp fiable, así que no registro el result-code
+      // DIAMETER_INVALID_AVP_LENGTH; // no podr� construir un avp fiable, as� que no registro el result-code
       throw anna::RuntimeException(anna::functions::asString("Not enough bytes to cover avp header length (avp code = %u)", code), ANNA_FILE_LOCATION);
     }
 
@@ -794,7 +800,7 @@ void Avp::decode(const anna::DataBlock &db, Message *answer) throw(anna::Runtime
 
     if(answer) {
       answer->setResultCode(helpers::base::AVPVALUES__Result_Code::DIAMETER_INVALID_AVP_LENGTH);
-      answer->setNewFailedAvp(a_id);
+      //answer->setFailedAvp(a_id);
     }
 
     throw anna::RuntimeException(anna::functions::asString("Avp format error, the avp length is incorrect (avp code = %u)", code), ANNA_FILE_LOCATION);
@@ -808,7 +814,7 @@ void Avp::decode(const anna::DataBlock &db, Message *answer) throw(anna::Runtime
 
     if(answer) {
       answer->setResultCode(helpers::base::AVPVALUES__Result_Code::DIAMETER_INVALID_AVP_VALUE); // unspecified error ...
-      answer->setNewFailedAvp((Avp*)this);
+      //answer->setFailedAvp((Avp*)this);
     }
 
     throw anna::RuntimeException(anna::functions::asString("Internal Avp decoding error (avp code = %u): %s", code, ex.getText().c_str()), ANNA_FILE_LOCATION);
@@ -885,7 +891,7 @@ void Avp::fix() throw() {
   }
 
   if(!stackFormat || !stackFormat->isGrouped()) {
-    //LOGDEBUG(anna::Logger::debug("Avp is not grouped. Nothing fix.", ANNA_FILE_LOCATION));
+    //LOGDEBUG(anna::Logger::debug("Avp is not grouped. Nothing to fix.", ANNA_FILE_LOCATION));
     return;
   }
 
@@ -939,7 +945,7 @@ bool Avp::validLevel(const avp_container &avps, anna::diameter::stack::const_avp
 
         if(answer) {
           answer->setResultCode(helpers::base::AVPVALUES__Result_Code::DIAMETER_MISSING_AVP);
-          answer->setNewFailedAvp((*rule_it).second.getId());
+          answer->setFailedAvp((*rule_it).second.getId());
         }
 
         engine->validationAnomaly(anna::functions::asString("Missing fixed rule %s inside %s", STRING_WITH_QUOTATION_MARKS__C_STR((*rule_it).second.asString(false /*ommit dots & pair*/)), STRING_WITH_QUOTATION_MARKS__C_STR(parentDescription)));
@@ -973,14 +979,14 @@ bool Avp::validLevel(const avp_container &avps, anna::diameter::stack::const_avp
 
         if(answer) {
           answer->setResultCode(helpers::base::AVPVALUES__Result_Code::DIAMETER_MISSING_AVP);
-          answer->setNewFailedAvp(id);
+          answer->setFailedAvp(id);
         }
       } else {
         oamModule.count(OamModule::Counter::LevelValidation__FailedRuleForCardinalityMoreThanNeeded);
 
         if(answer) {
           answer->setResultCode(helpers::base::AVPVALUES__Result_Code::DIAMETER_AVP_OCCURS_TOO_MANY_TIMES);
-          answer->setNewFailedAvp((Avp*)firstAvp(avps, id) /* first instance */);
+          answer->setFailedAvp((Avp*)firstAvp(avps, id) /* first instance */);
         }
       }
 
@@ -1030,7 +1036,7 @@ bool Avp::validLevel(const avp_container &avps, anna::diameter::stack::const_avp
 
       if(answer) {
         answer->setResultCode(helpers::base::AVPVALUES__Result_Code::DIAMETER_AVP_NOT_ALLOWED);
-        //answer->setNewFailedAvp((Avp*)firstAvp(avps, id) /* first instance */); // NO SENSE... what to put ?
+        //answer->setFailedAvp((Avp*)firstAvp(avps, id) /* first instance */); // NO SENSE... what to put ?
       }
 
       engine->validationAnomaly(anna::functions::asString("Failed Generic AVP rule %s for cardinality (found %d disregarded items inside %s)", STRING_WITH_QUOTATION_MARKS__C_STR((*generic_rule_it).second.asString(false /*ommit dots & pair*/)), amount, STRING_WITH_QUOTATION_MARKS__C_STR(parentDescription)));
@@ -1051,7 +1057,7 @@ bool Avp::validLevel(const avp_container &avps, anna::diameter::stack::const_avp
       // We wouldn't know where are these disregarded, but...
       if(answer) {
         answer->setResultCode(helpers::base::AVPVALUES__Result_Code::DIAMETER_AVP_NOT_ALLOWED);
-        answer->setNewFailedAvp((Avp*)firstAvp(avps, id) /* first instance */);
+        answer->setFailedAvp((Avp*)firstAvp(avps, id) /* first instance */);
       }
     }
 
@@ -1101,7 +1107,7 @@ bool Avp::valid(const std::string & parentDescription, Message *answer) const th
 
     if(answer) {
       answer->setResultCode(helpers::base::AVPVALUES__Result_Code::DIAMETER_INVALID_AVP_BITS);
-      //answer->setNewFailedAvp((Avp*)this); RFC 6733 says nothing about Failed-AVP in this case...
+      answer->setFailedAvp((Avp*)this); // RFC 6733 says nothing about Failed-AVP in this case...
     }
 
     getEngine()->validationAnomaly(anna::functions::asString("The AVP %s flags (%d) does not fulfill the defined flag rules: %s", STRING_WITH_QUOTATION_MARKS__C_STR(me), (int)a_flags, STRING_WITH_QUOTATION_MARKS__C_STR(stackAvp->getFlagRulesDescription())));
@@ -1119,7 +1125,7 @@ bool Avp::valid(const std::string & parentDescription, Message *answer) const th
 
       if(answer) {
         answer->setResultCode(helpers::base::AVPVALUES__Result_Code::DIAMETER_INVALID_AVP_VALUE);
-        answer->setNewFailedAvp((Avp*)this);
+        answer->setFailedAvp((Avp*)this);
       }
 
       getEngine()->validationAnomaly(anna::functions::asString("Enumerated AVP %s with value %d does not comply to restriction: %s", STRING_WITH_QUOTATION_MARKS__C_STR(me), a_Enumerated->getValue(), stackAvp->getEnums()));