Remove warnings
[anna.git] / source / diameter / helpers / ericsson / functions.cpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8
9 // Local
10 #include <anna/diameter/helpers/ericsson/defines.hpp>
11 #include <anna/diameter/helpers/ericsson/functions.hpp>
12 #include <anna/diameter/codec/Message.hpp>
13 #include <anna/diameter/codec/functions.hpp>
14 #include <anna/config/defines.hpp> // general types, decoding helpers (DECODE[2/3/4]BYTES_INDX_VALUETYPE), etc.
15
16 #include <anna/core/functions.hpp>
17 #include <anna/core/DataBlock.hpp>
18
19 // STL
20 #include <string>
21
22 using namespace anna;
23 using namespace anna::diameter::codec;
24 using namespace anna::diameter::helpers::ericsson;
25
26
27 // getters
28 std::string anna::diameter::helpers::ericsson::functions::getSCAPSubscriptionIdData(const anna::DataBlock & db, int scapSubscriptionIdType) throw(anna::RuntimeException) {
29   if(db.getSize() < Message::HeaderLength)
30     throw anna::RuntimeException("Not enough bytes to cover command header length", ANNA_FILE_LOCATION);
31
32   //anna::DataBlock avpsDB(db.getData() + Message::HeaderLength, db.getSize() - Message::HeaderLength);
33   const char *avpsDB = db.getData() + Message::HeaderLength;
34   int avpsLen = db.getSize() - Message::HeaderLength;
35   std::string result = "";
36   bool found = false;
37   int pos = 1; // first avp
38   const char * subscriptionIdPtr;
39   const char * subscriptionIdDataPtr;
40   // Decoded avp information:
41   AvpId _id;
42   char _flags;
43   int _length;
44   std::string _dataG /* grouped */, _data;
45
46   while(!found) {
47     //subscriptionIdPtr = anna::diameter::codec::functions::findAVP(avpsDB, AVPID__SCAP_Subscription_Id, pos);
48     subscriptionIdPtr = anna::diameter::codec::functions::findAVP(avpsDB, avpsLen, AVPID__SCAP_Subscription_Id, pos);
49
50     if(!subscriptionIdPtr) return result;
51
52     // Look up type:
53     anna::diameter::codec::functions::decodeAVP(subscriptionIdPtr, _id, _flags, _length, _dataG);
54     // Data is Fixed SCAP-Subscription-Id-Type (Enumerated derived from Integer32) and then Fixed SCAP-Subscription-Id-Data (UTF8String):
55     // No need to find SCAP-Subscription-Id-Type, it's always the first:
56     anna::diameter::codec::functions::decodeAVP(_dataG.c_str(), _id, _flags, _length, _data);
57     // Enumerated
58     int type = DECODE4BYTES_INDX_VALUETYPE(_data, 0, int);
59     found = (type == scapSubscriptionIdType);
60     pos++;
61   }
62
63   // No need to find SCAP-Subscription-Id-Data within _dataG, it's always the second, and the first takes always 4 words (has vendorID):
64   subscriptionIdDataPtr = _dataG.c_str() + 16;
65   anna::diameter::codec::functions::decodeAVP(subscriptionIdDataPtr, _id, _flags, _length, result);
66   return result;
67 }
68
69