1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
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 //
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.
16 #include <anna/core/functions.hpp>
17 #include <anna/core/DataBlock.hpp>
23 using namespace anna::diameter::codec;
24 using namespace anna::diameter::helpers::ericsson;
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);
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 = "";
37 int pos = 1; // first avp
38 const char * subscriptionIdPtr;
39 const char * subscriptionIdDataPtr;
40 // Decoded avp information:
44 std::string _dataG /* grouped */, _data;
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);
50 if(!subscriptionIdPtr) return result;
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);
58 int type = DECODE4BYTES_INDX_VALUETYPE(_data, 0, int);
59 found = (type == scapSubscriptionIdType);
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);