Stack selection by application-id (configurable), and minor fixes
[anna.git] / source / diameter / codec / Message.cpp
index 6f906f8..4938a03 100644 (file)
@@ -227,6 +227,20 @@ void Message::setId(const char *name) throw(anna::RuntimeException) {
 }
 
 
+//------------------------------------------------------------------------------
+//-------------------------------------------------- Message::setApplicationId()
+//------------------------------------------------------------------------------
+void Message::setApplicationId(U32 aid) throw() {
+  a_applicationId = aid;
+
+  // Default behaviour:
+  if (!getEngine()->selectStackWithApplicationId()) return;
+
+  // Adapts for Application-ID stack identifier:
+  getEngine()->setDictionary(aid);
+}
+
+
 //------------------------------------------------------------------------------
 //------------------------------------------------------------ Message::addAvp()
 //------------------------------------------------------------------------------
@@ -294,7 +308,7 @@ void Message::decode(const anna::DataBlock &db, Message *ptrAnswer) throw(anna::
   //
   // VALIDATION PHASE
   // Launch exception on first validation error (validateAll == false), or log warning reporting all validation errors when
-  //  complete validation is desired (validateAll == true, engine default) launching a final exception like "decoded an invalid message".
+  //  complete validation is desired (validateAll == true, engine default) launching a final exception like "the decoded message is invalid".
   // OAM
   OamModule &oamModule = OamModule::instantiate();
 
@@ -331,9 +345,10 @@ void Message::decode(const anna::DataBlock &db, Message *ptrAnswer) throw(anna::
 
   U24 code = DECODE3BYTES_INDX_VALUETYPE(buffer, 5, U24);
 
-  setId(CommandId(code, requestBit() /* based on a_flags */));
+  // This is called before setId, and in general before any operation which needs to know about the stack elements.
+  setApplicationId(DECODE4BYTES_INDX_VALUETYPE(buffer, 8, U32)); // centralize set, because it could be used for stack selection.
 
-  a_applicationId = DECODE4BYTES_INDX_VALUETYPE(buffer, 8, U32);
+  setId(CommandId(code, requestBit() /* based on a_flags */));
 
   a_hopByHop = DECODE4BYTES_INDX_VALUETYPE(buffer, 12, U32);
 
@@ -409,7 +424,7 @@ void Message::decode(const anna::DataBlock &db, Message *ptrAnswer) throw(anna::
 
   if((vmode == Engine::ValidationMode::AfterDecoding) || (vmode == Engine::ValidationMode::Always))
     if(!valid(answer))
-      throw anna::RuntimeException("Decoded an invalid message. See previous report on warning-level traces", ANNA_FILE_LOCATION);
+      throw anna::RuntimeException("The decoded message is invalid. See previous report on warning-level traces", ANNA_FILE_LOCATION);
 }
 
 
@@ -768,6 +783,10 @@ void Message::fromXML(const anna::xml::Node* messageNode) throw(anna::RuntimeExc
     a_version = i_aux;
   }
 
+  // Application-id
+  // This is called before setId, and in general before any operation which needs to know about the stack elements.
+  setApplicationId(appid->getIntegerValue()); // this could set the dictionary...
+
   // Dictionary
   const stack::Dictionary * dictionary = getEngine()->getDictionary();
   const stack::Command *stackCommand = NULL;
@@ -853,19 +872,6 @@ void Message::fromXML(const anna::xml::Node* messageNode) throw(anna::RuntimeExc
     a_flags = flagsBCK;
   }
 
-  // Application-id
-  u_aux = appid->getIntegerValue();
-
-  /*
-  if(u_aux < 0) {
-    std::string msg = "Error processing command <application-id '"; msg += appid->getValue();
-    msg += "': negative values are not allowed";
-    throw anna::RuntimeException(msg, ANNA_FILE_LOCATION);
-  }
-  */
-
-  setApplicationId(u_aux);
-
   // Hob-by-hop-id
   if(hbh) {
     u_aux = hbh->getIntegerValue();