System test feature
[anna.git] / source / diameter / codec / functions.cpp
index a58372d..767d960 100644 (file)
@@ -214,9 +214,11 @@ void functions::decodeAVP(const char *start, diameter::AvpId & id, char & flags,
   );
 }
 
-const char * functions::nextAVP(const anna::DataBlock & avpsDB, const char *start) throw(anna::RuntimeException) {
+const char * functions::nextAVP(const char *avpsDB, int avpsLen, const char *start) throw(anna::RuntimeException) {
   if(start == NULL)
     throw anna::RuntimeException("NULL provided start pointer", ANNA_FILE_LOCATION);
+  if(avpsDB == NULL)
+    throw anna::RuntimeException("NULL provided avpsDB pointer", ANNA_FILE_LOCATION);
 
   const char *result;
 //   LOGDEBUG(
@@ -227,18 +229,21 @@ const char * functions::nextAVP(const anna::DataBlock & avpsDB, const char *star
   //int avpLength = (start[5] << 16) + (start[6] << 8) + start[7]; // AVP Length
   int avpLength = DECODE3BYTES_INDX_VALUETYPE(start, 5, int);
   result = start + 4 * REQUIRED_WORDS(avpLength);
-  const char * first = avpsDB.getData();
-  int offset = (result - first);
+  int offset = (result - avpsDB);
 
-  if(offset > (avpsDB.getSize() - 1))
-    //throw anna::RuntimeException("Start pointer out of boundaries for DataBlock", ANNA_FILE_LOCATION);
+  if(offset > (avpsLen - 1))
+    //throw anna::RuntimeException("Start pointer out of boundaries for block(avpsDB, avpsLen)", ANNA_FILE_LOCATION);
     return NULL; // (*)
 
   return result;
 }
 
-const char * functions::findAVP(const anna::DataBlock & avpsDB, const diameter::AvpId & id, int n) throw(anna::RuntimeException) {
-  const char * result = avpsDB.getData(); // first avp
+//const char * functions::nextAVP(const anna::DataBlock & avpsDB, const char *start) throw(anna::RuntimeException) {
+//  return nextAVP(avpsDB.getData(), avpsDB.getSize(), start);
+//}
+
+const char * functions::findAVP(const char *avpsDB, int avpsLen, const diameter::AvpId & id, int n) throw(anna::RuntimeException) {
+  const char *result = avpsDB; // first avp
   int positives = 0;
   // Decoded avp information:
   diameter::AvpId _id;
@@ -250,7 +255,7 @@ const char * functions::findAVP(const anna::DataBlock & avpsDB, const diameter::
   if(_id == id) positives++;
 
   while((_id != id) || (positives != n)) {  // next search if not found or not ocurrence number reached
-    result = nextAVP(avpsDB, result);
+    result = nextAVP(avpsDB, avpsLen, result);
 
     if(result == NULL) {  // (*)
       LOGDEBUG(
@@ -270,6 +275,9 @@ const char * functions::findAVP(const anna::DataBlock & avpsDB, const diameter::
   return result;
 }
 
+//const char * functions::findAVP(const anna::DataBlock & avpsDB, const diameter::AvpId & id, int n) throw(anna::RuntimeException) {
+//  return findAVP(avpsDB.getData(), avpsDB.getSize(), id, n);
+//}
 
 // modifiers
 void functions::setHopByHop(anna::DataBlock & db, diameter::HopByHop hbh) throw(anna::RuntimeException) {