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 std::string result = "";
35 int pos = 1; // first avp
36 const char * subscriptionIdPtr;
37 const char * subscriptionIdDataPtr;
39 // Decoded avp information:
43 std::string _dataG /* grouped */, _data;
46 subscriptionIdPtr = anna::diameter::codec::functions::findAVP(avpsDB, AVPID__SCAP_Subscription_Id, pos);
48 if(!subscriptionIdPtr) return result;
51 anna::diameter::codec::functions::decodeAVP(subscriptionIdPtr, _id, _flags, _length, _dataG);
52 // Data is Fixed SCAP-Subscription-Id-Type (Enumerated derived from Integer32) and then Fixed SCAP-Subscription-Id-Data (UTF8String):
53 // No need to find SCAP-Subscription-Id-Type, it's always the first:
54 anna::diameter::codec::functions::decodeAVP(_dataG.c_str(), _id, _flags, _length, _data);
56 int type = DECODE4BYTES_INDX_VALUETYPE(_data, 0, int);
57 found = (type == scapSubscriptionIdType);
61 // No need to find SCAP-Subscription-Id-Data within _dataG, it's always the second, and the first takes always 4 words (has vendorID):
62 subscriptionIdDataPtr = _dataG.c_str() + 16;
63 anna::diameter::codec::functions::decodeAVP(subscriptionIdDataPtr, _id, _flags, _length, result);